def do_add_node(self, line): """Spawn a new node.""" host_num = len(NET.hosts) + 1 end_switch = NET.switches[-1] new_switch = NET.addSwitch('s%d' % host_num) new_host = NET.addHost("h%ds%d" % (host_num, host_num)) # TODO: Fix bug that doesn't allow adding nodes starting from 1 Link(new_host, new_switch) slink = Link(end_switch, new_switch) end_switch.attach(slink.intf1) new_switch.start(NET.controllers) new_host.configDefault(defaultRoute=new_host.defaultIntf()) c = xterm_cmd(ip=new_host.IP(), port=config.PORT, b_ip=NET.hosts[0].IP(), b_port=config.PORT) new_host.cmd(c % host_num) print("Started new node: %s" % new_host)
def emptyNet(): net = Mininet(topo=None, build=False) c0 = Controller('c0', inNamespace=False) h1 = Host('h1') h2 = Host('h2') #intf1 = Intf("h1-eth1") #intf2 = Intf("h2-eth1") s1 = OVSSwitch('br0', inNamespace=False) Link(h1, s1) Link(h2, s1) c0.start() s1.start([c0]) net.start() #s1.cmd('ovs-vsctl set bridge br0 protocols=OpenFlow13') CLI(net) net.stop() h1.stop() h2.stop() s1.stop() c0.stop()
def topology(): "Create a network." net = Mininet(controller=RemoteController, link=TCLink, switch=OVSKernelSwitch) print "*** Creating nodes" h1 = net.addHost('h1', mac='00:00:00:00:00:01', ip='10.0.0.1/24') h2 = net.addHost('h2', mac='00:00:00:00:00:02', ip='10.0.10.2/24') h3 = net.addHost('h3', mac='00:00:00:00:00:03', ip='10.0.0.2/24') s4 = net.addSwitch('s4', listenPort=6673, mac='00:00:00:00:00:04') s5 = net.addSwitch('s5', listenPort=6674, mac='00:00:00:00:00:05') c7 = net.addController('c7', controller=RemoteController, ip='127.0.0.1', port=6633) print "*** Creating links" net.addLink(s4, h3, 2, 0) #net.addLink(h1, s4, 0, 1) Link(h1, s4, intfName1='h1-eth0') net.addLink(s5, h2, 2, 0) #net.addLink(h1, s5, 0, 1) Link(h1, s5, intfName1='h1-eth1') h1.cmd('ifconfig h1-eth1 10.0.10.1 netmask 255.255.255.0') print "*** Starting network" net.build() c7.start() s4.start([c7]) s5.start([c7]) print "*** Running CLI" CLI(net) print "*** Stopping network" net.stop()
def emptyNet(): "Create an empty network and add nodes to it." "[h1]<---network-a--->[s3]<--wifi-bridge-->[s4]<---network-b--->[h2]" net = Mininet( controller=OVSController ) info( '*** Adding controllers\n' ) net.addController( 'c0' ) net.addController( 'c1' ) info( '*** Adding hosts\n' ) h1 = net.addHost( 'h1', ip='10.0.0.1' ) h2 = net.addHost( 'h2', ip='10.0.0.2' ) info( '*** Adding switches\n' ) s3 = net.addSwitch( 's3' ) s4 = net.addSwitch( 's4' ) info( '*** Creating links\n' ) Link( s3, h1 ) WIFIBridgeLink( s3, s4 ) Link( s4, h2 ) info( '*** Starting network\n') net.start() mininet.ns3.start() info( '*** Running CLI\n' ) CLI( net ) info( '*** Stopping network' ) mininet.ns3.stop() mininet.ns3.clear() net.stop()
def myNet(): "Create network from scratch using Open vSwitch." info( "*** Creating nodes\n" ) switch0 = Node( 's0', inNamespace=False ) h0 = Node( 'h0' ) h1 = Node( 'h1' ) h2 = Node( 'h2' ) info( "*** Creating links\n" ) Link( h0, switch0) Link( h1, switch0) Link( h2, switch0) info( "*** Configuring hosts\n" ) h0.setIP( '192.168.123.1/24' ) h1.setIP( '192.168.123.2/24' ) h2.setIP( '192.168.123.3/24' ) info( "*** Starting network using Open vSwitch\n" ) switch0.cmd( 'ovs-vsctl del-br dp0' ) switch0.cmd( 'ovs-vsctl add-br dp0' ) for intf in switch0.intfs.values(): print intf print switch0.cmd( 'ovs-vsctl add-port dp0 %s' % intf ) # Note: controller and switch are in root namespace, and we # can connect via loopback interface #switch0.cmd( 'ovs-vsctl set-controller dp0 tcp:127.0.0.1:6633' ) print switch0.cmd(r'ovs-vsctl show') print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=1,in_port=1,actions=flood' ) print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=1,in_port=2,actions=flood' ) print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=1,in_port=3,actions=flood' ) print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=10,ip,nw_dst=192.168.123.1,actions=output:1' ) print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=10,ip,nw_dst=192.168.123.2,actions=output:2' ) print switch0.cmd(r'ovs-ofctl add-flow dp0 idle_timeout=0,priority=10,ip,nw_dst=192.168.123.3,actions=output:3') #switch0.cmd('tcpdump -i s0-eth0 -U -w aaa &') #h0.cmd('tcpdump -i h0-eth0 -U -w aaa &') info( "*** Running test\n" ) h0.cmdPrint( 'ping -c 3 ' + h1.IP() ) h0.cmdPrint( 'ping -c 3 ' + h2.IP() ) #print switch0.cmd( 'ovs-ofctl show dp0' ) #print switch0.cmd( 'ovs-ofctl dump-tables dp0' ) #print switch0.cmd( 'ovs-ofctl dump-ports dp0' ) #print switch0.cmd( 'ovs-ofctl dump-flows dp0' ) #print switch0.cmd( 'ovs-ofctl dump-aggregate dp0' ) #print switch0.cmd( 'ovs-ofctl queue-stats dp0' ) info( "*** Stopping network\n" ) switch0.cmd( 'ovs-vsctl del-br dp0' ) switch0.deleteIntfs() info( '\n' )
def scratchNet(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) h0 = Node('h0') h1 = Node('h1') info("*** Creating links\n") Link(h0, switch) Link(h1, switch) info("*** Configuring hosts\n") h0.setIP('192.168.123.1/24') h1.setIP('192.168.123.2/24') info(str(h0) + '\n') info(str(h1) + '\n') info("*** Starting network using Open vSwitch\n") controller.cmd(cname + ' ' + cargs + '&') switch.cmd('ovs-vsctl del-br dp0') switch.cmd( 'ovs-vsctl add-br dp0 other-config:datapath-id={}'.format(datapath_id)) for intf in switch.intfs.values(): print switch.cmd('ovs-vsctl add-port dp0 %s' % intf) # Note: controller and switch are in root namespace, and we # can connect via loopback interface s_cmd = 'ovs-vsctl set-controller dp0 tcp:[{}]:{}'.format( CTLR_IP, CTLR_PRT) print s_cmd switch.cmd(s_cmd) ping_results = [ 'received,host,jitter,packet_loss,avgping,minping,time,sent,maxping\n' ] try: h0.cmd('echo "" > pings.txt') if mode == 0: step_wise_testing(h0, h1, ping_results) else: continuous_testing(h0, h1, ping_results) except KeyboardInterrupt: print "Warning: Caught KeyboardInterrupt, stopping network" tm_local = time.localtime() dt = time.gmtime() file_name = 'pings_{}_{}_{}-{}_{}_{}.csv'.format( dt.tm_year, dt.tm_mon, dt.tm_mday, tm_local.tm_hour, tm_local.tm_min, tm_local.tm_sec) f = open(file_name, 'w+') for item in ping_results: f.write(item) stop_net(controller, cname, switch)
def scratchNet(cname='controller', cargs='-v ptcp:'): "Create network from scratch using Open vSwitch." info("*** Creating nodes\n") controller = Node('c0', inNamespace=False) switch0 = Node('s0', inNamespace=False) h0 = Node('h0') h1 = Node('h1') info("*** Creating links\n") Link(h0, switch0) Link(h1, switch0) info("*** Configuring hosts\n") h0.setIP('192.168.123.1/24') h1.setIP('192.168.123.2/24') info(str(h0) + '\n') info(str(h1) + '\n') info("*** Starting network using Open vSwitch\n") controller.cmd(cname + ' ' + cargs + '&') switch0.cmd('ovs-vsctl del-br dp0') switch0.cmd('ovs-vsctl add-br dp0') for intf in switch0.intfs.values(): print intf print switch0.cmd('ovs-vsctl add-port dp0 %s' % intf) # Note: controller and switch are in root namespace, and we # can connect via loopback interface switch0.cmd('ovs-vsctl set-controller dp0 tcp:127.0.0.1:6633') switch0.cmd('ovs-ofctl add-flow dp0 \"in_port=1 actions=output:2\"') switch0.cmd('ovs-ofctl add-flow dp0 \"in_port=2 actions=output:1\"') 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 -c3 ' + h1.IP()) h1.cmdPrint('ping -c3 ' + h0.IP()) info("*** Stopping network\n") controller.cmd('kill %' + cname) switch0.cmd('ovs-vsctl del-br dp0') switch0.deleteIntfs() info('\n')
def scratchNet(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) h0 = Node('h0') h1 = Node('h1') info("*** Creating links\n") Link(h0, switch) Link(h1, switch) info("*** Configuring hosts\n") h0.setIP('192.168.123.1/24') h1.setIP('192.168.123.2/24') info(str(h0) + '\n') info(str(h1) + '\n') info("*** Starting network using Open vSwitch\n") controller.cmd(cname + ' ' + cargs + '&') switch.cmd('ovs-vsctl del-br dp0') switch.cmd('ovs-vsctl add-br dp0') for intf in switch.intfs.values(): print switch.cmd('ovs-vsctl add-port dp0 %s' % intf) # Note: controller and switch are in root namespace, and we # can connect via loopback interface s_cmd = 'ovs-vsctl set-controller dp0 tcp:[{}]:{}'.format( CTLR_IP, CTLR_PRT) print s_cmd switch.cmd(s_cmd) info('*** Waiting for switch to connect to controller') try: while 'is_connected' not in quietRun('ovs-vsctl show'): sleep(1) info('.') info('\n') while True: info("*** Running test\n") h0.cmdPrint('ping -c1 ' + h1.IP()) info("*** Sleep\n") sleep(2) except KeyboardInterrupt: print "Warning: Caught KeyboardInterrupt, stopping network" stop_net(controller, cname, switch)
def add_link(): Link(hosts[0], switches[0]) Link(hosts[1], switches[0]) tmp1 = int(hosts.index('h0')) + 1 tmp2 = int(hosts.index('h1')) + 1 ip1 = '10.' + str(tmp1) + '/8' ip2 = '10.' + str(tmp2) + '/8' hosts[0].setIP(ip1) hosts[1].setIP(ip2) controllers[0].start() switches[0].start(controllers[0]) ping = hosts[0].cmd('ping -c1', hosts[1].IP()) switches[0].stop() controllers[0].stop() return redirect(url_for('create'))
def do_AddNode(self, line): id = len(P2PNet.hosts) newHost = P2PNet.addHost("h%ds%d" % (id, id)) switch = P2PNet.switches[0] P2PNet.addLink(switch, newHost) slink = Link(switch, newHost) switch.attach(slink) switch.start(P2PNet.controllers) newHost.configDefault(defaultRoute=newHost.defaultIntf()) print(P2PNet.hosts[0].cmd("ping -c1 %s" % newHost.IP())) #important!!! print(newHost.cmd("ping -c1 10.0.0.1")) cmd = xtermCMD(newHost.IP(), PORT, P2PNet.hosts[0].IP(), PORT, MODE) print(cmd) newHost.cmd(cmd % (id)) print("Started new node: %s" % newHost)
def do_AddHost(self, line): global P2PNet id = len(P2PNet.hosts) + 1 newHost = P2PNet.addHost("h%d" % id) switch = P2PNet.switches[0] P2PNet.addLink(switch, newHost) slink = Link(switch, newHost) switch.attach(slink) switch.start(P2PNet.controllers) newHost.configDefault(defaultRoute=newHost.defaultIntf()) print(P2PNet.hosts[0].cmd("ping -c1 %s" % newHost.IP())) print(newHost.cmd("ping -c1 10.0.0.1")) cmd = xtermCMD(id, newHost.IP(), defaultPort, P2PNet.hosts[0].IP(), defaultPort, 'test') print(cmd) newHost.cmd(cmd) print("Started new node: %s" % newHost)
def connectToRootNS(net, ip='10.123.123.1', mac='00123456789A', prefixLen=8, routes=['10.0.0.0/8']): print "*** Creating controller" c0 = net.addController('c0', ip='127.0.0.1', port=6633) rootswitch = net.addSwitch('roots1', ) rootswitch.dpid = 'FFFFFFFFFFFFFFFF' # Connect hosts to root namespace via switch. Starts network. # network: Mininet() network object # ip: IP address for root namespace node # prefixLen: IP address prefix length (e.g. 8, 16, 24) # routes: host networks to route to" # Create a node in root namespace and link to switch 0 root = Node('root', inNamespace=False) intf = Link(root, rootswitch).intf1 intf.setMAC(mac) root.setIP(ip, prefixLen, intf) print "*** Added Interface", str(intf), "Connected To Root-NameSpace" fixNetworkManager(str(intf)) for host in net.hosts: net.addLink(host, rootswitch) # Add routes from root ns to hosts for route in routes: root.cmd('route add -net ' + route + ' dev ' + str(intf)) root.cmd('service network-manager restart') return rootswitch
def configNameSpace(self): global CONTROLLER if self.controllers: controller = self.controllers[0] self.sip = controller.IP() else: if not CONTROLLER: controller = P4Host('c0', inNamespace=False) CONTROLLER = controller else: controller = CONTROLLER self.cmd('ip link set lo up') if not self.inband: link = Link(self, controller, port1=0) sintf, cintf = link.intf1, link.intf2 if controller.IP() == '127.0.0.1' or not controller.IP(): cip = self.getIP() else: cip = controller.IP() controller.setIP(cip, intf='c0-eth%s' % (len(controller.intfs) - 1)) self.setIP(intf='%s-eth0' % self.name, ip=self.sip) controller.setHostRoute('%s' % self.sip, cintf) self.setHostRoute(cip, sintf) return controller
def scratchNet(cname='controller', cargs='-v ptcp:'): #create network from scratch using Open vswitch info("***Creating nodes\n") controller = Node('c0', inNamespace=False) switch0 = Node('s0', inNamespace=False) h0 = Node('h0') h1 = Node('h1') info("***Creating links\n") Link(h0, switch0) Link(h1, switch0) info(" ***Configuring hosts\n") h0.setIP('192.168.123.1/24') h1.setIP('192.168.123.2/24') info(str(h0) + '\n') info(str(h1) + '\n')
def fileCommand(): while True: line = readCommnadFromFile() if line != None: line = line.strip() if len(line) > 0: line = line.split() cmd = line[0] args = line[1:] if cmd in ["recordNodesInfo"]: recordNodesInfo() elif cmd in ["delNode"]: hostName = args[0].strip() node = None for host in P2PNet.hosts: if host.name == hostName: node = host break P2PNet.delNode(node) recordNodesInfo() elif cmd in ["addNode"]: id = len(P2PNet.hosts) newHost = P2PNet.addHost("h%ds%d" % (id, id)) switch = P2PNet.switches[0] P2PNet.addLink(switch, newHost) slink = Link(switch, newHost) switch.attach(slink) switch.start(P2PNet.controllers) newHost.configDefault(defaultRoute=newHost.defaultIntf()) print(P2PNet.hosts[0].cmd("ping -c1 %s" % newHost.IP())) # important!!! print(newHost.cmd("ping -c1 10.0.0.1")) cmd = xtermCMD(newHost.IP(), PORT, P2PNet.hosts[0].IP(), PORT, MODE) print(cmd) newHost.cmd(cmd % (id)) print("Started new node: %s" % newHost) recordNodesInfo() clearFileCMD() sleep(2)
def _build_test_host(self, mn_switch): for host_name, host_obj in self.node_mgr.test_host_index.items(): host = self.net.addHost(host_name) # host interface was created when Link-ed switch Link(host, mn_switch) for port_name, port_obj in host_obj.port_index.items(): # TODO: suppose that host has ONLY one interface thp = TestHostParam(host, host_obj, port_obj) self.logger.info("build test host: %s", thp) self.test_host_params.append(thp)
def myNetwork(): net = Mininet(topo=None, build=False, ipBase='10.0.0.0/8', link=TCLink) info('*** Adding controller\n') info('*** Add switches\n') info('*** Add hosts\n') h3 = net.addHost('h3', cls=Host, ip='10.0.0.3', defaultRoute=None) h1 = net.addHost('h1', cls=Host, ip='10.0.0.1', defaultRoute=None) h2 = net.addHost('h2', cls=Host, ip='10.0.0.2', defaultRoute=None) info('*** Add links\n') Link(h1, h2) Link(h2, h3, intfName1='h2-eth1') info('*** Starting network\n') net.build() info('*** Starting controllers\n') for controller in net.controllers: controller.start() info('*** Starting switches\n') info('*** Post configure switches and hosts\n') CLI(net) net.stop()
def emptyNet(): "Create an empty network and add nodes to it." "[h1]<---network-a--->[s3]<--wifi-bridge-->[s4]<---network-b--->[h2]" net = Mininet() c2 = net.addController(name='FloodLight', controller=RemoteController, ip='10.102.206.207', port=6653) info('*** Adding controllers\n') net.addController('c0') net.addController('c1') info('*** Adding hosts\n') h1 = net.addHost('h1', ip='10.0.0.1') h2 = net.addHost('h2', ip='10.0.0.2') h3 = net.addHost('h3', ip='10.0.0.3') h4 = net.addHost('h4', ip='10.0.0.4') info('*** Adding switches\n') s1 = net.addSwitch('s1') s2 = net.addSwitch('s2') s3 = net.addSwitch('s3') s4 = net.addSwitch('s4') info('*** Creating links\n') Link(s1, h1) Link(s2, h2) Link(s3, h3) Link(s4, h4) Link(s1, s2) Link(s1, s3) Link(s2, s4) Link(s3, s4) WIFIBridgeLink(s3, s4) info('*** Starting network\n') net.start() mininet.ns3.start() info('*** Running CLI\n') CLI(net) info('*** Stopping network') mininet.ns3.stop() mininet.ns3.clear() net.stop()
def enableSSH(self, net): print 'Enabling ssh' routes = ['10.0.0.0/24'] ip = '10.123.123.1/32' switch = self.CoreSwitchList[0] print switch switch = net[switch] root = Node('root', inNamespace=False) intf = Link(root, switch).intf1 root.setIP(ip, intf=intf) net.start() for route in routes: root.cmd('route add -net ' + route + ' dev ' + str(intf))
def topology(): "Create a network." net = Mininet(controller=RemoteController, link=TCLink, switch=OVSKernelSwitch) print "*** Creating nodes ***" h1 = net.addHost('h1', mac='00:00:00:00:00:01', ip='10.0.10.1/24') h2 = net.addHost('h2', mac='00:00:00:00:00:02', ip='10.0.10.2/24') h3 = net.addHost('h3', mac='00:00:00:00:00:03', ip='10.0.1.1/24') s1 = net.addSwitch('s1', listenPort=6673, mac='00:00:00:00:00:11') s2 = net.addSwitch('s2', listenPort=6674, mac='00:00:00:00:00:12') c0 = net.addController('c0', controller=RemoteController, ip='127.0.0.1', port=6633) print "*** Creating links ***" net.addLink(s1, h1, 1, 0) net.addLink(s2, h3, 1, 0) Link(h2, s1, intfName1='h2-eth0') Link(h2, s2, intfName1='h2-eth1') h2.cmd('ifconfig h2-eth1 10.0.1.2 netmask 255.255.255.0') h2.cmd('sysctl net.ipv4.ip_forward=1') print "*** Starting network ***" net.build() c0.start() s1.start([c0]) s2.start([c0]) h1.cmd('route add default gw 10.0.10.2') h3.cmd('route add default gw 10.0.1.2') print "*** Running CLI ***" CLI(net) print "*** Stopping network ***" net.stop()
def connectToRootNS(network, switch, ip, routes): """Connect hosts to root namespace via switch. Starts network. network: Mininet() network object switch: switch to connect to root namespace ip: IP address for root namespace node routes: host networks to route to""" # Create a node in root namespace and link to switch 0 root = Node('root', inNamespace=False) intf = Link(root, switch).intf1 root.setIP(ip, intf=intf) # Start network that now includes link to root namespace network.start() # Add routes from root ns to hosts for route in routes: root.cmd('route add -net ' + route + ' dev ' + str(intf))
def configNameSpace(self): if self.controllers: controller = self.controllers[0] self.sip = controller.IP() else: controller = ONOSHost('c0', inNamespace=False) if not self.inband: cip = self.getIP( ) if controller.IP() is '127.0.0.1' else controller.IP() link = Link(self, controller, port1=0) sintf, cintf = link.intf1, link.intf2 controller.setIP(intf='c0-eth%s' % (len(controller.intfs) - 1), ip=cip) self.setIP(intf='%s-eth0' % self.name, ip=self.sip) self.cmd('ip link set lo up') controller.setHostRoute('%s' % self.sip, cintf) self.setHostRoute(cip, sintf) return controller
class LacpTopo(Topo): net = Mininet(controller=RemoteController) c0 = net.addController('c0', controller=RemoteController, ip='CONTROLLER') s1 = net.addSwitch('s1') h1 = net.addHost('h1', mac='00:00:00:00:00:11') h2 = net.addHost('h2', mac='00:00:00:00:00:22') h3 = net.addHost('h3', mac='00:00:00:00:00:33', ip='10.1.1.3') h4 = net.addHost('h4', mac='00:00:00:00:00:44', ip='10.1.1.4') Link(s1, h1) Link(s1, h1) Link(s1, h2) Link(s1, h2) Link(s1, h3) Link(s1, h4) net.build() s1.start([c0]) s1.cmd('sudo ovs-vsctl set bridge s1 protocols=OpenFlow13') print h1.cmd('./h1-bond0.sh') print h2.cmd('./h2-bond0.sh') CLI(net) net.stop()
class LacpTopo(Topo): net = Mininet(controller=RemoteController) c0 = net.addController("c0", controller=RemoteController, ip="CONTROLLER") s1 = net.addSwitch("s1") h1 = net.addHost("h1", mac="00:00:00:00:00:11") h2 = net.addHost("h2", mac="00:00:00:00:00:22") h3 = net.addHost("h3", mac="00:00:00:00:00:33", ip="10.1.1.3") h4 = net.addHost("h4", mac="00:00:00:00:00:44", ip="10.1.1.4") Link(s1, h1) Link(s1, h1) Link(s1, h2) Link(s1, h2) Link(s1, h3) Link(s1, h4) net.build() s1.start([c0]) s1.cmd("sudo ovs-vsctl set bridge s1 protocols=OpenFlow13") print(h1.cmd("./h1-bond0.sh")) print(h2.cmd("./h2-bond0.sh")) CLI(net) net.stop()
#!/usr/bin/python from mininet.node import Host, OVSSwitch, Controller from mininet.link import Link h1 = Host('h1') h2 = Host('h2') h3 = Host('h3') h4 = Host('h4') s1 = OVSSwitch('s1', inNamespace=False) s2 = OVSSwitch('s2', inNamespace=False) c0 = Controller('c0', inNamespace=False) Link(h1, s1) Link(h2, s1) Link(h3, s2) Link(h4, s2) Link(s1, s2) h1.setIP('10.0.0.1/24') h2.setIP('10.0.0.2/24') h3.setIP('10.0.0.3/24') h4.setIP('10.0.0.4/24') c0.start() s1.start([c0]) s2.start([c0]) print h1.IP print h2.IP print h3.IP print h4.IP print 'Pinging ...' print h1.cmd('ping -c3 ', h2.IP()) print h1.cmd('ping -c3 ', h3.IP())
conf.register_cli_opts(opts) conf(project='ryu', version='run_mininet.py %s' % version) conf(sys.argv[1:]) switch_type = {'ovs': OVSSwitch, 'cpqd': UserSwitch} switch = switch_type.get(conf.switch) if switch is None: raise ValueError('Invalid switch type. [%s]', conf.switch) net = Mininet(switch=switch, controller=RemoteController) c0 = net.addController('c0') s1 = net.addSwitch('s1') s2 = net.addSwitch('s2') Link(s1, s2) Link(s1, s2) Link(s1, s2) net.build() c0.start() s1.start([c0]) s2.start([c0]) if conf.switch == 'ovs': s1.cmd('ovs-vsctl set Bridge s1 protocols=OpenFlow13') s2.cmd('ovs-vsctl set Bridge s2 protocols=OpenFlow13') CLI(net) net.stop()
def setUp(self): self.h3 = Node('t0', ip='10.0.0.3/8') self.n0 = Node('t1', inNamespace=False) Link(self.h3, self.n0) self.h3.configDefault()
if '__main__' == __name__: net = Mininet(link=TCLink) #h1 is under vlan10 h1 = net.addHost('h1') #h2 is under vlan20 h2 = net.addHost('h2') #h3 is a switch h3 = net.addHost('h3') #h4 is a switch h4 = net.addHost('h4') #h5 is under vlan10 h5 = net.addHost('h5') #h6 is under vlan20 h6 = net.addHost('h6') Link(h1, h3) Link(h2, h3) Link(h3, h4) Link(h5, h4) Link(h6, h4) net.build() h3.cmd("ifconfig h3-eth2 0") h4.cmd("ifconfig h4-eth0 0") h3.cmd("vconfig add h3-eth2 10") h3.cmd("vconfig add h3-eth2 20") h4.cmd("vconfig add h4-eth0 10") h4.cmd("vconfig add h4-eth0 20") h3.cmd("ifconfig h3-eth2.10 up") h3.cmd("ifconfig h3-eth2.20 up") h4.cmd("ifconfig h4-eth0.10 up") h4.cmd("ifconfig h4-eth0.20 up")
def scratchNet(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) h0 = Node('h0') h1 = Node('h1') info("*** Creating links\n") Link(h0, switch) Link(h1, switch) info("*** Configuring hosts\n") h0.setIP('192.168.123.1/24') h1.setIP('192.168.123.2/24') info(str(h0) + '\n') info(str(h1) + '\n') info("*** Starting network using Open vSwitch\n") controller.cmd(cname + ' ' + cargs + '&') #issue_switch_cmd(switch, 'ovs-vsctl del-br br-ex') issue_switch_cmd(switch, 'ovs-vsctl del-br br-int') #issue_switch_cmd(switch, 'ovs-vsctl add-br br-ex') issue_switch_cmd(switch, 'ovs-vsctl add-br br-int') # CONCLUSION # ovs-vsctl add-br br-ex # ovs-vsctl add-port br-ex {external_nic} # ovs-vsctl add-br br-int # ovs-vsctl add-port br-int {internal_nic} # ovs-vsctl --no-wait set bridge br-int fail-mode=secure other-config:disable-in-band=true # ovs-vsctl set bridge br-int protocols=OpenFlow10,OpenFlow13 # ovs-vsctl set-manager ptcp:6640:0.0.0.0 for intf in switch.intfs.values(): print issue_switch_cmd(switch, 'ovs-vsctl add-port br-int %s' % intf) # for intf in switch.intfs.values(): # print issue_switch_cmd(switch, 'ovs-vsctl add-port br-ex %s' % intf) issue_switch_cmd(switch, 'ovs-vsctl --no-wait set bridge br-int fail-mode=secure other-config:disable-in-band=true') issue_switch_cmd(switch, 'ovs-vsctl set bridge br-int protocols=OpenFlow10,OpenFlow13') #issue_switch_cmd(switch, 'ovs-vsctl set-manager ptcp:6640:0.0.0.0') # issue_switch_cmd(switch, 'ovs-ofctl -O OpenFlow13 dump-flows br-int') # Note: controller and switch are in root namespace, and we # can connect via loopback interface s_cmd = 'ovs-vsctl set-controller br-int tcp:{}:{}'.format(CTLR_IP, CTLR_PRT) issue_switch_cmd(switch, s_cmd) ping_results = ['received,host,jitter,packet_loss,avgping,minping,time,sent,maxping\n'] try: h0.cmd('echo "" > pings.txt') if mode == 0: step_wise_testing(h0, h1, ping_results) else: continuous_testing(h0, h1, ping_results) except KeyboardInterrupt: print "Warning: Caught KeyboardInterrupt, stopping network" tm_local = time.localtime() dt = time.gmtime() file_name = 'pings_{}_{}_{}-{}_{}_{}.csv'.format(dt.tm_year, dt.tm_mon, dt.tm_mday, tm_local.tm_hour, tm_local.tm_min, tm_local.tm_sec) f = open(file_name, 'w+') for item in ping_results: f.write(item) stop_net(controller, cname, switch)
#!/usr/bin/python from mininet.node import Host, OVSSwitch, Controller from mininet.link import Link h1 = Host('h1') h2 = Host('h2') h3 = Host('h3') h4 = Host('h4') s1 = OVSSwitch('s1', inNamespace=False) #s2 = OVSSwitch( 's2', inNamespace=False ) c0 = Controller('c0', inNamespace=False) Link(h1, s1) Link(h2, s1) Link(h3, s1) Link(h4, s1) #Link(s1,s2) h1.setIP('10.0.0.1/24') h2.setIP('10.0.0.2/24') h3.setIP('10.0.0.3/24') h4.setIP('10.0.0.4/24') c0.start() s1.start([c0]) #s2.start([c0]) print h1.IP print h2.IP print h3.IP