Changed emulator design and started to create the emuvim Mininet wrapper layer.
diff --git a/emuvim/__init__.py b/emuvim/api/__init__.py
similarity index 100%
rename from emuvim/__init__.py
rename to emuvim/api/__init__.py
diff --git a/emuvim/__init__.py b/emuvim/cli/__init__.py
similarity index 100%
copy from emuvim/__init__.py
copy to emuvim/cli/__init__.py
diff --git a/emuvim/__init__.py b/emuvim/cli/__main__.py
similarity index 100%
copy from emuvim/__init__.py
copy to emuvim/cli/__main__.py
diff --git a/emuvim/dcemulator/__init__.py b/emuvim/dcemulator/__init__.py
new file mode 100644
index 0000000..64f6616
--- /dev/null
+++ b/emuvim/dcemulator/__init__.py
@@ -0,0 +1,4 @@
+"""
+Distributed Cloud Emulator (dcemulator)
+(c) 2015 by Manuel Peuster <manuel.peuster@upb.de>
+"""
\ No newline at end of file
diff --git a/emuvim/__init__.py b/emuvim/dcemulator/link.py
similarity index 100%
copy from emuvim/__init__.py
copy to emuvim/dcemulator/link.py
diff --git a/emuvim/dcemulator/net.py b/emuvim/dcemulator/net.py
new file mode 100644
index 0000000..8ea41a7
--- /dev/null
+++ b/emuvim/dcemulator/net.py
@@ -0,0 +1,88 @@
+"""
+Distributed Cloud Emulator (dcemulator)
+(c) 2015 by Manuel Peuster <manuel.peuster@upb.de>
+"""
+import logging
+
+from mininet.net import Mininet
+from mininet.node import Controller, OVSKernelSwitch, Switch
+from mininet.cli import CLI
+from mininet.log import setLogLevel, info
+from mininet.link import TCLink, Link
+
+from node import Datacenter
+
+
+class DCNetwork(object):
+
+ def __init__(self):
+ self.dcs = {}
+ self.switches = {}
+ self.links = []
+
+ # create a Mininet/Dockernet network
+ setLogLevel('info') # set Mininet loglevel
+ self.mnet = Mininet(controller=Controller, switch=OVSKernelSwitch)
+ self.mnet.addController('c0')
+
+ def addDatacenter(self, name):
+ """
+ Create and add a logical cloud data center to the network.
+ """
+ if name in self.dcs:
+ raise Exception("Data center name already exists: %s" % name)
+ dc = Datacenter(name)
+ dc.net = self # set reference to network
+ self.dcs[name] = dc
+ dc.create() # finally create the data center in our Mininet instance
+ logging.info("added data center: %s" % name)
+ return dc
+
+ def addSwitch(self, name):
+ """
+ We can also add additional SDN switches between data centers.
+ """
+ s = self.mnet.addSwitch(name)
+ self.switches[name] = s
+ logging.info("added switch: %s" % name)
+ return s
+
+ def addLink(self, node1, node2):
+ assert node1 is not None
+ assert node2 is not None
+ # ensure type of node1
+ if isinstance( node1, basestring ):
+ if node1 in self.dcs:
+ node1 = self.dcs[node1].switch
+ elif node1 in self.switches:
+ node1 = self.switches[node1]
+ if isinstance( node1, Datacenter ):
+ node1 = node1.switch
+ # ensure type of node2
+ if isinstance( node2, basestring ):
+ if node2 in self.dcs:
+ node2 = self.dcs[node2].switch
+ elif node2 in self.switches:
+ node2 = self.switches[node2]
+ if isinstance( node2, Datacenter ):
+ node2 = node2.switch
+ # create link if everything is correct
+ if (node1 is not None and isinstance(node1, OVSKernelSwitch)
+ and node2 is not None and isinstance(node2, OVSKernelSwitch)):
+ self.mnet.addLink(node1, node2) # TODO we need TCLinks with user defined performance her
+ else:
+ raise Exception(
+ "one of the given nodes is not a Mininet switch or None")
+
+ def start(self):
+ # start
+ for dc in self.dcs.itervalues():
+ dc.start()
+ self.mnet.start()
+
+ def stop(self):
+ self.mnet.stop()
+
+ def CLI(self):
+ CLI(self.mnet)
+
diff --git a/emuvim/dcemulator/node.py b/emuvim/dcemulator/node.py
new file mode 100644
index 0000000..b12751f
--- /dev/null
+++ b/emuvim/dcemulator/node.py
@@ -0,0 +1,46 @@
+"""
+Distributed Cloud Emulator (dcemulator)
+(c) 2015 by Manuel Peuster <manuel.peuster@upb.de>
+"""
+import logging
+
+
+DCDPID_BASE = 1000 # start of switch dpid's used for data center switches
+
+
+class Datacenter(object):
+ """
+ Represents a logical data center to which compute resources
+ (Docker containers) can be added at runtime.
+ """
+
+ def __init__(self, name):
+ self.net = None # DCNetwork to which we belong
+ self.name = name
+ self.switch = None # first prototype assumes one "bigswitch" per DC
+
+ def _get_next_dc_dpid(self):
+ global DCDPID_BASE
+ DCDPID_BASE += 1
+ return DCDPID_BASE
+
+ def create(self):
+ """
+ Each data center is represented by a single switch to which
+ compute resources can be connected at run time.
+
+ TODO: This will be changes in the future to support multiple networks
+ per data center
+ """
+ self.switch = self.net.mnet.addSwitch(
+ "%s.s1" % self.name, dpid=hex(self._get_next_dc_dpid())[2:])
+ logging.debug("created data center switch: %s" % str(self.switch))
+
+ def start(self):
+ pass
+
+ def addCompute(self):
+ pass
+
+ def removeCompute(self):
+ pass
diff --git a/emuvim/example_topology.py b/emuvim/example_topology.py
new file mode 100644
index 0000000..f2be310
--- /dev/null
+++ b/emuvim/example_topology.py
@@ -0,0 +1,43 @@
+"""
+This is an example topology for the distributed cloud emulator (dcemulator).
+(c) 2015 by Manuel Peuster <manuel.peuster@upb.de>
+
+The original Mininet API has to be completely hidden and not be used by this
+script.
+"""
+import logging
+from dcemulator.net import DCNetwork
+
+logging.basicConfig(level=logging.DEBUG)
+
+
+def create_topology1():
+ # initialize network
+ net = DCNetwork()
+
+ # add data centers
+ dc1 = net.addDatacenter("dc1")
+ dc2 = net.addDatacenter("dc2")
+ dc3 = net.addDatacenter("dc3")
+ dc4 = net.addDatacenter("dc4")
+ # add additional SDN switches to our topology
+ s1 = net.addSwitch("s1")
+ # add links between data centers
+ net.addLink(dc1, dc2)
+ net.addLink("dc1", s1)
+ net.addLink(s1, "dc3")
+ net.addLink(s1, dc4)
+ # start network
+ net.start()
+ net.CLI() # TODO remove this when we integrate APIs?
+ net.stop() # TODO remove this when we integrate APIs?
+ # start APIs (to access emulated cloud data centers)
+ pass # TODO: how to reflect one API endpoint per DC?
+
+
+def main():
+ create_topology1()
+
+
+if __name__ == '__main__':
+ main()