| hadik3r | f3bf0e7 | 2016-06-27 18:20:44 +0200 | [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 | |
| 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 | |
| 16 | The original Mininet API has to be completely hidden and not be used by this |
| 17 | script. |
| 18 | """ |
| 19 | import logging |
| 20 | from mininet.log import setLogLevel |
| 21 | from emuvim.dcemulator.net import DCNetwork |
| 22 | from emuvim.api.rest.compute import RestApiEndpoint |
| 23 | #from emuvim.api.zerorpc.compute import ZeroRpcApiEndpoint |
| 24 | from emuvim.api.zerorpc.network import ZeroRpcApiEndpointDCNetwork |
| 25 | |
| 26 | logging.basicConfig(level=logging.INFO) |
| 27 | |
| 28 | |
| 29 | def create_topology1(): |
| 30 | """ |
| 31 | 1. Create a data center network object (DCNetwork) |
| 32 | """ |
| 33 | net = DCNetwork() |
| 34 | |
| 35 | """ |
| 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() |
| 41 | """ |
| 42 | 2. Add (logical) data centers to the topology |
| 43 | (each data center is one "bigswitch" in our simplified |
| 44 | first prototype) |
| 45 | """ |
| 46 | dc1 = net.addDatacenter("datacenter1") |
| 47 | dc2 = net.addDatacenter("datacenter2") |
| 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"}) |
| 52 | |
| 53 | """ |
| 54 | 3. You can add additional SDN switches for data center |
| 55 | interconnections to the network. |
| 56 | """ |
| 57 | s1 = net.addSwitch("s1") |
| 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 | """ |
| 64 | net.addLink(dc1, dc2) |
| 65 | net.addLink("datacenter1", s1) |
| 66 | net.addLink(s1, dc3) |
| 67 | net.addLink(s1, "datacenter4") |
| 68 | |
| 69 | """ |
| 70 | 5. We want to access and control our data centers from the outside, |
| 71 | e.g., we want to connect an orchestrator to start/stop compute |
| 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 |
| 80 | api1 = RestApiEndpoint("127.0.0.1", 5000) |
| 81 | # connect data centers to this endpoint |
| 82 | api1.connectDatacenter(dc1) |
| 83 | api1.connectDatacenter(dc2) |
| 84 | api1.connectDatacenter(dc3) |
| 85 | api1.connectDatacenter(dc4) |
| 86 | # run API endpoint server (in another thread, don't block) |
| 87 | api1.start() |
| 88 | |
| 89 | """ |
| 90 | 6. Finally we are done and can start our network (the emulator). |
| 91 | We can also enter the Mininet CLI to interactively interact |
| 92 | with our compute resources (just like in default Mininet). |
| 93 | But we can also implement fully automated experiments that |
| 94 | can be executed again and again. |
| 95 | """ |
| 96 | net.start() |
| 97 | net.CLI() |
| 98 | # when the user types exit in the CLI, we stop the emulator |
| 99 | net.stop() |
| 100 | |
| 101 | |
| 102 | def main(): |
| 103 | setLogLevel('info') # set Mininet loglevel |
| 104 | create_topology1() |
| 105 | |
| 106 | |
| 107 | if __name__ == '__main__': |
| 108 | main() |