-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTopo.py
More file actions
96 lines (85 loc) · 2.83 KB
/
Topo.py
File metadata and controls
96 lines (85 loc) · 2.83 KB
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
from mininet.net import Mininet
from mininet.node import Controller, RemoteController, OVSKernelSwitch, \
UserSwitch, OVSSwitch
from mininet.cli import CLI
from mininet.log import setLogLevel
from mininet.link import Link, TCLink
import threading, random, time
from utils import *
e_random_bw = None
t_random_bw = None
end = False
link = None
lock = threading.Lock()
def create_topo():
global link, e_random_bw, end, lock
net = Mininet(controller=RemoteController, link=TCLink, switch=OVSSwitch)
# Creating hosts
host = {}
for i in range(1, 8):
host[i] = net.addHost(
name='h%s'%(i),
mac='00:00:00:00:00:0%s'%(i),
ip='10.0.0.%s'%(i)
)
# Creating Switches
switch = {}
for i in range(1, 5):
switch[i] = net.addSwitch( name='s%s'%(i))
controller = net.addController(
name='controller',
controller=RemoteController,
ip=IP_CONTROLLER,
port=PORT_CONTROLLER,
)
# Establishing connection via links
connections = [
(switch[1], host[1]), (switch[1], switch[3]), (switch[1], switch[2]),
(switch[2], host[2]), (switch[2], switch[3]), (switch[2], switch[4]),
(switch[3], host[3]), (switch[3], host[4]), (switch[3], switch[4]),
(switch[4], host[5]), (switch[4], host[6]), (switch[4], host[7]),
]
link = {}
for i, item in enumerate(connections):
link[i] = net.addLink(item[0], item[1], cls=TCLink, bw=BANDWIDTH[0], loss=0)
net.build()
controller.start()
for _, item in switch.items():
item.start([controller])
CLI(net)
end = True
e_random_bw.set()
with lock:
print "net is done..."
net.stop()
def random_bandwidth():
global e_random_bw, lock, end, link
while True:
lock.acquire()
e_random_bw.wait(T_CHBW)
if end:
lock.release()
break
# TODO: randomly changing the Bandwidth of all Links.
for _, item in link.items():
# try:
# cmd1, _ = item.intf1.bwCmds(bw=1)
# cmd2, _ = item.intf2.bwCmds(bw=1)
# outs = [item.intf1.tc(cmd1), item.intf2.tc(cmd2)]
# for out in outs:
# if out != '':
# print " ********************* ERROR: %s"%out
# except Exception, e:
# # lock.release()
# print "hhhhhhooooooooshhhaaaaaaaaa ", e
rnd = random.randint(0, 1)
item.intf1.config(bw=BANDWIDTH[rnd])
item.intf2.config(bw=BANDWIDTH[rnd])
lock.release()
print "end of random bandwidth..."
if __name__ == '__main__':
setLogLevel('info')
e_random_bw = threading.Event()
t_random_bw = threading.Thread(target=random_bandwidth)
t_random_bw.start()
create_topo()