-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontainernet.py
More file actions
executable file
·91 lines (79 loc) · 3 KB
/
Copy pathcontainernet.py
File metadata and controls
executable file
·91 lines (79 loc) · 3 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
#!/usr/bin/python
"""
This is the most simple example to showcase Containernet.
"""
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
from emuvim.dcemulator.net import DCNetwork
from emuvim.api.rest.rest_api_endpoint import RestApiEndpoint
from emuvim.api.openstack.openstack_api_endpoint import OpenstackApiEndpoint
import logging
logging.basicConfig(level=logging.INFO)
logging.getLogger('werkzeug').setLevel(logging.DEBUG)
logging.getLogger('api.openstack.base').setLevel(logging.DEBUG)
logging.getLogger('api.openstack.compute').setLevel(logging.DEBUG)
logging.getLogger('api.openstack.keystone').setLevel(logging.DEBUG)
logging.getLogger('api.openstack.nova').setLevel(logging.DEBUG)
logging.getLogger('api.openstack.neutron').setLevel(logging.DEBUG)
logging.getLogger('api.openstack.heat').setLevel(logging.DEBUG)
logging.getLogger('api.openstack.heat.parser').setLevel(logging.DEBUG)
logging.getLogger('api.openstack.glance').setLevel(logging.DEBUG)
logging.getLogger('api.openstack.helper').setLevel(logging.DEBUG)
setLogLevel('info')
#net = Containernet(controller=Controller)
net = DCNetwork(monitor=False, enable_learning=True)
dc1 = net.addDatacenter("dc1")
# add OpenStack-like APIs to the emulated DC
api1 = OpenstackApiEndpoint("0.0.0.0", 6001)
api1.connect_datacenter(dc1)
api1.start()
api1.connect_dc_network(net)
# add the command line interface endpoint to the emulated DC (REST API)
rapi1 = RestApiEndpoint("127.0.0.1", 5001)
rapi1.connectDCNetwork(net)
rapi1.connectDatacenter(dc1)
rapi1.start()
info('*** Adding controller\n')
#net.addController('c0')
info('*** Adding docker containers\n')
srv = net.addDocker('srv', ip='10.0.0.30', dimage="server:latest")
gwi = net.addDocker('gwi', ip='10.0.0.31', dimage="gwi:latest")
gwf1 = net.addDocker('gwf1', ip='10.0.0.32', dimage="gwf:one")
dev1 = net.addDocker('dev1', ip='10.0.0.33', dimage="dev:one")
gwf2 = net.addDocker('gwf2', ip='10.0.0.34', dimage="gwf:two")
dev2 = net.addDocker('dev2', ip='10.0.0.35', dimage="dev:two")
gwf3 = net.addDocker('gwf3', ip='10.0.0.36', dimage="gwf:three")
dev3 = net.addDocker('dev3', ip='10.0.0.37', dimage="dev:three")
info('*** Adding switches\n')
s1 = net.addSwitch('s1')
s2 = net.addSwitch('s2')
s3 = net.addSwitch('s3')
s4 = net.addSwitch('s4')
s5 = net.addSwitch('s5')
info('*** Creating links\n')
net.addLink(srv, s1)
net.addLink(gwi, s1)
net.addLink(dc1, s1)
net.addLink(gwf1, s3)
net.addLink(dev1, s3)
net.addLink(gwf2, s4)
net.addLink(dev2, s4)
net.addLink(gwf3, s5)
net.addLink(dev3, s5)
net.addLink(s1, s2, cls=TCLink, delay='100ms', bw=1)
net.addLink(s2, s3, cls=TCLink, delay='100ms', bw=1)
net.addLink(s2, s4, cls=TCLink, delay='100ms', bw=1)
net.addLink(s2, s5, cls=TCLink, delay='100ms', bw=1)
info('*** Starting network\n')
net.start()
info('*** Testing connectivity\n')
net.ping([srv, dev1])
net.ping([srv, dev2])
net.ping([srv, dev3])
info('*** Running CLI\n')
CLI(net)
info('*** Stopping network')
net.stop()