def topology(): "Create a network." net = Mininet(controller=Controller, link=TCLink, switch=OVSKernelSwitch, accessPoint=OVSKernelAP) global gnet gnet = net print "*** Creating nodes" car = [] stas = [] for x in range(0, 4): car.append(x) stas.append(x) for x in range(0, 4): car[x] = net.addCar('car%s' % (x), wlans=2, ip='10.0.0.%s/8' % (x + 1), \ mac='00:00:00:00:00:0%s' % x, mode='b') eNodeB1 = net.addAccessPoint('eNodeB1', ssid='eNodeB1', dpid='1000000000000000', mode='ac', channel='1', position='80,75,0', range=60) eNodeB2 = net.addAccessPoint('eNodeB2', ssid='eNodeB2', dpid='2000000000000000', mode='ac', channel='6', position='180,75,0', range=70) rsu1 = net.addAccessPoint('rsu1', ssid='rsu1', dpid='3000000000000000', mode='g', channel='11', position='140,120,0', range=40) c1 = net.addController('c1', controller=Controller) client = net.addHost('client') switch = net.addSwitch('switch', dpid='4000000000000000') net.plotNode(client, position='125,230,0') net.plotNode(switch, position='125,200,0') print "*** Configuring wifi nodes" net.configureWifiNodes() print "*** Creating links" net.addLink(eNodeB1, switch) net.addLink(eNodeB2, switch) net.addLink(rsu1, switch) net.addLink(switch, client) print "*** Starting network" net.build() c1.start() eNodeB1.start([c1]) eNodeB2.start([c1]) rsu1.start([c1]) switch.start([c1]) for sw in net.vehicles: sw.start([c1]) client.cmd('ifconfig client-eth0 200.0.10.2') #net.vehiclesSTA[0].cmd('ifconfig car0STA-eth0 200.0.10.50') car[0].cmd('modprobe bonding mode=3') car[0].cmd('ip link add bond0 type bond') car[0].cmd('ip link set bond0 address 02:01:02:03:04:08') car[0].cmd('ip link set car0-eth0 down') car[0].cmd('ip link set car0-eth0 address 00:00:00:00:00:11') car[0].cmd('ip link set car0-eth0 master bond0') car[0].cmd('ip link set car0-wlan0 down') car[0].cmd('ip link set car0-wlan0 address 00:00:00:00:00:15') car[0].cmd('ip link set car0-wlan0 master bond0') car[0].cmd('ip link set car0-wlan1 down') car[0].cmd('ip link set car0-wlan1 address 00:00:00:00:00:13') car[0].cmd('ip link set car0-wlan1 master bond0') car[0].cmd('ip addr add 200.0.10.100/24 dev bond0') car[0].cmd('ip link set bond0 up') """plot graph""" net.plotGraph(max_x=250, max_y=250) net.startGraph() os.system('rm *.data') # Uncomment and modify the two commands below to stream video using VLC car[0].cmdPrint( "vlc -vvv bunnyMob.mp4 --sout '#duplicate{dst=rtp{dst=200.0.10.2,port=5004,,mux=ts},dst=display}' :sout-keep &" ) client.cmdPrint("vlc rtp://@200.0.10.2:5004 &") car[0].moveNodeTo('110,100,0') car[1].moveNodeTo('80,100,0') car[2].moveNodeTo('65,100,0') car[3].moveNodeTo('50,100,0') os.system('ovs-ofctl del-flows switch') time.sleep(3) apply_experiment(car, client, switch, net) print "*** Generating graphic" graphic() # kills all the xterms that have been opened os.system('pkill xterm') print "*** Running CLI" CLI(net) print "*** Stopping network" net.stop()
def topology(): global car1_new global car2_new global car3_new global car4_new car1_new = '' car2_new = '' car3_new = '' car4_new = '' "Create a network." net = Mininet(controller=RemoteController, link=TCLink, switch=OVSKernelSwitch) print "*** Creating nodes" car = [] stas = [] for x in range(0, 4): car.append(x) stas.append(x) for x in range(0, 4): min = random.randint(20, 40) max = random.randint(40, 60) car[x] = net.addCar('car%s' % (x + 1), wlans=1, ip='10.0.0.%s/8' % (x + 1), min_speed=min, max_speed=max, range=100) rsu11 = net.addAccessPoint('RSU11', ssid='RSU11', mode='g', channel='1', range=200, ip='192.168.0.11') rsu12 = net.addAccessPoint('RSU12', ssid='RSU12', mode='g', channel='6', range=200, ip='192.168.0.12') rsu13 = net.addAccessPoint('RSU13', ssid='RSU13', mode='g', channel='11', range=200, ip='192.168.0.13') rsu14 = net.addAccessPoint('RSU14', ssid='RSU14', mode='g', channel='1', range=200, ip='192.168.0.14') rsu15 = net.addAccessPoint('RSU15', ssid='RSU15', mode='g', channel='6', range=200, ip='192.168.0.15') c1 = net.addController('c1', controller=RemoteController, ip='192.168.56.107') print "*** Configuring wifi nodes" net.configureWifiNodes() net.meshRouting('custom') print "*** Associating and Creating links" net.addLink(rsu11, rsu12, bw=0.7, loss=2, delay='25ms') net.addLink(rsu12, rsu15, bw=1, loss=3, delay='10ms') net.addLink(rsu13, rsu15, bw=1, loss=2, delay='10ms') net.addLink(rsu13, rsu14, bw=5, loss=2, delay='5ms') net.addLink(rsu11, rsu14, bw=0.7, loss=8, delay='25ms') net.addLink(rsu11, rsu13, bw=0.7, loss=2, delay='25ms') net.addLink(rsu12, rsu14, bw=0.7, loss=8, delay='25ms') net.addLink(rsu11, rsu15, bw=0.7, loss=5, delay='25ms') net.addLink(rsu14, rsu15, bw=0.7, loss=6, delay='25ms') net.addLink(rsu12, rsu13, bw=5, loss=3, delay='5ms') print "*** Starting network" net.build() c1.start() rsu11.start([c1]) rsu12.start([c1]) rsu13.start([c1]) rsu14.start([c1]) rsu15.start([c1]) i = 201 for sw in net.vehicles: sw.start([c1]) os.system('ifconfig %s 10.0.0.%s' % (sw, i)) i += 1 """uncomment to plot graph""" net.plotGraph(max_x=1000, max_y=1000) """Number of Roads""" net.roads(6) """Start Mobility""" net.startMobility(startTime=0) i = 1 j = 2 k = 1 for c in car: c.cmd('ifconfig %s-wlan0 192.168.0.%s/24 up' % (c, k)) c.cmd('ifconfig %s-eth0 192.168.1.%s/24 up' % (c, i)) c.cmd('ip route add 10.0.0.0/8 via 192.168.1.%s' % j) i += 2 j += 2 k += 1 i = 1 j = 2 for v in net.vehiclesSTA: v.cmd('ifconfig %s-eth0 192.168.1.%s/24 up' % (v, j)) v.cmd('ifconfig %s-mp0 10.0.0.%s/24 up' % (v, i)) v.cmd('echo 1 > /proc/sys/net/ipv4/ip_forward') i += 1 j += 2 for v1 in net.vehiclesSTA: i = 1 j = 1 for v2 in net.vehiclesSTA: if v1 != v2: v1.cmd('route add -host 192.168.1.%s gw 10.0.0.%s' % (j, i)) i += 1 j += 2 car1 = car[0] car2 = car[1] car3 = car[2] car4 = car[3] output(car1, car2, car3, car4) print "*** Running CLI" cmdcli = CLI(net) #cmdcli.do_px("print car1.cmd('iwconfig > 1234_py_test.txt')") #CLI( net ) print "*** Stopping network" net.stop()
def topology(): "Create a network." net = Mininet(controller=Controller, link=TCLink, switch=OVSKernelSwitch, accessPoint=OVSKernelAP) global gnet gnet = net print "*** Creating nodes" car = [] stas = [] for x in range(0, 4): car.append(x) stas.append(x) for x in range(0, 4): car[x] = net.addCar('car%s' % (x), wlans=2, ip='10.0.0.%s/8' % (x + 1), \ mac='00:00:00:00:00:0%s' % x, mode='b') eNodeB1 = net.addAccessPoint('eNodeB1', ssid='eNodeB1', dpid='1000000000000000', mode='ac', channel='1', position='80,75,0', range=60) eNodeB2 = net.addAccessPoint('eNodeB2', ssid='eNodeB2', dpid='2000000000000000', mode='ac', channel='6', position='180,75,0', range=70) rsu1 = net.addAccessPoint('rsu1', ssid='rsu1', dpid='3000000000000000', mode='g', channel='11', position='140,120,0', range=40) c1 = net.addController('c1', controller=Controller) client = net.addHost('client') switch = net.addSwitch('switch', dpid='4000000000000000') net.plotNode(client, position='125,230,0') net.plotNode(switch, position='125,200,0') print "*** Configuring wifi nodes" net.configureWifiNodes() print "*** Creating links" net.addLink(eNodeB1, switch) net.addLink(eNodeB2, switch) net.addLink(rsu1, switch) net.addLink(switch, client) net.addLink(rsu1, car[0]) net.addLink(eNodeB2, car[0]) net.addLink(eNodeB1, car[3]) print "*** Starting network" net.build() c1.start() eNodeB1.start([c1]) eNodeB2.start([c1]) rsu1.start([c1]) switch.start([c1]) for sw in net.vehicles: sw.start([c1]) i = 1 j = 2 for c in car: c.cmd('ifconfig %s-wlan0 192.168.0.%s/24 up' % (c, i)) c.cmd('ifconfig %s-eth0 192.168.1.%s/24 up' % (c, i)) c.cmd('ip route add 10.0.0.0/8 via 192.168.1.%s' % j) i += 2 j += 2 i = 1 j = 2 for v in net.vehiclesSTA: v.cmd('ifconfig %s-eth0 192.168.1.%s/24 up' % (v, j)) v.cmd('ifconfig %s-mp0 10.0.0.%s/24 up' % (v, i)) v.cmd('echo 1 > /proc/sys/net/ipv4/ip_forward') i += 1 j += 2 for v1 in net.vehiclesSTA: i = 1 j = 1 for v2 in net.vehiclesSTA: if v1 != v2: v1.cmd('route add -host 192.168.1.%s gw 10.0.0.%s' % (j, i)) i += 1 j += 2 client.cmd('ifconfig client-eth0 200.0.10.2') net.vehiclesSTA[0].cmd('ifconfig car0STA-eth0 200.0.10.50') car[0].cmd('modprobe bonding mode=3') car[0].cmd('ip link add bond0 type bond') car[0].cmd('ip link set bond0 address 02:01:02:03:04:08') car[0].cmd('ip link set car0-eth0 down') car[0].cmd('ip link set car0-eth0 address 00:00:00:00:00:11') car[0].cmd('ip link set car0-eth0 master bond0') car[0].cmd('ip link set car0-wlan0 down') car[0].cmd('ip link set car0-wlan0 address 00:00:00:00:00:15') car[0].cmd('ip link set car0-wlan0 master bond0') car[0].cmd('ip link set car0-wlan1 down') car[0].cmd('ip link set car0-wlan1 address 00:00:00:00:00:13') car[0].cmd('ip link set car0-wlan1 master bond0') car[0].cmd('ip addr add 200.0.10.100/24 dev bond0') car[0].cmd('ip link set bond0 up') #connect through the other cars car[3].cmd('ifconfig car3-wlan0 200.0.10.150') client.cmd('ip route add 192.168.1.8 via 200.0.10.150') client.cmd('ip route add 10.0.0.1 via 200.0.10.150') net.vehiclesSTA[3].cmd('ip route add 200.0.10.2 via 192.168.1.7') net.vehiclesSTA[3].cmd('ip route add 200.0.10.100 via 10.0.0.1') net.vehiclesSTA[0].cmd('ip route add 200.0.10.2 via 10.0.0.4') car[0].cmd('ip route add 10.0.0.4 via 200.0.10.50') car[0].cmd('ip route add 192.168.1.7 via 200.0.10.50') car[0].cmd('ip route add 200.0.10.2 via 200.0.10.50') car[3].cmd('ip route add 200.0.10.100 via 192.168.1.8') """plot graph""" net.plotGraph(max_x=250, max_y=250) net.startGraph() # Uncomment and modify the two commands below to stream video using VLC # client(ip:200.0.10.2) is streaming and car0(ip:200.0.10.100) is the receiver car[0].cmdPrint( "vlc -vvv bunnyMob.mp4 --sout '#duplicate{dst=rtp{dst=200.0.10.2,port=5004,mux=ts},dst=display}' :sout-keep &" ) client.cmdPrint("vlc rtp://@200.0.10.2:5004 &") car[0].moveNodeTo('95,100,0') car[1].moveNodeTo('80,100,0') car[2].moveNodeTo('65,100,0') car[3].moveNodeTo('50,100,0') time.sleep(2) os.system('ovs-ofctl mod-flows switch in_port=1,actions=drop') os.system('ovs-ofctl mod-flows switch in_port=2,actions=drop') os.system('ovs-ofctl mod-flows switch in_port=3,actions=drop') apply_experiment(car, client, switch) # Uncomment the line below to generate the graph that you implemented graphic1() #total packets transmited,throughtput (through ifconfig) graphic2() #packets dropped (through ifconfig) #graphic3() #bandwidth (through iperf) #graphic4() #jitter (through iperf) graphic5() #latency (through ping) # kills all the xterms that have been opened os.system('pkill xterm') print "*** Running CLI" CLI(net) print "*** Stopping network" net.stop()
def topology(): taskTime = 20 "Create a network." net = Mininet(controller=Controller, link=TCLink, switch=OVSKernelSwitch, accessPoint=OVSKernelAP) print "*** Creating nodes" car = [] stas = [] for x in range(0, 4): car.append(x) stas.append(x) for x in range(0, 4): car[x] = net.addCar('car%s' % (x), wlans=2, ip='10.0.0.%s/8' % (x + 1), \ mac='00:00:00:00:00:0%s' % x, mode='b', position='%d,%d,0' % ((120 - (x * 20)), (100 - (x * 0)))) eNodeB1 = net.addAccessPoint('eNodeB1', ssid='eNodeB1', dpid='1000000000000000', mode='ac', channel='1', position='80,75,0') eNodeB2 = net.addAccessPoint('eNodeB2', ssid='eNodeB2', dpid='2000000000000000', mode='ac', channel='6', position='180,75,0') rsu1 = net.addAccessPoint('rsu1', ssid='rsu1', dpid='3000000000000000', mode='g', channel='11', position='140,120,0') c1 = net.addController('c1', controller=Controller) client = net.addHost('client') switch = net.addSwitch('switch', dpid='4000000000000000') net.plotNode(client, position='125,230,0') net.plotNode(switch, position='125,200,0') print "*** Configuring wifi nodes" net.configureWifiNodes() print "*** Creating links" net.addLink(eNodeB1, switch) net.addLink(eNodeB2, switch) net.addLink(rsu1, switch) net.addLink(switch, client) net.addLink(rsu1, car[0]) net.addLink(eNodeB2, car[0]) net.addLink(eNodeB1, car[3]) print "*** Starting network" net.build() c1.start() eNodeB1.start([c1]) eNodeB2.start([c1]) rsu1.start([c1]) switch.start([c1]) for sw in net.vehicles: sw.start([c1]) i = 1 j = 2 for c in car: c.cmd('ifconfig %s-wlan0 192.168.0.%s/24 up' % (c, i)) c.cmd('ifconfig %s-eth0 192.168.1.%s/24 up' % (c, i)) c.cmd('ip route add 10.0.0.0/8 via 192.168.1.%s' % j) i += 2 j += 2 i = 1 j = 2 for v in net.vehiclesSTA: v.cmd('ifconfig %s-eth0 192.168.1.%s/24 up' % (v, j)) v.cmd('ifconfig %s-mp0 10.0.0.%s/24 up' % (v, i)) v.cmd('echo 1 > /proc/sys/net/ipv4/ip_forward') i += 1 j += 2 for v1 in net.vehiclesSTA: i = 1 j = 1 for v2 in net.vehiclesSTA: if v1 != v2: v1.cmd('route add -host 192.168.1.%s gw 10.0.0.%s' % (j, i)) i += 1 j += 2 client.cmd('ifconfig client-eth0 200.0.10.2') net.vehiclesSTA[3].cmd('ifconfig car3STA-eth1 200.0.10.1') net.vehiclesSTA[0].cmd('ifconfig car0STA-eth0 200.0.10.50') car[0].cmd('modprobe bonding mode=3') car[0].cmd('ip link add bond0 type bond') car[0].cmd('ip link set bond0 address 02:01:02:03:04:08') car[0].cmd('ip link set car0-eth0 down') car[0].cmd('ip link set car0-eth0 address 00:00:00:00:00:11') car[0].cmd('ip link set car0-eth0 master bond0') car[0].cmd('ip link set car0-wlan0 down') car[0].cmd('ip link set car0-wlan0 address 00:00:00:00:00:15') car[0].cmd('ip link set car0-wlan0 master bond0') car[0].cmd('ip link set car0-wlan1 down') car[0].cmd('ip link set car0-wlan1 address 00:00:00:00:00:13') car[0].cmd('ip link set car0-wlan1 master bond0') car[0].cmd('ip addr add 200.0.10.100/24 dev bond0') car[0].cmd('ip link set bond0 up') car[3].cmd('ifconfig car3-wlan0 200.0.10.150') client.cmd('ip route add 192.168.1.8 via 200.0.10.150') client.cmd('ip route add 10.0.0.1 via 200.0.10.150') net.vehiclesSTA[3].cmd('ip route add 200.0.10.2 via 192.168.1.7') net.vehiclesSTA[3].cmd('ip route add 200.0.10.100 via 10.0.0.1') net.vehiclesSTA[0].cmd('ip route add 200.0.10.2 via 10.0.0.4') car[0].cmd('ip route add 10.0.0.4 via 200.0.10.50') car[0].cmd('ip route add 192.168.1.7 via 200.0.10.50') car[0].cmd('ip route add 200.0.10.2 via 200.0.10.50') car[3].cmd('ip route add 200.0.10.100 via 192.168.1.8') """uncomment to plot graph""" net.plotGraph(max_x=250, max_y=250) net.startGraph() os.system('rm *.vanetdata') #os.system('xterm -hold -title "car0" -e "util/m car0 ping 200.0.10.2" &') car[0].cmdPrint( "cvlc -vvv v4l2:///dev/video0 --mtu 1000 --sout \'#transcode{vcodec=mp4v,vb=800,scale=1,\ acodec=mpga,ab=128,channels=1}: duplicate{dst=display,dst=rtp{sdp=rtsp://200.0.10.100:8080/helmet.sdp}\' &" ) client.cmdPrint("cvlc rtsp://200.0.10.100:8080/helmet.sdp &") os.system('ovs-ofctl mod-flows switch in_port=1,actions=drop') os.system('ovs-ofctl mod-flows switch in_port=2,actions=drop') os.system('ovs-ofctl mod-flows switch in_port=3,actions=drop') time.sleep(2) print "applying first rule" os.system('ovs-ofctl mod-flows switch in_port=1,actions=output:4') os.system('ovs-ofctl mod-flows switch in_port=4,actions=output:1') os.system('ovs-ofctl mod-flows switch in_port=2,actions=drop') os.system('ovs-ofctl mod-flows switch in_port=3,actions=drop') os.system('ovs-ofctl del-flows eNodeB1') os.system('ovs-ofctl del-flows eNodeB2') os.system('ovs-ofctl del-flows rsu1') car[0].cmd('ip route add 200.0.10.2 via 200.0.10.50') client.cmd('ip route add 200.0.10.100 via 200.0.10.150') timeout = time.time() + taskTime currentTime = time.time() i = 0 while True: if time.time() > timeout: break if time.time() - currentTime >= i: car[0].cmd( 'ifconfig bond0 | grep \"TX packets\" | awk -F\' \' \'{print $3}\' >> %s' % c0_pkt) client.cmd( 'ifconfig client-eth0 | grep \"RX packets\" | awk -F\' \' \'{print $3}\' >> %s' % switch_pkt) car[0].cmd( 'ifconfig bond0 | grep \"bytes\" | awk -F\' \' \'NR==2{print $5}\' >> %s' % c0_throughput) client.cmd( 'ifconfig client-eth0 | grep \"bytes\" | awk -F\' \' \'NR==1{print $5}\' >> %s' % switch_throughput) i += 0.5 print "Moving nodes" car[0].moveNodeTo('150,100,0') car[1].moveNodeTo('120,100,0') car[2].moveNodeTo('90,100,0') car[3].moveNodeTo('70,100,0') #time.sleep(3) print "applying second rule" os.system('ovs-ofctl mod-flows switch in_port=1,actions=drop') os.system('ovs-ofctl mod-flows switch in_port=2,actions=output:4') os.system('ovs-ofctl mod-flows switch in_port=4,actions=output:2,3') os.system('ovs-ofctl mod-flows switch in_port=3,actions=output:4') os.system('ovs-ofctl del-flows eNodeB1') os.system('ovs-ofctl del-flows eNodeB2') os.system('ovs-ofctl del-flows rsu1') car[0].cmd('ip route del 200.0.10.2 via 200.0.10.50') client.cmd('ip route del 200.0.10.100 via 200.0.10.150') timeout = time.time() + taskTime currentTime = time.time() i = 0 while True: if time.time() > timeout: break if time.time() - currentTime >= i: car[0].cmd( 'ifconfig bond0 | grep \"TX packets\" | awk -F\' \' \'{print $3}\' >> %s' % c0_pkt) client.cmd( 'ifconfig client-eth0 | grep \"RX packets\" | awk -F\' \' \'{print $3}\' >> %s' % switch_pkt) car[0].cmd( 'ifconfig bond0 | grep \"bytes\" | awk -F\' \' \'NR==2{print $5}\' >> %s' % c0_throughput) client.cmd( 'ifconfig client-eth0 | grep \"bytes\" | awk -F\' \' \'NR==1{print $5}\' >> %s' % switch_throughput) i += 0.5 print "Moving nodes" car[0].moveNodeTo('190,100,0') car[1].moveNodeTo('150,100,0') car[2].moveNodeTo('120,100,0') car[3].moveNodeTo('90,100,0') #time.sleep(2) print "applying third rule" os.system('ovs-ofctl mod-flows switch in_port=1,actions=drop') os.system('ovs-ofctl mod-flows switch in_port=3,actions=drop') os.system('ovs-ofctl mod-flows switch in_port=2,actions=output:4') os.system('ovs-ofctl mod-flows switch in_port=4,actions=output:2') os.system('ovs-ofctl del-flows eNodeB1') os.system('ovs-ofctl del-flows eNodeB2') os.system('ovs-ofctl del-flows rsu1') timeout = time.time() + taskTime currentTime = time.time() i = 0 while True: if time.time() > timeout: break if time.time() - currentTime >= i: car[0].cmd( 'ifconfig bond0 | grep \"TX packets\" | awk -F\' \' \'{print $3}\' >> %s' % c0_pkt) client.cmd( 'ifconfig client-eth0 | grep \"RX packets\" | awk -F\' \' \'{print $3}\' >> %s' % switch_pkt) car[0].cmd( 'ifconfig bond0 | grep \"bytes\" | awk -F\' \' \'NR==2{print $5}\' >> %s' % c0_throughput) client.cmd( 'ifconfig client-eth0 | grep \"bytes\" | awk -F\' \' \'NR==1{print $5}\' >> %s' % switch_throughput) i += 0.5 print "*** Generating graphic" graphic() os.system('pkill xterm') print "*** Running CLI" CLI(net) #os.system('rm *.vanetdata') print "*** Stopping network" net.stop()
def topology(): "Create a network." net = Mininet(controller=None, accessPoint=UserAP, enable_wmediumd=True, enable_interference=True) print "*** Creating nodes" cars = [] stas = [] for x in range(0, 10): cars.append(x) stas.append(x) for x in range(0, 10): cars[x] = net.addCar('car%s' % (x), wlans=1, ip='10.0.0.%s/8' % (x + 1)) ap1 = net.addAccessPoint('ap1', ssid='vanet-ssid', mode='g', channel='1', position='1127.02,513.27,0', range='40') ap2 = net.addAccessPoint('ap2', ssid='vanet-ssid', mode='g', channel='6', position='1024.82,469.75,0', range='40') ap3 = net.addAccessPoint('ap3', ssid='vanet-ssid', mode='g', channel='11', position='914.42,299.22,0', range='40') ap4 = net.addAccessPoint('ap4', ssid='vanet-ssid', mode='g', channel='1', position='1165.62,345.92,0', range='40') ap5 = net.addAccessPoint('ap5', ssid='vanet-ssid', mode='g', channel='6', position='1159.62,151.61,0', range='40') ap6 = net.addAccessPoint('ap6', ssid='vanet-ssid', mode='g', channel='11', position='1363.68,337.40,0', range='40') c1 = net.addController('c1', controller=Controller, ip='127.0.0.1', port=6633) h1 = net.addHost('h1', mac='00:00:00:11:00:01', ip='10.0.0.1/8') s1 = net.addSwitch('s1', mac='00:00:00:00:00:01') s2 = net.addSwitch('s2', mac='00:00:00:00:00:02') s3 = net.addSwitch('s3', mac='00:00:00:00:00:03') s4 = net.addSwitch('s4', mac='00:00:00:00:00:04') lte = net.addSwitch('s10', mac='00:00:00:00:00:10') print "*** Setting bgscan" net.setBgscan(signal=-45, s_inverval=5, l_interval=10) print "*** Configuring Propagation Model" net.propagationModel(model="logDistance", exp=2) print "*** Configuring wifi nodes" net.configureWifiNodes() print "*** Add Wifi links" net.addLink(s1, h1) net.addLink(s2,s1, bw=10, delay='5ms', loss=2, use_htb=True) net.addLink(s3,s1, bw=10, delay='10ms', loss=1, use_htb=True) net.addLink(s4,s1, bw=10, delay='10ms', loss=1, use_htb=True) net.addLink(ap1, s2) net.addLink(ap2, s3) net.addLink(ap3, s4) print "*** Add LTE links" for x in range(0, 10): net.addLink(lte,'car%s' % (x)) net.addLink(lte,s1,bw=10, delay='50ms', loss=1, use_htb=True) print "*** Starting SUMO" net.useExternalProgram('sumo-gui', config_file='ucla.sumocfg') print "*** Starting network" net.build()
def topology(): "Create a network." net = Mininet(controller=Controller, switch=OVSKernelSwitch, enable_wmediumd=True, enable_interference=True) print "*** Creating nodes" cars = [] stas = [] for x in range(0, 10): cars.append(x) stas.append(x) for x in range(0, 10): cars[x] = net.addCar('car%s' % (x), wlans=1, ip='10.0.0.%s/8' % (x + 1)) e1 = net.addAccessPoint('e1', ssid='vanet-ssid', mac='00:00:00:11:00:01', mode='g', channel='1', passwd='123456789a', encrypt='wpa2', position='1127.02,513.27,0') e2 = net.addAccessPoint('e2', ssid='vanet-ssid', mac='00:00:00:11:00:02', mode='g', channel='6', passwd='123456789a', encrypt='wpa2', position='1024.82,469.75,0') e3 = net.addAccessPoint('e3', ssid='vanet-ssid', mac='00:00:00:11:00:03', mode='g', channel='11', passwd='123456789a', encrypt='wpa2', position='914.42,299.22,0') e4 = net.addAccessPoint('e4', ssid='vanet-ssid', mac='00:00:00:11:00:04', mode='g', channel='1', passwd='123456789a', encrypt='wpa2', position='1165.62,345.92,0') e5 = net.addAccessPoint('e5', ssid='vanet-ssid', mac='00:00:00:11:00:05', mode='g', channel='6', passwd='123456789a', encrypt='wpa2', position='1159.62,151.61,0') e6 = net.addAccessPoint('e6', ssid='vanet-ssid', mac='00:00:00:11:00:06', mode='g', channel='11', passwd='123456789a', encrypt='wpa2', position='1363.68,337.40,0') c1 = net.addController('c1', controller=Controller, ip='127.0.0.1', port=6633) print "*** Configuring Propagation Model" net.propagationModel(model="logDistance", exp=2) print "*** Configuring wifi nodes" net.configureWifiNodes() print "*** add links" net.addLink(e1, e2) net.addLink(e2, e3) net.addLink(e3, e4) net.addLink(e4, e5) net.addLink(e5, e6) print "*** Starting SUMO" net.useExternalProgram('sumo-gui', config_file='ucla.sumocfg') print "*** Starting network" net.build() c1.start() e1.start([c1]) e2.start([c1]) e3.start([c1]) e4.start([c1]) e5.start([c1]) e6.start([c1]) i = 201 for sw in net.carsSW: sw.start([c1]) os.system('ip addr add 10.0.0.%s dev %s' % (i, sw)) i += 1 i = 1 j = 2 for car in cars: car.setIP('192.168.0.%s/24' % i, intf='%s-wlan0' % car) car.setIP('192.168.1.%s/24' % i, intf='%s-eth1' % car) car.cmd('ip route add 10.0.0.0/8 via 192.168.1.%s' % j) i += 2 j += 2 i = 1 j = 2 for carsta in net.carsSTA: carsta.setIP('10.0.0.%s/24' % i, intf='%s-mp0' % carsta) carsta.setIP('192.168.1.%s/24' % j, intf='%s-eth2' % carsta) #May be confuse, but it allows ping to the name instead of ip addr carsta.setIP('10.0.0.%s/24' % i, intf='%s-wlan0' % carsta) carsta.cmd('echo 1 > /proc/sys/net/ipv4/ip_forward') i += 1 j += 2 for carsta1 in net.carsSTA: i = 1 j = 1 for carsta2 in net.carsSTA: if carsta1 != carsta2: carsta1.cmd('route add -host 192.168.1.%s gw 10.0.0.%s' % (j, i)) i += 1 j += 2 print "*** Running CLI" CLI(net) print "*** Stopping network" net.stop()
def topology(): "Create a network." net = Mininet(controller=Controller, link=TCLink, switch=OVSKernelSwitch, accessPoint=OVSKernelAP) print "*** Creating nodes" car = [] stas = [] for x in range(0, 4): car.append(x) stas.append(x) for x in range(0, 4): car[x] = net.addCar('car%s' % (x), wlans=2, ip='10.0.0.%s/8' % (x + 1), \ mac='00:00:00:00:00:0%s' % x, mode='b') eNodeB1 = net.addAccessPoint('eNodeB1', ssid='eNodeB1', dpid='1000000000000000', mode='ac', channel='1', position='80,75,0', range=60) eNodeB2 = net.addAccessPoint('eNodeB2', ssid='eNodeB2', dpid='2000000000000000', mode='ac', channel='6', position='180,75,0', range=70) rsu1 = net.addAccessPoint('rsu1', ssid='rsu1', dpid='3000000000000000', mode='g', channel='11', position='140,120,0', range=40) c1 = net.addController('c1', controller=Controller) client = net.addHost('client') switch = net.addSwitch('switch', dpid='4000000000000000') net.plotNode(client, position='125,230,0') net.plotNode(switch, position='125,200,0') print "*** Configuring wifi nodes" net.configureWifiNodes() print "*** Creating links" net.addLink(eNodeB1, switch) net.addLink(eNodeB2, switch) net.addLink(rsu1, switch) net.addLink(switch, client) print "*** Starting network" net.build() c1.start() eNodeB1.start([c1]) eNodeB2.start([c1]) rsu1.start([c1]) switch.start([c1]) for sw in net.vehicles: sw.start([c1]) i = 1 j = 2 for c in car: c.cmd('ifconfig %s-wlan0 192.168.0.%s/24 up' % (c, i)) c.cmd('ifconfig %s-eth0 192.168.1.%s/24 up' % (c, i)) c.cmd('ip route add 10.0.0.0/8 via 192.168.1.%s' % j) i += 2 j += 2 i = 1 j = 2 for v in net.vehiclesSTA: v.cmd('ifconfig %s-eth0 192.168.1.%s/24 up' % (v, j)) v.cmd('ifconfig %s-mp0 10.0.0.%s/24 up' % (v, i)) v.cmd('echo 1 > /proc/sys/net/ipv4/ip_forward') i += 1 j += 2 for v1 in net.vehiclesSTA: i = 1 j = 1 for v2 in net.vehiclesSTA: if v1 != v2: v1.cmd('route add -host 192.168.1.%s gw 10.0.0.%s' % (j, i)) i += 1 j += 2 client.cmd('ifconfig client-eth0 200.0.10.2') net.vehiclesSTA[0].cmd('ifconfig car0STA-eth0 200.0.10.50') car[0].cmd('modprobe bonding mode=3') car[0].cmd('ip link add bond0 type bond') car[0].cmd('ip link set bond0 address 02:01:02:03:04:08') car[0].cmd('ip link set car0-eth0 down') car[0].cmd('ip link set car0-eth0 address 00:00:00:00:00:11') car[0].cmd('ip link set car0-eth0 master bond0') car[0].cmd('ip link set car0-wlan0 down') car[0].cmd('ip link set car0-wlan0 address 00:00:00:00:00:15') car[0].cmd('ip link set car0-wlan0 master bond0') car[0].cmd('ip link set car0-wlan1 down') car[0].cmd('ip link set car0-wlan1 address 00:00:00:00:00:13') car[0].cmd('ip link set car0-wlan1 master bond0') car[0].cmd('ip addr add 200.0.10.100/24 dev bond0') car[0].cmd('ip link set bond0 up') car[3].cmd('ifconfig car3-wlan0 200.0.10.150') client.cmd('ip route add 192.168.1.8 via 200.0.10.150') client.cmd('ip route add 10.0.0.1 via 200.0.10.150') net.vehiclesSTA[3].cmd('ip route add 200.0.10.2 via 192.168.1.7') net.vehiclesSTA[3].cmd('ip route add 200.0.10.100 via 10.0.0.1') net.vehiclesSTA[0].cmd('ip route add 200.0.10.2 via 10.0.0.4') car[0].cmd('ip route add 10.0.0.4 via 200.0.10.50') car[0].cmd('ip route add 192.168.1.7 via 200.0.10.50') car[0].cmd('ip route add 200.0.10.2 via 200.0.10.50') car[3].cmd('ip route add 200.0.10.100 via 192.168.1.8') """plot graph""" net.plotGraph(max_x=250, max_y=250) net.startGraph() # Uncomment and modify the two commands below to stream video using VLC car[0].cmdPrint( "cvlc -vvv bwcLow.mp4 --mtu 1000 --sout \'#transcode{vcodec=mp4v,vb=800,scale=1,\ acodec=mpga,ab=128,channels=1}: duplicate{dst=display,dst=rtp{sdp=rtsp://200.0.10.100:8080/helmet.sdp}}\' &" ) client.cmdPrint("cvlc rtsp://200.0.10.100:8080/helmet.sdp &") car[0].moveNodeTo('95,100,0') car[1].moveNodeTo('80,100,0') car[2].moveNodeTo('65,100,0') car[3].moveNodeTo('50,100,0') os.system('ovs-ofctl del-flows switch') time.sleep(3) apply_experiment(car, client, switch, net) # Uncomment the line below to generate the graph that you implemented graphic() # kills all the xterms that have been opened #os.system('pkill xterm') print "*** Running CLI" CLI(net) print "*** Stopping network" net.stop()
def topology(): "Create a network." net = Mininet(controller=Controller, link=TCLink, switch=OVSKernelSwitch) print "*** Creating nodes" car = [] stas = [] for x in range(0, 4): car.append(x) stas.append(x) for x in range(0, 4): car[x] = net.addCar('car%s' % (x), wlans=2, ip='10.0.0.%s/8' % (x + 1), \ mac='00:00:00:00:00:0%s' % x, mode='b', position='%d,%d,0' % ((150-(x*20)),(100-(x*20))) ) rs1 = net.addAccessPoint('rs1', ssid='ssid1', mode='g', channel='1', position='60,50,0') rs2 = net.addAccessPoint('rs2', ssid='ssid2', mode='g', channel='6', position='160,100,0') bs3 = net.addAccessPoint('bs3', ssid='ssid3', mode='g', channel='6', position='150,120,0', range=70) c1 = net.addController('c1', controller=Controller) h1 = net.addHost('h1') s10 = net.addSwitch('s10') print "*** Configuring wifi nodes" net.configureWifiNodes() print "*** Creating links" net.addLink(rs1, s10) net.addLink(rs2, s10) net.addLink(bs3, s10) net.addLink(s10, h1) net.addLink(bs3, car[0]) net.addLink(rs2, car[0]) net.addLink(rs1, car[3]) print "*** Starting network" net.build() c1.start() rs1.start([c1]) rs2.start([c1]) bs3.start([c1]) s10.start([c1]) i = 201 for sw in net.vehicles: sw.start([c1]) i = 1 j = 2 for c in car: c.cmd('ifconfig %s-wlan0 192.168.0.%s/24 up' % (c, i)) c.cmd('ifconfig %s-eth0 192.168.1.%s/24 up' % (c, i)) c.cmd('ip route add 10.0.0.0/8 via 192.168.1.%s' % j) i += 2 j += 2 i = 1 j = 2 for v in net.vehiclesSTA: v.cmd('ifconfig %s-eth0 192.168.1.%s/24 up' % (v, j)) v.cmd('ifconfig %s-mp0 10.0.0.%s/24 up' % (v, i)) v.cmd('echo 1 > /proc/sys/net/ipv4/ip_forward') i += 1 j += 2 for v1 in net.vehiclesSTA: i = 1 j = 1 for v2 in net.vehiclesSTA: if v1 != v2: v1.cmd('route add -host 192.168.1.%s gw 10.0.0.%s' % (j, i)) i += 1 j += 2 h1.cmd('ifconfig h1-eth0 200.0.10.2') net.vehiclesSTA[3].cmd('ifconfig car3STA-eth1 200.0.10.1') net.vehiclesSTA[0].cmd('ip route add 200.0.10.0/24 via 10.0.0.4') car[0].cmd('modprobe bonding mode=3') car[0].cmd('ip link add bond0 type bond') car[0].cmd('ip link set bond0 address 02:01:02:03:04:08') car[0].cmd('ip link set car0-eth0 down') car[0].cmd('ip link set car0-eth0 address 00:00:00:00:00:11') car[0].cmd('ip link set car0-eth0 master bond0') car[0].cmd('ip link set car0-wlan0 down') car[0].cmd('ip link set car0-wlan0 address 00:00:00:00:00:15') car[0].cmd('ip link set car0-wlan0 master bond0') car[0].cmd('ip link set car0-wlan1 down') car[0].cmd('ip link set car0-wlan1 address 00:00:00:00:00:13') car[0].cmd('ip link set car0-wlan1 master bond0') car[0].cmd('ip addr add 200.0.10.100/24 dev bond0') car[0].cmd('ip link set bond0 up') """uncomment to plot graph""" net.plotGraph(max_x=250, max_y=250) mp1 = net.vehiclesSTA[0] mp2 = net.vehiclesSTA[1] mp3 = net.vehiclesSTA[2] mp4 = net.vehiclesSTA[3] print "*** Configure wmediumd" sta1wlan0 = DynamicWmediumdIntfRef(mp1) sta2wlan0 = DynamicWmediumdIntfRef(mp2) sta3wlan0 = DynamicWmediumdIntfRef(mp3) sta4wlan0 = DynamicWmediumdIntfRef(mp4) intfrefs = [sta1wlan0, sta2wlan0, sta3wlan0, sta4wlan0] links = [ WmediumdLink(sta1wlan0, sta2wlan0, 15), WmediumdLink(sta2wlan0, sta1wlan0, 15), WmediumdLink(sta2wlan0, sta3wlan0, 15), WmediumdLink(sta3wlan0, sta2wlan0, 15), WmediumdLink(sta3wlan0, sta4wlan0, 15), WmediumdLink(sta4wlan0, sta3wlan0, 15) ] WmediumdConn.set_wmediumd_data(intfrefs, links) WmediumdConn.connect_wmediumd_after_startup() print "*** Running CLI" CLI(net) print "*** Stopping wmediumd" WmediumdConn.disconnect_wmediumd() print "*** Stopping network" net.stop()
def topology(): "Create a network." net = Mininet(controller=Controller, link=TCLink, switch=OVSKernelSwitch, accessPoint=OVSKernelAP) global gnet gnet = net print "*** Creating nodes" car = [] car.append(0) car[0] = net.addCar('car0', wlans=2, ip='10.0.0.1/8', mac='00:00:00:00:00:00', mode='b') eNodeB1 = net.addAccessPoint('eNodeB1', ssid='eNodeB1', dpid='1000000000000000', mode='ac', channel='1', position='80,75,0', range=60) eNodeB2 = net.addAccessPoint('eNodeB2', ssid='eNodeB2', dpid='2000000000000000', mode='ac', channel='6', position='180,75,0', range=70) rsu1 = net.addAccessPoint('rsu1', ssid='rsu1', dpid='3000000000000000', mode='g', channel='11', position='140,120,0', range=52) c1 = net.addController('c1', controller=Controller) client = net.addHost('client') switch = net.addSwitch('switch', dpid='4000000000000000') net.plotNode(client, position='125,230,0') net.plotNode(switch, position='125,200,0') print "*** Configuring wifi nodes" net.configureWifiNodes() print "*** Creating links" net.addLink(eNodeB1, switch) net.addLink(eNodeB2, switch) net.addLink(rsu1, switch) net.addLink(switch, client) print "*** Starting network" net.build() c1.start() eNodeB1.start([c1]) eNodeB2.start([c1]) rsu1.start([c1]) switch.start([c1]) for sw in net.vehicles: sw.start([c1]) client.cmd('ifconfig client-eth0 200.0.10.2') # Broadcast policy: transmits everything on all slave interfaces. This mode provides fault tolerance. car[0].cmd('modprobe bonding mode=3') # Network device configuration, bonding car phisical architecture into one interface car[0].cmd('ip link add bond0 type bond') car[0].cmd('ip link set bond0 address 02:01:02:03:04:08') car[0].cmd('ip link set car0-eth0 down') car[0].cmd('ip link set car0-eth0 address 00:00:00:00:00:11') car[0].cmd('ip link set car0-eth0 master bond0') car[0].cmd('ip link set car0-wlan0 down') car[0].cmd('ip link set car0-wlan0 address 00:00:00:00:00:15') car[0].cmd('ip link set car0-wlan0 master bond0') car[0].cmd('ip link set car0-wlan1 down') car[0].cmd('ip link set car0-wlan1 address 00:00:00:00:00:13') car[0].cmd('ip link set car0-wlan1 master bond0') car[0].cmd('ip addr add 200.0.10.100/24 dev bond0') car[0].cmd('ip link set bond0 up') """plot graph""" net.plotGraph(max_x=250, max_y=250) net.startGraph() # Uncomment and modify the two commands below to stream video using VLC # car[0].cmdPrint( # "vlc -vvv bunnyMob.mp4 --sout '#duplicate{dst=rtp{dst=200.0.10.2,port=5004,mux=ts},dst=display}' :sout-keep &") #client.cmdPrint("vlc rtp://@200.0.10.2:5004 &") car[0].moveNodeTo('95,100,0') os.system('ovs-ofctl del-flows switch') time.sleep(3) apply_experiment(car, client, switch) # Uncomment the line below to generate the graph that you implemented # graphic() # kills all the xterms that have been opened os.system('pkill xterm') print "*** Running CLI" CLI(net) print "*** Stopping network" net.stop()
def topology(): "Create a network." net = Mininet(controller=Controller, link=TCLink, switch=OVSKernelSwitch, accessPoint=OVSKernelAP) global gnet gnet = net print "*** Creating nodes" car = [] for x in range(0, 4): car.append(x) for x in range(0, 4): car[x] = net.addCar('car%s' % (x), wlans=2, ip='10.0.0.%s/8' % (x + 1), \ mac='00:00:00:00:00:0%s' % x, mode='b') eNodeB1 = net.addAccessPoint('eNodeB1', ssid='eNodeB1', dpid='1000000000000000', mode='ac', channel='1', position='80,75,0', range=60) eNodeB2 = net.addAccessPoint('eNodeB2', ssid='eNodeB2', dpid='2000000000000000', mode='ac', channel='6', position='180,75,0', range=60) rsu1 = net.addAccessPoint('rsu1', ssid='rsu1', dpid='3000000000000000', mode='g', channel='11', position='140,120,0', range=40) c1 = net.addController('c1', controller=Controller) client = net.addHost('client') switch = net.addSwitch('switch', dpid='4000000000000000') net.plotNode(client, position='125,230,0') net.plotNode(switch, position='125,200,0') print "*** Configuring wifi nodes" net.configureWifiNodes() print "*** Creating links" net.addLink(eNodeB1, switch) net.addLink(eNodeB2, switch) net.addLink(rsu1, switch) net.addLink(switch, client) print "*** Starting network" net.build() c1.start() eNodeB1.start([c1]) eNodeB2.start([c1]) rsu1.start([c1]) switch.start([c1]) i = 1 j = 2 for c in car: c.cmd('ifconfig %s-wlan0 192.168.0.%s/24 up' % (c, i)) c.cmd('ifconfig %s-wlan1 192.168.1.%s/24 up' % (c, i)) i += 2 j += 2 print "\n" client.cmd('ifconfig client-eth0 200.0.10.2') car[0].cmd('modprobe bonding mode=3') car[0].cmd('ip link add bond0 type bond') car[0].cmd('ip link set bond0 address 02:01:02:03:04:08') car[0].cmd('ip link set car0-wlan0 down') car[0].cmd('ip link set car0-wlan0 address 00:00:00:00:00:15') car[0].cmd('ip link set car0-wlan0 master bond0') car[0].cmd('ip link set car0-wlan1 down') car[0].cmd('ip link set car0-wlan1 address 00:00:00:00:00:13') car[0].cmd('ip link set car0-wlan1 master bond0') car[0].cmd('ip addr add 200.0.10.100/24 dev bond0') car[0].cmd('ip link set bond0 up') """plot graph""" net.plotGraph(max_x=250, max_y=250) net.startGraph() # streaming video car[0].cmdPrint( "vlc -vvv ./bunnyMob.mp4 --sout '#duplicate{dst=rtp{dst=200.0.10.2,port=5004,mux=ts},dst=display}' :sout-keep --meta-title 'car0' &" ) client.cmdPrint("vlc rtp://@200.0.10.2:5004 --meta-title 'client' &") car[0].moveNodeTo('110,100,0') car[1].moveNodeTo('80,100,0') car[2].moveNodeTo('65,100,0') car[3].moveNodeTo('50,100,0') car[0].cmd('ip route add 200.0.10.2 via 200.0.10.100') apply_experiment(car, client, switch) # Uncomment the line below to generate the graph that you implemented graphic() # kills all the xterms that have been opened #--------------------- os.system('pkill xterm') print "*** Running CLI" CLI(net) print "*** Stopping network" net.stop()
def topology(): "Create a network." net = Mininet(controller=Controller, link=TCLink, switch=OVSKernelSwitch, enable_wmediumd=True, enable_interference=True) print "*** Creating nodes" cars = [] for x in range(0, 10): cars.append(x) for x in range(0, 10): min_ = random.randint(1, 4) max_ = random.randint(11, 30) cars[x] = net.addCar('car%s' % (x + 1), wlans=1, ip='10.0.0.%s/8' % (x + 1), min_speed=min_, max_speed=max_, range=50) rsu11 = net.addAccessPoint('RSU11', ssid='RSU11', mode='g', channel='1', range=100) rsu12 = net.addAccessPoint('RSU12', ssid='RSU12', mode='g', channel='6', range=100) rsu13 = net.addAccessPoint('RSU13', ssid='RSU13', mode='g', channel='11', range=100) rsu14 = net.addAccessPoint('RSU14', ssid='RSU14', mode='g', channel='11', range=100) c1 = net.addController('c1', controller=Controller) print "*** Configuring Propagation Model" net.propagationModel(model="logDistance", exp=4.5) print "*** Configuring wifi nodes" net.configureWifiNodes() print "*** Associating and Creating links" net.addLink(rsu11, rsu12) net.addLink(rsu11, rsu13) net.addLink(rsu11, rsu14) net.plotGraph(max_x=500, max_y=500) net.roads(10) net.startMobility(time=0) print "*** Starting network" net.build() c1.start() rsu11.start([c1]) rsu12.start([c1]) rsu13.start([c1]) rsu14.start([c1]) i = 201 for sw in net.carsSW: sw.start([c1]) os.system('ip addr add 10.0.0.%s dev %s' % (i, sw)) i += 1 i = 1 j = 2 k = 1 for car in cars: car.setIP('192.168.0.%s/24' % k, intf='%s-wlan0' % car) car.setIP('192.168.1.%s/24' % i, intf='%s-eth0' % car) car.cmd('ip route add 10.0.0.0/8 via 192.168.1.%s' % j) i += 2 j += 2 k += 1 i = 1 j = 2 for v in net.carsSTA: v.setIP('192.168.1.%s/24' % j, intf='%s-eth0' % v) v.setIP('10.0.0.%s/24' % i, intf='%s-mp0' % v) v.cmd('echo 1 > /proc/sys/net/ipv4/ip_forward') i += 1 j += 2 for v1 in net.carsSTA: i = 1 j = 1 for v2 in net.carsSTA: if v1 != v2: v1.cmd('route add -host 192.168.1.%s gw 10.0.0.%s' % (j, i)) i += 1 j += 2 print "*** Running CLI" CLI(net) print "*** Stopping network" net.stop()
def topology(): car_type = SD_Car op = raw_input("Choose Type of Experiment: (1)v2i \t (2)v2v \nChoice:") if (op == "1"): v2v = False pass else: v2v = True caching = raw_input( "What do you prefere to run:\n (1)car-level caching enabled (2)car-level caching disbled \nChoice: " ) if (caching == "1"): car_type = SD_C_Car else: car_type = SD_Car "Create a network." net = Mininet(controller=Vanet_controller, link=TCLink, accessPoint=UserAP, switch=SD_Car_Switch, station=SD_station, enable_wmediumd=True, enable_interference=True) print "*** Creating nodes" cars = [] stas = [] for x in range(0, 10): cars.append(x) stas.append(x) for x in range(0, 10): cars[x] = net.addCar('car%s' % (x), wlans=1, ip='10.0.0.%s/8' % (x + 1), cls=car_type) e1 = net.addAccessPoint('e1', ssid='vanet-ssid', mac='00:00:00:11:00:01', mode='g', channel='1', passwd='123456789a', encrypt='wpa2', position='3332.62,3253.92,0', cls=eNodeB) e2 = net.addAccessPoint('e2', ssid='vanet-ssid', mac='00:00:00:11:00:02', mode='g', channel='1', passwd='123456789a', encrypt='wpa2', position='3279.02,3736.27,0', cls=eNodeB) e3 = net.addAccessPoint('e3', ssid='vanet-ssid', mac='00:00:00:11:00:03', mode='g', channel='11', passwd='123456789a', encrypt='wpa2', position='2806.42,3395.22,0', cls=eNodeB) e4 = net.addAccessPoint('e4', ssid='vanet-ssid', mac='00:00:00:11:00:04', mode='g', channel='6', passwd='123456789a', encrypt='wpa2', position='2320.82,3565.75,0', cls=eNodeB) e5 = net.addAccessPoint('e5', ssid='vanet-ssid', mac='00:00:00:11:00:05', mode='g', channel='6', passwd='123456789a', encrypt='wpa2', position='2887.62,2935.61,0', cls=eNodeB) e6 = net.addAccessPoint('e6', ssid='vanet-ssid', mac='00:00:00:11:00:06', mode='g', channel='11', passwd='123456789a', encrypt='wpa2', position='2351.68,3083.40,0', cls=eNodeB) client = net.addHost('cloud', cls=Cloud_host) switch = net.addSwitch('switch', dpid='4000000000000000', cls=SD_Switch) c1 = net.addController('c1', controller=Vanet_controller, ip='127.0.0.1', port=6653) net.propagationModel("logDistancePropagationLossModel", exp=2.8) if (v2v): print "*** Setting bgscan" net.setBgscan(signal=-45, s_inverval=5, l_interval=10) print "*** Configuring wifi nodes" net.configureWifiNodes() net.addLink(switch, e1) net.addLink(client, switch) net.addLink(e1, e2) net.addLink(e2, e3) net.addLink(e3, e4) net.addLink(e4, e5) net.addLink(e5, e6) "Available Options: sumo, sumo-gui" net.useExternalProgram('sumo-gui', config_file='map.sumocfg') print "*** Starting network" net.build() c1.start() e1.start([c1]) e2.start([c1]) e3.start([c1]) e4.start([c1]) e5.start([c1]) e6.start([c1]) i = 201 for sw in net.carsSW: sw.start([c1]) os.system('ifconfig %s 10.0.0.%s' % (sw, i)) i += 1 i = 1 j = 2 for car in cars: car.cmd('ifconfig %s-wlan0 192.168.0.%s/24 up' % (car, i)) car.cmd('ifconfig %s-eth0 192.168.1.%s/24 up' % (car, i)) car.cmd('ip route add 10.0.0.0/8 via 192.168.1.%s' % j) i += 2 j += 2 i = 1 j = 2 for v in net.carsSTA: v.cmd('ifconfig %s-eth0 192.168.1.%s/24 up' % (v, j)) v.cmd('ifconfig %s-mp0 10.0.0.%s/24 up' % (v, i)) v.cmd('echo 1 > /proc/sys/net/ipv4/ip_forward') i += 1 j += 2 for v1 in net.carsSTA: i = 1 j = 1 for v2 in net.carsSTA: if v1 != v2: v1.cmd('route add -host 192.168.1.%s gw 10.0.0.%s' % (j, i)) i += 1 j += 2 c1.Initialize_resources(net) if (v2v): raw_input("Press Enter to continue (wait 30sec after t=28)...") os.system('clear') os.system('ovs-ofctl mod-flows car2SW in_port=2,actions=drop') cars[2].cmdPrint('iwconfig car2-wlan0') sleep(3) cars[6].cmdPrint('iwconfig car6-wlan0') print "****************************************************" print "*** Both car2 and car6 are associated to enodeB5 ***" print "****************************************************" sleep(6) os.system('clear') print "****************************************************************" print "*** Car6 is so far from enodeB5. Trying to send data by car2 ***" print "****************************************************************" sleep(6) os.system('clear') print "**************************************" print "*** Trying to send data to car6... ***" print "**************************************" cars[2].cmdPrint('ping -c5 10.0.0.7') print "****************************************************************************************************" print "*** Car2: V2V is blocked! Car6 is unreachable! Controller, please let me talk directly with car6 ***" print "****************************************************************************************************" sleep(6) os.system('clear') print "***********************************************" print "*** controller says: Car6 is now reachable! ***" print "***********************************************" os.system('ovs-ofctl mod-flows car2SW in_port=2,actions=1') sleep(6) os.system('clear') cars[2].cmdPrint('ping -c5 10.0.0.7') os.system('clear') print "***********************************" print "*** Car2: Requesting Content for car6! ***" print "***********************************" sleep(1) cars[2].RequestContent(net, 2) print "***********************************" print "*** Car2: Thank you Controller! ***" print "***********************************" else: print "***********************************" print "******** V2I experiment **********" print "***********************************" raw_input("PressEnter after T=28 ...") print "type>> py car4.RequestContent(net)" print "*** Running CLI" CLI(net) print "*** Stopping network" net.stop()
def topology(): "Create a network." net = Mininet(controller=Controller, link=TCLink, switch=OVSKernelSwitch, accessPoint=OVSKernelAP) global gnet gnet = net print "*** Creating nodes" car = [] stas = [] for x in range(0, 4): car.append(x) stas.append(x) for x in range(0, 4): car[x] = net.addCar('car%s' % (x), wlans=2, ip='10.0.0.%s/8' % (x + 1), \ mac='00:00:00:00:00:0%s' % x, mode='b') eNodeB1 = net.addAccessPoint('eNodeB1', ssid='eNodeB1', dpid='1000000000000000', mode='ac', channel='1', position='80,75,0', range=60) eNodeB2 = net.addAccessPoint('eNodeB2', ssid='eNodeB2', dpid='2000000000000000', mode='ac', channel='6', position='180,75,0', range=70) rsu1 = net.addAccessPoint('rsu1', ssid='rsu1', dpid='3000000000000000', mode='g', channel='11', position='140,120,0', range=40) c1 = net.addController('c1', controller=Controller) client = net.addHost('client') switch = net.addSwitch('switch', dpid='4000000000000000') net.plotNode(client, position='125,230,0') net.plotNode(switch, position='125,200,0') print "*** Configuring wifi nodes" net.configureWifiNodes() print "*** Creating links" net.addLink(eNodeB1, switch) net.addLink(eNodeB2, switch) net.addLink(rsu1, switch) net.addLink(switch, client) print "*** Starting network" net.build() c1.start() eNodeB1.start([c1]) eNodeB2.start([c1]) rsu1.start([c1]) switch.start([c1]) for sw in net.vehicles: sw.start([c1]) i = 1 j = 2 for c in car: c.cmd('ifconfig %s-wlan0 192.168.0.%s/24 up' % (c, i)) c.cmd('ifconfig %s-eth0 192.168.1.%s/24 up' % (c, i)) c.cmd('ip route add 10.0.0.0/8 via 192.168.1.%s' % j) i += 2 j += 2 i = 1 j = 2 for v in net.vehiclesSTA: v.cmd('ifconfig %s-eth0 192.168.1.%s/24 up' % (v, j)) v.cmd('ifconfig %s-mp0 10.0.0.%s/24 up' % (v, i)) v.cmd('echo 1 > /proc/sys/net/ipv4/ip_forward') i += 1 j += 2 for v1 in net.vehiclesSTA: i = 1 j = 1 for v2 in net.vehiclesSTA: if v1 != v2: v1.cmd('route add -host 192.168.1.%s gw 10.0.0.%s' % (j, i)) i += 1 j += 2 client.cmd('ifconfig client-eth0 200.0.10.2') car[0].cmd('ifconfig car0-wlan0 200.0.10.150') car[0].cmd('ifconfig car0-wlan1 200.0.10.100') client.cmd('ip route add 192.168.1.8 via 200.0.10.150') client.cmd('ip route add 10.0.0.1 via 200.0.10.150') #net.vehiclesSTA[0].cmd('ip route add 200.0.10.100 via 10.0.0.1') net.vehiclesSTA[0].cmd('ip route add 200.0.10.2 via 10.0.0.1') car[0].cmd('ip route add 200.0.10.2 via 200.0.10.150') car[0].cmd('ip route add 200.0.10.100 via 192.168.1.2') #car[0].cmd('ip route add 200.0.10.2 via 200.0.10.100') """plot graph""" net.plotGraph(max_x=250, max_y=250) net.startGraph() # Uncomment and modify the two commands below to stream video using VLC car[0].cmdPrint( "vlc -vvv bunnyMob.mp4 --sout '#duplicate{dst=rtp{dst=200.0.10.2,port=5004,mux=ts},dst=display}' :sout-keep &" ) client.cmdPrint("vlc rtp://@200.0.10.2:5004 &") car[0].moveNodeTo('95,100,0') car[1].moveNodeTo('80,100,0') car[2].moveNodeTo('65,100,0') car[3].moveNodeTo('50,100,0') os.system('ovs-ofctl del-flows switch') time.sleep(3) apply_experiment(car, client, switch) # Uncomment the line below to generate the graph that you implemented graphic() # kills all the xterms that have been opened os.system('pkill xterm') print "*** Running CLI" CLI(net) print "*** Stopping network" net.stop()
def topology(): print "Create a network." net = Mininet(controller=Controller, link=TCLink, accessPoint=OVSKernelAP) print "*** Creating nodes" cars = [] nodes = [] print "***Creating nodes" h1 = net.addHost('h1', mac='00:00:00:11:00:01', ip='10.0.0.1/8') nodes.append(h1) s1 = net.addSwitch('s1', mac='00:00:00:11:00:02') nodes.append(s1) for x in range(0, 5): cars.append(x) for x in range(0, 5): min_ = random.randint(1, 4) max_ = random.randint(11, 30) cars[x] = net.addCar('car%s' % (x + 1), wlans=1, ip='10.0.0.%s/8' % (x + 1), min_speed=min_, max_speed=max_, range=100) #nodes.append(car[x]) rsu11 = net.addAccessPoint('RSU11', ssid='RSU11', mode='g', channel='1') rsu12 = net.addAccessPoint('RSU12', ssid='RSU12', mode='g', channel='6') rsu13 = net.addAccessPoint('RSU13', ssid='RSU13', mode='g', channel='11') c1 = net.addController('c1', controller=Controller) print "*** Configuring Propagation Model" net.propagationModel(model="logDistance", exp=4.5) print "*** Configuring wifi nodes" net.configureWifiNodes() print "*** Associating and Creating links" net.addLink(s1, h1) net.addLink(rsu11, s1) net.addLink(rsu12, s1) net.addLink(rsu13, s1) for x in range(0, 5): net.addLink('car%s' % (x + 1), rsu11) net.plotGraph(max_x=500, max_y=500) net.roads(10) net.startMobility(time=20) print "*** Starting network" net.build() c1.start() rsu11.start([c1]) rsu12.start([c1]) rsu13.start([c1]) #rsu14.start([c1]) print('*** set flow tables ***\n') #call(["sudo", "bash","fa_ft.sh"]) i = 201 for sw in net.carsSW: sw.start([c1]) os.system('ip addr add 10.0.0.%s dev %s' % (i, sw)) i += 1 i = 1 j = 2 k = 1 for car in cars: car.setIP('192.168.0.%s/24' % k, intf='%s-wlan0' % car) car.setIP('192.168.1.%s/24' % i, intf='%s-eth1' % car) car.cmd('ip route add 10.0.0.0/8 via 192.168.1.%s' % j) i += 2 j += 2 k += 1 i = 1 j = 2 for carsta in net.carsSTA: carsta.setIP('10.0.0.%s/24' % i, intf='%s-mp0' % carsta) carsta.setIP('192.168.1.%s/24' % j, intf='%s-eth2' % carsta) #May be confuse, but it allows ping to the name instead of ip addr carsta.setIP('10.0.0.%s/24' % i, intf='%s-wlan0' % carsta) carsta.cmd('echo 1 > /proc/sys/net/ipv4/ip_forward') i += 1 j += 2 for carsta1 in net.carsSTA: i = 1 j = 1 for carsta2 in net.carsSTA: if carsta1 != carsta2: carsta1.cmd('route add -host 192.168.1.%s gw 10.0.0.%s' % (j, i)) i += 1 j += 2 print "*** Running CLI" CLI(net) print "*** Stopping network" net.stop()
def topology(): "Create a network." net = Mininet(controller=Controller, link=TCLink, accessPoint=UserAP, enable_wmediumd=True, enable_interference=True) print "*** Creating nodes" cars = [] stas = [] for x in range(0, 10): cars.append(x) stas.append(x) for x in range(0, 10): cars[x] = net.addCar('car%s' % (x), wlans=1, ip='10.0.0.%s/8' % (x + 1)) e1 = net.addAccessPoint('e1', ssid='vanet-ssid', mac='00:00:00:11:00:01', mode='g', channel='1', passwd='123456789a', encrypt='wpa2', position='3279.02,3736.27,0') e2 = net.addAccessPoint('e2', ssid='vanet-ssid', mac='00:00:00:11:00:02', mode='g', channel='6', passwd='123456789a', encrypt='wpa2', position='2320.82,3565.75,0') e3 = net.addAccessPoint('e3', ssid='vanet-ssid', mac='00:00:00:11:00:03', mode='g', channel='11', passwd='123456789a', encrypt='wpa2', position='2806.42,3395.22,0') e4 = net.addAccessPoint('e4', ssid='vanet-ssid', mac='00:00:00:11:00:04', mode='g', channel='1', passwd='123456789a', encrypt='wpa2', position='3332.62,3253.92,0') e5 = net.addAccessPoint('e5', ssid='vanet-ssid', mac='00:00:00:11:00:05', mode='g', channel='6', passwd='123456789a', encrypt='wpa2', position='2887.62,2935.61,0') e6 = net.addAccessPoint('e6', ssid='vanet-ssid', mac='00:00:00:11:00:06', mode='g', channel='11', passwd='123456789a', encrypt='wpa2', position='2351.68,3083.40,0') c1 = net.addController('c1', controller=Controller, ip='127.0.0.1', port=6653) net.propagationModel("logDistancePropagationLossModel", exp=2.5) print "*** Setting bgscan" net.setBgscan(signal=-45, s_inverval=5, l_interval=10) print "*** Configuring Propagation Model" net.propagationModel("logDistancePropagationLossModel", exp=2) print "*** Configuring wifi nodes" net.configureWifiNodes() net.addLink(e1, e2) net.addLink(e2, e3) net.addLink(e3, e4) net.addLink(e4, e5) net.addLink(e5, e6) "Available Options: sumo, sumo-gui" net.useExternalProgram('sumo-gui', config_file='map.sumocfg') print "*** Starting network" net.build() c1.start() e1.start([c1]) e2.start([c1]) e3.start([c1]) e4.start([c1]) e5.start([c1]) e6.start([c1]) i = 201 for sw in net.carsSW: sw.start([c1]) os.system('ifconfig %s 10.0.0.%s' % (sw, i)) i += 1 i = 1 j = 2 for car in cars: car.cmd('ifconfig %s-wlan0 192.168.0.%s/24 up' % (car, i)) car.cmd('ifconfig %s-eth0 192.168.1.%s/24 up' % (car, i)) car.cmd('ip route add 10.0.0.0/8 via 192.168.1.%s' % j) i += 2 j += 2 i = 1 j = 2 for v in net.carsSTA: v.cmd('ifconfig %s-eth0 192.168.1.%s/24 up' % (v, j)) v.cmd('ifconfig %s-mp0 10.0.0.%s/24 up' % (v, i)) v.cmd('echo 1 > /proc/sys/net/ipv4/ip_forward') i += 1 j += 2 for v1 in net.carsSTA: i = 1 j = 1 for v2 in net.carsSTA: if v1 != v2: v1.cmd('route add -host 192.168.1.%s gw 10.0.0.%s' % (j, i)) i += 1 j += 2 print "*** Running CLI" CLI(net) print "*** Stopping network" net.stop()
def topology(): "Create a network." net = Mininet(controller=Controller, link=TCLink, switch=OVSKernelSwitch) print "*** Creating nodes" car = [] stas = [] for x in range(0, 10): car.append(x) stas.append(x) for x in range(0, 10): car[x] = net.addCar('car%s' % (x), wlans=1, ip='10.0.0.%s/8' % (x + 1), mode='b', max_x=40, max_y=40, range=1000) rsu10 = net.addAccessPoint('rsu10', ssid='rsu10', mode='g', channel='1', position='3500,2500,0', range=500) rsu11 = net.addAccessPoint('rsu11', ssid='rsu11', mode='g', channel='6', position='3000,2500,0', range=500) rsu12 = net.addAccessPoint('rsu12', ssid='rsu12', mode='g', channel='11', position='2500,3000,0', range=500) rsu13 = net.addAccessPoint('rsu13', ssid='rsu13', mode='g', channel='11', position='4000,3000,0', range=500) rsu14 = net.addAccessPoint('rsu14', ssid='rsu14', mode='g', channel='11', position='4500,3000,0', range=500) c1 = net.addController('c1', controller=Controller, ip='127.0.0.1', port=6633) print "*** Configuring wifi nodes" net.configureWifiNodes() net.meshRouting('custom') net.addLink(rsu10, rsu11) net.addLink(rsu11, rsu12) net.addLink(rsu12, rsu13) net.addLink(rsu13, rsu14) """Available Options: sumo, sumo-gui""" # Put your sumocfg file in /mininet/sumo/data net.useExternalProgram('sumo-gui', config_file='map.sumocfg') print "*** Starting network" net.build() c1.start() rsu10.start([c1]) rsu11.start([c1]) rsu12.start([c1]) rsu13.start([c1]) rsu14.start([c1]) i = 201 for sw in net.vehicles: sw.start([c1]) os.system('ifconfig %s 10.0.0.%s' % (sw, i)) i += 1 i = 1 j = 2 for c in car: c.cmd('ifconfig %s-wlan0 192.168.0.%s/24 up' % (c, i)) c.cmd('ifconfig %s-eth0 192.168.1.%s/24 up' % (c, i)) c.cmd('ip route add 10.0.0.0/8 via 192.168.1.%s' % j) i += 2 j += 2 i = 1 j = 2 for v in net.vehiclesSTA: v.cmd('ifconfig %s-eth0 192.168.1.%s/24 up' % (v, j)) v.cmd('ifconfig %s-mp0 10.0.0.%s/24 up' % (v, i)) v.cmd('echo 1 > /proc/sys/net/ipv4/ip_forward') i += 1 j += 2 for v1 in net.vehiclesSTA: i = 1 j = 1 for v2 in net.vehiclesSTA: if v1 != v2: v1.cmd('route add -host 192.168.1.%s gw 10.0.0.%s' % (j, i)) i += 1 j += 2 print "*** Running CLI" CLI(net) print "*** Stopping network" net.stop()
def topology(): "Create a network." net = Mininet(controller=Controller, link=TCLink, switch=OVSKernelSwitch) print "*** Creating nodes" car = [] stas = [] for x in range(0, 10): car.append(x) stas.append(x) for x in range(0, 10): min = random.randint(1, 10) max = random.randint(11, 30) car[x] = net.addCar('car%s' % (x + 1), wlans=1, ip='10.0.0.%s/8' % (x + 1), min_speed=min, max_speed=max, range=50) rsu11 = net.addAccessPoint('RSU11', ssid='RSU11', mode='g', channel='1', range=100) rsu12 = net.addAccessPoint('RSU12', ssid='RSU12', mode='g', channel='6', range=100) rsu13 = net.addAccessPoint('RSU13', ssid='RSU13', mode='g', channel='11', range=100) rsu14 = net.addAccessPoint('RSU14', ssid='RSU14', mode='g', channel='11', range=100) c1 = net.addController('c1', controller=Controller) print "*** Configuring wifi nodes" net.configureWifiNodes() net.meshRouting('custom') print "*** Associating and Creating links" net.addLink(rsu11, rsu12) net.addLink(rsu11, rsu13) net.addLink(rsu11, rsu14) print "*** Starting network" net.build() c1.start() rsu11.start([c1]) rsu12.start([c1]) rsu13.start([c1]) rsu14.start([c1]) i = 201 for sw in net.vehicles: sw.start([c1]) os.system('ifconfig %s 10.0.0.%s' % (sw, i)) i += 1 """uncomment to plot graph""" net.plotGraph(max_x=500, max_y=500) """Number of Roads""" net.roads(20) """Start Mobility""" net.startMobility(startTime=0) i = 1 j = 2 k = 1 for c in car: c.cmd('ifconfig %s-wlan0 192.168.0.%s/24 up' % (c, k)) c.cmd('ifconfig %s-eth0 192.168.1.%s/24 up' % (c, i)) c.cmd('ip route add 10.0.0.0/8 via 192.168.1.%s' % j) i += 2 j += 2 k += 1 i = 1 j = 2 for v in net.vehiclesSTA: v.cmd('ifconfig %s-eth0 192.168.1.%s/24 up' % (v, j)) v.cmd('ifconfig %s-mp0 10.0.0.%s/24 up' % (v, i)) v.cmd('echo 1 > /proc/sys/net/ipv4/ip_forward') i += 1 j += 2 for v1 in net.vehiclesSTA: i = 1 j = 1 for v2 in net.vehiclesSTA: if v1 != v2: v1.cmd('route add -host 192.168.1.%s gw 10.0.0.%s' % (j, i)) i += 1 j += 2 print "*** Running CLI" CLI(net) print "*** Stopping network" net.stop()
def topology(): "Create a network." net = Mininet(controller=RemoteController, link=TCLink, switch=OVSKernelSwitch, accessPoint=OVSKernelAP) global gnet gnet = net print "*** Creating nodes " car = [] stas = [] for x in range(0, 4): car.append(x) stas.append(x) for x in range(0, 4): car[x] = net.addCar('car%s' % (x), wlans=2, ip='10.0.0.%s/8' % (x + 1), \ mac='00:00:00:00:00:0%s' % x, mode='b') eNodeB1 = net.addAccessPoint('eNodeB1', ssid='eNodeB1', dpid='1000000000000000', mode='ac', channel='1', position='80,75,0', range=60) eNodeB2 = net.addAccessPoint('eNodeB2', ssid='eNodeB2', dpid='2000000000000000', mode='ac', channel='6', position='180,75,0', range=70) rsu1 = net.addAccessPoint('rsu1', ssid='rsu1', dpid='3000000000000000', mode='g', channel='11', position='140,120,0', range=40) c1 = net.addController('c1', controller=RemoteController) client = net.addHost('client') switch = net.addSwitch('switch', dpid='4000000000000000') net.plotNode(client, position='125,230,0') net.plotNode(switch, position='125,200,0') print "*** Configuring wifi nodes" net.configureWifiNodes() print "*** Creating links " net.addLink(eNodeB1, switch) net.addLink(eNodeB2, switch) net.addLink(rsu1, switch) net.addLink(switch, client) print "*** Starting network" net.build() c1.start() eNodeB1.start([c1]) eNodeB2.start([c1]) rsu1.start([c1]) switch.start([c1]) for sw in net.vehicles: sw.start([c1]) print "*** Configuring interfaces " i = 1 j = 2 for c in car: c.cmd('ifconfig %s-wlan0 192.168.0.%s/24 up' % (c, i)) c.cmd('ifconfig %s-eth0 192.168.1.%s/24 up' % (c, i)) c.cmd('ip route add 10.0.0.0/8 via 192.168.1.%s' % j) i += 2 j += 2 i = 1 j = 2 for v in net.vehiclesSTA: v.cmd('ifconfig %s-eth0 192.168.1.%s/24 up' % (v, j)) v.cmd('ifconfig %s-mp0 10.0.0.%s/24 up' % (v, i)) v.cmd('echo 1 > /proc/sys/net/ipv4/ip_forward') i += 1 j += 2 for v1 in net.vehiclesSTA: i = 1 j = 1 for v2 in net.vehiclesSTA: if v1 != v2: v1.cmd('route add -host 192.168.1.%s gw 10.0.0.%s' % (j, i)) i += 1 j += 2 client.cmd('ifconfig client-eth0 200.0.10.2') net.vehiclesSTA[0].cmd('ifconfig car0STA-eth0 200.0.10.50') # Bonding interfaces for car0 car[0].cmd('modprobe bonding mode=3') car[0].cmd('ip link add bond0 type bond') car[0].cmd('ip link set bond0 address 02:01:02:03:04:08') car[0].cmd('ip link set car0-eth0 down') car[0].cmd('ip link set car0-eth0 address 00:00:00:00:00:11') car[0].cmd('ip link set car0-eth0 master bond0') car[0].cmd('ip link set car0-wlan0 down') car[0].cmd('ip link set car0-wlan0 address 00:00:00:00:00:15') car[0].cmd('ip link set car0-wlan0 master bond0') car[0].cmd('ip link set car0-wlan1 down') car[0].cmd('ip link set car0-wlan1 address 00:00:00:00:00:13') car[0].cmd('ip link set car0-wlan1 master bond0') car[0].cmd('ip addr add 200.0.10.100/24 dev bond0') car[0].cmd('ip link set bond0 up') # more configuring and routing commands car[3].cmd('ifconfig car3-wlan0 200.0.10.150') client.cmd('ip route add 192.168.1.8 via 200.0.10.150') client.cmd('ip route add 10.0.0.1 via 200.0.10.150') net.vehiclesSTA[3].cmd('ip route add 200.0.10.2 via 192.168.1.7') net.vehiclesSTA[3].cmd('ip route add 200.0.10.100 via 10.0.0.1') net.vehiclesSTA[0].cmd('ip route add 200.0.10.2 via 10.0.0.4') car[0].cmd('ip route add 10.0.0.4 via 200.0.10.50') car[0].cmd('ip route add 192.168.1.7 via 200.0.10.50') #car[0].cmd('ip route add 200.0.10.2 via 200.0.10.50') #car[3].cmd('ip route add 200.0.10.100 via 192.168.1.8') car[0].cmdPrint( "xterm -xrm 'XTerm.vt100.allowTitleOps: false' -T 'car0' &") #car[3].cmdPrint("xterm -xrm 'XTerm.vt100.allowTitleOps: false' -T 'car3' &") client.cmdPrint( "xterm -xrm 'XTerm.vt100.allowTitleOps: false' -T 'client' &") """plot graph""" net.plotGraph(max_x=250, max_y=250) net.startGraph() # remove previous data os.system('rm *.vanetdata') # stream video using VLC car[0].cmdPrint( "vlc -vvv /home/mininet/Desktop/bunnyMob.mp4 --sout '#duplicate{dst=rtp{dst=200.0.10.2,port=5004,mux=ts},dst=display}' :sout-keep &" ) client.cmdPrint("vlc rtp://@200.0.10.2:5004 &") # starting positions for cars car[0].moveNodeTo('110,100,0') car[1].moveNodeTo('80,100,0') car[2].moveNodeTo('65,100,0') car[3].moveNodeTo('50,100,0') # delete all previous flow rules #os.system('ovs-ofctl del-flows switch') # sleep... #time.sleep(3) # start experiment, 20 secs for each phase apply_experiment(car, client, switch) # Uncomment the line below to generate the graph that you implemented graphic() # kills all the xterms that have been opened #os.system('pkill xterm') print "*** Running CLI" CLI(net) print "*** Stopping network" net.stop()
def topology(): "Create a network." net = Mininet(controller=Controller, link=TCLink, switch=OVSKernelSwitch, accessPoint=OVSKernelAP) global gnet gnet = net print "*** Creating nodes" car = [] stas = [] for x in range(0, 4): car.append(x) stas.append(x) for x in range(0, 4): car[x] = net.addCar('car%s' % (x), wlans=2, ip='10.0.0.%s/8' % (x + 1), \ mac='00:00:00:00:00:0%s' % x, mode='b') eNodeB1 = net.addAccessPoint('eNodeB1', ssid='eNodeB1', dpid='1000000000000000', mode='ac', channel='1', position='80,75,0', range=60) eNodeB2 = net.addAccessPoint('eNodeB2', ssid='eNodeB2', dpid='2000000000000000', mode='ac', channel='6', position='180,75,0', range=70) rsu1 = net.addAccessPoint('rsu1', ssid='rsu1', dpid='3000000000000000', mode='g', channel='11', position='140,120,0', range=40) c1 = net.addController('c1', controller=Controller) client = net.addHost ('client') switch = net.addSwitch ('switch', dpid='4000000000000000') net.plotNode(client, position='125,230,0') net.plotNode(switch, position='125,200,0') print "*** Configuring wifi nodes" net.configureWifiNodes() print "*** Creating links" net.addLink(eNodeB1, switch) net.addLink(eNodeB2, switch) net.addLink(rsu1, switch) net.addLink(switch, client) print "*** Starting network" net.build() c1.start() eNodeB1.start([c1]) eNodeB2.start([c1]) rsu1.start([c1]) switch.start([c1]) for sw in net.vehicles: sw.start([c1]) i = 1 j = 2 for c in car: c.cmd('ifconfig %s-wlan0 192.168.0.%s/24 up' % (c, i)) c.cmd('ifconfig %s-eth0 192.168.1.%s/24 up' % (c, i)) c.cmd('ip route add 10.0.0.0/8 via 192.168.1.%s' % j) i += 2 j += 2 i = 1 j = 2 for v in net.vehiclesSTA: v.cmd('ifconfig %s-eth0 192.168.1.%s/24 up' % (v, j)) v.cmd('ifconfig %s-mp0 10.0.0.%s/24 up' % (v, i)) v.cmd('echo 1 > /proc/sys/net/ipv4/ip_forward') i += 1 j += 2 for v1 in net.vehiclesSTA: i = 1 j = 1 for v2 in net.vehiclesSTA: if v1 != v2: v1.cmd('route add -host 192.168.1.%s gw 10.0.0.%s' % (j, i)) i += 1 j += 2 client.cmd('ifconfig client-eth0 200.0.10.2') net.vehiclesSTA[0].cmd('ifconfig car0STA-eth0 200.0.10.50') car[0].cmd('modprobe bonding mode=3') car[0].cmd('ip link add bond0 type bond') car[0].cmd('ip link set bond0 address 02:01:02:03:04:08') car[0].cmd('ip link set car0-eth0 down') car[0].cmd('ip link set car0-eth0 address 00:00:00:00:00:11') car[0].cmd('ip link set car0-eth0 master bond0') car[0].cmd('ip link set car0-wlan0 down') car[0].cmd('ip link set car0-wlan0 address 00:00:00:00:00:15') car[0].cmd('ip link set car0-wlan0 master bond0') car[0].cmd('ip link set car0-wlan1 down') car[0].cmd('ip link set car0-wlan1 address 00:00:00:00:00:13') car[0].cmd('ip link set car0-wlan1 master bond0') car[0].cmd('ip addr add 200.0.10.100/24 dev bond0') car[0].cmd('ip link set bond0 up') car[3].cmd('ifconfig car3-wlan0 200.0.10.150') client.cmd('ip route add 192.168.1.8 via 200.0.10.150') client.cmd('ip route add 10.0.0.1 via 200.0.10.150') net.vehiclesSTA[3].cmd('ip route add 200.0.10.2 via 192.168.1.7') net.vehiclesSTA[3].cmd('ip route add 200.0.10.100 via 10.0.0.1') net.vehiclesSTA[0].cmd('ip route add 200.0.10.2 via 10.0.0.4') car[0].cmd('ip route add 10.0.0.4 via 200.0.10.50') car[0].cmd('ip route add 192.168.1.7 via 200.0.10.50') car[0].cmd('ip route add 200.0.10.2 via 200.0.10.50') car[3].cmd('ip route add 200.0.10.100 via 192.168.1.8') """plot graph""" net.plotGraph(max_x=250, max_y=250) net.startGraph() # STREAMING commands car[0].cmdPrint("cvlc -vvv bunnyMob.mp4 --sout '#duplicate{dst=rtp{dst=200.0.10.2,port=5004,mux=ts},dst=display}' :sout-keep &") car[0].cmdPrint("echo $!") # PID of latest bg process client.cmdPrint("cvlc rtp://200.0.10.2:5004/bunnyMob.mp4 &") client.cmdPrint("echo $!") car[0].moveNodeTo('95,100,0') car[1].moveNodeTo('80,100,0') car[2].moveNodeTo('65,100,0') car[3].moveNodeTo('50,100,0') os.system('ovs-ofctl del-flows switch') time.sleep(3) #apply_experiment(car,client,switch,net) # DOKIMH XWRIS FUNCTION time.sleep(2) print "Applying first phase" os.system('ovs-ofctl mod-flows switch in_port=1,actions=output:4') os.system('ovs-ofctl mod-flows switch in_port=4,actions=output:1') car[0].cmd('ip route add 200.0.10.2 via 200.0.10.50') client.cmd('ip route add 200.0.10.100 via 200.0.10.150') #me aftes edw tis entoles pane ta mhnymata #gia kapoio logo de tis dexetai mesa apo python #client.cmd('ip route add 200.0.10.100 via 200.0.10.2') #car[0].cmd('ip route add 200.0.10.2 via 200.0.10.100') CLI(net)#kanw xterm client ,car0 kai tis prosthetw #ifconfig output gathering #~ t_end = time.time() + 21 #gia 20 seconds #~ print time.time() print "ifonfig output gathering" t_simulation = 0 while t_simulation < 20: car[0].cmd('ifconfig bond0 | grep \"TX packets\" >> %s' % packets_t_car0) car[0].cmd('ifconfig bond0 | grep \"TX bytes\" >> %s' % bytes_t_car0) car[3].cmd('ifconfig car3-eth0 | grep \"RX packets\" >> %s' % packets_r_car3) car[3].cmd('ifconfig car3-eth0 | grep \"RX bytes\" >> %s' % bytes_r_car3) car[3].cmd('ifconfig car3-wlan0 | grep \"TX packets\" >> %s' % packets_t_car3) car[3].cmd('ifconfig car3-wlan0 | grep \"TX bytes\" >> %s' % bytes_t_car3) client.cmd('ifconfig client-eth0 | grep \"RX packets\" >> %s' % packets_r_client) client.cmd('ifconfig client-eth0 | grep \"RX bytes\" >> %s' % bytes_r_client) time.sleep(1) t_simulation=t_simulation+1 #iperf output gathering client.cmdPrint('iperf -s -u -i 1 > %s &' % iperf_out_srv) car[0].cmdPrint('iperf -u -i 1 -t 20 -c 200.0.10.2') #client.cmdPrint('sudo kill -9 $!') #skotwnw th diergasia tou iperf ston client #ping output gathering #~ car[3].cmd('ping -t 1 -c 20 200.0.10.100 > %s' % ping_v2v) #ping sto car3->car0 #~ car[3].cmd('ping -t 1 -c 20 200.0.10.2 > %s' % ping_v2i) #ping sto car3->client car[0].cmd('ping -t 1 -c 20 200.0.10.2 > %s' % car0_pings_client) client.cmd('ping -t 1 -c 20 200.0.10.100 > %s' % client_pings_car0) graphic1() print "xterm client -> sudo kill -9 <client_iperf_bg_process_PID>" CLI(net) #end of phase 1 print "Moving nodes" car[0].moveNodeTo('150,100,0') car[1].moveNodeTo('120,100,0') car[2].moveNodeTo('90,100,0') car[3].moveNodeTo('70,100,0') time.sleep(2) print "Applying second phase" os.system('ovs-ofctl del-flows switch') os.system('ovs-ofctl mod-flows switch in_port=2,actions=output:4') os.system('ovs-ofctl mod-flows switch in_port=4,actions=output:2') os.system('ovs-ofctl mod-flows switch in_port=3,actions=output:4') os.system('ovs-ofctl mod-flows switch in_port=4,actions=output:3') #~ mallon prepei ksana xterm client car0 kai tis parakatw #~ client.cmd('route add -host 200.0.10.100 gw 200.0.10.2') #~ car[0].cmd('route add -host 200.0.10.2 gw 200.0.10.100') #~ telika tis eixe akomh perasmenes apo to prohgoumeno xterm client car0 print "ifonfig output gathering" t_simulation = 0 while t_simulation < 20: car[0].cmd('ifconfig bond0 | grep \"TX packets\" >> %s' % packets2_t_car0) car[0].cmd('ifconfig bond0 | grep \"TX bytes\" >> %s' % bytes2_t_car0) client.cmd('ifconfig client-eth0 | grep \"RX packets\" >> %s' % packets2_r_client) client.cmd('ifconfig client-eth0 | grep \"RX bytes\" >> %s' % bytes2_r_client) time.sleep(1) t_simulation=t_simulation+1 print 'iperf output gathering' #CLI(net) client.cmdPrint('iperf -s -u -i 1 > %s &' % iperf2_out_srv) car[0].cmdPrint('iperf -u -i 1 -t 20 -c 200.0.10.2') #client.cmdPrint('sudo kill -9 $!') #skotwnw th diergasia tou iperf ston client print 'ping output gathering' #~ car[3].cmd('ping -t 1 -c 20 200.0.10.100 > %s' % ping_v2v) #ping sto car3->car0 #~ car[3].cmd('ping -t 1 -c 20 200.0.10.2 > %s' % ping_v2i) #ping sto car3->client car[0].cmd('ping -t 1 -c 20 200.0.10.2 > %s' % car0_pings2_client) client.cmd('ping -t 1 -c 20 200.0.10.100 > %s' % client_pings2_car0) graphic2() time.sleep(2) ################################################################################# print "Moving nodes" car[0].moveNodeTo('190,100,0') car[1].moveNodeTo('150,100,0') car[2].moveNodeTo('120,100,0') car[3].moveNodeTo('90,100,0') time.sleep(2) print "Applying third phase" ################################################################################ # 1) Add the flow rules below and routing commands if needed os.system('ovs-ofctl del-flows switch') os.system('ovs-ofctl mod-flows switch in_port=2,actions=output:4') os.system('ovs-ofctl mod-flows switch in_port=4,actions=output:2') # 2) Calculate Network Measurements using IPerf or command line tools(ifconfig) # Hint: Remember that you can insert commands via the mininet # Example: car[0].cmd('ifconfig bond0 | grep \"TX packets\" >> %s' % output.data) print "*** CLI 3 *** -- check if streaming is happening(eNodeB2 only) (car0 ping client)" print "ifonfig output gathering" t_simulation = 0 while t_simulation < 20: car[0].cmd('ifconfig bond0 | grep \"TX packets\" >> %s' % packets3_t_car0) car[0].cmd('ifconfig bond0 | grep \"TX bytes\" >> %s' % bytes3_t_car0) client.cmd('ifconfig client-eth0 | grep \"RX packets\" >> %s' % packets3_r_client) client.cmd('ifconfig client-eth0 | grep \"RX bytes\" >> %s' % bytes3_r_client) time.sleep(1) t_simulation=t_simulation+1 print 'iperf output gathering' CLI(net) client.cmdPrint('iperf -s -u -i 1 > %s &' % iperf3_out_srv) car[0].cmdPrint('iperf -u -i 1 -t 20 -c 200.0.10.2') #client.cmdPrint('sudo kill -9 $!') #skotwnw th diergasia tou iperf ston client print 'ping output gathering' #~ car[3].cmd('ping -t 1 -c 20 200.0.10.100 > %s' % ping_v2v) #ping sto car3->car0 #~ car[3].cmd('ping -t 1 -c 20 200.0.10.2 > %s' % ping_v2i) #ping sto car3->client car[0].cmd('ping -t 1 -c 20 200.0.10.2 > %s' % car0_pings3_client) client.cmd('ping -t 1 -c 20 200.0.10.100 > %s' % client_pings3_car0) # Uncomment the line below to generate the graph that you implemented graphic3() # time.sleep(5) #na prolavei na fortwsei ta figures # kills all the xterms that have been opened # os.system('pkill xterm') # print "*** Running CLI" print "last CLI before closing" CLI(net) print "*** Stopping network" net.stop()