blob: 94128636218eeb3e06a7a195b31f2c9773ed6f80 [file] [log] [blame]
peustermcbcd4c22015-12-28 11:33:42 +01001"""
2This is an example topology for the distributed cloud emulator (dcemulator).
3(c) 2015 by Manuel Peuster <manuel.peuster@upb.de>
4
peusterme4e89d32016-01-07 09:14:54 +01005
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
peustermcbcd4c22015-12-28 11:33:42 +010016The original Mininet API has to be completely hidden and not be used by this
17script.
18"""
19import logging
peustermd47ab252016-01-15 10:35:06 +010020from mininet.log import setLogLevel
peustermcbcd4c22015-12-28 11:33:42 +010021from dcemulator.net import DCNetwork
peusterm9c252b62016-01-06 16:59:53 +010022from api.zerorpcapi import ZeroRpcApiEndpoint
stevenvanrossem8fbf9782016-02-17 11:40:23 +010023from api.zerorpcapi_DCNetwork import ZeroRpcApiEndpointDCNetwork
peustermcbcd4c22015-12-28 11:33:42 +010024
peustermbd44f4a2016-01-13 14:53:30 +010025logging.basicConfig(level=logging.INFO)
peustermcbcd4c22015-12-28 11:33:42 +010026
27
28def create_topology1():
peusterme4e89d32016-01-07 09:14:54 +010029 """
30 1. Create a data center network object (DCNetwork)
31 """
peustermcbcd4c22015-12-28 11:33:42 +010032 net = DCNetwork()
33
peusterme4e89d32016-01-07 09:14:54 +010034 """
stevenvanrossem58bd1f22016-02-17 11:09:04 +010035 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 """
peusterme4e89d32016-01-07 09:14:54 +010042 2. Add (logical) data centers to the topology
43 (each data center is one "bigswitch" in our simplified
44 first prototype)
45 """
peusterma47db032016-02-04 14:55:29 +010046 dc1 = net.addDatacenter("datacenter1")
47 dc2 = net.addDatacenter("datacenter2")
peusterm53504942016-02-04 16:09:28 +010048 dc3 = net.addDatacenter("long_data_center_name3")
49 dc4 = net.addDatacenter(
50 "datacenter4",
51 metadata={"mydata": "we can also add arbitrary metadata to each DC"})
peusterme4e89d32016-01-07 09:14:54 +010052
53 """
54 3. You can add additional SDN switches for data center
55 interconnections to the network.
56 """
peustermcbcd4c22015-12-28 11:33:42 +010057 s1 = net.addSwitch("s1")
peusterme4e89d32016-01-07 09:14:54 +010058
59 """
60 4. Add links between your data centers and additional switches
61 to define you topology.
62 These links can use Mininet's features to limit bw, add delay or jitter.
63 """
peustermcbcd4c22015-12-28 11:33:42 +010064 net.addLink(dc1, dc2)
peusterma47db032016-02-04 14:55:29 +010065 net.addLink("datacenter1", s1)
66 net.addLink(s1, dc3)
67 net.addLink(s1, "datacenter4")
peusterm9c252b62016-01-06 16:59:53 +010068
peusterme4e89d32016-01-07 09:14:54 +010069 """
70 5. We want to access and control our data centers from the outside,
peusterm5b844a12016-01-11 15:58:15 +010071 e.g., we want to connect an orchestrator to start/stop compute
peusterme4e89d32016-01-07 09:14:54 +010072 resources aka. VNFs (represented by Docker containers in the emulated)
73
74 So we need to instantiate API endpoints (e.g. a zerorpc or REST
75 interface). Depending on the endpoint implementations, we can connect
76 one or more data centers to it, which can then be controlled through
77 this API, e.g., start/stop/list compute instances.
78 """
79 # create a new instance of a endpoint implementation
peusterm9c252b62016-01-06 16:59:53 +010080 zapi1 = ZeroRpcApiEndpoint("0.0.0.0", 4242)
peusterme4e89d32016-01-07 09:14:54 +010081 # connect data centers to this endpoint
peusterm9c252b62016-01-06 16:59:53 +010082 zapi1.connectDatacenter(dc1)
83 zapi1.connectDatacenter(dc2)
peusterm53504942016-02-04 16:09:28 +010084 zapi1.connectDatacenter(dc3)
85 zapi1.connectDatacenter(dc4)
peusterme4e89d32016-01-07 09:14:54 +010086 # run API endpoint server (in another thread, don't block)
peusterm9c252b62016-01-06 16:59:53 +010087 zapi1.start()
peusterme4e89d32016-01-07 09:14:54 +010088
89 """
90 5.1. For our example, we create a second endpoint to illustrate that
peustermeecafde2016-01-15 10:23:26 +010091 this is supported by our design. This feature allows us to have
peusterme4e89d32016-01-07 09:14:54 +010092 one API endpoint for each data center. This makes the emulation
93 environment more realistic because you can easily create one
94 OpenStack-like REST API endpoint for *each* data center.
95 This will look like a real-world multi PoP/data center deployment
96 from the perspective of an orchestrator.
97 """
peusterm9c252b62016-01-06 16:59:53 +010098 zapi2 = ZeroRpcApiEndpoint("0.0.0.0", 4343)
99 zapi2.connectDatacenter(dc3)
100 zapi2.connectDatacenter(dc4)
101 zapi2.start()
102
peusterme4e89d32016-01-07 09:14:54 +0100103 """
104 6. Finally we are done and can start our network (the emulator).
105 We can also enter the Mininet CLI to interactively interact
106 with our compute resources (just like in default Mininet).
107 But we can also implement fully automated experiments that
108 can be executed again and again.
109 """
peustermcbcd4c22015-12-28 11:33:42 +0100110 net.start()
peusterme4e89d32016-01-07 09:14:54 +0100111 net.CLI()
112 # when the user types exit in the CLI, we stop the emulator
stevenvanrossem58bd1f22016-02-17 11:09:04 +0100113 # we need to explicitly stop the monitoring api, so the Ryu controller is also terminated
114 mon_api.stop()
peusterme4e89d32016-01-07 09:14:54 +0100115 net.stop()
peustermcbcd4c22015-12-28 11:33:42 +0100116
117
118def main():
peustermd47ab252016-01-15 10:35:06 +0100119 setLogLevel('info') # set Mininet loglevel
peustermcbcd4c22015-12-28 11:33:42 +0100120 create_topology1()
121
122
123if __name__ == '__main__':
124 main()