-
Notifications
You must be signed in to change notification settings - Fork 2
/
mcast.py
181 lines (141 loc) · 7.16 KB
/
mcast.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/usr/bin/python
from mininet.net import Mininet
from mininet.node import OVSController, OVSKernelSwitch, RemoteController
from mininet.cli import CLI
from mininet.log import setLogLevel
from mininet.link import TCLink
import time
import os
import thread
def link_down(net):
time.sleep(31)
print "*** Link Down"
net.configLinkStatus('s15','s17','down')
os.system("echo \"$(date +'%F %T,%3N') Link s15 - s17 Down\"")
# os.system("echo \"$(date +'%F %T,%3N') Link s15 - s17 Down\" >> scripts/mcast_v1/log.txt")
def link_iperf(net, hc, hs1, hs2):
# for x in range(0, 5):
net.iperf( [ hc, hs1], seconds=25, l4Type='UDP', udpBw='9M')
net.iperf( [ hc, hs2], seconds=25, l4Type='UDP', udpBw='9M')
def topology():
# "Create a network."
net = Mininet( controller=RemoteController, link=TCLink, switch=OVSKernelSwitch )
_bw=10
_latency='5ms'
_max_queue_size=100
_use_htb=True
_ip_remote_control='127.0.0.1'
_port_remote_control=6653
adp_USB100MB_MAC = "00:13:3B:85:05:05"
print "*** Creating Hosts"
h1 = net.addHost( 'h1', mac="00:00:00:00:00:01", ip='192.168.2.1' )
h2 = net.addHost( 'h2', mac="00:00:00:00:00:02", ip='192.168.2.2' )
h3 = net.addHost( 'h3', mac="00:00:00:00:00:03", ip='192.168.2.3' )
h4 = net.addHost( 'h4', mac="00:00:00:00:00:04", ip='192.168.2.4' )
h5 = net.addHost( 'h5', mac="00:00:00:00:00:05", ip='192.168.2.5' )
h6 = net.addHost( 'h6', mac="00:00:00:00:00:06", ip='192.168.2.6' )
h7 = net.addHost( 'h7', mac="00:00:00:00:00:07", ip='192.168.2.7' )
h8 = net.addHost( 'h8', mac="00:00:00:00:00:08", ip='192.168.2.8' )
h9 = net.addHost( 'h9', mac="00:00:00:00:00:09", ip='192.168.2.9' )
h10 = net.addHost( 'h10', mac="00:00:00:00:00:10", ip='192.168.2.10' )
h11 = net.addHost( 'h11', mac="00:00:00:00:00:11", ip='192.168.2.11' )
# h12 = net.addHost( 'h12', mac="00:00:00:00:00:12", ip='192.168.2.12' )
# h13 = net.addHost( 'h13', mac="00:00:00:00:00:13", ip='192.168.2.13' )
hc = net.addHost( 'hc', mac="00:00:00:00:00:50", ip='192.168.2.50' )
hs1 = net.addHost( 'hs1', mac="00:00:00:00:00:51", ip='192.168.2.51' )
hs2 = net.addHost( 'hs2', mac="00:00:00:00:00:52", ip='192.168.2.52' )
print "*** Creating Switchs"
s35 = net.addSwitch( 's35', dpid='00:00:00:00:aa:bb:cc:35' )
s32 = net.addSwitch( 's32', dpid='00:00:00:00:aa:bb:cc:32' )
s15 = net.addSwitch( 's15', dpid='00:00:00:00:aa:bb:cc:15' )
s14 = net.addSwitch( 's14', dpid='00:00:00:00:aa:bb:cc:14' )
s02 = net.addSwitch( 's02', dpid='00:00:00:00:aa:bb:cc:02' )
s17 = net.addSwitch( 's17', dpid='00:00:00:00:aa:bb:cc:17' )
s38 = net.addSwitch( 's38', dpid='00:00:00:00:aa:bb:cc:38' )
print "*** Creating Controller Openflow"
c0 = RemoteController( 'c0', ip=_ip_remote_control, port=_port_remote_control )
print "*** Connecting hosts"
net.addLink(h1, s32, bw=_bw, use_htb=_use_htb)
net.addLink(h2, s38, bw=_bw, use_htb=_use_htb)
net.addLink(h3, s38, bw=_bw, use_htb=_use_htb)
net.addLink(h4, s38, bw=_bw, use_htb=_use_htb)
net.addLink(h5, s02, bw=_bw, use_htb=_use_htb)
net.addLink(h6, s02, bw=_bw, use_htb=_use_htb)
net.addLink(h7, s02, bw=_bw, use_htb=_use_htb)
net.addLink(h8, s17, bw=_bw, use_htb=_use_htb)
net.addLink(h9, s17, bw=_bw, use_htb=_use_htb)
net.addLink(h10, s17, bw=_bw, use_htb=_use_htb)
net.addLink(h11, s35, bw=_bw, use_htb=_use_htb)
# net.addLink(h12, s35, bw=_bw, use_htb=_use_htb)
# net.addLink(h13, s35, bw=_bw, use_htb=_use_htb)
net.addLink(hc, s32, bw=_bw, use_htb=_use_htb)
net.addLink(hs1, s14, bw=_bw, use_htb=_use_htb)
net.addLink(hs2, s15, bw=_bw, use_htb=_use_htb)
print "*** Creating connection between switches"
net.addLink(s35, s15, bw=_bw,latency=_latency,max_queue_size=_max_queue_size,use_htb=_use_htb)
net.addLink(s35, s14, bw=_bw,latency=_latency,max_queue_size=_max_queue_size,use_htb=_use_htb)
net.addLink(s32, s15, bw=_bw,latency=_latency,max_queue_size=_max_queue_size,use_htb=_use_htb)
net.addLink(s32, s14, bw=_bw,latency=_latency,max_queue_size=_max_queue_size,use_htb=_use_htb)
net.addLink(s15, s17, bw=_bw,latency=_latency,max_queue_size=_max_queue_size,use_htb=_use_htb)
net.addLink(s15, s02, bw=_bw,latency=_latency,max_queue_size=_max_queue_size,use_htb=_use_htb)
net.addLink(s14, s17, bw=_bw,latency=_latency,max_queue_size=_max_queue_size,use_htb=_use_htb)
net.addLink(s14, s02, bw=_bw,latency=_latency,max_queue_size=_max_queue_size,use_htb=_use_htb)
net.addLink(s02, s38, bw=_bw,latency=_latency,max_queue_size=_max_queue_size,use_htb=_use_htb)
net.addLink(s17, s38, bw=_bw,latency=_latency,max_queue_size=_max_queue_size,use_htb=_use_htb)
print "*** Starting network"
net.build()
c0.start()
s35.start( [c0] )
s15.start( [c0] )
s17.start( [c0] )
s14.start( [c0] )
s32.start( [c0] )
s02.start( [c0] )
s38.start( [c0] )
try:
#Run Floodlight in another terminal
exec_floodlight="cd ../floodlight && java -jar target/floodlight.jar > mcast_log.txt && exit"
# exec_floodlight="cd ../floodlight && ant && java -jar target/floodlight.jar > mcast_log.txt && exit"
os.system("gnome-terminal -x sh -c '"+exec_floodlight+" ; bash'")
#wait time for compile and run Floodlight
time.sleep(15)
# net.pingAll()
#Arquivo de log dos hosts
os.system("rm -f scripts/mcast_v1/log.txt")
# os.system("cd scripts/mcast_v1 && echo '' > log.txt")
print "\n"
#List of hots
hosts = [h2, h3, h4, h5, h6, h7, h8, h9, h10, h11]#, h12, h13]
#Start Server
h1.cmd('cd scripts/mcast_v1 && python mc_server.py h1 >> log.txt &')
print "H1 START "
time.sleep(2)
thread.start_new_thread( link_down, (net,) )
thread.start_new_thread( link_iperf, (net, hc, hs1, hs2) )
#Starts a host every 5 seconds
for i in range(2, (len(hosts)+2)):
hosts[i-2].cmd('cd scripts/mcast_v1 && python mc_client.py h'+str(i)+' >> log.txt &')
if(i==2):
os.system("sudo tcpdump -i any -n -tt -v tcp port 6653 > evalvid/files/open_flow_mcast.txt &")
# os.system("sudo tcpdump -i any -n -tt -v igmp > evalvid/files/igmp_mcast.txt &")
print("H"+str(i)+" START")
time.sleep(5)
except Exception as e:
print("Failed "+str(e))
try:
time.sleep(15)
os.system("sudo kill -1 $(ps -C 'java -jar target/floodlight.jar' -o pid=)")
time.sleep(1)
os.system("mv scripts/mcast_v1/log.txt evalvid/files && mv ../floodlight/mcast_log.txt evalvid/files")
time.sleep(1)
os.system("cd evalvid/files && sort -n -k1 log.txt -o log.txt")
time.sleep(1)
os.system("sudo kill -1 $(ps -C 'sh -c cd ../floodlight && ant && java -jar target/floodlight.jar > mcast_log.txt' -o pid=)")
# raw_input("\nPress Enter to continue...\n")
# os.system("cd evalvid && ./evaluation_complete.sh h2 mcast_10h_5s_linkdown")
finally:
print "*** Stopping network"
net.stop()
if __name__ == '__main__':
setLogLevel( 'info' )
topology()