| 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 | c038a99 | 2016-07-01 12:15:58 +0200 | [diff] [blame] | 45 | from emuvim.api.rest.rest_api_endpoint import RestApiEndpoint |
| peusterm | 085f442 | 2017-03-21 08:20:18 +0100 | [diff] [blame] | 46 | from mininet.node import RemoteController |
| peusterm | cbcd4c2 | 2015-12-28 11:33:42 +0100 | [diff] [blame] | 47 | |
| peusterm | bd44f4a | 2016-01-13 14:53:30 +0100 | [diff] [blame] | 48 | logging.basicConfig(level=logging.INFO) |
| peusterm | cbcd4c2 | 2015-12-28 11:33:42 +0100 | [diff] [blame] | 49 | |
| 50 | |
| 51 | def create_topology1(): |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 52 | """ |
| 53 | 1. Create a data center network object (DCNetwork) |
| 54 | """ |
| peusterm | 085f442 | 2017-03-21 08:20:18 +0100 | [diff] [blame] | 55 | net = DCNetwork(controller=RemoteController, monitor=False, enable_learning=True) |
| 56 | |
| stevenvanrossem | 58bd1f2 | 2016-02-17 11:09:04 +0100 | [diff] [blame] | 57 | """ |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 58 | 2. Add (logical) data centers to the topology |
| 59 | (each data center is one "bigswitch" in our simplified |
| 60 | first prototype) |
| 61 | """ |
| peusterm | a47db03 | 2016-02-04 14:55:29 +0100 | [diff] [blame] | 62 | dc1 = net.addDatacenter("datacenter1") |
| 63 | dc2 = net.addDatacenter("datacenter2") |
| peusterm | 5350494 | 2016-02-04 16:09:28 +0100 | [diff] [blame] | 64 | 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"}) |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 68 | |
| 69 | """ |
| 70 | 3. You can add additional SDN switches for data center |
| 71 | interconnections to the network. |
| 72 | """ |
| peusterm | cbcd4c2 | 2015-12-28 11:33:42 +0100 | [diff] [blame] | 73 | s1 = net.addSwitch("s1") |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 74 | |
| 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 | """ |
| peusterm | cbcd4c2 | 2015-12-28 11:33:42 +0100 | [diff] [blame] | 80 | net.addLink(dc1, dc2) |
| peusterm | a47db03 | 2016-02-04 14:55:29 +0100 | [diff] [blame] | 81 | net.addLink("datacenter1", s1) |
| 82 | net.addLink(s1, dc3) |
| 83 | net.addLink(s1, "datacenter4") |
| peusterm | 9c252b6 | 2016-01-06 16:59:53 +0100 | [diff] [blame] | 84 | |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 85 | """ |
| 86 | 5. We want to access and control our data centers from the outside, |
| peusterm | 5b844a1 | 2016-01-11 15:58:15 +0100 | [diff] [blame] | 87 | e.g., we want to connect an orchestrator to start/stop compute |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 88 | 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 |
| stevenvanrossem | f693a3b | 2017-06-01 15:15:59 +0200 | [diff] [blame] | 96 | rapi1 = RestApiEndpoint("127.0.0.1", 5001, net) |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 97 | # connect data centers to this endpoint |
| peusterm | c038a99 | 2016-07-01 12:15:58 +0200 | [diff] [blame] | 98 | rapi1.connectDatacenter(dc1) |
| 99 | rapi1.connectDatacenter(dc2) |
| 100 | rapi1.connectDatacenter(dc3) |
| 101 | rapi1.connectDatacenter(dc4) |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 102 | # run API endpoint server (in another thread, don't block) |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 103 | |
| peusterm | 085f442 | 2017-03-21 08:20:18 +0100 | [diff] [blame] | 104 | rapi1.start() |
| peusterm | 9c252b6 | 2016-01-06 16:59:53 +0100 | [diff] [blame] | 105 | |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 106 | """ |
| 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 | """ |
| peusterm | cbcd4c2 | 2015-12-28 11:33:42 +0100 | [diff] [blame] | 113 | net.start() |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 114 | net.CLI() |
| 115 | # when the user types exit in the CLI, we stop the emulator |
| 116 | net.stop() |
| peusterm | cbcd4c2 | 2015-12-28 11:33:42 +0100 | [diff] [blame] | 117 | |
| 118 | |
| 119 | def main(): |
| peusterm | d47ab25 | 2016-01-15 10:35:06 +0100 | [diff] [blame] | 120 | setLogLevel('info') # set Mininet loglevel |
| peusterm | cbcd4c2 | 2015-12-28 11:33:42 +0100 | [diff] [blame] | 121 | create_topology1() |
| 122 | |
| 123 | |
| 124 | if __name__ == '__main__': |
| 125 | main() |