本文共 3516 字,大约阅读时间需要 11 分钟。
控制器采用POX,基于OVS仿真
设置intf link.intf1 link.intf2
配置HOST
配置vswitch
contrller -v ptcp: &
绑定端口与对应的网桥
ovs-vsctl add-port br0 %s
% intfovs-vsctl set-controller dp0:127.0.0.1:6653
停止网络
在专业的网络世界中,经常使用到Virtual Routing and Forwarding(VRF),比如Cisco,Alcatel-Lucent, Juniper 等。对于L2 switch,自从上世纪90年代就开始使用VLAN,一个物理交换机上可以使用多个广播域,如今大多数交换机都支持4K vlan。
这个概念被引入到L3,如今很多网络设备支持VRF。这意味着,单个物理设备上可运行多个虚拟路由(L3 转发实例)。
在linux中,VRF被叫做“network namespace”,当然了linux中还包括其他namespace,不过本文不讨论。
每个network namespace拥有其对应的路由表(routing table)& 其对应的iptables,并且运行程序运行其中。 为什么有人使用它?比如一个运行在linux上的 Firewall,将firewall的所有服务端口分配给一个network namespace,这样,默认的network namespace 和 Firewall network namespace就运行着不同的路由表。像SSH这样的application运行在默认的network namespace,但是不在Firewall network namespace。
详解:
(Mininet Python API Reference Manual)[
#!/usr/bin/python#coding:utf-8from mininet.net import Mininetfrom mininet.node import Nodefrom mininet.link import TCLinkfrom mininet.log import setLogLevel, infofrom threading import Timerfrom mininet.util import quietRunfrom time import sleepdef myNet(cname='controller', cargs='-v ptcp:'): # Create network from scratch using Open vSwitch info("*** Creating nodes\n") controller = Node('c0', inNamespace=False) switch = Node('s0', inNamespace=False) switch1 = Node('s1', inNamespace=False) h0 = Node('h0') h1 = Node('h1') info("*** Creating links\n") linkopts0 = dict(bw=100, delay='1ms', loss=0) linkopts1 = dict(bw=100, delay='1ms', loss=10) link0 = TCLink(h0, switch, **linkopts0) link1 = TCLink(switch, switch1, **linkopts1) link2 = TCLink(h1, switch1, **linkopts0) # set mac to vDevice link0.intf2.setMAC("0:0:0:0:0:1") link1.intf1.setMAC("0:0:0:0:0:2") link1.intf2.setMAC("0:1:0:0:0:1") link2.intf2.setMAC("0:1:0:0:0:2") info("*** Configuring hosts\n") h0.setIP('192.168.123.1/24') h1.setIP('192.168.123.2/24') info("*** Starting network using Open vSwitch\n") switch.cmd('ovs-vsclt del-br dp0') switch.cmd('ovs-vsctl add-br dp0') switch1.cmd('ovs-vsctl del-br dp1') switch1.cmd('ovs-vsctl add-br dp1') controller.cmd(cname + ' ' + cargs + '&') for intf in switch.intfs.values(): print intf print switch.cmd('ovs-vsctl add-port dp0 %s' % intf) for intf in switch1.intfs.values(): print intf print switch1.cmd('ovs-vsctl add-port dp1 %s' % intf) # Note: controller and switch are in root namspace, and we # can connect via loopback interface switch.cmd('ovs-vsctl set-controller dp0:127.0.0.1:6633') switch1.cmd('ovs-vsctl set-controller dp1 tcp:127.0.0.1:6633') info('*** Waiting for switch to connect to controller') while 'is_connected' not in quietRun('ovs-vsctl show'): sleep(1) info('.') info('\n') # info("*** Running test\n") h0.cmdPrint('ping -Q 0x64 -c 20 ' + h1.IP()) sleep(1) info("*** Stopping network\n") controller.cmd('kill %' + cname) switch.cmd('ovs-vsctl del-br dp0') switch.deleteIntfs() switch1.cmd('ovs-vsctl del-br dp1') switch1.defaultIntf() info('\n')if __name__ == "__main__": setLogLevel('info') info('*** Scratch networkd demo (kernel datapath)\n') Mininet.init() myNet()
转载地址:http://dexym.baihongyu.com/