def setup(): topo = SingleSwitchTopo(k=4) net = Mininet(topo=topo, xterms=True) net.addNAT().configDefault() net.start() #neccessary for nat to work. controller = net.get('c0') #DISCO = controller.cmd('${ETCD_DISCOVERY:-$(curl https://discovery.etcd.io/new?size=3)}') DISCO = controller.cmd('curl https://discovery.etcd.io/new?size=3') print("DISCO %s" % DISCO) nodes = net.keys() print("nodes are %s" % nodes) for key in net.__iter__(): if 'h' in key: node = net.get(key) result = node.cmd('ifconfig') node.cmd('export ETCD_DISCOVERY=%s' % DISCO) print("node.cmd: %s" % node.cmd('echo $ETCD_DISCOVERY')) print(result) # h1 = net.get('h1') # result = h1.cmd('ifconfig') # print (result) CLI(net) #opens mn in terminal. Also is a kind of pause net.stop() #shuts everything down.
def setup(): topo = SingleSwitchTopo(k=15) net = Mininet(topo=topo, xterms=True) #net.addNAT().configDefault() net.start() #neccessary for nat to work. #------------------------------------------------------ # START LOCAL DISCOVERY #------------------------------------------------------ controller = net.get('c0') #DISCO = controller.cmd('${ETCD_DISCOVERY:-$(curl https://discovery.etcd.io/new?size=3)}') UUID = ((controller.cmd('uuidgen')).strip('\n')).strip('\r') print("UUID %s" % UUID, ) DISCO = "http://10.0.0.1:2379/v2/keys/discovery/" + UUID print("DISCO %s" % DISCO, ) with open('etcd.config', 'w') as f: f.write(DISCO) h1 = net.get('h1') setup_res = h1.cmd('./setupDisco.sh') print("setup_res %s" % setup_res) time.sleep(1) # need to give etcd cluster time to start. #------------------------------------------------------ # DEFINE SIZE OF INITIAL CLUSTER #------------------------------------------------------ if True: size = 11 cmd = "curl -X PUT " + DISCO + "/_config/size -d value=%s" % size print("cmd %s" % cmd) put_res = h1.cmd(cmd) print("put res %s" % put_res) result = h1.cmd("curl -X GET " + DISCO + "/_config/size") print("disco result: %s" % result) nodes = net.keys() print("nodes are %s" % nodes) i = 0 for key in net.__iter__(): if 'h' in key and key != 'h1' and i < size: node = net.get(key) print(node.cmd("./etcd-setup.sh ")) i = i + 1 # # # # h1 = net.get('h1') # # result = h1.cmd('ifconfig') # # print (result) CLI(net) #opens mn in terminal. Also is a kind of pause net.stop() #shuts everything down.
def test_verifying_mininet_hosts_in_onos_controller(self,switches=4): try: topo = LinearTopo(switches) net = Mininet( topo=topo) net.start() ctrl = net.addController( 'onos', controller=RemoteController, ip=self.controller, port=6653) for switch in net.switches: switch.start( [ctrl] ) log.info('mininet all the devices IDs %s'%net.keys()) log.info('mininet all the devices details %s'%net.values()) log.info('mininet all the devices information %s'%net.items()) response = net.pingAll() log.info('pingAll response is %s'%response) assert_equal(response, 0.0) self.cliEnter() hosts = json.loads(self.cli.hosts(jsonFormat = True)) log.info('Discovered hosts: %s' %hosts) assert_equal(len(hosts),switches) self.cliExit() except Exception as Error: log.info('Got unexpected error %s while creating topology'%Error) Cleanup.cleanup() raise Cleanup.cleanup()
# supress output of "sudo mn -c" command which cleans mininet with open(os.devnull, 'wb') as devnull: subprocess.check_call(['sudo', 'mn', '-c'], stdout=devnull, stderr=subprocess.STDOUT) tree = TreeTopo(depth=m, fanout=n) try: net = Mininet(topo=tree) except: cleanup() net = Mininet(topo=tree) print('Starting tree network') net.start() print('\nTree network started. Press ctrl+d to close CLI.\n') print('--Nodes--\n' + ' '.join(net.keys())) print('--Links--') for link in net.links: print('(%s,%s)' % (link.intf1.name.split('-')[0], link.intf2.name.split('-')[0])), print('\n') # Ping other hosts in parallel h1 = net.get('h1') print(h1.cmd('cat ips.txt | xargs -n 1 -I ^ -P 50 ping -c 4 ^')) CLI(net) print('Stopping network') net.stop() cleanup()
def main(): runstart = time() outdir = "%s/%s_%s" % (args.out, args.traffic, args.cong) if not os.path.exists(outdir): os.makedirs(outdir) workload = "" if args.traffic == 'web': workload = 'flows/websearch.txt' else: workload = 'flows/datamining.txt' # Setup topology if (args.topo == "fattree"): topo = FatTree(args.kary) else: topo = StarTopo(args.hosts) net = Mininet(topo=topo, link=TCLink) net.start() adjustSysSettings(args.cong, args.topo) if args.cong != "tcp": #add priority queuing to switch if needed switch = net.get('s0') deleteQDiscs(switch) addPriorityQDisc(switch) #debug #for intf in switch.intfList(): # print switch.cmd("tc qdisc show dev "+str(intf)) loadList = [x / 10.0 for x in range(1, 9)] hostList = makeHostList(net) #make list of host IP addresses print "Starting experiment with cong={}, workload={}".format( args.cong, args.traffic) #start receiver on every host for hostStr in net.keys(): if "h" in hostStr: host = net.get(hostStr) host.popen("sudo python receiver.py {} {} {}".format( 8000, args.cong, args.time), shell=True) for load in loadList: print "Running flows for load: {}".format(load) #start sender on every host senderList = [] for hostStr in net.keys(): if "h" in hostStr: host = net.get(hostStr) sender = Sender(host.IP(), workload, args.cong, hostList) with open("sender.pkl", "wb") as f: pickle.dump(sender, f, -1) sendProc = host.popen( "sudo python sender.py {} {} {} {}".format( load, args.time, outdir, args.hosts)) senderList.append(sendProc) for sendProc in senderList: sendProc.communicate() net.stop() resetSystem() print "Program for congestion control:%s, traffic type:%s completed in %.2fs" % ( args.cong, args.traffic, time() - runstart)