| peusterm | cbcd4c2 | 2015-12-28 11:33:42 +0100 | [diff] [blame] | 1 | """ |
| peusterm | c89ba38 | 2016-07-08 13:46:32 +0200 | [diff] [blame] | 2 | Copyright (c) 2015 SONATA-NFV |
| 3 | ALL RIGHTS RESERVED. |
| peusterm | cbcd4c2 | 2015-12-28 11:33:42 +0100 | [diff] [blame] | 4 | |
| peusterm | c89ba38 | 2016-07-08 13:46:32 +0200 | [diff] [blame] | 5 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | you may not use this file except in compliance with the License. |
| 7 | You may obtain a copy of the License at |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 8 | |
| peusterm | c89ba38 | 2016-07-08 13:46:32 +0200 | [diff] [blame] | 9 | http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | |
| 11 | Unless required by applicable law or agreed to in writing, software |
| 12 | distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | See the License for the specific language governing permissions and |
| 15 | limitations under the License. |
| 16 | |
| 17 | Neither the name of the SONATA-NFV [, ANY ADDITIONAL AFFILIATION] |
| 18 | nor the names of its contributors may be used to endorse or promote |
| 19 | products derived from this software without specific prior written |
| 20 | permission. |
| 21 | |
| 22 | This work has been performed in the framework of the SONATA project, |
| 23 | funded by the European Commission under Grant number 671517 through |
| 24 | the Horizon 2020 and 5G-PPP programmes. The authors would like to |
| 25 | acknowledge the contributions of their colleagues of the SONATA |
| 26 | partner consortium (www.sonata-nfv.eu). |
| 27 | """ |
| 28 | """ |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 29 | This is an example that shows how a user of the emulation tool can |
| 30 | define network topologies with multiple emulated cloud data centers. |
| 31 | |
| 32 | The definition is done with a Python API which looks very similar to the |
| 33 | Mininet API (in fact it is a wrapper for it). |
| 34 | |
| 35 | We only specify the topology *between* data centers not within a single |
| 36 | data center (data center internal setups or placements are not of interest, |
| 37 | we want to experiment with VNF chains deployed across multiple PoPs). |
| 38 | |
| peusterm | cbcd4c2 | 2015-12-28 11:33:42 +0100 | [diff] [blame] | 39 | The original Mininet API has to be completely hidden and not be used by this |
| 40 | script. |
| 41 | """ |
| 42 | import logging |
| peusterm | d47ab25 | 2016-01-15 10:35:06 +0100 | [diff] [blame] | 43 | from mininet.log import setLogLevel |
| cgeoffroy | 9524ad3 | 2016-03-03 18:24:15 +0100 | [diff] [blame] | 44 | from emuvim.dcemulator.net import DCNetwork |
| peusterm | 53337bc | 2016-03-08 10:11:48 +0100 | [diff] [blame] | 45 | from emuvim.api.zerorpc.compute import ZeroRpcApiEndpoint |
| peusterm | c038a99 | 2016-07-01 12:15:58 +0200 | [diff] [blame] | 46 | from emuvim.api.rest.rest_api_endpoint import RestApiEndpoint |
| peusterm | 53337bc | 2016-03-08 10:11:48 +0100 | [diff] [blame] | 47 | from emuvim.api.zerorpc.network import ZeroRpcApiEndpointDCNetwork |
| peusterm | cbcd4c2 | 2015-12-28 11:33:42 +0100 | [diff] [blame] | 48 | |
| peusterm | bd44f4a | 2016-01-13 14:53:30 +0100 | [diff] [blame] | 49 | logging.basicConfig(level=logging.INFO) |
| peusterm | cbcd4c2 | 2015-12-28 11:33:42 +0100 | [diff] [blame] | 50 | |
| 51 | |
| 52 | def create_topology1(): |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 53 | """ |
| 54 | 1. Create a data center network object (DCNetwork) |
| 55 | """ |
| peusterm | cbcd4c2 | 2015-12-28 11:33:42 +0100 | [diff] [blame] | 56 | net = DCNetwork() |
| 57 | |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 58 | """ |
| stevenvanrossem | 58bd1f2 | 2016-02-17 11:09:04 +0100 | [diff] [blame] | 59 | 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() |
| stevenvanrossem | 58bd1f2 | 2016-02-17 11:09:04 +0100 | [diff] [blame] | 64 | """ |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 65 | 2. Add (logical) data centers to the topology |
| 66 | (each data center is one "bigswitch" in our simplified |
| 67 | first prototype) |
| 68 | """ |
| peusterm | a47db03 | 2016-02-04 14:55:29 +0100 | [diff] [blame] | 69 | dc1 = net.addDatacenter("datacenter1") |
| 70 | dc2 = net.addDatacenter("datacenter2") |
| peusterm | 5350494 | 2016-02-04 16:09:28 +0100 | [diff] [blame] | 71 | 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"}) |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 75 | |
| 76 | """ |
| 77 | 3. You can add additional SDN switches for data center |
| 78 | interconnections to the network. |
| 79 | """ |
| peusterm | cbcd4c2 | 2015-12-28 11:33:42 +0100 | [diff] [blame] | 80 | s1 = net.addSwitch("s1") |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 81 | |
| 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 | """ |
| peusterm | cbcd4c2 | 2015-12-28 11:33:42 +0100 | [diff] [blame] | 87 | net.addLink(dc1, dc2) |
| peusterm | a47db03 | 2016-02-04 14:55:29 +0100 | [diff] [blame] | 88 | net.addLink("datacenter1", s1) |
| 89 | net.addLink(s1, dc3) |
| 90 | net.addLink(s1, "datacenter4") |
| peusterm | 9c252b6 | 2016-01-06 16:59:53 +0100 | [diff] [blame] | 91 | |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 92 | """ |
| 93 | 5. We want to access and control our data centers from the outside, |
| peusterm | 5b844a1 | 2016-01-11 15:58:15 +0100 | [diff] [blame] | 94 | e.g., we want to connect an orchestrator to start/stop compute |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 95 | 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 |
| peusterm | 9c252b6 | 2016-01-06 16:59:53 +0100 | [diff] [blame] | 103 | zapi1 = ZeroRpcApiEndpoint("0.0.0.0", 4242) |
| peusterm | 0a336cc | 2016-07-04 09:15:47 +0200 | [diff] [blame] | 104 | rapi1 = RestApiEndpoint("127.0.0.1", 5001) |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 105 | # connect data centers to this endpoint |
| peusterm | 9c252b6 | 2016-01-06 16:59:53 +0100 | [diff] [blame] | 106 | zapi1.connectDatacenter(dc1) |
| 107 | zapi1.connectDatacenter(dc2) |
| peusterm | 5350494 | 2016-02-04 16:09:28 +0100 | [diff] [blame] | 108 | zapi1.connectDatacenter(dc3) |
| 109 | zapi1.connectDatacenter(dc4) |
| peusterm | c038a99 | 2016-07-01 12:15:58 +0200 | [diff] [blame] | 110 | rapi1.connectDatacenter(dc1) |
| 111 | rapi1.connectDatacenter(dc2) |
| 112 | rapi1.connectDatacenter(dc3) |
| 113 | rapi1.connectDatacenter(dc4) |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 114 | # run API endpoint server (in another thread, don't block) |
| peusterm | 9c252b6 | 2016-01-06 16:59:53 +0100 | [diff] [blame] | 115 | zapi1.start() |
| peusterm | c038a99 | 2016-07-01 12:15:58 +0200 | [diff] [blame] | 116 | rapi1.start() |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 117 | |
| 118 | """ |
| 119 | 5.1. For our example, we create a second endpoint to illustrate that |
| peusterm | eecafde | 2016-01-15 10:23:26 +0100 | [diff] [blame] | 120 | this is supported by our design. This feature allows us to have |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 121 | 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 | """ |
| peusterm | 9c252b6 | 2016-01-06 16:59:53 +0100 | [diff] [blame] | 127 | zapi2 = ZeroRpcApiEndpoint("0.0.0.0", 4343) |
| 128 | zapi2.connectDatacenter(dc3) |
| 129 | zapi2.connectDatacenter(dc4) |
| 130 | zapi2.start() |
| 131 | |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 132 | """ |
| 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 | """ |
| peusterm | cbcd4c2 | 2015-12-28 11:33:42 +0100 | [diff] [blame] | 139 | net.start() |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 140 | net.CLI() |
| 141 | # when the user types exit in the CLI, we stop the emulator |
| 142 | net.stop() |
| peusterm | cbcd4c2 | 2015-12-28 11:33:42 +0100 | [diff] [blame] | 143 | |
| 144 | |
| 145 | def main(): |
| peusterm | d47ab25 | 2016-01-15 10:35:06 +0100 | [diff] [blame] | 146 | setLogLevel('info') # set Mininet loglevel |
| peusterm | cbcd4c2 | 2015-12-28 11:33:42 +0100 | [diff] [blame] | 147 | create_topology1() |
| 148 | |
| 149 | |
| 150 | if __name__ == '__main__': |
| 151 | main() |