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()
import subprocess
+import pyroute2
from pyroute2 import IPRoute, NetNS, IPDB, NSPopen
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:
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",