| peusterm | cbcd4c2 | 2015-12-28 11:33:42 +0100 | [diff] [blame] | 1 | """ |
| 2 | This is an example topology for the distributed cloud emulator (dcemulator). |
| 3 | (c) 2015 by Manuel Peuster <manuel.peuster@upb.de> |
| 4 | |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 5 | |
| 6 | This is an example that shows how a user of the emulation tool can |
| 7 | define network topologies with multiple emulated cloud data centers. |
| 8 | |
| 9 | The definition is done with a Python API which looks very similar to the |
| 10 | Mininet API (in fact it is a wrapper for it). |
| 11 | |
| 12 | We only specify the topology *between* data centers not within a single |
| 13 | data center (data center internal setups or placements are not of interest, |
| 14 | we want to experiment with VNF chains deployed across multiple PoPs). |
| 15 | |
| peusterm | cbcd4c2 | 2015-12-28 11:33:42 +0100 | [diff] [blame] | 16 | The original Mininet API has to be completely hidden and not be used by this |
| 17 | script. |
| 18 | """ |
| 19 | import logging |
| peusterm | d47ab25 | 2016-01-15 10:35:06 +0100 | [diff] [blame] | 20 | from mininet.log import setLogLevel |
| cgeoffroy | 9524ad3 | 2016-03-03 18:24:15 +0100 | [diff] [blame] | 21 | from emuvim.dcemulator.net import DCNetwork |
| peusterm | 53337bc | 2016-03-08 10:11:48 +0100 | [diff] [blame] | 22 | from emuvim.api.zerorpc.compute import ZeroRpcApiEndpoint |
| peusterm | c038a99 | 2016-07-01 12:15:58 +0200 | [diff] [blame] | 23 | from emuvim.api.rest.rest_api_endpoint import RestApiEndpoint |
| peusterm | 53337bc | 2016-03-08 10:11:48 +0100 | [diff] [blame] | 24 | from emuvim.api.zerorpc.network import ZeroRpcApiEndpointDCNetwork |
| peusterm | cbcd4c2 | 2015-12-28 11:33:42 +0100 | [diff] [blame] | 25 | |
| peusterm | bd44f4a | 2016-01-13 14:53:30 +0100 | [diff] [blame] | 26 | logging.basicConfig(level=logging.INFO) |
| peusterm | cbcd4c2 | 2015-12-28 11:33:42 +0100 | [diff] [blame] | 27 | |
| 28 | |
| 29 | def create_topology1(): |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 30 | """ |
| 31 | 1. Create a data center network object (DCNetwork) |
| 32 | """ |
| peusterm | cbcd4c2 | 2015-12-28 11:33:42 +0100 | [diff] [blame] | 33 | net = DCNetwork() |
| 34 | |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 35 | """ |
| stevenvanrossem | 58bd1f2 | 2016-02-17 11:09:04 +0100 | [diff] [blame] | 36 | 1b. add a monitoring agent to the DCNetwork |
| 37 | """ |
| 38 | mon_api = ZeroRpcApiEndpointDCNetwork("0.0.0.0", 5151) |
| 39 | mon_api.connectDCNetwork(net) |
| 40 | mon_api.start() |
| stevenvanrossem | 58bd1f2 | 2016-02-17 11:09:04 +0100 | [diff] [blame] | 41 | """ |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 42 | 2. Add (logical) data centers to the topology |
| 43 | (each data center is one "bigswitch" in our simplified |
| 44 | first prototype) |
| 45 | """ |
| peusterm | a47db03 | 2016-02-04 14:55:29 +0100 | [diff] [blame] | 46 | dc1 = net.addDatacenter("datacenter1") |
| 47 | dc2 = net.addDatacenter("datacenter2") |
| peusterm | 5350494 | 2016-02-04 16:09:28 +0100 | [diff] [blame] | 48 | dc3 = net.addDatacenter("long_data_center_name3") |
| 49 | dc4 = net.addDatacenter( |
| 50 | "datacenter4", |
| 51 | metadata={"mydata": "we can also add arbitrary metadata to each DC"}) |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 52 | |
| 53 | """ |
| 54 | 3. You can add additional SDN switches for data center |
| 55 | interconnections to the network. |
| 56 | """ |
| peusterm | cbcd4c2 | 2015-12-28 11:33:42 +0100 | [diff] [blame] | 57 | s1 = net.addSwitch("s1") |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 58 | |
| 59 | """ |
| 60 | 4. Add links between your data centers and additional switches |
| 61 | to define you topology. |
| 62 | These links can use Mininet's features to limit bw, add delay or jitter. |
| 63 | """ |
| peusterm | cbcd4c2 | 2015-12-28 11:33:42 +0100 | [diff] [blame] | 64 | net.addLink(dc1, dc2) |
| peusterm | a47db03 | 2016-02-04 14:55:29 +0100 | [diff] [blame] | 65 | net.addLink("datacenter1", s1) |
| 66 | net.addLink(s1, dc3) |
| 67 | net.addLink(s1, "datacenter4") |
| peusterm | 9c252b6 | 2016-01-06 16:59:53 +0100 | [diff] [blame] | 68 | |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 69 | """ |
| 70 | 5. We want to access and control our data centers from the outside, |
| peusterm | 5b844a1 | 2016-01-11 15:58:15 +0100 | [diff] [blame] | 71 | e.g., we want to connect an orchestrator to start/stop compute |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 72 | resources aka. VNFs (represented by Docker containers in the emulated) |
| 73 | |
| 74 | So we need to instantiate API endpoints (e.g. a zerorpc or REST |
| 75 | interface). Depending on the endpoint implementations, we can connect |
| 76 | one or more data centers to it, which can then be controlled through |
| 77 | this API, e.g., start/stop/list compute instances. |
| 78 | """ |
| 79 | # create a new instance of a endpoint implementation |
| peusterm | 9c252b6 | 2016-01-06 16:59:53 +0100 | [diff] [blame] | 80 | zapi1 = ZeroRpcApiEndpoint("0.0.0.0", 4242) |
| peusterm | 0a336cc | 2016-07-04 09:15:47 +0200 | [diff] [blame] | 81 | rapi1 = RestApiEndpoint("127.0.0.1", 5001) |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 82 | # connect data centers to this endpoint |
| peusterm | 9c252b6 | 2016-01-06 16:59:53 +0100 | [diff] [blame] | 83 | zapi1.connectDatacenter(dc1) |
| 84 | zapi1.connectDatacenter(dc2) |
| peusterm | 5350494 | 2016-02-04 16:09:28 +0100 | [diff] [blame] | 85 | zapi1.connectDatacenter(dc3) |
| 86 | zapi1.connectDatacenter(dc4) |
| peusterm | c038a99 | 2016-07-01 12:15:58 +0200 | [diff] [blame] | 87 | rapi1.connectDatacenter(dc1) |
| 88 | rapi1.connectDatacenter(dc2) |
| 89 | rapi1.connectDatacenter(dc3) |
| 90 | rapi1.connectDatacenter(dc4) |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 91 | # run API endpoint server (in another thread, don't block) |
| peusterm | 9c252b6 | 2016-01-06 16:59:53 +0100 | [diff] [blame] | 92 | zapi1.start() |
| peusterm | c038a99 | 2016-07-01 12:15:58 +0200 | [diff] [blame] | 93 | rapi1.start() |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 94 | |
| 95 | """ |
| 96 | 5.1. For our example, we create a second endpoint to illustrate that |
| peusterm | eecafde | 2016-01-15 10:23:26 +0100 | [diff] [blame] | 97 | this is supported by our design. This feature allows us to have |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 98 | one API endpoint for each data center. This makes the emulation |
| 99 | environment more realistic because you can easily create one |
| 100 | OpenStack-like REST API endpoint for *each* data center. |
| 101 | This will look like a real-world multi PoP/data center deployment |
| 102 | from the perspective of an orchestrator. |
| 103 | """ |
| peusterm | 9c252b6 | 2016-01-06 16:59:53 +0100 | [diff] [blame] | 104 | zapi2 = ZeroRpcApiEndpoint("0.0.0.0", 4343) |
| 105 | zapi2.connectDatacenter(dc3) |
| 106 | zapi2.connectDatacenter(dc4) |
| 107 | zapi2.start() |
| 108 | |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 109 | """ |
| 110 | 6. Finally we are done and can start our network (the emulator). |
| 111 | We can also enter the Mininet CLI to interactively interact |
| 112 | with our compute resources (just like in default Mininet). |
| 113 | But we can also implement fully automated experiments that |
| 114 | can be executed again and again. |
| 115 | """ |
| peusterm | cbcd4c2 | 2015-12-28 11:33:42 +0100 | [diff] [blame] | 116 | net.start() |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 117 | net.CLI() |
| 118 | # when the user types exit in the CLI, we stop the emulator |
| 119 | net.stop() |
| peusterm | cbcd4c2 | 2015-12-28 11:33:42 +0100 | [diff] [blame] | 120 | |
| 121 | |
| 122 | def main(): |
| peusterm | d47ab25 | 2016-01-15 10:35:06 +0100 | [diff] [blame] | 123 | setLogLevel('info') # set Mininet loglevel |
| peusterm | cbcd4c2 | 2015-12-28 11:33:42 +0100 | [diff] [blame] | 124 | create_topology1() |
| 125 | |
| 126 | |
| 127 | if __name__ == '__main__': |
| 128 | main() |