blob: 55f0037c3b617dbe9145efa474ac33830ab9a1fe [file] [log] [blame]
peustermcbcd4c22015-12-28 11:33:42 +01001"""
peustermc89ba382016-07-08 13:46:32 +02002Copyright (c) 2015 SONATA-NFV
3ALL RIGHTS RESERVED.
peustermcbcd4c22015-12-28 11:33:42 +01004
peustermc89ba382016-07-08 13:46:32 +02005Licensed under the Apache License, Version 2.0 (the "License");
6you may not use this file except in compliance with the License.
7You may obtain a copy of the License at
peusterme4e89d32016-01-07 09:14:54 +01008
peustermc89ba382016-07-08 13:46:32 +02009 http://www.apache.org/licenses/LICENSE-2.0
10
11Unless required by applicable law or agreed to in writing, software
12distributed under the License is distributed on an "AS IS" BASIS,
13WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14See the License for the specific language governing permissions and
15limitations under the License.
16
17Neither the name of the SONATA-NFV [, ANY ADDITIONAL AFFILIATION]
18nor the names of its contributors may be used to endorse or promote
19products derived from this software without specific prior written
20permission.
21
22This work has been performed in the framework of the SONATA project,
23funded by the European Commission under Grant number 671517 through
24the Horizon 2020 and 5G-PPP programmes. The authors would like to
25acknowledge the contributions of their colleagues of the SONATA
26partner consortium (www.sonata-nfv.eu).
27"""
28"""
peusterme4e89d32016-01-07 09:14:54 +010029This is an example that shows how a user of the emulation tool can
30define network topologies with multiple emulated cloud data centers.
31
32The definition is done with a Python API which looks very similar to the
33Mininet API (in fact it is a wrapper for it).
34
35We only specify the topology *between* data centers not within a single
36data center (data center internal setups or placements are not of interest,
37we want to experiment with VNF chains deployed across multiple PoPs).
38
peustermcbcd4c22015-12-28 11:33:42 +010039The original Mininet API has to be completely hidden and not be used by this
40script.
41"""
42import logging
peustermd47ab252016-01-15 10:35:06 +010043from mininet.log import setLogLevel
cgeoffroy9524ad32016-03-03 18:24:15 +010044from emuvim.dcemulator.net import DCNetwork
peusterm53337bc2016-03-08 10:11:48 +010045from emuvim.api.zerorpc.compute import ZeroRpcApiEndpoint
peustermc038a992016-07-01 12:15:58 +020046from emuvim.api.rest.rest_api_endpoint import RestApiEndpoint
peusterm53337bc2016-03-08 10:11:48 +010047from emuvim.api.zerorpc.network import ZeroRpcApiEndpointDCNetwork
peustermcbcd4c22015-12-28 11:33:42 +010048
peustermbd44f4a2016-01-13 14:53:30 +010049logging.basicConfig(level=logging.INFO)
peustermcbcd4c22015-12-28 11:33:42 +010050
51
52def create_topology1():
peusterme4e89d32016-01-07 09:14:54 +010053 """
54 1. Create a data center network object (DCNetwork)
55 """
peustermcbcd4c22015-12-28 11:33:42 +010056 net = DCNetwork()
57
peusterme4e89d32016-01-07 09:14:54 +010058 """
stevenvanrossem58bd1f22016-02-17 11:09:04 +010059 1b. add a monitoring agent to the DCNetwork
60 """
61 mon_api = ZeroRpcApiEndpointDCNetwork("0.0.0.0", 5151)
62 mon_api.connectDCNetwork(net)
63 mon_api.start()
stevenvanrossem58bd1f22016-02-17 11:09:04 +010064 """
peusterme4e89d32016-01-07 09:14:54 +010065 2. Add (logical) data centers to the topology
66 (each data center is one "bigswitch" in our simplified
67 first prototype)
68 """
peusterma47db032016-02-04 14:55:29 +010069 dc1 = net.addDatacenter("datacenter1")
70 dc2 = net.addDatacenter("datacenter2")
peusterm53504942016-02-04 16:09:28 +010071 dc3 = net.addDatacenter("long_data_center_name3")
72 dc4 = net.addDatacenter(
73 "datacenter4",
74 metadata={"mydata": "we can also add arbitrary metadata to each DC"})
peusterme4e89d32016-01-07 09:14:54 +010075
76 """
77 3. You can add additional SDN switches for data center
78 interconnections to the network.
79 """
peustermcbcd4c22015-12-28 11:33:42 +010080 s1 = net.addSwitch("s1")
peusterme4e89d32016-01-07 09:14:54 +010081
82 """
83 4. Add links between your data centers and additional switches
84 to define you topology.
85 These links can use Mininet's features to limit bw, add delay or jitter.
86 """
peustermcbcd4c22015-12-28 11:33:42 +010087 net.addLink(dc1, dc2)
peusterma47db032016-02-04 14:55:29 +010088 net.addLink("datacenter1", s1)
89 net.addLink(s1, dc3)
90 net.addLink(s1, "datacenter4")
peusterm9c252b62016-01-06 16:59:53 +010091
peusterme4e89d32016-01-07 09:14:54 +010092 """
93 5. We want to access and control our data centers from the outside,
peusterm5b844a12016-01-11 15:58:15 +010094 e.g., we want to connect an orchestrator to start/stop compute
peusterme4e89d32016-01-07 09:14:54 +010095 resources aka. VNFs (represented by Docker containers in the emulated)
96
97 So we need to instantiate API endpoints (e.g. a zerorpc or REST
98 interface). Depending on the endpoint implementations, we can connect
99 one or more data centers to it, which can then be controlled through
100 this API, e.g., start/stop/list compute instances.
101 """
102 # create a new instance of a endpoint implementation
peusterm9c252b62016-01-06 16:59:53 +0100103 zapi1 = ZeroRpcApiEndpoint("0.0.0.0", 4242)
peusterm0a336cc2016-07-04 09:15:47 +0200104 rapi1 = RestApiEndpoint("127.0.0.1", 5001)
peusterme4e89d32016-01-07 09:14:54 +0100105 # connect data centers to this endpoint
peusterm9c252b62016-01-06 16:59:53 +0100106 zapi1.connectDatacenter(dc1)
107 zapi1.connectDatacenter(dc2)
peusterm53504942016-02-04 16:09:28 +0100108 zapi1.connectDatacenter(dc3)
109 zapi1.connectDatacenter(dc4)
peustermc038a992016-07-01 12:15:58 +0200110 rapi1.connectDatacenter(dc1)
111 rapi1.connectDatacenter(dc2)
112 rapi1.connectDatacenter(dc3)
113 rapi1.connectDatacenter(dc4)
peusterme4e89d32016-01-07 09:14:54 +0100114 # run API endpoint server (in another thread, don't block)
peusterm9c252b62016-01-06 16:59:53 +0100115 zapi1.start()
peustermc038a992016-07-01 12:15:58 +0200116 rapi1.start()
peusterme4e89d32016-01-07 09:14:54 +0100117
118 """
119 5.1. For our example, we create a second endpoint to illustrate that
peustermeecafde2016-01-15 10:23:26 +0100120 this is supported by our design. This feature allows us to have
peusterme4e89d32016-01-07 09:14:54 +0100121 one API endpoint for each data center. This makes the emulation
122 environment more realistic because you can easily create one
123 OpenStack-like REST API endpoint for *each* data center.
124 This will look like a real-world multi PoP/data center deployment
125 from the perspective of an orchestrator.
126 """
peusterm9c252b62016-01-06 16:59:53 +0100127 zapi2 = ZeroRpcApiEndpoint("0.0.0.0", 4343)
128 zapi2.connectDatacenter(dc3)
129 zapi2.connectDatacenter(dc4)
130 zapi2.start()
131
peusterme4e89d32016-01-07 09:14:54 +0100132 """
133 6. Finally we are done and can start our network (the emulator).
134 We can also enter the Mininet CLI to interactively interact
135 with our compute resources (just like in default Mininet).
136 But we can also implement fully automated experiments that
137 can be executed again and again.
138 """
peustermcbcd4c22015-12-28 11:33:42 +0100139 net.start()
peusterme4e89d32016-01-07 09:14:54 +0100140 net.CLI()
141 # when the user types exit in the CLI, we stop the emulator
142 net.stop()
peustermcbcd4c22015-12-28 11:33:42 +0100143
144
145def main():
peustermd47ab252016-01-15 10:35:06 +0100146 setLogLevel('info') # set Mininet loglevel
peustermcbcd4c22015-12-28 11:33:42 +0100147 create_topology1()
148
149
150if __name__ == '__main__':
151 main()