def iperfTopo(): topo = CustomTopo() net = Mininet(topo=topo, host=CPULimitedHost, link=TCLink, controller=OVSController) net.start() H1 = net.get('H1') H2 = net.get('H2') H3 = net.get('H3') H4 = net.get('H4') # Generation of TCP flow from clients (H1,H2) to servers (H3,H4) respectively def iperfH3H1(): h3 = H3.cmd('iperf -s &') print h3 h1 = H1.cmd('iperf -c 10.0.0.3 -t 20 -i 0.5') print h1 time.sleep(10) def iperfH4H2(): h4 = H4.cmd('iperf -s &') print h4 h2 = H2.cmd('iperf -c 10.0.0.4 -t 20 -i 0.5 ') print h2 t1 = threading.Thread(target=iperfH3H1, args=()) t2 = threading.Thread(target=iperfH4H2, args=()) t1.start() t2.start() t1.join() t2.join() net.stop()
def myNet(): #call(['sudo', 'mn', '-c']) britefile = sys.argv[1] if len(sys.argv) >=2 else None print "britefile:", britefile generateOps() topo = MyBriteTopo(britefile) remotecontroller = customConstructor(CONTROLLERS, "remote,ip=192.168.56.1") net = Mininet(topo = topo, controller=remotecontroller) net.start() #启动您的拓扑网络 for host in net.hosts: host.cmdPrint('route add default dev %s-eth0' %host.name) time.sleep(SLEEP_TIME) for i in range(len(operations)): if(operations[i] == 1): addhost = operationNodes[i] host = net.get(addhost) print "%s is ready to join" % addhost host.cmdPrint('iperf -s -u -B 224.0.55.55 &') time.sleep(ADD_SLEEP_T) else: removehost = operationNodes[i] host = net.get(removehost) print "%s is ready to leave and its last pid is %s" % (removehost, host.lastPid) cmd = "kill %s" % host.lastPid host.cmd(cmd) time.sleep(REMOVE_SLEEP_T) net.stop()
def run_experiment(num_hosts, application_path): """ Construct a mininet topology of num_hosts hosts running the Beehive application at application_path, run some benchmarking tests on it, and save the results to an output file. """ topo = TestTopo(n=num_hosts) net = Mininet(topo=topo, host=CPULimitedHost) net.start() h0 = net.get("h0") # Start the initial end host that all peers will connect to command = get_run_command(h0, 0, application_path) print("Executing {} on host {}...".format(command, 0)) h0.cmd(command) wait_for_hive(0) # Now start all the peers for i in range(1, num_hosts): host = net.get("h{}".format(i)) command = get_run_command(host, i, application_path, [h0]) print("Executing {} on host {}...".format(command, i)) host.cmd(command) # Wait for all peers to start for i in range(1, num_hosts): wait_for_hive(i) print("All hives started") # Run the experiment and save the results to a file hcon = net.get("hcon") hcon.cmd("python ./metric.py >> experimentStdout 2>> experimentStderr") net.stop()
def output(partIdx): """Uses the student code to compute the output for test cases.""" outputString = "" if partIdx == 0: # This is agPA2 "Set up link parameters" print "a. Setting link parameters" "--- core to aggregation switches" linkopts1 = {"bw": 50, "delay": "5ms"} "--- aggregation to edge switches" linkopts2 = {"bw": 30, "delay": "10ms"} "--- edge switches to hosts" linkopts3 = {"bw": 10, "delay": "15ms"} "Creating network and run simple performance test" print "b. Creating Custom Topology" topo = CustomTopo(linkopts1, linkopts2, linkopts3, fanout=3) print "c. Firing up Mininet" net = Mininet(topo=topo, link=TCLink) net.start() h1 = net.get("h1") h27 = net.get("h27") print "d. Starting Test" # Start pings outputString = h1.cmd("ping", "-c6", h27.IP()) print "e. Stopping Mininet" net.stop() return outputString.strip()
def main(): behavioral_model = os.path.join(sys.path[0], '../targets/switch/behavioral-model') topo = SingleSwitchTopo(behavioral_model) net = Mininet(topo=topo, host=P4Host, switch=OpenflowEnabledP4Switch, controller=None ) net.start() h1 = net.get('h1') h1.setARP("10.0.0.1", "00:aa:bb:00:00:00") h1.setDefaultRoute("dev eth0 via 10.0.0.1") h1.describe() h2 = net.get('h2') h2.setARP("10.0.1.1", "00:aa:bb:00:00:01") h2.setDefaultRoute("dev eth0 via 10.0.1.1") h2.describe() configure_switch() time.sleep(1) print "Ready !" CLI( net ) net.stop()
def main(): num_hosts = args.num_hosts topo = SingleSwitchTopo(args.behavioral_exe, args.thrift_port, num_hosts ) net = Mininet(topo = topo, host = P4Host, switch = P4Switch, controller = None, link=TCLink) net.start() sw_mac = ["00:aa:bb:00:00:%02x" % n for n in xrange(num_hosts)] sw_addr = ["10.0.%d.1" % n for n in xrange(num_hosts)] for n in xrange(num_hosts): h = net.get('h%d' % (n + 1)) h.setARP(sw_addr[n], sw_mac[n]) h.setDefaultRoute("dev eth0 via %s" % sw_addr[n]) for n in xrange(num_hosts): h = net.get('h%d' % (n + 1)) h.describe() sleep(1) print "Ready !" CLI( net ) net.stop()
def perfTest(): "Create network and run simple performance test" prm = myParam(n=200, data_size=200) print prm.n, prm.m, prm.data_size, prm.pipes topo = myTopo(prm.n, prm.m) net = Mininet(topo=topo, link=TCLink) net.start() print "Dumping host connections" dumpNodeConnections( net.hosts ) print "Dumping switch connections" dumpNodeConnections( net.switches ) #print "Testing network connectivity" #net.pingAll() print "Testing bandwidth under s1" h1, h2 = net.get('h1', 'h2') net.iperf((h1, h2)) print "Testing bandwidth across tree" h1, h2 = net.get('h1', 'h%d'%(prm.n+1)) net.iperf((h1, h2)) for p in (1, 2, 5, 10, 20): prm.pipes = p simTrans(net.hosts, prm) #CLI( net ) net.stop()
def test(): topo = DssTopo() net = Mininet(topo, link=TCLink) net.start() pIDs = pidList(net) # start iperf server net.get('h1').cmd('iperf3 -s > %sSrv.log &' % file_out) # make sure server has started time.sleep(1) start = time.time() net.get('h2').cmd('iperf3 -c 10.0.0.1 -t %s > %sBsl.log 2>&1' \ % (perf_time, file_out)) baseline_runtime = time.time() - start frozen_iperf = iperfThread(net, perf_time, file_out) frozen_iperf.start() time.sleep(1) start = time.time() for x in range(0, num_pause): pause(pIDs) time.sleep(interval) frozen_iperf.join() frozen_runtime = time.time() - start print "Runtime of baseline iperf = %f" % baseline_runtime print "Runtime of frozen iperf = %f" % frozen_runtime net.stop()
def output(partIdx): """Uses the student code to compute the output for test cases.""" outputString = '' if partIdx == 0: # This is m3a "Set up link parameters" print "a. Setting link parameters" "--- core to aggregation switches" linkopts1 = {'bw':50, 'delay':'5ms'} "--- aggregation to edge switches" linkopts2 = {'bw':30, 'delay':'10ms'} "--- edge switches to hosts" linkopts3 = {'bw':10, 'delay':'15ms'} "Creating network and run simple performance test" print "b. Creating Custom Topology" topo = CustomTopo(linkopts1, linkopts2, linkopts3, fanout=3) print "c. Firing up Mininet" net = Mininet(topo=topo, link=TCLink) net.start() h1 = net.get('h1') h27 = net.get('h27') print "d. Starting Test" # Start pings outputString = h1.cmd('ping', '-c6', h27.IP()) print "e. Stopping Mininet" net.stop() return outputString.strip()
def test(): topo = DssTopo() net = Mininet(topo, link=TCLink) net.start() pidList(net) global NPAUSE global NRESUME NPAUSE = 'sudo /home/vagrant/vTime/VirtualTimeKernel/test_virtual_time/freeze_all_procs -f -p %s'%pIDS NRESUME ='sudo /home/vagrant/vTime/VirtualTimeKernel/test_virtual_time/freeze_all_procs -u -p %s'%pIDS net.get('h1').cmd('iperf3 -s &') time.sleep(0.5) net.get('h2').cmd('iperf3 -c 10.0.0.1 -t 60 > %sbl.iperf 2>&1' % FileOut) ''' # net.get('h1').cmd('iperf3 -s &') net.get('h2').cmd('iperf3 -c 10.0.0.1 -t 60 > %svt.iperf 2>&1 &' % FileOut) for x in range(0,int(sys.argv[3])): print 'pausing' pause() time.sleep(stime) print 'resumed' ''' CLI(net) net.stop()
def sdnnet(opt): topo = SDNTopo() info( '*** Creating network\n' ) net = Mininet( topo=topo, controller=MyController, link=TCLink) host = [] for i in range (8): host.append(net.get( 'host%d' % i )) net.start() core_sw = [] for i in range (2): name_suffix = '%s' % NWID + '0c' + '%02d' % i net.get('sw' + name_suffix).attach('tap%s0' % NWID) for i in range (8): host[i].defaultIntf().setIP('192.168.10.10%d/24' % i) root = [] for i in range (8): root.append(net.get( 'root%d' % i )) for i in range (8): host[i].intf('host%d-eth1' % i).setIP('1.1.%d.1/24' % i) root[i].intf('root%d-eth0' % i).setIP('1.1.%d.2/24' % i) stopsshd () startsshds ( host ) if opt=="cli": CLI(net) stopsshd() net.stop()
def main(): """@todo: Docstring for main. :returns: @todo """ linkopts1 = dict(bw=1000, delay='1ms') linkopts2 = dict(bw=100, delay='5ms') linkopts3 = dict(bw=10, delay='50ms') fanout = 4 topo = CustomTopo(linkopts1, linkopts2, linkopts3, fanout) net = Mininet(topo = topo, link=TCLink) net.start() print "Dumping host connections" dumpNodeConnections(net.hosts) print "Testing network connectivity" h1 = net.get('h1') h27 = net.get('h27') print "Starting Test: ping h1 to h27" # Start pings outputString = h1.cmd('ping', '-c6', h27.IP()) print outputString print # print "Starting Test2: pingAll" # net.pingAll() net.stop()
def simpleTest(): "Create and test a simple network" topo = UnblancedTree() net = Mininet(topo, host=CPULimitedHost, link=TCLink) net.start() for srcHostNum in range(8) : srcHost = net.get('h%s' % (srcHostNum + 1)) # iperf_outfiles[ srcHostNum ] = '/tmp/iperf%s.out' % srcHostNum.name # iperf_errfiles[ srcHostNum ] = '/tmp/iperf%s.err' % srcHostNum.name for dstHostNum in range(8): if srcHostNum == dstHostNum: continue #tmp_out = 'h{param1}_ping_h{param2}.out'.format(param1 = srcHostNum + 1, param2 = dstHostNum + 1) #tmp_err = 'h{param1}_ping_h{param2}.err'.format(param1 = srcHostNum + 1, param2 = dstHostNum + 1) dstHost = net.get('h%s' % (dstHostNum + 1)) print 'Now! h{param1} ping h{param2}'.format(param1 = srcHostNum + 1, param2 = dstHostNum + 1) dstHost.cmdPrint('iperf -u -s &') #clientcmd = "iperf -u -c " + dstHost.IP() + " -b 15" srcHost.cmdPrint('iperf -u -c' , dstHost.IP(), ' -b 15000000 -l 500') print "\n\n\n" CLI(net) net.stop()
def required(x,y): topo = MyTopo(x, y) net = Mininet(topo,host=CPULimitedHost, link=TCLink) net.start() for i in xrange(y): for j in xrange(y): if (i+1)%2==0 and (j+1)%2==1: net.nameToNode["h"+str(i+1)].cmd("iptables -A OUTPUT -o h"+str(i+1)+"-eth0 -d 10.0.0."+ str(j+1)+" -j DROP") net.nameToNode["h"+str(j+1)].cmd("iptables -A OUTPUT -o h"+str(j+1)+"-eth0 -d 10.0.0."+ str(i+1)+" -j DROP") elif (i+1)%2==1 and (j+1)%2==0: net.nameToNode["h"+str(i+1)].cmd("iptables -A OUTPUT -o h"+str(i+1)+"-eth0 -d 10.0.0."+ str(j+1)+" -j DROP") net.nameToNode["h"+str(j+1)].cmd("iptables -A OUTPUT -o h"+str(j+1)+"-eth0 -d 10.0.0."+ str(i+1)+" -j DROP") net.pingAll() try: print "Testing bandwidth between h1 and h3" h1, h3 = net.get('h1', 'h3') net.iperf((h1, h3)) except: c=1 try: print "Testing bandwidth between h1 and h3" h4, h2 = net.get('h2', 'h4') net.iperf((h2, h4)) except: c=1 dumpNodeConnections(net.switches) CLI(net) net.stop()
def myNetwork(): net = Mininet( topo=None, build=False, ipBase='10.0.0.0/8') info( '*** Adding controller\n' ) info( '*** Add switches\n') s1 = net.addSwitch('s1', cls=OVSKernelSwitch, failMode='standalone') info( '*** Add hosts\n') 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') net.addLink(s1, h1) net.addLink(s1, h2) info( '*** Starting network\n') net.build() info( '*** Starting controllers\n') for controller in net.controllers: controller.start() info( '*** Starting switches\n') net.get('s1').start([]) info( '*** Post configure switches and hosts\n') CLI(net) net.stop()
def main(): num_hosts = args.num_hosts topo = SingleSwitchTopo(args.behavioral_exe, args.thrift_port, num_hosts ) net = Mininet(topo = topo, host = P4Host, switch = P4Switch, controller = None ) net.start() sw_mac = ["00:aa:bb:00:00:%02x" % n for n in xrange(num_hosts)] for n in xrange(num_hosts): h = net.get('h%d' % (n + 1)) for n in xrange(num_hosts): h = net.get('h%d' % (n + 1)) h.describe() sleep(1) print "Ready !" CLI( net ) net.stop()
def test(): topo = DssTopo() net = Mininet(topo, link=TCLink) net.start() pIDS = pidList(net) global NPAUSE global NRESUME NPAUSE = 'sudo /home/kd/VirtualTimeKernel/test_virtual_time/freeze_all_procs -f -p %s' % pIDS NRESUME = 'sudo /home/kd/VirtualTimeKernel/test_virtual_time/freeze_all_procs -u -p %s' % pIDS # skip ARP print(net.get('h1').cmd('ping -c 1 10.0.0.2')) info('\n*** Start baseline test ***\n') net.get('h1').cmd('ping -c %s 10.0.0.2 > %sBsl.log' % (ping_count, file_out)) info('\n*** Start freeze test ***\n') frozen_ping = pingThread(net, ping_count, file_out) frozen_ping.start() print "Schedule %d freeze" % num_pause for x in range(0, num_pause): pause() time.sleep(interval) frozen_ping.join() net.stop()
def project(choice, buffsize, destfile, segments): topo = router(choice) net = Mininet(topo=topo, link=TCLink) print('Starting network...') net.start() print('Network started!') h1 = net.get('h1') h2 = net.get('h2') h3 = net.get('h3') #the configuration of hosts h1.cmd('ifconfig h1-eth0 10.0.0.1 netmask 255.255.255.0') h2.cmd('ifconfig h2-eth0 10.0.0.2 netmask 255.255.255.0') h2.cmd('ifconfig h2-eth1 10.0.1.2 netmask 255.255.255.0') h3.cmd('ifconfig h3-eth0 10.0.1.3 netmask 255.255.255.0') h1.cmd('route add default gw 10.0.0.2') h3.cmd ('route add default gw 10.0.1.2') #Activating the forward mode at host B h2.cmd('sysctl net.ipv4.ip_forward=1') #ping between hosts print('ping h1 - > h3') print h1.cmd('ping -c5 10.0.1.3') #nc6 and tcpdump nc6TCPd(h1, h2, h3, transferSize(buffsize), destfile, segments) net.stop() print ('Network stopped!')
def perTest(): "Specify performance parameters for the links" # Between core and aggregation switches linkopts1 = dict(bw=10, delay='5ms', loss=1, max_queue_size=1000, use_htb=True) # Between aggregation and edge switches linkopts2 = dict(bw=10, delay='5ms', loss=1, max_queue_size=1000, use_htb=True) # Between edge switches and hosts linkopts3 = dict(bw=10, delay='5ms', loss=1, max_queue_size=1000, use_htb=True) "Create and test a simple network" topo = CustomTopo(linkopts1=linkopts1, linkopts2=linkopts2, linkopts3=linkopts3, fanout=2) net = Mininet(topo=topo, host=CPULimitedHost, link=TCLink) net.start() print "Dumping host connections" dumpNodeConnections(net.hosts) print "Testing network connectivity" net.pingAll() print "Testing bandwidth between h1 with h2, h3 and h5" h1, h2 = net.get('h1', 'h2') net.iperf( ( h1, h2 ) ) h1, h3 = net.get('h1', 'h3') net.iperf( ( h1, h3 ) ) h1, h5 = net.get('h1', 'h5') net.iperf( ( h1, h5 ) ) h1, h7 = net.get('h1', 'h7') net.iperf( ( h1, h7 ) ) net.stop()
def RunTest(): """TOPO""" topo = FatTreeTopo() topo.topoCreate(4,4,2,2,2) CONTROLLER_NAME = topo.crtlname CONTROLLER_IP = topo.crtlip CONTROLLER_PORT = topo.crtlport net = Mininet(topo=topo,build= False,link=TCLink, controller=None) time.sleep(1) net.addController( CONTROLLER_NAME,controller=RemoteController, ip=CONTROLLER_IP, port=CONTROLLER_PORT) net.start() dumpNodeConnections(net.hosts) net.pingAll() h1 = net.get('h000') h16 = net.get('h311') h2 = net.get('h001') h1.popen('iperf -s -u -i 1') h16.popen('iperf -s -u -i 1') h2.cmdPrint('iperf -c '+ h1.IP() + ' -u -t 10 -i 1 -b 100m') h2.cmdPrint('iperf -c '+ h16.IP() + ' -u -t 10 -i 1 -b 100m') CLI(net) net.stop()
def simpleTest(): "Create and test a simple network" outputString = '' "Set up link parameters" print "a. Setting link parameters" "--- core to aggregation switches" linkopts1 = {'bw':50, 'delay':'5ms'} "--- aggregation to edge switches" linkopts2 = {'bw':30, 'delay':'10ms'} "--- edge switches to hosts" linkopts3 = {'bw':10, 'delay':'15ms'} "Creating network and run simple performance test" print "b. Creating Custom Topology" topo = CustomTopo(linkopts1, linkopts2, linkopts3, fanout=3) print "c. Firing up Mininet" net = Mininet(topo=topo, link=TCLink) net.start() h1 = net.get('h1') h27 = net.get('h27') print "d. Starting Test" # Start pings outputString = h1.cmd('ping', '-c6', h27.IP()) print "e. Stopping Mininet" net.stop() print outputString.strip()
def perfTest(): "Create network and run simple performance test" topo =LinearTopo(k=Y) net =Mininet(topo=topo, host=CPULimitedHost, link=TCLink,controller=OVSController) count=1 for i in range(1,X+1,2): stri="h" stri2="127.0.0." stri2=stri2+str(count) count=count+1 stri=stri+str(i) hi=net.get(stri) hi.setIP(stri2,24) count=1 for i in range(2,X+1,2): stri="h" stri2="192.168.0." stri=stri+str(i) stri2=stri2+str(count) count=count+1 hi=net.get(stri) hi.setIP(stri2,29) net.start() print "Dumping host connections" dumpNodeConnections(net.hosts) print "Testing network connectivity" net.pingAll() net.stop()
def simpleTest(): linkopts1 = {'bw':50, 'delay':'5ms'} linkopts2 = {'bw':30, 'delay':'10ms'} linkopts3 = {'bw':10, 'delay':'15ms'} topo = CustomTopo(linkopts1, linkopts2, linkopts3, fanout=3) #topo = CustomTopo(fanout=3) print "c. Firing up Mininet" net = Mininet(topo=topo, link=TCLink) net.start() h1 = net.get('h1') h27 = net.get('h27') print "d. Starting Test" # Start pings outputString = h1.cmd('ping', '-c6', h27.IP()) print outputString print "d.bis Cli" CLI(net) print "e. Stopping Mininet" net.stop()
def run(): #clean previous run os.system("rm -f /tmp/*.pid logs/*") os.system("mn -c >/dev/null 2>&1") os.system("killall -9 zebra bgpd > /dev/null 2>&1") os.system("/etc/init.d/quagga restart") topo = BgpPoisoningTopo() net = Mininet( topo=topo ) net.start() for router in net.switches: router.cmd("sysctl -w net.ipv4.ip_forward=1") router.waitOutput() #Waiting (sleepytime) seconds for sysctl changes to take effect.. sleep(sleepytime) for R in ['R1','R2','R3','R4','R5','R6','R7']: net.get(R).initZebra("conf/zebra-%s.conf" % R) router.waitOutput() net.get(R).initBgpd("conf/bgpd-%s.conf" % R) router.waitOutput() CLI( net ) net.stop()
def test_L3EthStar(): topo = L3EthStar(add_attacker=True) net = Mininet( topo=topo, link=TCLink, listenPort=OF_MISC['switch_debug_port']) net.start() net.pingAll() n = L3_NODES for h in range(n - 2): key = 'plc%s' % (h + 1) plc = net.get(key) # get host obj reference by name ok_(plc.IP(), L1_PLCS_IP[key]) ok_(plc.MAC(), PLCS_MAC[key]) histn = net.get('histn') ok_(histn.IP(), L3_PLANT_NETWORK['histn']) ok_(histn.MAC(), OTHER_MACS['histn']) workstn = net.get('workstn') ok_(workstn.IP(), L3_PLANT_NETWORK['workstn']) ok_(workstn.MAC(), OTHER_MACS['workstn']) # alternative way to obtain IP and MAC # params = workstn.params net.stop()
def test(): topo = DssTopo() net = Mininet(topo, link=TCLink) net.start() pidList(net) global NPAUSE global NRESUME NPAUSE = 'sudo /home/vagrant/vTime/VirtualTimeKernel/test_virtual_time/freeze_all_procs -f -p %s'%pIDS NRESUME ='sudo /home/vagrant/vTime/VirtualTimeKernel/test_virtual_time/freeze_all_procs -u -p %s'%pIDS #block print(net.get('h1').cmd('ping -c 1 10.0.0.2')) net.get('h1').cmd('~/cosim/cosim/mininet/benchmarks/ping_mod/VirtualTimeKernel/iputils/ping -c 1000 10.0.0.2 > %sbl.test 2>&1 '% FileOut) ''' #dont block net.get('h1').cmd('ping -A -c 1000 10.0.0.2 > %svt.test 2>&1 &'% FileOut) for x in range(0,int(sys.argv[3])): print 'pausing' pause() time.sleep(stime) print 'resumed' ''' CLI(net) net.stop()
def perfTest(): "Create network and run perf test" linkopts1 = dict(bw=50, delay='5ms') #, loss=1, max_queue_size=1000, use_htb=True) linkopts2 = dict(bw=30, delay='10ms') #, loss=3, max_queue_size=2000, use_htb=True) linkopts3 = dict(bw=10, delay='15ms') #, loss=5, max_queue_size=3000, use_htb=True) topo = CustomTopo(linkopts1, linkopts2, linkopts3, fanout=3) net = Mininet(topo=topo, link=TCLink) net.start() """ print "Dump host connections" dumpNodeConnections(net.hosts) print "Testing network connectivity" net.pingAll() """ print "Testing bandwidth between h1 and h27" h1 = net.get('h1') h27 = net.get('h27') net.iperf((h1, h27)) outputString = h1.cmd('ping', '-c6', h27.IP()) print "output: " + outputString.strip() net.stop()
def test(): topo = DssTopo() net = Mininet(topo, link=TCLink) net.start() pidList(net) global NPAUSE global NRESUME NPAUSE = 'sudo /home/kd/VirtualTimeKernel/test_virtual_time/freeze_all_procs -f -p %s'%pIDS NRESUME ='sudo /home/kd/VirtualTimeKernel/test_virtual_time/freeze_all_procs -u -p %s'%pIDS #block print(net.get('h1').cmd('ping -c 1 10.0.0.2')) net.get('h1').cmd('ping -c 40 10.0.0.2 > %sbl.test'% FileOut) #dont block net.get('h1').cmd('/home/kd/VirtualTimeKernel/iputils/ping -c 40 -D 10.0.0.2 > %svt.test &'% FileOut) time.sleep(5) for x in range(0,int(sys.argv[3])): print 'pausing' pause() time.sleep(stime) print 'resumed' time.sleep(30) net.stop()
def myNetwork(): net = Mininet( topo=None, build=False, link=TCLink, ipBase='10.0.0.0/8') info( '*** Adding controller\n' ) c0=net.addController(name='c0', controller=RemoteController, ip='10.0.0.3', protocol='tcp', port=6653) info( '*** Add switches\n') s1 = net.addSwitch('s1', cls=OVSKernelSwitch, inband=True) s2 = net.addSwitch('s2', cls=OVSKernelSwitch, inband=True) s3 = net.addSwitch('s3', cls=OVSKernelSwitch, inband=True) s4 = net.addSwitch('s4', cls=OVSKernelSwitch, inband=True) info( '*** Add hosts\n') 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) h3 = net.addHost('h3', cls=Host, ip='10.0.0.3', defaultRoute=None) h4 = net.addHost('h4', cls=Host, ip='10.0.0.4', defaultRoute=None) h5 = net.addHost('h5', cls=Host, ip='10.0.0.5', defaultRoute=None) h6 = net.addHost('h6', cls=Host, ip='10.0.0.6', defaultRoute=None) h7 = net.addHost('h7', cls=Host, ip='10.0.0.7', defaultRoute=None) h8 = net.addHost('h8', cls=Host, ip='10.0.0.8', defaultRoute=None) info( '*** Add links\n') net.addLink(h1, s1) net.addLink(h2, s1) net.addLink(s1, s2,delay='100ms') net.addLink(h3, s2) net.addLink(h4, s2) net.addLink(s2, s3, delay='1000ms') net.addLink(h5, s3) net.addLink(h6, s3) net.addLink(s3, s4, delay='1000ms') net.addLink(h7, s4) net.addLink(h8, s4) info( '*** Starting network\n') net.build() info( '*** Starting controllers\n') for controller in net.controllers: controller.start() info( '*** Starting switches\n') net.get('s1').start(net.controllers) net.get('s2').start(net.controllers) net.get('s3').start(net.controllers) net.get('s4').start(net.controllers) info( '*** Post configure switches and hosts\n') CLI(net) net.stop()
def myNetwork(): net = Mininet(topo=None, build=False, ipBase='10.0.0.0/8') info('*** Adding controller\n') c0 = net.addController(name='c0', controller=RemoteController, ip='127.0.0.1', protocol='tcp', port=6633) info('*** Add switches\n') info('*** switches protocols') openFlowVersions = [] openFlowVersions.append('OpenFlow13') protoList = ",".join(openFlowVersions) switchParms = {} switchParms['protocols'] = protoList s1 = net.addSwitch('s1', cls=OVSKernelSwitch, **switchParms) s2 = net.addSwitch('s2', cls=OVSKernelSwitch, **switchParms) s3 = net.addSwitch('s3', cls=OVSKernelSwitch, **switchParms) s4 = net.addSwitch('s4', cls=OVSKernelSwitch, **switchParms) info('*** Add hosts\n') h1 = net.addHost('h1', cls=Host, ip='10.0.0.1', mac='B6:29:CE:E1:DB:51') h2 = net.addHost('h2', cls=Host, ip='10.0.0.2', mac='B6:29:CE:E1:DB:52') h3 = net.addHost('h3', cls=Host, ip='10.0.0.3', mac='B6:29:CE:E1:DB:53') h4 = net.addHost('h4', cls=Host, ip='10.0.0.4', mac='B6:29:CE:E1:DB:54') info('*** Add links\n') net.addLink(s1, s2) net.addLink(s2, s3) net.addLink(s3, s4) net.addLink(s4, s1) net.addLink(h1, s1) net.addLink(h2, s2) net.addLink(h3, s3) net.addLink(h4, s4) info('*** Starting network\n') net.build() info('*** Starting controllers\n') for controller in net.controllers: controller.start() info('*** Starting switches\n') net.get('s1').start([c0]) net.get('s2').start([c0]) net.get('s3').start([c0]) net.get('s4').start([c0]) info('*** Post configure switches and hosts\n') CLI(net) net.stop()
def build(self): h1 = self.addHost('h1') h2 = self.addHost('h2') h3 = self.addHost('h3') b1 = self.addHost('b1') self.addLink(h1, b1, bw=20) self.addLink(h2, b1, bw=10) self.addLink(h3, b1, bw=10) if __name__ == '__main__': check_scripts() topo = BroadcastTopo() net = Mininet(topo=topo, link=TCLink, controller=None) h1, h2, h3, b1 = net.get('h1', 'h2', 'h3', 'b1') h1.cmd('ifconfig h1-eth0 10.0.0.1/8') h2.cmd('ifconfig h2-eth0 10.0.0.2/8') h3.cmd('ifconfig h3-eth0 10.0.0.3/8') clearIP(b1) for h in [h1, h2, h3, b1]: h.cmd('./scripts/disable_offloading.sh') h.cmd('./scripts/disable_ipv6.sh') net.start() CLI(net) net.stop()
def myNetwork(): net = Mininet( topo=None, build=False, ipBase='10.0.0.0/8') info( '*** Adding controller\n' ) c0=net.addController(name='c0', controller=RemoteController, ip='127.0.0.1', protocol='tcp', port=6633) info( '*** Add switches\n') info('*** switches protocols') openFlowVersions = [] openFlowVersions.append('OpenFlow13') protoList = ",".join(openFlowVersions) switchParms={} switchParms['protocols'] = protoList s1 = net.addSwitch('s1', cls=OVSKernelSwitch, **switchParms) s2 = net.addSwitch('s2', cls=OVSKernelSwitch, **switchParms) s3 = net.addSwitch('s3', cls=OVSKernelSwitch, **switchParms) s4 = net.addSwitch('s4', cls=OVSKernelSwitch, **switchParms) s5 = net.addSwitch('s5', cls=OVSKernelSwitch, **switchParms) s6 = net.addSwitch('s6', cls=OVSKernelSwitch, **switchParms) s7 = net.addSwitch('s7', cls=OVSKernelSwitch, **switchParms) info( '*** Add hosts\n') h1_1 = net.addHost('h1_1', cls=Host, ip='10.0.1.1', mac='B6:29:CE:E1:DB:51', defaultRoute=None) h1_2 = net.addHost('h1_2', cls=Host, ip='10.0.1.2', mac='B6:29:CE:E1:DB:52', defaultRoute=None) h1_3 = net.addHost('h1_3', cls=Host, ip='10.0.1.3', mac='B6:29:CE:E1:DB:53', defaultRoute=None) h2_1 = net.addHost('h2_1', cls=Host, ip='10.0.2.1', mac='92:88:E9:9C:0D:81', defaultRoute=None) h2_2 = net.addHost('h2_2', cls=Host, ip='10.0.2.2', mac='92:88:E9:9C:0D:82', defaultRoute=None) h2_3 = net.addHost('h2_3', cls=Host, ip='10.0.2.3', mac='92:88:E9:9C:0D:83', defaultRoute=None) info( '*** Add links\n') net.addLink(s1, s2) net.addLink(s1, s6) net.addLink(s2, s5) net.addLink(s2, s7) net.addLink(s2, s4) net.addLink(s2, s3) net.addLink(s3, s6) net.addLink(s4, s6) net.addLink(s6, s5) net.addLink(s6, s7) #hosts links group 1 net.addLink(h1_1, s2) net.addLink(h1_2, s2) net.addLink(h1_3, s2) #hosts links group 2 net.addLink(h2_1, s6) net.addLink(h2_2, s6) net.addLink(h2_3, s6) info( '*** Starting network\n') net.build() info( '*** Starting controllers\n') for controller in net.controllers: controller.start() info( '*** Starting switches\n') net.get('s1').start([c0]) net.get('s2').start([c0]) net.get('s3').start([c0]) net.get('s4').start([c0]) net.get('s5').start([c0]) net.get('s6').start([c0]) net.get('s7').start([c0]) info( '*** Post configure switches and hosts\n') CLI(net) net.stop()
def bufferbloat(): if not os.path.exists(args.dir): os.makedirs(args.dir) os.system("sysctl -w net.ipv4.tcp_congestion_control=%s" % args.cong) # Cleanup any leftovers from previous mininet runs cleanup() topo = BBTopo() net = Mininet(topo=topo, host=CPULimitedHost, link=TCLink) net.start() # This dumps the topology and how nodes are interconnected through # links. dumpNodeConnections(net.hosts) # This performs a basic all pairs ping test. net.pingAll() # Start all the monitoring processes start_tcpprobe("cwnd.txt") start_ping(net) # TODO: Start monitoring the queue sizes. Since the switch I # created is "s0", I monitor one of the interfaces. Which # interface? The interface numbering starts with 1 and increases. # Depending on the order you add links to your network, this # number may be 1 or 2. Ensure you use the correct number. # qmon = start_qmon(iface='s0-eth2', outfile='%s/q.txt' % (args.dir)) # qmon = None # TODO: Start iperf, webservers, etc. iperf = Process(target=start_iperf, args=(net, )) ping = Process(target=start_ping, args=(net, )) web = Process(target=start_webserver, args=(net, )) iperf.start() ping.start() web.start() # Hint: The command below invokes a CLI which you can use to # debug. It allows you to run arbitrary commands inside your # emulated hosts h1 and h2. # # CLI(net) # TODO: measure the time it takes to complete webpage transfer # from h1 to h2 (say) 3 times. Hint: check what the following # command does: curl -o /dev/null -s -w %{time_total} google.com # Now use the curl command to fetch webpage from the webserver you # spawned on host h1 (not from google!) # Hint: have a separate function to do this and you may find the # loop below useful. start_time = time() h1 = net.get('h1') h2 = net.get('h2') downloads = [] curls = [] while True: # Downloading every 2 seconds so sleep for 2 seconds sleep(2) now = time() delta = now - start_time # Finishing 60 seconds if delta > args.time: break print("%.1fs left..." % (args.time - delta)) # Downloaded to h2, download time raw data appended to a list curls.append( h2.popen( 'curl -o /dev/null -s -w %%{time_total} %s/http/index.html' % h1.IP())) # Processing raw data of download time for curl in curls: download = curl.communicate()[0] downloads.append(float(download)) # Writing download data to a text file as floats for plotting purposes f = open("%s/download.txt" % args.dir, "w") f.writelines("%f\n" % download for download in downloads) f.close() # TODO: compute average (and standard deviation) of the fetch # times. You don't need to plot them. Just note it in your # README and explain. with open(os.path.join(args.dir, 'measurements.txt'), 'w') as f: f.write( "Average download time is %lf, standard deviation for download time is %lf\n" % (helper.avg(downloads), helper.stdev(downloads))) stop_tcpprobe() if qmon is not None: qmon.terminate() net.stop() # Ensure that all processes you create within Mininet are killed. # Sometimes they require manual killing. Popen("pgrep -f webserver.py | xargs kill -9", shell=True).wait()
self.addLink(s2, tor, port1=10, port2=2) if __name__ == '__main__': setLogLevel('debug') topo = VXLANTopo() net = Mininet(topo=topo, controller=None) net.start() c0 = net.addController(name='c0', controller=RemoteController, ip='127.0.0.1', port=6633) net.get('red1').setMAC('00:00:00:00:00:01') net.get('red2').setMAC('00:00:00:00:00:02') net.get('blue1').setMAC('00:00:00:00:00:01') net.get('blue2').setMAC('00:00:00:00:00:02') net.get('s1').start([c0]) net.get('s2').start([c0]) os.popen('ip addr add 192.168.10.1/16 dev s1-eth10') os.popen('ip addr add 192.168.20.1/16 dev s2-eth10') os.popen( 'ovs-vsctl set interface s1-eth10 type=vxlan option:remote_ip=192.168.20.1 option:key=flow' ) os.popen( 'ovs-vsctl set interface s2-eth10 type=vxlan option:remote_ip=192.168.10.1 option:key=flow' )
def myNetwork(): net = Mininet( topo=None, build=False, link=TCLink) info( '*** Adding controller\n' ) c0=net.addController(name='c0', controller=RemoteController, protocol='tcp', ip='127.0.0.1', port=6633) info( '*** Add switches\n') s1 = net.addSwitch('s1', cls=OVSKernelSwitch, protocols='OpenFlow13') s2 = net.addSwitch('s2', cls=OVSKernelSwitch, protocols='OpenFlow13') s3 = net.addSwitch('s3', cls=OVSKernelSwitch, protocols='OpenFlow13') s4 = net.addSwitch('s4', cls=OVSKernelSwitch, protocols='OpenFlow13') s5 = net.addSwitch('s5', cls=OVSKernelSwitch, protocols='OpenFlow13') s6 = net.addSwitch('s6', cls=OVSKernelSwitch, protocols='OpenFlow13') net.addLink('s1','s2',bw=10) net.addLink('s1','s3',bw=10) net.addLink('s1','s4',bw=10) net.addLink('s1','s5',bw=10) net.addLink('s2','s6',bw=10) net.addLink('s3','s6',bw=10) net.addLink('s4','s6',bw=10) net.addLink('s5','s6',bw=10) info( '*** Starting network\n') net.build() info( '*** Starting controllers\n') for controller in net.controllers: controller.start() info( '*** Starting switches\n') net.get('s1').start([c0]) net.get('s2').start([c0]) net.get('s3').start([c0]) net.get('s4').start([c0]) net.get('s5').start([c0]) net.get('s6').start([c0]) info( '*** Post configure switches and hosts\n') info( '*** Add interfaces to switch ***' ) _intf = Intf( 'eth0', node=s1 ) _intf = Intf( 'eth1', node=s1 ) _intf = Intf( 'eth2', node=s6 ) _intf = Intf( 'eth3', node=s6 ) call(['ovs-vsctl','add-port','s1','eth0']) call(['ovs-vsctl','add-port','s1','eth1']) call(['ovs-vsctl','add-port','s6','eth2']) call(['ovs-vsctl','add-port','s6','eth3']) CLI(net) net.stop()
class ExerciseRunner: """ Attributes: log_dir : string // directory for mininet log files pcap_dir : string // directory for mininet switch pcap files quiet : bool // determines if we print logger messages hosts : list<string> // list of mininet host names agents : list<string> // list of agent names, running as mininet hosts switches : dict<string, dict> // mininet host names and their associated properties links : list<dict> // list of mininet link properties switch_json : string // json of the compiled p4 example bmv2_exe : string // name or path of the p4 switch binary topo : Topo object // The mininet topology instance net : Mininet object // The mininet instance """ def logger(self, *items): if not self.quiet: print(' '.join(items)) def formatLatency(self, l): """ Helper method for parsing link latencies from the topology json. """ if isinstance(l, (str, unicode)): return l else: return str(l) + "ms" def __init__(self, topo_file, log_dir, pcap_dir, switch_json, bmv2_exe='simple_switch', quiet=False, cpu_port=None): """ Initializes some attributes and reads the topology json. Does not actually run the exercise. Use run_exercise() for that. Arguments: topo_file : string // A json file which describes the exercise's mininet topology. log_dir : string // Path to a directory for storing exercise logs pcap_dir : string // Ditto, but for mininet switch pcap files switch_json : string // Path to a compiled p4 json for bmv2 bmv2_exe : string // Path to the p4 behavioral binary quiet : bool // Enable/disable script debug messages """ self.quiet = quiet self.logger('Reading topology file.') with open(topo_file, 'r') as f: topo = json.load(f) self.hosts = topo['hosts'] self.switches = topo['switches'] self.links = self.parse_links(topo['links']) # Ensure all the needed directories exist and are directories for dir_name in [log_dir, pcap_dir]: if not os.path.isdir(dir_name): if os.path.exists(dir_name): raise Exception("'%s' exists and is not a directory!" % dir_name) os.mkdir(dir_name) self.log_dir = log_dir self.pcap_dir = pcap_dir self.switch_json = switch_json self.bmv2_exe = bmv2_exe self.cpu_port = cpu_port def run_exercise(self): """ Sets up the mininet instance, programs the switches, and starts the mininet CLI. This is the main method to run after initializing the object. """ # Initialize mininet with the topology specified by the config self.create_network() self.net.start() sleep(1) # some programming that must happen after the net has started self.program_hosts() self.program_switches() # wait for that to finish. Not sure how to do this better sleep(1) self.do_net_cli() # stop right after the CLI is exited self.net.stop() def parse_links(self, unparsed_links): """ Given a list of links descriptions of the form [node1, node2, latency, bandwidth] with the latency and bandwidth being optional, parses these descriptions into dictionaries and store them as self.links """ links = [] for link in unparsed_links: # make sure each link's endpoints are ordered alphabetically s, t, = link[0], link[1] if s > t: s, t = t, s link_dict = { 'node1': s, 'node2': t, 'latency': '0ms', 'bandwidth': None } if len(link) > 2: link_dict['latency'] = self.formatLatency(link[2]) if len(link) > 3: link_dict['bandwidth'] = link[3] if link_dict['node1'][0] == 'h': assert link_dict['node2'][ 0] == 's', 'Hosts should be connected to switches, not ' + str( link_dict['node2']) if link_dict['node2'][0] == 'c': assert link_dict['node1'][ 0] == 'a', 'Controller should be connected to agents, not ' + str( link_dict['node1']) links.append(link_dict) return links def create_network(self): """ Create the mininet network object, and store it as self.net. Side effects: - Mininet topology instance stored as self.topo - Mininet instance stored as self.net """ self.logger("Building mininet topology.") self.topo = ExerciseTopo(self.hosts, self.switches.keys(), self.links, self.log_dir, self.cpu_port) switchClass = configureP4Switch(sw_path=self.bmv2_exe, json_path=self.switch_json, log_console=True, pcap_dump=self.pcap_dir, cpu_port=self.cpu_port) self.net = Mininet(topo=self.topo, link=TCLink, host=P4Host, switch=switchClass, controller=None) #for sw_name in self.switches.keys(): #sw_obj = self.net.get(sw_name) #add a physical interface to the switch #Intf(name="{0}-eth7".format(sw_name), node=sw_obj, port=7) #sw_obj.addIntf() #makeIntfPair(name="{0}-eth7".format(sw_name)) def program_switches(self): """ If any command files were provided for the switches, this method will start up the CLI on each switch and use the contents of the command files as input. Assumes: - A mininet instance is stored as self.net and self.net.start() has been called. """ cli = 'simple_switch_CLI' #for sw_name, sw_dict in self.switches.iteritems(): # if 'cli_input' not in sw_dict: continue # # get the port for this particular switch's thrift server # sw_obj = self.net.get(sw_name) # thrift_port = sw_obj.thrift_port # # cli_input_commands = sw_dict['cli_input'] # self.logger('Configuring switch %s with file %s' % (sw_name, cli_input_commands)) # with open(cli_input_commands, 'r') as fin: # cli_outfile = '%s/%s_cli_output.log'%(self.log_dir, sw_name) # with open(cli_outfile, 'w') as fout: # subprocess.Popen([cli, '--thrift-port', str(thrift_port)], # stdin=fin, stdout=fout) print("currently programming the switch tables is not supported") def program_hosts(self): """ Adds static ARP entries and default routes to each mininet host. Assumes: - A mininet instance is stored as self.net and self.net.start() has been called. """ for host_name in self.topo.hosts(): h = self.net.get(host_name) h_iface = h.intfs.values()[0] link = h_iface.link sw_iface = link.intf1 if link.intf1 != h_iface else link.intf2 # phony IP to lie to the host about host_id = int(host_name[1:]) sw_ip = '10.0.%d.254' % host_id # Ensure each host's interface name is unique, or else # mininet cannot shutdown gracefully h.defaultIntf().rename('%s-eth0' % host_name) # static arp entries and default routes h.cmd('arp -i %s -s %s %s' % (h_iface.name, sw_ip, sw_iface.mac)) h.cmd('ethtool --offload %s rx off tx off' % h_iface.name) h.cmd('ip route add %s dev %s' % (sw_ip, h_iface.name)) h.setDefaultRoute("via %s" % sw_ip) def do_net_cli(self): """ Starts up the mininet CLI and prints some helpful output. Assumes: - A mininet instance is stored as self.net and self.net.start() has been called. """ for s in self.net.switches: s.describe() for h in self.net.hosts: h.describe() self.logger("Starting mininet CLI") # Generate a message that will be printed by the Mininet CLI to make # interacting with the simple switch a little easier. print('') print( '======================================================================' ) print('Welcome to the BMV2 Mininet CLI!') print( '======================================================================' ) print('Your P4 program is installed into the BMV2 software switch') print('and your initial configuration is loaded. You can interact') print('with the network using the mininet CLI below.') print('') if self.switch_json: print('To inspect or change the switch configuration, connect to') print( 'its CLI from your host operating system using this command:') print(' simple_switch_CLI --thrift-port <switch thrift port>') print('') print('To view a switch log, run this command from your host OS:') print(' tail -f %s/<switchname>.log' % self.log_dir) print('') print('To view the switch output pcap, check the pcap files in %s:' % self.pcap_dir) print(' for example run: sudo tcpdump -xxx -r s1-eth1.pcap') print('') CLI(self.net)
class Experimento: def __init__(self): self.net = None self.inputs = None def configureParams(self,ue): self.inputs = ue self.net = Mininet( controller=ue.getController(), switch=OVSSwitch, build=False, link=TCLink, topo = ue.getTopo() ) self.net.build() def getUnidadExperimental(self): return self.inputs def killTopo(self): subprocess.call(["mn", "-c"]) def killController(self): if self.inputs.getController() == 'ryu': for proc in psutil.process_iter(attrs=['pid', 'name']): if "ryu-manager" in proc.info['name']: os.kill(proc.info['pid'], 9) def startTest(self): self.net.start() def endTest(self): self.net.stop() def startCLI(self): CLI(self.net) def pingAllTest(self): #self.net.start() self.net.pingAll() #self.net.start() def pingMeasure(self, src_in = None, dst_in = None, veces = 4, intervalo = 1, filename = None): nodosClaves = self.inputs.obtenerNodosClaves() if filename == None: if src_in == None and dst_in == None: src = nodosClaves[1] dst = nodosClaves[2] #self.net.ping(src,dst) src = self.net.get(src) dst = self.net.get(dst) else: src = self.net.get(src_in) dst = self.net.get(dst_in) src.cmdPrint('ping -c',veces,'-i',intervalo,str(dst.IP())) else: if src_in == None and dst_in == None: src = nodosClaves[1] dst = nodosClaves[2] src = self.net.get(src) dst = self.net.get(dst) else: src = self.net.get(src_in) dst = self.net.get(dst_in) info("Starting Pings: %s ---> %s\n" % (str(src.IP()), str(dst.IP()))) logfile = open(filename, 'w') p = src.popen(['ping', str(dst.IP()), '-i', str(intervalo), '-c', str(veces)], stdout=PIPE) for line in p.stdout: logfile.write(line) p.wait() logfile.close() info("End pings ***\n") def iperfTest(self, src_in=None, dst_in=None, veces=4, filename=None): if filename == None: nodosClaves = self.inputs.obtenerNodosClaves() if src_in == None and dst_in == None: self.net.iperf() else: src = self.net.get(src_in) dst = self.net.get(dst_in) self.net.iperf([src, dst]) def iperfMeasure(self, src_in=None, dst_in=None, intervalo=1, tiempo = 10, filename = 'salida.log' ): nodosClaves = self.inputs.obtenerNodosClaves() if src_in == None and dst_in == None: src = nodosClaves[1] dst = nodosClaves[2] # self.net.ping(src,dst) src = self.net.get(src) dst = self.net.get(dst) else: src = self.net.get(src_in) dst = self.net.get(dst_in) logfile = open(filename, 'w') info("Starting Iperf: %s ---> %s\n" % (str(src.IP()), str(dst.IP()))) p1 = dst.popen(['iperf', '-s']) # Iniciando el servidor p2 = src.popen(['iperf', '-c', str(dst.IP()), '-i', str(intervalo), '-t ' + str(tiempo)], stdout=PIPE) for line in p2.stdout: logfile.write(line) p2.wait() logfile.close() info("*** End iperf measure ***\n")
def myNetwork(): net = Mininet(topo=None, build=False, ipBase='10.0.0.0/8') info('*** Adding controller\n') info('*** Add switches\n') s1 = net.addSwitch('s1', cls=OVSKernelSwitch, failMode='standalone') r3 = net.addHost('r3', cls=Node, ip='0.0.0.0') r3.cmd('sysctl -w net.ipv4.ip_forward=1') r4 = net.addHost('r4', cls=Node, ip='0.0.0.0') r4.cmd('sysctl -w net.ipv4.ip_forward=1') s2 = net.addSwitch('s2', cls=OVSKernelSwitch, failMode='standalone') info('*** Add hosts\n') h1 = net.addHost('h1', cls=Host, ip='172.30.0.101/16', defaultRoute=None) h2 = net.addHost('h2', cls=Host, ip='172.30.0.102/16', defaultRoute=None) h3 = net.addHost('h3', cls=Host, ip='192.168.0.101/24', defaultRoute=None) h4 = net.addHost('h4', cls=Host, ip='192.168.0.102/24', defaultRoute=None) info('*** Add links\n') net.addLink(h1, s1) net.addLink(s1, h2) net.addLink(h3, s2) net.addLink(s2, h4) net.addLink(r4, s2) net.addLink(r3, s1) net.addLink(r3, r4) info('*** Starting network\n') net.build() info('*** Starting controllers\n') for controller in net.controllers: controller.start() info('*** Starting switches\n') net.get('s1').start([]) net.get('s2').start([]) info('*** Post configure switches and hosts\n') r3.cmd('ifconfig r3-eth0 172.30.0.1 netmask 255.255.0.0 up') r3.cmd('ifconfig r3-eth1 10.0.0.1 netmask 255.0.0.0 up') r4.cmd('ifconfig r4-eth0 192.168.0.1 netmask 255.255.255.0 up') r4.cmd('ifconfig r4-eth1 10.0.0.2 netmask 255.0.0.0 up') h1.cmd('route add default gw 172.30.0.1') h2.cmd('route add default gw 172.30.0.1') h3.cmd('route add default gw 192.168.0.1') h4.cmd('route add default gw 192.168.0.1') #ZERBA #r3.cmd('zebra -f /etc/quagga/r3zebra.conf -d -z /tmp/r3zebra.api -i /tmp/r3zebra.interface') #time.sleep(1) #r4.cmd('zebra -f /etc/quagga/r4zebra.conf -d -z /tmp/r4zebra.api -i /tmp/r4zebra.interface') #OSPF #r3.cmd('ospfd -f /etc/quagga/r3_ospfd.conf -d -z /tmp/r3zebra.api -i /tmp/r3ospfd.interface') #r4.cmd('ospfd -f /etc/quagga/r4_ospfd.conf -d -z /tmp/r4zebra.api -i /tmp/r4ospfd.interface') #RIP #r3.cmd('ripd -f /etc/quagga/r3_ripd.conf -d -z /tmp/r3zebra.api -i /tmp/r3ripd.interface') #r4.cmd('ripd -f /etc/quagga/r4_ripd.conf -d -z /tmp/r4zebra.api -i /tmp/r4ripd.interface') r3.cmd('route add -net 172.30.0.0/16 gw 172.30.0.1') r3.cmd('route add -net 192.168.0.0/24 gw 10.0.0.2') #r3.cmd('route add -net 10.0.0.0/8 gw 10.10.0.1') r4.cmd('route add -net 192.168.0.0/24 gw 192.168.0.1') r4.cmd('route add -net 172.30.0.0/16 gw 10.0.0.1') #r4.cmd('route add -net 10.0.0.0/8 gw 10.10.0.2') CLI(net) net.stop() os.system('killall -9 ripd ospfd zebra') os.system('rm -f *api*') os.system('rm -f *interface*')
def start_topo(): controller = RemoteController('controller', '0.0.0.0', 6633) net = Mininet(topo=G5Topo(), host=CPULimitedHost, controller=controller, autoSetMacs=True, switch=OVSSwitch) #net.addController(controller) net.start() # Start DNS server net.get('ds1').cmd('python /var/dns.py 100.0.0.20 &') net.get('ds2').cmd('python /var/dns.py 100.0.0.21 &') net.get('ds3').cmd('python /var/dns.py 100.0.0.22 &') # Set the name server for all the hosts to the DNS loadbalancer IP address net.get('h1').cmd('echo "nameserver 100.0.0.25" >> /etc/resolv.conf &') net.get('ws1').cmd('cd /var/www/ ; python -m CGIHTTPServer 80 &') net.get('ws2').cmd('cd /var/www/ ; python -m CGIHTTPServer 80 &') net.get('ws3').cmd('cd /var/www/ ; python -m CGIHTTPServer 80 &') CLI(net) #======================================= Testing =======================================# log = open(LOG_FILE, 'w') #Test 1: PrZ_Hosts --- ping test from Pbz to PrZ log.write( '====================================================================================\n' ) log.write( 'Test 1: PrZ_Hosts --- ping test from PbZ to PrZ >>> Blocked by FW \n\n' ) log.write('h1 ping h3 \n' + net.get('h1').cmd('ping -c 2 10.0.0.50') + '\n') log.write('h1 ping h4 \n' + net.get('h1').cmd('ping -c 2 10.0.0.51') + '\n') log.write('h2 ping h3 \n' + net.get('h2').cmd('ping -c 2 10.0.0.50') + '\n') log.write('h2 ping h4 \n' + net.get('h2').cmd('ping -c 2 10.0.0.51') + '\n\n\n') #Test 2: PbZ_Hosts --- ping test from PrZ to PbZ log.write( '====================================================================================\n' ) log.write( 'Test 2: PbZ_Hosts --- ping test from PrZ to PbZ >>> Successful Through NAPT \n\n' ) log.write('h3 ping h1 \n' + net.get('h3').cmd('ping -c 2 100.0.0.10') + '\n') log.write('h3 ping h2 \n' + net.get('h3').cmd('ping -c 2 100.0.0.11') + '\n') log.write('h4 ping h1 \n' + net.get('h4').cmd('ping -c 2 100.0.0.10') + '\n') log.write('h4 ping h2 \n' + net.get('h4').cmd('ping -c 2 100.0.0.11') + '\n\n\n') #Test 3: ping hosts to LB2 log.write( '====================================================================================\n' ) log.write( 'Test 3: ping PbZ_Hosts and PrZ_Hosts -> LB2 >>> Successful \n\n') log.write('h1 ping LB2 \n' + net.get('h1').cmd('ping -c 3 100.0.0.45') + '\n') log.write('h2 ping LB2 \n' + net.get('h2').cmd('ping -c 3 100.0.0.45') + '\n') log.write('h3 ping LB2 \n' + net.get('h3').cmd('ping -c 3 100.0.0.45') + '\n') log.write('h4 ping LB2 \n' + net.get('h4').cmd('ping -c 3 100.0.0.45') + '\n\n\n') #Test 4: ping hosts to LB1 log.write( '====================================================================================\n' ) log.write( 'Test 4: ping PbZ_Hosts and PrZ_Hosts -> LB1 >>> Successful \n\n') log.write('h1 ping LB1 \n' + net.get('h1').cmd('ping -c 3 100.0.0.25') + '\n') log.write('h2 ping LB1 \n' + net.get('h2').cmd('ping -c 3 100.0.0.25') + '\n') log.write('h3 ping LB1 \n' + net.get('h3').cmd('ping -c 3 100.0.0.25') + '\n') log.write('h4 ping LB1 \n' + net.get('h4').cmd('ping -c 3 100.0.0.25') + '\n\n\n') #Test 5: ping hosts to DNS log.write( '====================================================================================\n' ) log.write( 'Test 5: ping PbZ_Hosts and PrZ_Hosts -> DNS >>> Blocked by LB1 \n\n' ) log.write('h1 ping ds1 \n' + net.get('h1').cmd('ping -c 2 100.0.0.20') + '\n') log.write('h1 ping ds2 \n' + net.get('h1').cmd('ping -c 2 100.0.0.21') + '\n') log.write('h1 ping ds3 \n' + net.get('h1').cmd('ping -c 2 100.0.0.22') + '\n') log.write('h2 ping ds1 \n' + net.get('h2').cmd('ping -c 2 100.0.0.20') + '\n') log.write('h2 ping ds2 \n' + net.get('h2').cmd('ping -c 2 100.0.0.21') + '\n') log.write('h2 ping ds3 \n' + net.get('h2').cmd('ping -c 2 100.0.0.22') + '\n') log.write('h3 ping ds1 \n' + net.get('h3').cmd('ping -c 2 100.0.0.20') + '\n') log.write('h3 ping ds2 \n' + net.get('h3').cmd('ping -c 2 100.0.0.21') + '\n') log.write('h3 ping ds3 \n' + net.get('h3').cmd('ping -c 2 100.0.0.22') + '\n') log.write('h4 ping ds1 \n' + net.get('h4').cmd('ping -c 2 100.0.0.20') + '\n') log.write('h4 ping ds2 \n' + net.get('h4').cmd('ping -c 2 100.0.0.21') + '\n') log.write('h4 ping ds3 \n' + net.get('h4').cmd('ping -c 2 100.0.0.22') + '\n\n\n') #Test 6: ping hosts to WS log.write( '====================================================================================\n' ) log.write( 'Test 6: ping PbZ_Hosts and PrZ_Hosts -> WS >>> Blocked by LB2 \n\n') log.write('h1 ping ws1 \n' + net.get('h1').cmd('ping -c 2 100.0.0.40') + '\n') log.write('h1 ping ws2 \n' + net.get('h1').cmd('ping -c 2 100.0.0.41') + '\n') log.write('h1 ping ws3 \n' + net.get('h1').cmd('ping -c 2 100.0.0.42') + '\n') log.write('h2 ping ws1 \n' + net.get('h2').cmd('ping -c 2 100.0.0.40') + '\n') log.write('h2 ping ws2 \n' + net.get('h2').cmd('ping -c 2 100.0.0.41') + '\n') log.write('h2 ping ws3 \n' + net.get('h2').cmd('ping -c 2 100.0.0.42') + '\n') log.write('h3 ping ws1 \n' + net.get('h3').cmd('ping -c 2 100.0.0.40') + '\n') log.write('h3 ping ws2 \n' + net.get('h3').cmd('ping -c 2 100.0.0.41') + '\n') log.write('h3 ping ws3 \n' + net.get('h3').cmd('ping -c 2 100.0.0.42') + '\n') log.write('h4 ping ws1 \n' + net.get('h4').cmd('ping -c 2 100.0.0.40') + '\n') log.write('h4 ping ws2 \n' + net.get('h4').cmd('ping -c 2 100.0.0.41') + '\n') log.write('h4 ping ws3 \n' + net.get('h4').cmd('ping -c 2 100.0.0.42') + '\n\n\n') #Test 7: DNS nslookup log.write( '====================================================================================\n' ) log.write( 'Test 7: PbZ_Hosts and PbZ_Hosts -> nslookup >>> DNS round-robin \n\n' ) log.write('h1 nslookup \n' + net.get('h1').cmd('nslookup kth.se 100.0.0.25') + '\n') log.write('h2 nslookup \n' + net.get('h2').cmd('nslookup kth.se 100.0.0.25') + '\n') log.write('h3 nslookup \n' + net.get('h3').cmd('nslookup kth.se 100.0.0.25') + '\n') log.write('h4 nslookup \n' + net.get('h4').cmd('nslookup kth.se 100.0.0.25') + '\n\n\n') #Test 8: WS echo log.write( '====================================================================================\n' ) log.write('Test 8: PbZ_Hosts and PbZ_Hosts -> echo \n\n') log.write('h1 echo \n' + net.get('h1').cmd('echo abs | netcat 100.0.0.45 80') + '\n') log.write('h2 echo \n' + net.get('h2').cmd('echo abs | netcat 100.0.0.45 80') + '\n') log.write('h3 echo \n' + net.get('h3').cmd('echo abs | netcat 100.0.0.45 80') + '\n') log.write('h4 echo \n' + net.get('h4').cmd('echo abs | netcat 100.0.0.45 80') + '\n\n\n') #Test 9: Test UDP connection log.write( '====================================================================================\n' ) log.write('Test 9: Test UDP connection \n\n') log.write('Open iperf h1 >>> Successful PrZ to PbZ \n' + net.get('h1').cmd('iperf -s -u -p 1053 &') + '\n') log.write('h3 iperf h1 \n' + net.get('h3').cmd('iperf -p 1053 -c 100.0.0.10 -u -t 1') + '\n') log.write('Open iperf h3 >>> Restricted PbZ to PrZ Blocked by NAPT \n' + net.get('h3').cmd('iperf -s -u -p 1053 &') + '\n') log.write('h1 iperf h3 \n' + net.get('h1').cmd('iperf -p 1053 -c 10.0.0.50 -u -t 1') + '\n') log.write('Open iperf ds1 >>> Successful Through LB1 \n' + net.get('ds1').cmd('iperf -s -u -p 53 &') + '\n') log.write('Open iperf ds2 >>> Successful Through LB1 \n' + net.get('ds2').cmd('iperf -s -u -p 53 &') + '\n') log.write('Open iperf ds3 >>> Successful Through LB1 \n' + net.get('ds3').cmd('iperf -s -u -p 53 &') + '\n') log.write('h2 iperf DNS \n' + net.get('h2').cmd('iperf -p 53 -c 100.0.0.25 -u -t 1') + '\n') log.write('h4 iperf DNS \n' + net.get('h4').cmd('iperf -p 53 -c 100.0.0.25 -u -t 1') + '\n\n\n') #Test 10: Test TCP connection log.write( '====================================================================================\n' ) log.write('Test 10: Test TCP connection \n\n') log.write('Open nc h2 >>> Successful PrZ to PbZ \n' + net.get('h2').cmd('nc -l 1080 &') + '\n') log.write('h4 nc h2 \n' + net.get('h4').cmd( 'nc -v -z -w 2 100.0.0.11 1080 &> /dev/null && echo "Up" || echo "Down"' ) + '\n') log.write('Open nc h4 >>> Restricted PbZ to PrZ Blocked by NAPT \n' + net.get('h4').cmd('nc -l 1080 &') + '\n') log.write('h2 nc h4 \n' + net.get('h2').cmd( 'nc -v -z -w 2 10.0.0.51 1080 &> /dev/null && echo "Up" || echo "Down"' ) + '\n') log.write('Open nc ws1 >>> Successful Through LB2 \n' + net.get('ws1').cmd('nc -l 80 &') + '\n') log.write('Open nc ws2 >>> Successful Through LB2 \n' + net.get('ws2').cmd('nc -l 80 &') + '\n') log.write('Open nc ws3 >>> Successful Through LB2 \n' + net.get('ws3').cmd('nc -l 80 &') + '\n') log.write('h2 nc DNS \n' + net.get('h2').cmd( 'nc -v -z -w 2 100.0.0.45 80 &> /dev/null && echo "Up" || echo "Down"') + '\n') log.write('h4 nc DNS \n' + net.get('h4').cmd( 'nc -v -z -w 2 100.0.0.45 80 &> /dev/null && echo "Up" || echo "Down"') + '\n\n\n') #Test 11: IDS HTTP PUT and POST Allowed log.write( '====================================================================================\n' ) log.write('Open Inspector \n' + net.get('insp').cmd('tcpdump -eni insp-eth0 -w insp.pcap &') + '\n\n') log.write('Test 11: IDS allows POST & PUT >>> Successful \n\n') log.write('h1 POST 100.0.0.45 \n' + net.get('h1').cmd('curl -X POST 100.0.0.45 &') + '\n') log.write('h3 POST 100.0.0.45 \n' + net.get('h3').cmd('curl -X POST 100.0.0.45 &') + '\n') log.write('h1 PUT 100.0.0.45 \n' + net.get('h1').cmd('curl -X PUT 100.0.0.45 &') + '\n') log.write('h3 PUT 100.0.0.45 \n' + net.get('h3').cmd('curl -X PUT 100.0.0.45 &') + '\n\n\n') #Test 12: IDS HTTP PUT Linux and SQL code injection Blocked log.write( '====================================================================================\n' ) log.write( 'Test 12: IDS Inspcts PUT >>> Linux and SQL code injection Blocked \n\n' ) log.write( 'h1 PUT cat /var/log/ 100.0.0.45 \n' + net.get('h1').cmd('curl -X PUT -d "cat /var/log/" 100.0.0.45 &') + '\n') log.write( 'h1 PUT cat /etc/passwd 100.0.0.45 \n' + net.get('h1').cmd('curl -X PUT -d "cat /etc/passwd" 100.0.0.45 &') + '\n') log.write('h1 PUT INSERT 100.0.0.45 \n' + net.get('h1').cmd('curl -X PUT -d "INSERT" 100.0.0.45 &') + '\n') log.write('h1 PUT UPDATE 100.0.0.45 \n' + net.get('h1').cmd('curl -X PUT -d "UPDATE" 100.0.0.45 &') + '\n') log.write('h1 PUT DELETE 100.0.0.45 \n' + net.get('h1').cmd('curl -X PUT -d "DELETE" 100.0.0.45 &') + '\n\n\n') #Test 13: IDS HTTP other Methods are Blocked log.write( '====================================================================================\n' ) log.write('Test 13: IDS Inspcts HTTP Methods >>> Blocked \n\n') log.write('h4 GET \n' + net.get('h4').cmd('curl -X GET 100.0.0.45 &') + '\n') log.write('h4 HEAD \n' + net.get('h4').cmd('curl -X HEAD 100.0.0.45 &') + '\n') log.write('h4 OPTIONS \n' + net.get('h4').cmd('curl -X OPTIONS 100.0.0.45 &') + '\n') log.write('h4 TRACE \n' + net.get('h4').cmd('curl -X TRACE 100.0.0.45 &') + '\n') log.write('h4 DELETE \n' + net.get('h4').cmd('curl -X DELETE 100.0.0.45 &') + '\n') log.write('h4 CONNECT \n' + net.get('h4').cmd('curl -X CONNECT 100.0.0.45 &') + '\n') net.stop()
pickle.dump(src_dest_to_next_hop, open("d1.p", "w")) pickle.dump(host_ip_to_host_name, open("d2.p", "w")) for host_idx in range(len(nx_topology.sender_to_receiver)): for idx in range(len(nx_topology.sender_to_receiver)): if host_idx == idx: continue if idx < 15: IP_to_MAC = "10.0.0.{} 00:00:00:00:00:{}".format( idx + 1, '0' + hex(idx + 1).split('x')[-1]) else: IP_to_MAC = "10.0.0.{} 00:00:00:00:00:{}".format( idx + 1, hex(idx + 1).split('x')[-1]) command_str = "sudo arp -s {}".format(IP_to_MAC) sender_host = net.get('h' + str(host_idx)) sender_host.cmd(command_str) ''' s_popens = {} c_popens = {} for host in net.hosts: s_popens[host] = host.popen("iperf -s -i 1 &") for sender in range(len(nx_topology.sender_to_receiver)): receiver = nx_topology.sender_to_receiver[sender] # int sender_host = net.get('h'+str(sender)) # host object receiver_host = net.get('h'+str(receiver)) # host object c_popens[sender_host] = host.popen("iperf -c {} -i 1 -t 10 &".format(receiver_host.IP())) # print "iperf -c {} -i 1 -t 60".format(receiver_host.IP()) # Monitor them and print output
def myNetwork(): net = Mininet( topo=None, build=False, ipBase='10.0.0.0/8') info( '*** Adding controller\n' ) info( '*** Add switches\n') s1 = net.addSwitch('s1', cls=OVSKernelSwitch, failMode='standalone') info( '*** Add hosts\n') server = net.addHost('server', cls=Host, ip='10.0.0.2', defaultRoute=None) cache = net.addHost('cache', cls=Host, ip='10.0.0.3', defaultRoute=None) h1 = net.addHost('h1', cls=Host, ip='10.0.0.1', defaultRoute=None) info( '*** Add links\n') net.addLink(s1, server) net.addLink(h1, s1) net.addLink(cache, s1) info( '*** Starting network\n') net.build() info( '*** Starting switches\n') net.get('s1').start([]) info( '*** Post configure switches and hosts\n') # set up directory h1, cache, server = setup_dir(h1, cache, server) # get directory dir_h1, dir_cache, dir_server = get_dir(h1, cache, server) # DEBUG: show dir print(dir_h1) print(dir_cache) print(dir_server) # open port 80 get data open_port(cache, server) time.sleep(1) # 1s #links link_host_cache = 'wget ' + '10.0.0.3/' link_cache_server = 'wget ' + '10.0.0.2/' # DEBUG: testing with input # request = raw_input('request file:') # full_link = link_cache_server + request # print(cache.cmd(full_link)) # DEBUG: random; get file name; get size # files = get_memmory_info(dir_server) # numberOfRequests = raw_input('Number of requests:') # for i in range(int(numberOfRequests)): # # unifrom # print(random.choice(files)) # # # get the size of memmory # get_memmory_size(dir_server) # DEBUG: delete file from cache_data # request = raw_input('request file:') # fp = os.path.join(dir_cache, request) # os.remove(fp) numberOfRequests = raw_input('Number of requests:') FIFO(h1, cache, server, dir_cache, dir_server, link_host_cache, link_cache_server, numberOfRequests) CLI(net) net.stop()
class ExerciseRunner: """ Attributes: log_dir : string // directory for mininet log files pcap_dir : string // directory for mininet switch pcap files quiet : bool // determines if we print logger messages hosts : list<string> // list of mininet host names switches : dict<string, dict> // mininet host names and their associated properties links : list<dict> // list of mininet link properties switch_json : string // json of the compiled p4 example bmv2_exe : string // name or path of the p4 switch binary topo : Topo object // The mininet topology instance net : Mininet object // The mininet instance host_mode: integer // IPv4/IPv6 specification """ def logger(self, *items): if not self.quiet: print(' '.join(items)) def formatLatency(self, l): """ Helper method for parsing link latencies from the topology json. """ if isinstance(l, (str, unicode)): return l else: return str(l) + "ms" def __init__(self, topo_file, log_dir, pcap_dir, switch_json, bmv2_exe='simple_switch', quiet=False, host_mode=4): """ Initializes some attributes and reads the topology json. Does not actually run the exercise. Use run_exercise() for that. Arguments: topo_file : string // A json file which describes the exercise's mininet topology. log_dir : string // Path to a directory for storing exercise logs pcap_dir : string // Ditto, but for mininet switch pcap files switch_json : string // Path to a compiled p4 json for bmv2 bmv2_exe : string // Path to the p4 behavioral binary quiet : bool // Enable/disable script debug messages """ self.quiet = quiet self.logger('Reading topology file.') with open(topo_file, 'r') as f: topo = json.load(f) self.hosts = topo['hosts'] self.switches = topo['switches'] self.links = self.parse_links(topo['links']) # Ensure all the needed directories exist and are directories for dir_name in [log_dir, pcap_dir]: if not os.path.isdir(dir_name): if os.path.exists(dir_name): raise Exception("'%s' exists and is not a directory!" % dir_name) os.mkdir(dir_name) self.log_dir = log_dir self.pcap_dir = pcap_dir self.switch_json = switch_json self.bmv2_exe = bmv2_exe # IPv4/6 self.host_mode = host_mode def run_exercise(self): """ Sets up the mininet instance, programs the switches, and starts the mininet CLI. This is the main method to run after initializing the object. """ # Initialize mininet with the topology specified by the config self.create_network() swobj = self.net.get('s1') Intf('enp0s3',node=swobj) self.net.start() sleep(1) # some programming that must happen after the net has started self.program_hosts() self.program_switches() # wait for that to finish. Not sure how to do this better sleep(1) ## Begin Scenario print '=====================================' print ' Start Controllers. Waiting 10s ' print '=====================================' sleep(10) print '=====================================' print ' Initializing.................. ' print '=====================================' h1 = self.net.hosts[0] s1, s2 = self.net.switches[0], self.net.switches[1] h1.cmd('dhclient h1-eth0') h1.cmd('sudo ethtool -K h1-eth0 gro off gso off tso off') s2.cmd('sudo ethtool -K s2-eth1 gro off gso off tso off') s2.cmd('sudo ethtool -K s2-eth2 gro off gso off tso off') s1.cmd('sudo ethtool -K s1-eth1 gro off gso off tso off') s1.cmd('sudo ethtool -K enp0s3 gro off gso off tso off') h1.cmd('ping -c10 8.8.8.8') h1.cmd('ping -c10 sbrc2010.inf.ufrgs.br') h1.cmd('cp logs/* results/before/scenario10/logs/') h1.cmd('../experiments/scripts/clean/clean_logs.sh') h1.cmd('../experiments/scripts/clean/clean_pcaps.sh') h1.cmd('../experiments/scripts/clean/clean_scenario10STD.sh') print '==========================================' print ' Scenario10 WGET - 256k' print '==========================================' h1.cmd('wget http://sbrc2010.inf.ufrgs.br/anais/data/pdf/minicursos.pdf --progress=dot:binary -o results/scenario10/STD-WGET-256k.txt') sleep(5) h1.cmd('cp logs/* results/scenario10/STD/logs/') h1.cmd('../experiments/scripts/clean/clean_logs.sh') h1.cmd('cp pcaps/* results/scenario10/STD/pcaps/') h1.cmd('../experiments/scripts/clean/clean_pcaps.sh') print '=====================================' print ' Ending.................. ' print '=====================================' ## End Scenario self.do_net_cli() # stop right after the CLI is exited self.net.stop() def parse_links(self, unparsed_links): """ Given a list of links descriptions of the form [node1, node2, latency, bandwidth] with the latency and bandwidth being optional, parses these descriptions into dictionaries and store them as self.links """ links = [] for link in unparsed_links: # make sure each link's endpoints are ordered alphabetically s, t, = link[0], link[1] if s > t: s,t = t,s link_dict = {'node1':s, 'node2':t, 'latency':'0ms', 'bandwidth':None, 'loss':None } if len(link) > 2: link_dict['latency'] = self.formatLatency(link[2]) if len(link) > 3: link_dict['bandwidth'] = link[3] if len(link) > 4: link_dict['loss'] = link[4] if link_dict['node1'][0] == 'h': assert link_dict['node2'][0] == 's', 'Hosts should be connected to switches, not ' + str(link_dict['node2']) links.append(link_dict) return links def create_network(self): """ Create the mininet network object, and store it as self.net. Side effects: - Mininet topology instance stored as self.topo - Mininet instance stored as self.net """ self.logger("Building mininet topology.") self.topo = ExerciseTopo(self.hosts, self.switches, self.links, self.log_dir,self.host_mode) """ retirada keys do switches """ switchClass = configureP4Switch( sw_path=self.bmv2_exe, json_path=self.switch_json, log_console=True, pcap_dump=self.pcap_dir) if self.host_mode is 4: self.net = Mininet(topo = self.topo, link = TCLink, host = P4Host, switch = switchClass, controller = None) if self.host_mode is 6: self.net = Mininet(topo = self.topo, link = TCLink, host = P4HostV6, switch = switchClass, controller = None) def program_switch_p4runtime(self, sw_name, sw_dict): """ This method will use P4Runtime to program the switch using the content of the runtime JSON file as input. """ sw_obj = self.net.get(sw_name) grpc_port = sw_obj.grpc_port device_id = sw_obj.device_id runtime_json = sw_dict['runtime_json'] self.logger('Configuring switch %s using P4Runtime with file %s' % (sw_name, runtime_json)) with open(runtime_json, 'r') as sw_conf_file: outfile = '%s/%s-p4runtime-requests.txt' %(self.log_dir, sw_name) p4runtime_lib.simple_controller.program_switch( addr='127.0.0.1:%d' % grpc_port, device_id=device_id, sw_conf_file=sw_conf_file, workdir=os.getcwd(), proto_dump_fpath=outfile) def program_switch_cli(self, sw_name, sw_dict): """ This method will start up the CLI and use the contents of the command files as input. """ cli = 'simple_switch_CLI' # get the port for this particular switch's thrift server sw_obj = self.net.get(sw_name) thrift_port = sw_obj.thrift_port cli_input_commands = sw_dict['cli_input'] self.logger('Configuring switch %s with file %s' % (sw_name, cli_input_commands)) with open(cli_input_commands, 'r') as fin: cli_outfile = '%s/%s_cli_output.log'%(self.log_dir, sw_name) with open(cli_outfile, 'w') as fout: subprocess.Popen([cli, '--thrift-port', str(thrift_port)], stdin=fin, stdout=fout) def program_switches(self): """ This method will program each switch using the BMv2 CLI and/or P4Runtime, depending if any command or runtime JSON files were provided for the switches. """ for sw_name, sw_dict in self.switches.iteritems(): if 'cli_input' in sw_dict: self.program_switch_cli(sw_name, sw_dict) if 'runtime_json' in sw_dict: self.program_switch_p4runtime(sw_name, sw_dict) def program_hosts(self): """ Adds static ARP entries and default routes to each mininet host. Assumes: - A mininet instance is stored as self.net and self.net.start() has been called. """ for host_name in self.topo.hosts(): h = self.net.get(host_name) h_iface = h.intfs.values()[0] link = h_iface.link sw_iface = link.intf1 if link.intf1 != h_iface else link.intf2 # phony IP to lie to the host about host_id = int(host_name[1:]) sw_ip = '10.0.%d.254' % host_id if self.host_mode is 6: sw_v6_ip = '1000::%d:1' % host_id # Ensure each host's interface name is unique, or else # mininet cannot shutdown gracefully h.defaultIntf().rename('%s-eth0' % host_name) # static arp entries and default routes h.cmd('arp -i %s -s %s %s' % (h_iface.name, sw_ip, sw_iface.mac)) h.cmd('ethtool --offload %s rx off tx off' % h_iface.name) h.cmd('ip route add %s dev %s' % (sw_ip, h_iface.name)) if self.host_mode is 6: h.cmd('ip -6 route add %s dev %s' % (sw_v6_ip, h_iface.name)) h.setDefaultRoute("via %s" % sw_ip) #if self.host_mode is 6: # h.setDefaultRoute("via %s" % sw_v6_ip) def do_net_cli(self): """ Starts up the mininet CLI and prints some helpful output. Assumes: - A mininet instance is stored as self.net and self.net.start() has been called. """ for s in self.net.switches: s.describe() for h in self.net.hosts: h.describe() self.logger("Starting mininet CLI") # Generate a message that will be printed by the Mininet CLI to make # interacting with the simple switch a little easier. print('') print('======================================================================') print('Welcome to the BMV2 Mininet CLI!') print('======================================================================') print('Your P4 program is installed into the BMV2 software switch') print('and your initial runtime configuration is loaded. You can interact') print('with the network using the mininet CLI below.') print('') if self.switch_json: print('To inspect or change the switch configuration, connect to') print('its CLI from your host operating system using this command:') print(' simple_switch_CLI --thrift-port <switch thrift port>') print('') print('To view a switch log, run this command from your host OS:') print(' tail -f %s/<switchname>.log' % self.log_dir) print('') print('To view the switch output pcap, check the pcap files in %s:' % self.pcap_dir) print(' for example run: sudo tcpdump -xxx -r s1-eth1.pcap') print('') if 'grpc' in self.bmv2_exe: print('To view the P4Runtime requests sent to the switch, check the') print('corresponding txt file in %s:' % self.log_dir) print(' for example run: cat %s/s1-p4runtime-requests.txt' % self.log_dir) print('') CLI(self.net)
def simpleTest(): "Create and test the network" topo = NewTopo(n=4) net = Mininet(topo=topo, link=TCLink, host=CPULimitedHost) print "Starting the network" net.start() print "Dumping host connections" dumpNodeConnections(net.hosts) print "TCP Performance rate" h1, h2 = net.get('h1', 'h2') h1, h3 = net.get('h1', 'h3') h1, h4 = net.get('h1', 'h4') h1, h5 = net.get('h1', 'h5') h1, h6 = net.get('h1', 'h6') h1, h7 = net.get('h1', 'h7') h1, h8 = net.get('h1', 'h8') h2, h3 = net.get('h2', 'h3') h2, h4 = net.get('h2', 'h4') h2, h5 = net.get('h2', 'h5') h2, h6 = net.get('h2', 'h6') h2, h7 = net.get('h2', 'h7') h2, h8 = net.get('h2', 'h8') h3, h4 = net.get('h3', 'h4') h3, h5 = net.get('h3', 'h5') h3, h6 = net.get('h3', 'h6') h3, h7 = net.get('h3', 'h7') h3, h8 = net.get('h3', 'h8') h4, h5 = net.get('h4', 'h5') h4, h6 = net.get('h4', 'h6') h4, h7 = net.get('h4', 'h7') h4, h8 = net.get('h4', 'h8') h5, h6 = net.get('h5', 'h6') h5, h7 = net.get('h5', 'h7') h5, h8 = net.get('h5', 'h8') h6, h7 = net.get('h6', 'h7') h6, h8 = net.get('h6', 'h8') h7, h8 = net.get('h7', 'h8') perfopts = dict(l4Type='TCP') net.iperf((h1, h2), l4Type='TCP') net.iperf((h1, h3), l4Type='TCP') net.iperf((h1, h4), l4Type='TCP') net.iperf((h1, h5), l4Type='TCP') net.iperf((h1, h6), l4Type='TCP') net.iperf((h1, h7), l4Type='TCP') net.iperf((h1, h8), l4Type='TCP') net.iperf((h2, h3), l4Type='TCP') net.iperf((h2, h4), l4Type='TCP') net.iperf((h2, h5), l4Type='TCP') net.iperf((h2, h6), l4Type='TCP') net.iperf((h2, h7), l4Type='TCP') net.iperf((h2, h8), l4Type='TCP') net.iperf((h3, h4), l4Type='TCP') net.iperf((h3, h5), l4Type='TCP') net.iperf((h3, h6), l4Type='TCP') net.iperf((h3, h7), l4Type='TCP') net.iperf((h3, h8), l4Type='TCP') net.iperf((h4, h5), l4Type='TCP') net.iperf((h4, h6), l4Type='TCP') net.iperf((h4, h7), l4Type='TCP') net.iperf((h4, h8), l4Type='TCP') net.iperf((h5, h6), l4Type='TCP') net.iperf((h5, h7), l4Type='TCP') net.iperf((h5, h8), l4Type='TCP') net.iperf((h6, h7), l4Type='TCP') net.iperf((h6, h8), l4Type='TCP') net.iperf((h7, h8), l4Type='TCP') net.stop()
def simpleTest(): os.system("sudo mysql -u root -p mysql < ./schema.sql") "Create and test a simple network" topo = SingleSwitchTopo(n=4) net = Mininet(topo, controller=partial(RemoteController, ip='127.0.0.1', port=6633)) net.start() net.pingAll() # Inintalize components sff = net.get('sff1') firewall = net.get('firewall') admin = net.get('admin') facebook = net.get('facebook') google = net.get('google') naver = net.get('naver') instagram = net.get('instagram') dpi = net.get('dpi') staff_1 = net.get('staff_1') staff_2 = net.get('staff_2') manager = net.get('manager') president = net.get('president') pkt_gen = net.get('pkt_gen') sff.cmd('../bin/sff sff1-eth0 > /tmp/sff.out &') firewall.cmd('cd ../NSF/Firewall; sudo make init') firewall.cmd('secu') firewall.cmd('sudo ../../bin/firewall firewall-eth0 > /tmp/firewall.out &') dpi.cmd('cd ../NSF/DPI; sudo make init') dpi.cmd('secu') dpi.cmd('sudo ../../bin/dpi dpi-eth0 > /tmp/dpi.out &') admin.cmd('cd ../SecurityController') admin.cmd('sudo service apache2 stop >> /tmp/webserver.out') admin.cmd('sudo service apache2 start >> /tmp/webserver.out') admin.cmd('sudo python server.py >> /tmp/webserver.out &') # In order to check flow rule facebook.cmd('../bin/ipPacketReceiver > /tmp/facebook.out &') google.cmd('../bin/ipPacketReceiver > /tmp/google.out &') naver.cmd('../bin/ipPacketReceiver > /tmp/naver.out &') instagram.cmd('../bin/ipPacketReceiver > /tmp/instagram.out &') staff_1.cmd('../bin/ipPacketReceiver > /tmp/staff_1.out &') staff_2.cmd('../bin/ipPacketReceiver > /tmp/staff_2.out &') manager.cmd('../bin/ipPacketReceiver > /tmp/manager.out &') president.cmd('../bin/ipPacketReceiver > /tmp/president.out &') # Wait server # sleep(3); # Start Packet Generation #packetGenerator.cmd('while true; do ../bin/ipPacketGenerator ', packetGenerator.IP(), destination.IP(), '; sleep 1; done > /tmp/generator.out &'); # Wait For a While # sleep(5); # Clear all program #packetGenerator.cmd('kill %while'); #sff.cmd('echo -n end', 'nc -4u -w1', sff.IP(),'8000'); #sff.cmd('wait', sffProcessID); CLI(net) # Stop Simulation net.stop()
#info('*** Starting Mininet *** \n') print '*** Starting Mininet *** \n' topo = RevocationTopo() net = Mininet(topo=topo, link=TCLink, controller=RemoteController) #info('*** Topology Created *** \n') print "*** Toplology Created*** \n" net.start() run("ovs-vsctl set bridge s1 protocols=OpenFlow13") #info('*** Running CLI *** \n') print "*** Running CLI *** \n" # if the nat1-eth2 interface needs to be created, uncomment below line. #net.get('nat1').cmd('echo "iface nat1-eth2 inet manual" >> /etc/network/interfaces ') print "*** Assigning IPs to nat1-eth1 and nat1-eth2 ***" net.get('nat1').cmd('ifconfig nat1-eth1 192.168.1.1') net.get('nat1').cmd('ifconfig nat1-eth2 192.168.2.1') ##IPTABLE Config print "*** Configuring IP Tables for nat1 (allowing second interface)." net.get('nat1').cmd('iptables -P INPUT ACCEPT') net.get('nat1').cmd('iptables -P OUTPUT ACCEPT') net.get('nat1').cmd('iptables -P FORWARD DROP') net.get('nat1').cmd('sysctl net.ipv4.ip_forward=0') net.get( 'nat1').cmd('iptables -A FORWARD -i nat1-eth1 -o nat1-eth0 -m state ' + '-state NEW,ESTABLISHED,RELATED -j ACCEPT') net.get( 'nat1').cmd('iptables -A FORWARD -i nat1-eth1 -o nat1-eth0 -m state ' + '--state NEW,ESTABLISHED,RELATED -j ACCEPT') net.get('nat1').cmd( 'iptables -A FORWARD -i nat1-eth0 -d 192.168.2.0/24 -j ACCEPT')
start_time = time.time() while time.time() - start_time < args.test_time: print("Link changed!") change_link_state() stable_time = random.randint(1, 10) time.sleep(stable_time) if __name__ == "__main__": if "log" not in os.listdir("."): os.mkdir("./log") single_topo = Single() net = Mininet(topo=single_topo, link=TCLink, controller=None) h1_addr, h2_addr = "10.0.0.1", "10.0.0.2" h1, h2 = net.get("h1", "h2") h1.cmd("ifconfig h1-eth0 " + h1_addr + "/8") h2.cmd("ifconfig h2-eth0 " + h2_addr + "/8") h1.cmd("sysctl net.ipv4.ip_forward=1") h2.cmd("sysctl net.ipv4.ip_forward=1") net.start() # h1.popen("python server.py -i " + h1_addr) # h2.popen("python client.py -i " + h1_addr + " -t " + str(args.test_time - 10)) CLI(net) t = thd.Thread(target=change_link_state_thread) # change link state print("Link state is changable!") t.start() t.join() net.stop()
h2 = self.addHost('h2') r3 = self.addHost('r3') r1 = self.addHost('r1') r2 = self.addHost('r2') self.addLink(h1, r1) self.addLink(r2, r1) self.addLink(r3, r2) self.addLink(r3, h2) if __name__ == '__main__': topo = RouterTopo() net = Mininet(topo=topo, controller=None) h1, h2, r1, r2, r3 = net.get('h1', 'h2', 'r1', 'r2', 'r3') h1.cmd('ifconfig h1-eth0 10.0.1.11/24') h2.cmd('ifconfig h2-eth0 10.0.4.22/24') h1.cmd('route add default gw 10.0.1.1') h2.cmd('route add default gw 10.0.4.1') for h in (h1, h2): h.cmd('./scripts/disable_offloading.sh') h.cmd('./scripts/disable_ipv6.sh') r1.cmd('ifconfig r1-eth0 10.0.1.1/24') r1.cmd('ifconfig r1-eth1 10.0.2.1/24') r2.cmd('ifconfig r2-eth0 10.0.2.2/24') r2.cmd('ifconfig r2-eth1 10.0.3.2/24') r3.cmd('ifconfig r3-eth0 10.0.3.1/24')
def myNetwork(): net = Mininet(topo=None, listenPort=4444, build=False, ipBase='10.0.0.0/8') info('*** Adding controller\n') c0 = net.addController(name='c0', controller=RemoteController, ip='127.0.0.1', protocol='tcp', port=2000) info('*** Add switches\n') s1 = net.addSwitch('s1', cls=OVSKernelSwitch) s2 = net.addSwitch('s2', cls=OVSKernelSwitch) Intf('enx403cfc016722', node=s2) info('*** Add hosts\n') h2 = net.addHost('h2', cls=Host, ip='10.0.0.2', defaultRoute='via 10.0.0.254') h1 = net.addHost('h1', cls=Host, ip='10.0.0.1', defaultRoute='via 10.0.0.254') h3 = net.addHost('h3', cls=Host, ip='10.0.0.3', defaultRoute='via 10.0.0.254') info('*** Add links\n') net.addLink(h1, s1) net.addLink(h2, s1) net.addLink(h3, s2) net.addLink(s1, s2) info('*** Starting network\n') net.build() info('*** Starting controllers\n') for controller in net.controllers: controller.start() info('*** Starting switches\n') net.get('s1').start([c0]) net.get('s2').start([c0]) info('*** Post configure switches and hosts\n') for h in net.hosts: print "disable ipv6" h.cmd("sysctl -w net.ipv6.conf.all.disable_ipv6=1") h.cmd("sysctl -w net.ipv6.conf.default.disable_ipv6=1") h.cmd("sysctl -w net.ipv6.conf.lo.disable_ipv6=1") for sw in net.switches: print "disable ipv6" sw.cmd("sysctl -w net.ipv6.conf.all.disable_ipv6=1") sw.cmd("sysctl -w net.ipv6.conf.default.disable_ipv6=1") sw.cmd("sysctl -w net.ipv6.conf.lo.disable_ipv6=1") print "Dumping host connections" dumpNodeConnections(net.hosts) #s2.cmd("brctl addbr bri1") #s2.cmd("brctl addif bri1 eth3") #s2.cmd("ip addr add 10.0.0.4/24 dev eth3") #s2.cmd("ifconfig bri1 up") #s2.cmd("ip route add default via 10.0.0.254 dev eth3") CLI(net) net.stop()
def topology(): net = Mininet( topo=None, build=False, ipBase='10.0.0.0/8', link=TCLink, ) info('*** Adding controller\n') c0 = net.addController(name='c1', controller=RemoteController, ip='127.0.0.1', protocol='tcp', port=6633) info('*** Add switches\n') s5 = net.addSwitch('s5', cls=OVSKernelSwitch) s3 = net.addSwitch('s3', cls=OVSKernelSwitch) s4 = net.addSwitch('s4', cls=OVSKernelSwitch) s6 = net.addSwitch('s6', cls=OVSKernelSwitch) s1 = net.addSwitch('s1', cls=OVSKernelSwitch) s2 = net.addSwitch('s2', cls=OVSKernelSwitch) info('*** Add hosts\n') h2 = net.addHost('h2', cls=Host, ip='10.0.0.2', defaultRoute=None) 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) h4 = net.addHost('h4', cls=Host, ip='10.0.0.4', defaultRoute=None) h5 = net.addHost('h5', cls=Host, ip='10.0.0.5', defaultRoute=None) h6 = net.addHost('h6', cls=Host, ip='10.0.0.6', defaultRoute=None) info('*** Add links\n') net.addLink(h1, s1, delay='5ms', bw=100) net.addLink(h2, s1, delay='5ms', bw=100) net.addLink(h3, s1, delay='5ms', bw=100) net.addLink(h4, s2, delay='5ms', bw=100) net.addLink(h5, s2, delay='5ms', bw=100) net.addLink(h6, s2, delay='5ms', bw=100) net.addLink(s2, s4, delay='10ms', bw=40) net.addLink(s2, s6, delay='50ms', bw=100) net.addLink(s1, s3, delay='10ms', bw=100) net.addLink(s1, s5, delay='70ms', bw=100) net.addLink(s5, s4, delay='100ms', bw=100) net.addLink(s5, s6, delay='80ms', bw=100) net.addLink(s3, s4, delay='10ms', bw=70) net.addLink(s3, s6, delay='10ms', bw=100) info('*** Starting network\n') net.build() info('*** Starting controllers\n') for controller in net.controllers: controller.start() info('*** Starting switches\n') net.get('s5').start([c0]) net.get('s3').start([c0]) net.get('s4').start([c0]) net.get('s6').start([c0]) net.get('s1').start([c0]) net.get('s2').start([c0]) info('*** Post configure switches and hosts\n') CLI(net) net.stop()
def build(self): h1 = self.addHost('h1') h2 = self.addHost('h2') h3 = self.addHost('h3') s1 = self.addHost('s1') self.addLink(h1, s1, bw=20) self.addLink(h2, s1, bw=10) self.addLink(h3, s1, bw=10) if __name__ == '__main__': topo = BroadcastTopo() net = Mininet(topo=topo, link=TCLink, controller=None) h1, h2, h3, s1 = net.get('h1', 'h2', 'h3', 's1') h1.cmd('ifconfig h1-eth0 10.0.0.1/8') h2.cmd('ifconfig h2-eth0 10.0.0.2/8') h3.cmd('ifconfig h3-eth0 10.0.0.3/8') clearIP(s1) for h in net.get('h1', 'h2', 'h3'): h.cmd('./disable_offloading.sh') for h in net.get('h1', 'h2', 'h3', 's1'): h.cmd('./disable_ipv6.sh') net.start() s1.cmd('./switch &') h2.cmd('iperf -s &') h3.cmd('iperf -s &')
def myNetwork(): net = Mininet( topo=None, build=False, ipBase='10.0.0.0/8') core_sw = [] dist_sw = [] aces_sw = [] h = [] core_num = 1 dist_num = 2 aces_num = 10 fanout_num = 10 info( '*** Adding controller ***\n' ) RYU=net.addController(name='RYU', controller=RemoteController, ip='127.0.0.1', protocol='tcp', port=6633) info( '*** Adding switches ***\n') #Adding core switches for i in range(core_num): switch_name = 's10' + str( i + 1 ) sw = net.addSwitch(switch_name, cls=OVSKernelSwitch) core_sw.append( sw ) #Adding distribution switches for i in range(dist_num): switch_name = 's20' + str( i + 1 ) sw = net.addSwitch(switch_name, cls=OVSKernelSwitch) dist_sw.append( sw ) #Adding access switches for i in range(aces_num): if i <= 8: switch_name = 's30' + str( i + 1 ) else: switch_name = 's3' + str( i +1 ) sw = net.addSwitch(switch_name, cls=OVSKernelSwitch) aces_sw.append( sw ) info( '*** Adding hosts ***\n') #Adding normal hosts for i in xrange(1,191): host_name = 'h' + str(i) ip_addr = '10.0.' + str((i/100)) + '.' + str((i%100)) hs = net.addHost(host_name,cls = Host,ip = ip_addr,defaultRoute=None) h.append( hs ) #Adding the special host "h291" hs = net.addHost('h191',cls = Host,ip = '10.0.1.91',defaultRoute=None) h.append( hs ) info( '*** Adding links ***\n') #Adding the special link between h291 and s101 net.addLink(core_sw[0],h[190]) #Adding links between core switches and distribution switches for i in range(core_num): for j in range(dist_num): net.addLink(core_sw[i],dist_sw[j]) #Adding links between distribution switches and access switches for i in range(dist_num): for j in range(5): net.addLink(dist_sw[i],aces_sw[i*5+ j]) #Adding links between access switche s301 and 100 normal hosts for i in range(100): net.addLink(aces_sw[0], h[i]) #Adding links between other access switches and ohter normal hosts for i in xrange(1,aces_num): for j in range(fanout_num): net.addLink(aces_sw[i], h[(i-1)*fanout_num+j+100]) info( '*** Starting network ***\n') net.build() info( '*** Starting controllers ***\n') for controller in net.controllers: controller.start() info( '*** Starting switches ***\n') for i in range(core_num): net.get(core_sw[i].name).start([RYU]) for i in range(dist_num): net.get(dist_sw[i].name).start([RYU]) for i in range(aces_num): net.get(aces_sw[i].name).start([RYU]) info( '*** Post configure switches and hosts ***\n') CLI(net) net.stop()
def myNetwork(): net = Mininet(topo=None, build=False, ipBase='10.0.0.0/8') info('*** Adding controller\n') c0 = net.addController(name='c0', controller=Controller, protocol='tcp', port=6633) info('*** Add switches\n') s8 = net.addSwitch('s8', cls=OVSKernelSwitch) s6 = net.addSwitch('s6', cls=OVSKernelSwitch) s4 = net.addSwitch('s4', cls=OVSKernelSwitch) s5 = net.addSwitch('s5', cls=OVSKernelSwitch) s3 = net.addSwitch('s3', cls=OVSKernelSwitch) s7 = net.addSwitch('s7', cls=OVSKernelSwitch) s2 = net.addSwitch('s2', cls=OVSKernelSwitch) s1 = net.addSwitch('s1', cls=OVSKernelSwitch) info('*** Add hosts\n') h7 = net.addHost('h7', cls=Host, ip='10.0.0.7', defaultRoute=None) h8 = net.addHost('h8', cls=Host, ip='10.0.0.8', defaultRoute=None) h5 = net.addHost('h5', cls=Host, ip='10.0.0.5', defaultRoute=None) 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) h4 = net.addHost('h4', cls=Host, ip='10.0.0.4', defaultRoute=None) h6 = net.addHost('h6', cls=Host, ip='10.0.0.6', defaultRoute=None) h2 = net.addHost('h2', cls=Host, ip='10.0.0.2', defaultRoute=None) info('*** Add links\n') net.addLink(s1, s3, 10) net.addLink(s1, s4, 10) net.addLink(s2, s3, 10) net.addLink(s2, s4, 10) net.addLink(s3, s5, 10) net.addLink(s3, s6, 10) net.addLink(s3, s7, 10) net.addLink(s3, s8, 10) net.addLink(s4, s8, 10) net.addLink(s4, s7, 10) net.addLink(s4, s6, 10) net.addLink(s4, s5, 10) net.addLink(s5, h1, 10) net.addLink(s5, h2, 10) net.addLink(s6, h3, 10) net.addLink(s6, h4, 10) net.addLink(s7, h5, 10) net.addLink(s7, h6, 10) net.addLink(s8, h7, 10) net.addLink(s8, h8, 10) info('*** Starting network\n') net.build() info('*** Starting controllers\n') for controller in net.controllers: controller.start() info('*** Starting switches\n') net.get('s8').start([]) net.get('s6').start([]) net.get('s4').start([]) net.get('s5').start([]) net.get('s3').start([]) net.get('s7').start([]) net.get('s2').start([c0]) net.get('s1').start([c0]) info('*** Post configure switches and hosts\n') CLI(net) net.stop()
args = parser.parse_args() if args.notmake == True: print('not make') else: os.system('make clean') if os.system('make') != 0: #if success,return 0 exit() print('Compile Success!!!') print('preparing for mininet...') topo = MyTopo() net = Mininet(topo=topo) print('net start') net.start() h1, h2, h3 = net.get('h1', 'h2', 'h3') print('h2 running') h2.cmd('./worker > h2.txt &') print('h3 running') h3.cmd('./worker > h3.txt &') print('h1 running') h1.cmd('xterm') CLI(net) net.stop() print('net stop\n') print('##################### h1.txt #####################') os.system('cat h1.txt') print('##################### h2.txt #####################')
#def Test(): setLogLevel('info') topo = MyTopo() net = Mininet(topo=topo, host=CPULimitedHost, link=TCLink, controller=OVSController) count = 1 for i in range(0, int(y), 2): str1 = "h" stri2 = "10.0.0." stri2 = stri2 + str(count) count = count + 1 str1 = str1 + str(i) hi = net.get(str1) hi.setIP(stri2, 24) for i in range(1, int(y), 2): str1 = "h" stri2 = "192.168.0." stri2 = stri2 + str(count) count = count + 1 str1 = str1 + str(i) hi = net.get(str1) hi.setIP(stri2, 29) net.start() dumpNodeConnections(net.hosts) net.pingAll() net.stop()
r2 = self.addHost('r2') r3 = self.addHost('r3') r4 = self.addHost('r4') self.addLink(h1, r1) self.addLink(r1, r2) self.addLink(r2, r3) self.addLink(r3, r4) self.addLink(r4, h2) if __name__ == '__main__': topo = RouterTopo() net = Mininet(topo=topo, controller=None) h1, r1, r2, r3, r4, h2 = net.get('h1', 'r1', 'r2', 'r3', 'r4', 'h2') h1.cmd('ifconfig h1-eth0 10.0.1.11/24') h2.cmd('ifconfig h2-eth0 10.0.5.11/24') h1.cmd('route add default gw 10.0.1.1') h2.cmd('route add default gw 10.0.5.1') for h in (h1, h2): h.cmd('./scripts/disable_offloading.sh') h.cmd('./scripts/disable_ipv6.sh') r1.cmd('ifconfig r1-eth0 10.0.1.1/24') r1.cmd('ifconfig r1-eth1 10.0.2.1/24') r1.cmd( 'route add -net 10.0.5.0 netmask 255.255.255.0 gw 10.0.2.2 dev r1-eth1' )
def myNetwork(): net = Mininet(topo=None, build=False, ipBase='10.0.0.0/8') info('*** Adding controller\n') c0 = net.addController(name='c0', controller=RemoteController, ip='172.17.0.3', protocol='tcp', port=6653) info('*** Add switches/APs\n') s1 = net.addSwitch('s1', cls=OVSKernelSwitch) s2 = net.addSwitch('s2', cls=OVSKernelSwitch) s3 = net.addSwitch('s3', cls=OVSKernelSwitch) s4 = net.addSwitch('s4', cls=OVSKernelSwitch) s6 = net.addSwitch('s6', cls=OVSKernelSwitch) s7 = net.addSwitch('s7', cls=OVSKernelSwitch) s8 = net.addSwitch('s8', cls=OVSKernelSwitch) s9 = net.addSwitch('s9', cls=OVSKernelSwitch) s5 = net.addSwitch('s5', cls=OVSKernelSwitch) s10 = net.addSwitch('s10', cls=OVSKernelSwitch) info('*** Add hosts/stations\n') h13 = net.addHost('h13', cls=Host, ip='10.0.0.13', defaultRoute=None) h19 = net.addHost('h19', cls=Host, ip='10.0.0.19', defaultRoute=None) h29 = net.addHost('h29', cls=Host, ip='10.0.0.29', defaultRoute=None) h12 = net.addHost('h12', cls=Host, ip='10.0.0.12', defaultRoute=None) h11 = net.addHost('h11', cls=Host, ip='10.0.0.11', defaultRoute=None) h31 = net.addHost('h31', cls=Host, ip='10.0.0.31', defaultRoute=None) h10 = net.addHost('h10', cls=Host, ip='10.0.0.10', defaultRoute=None) h20 = net.addHost('h20', cls=Host, ip='10.0.0.20', defaultRoute=None) h21 = net.addHost('h21', cls=Host, ip='10.0.0.21', defaultRoute=None) h26 = net.addHost('h26', cls=Host, ip='10.0.0.26', defaultRoute=None) h3 = net.addHost('h3', cls=Host, ip='10.0.0.3', defaultRoute=None) h23 = net.addHost('h23', cls=Host, ip='10.0.0.23', defaultRoute=None) h4 = net.addHost('h4', cls=Host, ip='10.0.0.4', defaultRoute=None) h24 = net.addHost('h24', cls=Host, ip='10.0.0.24', defaultRoute=None) h5 = net.addHost('h5', cls=Host, ip='10.0.0.5', defaultRoute=None) h2 = net.addHost('h2', cls=Host, ip='10.0.0.2', defaultRoute=None) h25 = net.addHost('h25', cls=Host, ip='10.0.0.25', defaultRoute=None) h33 = net.addHost('h33', cls=Host, ip='10.0.0.33', defaultRoute=None) h34 = net.addHost('h34', cls=Host, ip='10.0.0.34', defaultRoute=None) h22 = net.addHost('h22', cls=Host, ip='10.0.0.22', defaultRoute=None) h14 = net.addHost('h14', cls=Host, ip='10.0.0.14', defaultRoute=None) h28 = net.addHost('h28', cls=Host, ip='10.0.0.28', defaultRoute=None) h15 = net.addHost('h15', cls=Host, ip='10.0.0.15', defaultRoute=None) h30 = net.addHost('h30', cls=Host, ip='10.0.0.30', defaultRoute=None) h27 = net.addHost('h27', cls=Host, ip='10.0.0.27', defaultRoute=None) h32 = net.addHost('h32', cls=Host, ip='10.0.0.32', defaultRoute=None) h16 = net.addHost('h16', cls=Host, ip='10.0.0.16', defaultRoute=None) h9 = net.addHost('h9', cls=Host, ip='10.0.0.9', defaultRoute=None) h17 = net.addHost('h17', cls=Host, ip='10.0.0.17', defaultRoute=None) h18 = net.addHost('h18', cls=Host, ip='10.0.0.18', defaultRoute=None) h1 = net.addHost('h1', cls=Host, ip='10.0.0.1', defaultRoute=None) info('*** Add links\n') net.addLink(s2, s1) net.addLink(s1, s3) net.addLink(s3, s4) net.addLink(s2, s4) net.addLink(s4, s6) net.addLink(s6, s5) net.addLink(s4, s5) net.addLink(s6, s8) net.addLink(s8, s7) net.addLink(s5, s7) net.addLink(s7, s9) net.addLink(s9, s10) net.addLink(s8, s10) net.addLink(s8, s9) net.addLink(h1, s1) net.addLink(h2, s2) net.addLink(h4, s6) net.addLink(h3, s5) net.addLink(h5, s8) net.addLink(h25, s1) net.addLink(h14, s1) net.addLink(h26, s1) net.addLink(h13, s10) net.addLink(s10, h24) net.addLink(s10, h32) net.addLink(h31, s9) net.addLink(h12, s9) net.addLink(h23, s9) net.addLink(s7, h11) net.addLink(s7, h29) net.addLink(s7, h22) net.addLink(h30, s7) net.addLink(h10, s8) net.addLink(h21, s8) net.addLink(h19, s5) net.addLink(s5, h27) net.addLink(s6, h28) net.addLink(s6, h20) net.addLink(h9, s3) net.addLink(h18, s3) net.addLink(h17, s3) net.addLink(h15, s2) net.addLink(s2, h16) net.addLink(h34, s5) net.addLink(h33, s6) info('*** Starting network\n') net.build() info('*** Starting controllers\n') for controller in net.controllers: controller.start() info('*** Starting switches/APs\n') net.get('s1').start([c0]) net.get('s2').start([c0]) net.get('s3').start([c0]) net.get('s4').start([c0]) net.get('s6').start([c0]) net.get('s7').start([c0]) net.get('s8').start([c0]) net.get('s9').start([c0]) net.get('s5').start([c0]) net.get('s10').start([c0]) info('*** Post configure nodes\n') CLI(net) net.stop()
class SwitchingTopo(Topo): def build(self): h1 = self.addHost('h1') h2 = self.addHost('h2') h3 = self.addHost('h3') s1 = self.addHost('s1') self.addLink(h1, s1, bw=20) self.addLink(h2, s1, bw=10) self.addLink(h3, s1, bw=10) if __name__ == '__main__': topo = SwitchingTopo() net = Mininet(topo = topo, link = TCLink, controller = None) h1, h2, h3, s1 = net.get('h1', 'h2', 'h3', 's1') h1.cmd('ifconfig h1-eth0 10.0.0.1/24') h2.cmd('ifconfig h2-eth0 10.0.0.2/24') h3.cmd('ifconfig h3-eth0 10.0.0.3/24') clearIP(s1) h1.cmd('./disable_offloading.sh') h2.cmd('./disable_offloading.sh') h3.cmd('./disable_offloading.sh') h1.cmd('./disable_ipv6.sh') h2.cmd('./disable_ipv6.sh') h3.cmd('./disable_ipv6.sh') net.start() CLI(net)
def quic_exchange(): dumbbell = DumbbellTopo() network = Mininet(topo=dumbbell, host=CPULimitedHost, link=TCLink, autoPinCpus=True) network.start() dumpNodeConnections(network.hosts) network.pingAll() #crossClient = network.get('cClient') #crossServer = network.get('cServer') appClient = network.get('aClient') appServer = network.get('aServer') # disable offloading - when enabled, permits segments larger than 1500 bytes #crossClient.cmd('ethtool -K ' + str(crossClient.intf()) + ' gso off') #crossServer.cmd('ethtool -K ' + str(crossServer.intf()) + ' gso off') appClient.cmd('ethtool -K ' + str(appClient.intf()) + ' gso off') appServer.cmd('ethtool -K ' + str(appServer.intf()) + ' gso off') #appClient.cmd('echo `ping', appServer.IP(), ' > vagrant_data/client-sent-ping`') #appServer.cmd('echo `ping', appClient.IP(), ' > vagrant_data/server-sent-ping`') #appServer.cmd('./vagrant/quiche/examples/server ', appServer.IP(), ' 5006 >> vagrant_data/quic-server') #for i in range(5): #appClient.cmd('./vagrant/quiche/examples/client ', appServer.IP(), ' 5006 >> vagrant_data/quic-client') #time.sleep(1) #appServer.cmd('./ngtcp2/examples/server -b 3 -t 0.1 -l 100 -i 3000 -q -f 60 ' + appServer.IP() + ' 5004 ngtcp2/test-ca/rsa/ca.key ngtcp2/test-ca/rsa/ca.cert > ngtcp2/datasets/PARTIAL_3B_10L_100F_2000D_60R_server.txt &') #pid = int( appServer.cmd('./ngtcp2/examples/server -b 3 -t 0.1 -l 100 -i 3000 -q -f 60 ' + appServer.IP() + ' 5004 ngtcp2/test-ca/rsa/ca.key ngtcp2/test-ca/rsa/ca.cert > ngtcp2/datasets/PARTIAL_3B_10L_18000F_2000D_60R_server.txt') ) #appServer.cmd('wait', pid) #appServer.cmd('./home/mininet/quic_data/mininet/ngtcp2/examples/server -b 3 -t 0.1 -l 100 -i 3000 -q -f 60 ', appServer.IP(), ' 5004 ../test-ca/rsa/ca.key test-ca/rsa/ca.cert') #appServer.cmd('echo "hi" >> foo.txt') #appServer.cmd('sudo ./ngtcp2/datasets/generate_data_server.sh ' + appServer.IP() + ' &') #print("server command run") #print('sudo ./ngtcp2/datasets/generate_data_server.sh ' + appServer.IP() + ' &') #appServer.cmd('./ngtcp2/examples/server -b 3 -l 18000 -i 3000 -q -f 60 ', appServer.IP(), ' 5004 ngtcp2/test-ca/rsa/ca.key ngtcp2/test-ca/rsa/ca.cert > ngtcp2/datasets/PARTIAL_3B_0L_18000F_2000D_60R_server.txt &') #for i in range(5): #appClient.cmd('./ngtcp2/examples/client -b 3 -e -a 3000 -q ' + appServer.IP() + ' 5004 > ngtcp2/datasets/PARTIAL_3B_0L_100F_2000D_60R_client.txt') #pid = int( appClient.cmd('./ngtcp2/examples/client -b 3 -e -a 3000 -q ' + appServer.IP() + ' 5004 > ngtcp2/datasets/PARTIAL_3B_10L_18000F_2000D_60R_client.txt') ) #appClient.cmd('wait', pid) #appClient.cmd('./home/mininet/quic_data/mininet/ngtcp2/examples/client -b 3 -e -a 3000 -q', appServer.IP(), ' 5004') #print('sudo ./ngtcp2/datasets/generate_data_client.sh ' + appServer.IP() + ' &') #appClient.cmd('sudo ./ngtcp2/datasets/generate_data_client.sh ' + appServer.IP() + ' &') #print("client command run") #appClient.cmd('./ngtcp2/examples/client -b 3 -e -a 3000 -q ', appServer.IP(), ' 5004 > ngtcp2/datasets/PARTIAL_3B_0L_18000F_2000D_60R_client.txt') ''' #0.01% loss, reliable ################################# appServer.cmd('./ngtcp2-reliable/examples/server -b 3 -t 0.0001 -l 216000 -i 3000 -q -f 60 ', appServer.IP(), ' 5004 ngtcp2/test-ca/rsa/ca.key ngtcp2/test-ca/rsa/ca.cert > ngtcp2/datasets/1hr/50ms/RELIABLE_3B_001L_216000F_2000D_60R_server.txt &') appClient.cmd('./ngtcp2-reliable/examples/client -b 3 -e -a 3000 -q ', appServer.IP(), ' 5004 > ngtcp2/datasets/1hr/50ms/RELIABLE_3B_001L_216000F_2000D_60R_client.txt') time.sleep(20) ################################# #0.1% loss, reliable ################################# appServer.cmd('./ngtcp2-reliable/examples/server -b 3 -t 0.001 -l 216000 -i 3000 -q -f 60 ', appServer.IP(), ' 5004 ngtcp2/test-ca/rsa/ca.key ngtcp2/test-ca/rsa/ca.cert > ngtcp2/datasets/1hr/50ms/RELIABLE_3B_01L_216000F_2000D_60R_server.txt &') appClient.cmd('./ngtcp2-reliable/examples/client -b 3 -e -a 3000 -q ', appServer.IP(), ' 5004 > ngtcp2/datasets/1hr/50ms/RELIABLE_3B_01L_216000F_2000D_60R_client.txt') time.sleep(20) ################################ ''' #1% loss, reliable ################################# appServer.cmd( './ngtcp2-reliable/examples/server -b 3 -t 0.01 -l 216000 -i 3000 -q -f 60 ', appServer.IP(), ' 5004 ngtcp2/test-ca/rsa/ca.key ngtcp2/test-ca/rsa/ca.cert > ngtcp2/datasets/1hr/50ms/PARTIAL_3B_1L_216000F_2000D_60R_server.txt &' ) appClient.cmd( './ngtcp2-reliable/examples/client -b 3 -e -a 3000 -q ', appServer.IP(), ' 5004 > ngtcp2/datasets/1hr/50ms/RELIABLE_3B_1L_216000F_2000D_60R_client.txt' ) time.sleep(20) ################################# network.stop() time.sleep(5)
self.addLink(b1, b2) self.addLink(b1, b3) self.addLink(b2, b4) self.addLink(b3, b4) if __name__ == '__main__': check_scripts() topo = RingTopo() net = Mininet(topo=topo, controller=None) for idx in range(4): name = 'b' + str(idx + 1) node = net.get(name) clearIP(node) node.cmd('./scripts/disable_offloading.sh') node.cmd('./scripts/disable_ipv6.sh') # set mac address for each interface for port in range(len(node.intfList())): intf = '%s-eth%d' % (name, port) mac = '00:00:00:00:0%d:0%d' % (idx + 1, port + 1) node.setMAC(mac, intf=intf) node.cmd('./stp > %s-output.txt 2>&1 &' % name) # node.cmd('./stp-reference > %s-output.txt 2>&1 &' % name) net.start()
def bufferbloat(): if not os.path.exists(args.dir): os.makedirs(args.dir) os.system("sysctl -w net.ipv4.tcp_congestion_control=%s" % args.cong) topo = BBTopo() net = Mininet(topo=topo, host=CPULimitedHost, link=TCLink) net.start() # This dumps the topology and how nodes are interconnected through # links. dumpNodeConnections(net.hosts) # This performs a basic all pairs ping test. net.pingAll() # Start all the monitoring processes start_tcpprobe("cwnd.txt") # TODO: Start monitoring the queue sizes. Since the switch I # created is "s0", I monitor one of the interfaces. Which # interface? The interface numbering starts with 1 and increases. # Depending on the order you add links to your network, this # number may be 1 or 2. Ensure you use the correct number. qmon = start_qmon(iface='s0-eth2', outfile='%s/q.txt' % (args.dir)) # TODO: Start iperf, webservers, etc. start_iperf(net) start_ping(net) start_webserver(net) # TODO: measure the time it takes to complete webpage transfer # from h1 to h2 (say) 3 times. Hint: check what the following # command does: curl -o /dev/null -s -w %{time_total} google.com # Now use the curl command to fetch webpage from the webserver you # spawned on host h1 (not from google!) # Hint: have a separate function to do this and you may find the # loop below useful. #start_time = time() #while True: # do the measurement (say) 3 times. # sleep(5) # now = time() # delta = now - start_time # if delta > args.time: # break # print "%.1fs left..." % (args.time - delta) h1 = net.get('h1') h2 = net.get('h2') times = [] start = time() while True: # do the measurement (say) 3 times. sleep(5) now = time() delta = now - start if delta > args.time: break print "%.1fs left..." % (args.time - delta) fetch = h2.popen( "curl -o /dev/null -s -w \%{time_total} 10.0.0.1/http/index.html", shell=True, stdout=PIPE) #fetch.wait() var = float(fetch.stdout.read()) times.append(var) print "Average get time: " + str(numpy.average(times)) print "Standard Deviation of get times: " + str(numpy.std(times)) # TODO: compute average (and standard deviation) of the fetch # times. You don't need to plot them. Just note it in your # README and explain. # Hint: The command below invokes a CLI which you can use to # debug. It allows you to run arbitrary commands inside your # emulated hosts h1 and h2. # CLI(net) stop_tcpprobe() qmon.terminate() net.stop() # Ensure that all processes you create within Mininet are killed. # Sometimes they require manual killing. Popen("pgrep -f webserver.py | xargs kill -9", shell=True).wait()