blob: eabec443cf44ab45ba47623f150e703714615089 [file] [log] [blame]
hadik3rf3bf0e72016-06-27 18:20:44 +02001"""
peustermc89ba382016-07-08 13:46:32 +02002Copyright (c) 2015 SONATA-NFV
3ALL RIGHTS RESERVED.
hadik3rf3bf0e72016-06-27 18:20:44 +02004
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
hadik3rf3bf0e72016-06-27 18:20:44 +02008
peustermc89ba382016-07-08 13:46:32 +02009 http://www.apache.org/licenses/LICENSE-2.0
hadik3rf3bf0e72016-06-27 18:20:44 +020010
peustermc89ba382016-07-08 13:46:32 +020011Unless 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.
hadik3rf3bf0e72016-06-27 18:20:44 +020016
peustermc89ba382016-07-08 13:46:32 +020017Neither 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.
hadik3rf3bf0e72016-06-27 18:20:44 +020021
peustermc89ba382016-07-08 13:46:32 +020022This 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).
hadik3rf3bf0e72016-06-27 18:20:44 +020027"""
28import logging
29from mininet.log import setLogLevel
30from emuvim.dcemulator.net import DCNetwork
stevenvanrossem73efd192016-06-29 01:44:07 +020031from emuvim.api.rest.rest_api_endpoint import RestApiEndpoint
32
33from emuvim.api.zerorpc.compute import ZeroRpcApiEndpoint
hadik3rf3bf0e72016-06-27 18:20:44 +020034from emuvim.api.zerorpc.network import ZeroRpcApiEndpointDCNetwork
35
36logging.basicConfig(level=logging.INFO)
37
38
39def create_topology1():
40 """
41 1. Create a data center network object (DCNetwork)
42 """
peusterm3f7eb552016-07-04 11:19:34 +020043 net = DCNetwork(monitor=True, enable_learning=True)
hadik3rf3bf0e72016-06-27 18:20:44 +020044
45 """
46 1b. add a monitoring agent to the DCNetwork
47 """
stevenvanrossem73efd192016-06-29 01:44:07 +020048 #keep old zeroRPC interface to test the prometheus metric query
hadik3rf3bf0e72016-06-27 18:20:44 +020049 mon_api = ZeroRpcApiEndpointDCNetwork("0.0.0.0", 5151)
50 mon_api.connectDCNetwork(net)
51 mon_api.start()
52 """
53 2. Add (logical) data centers to the topology
54 (each data center is one "bigswitch" in our simplified
55 first prototype)
56 """
57 dc1 = net.addDatacenter("datacenter1")
58 dc2 = net.addDatacenter("datacenter2")
59 dc3 = net.addDatacenter("long_data_center_name3")
60 dc4 = net.addDatacenter(
61 "datacenter4",
62 metadata={"mydata": "we can also add arbitrary metadata to each DC"})
63
64 """
65 3. You can add additional SDN switches for data center
66 interconnections to the network.
67 """
68 s1 = net.addSwitch("s1")
69
70 """
71 4. Add links between your data centers and additional switches
72 to define you topology.
73 These links can use Mininet's features to limit bw, add delay or jitter.
74 """
75 net.addLink(dc1, dc2)
76 net.addLink("datacenter1", s1)
77 net.addLink(s1, dc3)
78 net.addLink(s1, "datacenter4")
79
80 """
81 5. We want to access and control our data centers from the outside,
82 e.g., we want to connect an orchestrator to start/stop compute
83 resources aka. VNFs (represented by Docker containers in the emulated)
84
85 So we need to instantiate API endpoints (e.g. a zerorpc or REST
86 interface). Depending on the endpoint implementations, we can connect
87 one or more data centers to it, which can then be controlled through
88 this API, e.g., start/stop/list compute instances.
89 """
stevenvanrossem73efd192016-06-29 01:44:07 +020090 # keep the old zeroRPC interface for the prometheus metric query test
91 zapi1 = ZeroRpcApiEndpoint("0.0.0.0", 4242)
92 # connect data centers to this endpoint
93 zapi1.connectDatacenter(dc1)
94 zapi1.connectDatacenter(dc2)
95 # run API endpoint server (in another thread, don't block)
96 zapi1.start()
97
hadik3rf3bf0e72016-06-27 18:20:44 +020098 # create a new instance of a endpoint implementation
peusterm0a336cc2016-07-04 09:15:47 +020099 api1 = RestApiEndpoint("127.0.0.1", 5001)
hadik3rf3bf0e72016-06-27 18:20:44 +0200100 # connect data centers to this endpoint
101 api1.connectDatacenter(dc1)
102 api1.connectDatacenter(dc2)
103 api1.connectDatacenter(dc3)
104 api1.connectDatacenter(dc4)
stevenvanrossem73efd192016-06-29 01:44:07 +0200105 # connect total network also, needed to do the chaining and monitoring
106 api1.connectDCNetwork(net)
hadik3rf3bf0e72016-06-27 18:20:44 +0200107 # run API endpoint server (in another thread, don't block)
108 api1.start()
109
110 """
111 6. Finally we are done and can start our network (the emulator).
112 We can also enter the Mininet CLI to interactively interact
113 with our compute resources (just like in default Mininet).
114 But we can also implement fully automated experiments that
115 can be executed again and again.
116 """
117 net.start()
118 net.CLI()
119 # when the user types exit in the CLI, we stop the emulator
120 net.stop()
121
122
123def main():
124 setLogLevel('info') # set Mininet loglevel
125 create_topology1()
126
127
128if __name__ == '__main__':
129 main()