forked from edoardesd/mqttbench_containernet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_broadcast.py
54 lines (52 loc) · 1.62 KB
/
test_broadcast.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
"""
Example topology with two containers (d1, d2),
two switches, and one controller:
- (c)-
| |
(d1) - (s1) - (s2) - (d2)
"""
from mininet.net import Containernet
from mininet.node import Controller
from mininet.cli import CLI
from mininet.link import TCLink
from mininet.log import info, setLogLevel
setLogLevel('info')
net = Containernet(controller=Controller)
info('*** Adding controller\n')
net.addController('c0')
info('*** Adding docker containers using ubuntu:trusty images\n')
d1 = net.addDocker('d1', ip='10.0.0.251', dimage="flipperthedog/mqttplusdistr:latest",
environment={
"WS_PORT": 8080,
"BROKER_PORT": 1883,
"CLUSTER_SIZE": 2,
"BROKER_NUM": 0,
"IP_ADDR": '10.0.0.251'
}
)
d2 = net.addDocker('d2', ip='10.0.0.252', dimage="flipperthedog/mqttplusdistr:latest",
environment={
"WS_PORT": 8081,
"BROKER_PORT": 1884,
"CLUSTER_SIZE": 2,
"BROKER_NUM": 1,
"IP_ADDR": '10.0.0.252'
})
info('*** Adding switches\n')
s1 = net.addSwitch('s1')
s2 = net.addSwitch('s2')
info('*** Creating links\n')
net.addLink(d1, s1)
net.addLink(s1, s2, cls=TCLink, delay='1ms', bw=1)
net.addLink(s2, d2)
info('*** Starting network\n')
net.start()
info('*** Testing connectivity\n')
net.ping([d1, d2])
info('*** Starting CMDs\n')
d1.start()
d2.start()
info('*** Running CLI\n')
CLI(net)
info('*** Stopping network')
net.stop()