| 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 |
| peusterm | cbcd4c2 | 2015-12-28 11:33:42 +0100 | [diff] [blame] | 21 | from dcemulator.net import DCNetwork |
| peusterm | 9c252b6 | 2016-01-06 16:59:53 +0100 | [diff] [blame] | 22 | from api.zerorpcapi import ZeroRpcApiEndpoint |
| peusterm | cbcd4c2 | 2015-12-28 11:33:42 +0100 | [diff] [blame] | 23 | |
| peusterm | bd44f4a | 2016-01-13 14:53:30 +0100 | [diff] [blame] | 24 | logging.basicConfig(level=logging.INFO) |
| peusterm | cbcd4c2 | 2015-12-28 11:33:42 +0100 | [diff] [blame] | 25 | |
| 26 | |
| 27 | def create_topology1(): |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 28 | """ |
| 29 | 1. Create a data center network object (DCNetwork) |
| 30 | """ |
| peusterm | cbcd4c2 | 2015-12-28 11:33:42 +0100 | [diff] [blame] | 31 | net = DCNetwork() |
| 32 | |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 33 | """ |
| 34 | 2. Add (logical) data centers to the topology |
| 35 | (each data center is one "bigswitch" in our simplified |
| 36 | first prototype) |
| 37 | """ |
| peusterm | a47db03 | 2016-02-04 14:55:29 +0100 | [diff] [blame^] | 38 | dc1 = net.addDatacenter("datacenter1") |
| 39 | dc2 = net.addDatacenter("datacenter2") |
| 40 | dc3 = net.addDatacenter("a_very_long_data_center_name3") |
| 41 | dc4 = net.addDatacenter("datacenter4") |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 42 | |
| 43 | """ |
| 44 | 3. You can add additional SDN switches for data center |
| 45 | interconnections to the network. |
| 46 | """ |
| peusterm | cbcd4c2 | 2015-12-28 11:33:42 +0100 | [diff] [blame] | 47 | s1 = net.addSwitch("s1") |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 48 | |
| 49 | """ |
| 50 | 4. Add links between your data centers and additional switches |
| 51 | to define you topology. |
| 52 | These links can use Mininet's features to limit bw, add delay or jitter. |
| 53 | """ |
| peusterm | cbcd4c2 | 2015-12-28 11:33:42 +0100 | [diff] [blame] | 54 | net.addLink(dc1, dc2) |
| peusterm | a47db03 | 2016-02-04 14:55:29 +0100 | [diff] [blame^] | 55 | net.addLink("datacenter1", s1) |
| 56 | net.addLink(s1, dc3) |
| 57 | net.addLink(s1, "datacenter4") |
| peusterm | 9c252b6 | 2016-01-06 16:59:53 +0100 | [diff] [blame] | 58 | |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 59 | """ |
| 60 | 5. We want to access and control our data centers from the outside, |
| peusterm | 5b844a1 | 2016-01-11 15:58:15 +0100 | [diff] [blame] | 61 | e.g., we want to connect an orchestrator to start/stop compute |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 62 | resources aka. VNFs (represented by Docker containers in the emulated) |
| 63 | |
| 64 | So we need to instantiate API endpoints (e.g. a zerorpc or REST |
| 65 | interface). Depending on the endpoint implementations, we can connect |
| 66 | one or more data centers to it, which can then be controlled through |
| 67 | this API, e.g., start/stop/list compute instances. |
| 68 | """ |
| 69 | # create a new instance of a endpoint implementation |
| peusterm | 9c252b6 | 2016-01-06 16:59:53 +0100 | [diff] [blame] | 70 | zapi1 = ZeroRpcApiEndpoint("0.0.0.0", 4242) |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 71 | # connect data centers to this endpoint |
| peusterm | 9c252b6 | 2016-01-06 16:59:53 +0100 | [diff] [blame] | 72 | zapi1.connectDatacenter(dc1) |
| 73 | zapi1.connectDatacenter(dc2) |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 74 | # run API endpoint server (in another thread, don't block) |
| peusterm | 9c252b6 | 2016-01-06 16:59:53 +0100 | [diff] [blame] | 75 | zapi1.start() |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 76 | |
| 77 | """ |
| 78 | 5.1. For our example, we create a second endpoint to illustrate that |
| peusterm | eecafde | 2016-01-15 10:23:26 +0100 | [diff] [blame] | 79 | this is supported by our design. This feature allows us to have |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 80 | one API endpoint for each data center. This makes the emulation |
| 81 | environment more realistic because you can easily create one |
| 82 | OpenStack-like REST API endpoint for *each* data center. |
| 83 | This will look like a real-world multi PoP/data center deployment |
| 84 | from the perspective of an orchestrator. |
| 85 | """ |
| peusterm | 9c252b6 | 2016-01-06 16:59:53 +0100 | [diff] [blame] | 86 | zapi2 = ZeroRpcApiEndpoint("0.0.0.0", 4343) |
| 87 | zapi2.connectDatacenter(dc3) |
| 88 | zapi2.connectDatacenter(dc4) |
| 89 | zapi2.start() |
| 90 | |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 91 | """ |
| 92 | 6. Finally we are done and can start our network (the emulator). |
| 93 | We can also enter the Mininet CLI to interactively interact |
| 94 | with our compute resources (just like in default Mininet). |
| 95 | But we can also implement fully automated experiments that |
| 96 | can be executed again and again. |
| 97 | """ |
| peusterm | cbcd4c2 | 2015-12-28 11:33:42 +0100 | [diff] [blame] | 98 | net.start() |
| peusterm | e4e89d3 | 2016-01-07 09:14:54 +0100 | [diff] [blame] | 99 | net.CLI() |
| 100 | # when the user types exit in the CLI, we stop the emulator |
| 101 | net.stop() |
| peusterm | cbcd4c2 | 2015-12-28 11:33:42 +0100 | [diff] [blame] | 102 | |
| 103 | |
| 104 | def main(): |
| peusterm | d47ab25 | 2016-01-15 10:35:06 +0100 | [diff] [blame] | 105 | setLogLevel('info') # set Mininet loglevel |
| peusterm | cbcd4c2 | 2015-12-28 11:33:42 +0100 | [diff] [blame] | 106 | create_topology1() |
| 107 | |
| 108 | |
| 109 | if __name__ == '__main__': |
| 110 | main() |