-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmytopo.py
101 lines (76 loc) · 2.58 KB
/
mytopo.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
from mininet.net import Mininet
from mininet.node import RemoteController
from mininet.cli import CLI
from mininet.log import setLogLevel, info
from threading import Thread
import time
def customtopo():
info('*** Adding controller\n')
c0 = net.addController(
name='c0', controller=RemoteController, ip='192.168.58.129', port=6633)
info('*** Adding switches\n')
switcha = net.addSwitch('s1')
switchb = net.addSwitch('s2')
info('*** Adding hosts\n')
for h in range(1, 46):
net.addHost('h' + str(h))
net.addHost('server')
info('*** Creating links\n')
info(net.addLink('server', switchb))
info(net.addLink(switcha, switchb))
for h in range(1, 46):
net.addLink('h' + str(h), switcha)
def tester(host):
info(host.cmd('python traffic.py &'))
def tester1(host):
info(host.cmd('python traffic1.py &'))
def tester2(host):
info(host.cmd('python traffic2.py &'))
def runEverything(net):
for host in hosts[0:1]:
t = Thread(target=tester, args=(host, ))
t.start()
time.sleep(0.2)
time.sleep(60)
info(hosts[45].cmd('hping3 10.0.0.46 -p 12345 -S -i u33000 -c 450'))
info(hosts[44].cmd('hping3 10.0.0.46 -p 12345 -S -i u33000 -c 450'))
time.sleep(10)
for host in hosts[10:26]:
t = Thread(target=tester1, args=(host, ))
t.start()
time.sleep(0.2)
time.sleep(72)
info(hosts[45].cmd('hping3 10.0.0.46 -p 12345 -S -i u14285 -c 1050'))
info(hosts[44].cmd('hping3 10.0.0.46 -p 12345 -S -i u11111 -c 1350'))
time.sleep(33)
for host in hosts[26:44]:
t = Thread(target=tester2, args=(host, ))
t.start()
time.sleep(0.2)
time.sleep(600)
for host in hosts[0:10]:
t = Thread(target=tester, args=(host, ))
t.start()
time.sleep(0.2)
for host in hosts[10:26]:
t = Thread(target=tester1, args=(host, ))
t.start()
time.sleep(0.2)
info(hosts[45].cmd('hping3 10.0.0.46 -p 12345 -S -i u10000 -c 1500'))
info(hosts[44].cmd('hping3 10.0.0.46 -p 12345 -S -i u10000 -c 1500'))
if __name__ == '__main__':
setLogLevel('info')
"Create an empty network and then add nodes"
net = Mininet()
customtopo()
info('*** Starting network\n')
net.start()
hosts = net.hosts
time.sleep(2)
# runEverything(net)
th = Thread(target=runEverything, args=(net, ))
th.start()
info('*** Running CLI\n')
CLI(net)
info('*** Stopping network')
net.stop()