from functools import partial mininet.log.setLogLevel('info') Switch = partial(mininet.node.OVSSwitch, protocols='OpenFlow13') net = mininet.net.Containernet(switch=Switch) net.addController('c0', controller=mininet.node.RemoteController, ip='172.17.42.1', port=6652) runtime_id = os.urandom(2).encode('hex') # runtime_id = sys.argv[1] s0 = net.addSwitch("s0") s1 = net.addSwitch("s1") s2 = net.addSwitch("s2") s3 = net.addSwitch("s3") s4 = net.addSwitch("s4") net.addLink(s0, s1, cls=mininet.link.TCLink, delay="100ms", bw=40) net.addLink(s1, s2, cls=mininet.link.TCLink, delay="10ms", bw=20) net.addLink(s0, s3, cls=mininet.link.TCLink, delay="100ms", bw=40) net.addLink(s3, s4, cls=mininet.link.TCLink, delay="10ms", bw=20) c0 = net.addDocker( 'c0' + runtime_id, ip='10.0.1.1/8', dimage='dx_cloud', # dcmd='python deploy-service/main.py', dcmd='bash boot.sh', # dcmd='tail -f /dev/null', environment={ 'TOPO_NAME': 'c1f2d2_cloud', 'CADVISOR_HOST': '172.17.42.1', 'CADVISOR_PORT': 9001
Switch = partial(mininet.node.OVSSwitch, protocols='OpenFlow13') net = mininet.net.Containernet(switch=Switch) net.addController('c0', controller=mininet.node.RemoteController, ip='172.17.42.1', port=6652) # runtime_id = os.urandom(2).encode('hex') runtime_id = sys.argv[1] s0 = net.addSwitch("s0") s1 = net.addSwitch("s1") s2 = net.addSwitch("s2") s3 = net.addSwitch("s3") s4 = net.addSwitch("s4") net.addLink(s0, s1, cls=mininet.link.TCLink, delay="100ms", bw=40) net.addLink(s1, s2, cls=mininet.link.TCLink, delay="10ms", bw=20) net.addLink(s0, s3, cls=mininet.link.TCLink, delay="100ms", bw=40) net.addLink(s3, s4, cls=mininet.link.TCLink, delay="10ms", bw=20) c0 = net.addDocker( 'c0' + runtime_id, ip='10.0.1.1/8', dimage='dx_cloud_deploy', dcmd='python deploy-service/main.py', environment={ 'TOPO_NAME': 'c4d16', 'CADVISOR_HOST': '172.17.42.1', 'CADVISOR_PORT': 9001 }, volumes=[
def WifiNet(): """ Create an Wifi network and add nodes to it. """ net = Mininet() info('*** Adding controller\n') net.addController('c0', controller=RemoteController, ip='127.0.0.1', port=6633) """ Initialize the WifiSegment, please refer ns3.py """ wifi = WifiSegment(standard=ns.wifi.WIFI_PHY_STANDARD_80211g) wifinodes = [] """ Initialize nodes """ for n in nodes: """ Get attributes """ nodename = n.get('name', None) nodetype = n.get('type', None) nodemob = n.get('mobility', None) nodepos = n.get('position', None) nodevel = n.get('velocity', None) nodeip = n.get('ip', None) """ Assign the addfunc, please refer Mininet for more details about addHost and addSwitch """ if nodetype is 'host': addfunc = net.addHost elif nodetype is 'switch': addfunc = net.addSwitch else: addfunc = None if nodename is None or addfunc is None: continue """ Add the node into Mininet """ node = addfunc(nodename, ip=nodeip) """ Set the mobility model """ mininet.ns3.setMobilityModel(node, nodemob) if nodepos is not None: mininet.ns3.setPosition(node, nodepos[0], nodepos[1], nodepos[2]) if nodevel is not None: mininet.ns3.setVelocity(node, nodevel[0], nodevel[1], nodevel[2]) """ Append the node into wifinodes """ wifinodes.append(node) """ Initialize Wifi Interfaces """ for wi in wifiintfs: """ Get attributes """ winodename = wi.get('nodename', None) witype = wi.get('type', None) wichannel = wi.get('channel', None) wissid = wi.get('ssid', None) """ Assign the addfunc, please refer the WifiSegment in ns3.py """ if witype is 'sta': addfunc = wifi.addSta elif witype is 'ap': addfunc = wifi.addAp else: addfunc = None if winodename is None or addfunc is None or wichannel is None: continue """ Get wifi node and add it to the TapBridge """ node = getWifiNode(wifinodes, winodename) addfunc(node, wichannel, wissid) """ Initialize Ehternet links between switches """ for cl in links: clnodename1 = cl.get('nodename1', None) clnodename2 = cl.get('nodename2', None) if clnodename1 is None or clnodename2 is None: continue clnode1 = getWifiNode(wifinodes, clnodename1) clnode2 = getWifiNode(wifinodes, clnodename2) if clnode1 is None or clnode2 is None: continue net.addLink(clnode1, clnode2) """ Enable Pcap output""" pcap = Pcap() pcap.enable() print pcap """ Enable netanim output""" anim = Netanim("/tmp/xml/wifi-wired-bridged4.xml", nodes) print anim """ Update node descriptions in the netanim """ for node in wifinodes: anim.UpdateNodeDescription(node.nsNode, str(node) + '-' + str(node.nsNode.GetId())) if isinstance(node, mininet.node.OVSSwitch): color = (0, 255, 0) elif isinstance(node, mininet.node.Host): color = (0, 0, 255) anim.UpdateNodeColor(node.nsNode, color[0], color[1], color[2]) """ Start the simulation """ info('*** Starting network\n') net.start() mininet.ns3.start() info('Testing network connectivity\n') wifinodes[0].cmdPrint('ping 10.10.10.2 -c 3') CLI(net) info('*** Stopping network\n') mininet.ns3.stop() info('*** mininet.ns3.stop()\n') mininet.ns3.clear() info('*** mininet.ns3.clear()\n') net.stop() info('*** net.stop()\n')
def WifiNet(): """ Create an Wifi network and add nodes to it. """ net = Mininet() info( '*** Adding controller\n' ) net.addController( 'c0', controller=RemoteController, ip='127.0.0.1', port=6633 ) """ Initialize the WifiSegment, please refer ns3.py """ wifi = WifiSegment(standard = ns.wifi.WIFI_PHY_STANDARD_80211g) wifinodes = [] """ Initialize nodes """ for n in nodes: """ Get attributes """ nodename = n.get('name', None) nodetype = n.get('type', None) nodemob = n.get('mobility', None) nodepos = n.get('position', None) nodevel = n.get('velocity', None) nodeip = n.get('ip', None) """ Assign the addfunc, please refer Mininet for more details about addHost and addSwitch """ if nodetype is 'host': addfunc = net.addHost elif nodetype is 'switch': addfunc = net.addSwitch else: addfunc = None if nodename is None or addfunc is None: continue """ Add the node into Mininet """ node = addfunc (nodename, ip=nodeip) """ Set the mobility model """ mininet.ns3.setMobilityModel (node, nodemob) if nodepos is not None: mininet.ns3.setPosition (node, nodepos[0], nodepos[1], nodepos[2]) if nodevel is not None: mininet.ns3.setVelocity (node, nodevel[0], nodevel[1], nodevel[2]) """ Append the node into wifinodes """ wifinodes.append (node) """ Initialize Wifi Interfaces """ for wi in wifiintfs: """ Get attributes """ winodename = wi.get('nodename', None) witype = wi.get('type', None) wichannel = wi.get('channel', None) wissid = wi.get('ssid', None) """ Assign the addfunc, please refer the WifiSegment in ns3.py """ if witype is 'sta': addfunc = wifi.addSta elif witype is 'ap': addfunc = wifi.addAp else: addfunc = None if winodename is None or addfunc is None or wichannel is None: continue """ Get wifi node and add it to the TapBridge """ node = getWifiNode (wifinodes, winodename) addfunc (node, wichannel, wissid) """ Initialize Ehternet links between switches """ for cl in links: clnodename1 = cl.get('nodename1', None) clnodename2 = cl.get('nodename2', None) if clnodename1 is None or clnodename2 is None: continue clnode1 = getWifiNode (wifinodes, clnodename1) clnode2 = getWifiNode (wifinodes, clnodename2) if clnode1 is None or clnode2 is None: continue net.addLink( clnode1, clnode2 ) """ Enable Pcap output""" pcap = Pcap() pcap.enable() print pcap """ Enable netanim output""" anim = Netanim("/tmp/xml/wifi-wired-bridged4.xml", nodes) print anim """ Update node descriptions in the netanim """ for node in wifinodes: anim.UpdateNodeDescription (node.nsNode, str(node) + '-' + str(node.nsNode.GetId())) if isinstance(node, mininet.node.OVSSwitch): color = (0, 255, 0) elif isinstance(node, mininet.node.Host): color = (0, 0, 255) anim.UpdateNodeColor (node.nsNode, color[0], color[1], color[2]) """ Start the simulation """ info( '*** Starting network\n' ) net.start() mininet.ns3.start() info( 'Testing network connectivity\n' ) wifinodes[0].cmdPrint( 'ping 10.10.10.2 -c 3' ) CLI( net ) info( '*** Stopping network\n' ) mininet.ns3.stop() info( '*** mininet.ns3.stop()\n' ) mininet.ns3.clear() info( '*** mininet.ns3.clear()\n' ) net.stop() info( '*** net.stop()\n' )