Commit a3ef55b6 authored by Brenden Blanco's avatar Brenden Blanco

Change to simulator arguments for readability

* Let one argument be optional
* Disable ipv6 for whole namespace once
* Python 2/3 compatibility fix
Signed-off-by: default avatarBrenden Blanco <bblanco@plumgrid.com>
parent 0afb0a21
...@@ -18,13 +18,18 @@ class Simulation(object): ...@@ -18,13 +18,18 @@ class Simulation(object):
# if called directly outside Simulation class, "ifc_base_name" should be # if called directly outside Simulation class, "ifc_base_name" should be
# different from "name", the "ifc_base_name" and "name" are the same for # different from "name", the "ifc_base_name" and "name" are the same for
# the first ifc created by namespace # the first ifc created by namespace
def _ns_add_ifc(self, name, ns_ifc, ifc_base_name, in_ifc=None, out_ifc=None, def _ns_add_ifc(self, name, ns_ifc, ifc_base_name=None, in_ifc=None,
ipaddr=None, macaddr=None, fn=None, cmd=None, action="ok", out_ifc=None, ipaddr=None, macaddr=None, fn=None, cmd=None,
disable_ipv6=False): action="ok", disable_ipv6=False):
if name in self.ipdbs: if name in self.ipdbs:
ns_ipdb = self.ipdbs[name] ns_ipdb = self.ipdbs[name]
else: else:
ns_ipdb = IPDB(nl=NetNS(name)) ns_ipdb = IPDB(nl=NetNS(name))
if disable_ipv6:
cmd = ["sysctl", "-q", "-w", "net.ipv6.conf.default.disable_ipv6=1"]
nsp = NSPopen(ns_ipdb.nl.netns, cmd)
nsp.wait(); nsp.release()
ns_ipdb.interfaces.lo.up().commit()
if in_ifc: if in_ifc:
in_ifname = in_ifc.ifname in_ifname = in_ifc.ifname
else: else:
...@@ -43,13 +48,6 @@ class Simulation(object): ...@@ -43,13 +48,6 @@ class Simulation(object):
if ipaddr: v.add_ip("%s" % ipaddr) if ipaddr: v.add_ip("%s" % ipaddr)
if macaddr: v.address = macaddr if macaddr: v.address = macaddr
v.up() v.up()
# if required, disable ipv6 before attaching the filter
if disable_ipv6:
subprocess.call(["sysctl", "-q", "-w",
"net.ipv6.conf." + out_ifc.ifname+ ".disable_ipv6=1"])
nsp = NSPopen(ns_ipdb.nl.netns,
["sysctl", "-q", "-w", "net.ipv6.conf." + ns_ifc + ".disable_ipv6=1"])
nsp.wait(); nsp.release()
if fn and out_ifc: if fn and out_ifc:
self.ipdb.nl.tc("add", "ingress", out_ifc["index"], "ffff:") self.ipdb.nl.tc("add", "ingress", out_ifc["index"], "ffff:")
self.ipdb.nl.tc("add-filter", "bpf", out_ifc["index"], ":1", self.ipdb.nl.tc("add-filter", "bpf", out_ifc["index"], ":1",
......
...@@ -109,7 +109,7 @@ class TestBPFSocket(TestCase): ...@@ -109,7 +109,7 @@ class TestBPFSocket(TestCase):
br_dest_map[c_uint(curr_br_pid)] = br_dest_map.Leaf(prog_id_pem, curr_pem_pid) br_dest_map[c_uint(curr_br_pid)] = br_dest_map.Leaf(prog_id_pem, curr_pem_pid)
self.pem_port[c_uint(curr_pem_pid)] = c_uint(ifindex) self.pem_port[c_uint(curr_pem_pid)] = c_uint(ifindex)
self.pem_ifindex[c_uint(ifindex)] = c_uint(curr_pem_pid) self.pem_ifindex[c_uint(ifindex)] = c_uint(curr_pem_pid)
mac_addr = br_mac_map.Key(int(EUI(vm_mac.decode()))) mac_addr = br_mac_map.Key(int(EUI(vm_mac)))
br_mac_map[mac_addr] = c_uint(curr_br_pid) br_mac_map[mac_addr] = c_uint(curr_br_pid)
def config_maps(self): def config_maps(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment