X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=src%2Femuvim%2Fdcemulator%2Fnet.py;h=bca20b2dfcf5ce97ad2a5d17718534352ab82158;hb=50bb06a5a9aa9954d0a6300add216485eddf702c;hp=ade984fbb54fa5183eaef295ba3e765830e363bf;hpb=53d3c141d3fcd2e56e1dbc1cffd862b4f32010ff;p=osm%2Fvim-emu.git diff --git a/src/emuvim/dcemulator/net.py b/src/emuvim/dcemulator/net.py index ade984f..bca20b2 100755 --- a/src/emuvim/dcemulator/net.py +++ b/src/emuvim/dcemulator/net.py @@ -39,6 +39,7 @@ from mininet.net import Containernet from mininet.node import Controller, DefaultController, OVSSwitch, OVSKernelSwitch, Docker, RemoteController from mininet.cli import CLI from mininet.link import TCLink +from mininet.clean import cleanup import networkx as nx from emuvim.dcemulator.monitoring import DCNetworkMonitor from emuvim.dcemulator.node import Datacenter, EmulatorCompute @@ -66,15 +67,19 @@ class DCNetwork(Containernet): :param kwargs: path through for Mininet parameters :return: """ + # members self.dcs = {} + self.ryu_process = None + + # always cleanup environment before we start the emulator + self.killRyu() + cleanup() # call original Docker.__init__ and setup default controller Containernet.__init__( self, switch=OVSKernelSwitch, controller=controller, **kwargs) - # Ryu management - self.ryu_process = None if controller == RemoteController: # start Ryu controller self.startRyu(learning_switch=enable_learning) @@ -250,7 +255,7 @@ class DCNetwork(Containernet): Containernet.stop(self) # stop Ryu controller - self.stopRyu() + self.killRyu() def CLI(self): @@ -400,6 +405,7 @@ class DCNetwork(Containernet): path = kwargs.get('path') current_hop = kwargs.get('current_hop') vlan = kwargs.get('vlan') + priority = kwargs.get('priority') s = ',' if match_input: @@ -410,7 +416,8 @@ class DCNetwork(Containernet): if cookie: flow['cookie'] = int(cookie) - + if priority: + flow['priority'] = int(priority) flow['actions'] = [] @@ -513,10 +520,17 @@ class DCNetwork(Containernet): self.ryu_process = Popen([ryu_cmd, ryu_path2, ryu_option, ryu_of_port], stdout=FNULL, stderr=FNULL) time.sleep(1) - def stopRyu(self): + def killRyu(self): + """ + Stop the Ryu controller that might be started by son-emu. + :return: + """ + # try it nicely if self.ryu_process is not None: self.ryu_process.terminate() self.ryu_process.kill() + # ensure its death ;-) + Popen(['pkill', '-f', 'ryu-manager']) def ryu_REST(self, prefix, dpid=None, data=None): try: