blob: 440a0855e24a738ebd35e01ae7cb91ba28b81776 [file] [log] [blame]
hadik3rf3bf0e72016-06-27 18:20:44 +02001"""
2This is an example topology for the distributed cloud emulator (dcemulator).
3(c) 2015 by Manuel Peuster <manuel.peuster@upb.de>
4
5
6This is an example that shows how a user of the emulation tool can
7define network topologies with multiple emulated cloud data centers.
8
9The definition is done with a Python API which looks very similar to the
10Mininet API (in fact it is a wrapper for it).
11
12We only specify the topology *between* data centers not within a single
13data center (data center internal setups or placements are not of interest,
14we want to experiment with VNF chains deployed across multiple PoPs).
15
16The original Mininet API has to be completely hidden and not be used by this
17script.
18"""
19import logging
20from mininet.log import setLogLevel
21from emuvim.dcemulator.net import DCNetwork
stevenvanrossem73efd192016-06-29 01:44:07 +020022from emuvim.api.rest.rest_api_endpoint import RestApiEndpoint
23
24from emuvim.api.zerorpc.compute import ZeroRpcApiEndpoint
hadik3rf3bf0e72016-06-27 18:20:44 +020025from emuvim.api.zerorpc.network import ZeroRpcApiEndpointDCNetwork
26
27logging.basicConfig(level=logging.INFO)
28
29
30def create_topology1():
31 """
32 1. Create a data center network object (DCNetwork)
33 """
stevenvanrossem73efd192016-06-29 01:44:07 +020034 net = DCNetwork(monitor=True, enable_learning=False)
hadik3rf3bf0e72016-06-27 18:20:44 +020035
36 """
37 1b. add a monitoring agent to the DCNetwork
38 """
stevenvanrossem73efd192016-06-29 01:44:07 +020039 #keep old zeroRPC interface to test the prometheus metric query
hadik3rf3bf0e72016-06-27 18:20:44 +020040 mon_api = ZeroRpcApiEndpointDCNetwork("0.0.0.0", 5151)
41 mon_api.connectDCNetwork(net)
42 mon_api.start()
43 """
44 2. Add (logical) data centers to the topology
45 (each data center is one "bigswitch" in our simplified
46 first prototype)
47 """
48 dc1 = net.addDatacenter("datacenter1")
49 dc2 = net.addDatacenter("datacenter2")
50 dc3 = net.addDatacenter("long_data_center_name3")
51 dc4 = net.addDatacenter(
52 "datacenter4",
53 metadata={"mydata": "we can also add arbitrary metadata to each DC"})
54
55 """
56 3. You can add additional SDN switches for data center
57 interconnections to the network.
58 """
59 s1 = net.addSwitch("s1")
60
61 """
62 4. Add links between your data centers and additional switches
63 to define you topology.
64 These links can use Mininet's features to limit bw, add delay or jitter.
65 """
66 net.addLink(dc1, dc2)
67 net.addLink("datacenter1", s1)
68 net.addLink(s1, dc3)
69 net.addLink(s1, "datacenter4")
70
71 """
72 5. We want to access and control our data centers from the outside,
73 e.g., we want to connect an orchestrator to start/stop compute
74 resources aka. VNFs (represented by Docker containers in the emulated)
75
76 So we need to instantiate API endpoints (e.g. a zerorpc or REST
77 interface). Depending on the endpoint implementations, we can connect
78 one or more data centers to it, which can then be controlled through
79 this API, e.g., start/stop/list compute instances.
80 """
stevenvanrossem73efd192016-06-29 01:44:07 +020081 # keep the old zeroRPC interface for the prometheus metric query test
82 zapi1 = ZeroRpcApiEndpoint("0.0.0.0", 4242)
83 # connect data centers to this endpoint
84 zapi1.connectDatacenter(dc1)
85 zapi1.connectDatacenter(dc2)
86 # run API endpoint server (in another thread, don't block)
87 zapi1.start()
88
hadik3rf3bf0e72016-06-27 18:20:44 +020089 # create a new instance of a endpoint implementation
peusterm0a336cc2016-07-04 09:15:47 +020090 api1 = RestApiEndpoint("127.0.0.1", 5001)
hadik3rf3bf0e72016-06-27 18:20:44 +020091 # connect data centers to this endpoint
92 api1.connectDatacenter(dc1)
93 api1.connectDatacenter(dc2)
94 api1.connectDatacenter(dc3)
95 api1.connectDatacenter(dc4)
stevenvanrossem73efd192016-06-29 01:44:07 +020096 # connect total network also, needed to do the chaining and monitoring
97 api1.connectDCNetwork(net)
hadik3rf3bf0e72016-06-27 18:20:44 +020098 # run API endpoint server (in another thread, don't block)
99 api1.start()
100
101 """
102 6. Finally we are done and can start our network (the emulator).
103 We can also enter the Mininet CLI to interactively interact
104 with our compute resources (just like in default Mininet).
105 But we can also implement fully automated experiments that
106 can be executed again and again.
107 """
108 net.start()
109 net.CLI()
110 # when the user types exit in the CLI, we stop the emulator
111 net.stop()
112
113
114def main():
115 setLogLevel('info') # set Mininet loglevel
116 create_topology1()
117
118
119if __name__ == '__main__':
120 main()