-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsumo-experimental.py
executable file
·143 lines (116 loc) · 4.74 KB
/
sumo-experimental.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/python
"""Sample file for SUMO
***Requirements***:
sumo
sumo-gui"""
import os
#from mininet.node import Controller, RemoteController, OVSKernelSwitch
from mininet.node import Controller
from mininet.log import setLogLevel, info
from mininet.wifi.node import UserAP
from mininet.wifi.link import wmediumd
from mininet.wifi.cli import CLI_wifi
from mininet.wifi.net import Mininet_wifi
from mininet.wifi.wmediumdConnector import interference
def topology():
#private_dirs = [ ( '/var/log', '/tmp/%(name)s/var/log' ),
#( '/var/run', '/tmp/%(name)s/var/run' ),
#'/var/mn' ]
"Create a network."
#net = Mininet_wifi(controller=Controller, accessPoint=UserAP,
net = Mininet_wifi(controller=RemoteController, accessPoint=UserAP,
link=wmediumd, wmediumd_mode=interference, switch=OVSKernelSwitch)
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))
#cars[x] = net.addCar('car%s' % (x),
#wlans=1, ip='10.0.0.%s/8' % (x + 1), privateDirs=private_dirs)
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=RemoteController, ip='IP_REMOTE_CONTROLLER',
port=6633)
#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()
if __name__ == '__main__':
setLogLevel('info')
topology()