add SDN chaining unit test
[osm/vim-emu.git] / src / emuvim / examples / monitoring_demo_topology.py
1 """
2 This is an example topology for the distributed cloud emulator (dcemulator).
3 (c) 2015 by Manuel Peuster <manuel.peuster@upb.de>
4
5
6 This is an example that shows how a user of the emulation tool can
7 define network topologies with multiple emulated cloud data centers.
8
9 The definition is done with a Python API which looks very similar to the
10 Mininet API (in fact it is a wrapper for it).
11
12 We only specify the topology *between* data centers not within a single
13 data center (data center internal setups or placements are not of interest,
14 we want to experiment with VNF chains deployed across multiple PoPs).
15
16 The original Mininet API has to be completely hidden and not be used by this
17 script.
18 """
19 import logging
20 from mininet.log import setLogLevel
21 from emuvim.dcemulator.net import DCNetwork
22 from emuvim.api.zerorpc.compute import ZeroRpcApiEndpoint
23 from emuvim.api.zerorpc.network import ZeroRpcApiEndpointDCNetwork
24
25 logging.basicConfig(level=logging.INFO)
26
27
28 def create_topology1():
29 """
30 1. Create a data center network object (DCNetwork) with monitoring enabled
31 """
32 net = DCNetwork(monitor=True, enable_learning=False)
33
34 """
35 1b. add a monitoring agent to the DCNetwork
36 """
37 mon_api = ZeroRpcApiEndpointDCNetwork("0.0.0.0", 5151)
38 mon_api.connectDCNetwork(net)
39 mon_api.start()
40 """
41 2. Add (logical) data centers to the topology
42 (each data center is one "bigswitch" in our simplified
43 first prototype)
44 """
45 dc1 = net.addDatacenter("datacenter1")
46 dc2 = net.addDatacenter("datacenter2")
47 #dc3 = net.addDatacenter("long_data_center_name3")
48 #dc4 = net.addDatacenter(
49 # "datacenter4",
50 # metadata={"mydata": "we can also add arbitrary metadata to each DC"})
51
52 """
53 3. You can add additional SDN switches for data center
54 interconnections to the network.
55 """
56 s1 = net.addSwitch("s1")
57
58 """
59 4. Add links between your data centers and additional switches
60 to define you topology.
61 These links can use Mininet's features to limit bw, add delay or jitter.
62 """
63 #net.addLink(dc1, dc2, delay="10ms")
64 #net.addLink(dc1, dc2)
65 net.addLink(dc1, s1)
66 net.addLink(s1, dc2)
67 #net.addLink("datacenter1", s1, delay="20ms")
68 #net.addLink(s1, dc3)
69 #net.addLink(s1, "datacenter4")
70
71
72 """
73 5. We want to access and control our data centers from the outside,
74 e.g., we want to connect an orchestrator to start/stop compute
75 resources aka. VNFs (represented by Docker containers in the emulated)
76
77 So we need to instantiate API endpoints (e.g. a zerorpc or REST
78 interface). Depending on the endpoint implementations, we can connect
79 one or more data centers to it, which can then be controlled through
80 this API, e.g., start/stop/list compute instances.
81 """
82 # create a new instance of a endpoint implementation
83 zapi1 = ZeroRpcApiEndpoint("0.0.0.0", 4242)
84 # connect data centers to this endpoint
85 zapi1.connectDatacenter(dc1)
86 zapi1.connectDatacenter(dc2)
87 #zapi1.connectDatacenter(dc3)
88 #zapi1.connectDatacenter(dc4)
89 # run API endpoint server (in another thread, don't block)
90 zapi1.start()
91
92 """
93 5.1. For our example, we create a second endpoint to illustrate that
94 this is supported by our design. This feature allows us to have
95 one API endpoint for each data center. This makes the emulation
96 environment more realistic because you can easily create one
97 OpenStack-like REST API endpoint for *each* data center.
98 This will look like a real-world multi PoP/data center deployment
99 from the perspective of an orchestrator.
100 """
101 #zapi2 = ZeroRpcApiEndpoint("0.0.0.0", 4343)
102 #zapi2.connectDatacenter(dc3)
103 #zapi2.connectDatacenter(dc4)
104 #zapi2.start()
105
106 """
107 6. Finally we are done and can start our network (the emulator).
108 We can also enter the Mininet CLI to interactively interact
109 with our compute resources (just like in default Mininet).
110 But we can also implement fully automated experiments that
111 can be executed again and again.
112 """
113 net.start()
114 net.CLI()
115 # when the user types exit in the CLI, we stop the emulator
116 net.stop()
117
118
119 def main():
120 setLogLevel('info') # set Mininet loglevel
121 create_topology1()
122
123
124 if __name__ == '__main__':
125 main()