From: stevenvanrossem Date: Mon, 22 Feb 2016 09:13:05 +0000 (+0100) Subject: fix unit test and start Ryu from DCNetwork init X-Git-Tag: v3.1~175^2~1 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=9ebd094670679a7cba47d1e508cda37242bc864b;p=osm%2Fvim-emu.git fix unit test and start Ryu from DCNetwork init --- diff --git a/emuvim/api/zerorpcapi_DCNetwork.py b/emuvim/api/zerorpcapi_DCNetwork.py index b60093d..27527aa 100755 --- a/emuvim/api/zerorpcapi_DCNetwork.py +++ b/emuvim/api/zerorpcapi_DCNetwork.py @@ -6,8 +6,7 @@ Distributed Cloud Emulator (dcemulator) import logging import threading import zerorpc -import site -from subprocess import Popen + logging.basicConfig(level=logging.INFO) @@ -30,17 +29,6 @@ class ZeroRpcApiEndpointDCNetwork(object): logging.debug("Created monitoring API endpoint %s(%s:%d)" % ( self.__class__.__name__, self.ip, self.port)) - # 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' - # 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' - self.ryu_process = Popen([ryu_cmd, ryu_path, ryu_path2, ryu_option, ryu_of_port]) - def connectDCNetwork(self, net): self.net = net logging.info("Connected DCNetwork to API endpoint %s(%s:%d)" % ( @@ -59,17 +47,17 @@ class ZeroRpcApiEndpointDCNetwork(object): s.run() def stop(self): - # stop ryu controller logging.info("Stop the monitoring API endpoint") - self.ryu_process.terminate() - #self.ryu_process.kill() return class DCNetworkApi(object): """ + The networking and monitoring commands need the scope of the + whole DC network to find the requested vnf. So this API is intended + to work with a DCNetwork. Just pass through the corresponding request to the - selected data center. Do not implement provisioning + selected data center network. Do not implement provisioning logic here because will will have multiple API endpoint implementations at the end. """ diff --git a/emuvim/dcemulator/net.py b/emuvim/dcemulator/net.py index 324c4d3..20ab33a 100755 --- a/emuvim/dcemulator/net.py +++ b/emuvim/dcemulator/net.py @@ -4,6 +4,10 @@ Distributed Cloud Emulator (dcemulator) """ import logging +import site +from subprocess import Popen +import os + from mininet.net import Dockernet from mininet.node import Controller, OVSSwitch, OVSKernelSwitch, Switch, Docker, Host, RemoteController from mininet.cli import CLI @@ -39,6 +43,9 @@ class DCNetwork(Dockernet): # monitoring agent self.monitor_agent = DCNetworkMonitor(self) + # start Ryu controller + self.startRyu() + def addDatacenter(self, label, metadata={}): """ @@ -133,6 +140,9 @@ class DCNetwork(Dockernet): Dockernet.start(self) def stop(self): + # stop Ryu controller + self.ryu_process.terminate() + #self.ryu_process.kill() Dockernet.stop(self) def CLI(self): @@ -179,4 +189,18 @@ class DCNetwork(Dockernet): current_hop = next_hop - return "destination node: {0} not reached".format(vnf_dst_name) \ No newline at end of file + return "destination node: {0} not reached".format(vnf_dst_name) + + # start Ryu Openflow controller as Remote Controller for the DCNetwork + def startRyu(self): + # 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' + # 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' + FNULL = open(os.devnull, 'w') + self.ryu_process = Popen([ryu_cmd, ryu_path, ryu_path2, ryu_option, ryu_of_port], stdout=FNULL, stderr=FNULL) \ No newline at end of file diff --git a/emuvim/example_topology.py b/emuvim/example_topology.py index 2342fd1..5c459ce 100755 --- a/emuvim/example_topology.py +++ b/emuvim/example_topology.py @@ -110,7 +110,7 @@ def create_topology1(): net.CLI() # when the user types exit in the CLI, we stop the emulator # we need to explicitly stop the monitoring api, so the Ryu controller is also terminated - mon_api.stop() + #mon_api.stop() net.stop()