Added memory model to UPB simple resource model
[osm/vim-emu.git] / src / emuvim / dcemulator / net.py
index bc54293..80fb2f8 100755 (executable)
@@ -27,7 +27,10 @@ class DCNetwork(Dockernet):
     This class is used by topology definition scripts.
     """
 
-    def __init__(self, controller=RemoteController, dc_emulation_max_cpu=1.0, **kwargs):
+    def __init__(self, controller=RemoteController,
+                 dc_emulation_max_cpu=1.0,  # fraction of overall CPU time for emulation
+                 dc_emulation_max_mem=512,  # emulation max mem in MB
+                 **kwargs):
         """
         Create an extended version of a Dockernet network
         :param dc_emulation_max_cpu: max. CPU time used by containers in data centers
@@ -40,10 +43,13 @@ class DCNetwork(Dockernet):
         Dockernet.__init__(
             self, switch=OVSKernelSwitch, **kwargs)
 
-        # start Ryu controller
-        self.startRyu()
+        # Ryu management
+        self.ryu_process = None
+        if controller == RemoteController:
+            # start Ryu controller
+            self.startRyu()
 
-        # add a remote controller to be able to use Ryu
+        # add the specified controller
         self.addController('c0', controller=controller)
 
         # graph of the complete DC network
@@ -53,7 +59,8 @@ class DCNetwork(Dockernet):
         self.monitor_agent = DCNetworkMonitor(self)
 
         # initialize resource model registrar
-        self.rm_registrar = ResourceModelRegistrar(dc_emulation_max_cpu)
+        self.rm_registrar = ResourceModelRegistrar(
+            dc_emulation_max_cpu, dc_emulation_max_mem)
 
     def addDatacenter(self, label, metadata={}):
         """
@@ -154,9 +161,8 @@ class DCNetwork(Dockernet):
 
     def stop(self):
         # stop Ryu controller
-        self.ryu_process.terminate()
-        #self.ryu_process.kill()
         Dockernet.stop(self)
+        self.stopRyu()
 
     def CLI(self):
         CLI(self)
@@ -209,12 +215,18 @@ class DCNetwork(Dockernet):
         # start Ryu controller with rest-API
         python_install_path = site.getsitepackages()[0]
         ryu_path = python_install_path + '/ryu/app/simple_switch_13.py'
-        ryu_path2 =  python_install_path + '/ryu/app/ofctl_rest.py'
+        ryu_path2 = python_install_path + '/ryu/app/ofctl_rest.py'
         # change the default Openflow controller port to 6653 (official IANA-assigned port number), as used by Mininet
         # Ryu still uses 6633 as default
         ryu_option = '--ofp-tcp-listen-port'
         ryu_of_port = '6653'
-        ryu_cmd =  'ryu-manager'
+        ryu_cmd = 'ryu-manager'
         FNULL = open("/tmp/ryu.log", 'w')
         self.ryu_process = Popen([ryu_cmd, ryu_path, ryu_path2, ryu_option, ryu_of_port], stdout=FNULL, stderr=FNULL)
-        time.sleep(1)
\ No newline at end of file
+        time.sleep(1)
+
+    def stopRyu(self):
+        if self.ryu_process is not None:
+            self.ryu_process.terminate()
+            self.ryu_process.kill()
+