blob: d63a07c98d39a1312cabd232acb4942200d94572 [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
peustermc038a992016-07-01 12:15:58 +020045from emuvim.api.rest.rest_api_endpoint import RestApiEndpoint
peusterm085f4422017-03-21 08:20:18 +010046from mininet.node import RemoteController
peustermcbcd4c22015-12-28 11:33:42 +010047
peustermbd44f4a2016-01-13 14:53:30 +010048logging.basicConfig(level=logging.INFO)
peustermcbcd4c22015-12-28 11:33:42 +010049
50
51def create_topology1():
peusterme4e89d32016-01-07 09:14:54 +010052 """
53 1. Create a data center network object (DCNetwork)
54 """
peusterm085f4422017-03-21 08:20:18 +010055 net = DCNetwork(controller=RemoteController, monitor=False, enable_learning=True)
56
stevenvanrossem58bd1f22016-02-17 11:09:04 +010057 """
peusterme4e89d32016-01-07 09:14:54 +010058 2. Add (logical) data centers to the topology
59 (each data center is one "bigswitch" in our simplified
60 first prototype)
61 """
peusterma47db032016-02-04 14:55:29 +010062 dc1 = net.addDatacenter("datacenter1")
63 dc2 = net.addDatacenter("datacenter2")
peusterm53504942016-02-04 16:09:28 +010064 dc3 = net.addDatacenter("long_data_center_name3")
65 dc4 = net.addDatacenter(
66 "datacenter4",
67 metadata={"mydata": "we can also add arbitrary metadata to each DC"})
peusterme4e89d32016-01-07 09:14:54 +010068
69 """
70 3. You can add additional SDN switches for data center
71 interconnections to the network.
72 """
peustermcbcd4c22015-12-28 11:33:42 +010073 s1 = net.addSwitch("s1")
peusterme4e89d32016-01-07 09:14:54 +010074
75 """
76 4. Add links between your data centers and additional switches
77 to define you topology.
78 These links can use Mininet's features to limit bw, add delay or jitter.
79 """
peustermcbcd4c22015-12-28 11:33:42 +010080 net.addLink(dc1, dc2)
peusterma47db032016-02-04 14:55:29 +010081 net.addLink("datacenter1", s1)
82 net.addLink(s1, dc3)
83 net.addLink(s1, "datacenter4")
peusterm9c252b62016-01-06 16:59:53 +010084
peusterme4e89d32016-01-07 09:14:54 +010085 """
86 5. We want to access and control our data centers from the outside,
peusterm5b844a12016-01-11 15:58:15 +010087 e.g., we want to connect an orchestrator to start/stop compute
peusterme4e89d32016-01-07 09:14:54 +010088 resources aka. VNFs (represented by Docker containers in the emulated)
89
90 So we need to instantiate API endpoints (e.g. a zerorpc or REST
91 interface). Depending on the endpoint implementations, we can connect
92 one or more data centers to it, which can then be controlled through
93 this API, e.g., start/stop/list compute instances.
94 """
95 # create a new instance of a endpoint implementation
peusterm0a336cc2016-07-04 09:15:47 +020096 rapi1 = RestApiEndpoint("127.0.0.1", 5001)
peusterme4e89d32016-01-07 09:14:54 +010097 # connect data centers to this endpoint
peustermc038a992016-07-01 12:15:58 +020098 rapi1.connectDatacenter(dc1)
99 rapi1.connectDatacenter(dc2)
100 rapi1.connectDatacenter(dc3)
101 rapi1.connectDatacenter(dc4)
peusterme4e89d32016-01-07 09:14:54 +0100102 # run API endpoint server (in another thread, don't block)
peusterme4e89d32016-01-07 09:14:54 +0100103
peusterm085f4422017-03-21 08:20:18 +0100104 rapi1.start()
peusterm9c252b62016-01-06 16:59:53 +0100105
peusterme4e89d32016-01-07 09:14:54 +0100106 """
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 """
peustermcbcd4c22015-12-28 11:33:42 +0100113 net.start()
peusterme4e89d32016-01-07 09:14:54 +0100114 net.CLI()
115 # when the user types exit in the CLI, we stop the emulator
116 net.stop()
peustermcbcd4c22015-12-28 11:33:42 +0100117
118
119def main():
peustermd47ab252016-01-15 10:35:06 +0100120 setLogLevel('info') # set Mininet loglevel
peustermcbcd4c22015-12-28 11:33:42 +0100121 create_topology1()
122
123
124if __name__ == '__main__':
125 main()