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 = 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_wifi(controller=Vanet_controller, accessPoint=UserAP, switch=SD_Car_Switch, station=SD_station,link=wmediumd, wmediumd_mode=interference) 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), encrypt='wpa2', cls=car_type) e1 = net.addAccessPoint('e1', wlans=2, 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, inNamespace=True) e2 = net.addAccessPoint('e2', wlans=2, 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, inNamespace=True) e3 = net.addAccessPoint('e3', wlans=2, 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, inNamespace=True) e4 = net.addAccessPoint('e4', wlans=2, 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, inNamespace=True) e5 = net.addAccessPoint('e5', wlans=2, 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, inNamespace=True) e6 = net.addAccessPoint('e6', wlans=2, 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, inNamespace=True) 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) # "logDistancePropagationLossModel" net.propagationModel(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)""" net.addLink(e1, intf = 'e1-wlan2', cls=mesh, ssid='mesh-ssid') net.addLink(e2, intf = 'e2-wlan2', cls=mesh, ssid='mesh-ssid') net.addLink(e3, intf = 'e3-wlan2', cls=mesh, ssid='mesh-ssid') net.addLink(e4, intf = 'e4-wlan2', cls=mesh, ssid='mesh-ssid') net.addLink(e5, intf = 'e5-wlan2', cls=mesh, ssid='mesh-ssid') net.addLink(e6, intf = 'e6-wlan2', cls=mesh, ssid='mesh-ssid') "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.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 # Assigning IPs for Access points wlan interfaces IPs = ['90','91','92','93','94','95','96'] for i in range(0,6): net.aps[i].cmd('ifconfig e%s-wlan1 192.168.0.%s'%(i+1,IPs[i])) net.aps[i].cmd('ifconfig e%s-mp2 192.168.2.%s'%(i+1,i+1)) net.aps[i].extIP = '192.168.0.%s'%(IPs[i]) c1.initializeNetworkResources(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_wifi(net) print ("*** Stopping network") net.stop()
def topology(): taskTime = 20 ncars = 4 "Create a network." net = Mininet_wifi(controller=Controller, switch=OVSKernelSwitch, accessPoint=OVSKernelAP) print("*** Creating nodes") cars = [] stas = [] for idx in range(0, ncars): cars.append(idx) stas.append(idx) for idx in range(0, ncars): cars[idx] = net.addCar('car%s' % idx, wlans=2, ip='10.0.0.%s/8' % (idx + 1), range="50,50", mac='00:00:00:00:00:0%s' % idx, mode='b', position='%d,%d,0' % ((120 - (idx * 20)), (100 - (idx * 0)))) eNodeB1 = net.addAccessPoint('eNodeB1', ssid='eNodeB1', dpid='1000000000000000', mode='ac', channel='36', position='80,75,0') eNodeB2 = net.addAccessPoint('eNodeB2', ssid='eNodeB2', dpid='2000000000000000', mode='ac', channel='40', 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') client.plot(position='125,230,0') switch.plot(position='125,200,0') print("*** Configuring Propagation Model") net.propagationModel(model="logDistance", exp=4.1) 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, cars[0]) net.addLink(eNodeB2, cars[0]) net.addLink(eNodeB1, cars[3]) 'Plotting Graph' net.plotGraph(max_x=250, max_y=250) print("*** Starting network") net.build() c1.start() eNodeB1.start([c1]) eNodeB2.start([c1]) rsu1.start([c1]) switch.start([c1]) for sw in net.carsSW: sw.start([c1]) 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-eth2' % car) car.cmd('ip route add 10.0.0.0/8 via 192.168.1.%s' % j) car.cmd('echo 1 > /proc/sys/net/ipv4/ip_forward') 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-eth3' % 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 client.cmd('ifconfig client-eth0 200.0.10.2') net.carsSTA[0].cmd('ifconfig car0STA-eth3 200.0.10.50') cars[0].cmd('modprobe bonding mode=3') cars[0].cmd('ip link add bond0 type bond') cars[0].cmd('ip link set bond0 address 02:01:02:03:04:08') cars[0].cmd('ip link set car0-eth2 down') cars[0].cmd('ip link set car0-eth2 address 00:00:00:00:00:11') cars[0].cmd('ip link set car0-eth2 master bond0') cars[0].cmd('ip link set car0-wlan0 down') cars[0].cmd('ip link set car0-wlan0 address 00:00:00:00:00:15') cars[0].cmd('ip link set car0-wlan0 master bond0') cars[0].cmd('ip link set car0-wlan1 down') cars[0].cmd('ip link set car0-wlan1 address 00:00:00:00:00:13') cars[0].cmd('ip link set car0-wlan1 master bond0') cars[0].cmd('ip addr add 200.0.10.100/24 dev bond0') cars[0].cmd('ip link set bond0 up') cars[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.carsSTA[3].cmd('ip route add 200.0.10.2 via 192.168.1.7') net.carsSTA[3].cmd('ip route add 200.0.10.100 via 10.0.0.1') net.carsSTA[0].cmd('ip route add 200.0.10.2 via 10.0.0.4') cars[0].cmd('ip route add 10.0.0.4 via 200.0.10.50') cars[0].cmd('ip route add 192.168.1.7 via 200.0.10.50') cars[0].cmd('ip route add 200.0.10.2 via 200.0.10.50') cars[3].cmd('ip route add 200.0.10.100 via 192.168.1.8') os.system('rm *.vanetdata') #os.system('xterm -hold -title "car0" -e "util/m car0 ping 200.0.10.2" &') cars[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') cars[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') kernel = 0 var = client.cmd('ifconfig client-eth0 | grep \"bytes\" | awk -F\' \' \'NR==1{print $5}\'') if var: kernel = 1 timeout = time.time() + taskTime currentTime = time.time() i = 0 while True: if time.time() > timeout: break if time.time() - currentTime >= i: recordValues(cars[0], client, kernel) i += 0.5 print("Moving nodes") cars[0].setPosition('150,100,0') cars[1].setPosition('120,100,0') cars[2].setPosition('90,100,0') cars[3].setPosition('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') cars[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: recordValues(cars[0], client, kernel) i += 0.5 print("Moving nodes") cars[0].setPosition('190,100,0') cars[1].setPosition('150,100,0') cars[2].setPosition('120,100,0') cars[3].setPosition('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: recordValues(cars[0], client, kernel) i += 0.5 print("*** Generating graph") graphic() os.system('pkill -f vlc') os.system('pkill xterm') print("*** Running CLI") CLI_wifi(net) #os.system('rm *.vanetdata') print("*** Stopping network") net.stop()
def topology(): "Create a network." net = Mininet_wifi(controller=Controller, switch=OVSKernelSwitch, enable_wmediumd=True, enable_interference=True) info("*** Creating nodes\n") 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_) 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') rsu14 = net.addAccessPoint('RSU14', ssid='RSU14', mode='g', channel='11') c1 = net.addController('c1', controller=Controller) info("*** Configuring Propagation Model\n") net.propagationModel(model="logDistance", exp=4.5) info("*** Configuring wifi nodes\n") net.configureWifiNodes() info("*** Associating and Creating links\n") 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) info("*** Starting network\n") 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-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 info("*** Running CLI\n") CLI_wifi(net) info("*** Stopping network\n") net.stop()
def topology(): "Create a network." net = Mininet_wifi(controller=Controller, accessPoint=UserAP, link=wmediumd, enable_interference=True) info("*** Creating nodes\n") 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=6633) net.propagationModel(model="logDistance", exp=2.5) info("*** Setting bgscan\n") net.setBgscan(signal=-45, s_inverval=5, l_interval=10) info("*** Configuring Propagation Model\n") net.propagationModel(model="logDistance", exp=2) info("*** Configuring wifi nodes\n") net.configureWifiNodes() net.addLink(e1, e2) net.addLink(e2, e3) net.addLink(e3, e4) net.addLink(e4, e5) net.addLink(e5, e6) net.useExternalProgram('sumo-gui', config_file='map.sumocfg') info("*** Starting network\n") 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 info("*** Running CLI\n") CLI_wifi(net) info("*** Stopping network\n") net.stop()
def build_vndn(vndnTopo, ssid, channel, mode, wmediumd, interference, cluster, placement, servers, tunnelType, ctime, nPings, pctTraffic, experimentName, nlsrSecurity): """Create an ad hoc network from a topology object At the end of this function, everything should be connected and up.. adhocTopo:topology object that be builded according to a file of network topology configure; isManet: mobile ad hoc network; isAdhoc: stationary ad hoc network; channel: channel parames; ssid: service set identifier; wmedimd:param for 802.11 simulation tool; interferce:param for 802.11 simulation tool; placement: servers: tunnelType: the following paramters are for experiments. ctime: specific time that the nentwork covergence; nPings: number that perform """ t = datetime.datetime.now() cls = Association cls.printCon = False #<<<<<<< HEAD # vndn = Mininet(host=NdnHost, station=NdnStation, car=NdnCar, controller=Controller, switch=OVSKernelSwitch, ssid=ssid, channel=channel, #======= vndn = Mininet_wifi( host=NdnHost, station=NdnStation, car=NdnCar, controller=Controller, switch=OVSKernelSwitch, ssid=ssid, channel=channel, #>>>>>>> 43eaca4746df52b3eec2b5d2a3bd70a1afb8ae2b mode=mode, enable_wmediumd=wmediumd, enable_interference=interference) # Possibly we should clean up here and/or validate # the topo #if vndn.cleanup: # pass info('*** Creating ndn based vehicle network\n') if not vndn.controllers and vndn.controller: # Add a default controller info('*** Adding controller\n') classes = vndn.controller if not isinstance(classes, list): classes = [classes] for i, cls in enumerate(classes): # Allow Controller objects because nobody understands partial() if isinstance(cls, Controller): vndn.addController(cls) else: vndn.addController('c%d' % i, cls) info('c%d' % i) info('\n*** Adding cars and car stations:\n') x = 0 for carName in vndnTopo.hosts(): min = random.randint(1, 5) max = random.randint(5, 15) if 'car' in str(carName): vndn.addCar(carName, ip='10.0.0.%s/8' % (x + 1), wlans=1, range='100', min_speed=min, max_speed=max, **vndnTopo.nodeInfo(carName)) else: vndn.addHost(carName, **vndnTopo.nodeInfo(carName)) x = x + 1 info(carName + ' ') info('\n*** Adding Road Sides Units:\n') channelValueList = [1, 6, 11] i = 0 for accessPointName in vndnTopo.switches(): # A bit ugly: add batch parameter if appropriate i = i + 1 #randomly select a channel value channelValue = channelValueList[random.randint( 0, len(channelValueList) - 1)] params = vndnTopo.nodeInfo(accessPointName) cls = params.get('cls', vndn.accessPoint) if hasattr(cls, 'batchStartup'): params.setdefault('batch', True) if 'rsu' in str(accessPointName): vndn.addAccessPoint(accessPointName, ssid="RSU1%s" % i, range='50', mode='g', channel='%s' % channelValue, **params) else: vndn.addSwitch(accessPointName, **params) info(accessPointName + ' ') info(accessPointName + ' ') info('\n*** Configuring propagation model...\n') # this code line must be put here vndn.propagationModel(model="logDistance", exp=4.5) #Only can use this propagation model info('\n*** Configuring wifi nodes...\n') vndn.configureWifiNodes() info('\n*** Adding links......\n') for srcName, dstName, params in vndnTopo.links(sort=True, withInfo=True): vndn.addLink(**params) info('(%s, %s) ' % (srcName, dstName)) info('\n') print "*** Starting network" vndn.plotGraph(max_x=500, max_y=500) """Number of Roads""" vndn.roads(10) """Start Mobility""" # this code line must be put here vndn.startMobility(startTime=0) print "start network......" vndn.build() vndn.controllers[0].start() for rsu in vndn.accessPoints: rsu.start(vndn.controllers) i = 201 for sw in vndn.carsSW: sw.start(vndn.controllers) os.system('ip addr add 10.0.0.%s dev %s' % (i, sw)) i += 1 i = 1 j = 2 k = 1 for car in vndn.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 vndn.carsSTA: v.setIP('192.168.1.%s/24' % j, intf='%s-eth0' % v) v.setIP('10.0.0.%s/24' % i, intf='%s-wlan0' % v) #This is for v2v communication in ad hoc mode v.cmd('echo 1 > /proc/sys/net/ipv4/ip_forward') i += 1 j += 2 for v1 in vndn.carsSTA: i = 1 j = 1 for v2 in vndn.carsSTA: if v1 != v2: v1.cmd('route add -host 192.168.1.%s gw 10.0.0.%s' % (j, i)) i += 1 j += 2 # Load experiment if experimentName is not None: print("Loading experiment: %s" % experimentName) experimentArgs = { "isWiFi": True, "isVndn": True, "isSumoVndn": False, "net": vndn, "ctime": ctime, "nPings": nPings, "strategy": Nfd.STRATEGY_BEST_ROUTE, "pctTraffic": pctTraffic, "nlsrSecurity": nlsrSecurity } experiment = WifiExperimentManager.create(experimentName, experimentArgs) if experiment is not None: experiment.start() else: print("ERROR: Experiment '%s' does not exist" % experimentName) return """Running CLI.....""" MiniNdnWifiCLI(vndn) print "*** Stopping network" vndn.stop() print('Cleaning up...') call(["nfd-stop"]) call(["sudo", "mn", "--clean"]) sys.exit(1)
def topology(): "Create a network." net = Mininet_wifi(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=100) rsu11 = net.addAccessPoint('RSU11', ssid='RSU11', mode='g', channel='1', range=50,position='150,200,0') rsu12 = net.addAccessPoint('RSU12', ssid='RSU12', mode='g', channel='6', range=50, position= '450,350,0') rsu13 = net.addAccessPoint('RSU13', ssid='RSU13', mode='g', channel='11', range=50, position= '300,100,0') rsu14 = net.addAccessPoint('RSU14', ssid='RSU14', mode='g', channel='11', range=50, position= '300,300,0') rsu15 = net.addAccessPoint('RSU15', ssid='RSU15', mode='g', channel='11', range=50, position= '100,350,0') c1 = net.addController('c1', controller=Controller) print "*** Configuring Propagation Model" net.propagationModel("logDistancePropagationLossModel", exp=4) print "*** Configuring wifi nodes" net.configureWifiNodes() print "*** Associating and Creating links" net.addLink(rsu11, rsu12) net.addLink(rsu11, rsu13) net.addLink(rsu11, rsu14) net.addLink(rsu11, rsu15) print "asdfasdfasdfasdfalsdjfalsdfjasldfkajsldkfjalsdfjalsdfjasldkfjalsdkfjalsdkfasldkfasldfkjasl" net.plotGraph(max_x=500, max_y=500) net.startMobility(time=0, model='RandomWayPoint', max_x=500, max_y=400, min_v=0.1, max_v=0.2) 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.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.setIP('ifconfig lo: 127.0.0.1 netmask 255.0.0.0 up') 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_wifi(net) print "*** Stopping network" net.stop()
def topology(): ncars = 3 "Create a network." net = Mininet_wifi(controller=None, autoStaticArp=True, switch=OVSKernelSwitch, accessPoint=OVSKernelAP) c1 = net.addController('c1', controller=RemoteController, ip='127.0.0.1', port=6633) print("*** Creating nodes") cars = [] stas = [] for idx in range(0, ncars): cars.append(idx) stas.append(idx) #for idx in range(0, ncars): cars[0] = net.addCar('car0', wlans=1, range='30', ip='200.0.10.100/8', mac='00:00:00:00:00:01', mode='b', position='40,125,0') cars[1] = net.addCar('car1', wlans=1, range='30', ip='200.0.10.150/8', mac='00:00:00:00:00:02', mode='b', position='50,125,0') cars[2] = net.addCar('car2', wlans=1, range='30', ip='200.0.10.200/8', mac='00:00:00:00:00:03', mode='b', position='60,125,0') rsu1 = net.addAccessPoint('rsu1', ssid='rsu1', dpid='0000000000000006', mode='g', channel='11', range='40', position='50,140,0', protocols='OpenFlow13') rsu2 = net.addAccessPoint('rsu2', ssid='rsu2', dpid='0000000000000007', mode='g', channel='11', range='40', position='130,140,0', protocols='OpenFlow13') rsu3 = net.addAccessPoint('rsu3', ssid='rsu3', dpid='0000000000000008', mode='g', channel='11', range='40', position='210,140,0', protocols='OpenFlow13') sw1 = net.addSwitch('sw1', dpid='0000000000000009', protocols='OpenFlow13') sw2 = net.addSwitch('sw2', dpid='0000000000000010', protocols='OpenFlow13') server_s = net.addHost('server_s', ip='200.0.10.2/8') server_e = net.addHost('server_e', ip='200.0.10.3/8') server_e2 = net.addHost('server_e2', ip='200.0.10.4/8') server_s.plot(position='210,190,0') server_e.plot(position='210,220,0') server_e2.plot(position='210,240,0') sw1.plot(position='125,218,0') sw2.plot(position='170,218,0') print("*** Configuring Propagation Model") net.propagationModel(model="logDistance", exp=4.5) net.useIFB() print("*** Configuring wifi nodes") net.configureWifiNodes() print("*** Creating links") net.addLink(rsu1, rsu2) net.addLink(rsu2, rsu3) net.addLink(server_s, sw2) net.addLink(server_e, sw2) net.addLink(server_e2, sw2) link1 = net.addLink(sw1, sw2, cls=TCLink) link2 = net.addLink(rsu1, sw1, cls=TCLink) link3 = net.addLink(rsu2, sw1, cls=TCLink) link4 = net.addLink(rsu3, sw1, cls=TCLink) print("*** Configuring links bandwidth") link1.intf1.config(bw=9) link2.intf1.config(bw=6) link3.intf1.config(bw=6) link4.intf1.config(bw=6) 'Plotting Graph' net.plotGraph(max_x=250, max_y=250) print("*** Starting network") net.build() c1.start() rsu1.start([c1]) rsu2.start([c1]) rsu3.start([c1]) sw1.start([c1]) sw2.start([c1]) for sw in net.carsSW: sw.start([c1]) print("*** Shutting ports") time.sleep(3) os.system('ovs-ofctl mod-port rsu1 rsu1-eth3 down -O Openflow13') os.system('ovs-ofctl mod-port rsu2 rsu2-eth3 down -O Openflow13') os.system('ovs-ofctl mod-port rsu2 rsu2-eth4 down -O Openflow13') os.system('ovs-ofctl mod-port rsu3 rsu3-eth3 down -O Openflow13') # time.sleep(1) # makeTerm(cars[0], cmd="bash -c 'ping 200.0.10.2;'") print("*** Moving nodes") taskTime = 40 os.system('rm *.vanetdata') os.system('ovs-vsctl --all destroy QoS; ovs-vsctl --all destroy Queue') os.system('ovs-vsctl set-manager ptcp:6632') os.system( 'curl -X PUT -d \'"tcp:127.0.0.1:6632"\' http://localhost:8080/v1.0/conf/switches/0000000000000006/ovsdb_addr' ) os.system( 'curl -X PUT -d \'"tcp:127.0.0.1:6632"\' http://localhost:8080/v1.0/conf/switches/0000000000000007/ovsdb_addr' ) os.system( 'curl -X PUT -d \'"tcp:127.0.0.1:6632"\' http://localhost:8080/v1.0/conf/switches/0000000000000008/ovsdb_addr' ) os.system( 'curl -X PUT -d \'"tcp:127.0.0.1:6632"\' http://localhost:8080/v1.0/conf/switches/0000000000000009/ovsdb_addr' ) os.system( 'curl -X PUT -d \'"tcp:127.0.0.1:6632"\' http://localhost:8080/v1.0/conf/switches/0000000000000010/ovsdb_addr' ) print("*** Starting servers") server_s.cmdPrint("iperf -s -u -i 1 -p 5002 > result_safety.datares &") server_e.cmdPrint("iperf -s -u -i 1 -p 5003 > result_enter.datares &") server_e2.cmdPrint("iperf -s -u -i 1 -p 5003 > result_enter2.datares &") time.sleep(2) print("*** Car[0] connection 7.5Mbps") cars[0].cmdPrint("iperf -c 200.0.10.2 -p 5002 -u -b 1.5M -t130 &") cars[1].cmdPrint("iperf -c 200.0.10.3 -p 5003 -u -b 1.5M -t100 &") cars[2].cmdPrint("iperf -c 200.0.10.4 -p 5003 -u -b 1.5M -t100 &") timeout = time.time() + taskTime currentTime = time.time() i = 0 while True: if time.time() > timeout: break if time.time() - currentTime >= i: recordValues(cars[0], server_s) i += 0.5 cars[0].setPosition('115,125,0') cars[1].setPosition('125,125,0') cars[2].setPosition('135,125,0') os.system( 'ovs-ofctl del-flows sw1 -O Openflow13; ovs-ofctl add-flow sw1 "table=0, priority=0, actions=goto_table:1" -O Openflow13; ovs-ofctl add-flow sw1 "table=1, priority=0, actions=CONTROLLER:65535" -O Openflow13' ) timeout = time.time() + taskTime currentTime = time.time() i = 0 while True: if time.time() > timeout: break if time.time() - currentTime >= i: recordValues(cars[0], server_s) i += 0.5 cars[0].setPosition('200,125,0') cars[1].setPosition('210,125,0') cars[2].setPosition('220,125,0') os.system( 'ovs-ofctl del-flows sw1 -O Openflow13; ovs-ofctl add-flow sw1 "table=0, priority=0, actions=goto_table:1" -O Openflow13; ovs-ofctl add-flow sw1 "table=1, priority=0, actions=CONTROLLER:65535" -O Openflow13' ) timeout = time.time() + taskTime currentTime = time.time() i = 0 while True: if time.time() > timeout: break if time.time() - currentTime >= i: recordValues(cars[0], server_s) i += 0.5 # print("*** Aplica QoS") # os.system('curl -X POST -d \'{"port_name": "rsu2-eth2", "type": "linux-htb", "max_rate": "8300000", "queues": [{"max_rate": "1000000"}, {"min_rate": "7500000"}]}\' http://localhost:8080/qos/queue/0000000000000007') # os.system('curl -X POST -d \'{"port_name": "rsu1-eth2", "type": "linux-htb", "max_rate": "8300000", "queues": [{"max_rate": "1000000"}, {"min_rate": "7500000"}]}\' http://localhost:8080/qos/queue/0000000000000006') # os.system('curl -X POST -d \'{"match": {"nw_dst": "200.0.10.2", "nw_proto": "UDP", "tp_dst": "5002"}, "actions":{"queue": "1"}}\' http://localhost:8080/qos/rules/0000000000000007') # os.system('curl -X POST -d \'{"match": {"nw_dst": "200.0.10.2", "nw_proto": "UDP", "tp_dst": "5002"}, "actions":{"queue": "1"}}\' http://localhost:8080/qos/rules/0000000000000006') # timeout = time.time() + taskTime # currentTime = time.time() # i = 0 # while True: # if time.time() > timeout: # break # if time.time() - currentTime >= i: # recordValues(cars[0], server_s) # i += 0.5 print("*** Generating graph") graphic() # os.system('pkill -f vlc') os.system('pkill xterm') print("*** Running CLI") CLI_wifi(net) #os.system('rm *.vanetdata') print("*** Stopping network") net.stop()
def topology(): "Create a network." net = Mininet_wifi(controller=VANET_Controller, link=wmediumd, switch=SD_Switch, station=SD_station, enable_interference=True) print ("*** Creating nodes") car = [] stas = [] mec = [] channel = ['1','6','11'] NUM_OF_MECS = 4 for x in range(0, 5): car.append(x) stas.append(x) for x in range(0, 5): 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,cls=SD_Car) c = 0 for m in range(0, NUM_OF_MECS): mec.append(m) for m in range(0,NUM_OF_MECS): #print "Counter of mecs is %s "%m if((m+1) % 3 == 0): c=0 mec[m] = net.addAccessPoint('MEC%s' % (m+1), ssid= 'RSU%s' % (m+1), mode= 'g', channel= channel[c], range=100 ,cls=RSU) c += 1 c1 = net.addController( 'c1', controller=VANET_Controller ) def SDStorage(datasize): start2 = time.time() datasize = int(datasize) print ("car %s want to store %s bytes" % (0, datasize)) car[0].store(datasize,Modes.MEC, net) end2 = time.time() with open('Storage.txt', 'a') as f: f.write('%.12f \n' % (end2-start2)) print ("took : ", end2 - start2) print ("*** Configuring wifi nodes") net.configureWifiNodes() #net.meshRouting('custom') print ("*** Associating and Creating links") for m in range(0, NUM_OF_MECS): if(m < (NUM_OF_MECS-1)): net.addLink(mec[m],mec[m+1]) else: net.addLink(mec[0],mec[m]) """uncomment to plot graph""" net.plotGraph(max_x=700, max_y=700) """Number of Roads""" net.roads(10) """Start Mobility""" net.startMobility(time=0) print ("*** Starting network") net.build() c1.start() c1.initializeNetworkResources(net) print ("Draw 10 roads and place the 4 MEC nodes along them?") print ("\n\n\n***************************START*******************************") datasize = raw_input("What is the amount of storage you want (in bytes)") SDStorage(datasize) print ("\n\n\n***************************END*******************************") print ("(MEC) info Table after the test") net.aps[0].listMecContents(Modes.MEC, net) print ("*** Running CLI") CLI( net ) print ("*** Stopping network") net.stop()