Fixing more ctrl-c problem
authorYonghong Song <yhs@plumgrid.com>
Mon, 10 Aug 2015 18:35:28 +0000 (11:35 -0700)
committerYonghong Song <yhs@plumgrid.com>
Mon, 10 Aug 2015 18:55:55 +0000 (11:55 -0700)
Signed-off-by: Yonghong Song <yhs@plumgrid.com>
examples/distributed_bridge/main.py
examples/simulation.py

index 0421bed..79cc8bd 100755 (executable)
@@ -45,9 +45,12 @@ try:
     sim = TunnelSimulation(ipdb)
     sim.start()
     input("Press enter to quit:")
+    for p in sim.processes: p.communicate(b"\n")
+except:
+    if "sim" in locals():
+        for p in sim.processes: p.kill(); p.wait()
 finally:
     if "br-fabric" in ipdb.interfaces: ipdb.interfaces["br-fabric"].remove().commit()
-    for p in sim.processes: p.communicate(b"\n")
-    sim.release()
+    if "sim" in locals(): sim.release()
     ipdb.release()
     null.close()
index 1e1b407..269ad3f 100644 (file)
@@ -1,4 +1,5 @@
 import subprocess
+import pyroute2
 from pyroute2 import IPRoute, NetNS, IPDB, NSPopen
 
 class Simulation(object):
@@ -34,9 +35,9 @@ class Simulation(object):
             ns_ipdb = IPDB(nl)
             self.ipdbs[nl.netns] = ns_ipdb
             if disable_ipv6:
-                cmd = ["sysctl", "-q", "-w",
+                cmd1 = ["sysctl", "-q", "-w",
                        "net.ipv6.conf.default.disable_ipv6=1"]
-                nsp = NSPopen(ns_ipdb.nl.netns, cmd)
+                nsp = NSPopen(ns_ipdb.nl.netns, cmd1)
                 nsp.wait(); nsp.release()
             ns_ipdb.interfaces.lo.up().commit()
         if in_ifc:
@@ -67,9 +68,9 @@ class Simulation(object):
             if macaddr: v.address = macaddr
             v.up()
         if disable_ipv6:
-            cmd = ["sysctl", "-q", "-w",
+            cmd1 = ["sysctl", "-q", "-w",
                    "net.ipv6.conf.%s.disable_ipv6=1" % out_ifc.ifname]
-            subprocess.call(cmd)
+            subprocess.call(cmd1)
         if fn and out_ifc:
             self.ipdb.nl.tc("add", "ingress", out_ifc["index"], "ffff:")
             self.ipdb.nl.tc("add-filter", "bpf", out_ifc["index"], ":1",