blob: 3c53c58b0cf9232138014ddab5461444dfb7de10 [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
peustermcbcd4c22015-12-28 11:33:42 +010023
peustermbd44f4a2016-01-13 14:53:30 +010024logging.basicConfig(level=logging.INFO)
peustermcbcd4c22015-12-28 11:33:42 +010025
26
27def create_topology1():
peusterme4e89d32016-01-07 09:14:54 +010028 """
29 1. Create a data center network object (DCNetwork)
30 """
peustermcbcd4c22015-12-28 11:33:42 +010031 net = DCNetwork()
32
peusterme4e89d32016-01-07 09:14:54 +010033 """
34 2. Add (logical) data centers to the topology
35 (each data center is one "bigswitch" in our simplified
36 first prototype)
37 """
peusterma47db032016-02-04 14:55:29 +010038 dc1 = net.addDatacenter("datacenter1")
39 dc2 = net.addDatacenter("datacenter2")
peusterm53504942016-02-04 16:09:28 +010040 dc3 = net.addDatacenter("long_data_center_name3")
41 dc4 = net.addDatacenter(
42 "datacenter4",
43 metadata={"mydata": "we can also add arbitrary metadata to each DC"})
peusterme4e89d32016-01-07 09:14:54 +010044
45 """
46 3. You can add additional SDN switches for data center
47 interconnections to the network.
48 """
peustermcbcd4c22015-12-28 11:33:42 +010049 s1 = net.addSwitch("s1")
peusterme4e89d32016-01-07 09:14:54 +010050
51 """
52 4. Add links between your data centers and additional switches
53 to define you topology.
54 These links can use Mininet's features to limit bw, add delay or jitter.
55 """
peustermcbcd4c22015-12-28 11:33:42 +010056 net.addLink(dc1, dc2)
peusterma47db032016-02-04 14:55:29 +010057 net.addLink("datacenter1", s1)
58 net.addLink(s1, dc3)
59 net.addLink(s1, "datacenter4")
peusterm9c252b62016-01-06 16:59:53 +010060
peusterme4e89d32016-01-07 09:14:54 +010061 """
62 5. We want to access and control our data centers from the outside,
peusterm5b844a12016-01-11 15:58:15 +010063 e.g., we want to connect an orchestrator to start/stop compute
peusterme4e89d32016-01-07 09:14:54 +010064 resources aka. VNFs (represented by Docker containers in the emulated)
65
66 So we need to instantiate API endpoints (e.g. a zerorpc or REST
67 interface). Depending on the endpoint implementations, we can connect
68 one or more data centers to it, which can then be controlled through
69 this API, e.g., start/stop/list compute instances.
70 """
71 # create a new instance of a endpoint implementation
peusterm9c252b62016-01-06 16:59:53 +010072 zapi1 = ZeroRpcApiEndpoint("0.0.0.0", 4242)
peusterme4e89d32016-01-07 09:14:54 +010073 # connect data centers to this endpoint
peusterm9c252b62016-01-06 16:59:53 +010074 zapi1.connectDatacenter(dc1)
75 zapi1.connectDatacenter(dc2)
peusterm53504942016-02-04 16:09:28 +010076 zapi1.connectDatacenter(dc3)
77 zapi1.connectDatacenter(dc4)
peusterme4e89d32016-01-07 09:14:54 +010078 # run API endpoint server (in another thread, don't block)
peusterm9c252b62016-01-06 16:59:53 +010079 zapi1.start()
peusterme4e89d32016-01-07 09:14:54 +010080
81 """
82 5.1. For our example, we create a second endpoint to illustrate that
peustermeecafde2016-01-15 10:23:26 +010083 this is supported by our design. This feature allows us to have
peusterme4e89d32016-01-07 09:14:54 +010084 one API endpoint for each data center. This makes the emulation
85 environment more realistic because you can easily create one
86 OpenStack-like REST API endpoint for *each* data center.
87 This will look like a real-world multi PoP/data center deployment
88 from the perspective of an orchestrator.
89 """
peusterm9c252b62016-01-06 16:59:53 +010090 zapi2 = ZeroRpcApiEndpoint("0.0.0.0", 4343)
91 zapi2.connectDatacenter(dc3)
92 zapi2.connectDatacenter(dc4)
93 zapi2.start()
94
peusterme4e89d32016-01-07 09:14:54 +010095 """
96 6. Finally we are done and can start our network (the emulator).
97 We can also enter the Mininet CLI to interactively interact
98 with our compute resources (just like in default Mininet).
99 But we can also implement fully automated experiments that
100 can be executed again and again.
101 """
peustermcbcd4c22015-12-28 11:33:42 +0100102 net.start()
peusterme4e89d32016-01-07 09:14:54 +0100103 net.CLI()
104 # when the user types exit in the CLI, we stop the emulator
105 net.stop()
peustermcbcd4c22015-12-28 11:33:42 +0100106
107
108def main():
peustermd47ab252016-01-15 10:35:06 +0100109 setLogLevel('info') # set Mininet loglevel
peustermcbcd4c22015-12-28 11:33:42 +0100110 create_topology1()
111
112
113if __name__ == '__main__':
114 main()