Commit 53c49b08 authored by Martín Ferrari's avatar Martín Ferrari

Mass change: rename netns to nemu.

parent eac808b8
Required packages for using netns
=================================
Required packages for using nemu
================================
python-unshare http://pypi.python.org/pypi/python-unshare
python-passfd http://pypi.python.org/pypi/python-passfd
......
......@@ -3,7 +3,7 @@ Makefile
sample-api.py
setup.cfg
setup.py
src/netns/__init__.py
src/nemu/__init__.py
t/test_core.py
t/test_interfaces.py
t/test_node.py
......
#!/usr/bin/env python
# vim: ts=4:sw=4:et:ai:sts=4
import csv, getopt, netns, os, os.path, re, select, subprocess, sys
import csv, getopt, nemu, os, os.path, re, select, subprocess, sys
__doc__ = """Creates a linear network topology, and measures the maximum
end-to-end throughput for the specified packet size."""
......@@ -107,7 +107,7 @@ def main():
if not (time or nbytes or packets):
time = 10
udp_perf = netns.environ.find_bin("udp-perf",
udp_perf = nemu.environ.find_bin("udp-perf",
extra_path = [".", os.path.dirname(sys.argv[0])])
if not udp_perf:
raise RuntimeError("Cannot find `udp-perf'")
......@@ -197,11 +197,11 @@ def create_topo(n, p2p, delay, jitter, bw):
interfaces = []
links = []
for i in range(n):
nodes.append(netns.Node())
nodes.append(nemu.Node())
if p2p:
interfaces = [[None]]
for i in range(n - 1):
a, b = netns.P2PInterface.create_pair(nodes[i], nodes[i + 1])
a, b = nemu.P2PInterface.create_pair(nodes[i], nodes[i + 1])
interfaces[i].append(a)
interfaces.append([])
interfaces[i + 1] = [b]
......@@ -218,7 +218,7 @@ def create_topo(n, p2p, delay, jitter, bw):
right = None
interfaces.append((left, right))
for i in range(n - 1):
links = netns.Switch(bandwidth = bw, delay = delay,
links = nemu.Switch(bandwidth = bw, delay = delay,
delay_jitter = jitter)
links.up = True
links.connect(interfaces[i][1])
......
#/usr/bin/env python
# vim:ts=4:sw=4:et:ai:sts=4
import netns
import nemu
import signal
# run_as: user to setuid() to before running applications (this is assumed to
# run as root)
netns.config.run_as = 'nobody'
nemu.config.run_as = 'nobody'
# Clean-up is essential to avoid leaving bridge devices all over the place
# (luckily, the veths die automatically). This installs signals and exit
# handlers.
netns.set_cleanup_hooks(on_exit = True,
nemu.set_cleanup_hooks(on_exit = True,
on_signals = [signal.SIGTERM, signal.SIGINT])
# each Node is a netns
a = netns.Node()
b = netns.Node()
a = nemu.Node()
b = nemu.Node()
print "Nodes started with pids: %d and %d" % (a.pid, b.pid)
# interface object maps to a veth pair with one end in a netns
if0 = a.add_if(lladdr = '42:71:e0:90:ca:42')
# This is equivalent
#if0 = netns.NodeInterface(a)
#if0 = nemu.NodeInterface(a)
#if0.lladdr = '42:71:e0:90:ca:42'
if1 = b.add_if(mtu = 1492)
......@@ -31,7 +31,7 @@ if2 = b.import_if('tun0')
# each Switch is a linux bridge, all the parameters are applied to the
# associated interfaces as tc qdiscs.
switch0 = netns.Switch(bandwidth = 100 * 1024 * 1024,
switch0 = nemu.Switch(bandwidth = 100 * 1024 * 1024,
delay = 0.01, delay_jitter = 0.001,
delay_correlation = 0.25, delay_distribution = 'normal',
loss = 0.005, loss_correlation = 0.20,
......@@ -45,15 +45,15 @@ switch0.connect(if1)
# Should be experimented with Tom Geoff's patch to see if the bridge could be
# avoided; but for that the API would be slightly different, as these would be
# point-to-point interfaces and links.
# ppp0 = netns.PPPSwitch(a, b, bandwidth = ....)
# ppp0 = nemu.PPPSwitch(a, b, bandwidth = ....)
# if0 = ppp0.interface(a)
# For now, we have simple P2P interfaces:
(pppa, pppb) = netns.P2PInterface.create_pair(a, b)
(pppa, pppb) = nemu.P2PInterface.create_pair(a, b)
# Add and connect a tap device (as if a external router were plugged into a
# switch)
if2 = netns.ImportedInterface('tap0')
if2 = nemu.ImportedInterface('tap0')
switch0.connect(if2)
switch0.up = True
......@@ -78,8 +78,8 @@ addrs = if0.get_addresses()
stats = if0.get_stats()
routes = a.get_routes()
ifaces = a.get_interfaces()
nodes = netns.get_nodes()
switches = netns.get_switches()
nodes = nemu.get_nodes()
switches = nemu.get_switches()
stats = link0.get_stats()
# Run a process in background
......@@ -101,14 +101,14 @@ app2.wait()
def setup_linear_topology(n, bd, delay):
nodes = []
for i in range(n):
nodes.append(netns.Node())
nodes.append(nemu.Node())
for i in range(n - 1):
if1 = nodes[i].add_if()
if2 = nodes[i + 1].add_if()
if1.add_v4_address(addr = ('10.0.%d.2' % i), prefix_len = 24)
if2.add_v4_address(addr = ('10.0.%d.1' % i), prefix_len = 24)
switch = netns.Switch(bandwidth = bd, delay = delay)
switch = nemu.Switch(bandwidth = bd, delay = delay)
switch.connect(if1)
switch.connect(if2)
......
#!/usr/bin/env python
# vim:ts=4:sw=4:et:ai:sts=4
import os, netns, subprocess, time
import os, nemu, subprocess, time
xterm = netns.environ.find_bin("xterm")
xterm = nemu.environ.find_bin("xterm")
X = "DISPLAY" in os.environ and xterm
# each Node is a netns
node0 = netns.Node(forward_X11 = X)
node1 = netns.Node(forward_X11 = X)
node2 = netns.Node(forward_X11 = X)
node0 = nemu.Node(forward_X11 = X)
node1 = nemu.Node(forward_X11 = X)
node2 = nemu.Node(forward_X11 = X)
print "Nodes started with pids: %s" % str((node0.pid, node1.pid,
node2.pid))
# interface object maps to a veth pair with one end in a netns
if0 = netns.NodeInterface(node0)
if1a = netns.NodeInterface(node1)
if0 = nemu.NodeInterface(node0)
if1a = nemu.NodeInterface(node1)
# Between node1 and node2, we use a P2P interface
(if1b, if2) = netns.P2PInterface.create_pair(node1, node2)
(if1b, if2) = nemu.P2PInterface.create_pair(node1, node2)
switch0 = netns.Switch(
switch0 = nemu.Switch(
bandwidth = 100 * 1024 * 1024,
delay = 0.1, # 100 ms
delay_jitter = 0.01, # 10ms
......@@ -56,7 +56,7 @@ print "Connectivity IPv4 OK!"
if X:
app1 = node1.Popen("%s -geometry -0+0 -e %s -ni %s" %
(xterm, netns.environ.tcpdump_path, if1b.name), shell = True)
(xterm, nemu.environ.tcpdump_path, if1b.name), shell = True)
time.sleep(3)
app0 = node0.Popen("%s -geometry +0+0 -e ping -c 10 10.0.1.2" % xterm,
shell = True)
......
#!/usr/bin/env python
# vim: set fileencoding=utf-8
# -*- coding: utf-8 -*-
# vim: ts=4:sw=4:et:ai:sts=4
from distutils.core import setup, Extension, Command
setup(
name = 'netns',
name = 'nemu',
version = '0.1',
description = '''A framework for creating emulated networks in a
single host and run experiments on them''',
# long_description = longdesc,
author = 'Martin Ferrari',
author = 'Martín Ferrari',
author_email = 'martin.ferrari@gmail.com',
url = 'http://yans.pl.sophia.inria.fr/code/hgwebdir.cgi/netns/',
url = 'http://code.google.com/p/nemu/',
license = 'GPLv2',
platforms = 'Linux',
packages = ['netns'],
packages = ['nemu'],
package_dir = {'': 'src'}
)
......@@ -18,8 +18,8 @@
# Nemu. If not, see <http://www.gnu.org/licenses/>.
import os, pwd
from netns.node import *
from netns.interface import *
from nemu.node import *
from nemu.interface import *
class __Config(object):
def __init__(self):
......
......@@ -147,7 +147,7 @@ def log_use_syslog(use = True, ident = None, logopt = 0,
return
if not ident:
#ident = os.path.basename(sys.argv[0])
ident = "netns"
ident = "nemu"
syslog.openlog("%s[%d]" % (ident, os.getpid()), logopt, facility)
_log_syslog_opts = (ident, logopt, facility)
_log_use_syslog = True
......
......@@ -18,8 +18,8 @@
# Nemu. If not, see <http://www.gnu.org/licenses/>.
import os, weakref
import netns.iproute
from netns.environ import *
import nemu.iproute
from nemu.environ import *
__all__ = ['NodeInterface', 'P2PInterface', 'ImportedInterface',
'ImportedNodeInterface', 'Switch']
......@@ -94,24 +94,24 @@ class NSInterface(Interface):
if name[0] == '_': # forbid anything that doesn't start with a _
super(Interface, self).__setattr__(name, value)
return
iface = netns.iproute.interface(index = self.index)
iface = nemu.iproute.interface(index = self.index)
setattr(iface, name, value)
return self._slave.set_if(iface)
def add_v4_address(self, address, prefix_len, broadcast = None):
addr = netns.iproute.ipv4address(address, prefix_len, broadcast)
addr = nemu.iproute.ipv4address(address, prefix_len, broadcast)
self._slave.add_addr(self.index, addr)
def add_v6_address(self, address, prefix_len):
addr = netns.iproute.ipv6address(address, prefix_len)
addr = nemu.iproute.ipv6address(address, prefix_len)
self._slave.add_addr(self.index, addr)
def del_v4_address(self, address, prefix_len, broadcast = None):
addr = netns.iproute.ipv4address(address, prefix_len, broadcast)
addr = nemu.iproute.ipv4address(address, prefix_len, broadcast)
self._slave.del_addr(self.index, addr)
def del_v6_address(self, address, prefix_len):
addr = netns.iproute.ipv6address(address, prefix_len)
addr = nemu.iproute.ipv6address(address, prefix_len)
self._slave.del_addr(self.index, addr)
def get_addresses(self):
......@@ -139,13 +139,13 @@ class NodeInterface(NSInterface):
"""Create a new interface. `node' is the name space in which this
interface should be put."""
self._slave = None
if1 = netns.iproute.interface(name = self._gen_if_name())
if2 = netns.iproute.interface(name = self._gen_if_name())
ctl, ns = netns.iproute.create_if_pair(if1, if2)
if1 = nemu.iproute.interface(name = self._gen_if_name())
if2 = nemu.iproute.interface(name = self._gen_if_name())
ctl, ns = nemu.iproute.create_if_pair(if1, if2)
try:
netns.iproute.change_netns(ns, node.pid)
nemu.iproute.change_netns(ns, node.pid)
except:
netns.iproute.del_if(ctl)
nemu.iproute.del_if(ctl)
# the other interface should go away automatically
raise
self._control = SlaveInterface(ctl.index)
......@@ -173,14 +173,14 @@ class P2PInterface(NSInterface):
def create_pair(node1, node2):
"""Create and return a pair of connected P2PInterface objects,
assigned to name spaces represented by `node1' and `node2'."""
if1 = netns.iproute.interface(name = P2PInterface._gen_if_name())
if2 = netns.iproute.interface(name = P2PInterface._gen_if_name())
pair = netns.iproute.create_if_pair(if1, if2)
if1 = nemu.iproute.interface(name = P2PInterface._gen_if_name())
if2 = nemu.iproute.interface(name = P2PInterface._gen_if_name())
pair = nemu.iproute.create_if_pair(if1, if2)
try:
netns.iproute.change_netns(pair[0], node1.pid)
netns.iproute.change_netns(pair[1], node2.pid)
nemu.iproute.change_netns(pair[0], node1.pid)
nemu.iproute.change_netns(pair[1], node2.pid)
except:
netns.iproute.del_if(pair[0])
nemu.iproute.del_if(pair[0])
# the other interface should go away automatically
raise
......@@ -215,13 +215,13 @@ class ImportedNodeInterface(NSInterface):
self._slave = None
self._migrate = migrate
if self._migrate:
iface = netns.iproute.get_if(iface)
iface = nemu.iproute.get_if(iface)
self._original_state = iface.copy()
# Change the name to avoid clashes
iface.name = self._gen_if_name()
netns.iproute.set_if(iface)
nemu.iproute.set_if(iface)
# Migrate it
netns.iproute.change_netns(iface, node.pid)
nemu.iproute.change_netns(iface, node.pid)
else:
iface = node._slave.get_if_data(iface)
self._original_state = iface.copy()
......@@ -239,7 +239,7 @@ class ImportedNodeInterface(NSInterface):
self._slave.set_if(self._original_state)
if self._migrate:
# else, assume it is already in the main name space
netns.iproute.set_if(self._original_state)
nemu.iproute.set_if(self._original_state)
self._slave = None
class TapNodeInterface(NSInterface):
......@@ -251,9 +251,9 @@ class TapNodeInterface(NSInterface):
interface should be put."""
self._fd = None
self._slave = None
iface = netns.iproute.interface(name = self._gen_if_name())
iface, self._fd = netns.iproute.create_tap(iface, use_pi = use_pi)
netns.iproute.change_netns(iface.name, node.pid)
iface = nemu.iproute.interface(name = self._gen_if_name())
iface, self._fd = nemu.iproute.create_tap(iface, use_pi = use_pi)
nemu.iproute.change_netns(iface.name, node.pid)
super(TapNodeInterface, self).__init__(node, iface.index)
@property
......@@ -278,10 +278,10 @@ class TunNodeInterface(NSInterface):
interface should be put."""
self._fd = None
self._slave = None
iface = netns.iproute.interface(name = self._gen_if_name())
iface, self._fd = netns.iproute.create_tap(iface, use_pi = use_pi,
iface = nemu.iproute.interface(name = self._gen_if_name())
iface, self._fd = nemu.iproute.create_tap(iface, use_pi = use_pi,
tun = True)
netns.iproute.change_netns(iface.name, node.pid)
nemu.iproute.change_netns(iface.name, node.pid)
super(TunNodeInterface, self).__init__(node, iface.index)
@property
......@@ -307,35 +307,35 @@ class ExternalInterface(Interface):
# some black magic to automatically get/set interface attributes
def __getattr__(self, name):
iface = netns.iproute.get_if(self.index)
iface = nemu.iproute.get_if(self.index)
return getattr(iface, name)
def __setattr__(self, name, value):
if name[0] == '_': # forbid anything that doesn't start with a _
super(ExternalInterface, self).__setattr__(name, value)
return
iface = netns.iproute.interface(index = self.index)
iface = nemu.iproute.interface(index = self.index)
setattr(iface, name, value)
return netns.iproute.set_if(iface)
return nemu.iproute.set_if(iface)
def add_v4_address(self, address, prefix_len, broadcast = None):
addr = netns.iproute.ipv4address(address, prefix_len, broadcast)
netns.iproute.add_addr(self.index, addr)
addr = nemu.iproute.ipv4address(address, prefix_len, broadcast)
nemu.iproute.add_addr(self.index, addr)
def add_v6_address(self, address, prefix_len):
addr = netns.iproute.ipv6address(address, prefix_len)
netns.iproute.add_addr(self.index, addr)
addr = nemu.iproute.ipv6address(address, prefix_len)
nemu.iproute.add_addr(self.index, addr)
def del_v4_address(self, address, prefix_len, broadcast = None):
addr = netns.iproute.ipv4address(address, prefix_len, broadcast)
netns.iproute.del_addr(self.index, addr)
addr = nemu.iproute.ipv4address(address, prefix_len, broadcast)
nemu.iproute.del_addr(self.index, addr)
def del_v6_address(self, address, prefix_len):
addr = netns.iproute.ipv6address(address, prefix_len)
netns.iproute.del_addr(self.index, addr)
addr = nemu.iproute.ipv6address(address, prefix_len)
nemu.iproute.del_addr(self.index, addr)
def get_addresses(self):
addresses = netns.iproute.get_addr_data(self.index)
addresses = nemu.iproute.get_addr_data(self.index)
ret = []
for a in addresses:
if hasattr(a, 'broadcast'):
......@@ -363,10 +363,10 @@ class ImportedInterface(ExternalInterface):
not migrated inside the name space. This kind of interfaces can only be
connected to Switch objects and not assigned to a name space. On
destruction, the code will try to restore the interface to the state it
was in before being imported into netns."""
was in before being imported into nemu."""
def __init__(self, iface):
self._original_state = None
iface = netns.iproute.get_if(iface)
iface = nemu.iproute.get_if(iface)
self._original_state = iface.copy()
super(ImportedInterface, self).__init__(iface.index)
......@@ -374,7 +374,7 @@ class ImportedInterface(ExternalInterface):
def destroy(self): # override: restore as much as possible
if self._original_state:
debug("ImportedInterface(0x%x).destroy()" % id(self))
netns.iproute.set_if(self._original_state)
nemu.iproute.set_if(self._original_state)
self._original_state = None
# Switch is just another interface type
......@@ -395,7 +395,7 @@ class Switch(ExternalInterface):
self._parameters = {}
self._ports = weakref.WeakValueDictionary()
iface = netns.iproute.create_bridge(self._gen_br_name())
iface = nemu.iproute.create_bridge(self._gen_br_name())
super(Switch, self).__init__(iface.index)
# FIXME: is this correct/desirable/etc?
......@@ -406,7 +406,7 @@ class Switch(ExternalInterface):
self.set_parameters(**args)
def __getattr__(self, name):
iface = netns.iproute.get_bridge(self.index)
iface = nemu.iproute.get_bridge(self.index)
return getattr(iface, name)
def __setattr__(self, name, value):
......@@ -419,9 +419,9 @@ class Switch(ExternalInterface):
if self._check_port(i.index):
setattr(i, name, value)
# Set bridge
iface = netns.iproute.bridge(index = self.index)
iface = nemu.iproute.bridge(index = self.index)
setattr(iface, name, value)
netns.iproute.set_bridge(iface)
nemu.iproute.set_bridge(iface)
def destroy(self):
if not self.index:
......@@ -437,14 +437,14 @@ class Switch(ExternalInterface):
self.disconnect(p)
self._ports.clear()
netns.iproute.del_bridge(self.index)
nemu.iproute.del_bridge(self.index)
self._idx = None
def connect(self, iface):
assert iface.control.index not in self._ports
try:
self._apply_parameters(self._parameters, iface.control)
netns.iproute.add_bridge_port(self.index, iface.control.index)
nemu.iproute.add_bridge_port(self.index, iface.control.index)
except:
self._apply_parameters({}, iface.control)
raise
......@@ -453,7 +453,7 @@ class Switch(ExternalInterface):
self._ports[iface.control.index] = iface.control
def _check_port(self, port_index):
ports = netns.iproute.get_bridge_data()[2]
ports = nemu.iproute.get_bridge_data()[2]
if self.index in ports and port_index in ports[self.index]:
return True
# else
......@@ -466,7 +466,7 @@ class Switch(ExternalInterface):
assert iface.control.index in self._ports
if not self._check_port(iface.control.index):
return
netns.iproute.del_bridge_port(self.index, iface.control.index)
nemu.iproute.del_bridge_port(self.index, iface.control.index)
self._apply_parameters({}, iface.control)
del self._ports[iface.control.index]
......@@ -506,5 +506,5 @@ class Switch(ExternalInterface):
def _apply_parameters(self, parameters, port = None):
for i in [port] if port else self._ports.values():
netns.iproute.set_tc(i.index, **parameters)
nemu.iproute.set_tc(i.index, **parameters)
......@@ -18,7 +18,7 @@
# Nemu. If not, see <http://www.gnu.org/licenses/>.
import copy, fcntl, os, re, socket, struct, subprocess, sys
from netns.environ import *
from nemu.environ import *
# helpers
def _any_to_bool(any):
......
......@@ -18,8 +18,8 @@
# Nemu. If not, see <http://www.gnu.org/licenses/>.
import os, socket, sys, traceback, unshare, weakref
from netns.environ import *
import netns.interface, netns.protocol, netns.subprocess_
from nemu.environ import *
import nemu.interface, nemu.protocol, nemu.subprocess_
__all__ = ['Node', 'get_nodes', 'import_if']
......@@ -35,7 +35,7 @@ class Node(object):
"""Create a new node in the emulation. Implemented as a separate
process in a new network name space. Requires root privileges to run.
If keepns is true, the network name space is not created and can be
If nonetns is true, the network name space is not created and can be
run as a normal user, for testing."""
# Initialize attributes, in case something fails during __init__
......@@ -47,7 +47,7 @@ class Node(object):
fd, pid = _start_child(nonetns)
self._pid = pid
debug("Node(0x%x).__init__(), pid = %s" % (id(self), pid))
self._slave = netns.protocol.Client(fd, fd)
self._slave = nemu.protocol.Client(fd, fd)
if forward_X11:
self._slave.enable_x11_forwarding()
......@@ -93,44 +93,44 @@ class Node(object):
self._processes[subprocess.pid] = subprocess
def Subprocess(self, *kargs, **kwargs):
return netns.subprocess_.Subprocess(self, *kargs, **kwargs)
return nemu.subprocess_.Subprocess(self, *kargs, **kwargs)
def Popen(self, *kargs, **kwargs):
return netns.subprocess_.Popen(self, *kargs, **kwargs)
return nemu.subprocess_.Popen(self, *kargs, **kwargs)
def system(self, *kargs, **kwargs):
return netns.subprocess_.system(self, *kargs, **kwargs)
return nemu.subprocess_.system(self, *kargs, **kwargs)
def backticks(self, *kargs, **kwargs):
return netns.subprocess_.backticks(self, *kargs, **kwargs)
return nemu.subprocess_.backticks(self, *kargs, **kwargs)
def backticks_raise(self, *kargs, **kwargs):
return netns.subprocess_.backticks_raise(self, *kargs, **kwargs)
return nemu.subprocess_.backticks_raise(self, *kargs, **kwargs)
# Interfaces
def _add_interface(self, interface):
self._interfaces[interface.index] = interface
def add_if(self, **kwargs):
i = netns.interface.NodeInterface(self)
i = nemu.interface.NodeInterface(self)
for k, v in kwargs.items():
setattr(i, k, v)
return i
def add_tap(self, use_pi = False, **kwargs):
i = netns.interface.TapNodeInterface(self, use_pi)
i = nemu.interface.TapNodeInterface(self, use_pi)
for k, v in kwargs.items():
setattr(i, k, v)
return i
def add_tun(self, use_pi = False, **kwargs):
i = netns.interface.TunNodeInterface(self, use_pi)
i = nemu.interface.TunNodeInterface(self, use_pi)
for k, v in kwargs.items():
setattr(i, k, v)
return i
def import_if(self, interface):
return netns.interface.ImportedNodeInterface(self, interface)
return nemu.interface.ImportedNodeInterface(self, interface)
def del_if(self, iface):
"""Doesn't destroy the interface if it wasn't created by us."""
......@@ -146,7 +146,7 @@ class Node(object):
ifaces = self._slave.get_if_data()
for i in ifaces:
if i not in self._interfaces:
iface = netns.interface.ImportedNodeInterface(self, i,
iface = nemu.interface.ImportedNodeInterface(self, i,
migrate = False)
self._auto_interfaces.append(iface) # keep it referenced!
self._interfaces[i] = iface
......@@ -161,7 +161,7 @@ class Node(object):
def route(self, tipe = 'unicast', prefix = None, prefix_len = 0,
nexthop = None, interface = None, metric = 0):
return netns.iproute.route(tipe, prefix, prefix_len, nexthop,
return nemu.iproute.route(tipe, prefix, prefix_len, nexthop,
interface.index if interface else None, metric)
def add_route(self, *args, **kwargs):
......@@ -197,7 +197,7 @@ def _start_child(nonetns):
# FIXME: clean up signal handers, atexit functions, etc.
try:
s0.close()
srv = netns.protocol.Server(s1, s1)
srv = nemu.protocol.Server(s1, s1)
if not nonetns:
# create new name space
unshare.unshare(unshare.CLONE_NEWNET)
......@@ -222,4 +222,4 @@ def _start_child(nonetns):
# NOTREACHED
get_nodes = Node.get_nodes
import_if = netns.interface.ImportedInterface
import_if = nemu.interface.ImportedInterface
......@@ -19,8 +19,8 @@
import base64, errno, os, passfd, re, select, signal, socket, sys, tempfile
import time, traceback, unshare
import netns.subprocess_, netns.iproute
from netns.environ import *
import nemu.subprocess_, nemu.iproute
from nemu.environ import *
try:
from cPickle import loads, dumps
......@@ -119,7 +119,7 @@ class Server(object):
while time.time() - now < KILL_WAIT:
for pid in ch:
try:
if netns.subprocess_.poll(pid):
if nemu.subprocess_.poll(pid):
ch.remove(pid)
except OSError, e:
if e.errno == errno.ECHILD:
......@@ -136,7 +136,7 @@ class Server(object):
os.kill(-pid, signal.SIGKILL)
for pid in ch:
try:
netns.subprocess_.poll(pid)
nemu.subprocess_.poll(pid)
except OSError, e:
if e.errno != errno.ECHILD:
raise
......@@ -368,7 +368,7 @@ class Server(object):
"%s/unix:%d" % (socket.gethostname(), display),
protoname, hexkey])
if user:
user, uid, gid = netns.subprocess_.get_user(user)
user, uid, gid = nemu.subprocess_.get_user(user)
os.chown(xauth, uid, gid)
params['env']['DISPLAY'] = "127.0.0.1:%d" % display
......@@ -385,7 +385,7 @@ class Server(object):
del params['env']['DISPLAY']
try:
chld = netns.subprocess_.spawn(**params)
chld = nemu.subprocess_.spawn(**params)
finally:
# I can close the fds now
for d in ('stdin', 'stdout', 'stderr'):
......@@ -406,9 +406,9 @@ class Server(object):
self.reply(500, "Process does not exist.")
return
if cmdname == 'PROC POLL':
ret = netns.subprocess_.poll(pid)
ret = nemu.subprocess_.poll(pid)
else:
ret = netns.subprocess_.wait(pid)
ret = nemu.subprocess_.wait(pid)
if ret != None:
self._children.remove(pid)
......@@ -438,9 +438,9 @@ class Server(object):
def do_IF_LIST(self, cmdname, ifnr = None):
if ifnr == None:
ifdata = netns.iproute.get_if_data()[0]
ifdata = nemu.iproute.get_if_data()[0]
else:
ifdata = netns.iproute.get_if(ifnr)
ifdata = nemu.iproute.get_if(ifnr)
self.reply(200, ["# Interface data follows.",
_b64(dumps(ifdata, protocol = 2))])
......@@ -453,20 +453,20 @@ class Server(object):
for i in range(len(args) / 2):
d[str(args[i * 2])] = args[i * 2 + 1]
iface = netns.iproute.interface(**d)
netns.iproute.set_if(iface)
iface = nemu.iproute.interface(**d)
nemu.iproute.set_if(iface)
self.reply(200, "Done.")
def do_IF_RTRN(self, cmdname, ifnr, ns):
netns.iproute.change_netns(ifnr, ns)
nemu.iproute.change_netns(ifnr, ns)
self.reply(200, "Done.")
def do_IF_DEL(self, cmdname, ifnr):
netns.iproute.del_if(ifnr)
nemu.iproute.del_if(ifnr)
self.reply(200, "Done.")
def do_ADDR_LIST(self, cmdname, ifnr = None):
addrdata = netns.iproute.get_addr_data()[0]
addrdata = nemu.iproute.get_addr_data()[0]
if ifnr != None:
addrdata = addrdata[ifnr]
self.reply(200, ["# Address data follows.",
......@@ -474,34 +474,34 @@ class Server(object):
def do_ADDR_ADD(self, cmdname, ifnr, address, prefixlen, broadcast = None):
if address.find(":") < 0: # crude, I know
a = netns.iproute.ipv4address(address, prefixlen, broadcast)
a = nemu.iproute.ipv4address(address, prefixlen, broadcast)
else:
a = netns.iproute.ipv6address(address, prefixlen)
netns.iproute.add_addr(ifnr, a)
a = nemu.iproute.ipv6address(address, prefixlen)
nemu.iproute.add_addr(ifnr, a)
self.reply(200, "Done.")
def do_ADDR_DEL(self, cmdname, ifnr, address, prefixlen):
if address.find(":") < 0: # crude, I know
a = netns.iproute.ipv4address(address, prefixlen, None)
a = nemu.iproute.ipv4address(address, prefixlen, None)
else:
a = netns.iproute.ipv6address(address, prefixlen)
netns.iproute.del_addr(ifnr, a)
a = nemu.iproute.ipv6address(address, prefixlen)
nemu.iproute.del_addr(ifnr, a)
self.reply(200, "Done.")
def do_ROUT_LIST(self, cmdname):
rdata = netns.iproute.get_route_data()
rdata = nemu.iproute.get_route_data()
self.reply(200, ["# Routing data follows.",
_b64(dumps(rdata, protocol = 2))])
def do_ROUT_ADD(self, cmdname, tipe, prefix, prefixlen, nexthop, ifnr,
metric):
netns.iproute.add_route(netns.iproute.route(tipe, prefix, prefixlen,
nemu.iproute.add_route(nemu.iproute.route(tipe, prefix, prefixlen,
nexthop, ifnr or None, metric))
self.reply(200, "Done.")
def do_ROUT_DEL(self, cmdname, tipe, prefix, prefixlen, nexthop, ifnr,
metric):
netns.iproute.del_route(netns.iproute.route(tipe, prefix, prefixlen,
nemu.iproute.del_route(nemu.iproute.route(tipe, prefix, prefixlen,
nexthop, ifnr or None, metric))
self.reply(200, "Done.")
......@@ -631,7 +631,7 @@ class Client(object):
"""Start a subprocess in the slave; the interface resembles
subprocess.Popen, but with less functionality. In particular
stdin/stdout/stderr can only be None or a open file descriptor.
See netns.subprocess_.spawn for details."""
See nemu.subprocess_.spawn for details."""
if executable == None:
executable = argv[0]
......
......@@ -18,7 +18,7 @@
# Nemu. If not, see <http://www.gnu.org/licenses/>.
import fcntl, grp, os, pickle, pwd, signal, select, sys, time, traceback
from netns.environ import eintr_wrapper
from nemu.environ import eintr_wrapper
__all__ = [ 'PIPE', 'STDOUT', 'Popen', 'Subprocess', 'spawn', 'wait', 'poll',
'get_user', 'system', 'backticks', 'backticks_raise' ]
......@@ -28,7 +28,7 @@ __all__ = [ 'PIPE', 'STDOUT', 'Popen', 'Subprocess', 'spawn', 'wait', 'poll',
KILL_WAIT = 3 # seconds
class Subprocess(object):
"""Class that allows the execution of programs inside a netns Node. This is
"""Class that allows the execution of programs inside a nemu Node. This is
the base class for all process operations, Popen provides a more high level
interface."""
# FIXME
......@@ -40,7 +40,7 @@ class Subprocess(object):
"""Forks and execs a program, with stdio redirection and user
switching.
A netns Node to run the program is is specified as the first parameter.
A nemu Node to run the program is is specified as the first parameter.
The program is specified by `executable', if it does not contain any
slash, the PATH environment variable is used to search for the file.
......@@ -148,7 +148,7 @@ class Popen(Subprocess):
def __init__(self, node, argv, executable = None,
stdin = None, stdout = None, stderr = None, bufsize = 0,
shell = False, cwd = None, env = None, user = None):
"""As in Subprocess, `node' specifies the netns Node to run in.
"""As in Subprocess, `node' specifies the nemu Node to run in.
The `stdin', `stdout', and `stderr' parameters also accept the special
values subprocess.PIPE or subprocess.STDOUT. Check the stdlib's
......@@ -267,7 +267,7 @@ def backticks_raise(node, args):
# =======================================================================
#
# Server-side code, called from netns.protocol.Server
# Server-side code, called from nemu.protocol.Server
def spawn(executable, argv = None, cwd = None, env = None, close_fds = False,
stdin = None, stdout = None, stderr = None, user = None):
......
......@@ -2,27 +2,27 @@
# vim:ts=4:sw=4:et:ai:sts=4
import grp, os, pwd, select, time, unittest
import netns, test_util
import nemu, test_util
class TestConfigure(unittest.TestCase):
def test_config_run_as_static(self):
# Don't allow root as default user
self.assertRaises(AttributeError, setattr, netns.config,
self.assertRaises(AttributeError, setattr, nemu.config,
'run_as', 'root')
self.assertRaises(AttributeError, setattr, netns.config,
self.assertRaises(AttributeError, setattr, nemu.config,
'run_as', 0)
# Don't allow invalid users
self.assertRaises(AttributeError, setattr, netns.config,
self.assertRaises(AttributeError, setattr, nemu.config,
'run_as', 'foobarbaz') # hope nobody has this user!
self.assertRaises(AttributeError, setattr, netns.config,
self.assertRaises(AttributeError, setattr, nemu.config,
'run_as', -1)
class TestGlobal(unittest.TestCase):
@test_util.skipUnless(os.getuid() == 0, "Test requires root privileges")
def test_run_ping_p2pif(self):
n1 = netns.Node()
n2 = netns.Node()
i1, i2 = netns.P2PInterface.create_pair(n1, n2)
n1 = nemu.Node()
n2 = nemu.Node()
i1, i2 = nemu.P2PInterface.create_pair(n1, n2)
i1.up = i2.up = True
i1.lladdr = 'd6:4b:3f:f7:ff:7e'
i2.lladdr = 'd6:4b:3f:f7:ff:7f'
......@@ -46,12 +46,12 @@ class TestGlobal(unittest.TestCase):
@test_util.skipUnless(os.getuid() == 0, "Test requires root privileges")
def test_run_ping_node_if(self):
n1 = netns.Node()
n2 = netns.Node()
n1 = nemu.Node()
n2 = nemu.Node()
i1 = n1.add_if()
i2 = n2.add_if()
i1.up = i2.up = True
l = netns.Switch()
l = nemu.Switch()
l.connect(i1)
l.connect(i2)
l.up = True
......@@ -66,11 +66,11 @@ class TestGlobal(unittest.TestCase):
@test_util.skipUnless(os.getuid() == 0, "Test requires root privileges")
def test_run_ping_routing_p2p(self):
n1 = netns.Node()
n2 = netns.Node()
n3 = netns.Node()
i12, i21 = netns.P2PInterface.create_pair(n1, n2)
i23, i32 = netns.P2PInterface.create_pair(n2, n3)
n1 = nemu.Node()
n2 = nemu.Node()
n3 = nemu.Node()
i12, i21 = nemu.P2PInterface.create_pair(n1, n2)
i23, i32 = nemu.P2PInterface.create_pair(n2, n3)
i12.up = i21.up = i23.up = i32.up = True
i12.add_v4_address('10.0.0.1', 24)
i21.add_v4_address('10.0.0.2', 24)
......@@ -90,16 +90,16 @@ class TestGlobal(unittest.TestCase):
@test_util.skipUnless(os.getuid() == 0, "Test requires root privileges")
def test_run_ping_routing(self):
n1 = netns.Node()
n2 = netns.Node()
n3 = netns.Node()
n1 = nemu.Node()
n2 = nemu.Node()
n3 = nemu.Node()
i1 = n1.add_if()
i2a = n2.add_if()
i2b = n2.add_if()
i3 = n3.add_if()
i1.up = i2a.up = i2b.up = i3.up = True
l1 = netns.Switch()
l2 = netns.Switch()
l1 = nemu.Switch()
l2 = nemu.Switch()
l1.connect(i1)
l1.connect(i2a)
l2.connect(i2b)
......@@ -125,8 +125,8 @@ class TestGlobal(unittest.TestCase):
def test_run_ping_tap(self):
"""This test simulates a point to point connection between two hosts
using two tap devices"""
n1 = netns.Node()
n2 = netns.Node()
n1 = nemu.Node()
n2 = nemu.Node()
tap1 = n1.add_tap()
tap2 = n2.add_tap()
......@@ -157,10 +157,10 @@ class TestGlobal(unittest.TestCase):
def test_run_ping_tap_routing(self):
"""This test simulates a point to point connection between two hosts
using two tap devices"""
n1 = netns.Node()
n2 = netns.Node()
n3 = netns.Node()
n4 = netns.Node()
n1 = nemu.Node()
n2 = nemu.Node()
n3 = nemu.Node()
n4 = nemu.Node()
i1 = n1.add_if()
i2 = n2.add_if()
......@@ -171,8 +171,8 @@ class TestGlobal(unittest.TestCase):
i1.up = i2.up = tap1.up = tap2.up = i3.up = i4.up = True
l1 = netns.Switch()
l2 = netns.Switch()
l1 = nemu.Switch()
l2 = nemu.Switch()
l1.connect(i1)
l1.connect(i2)
......@@ -215,26 +215,26 @@ class TestGlobal(unittest.TestCase):
class TestX11(unittest.TestCase):
@test_util.skipUnless("DISPLAY" in os.environ, "Test requires working X11")
@test_util.skipUnless(netns.environ.xdpyinfo_path, "Test requires xdpyinfo")
@test_util.skipUnless(nemu.environ.xdpyinfo_path, "Test requires xdpyinfo")
def test_run_xdpyinfo(self):
xdpy = netns.environ.xdpyinfo_path
info = netns.environ.backticks([xdpy])
xdpy = nemu.environ.xdpyinfo_path
info = nemu.environ.backticks([xdpy])
# remove first line, contains the display name
info = info.partition("\n")[2]
n = netns.Node(nonetns = True, forward_X11 = True)
n = nemu.Node(nonetns = True, forward_X11 = True)
info2 = n.backticks([xdpy])
info2 = info2.partition("\n")[2]
self.assertEquals(info, info2)
@test_util.skipUnless(os.getuid() == 0, "Test requires root privileges")
@test_util.skipUnless("DISPLAY" in os.environ, "Test requires working X11")
@test_util.skipUnless(netns.environ.xdpyinfo_path, "Test requires xdpyinfo")
@test_util.skipUnless(nemu.environ.xdpyinfo_path, "Test requires xdpyinfo")
def test_run_xdpyinfo_netns(self):
xdpy = netns.environ.xdpyinfo_path
info = netns.environ.backticks([xdpy])
xdpy = nemu.environ.xdpyinfo_path
info = nemu.environ.backticks([xdpy])
# remove first line, contains the display name
info = info.partition("\n")[2]
n = netns.Node(forward_X11 = True)
n = nemu.Node(forward_X11 = True)
info2 = n.backticks([xdpy])
info2 = info2.partition("\n")[2]
self.assertEquals(info, info2)
......
......@@ -2,8 +2,8 @@
# vim:ts=4:sw=4:et:ai:sts=4
from test_util import get_devs, get_devs_netns
from netns.environ import *
import netns, test_util
from nemu.environ import *
import nemu, test_util
import os, unittest
class TestUtils(unittest.TestCase):
......@@ -22,7 +22,7 @@ class TestUtils(unittest.TestCase):
class TestInterfaces(unittest.TestCase):
@test_util.skipUnless(os.getuid() == 0, "Test requires root privileges")
def test_interface_creation(self):
node0 = netns.Node()
node0 = nemu.Node()
ifaces = []
for i in range(5):
ifaces.append(node0.add_if())
......@@ -40,12 +40,12 @@ class TestInterfaces(unittest.TestCase):
devs = get_devs()
for i in range(5):
peer_name = netns.iproute.get_if(ifaces[i].control.index).name
peer_name = nemu.iproute.get_if(ifaces[i].control.index).name
self.assertTrue(peer_name in devs)
@test_util.skipUnless(os.getuid() == 0, "Test requires root privileges")
def test_interface_settings(self):
node0 = netns.Node()
node0 = nemu.Node()
if0 = node0.add_if(lladdr = '42:71:e0:90:ca:42', mtu = 1492)
self.assertEquals(if0.lladdr, '42:71:e0:90:ca:42',
"Constructor parameters")
......@@ -90,7 +90,7 @@ class TestInterfaces(unittest.TestCase):
@test_util.skipUnless(os.getuid() == 0, "Test requires root privileges")
def test_interface_addresses(self):
node0 = netns.Node()
node0 = nemu.Node()
if0 = node0.add_if()
if0.add_v4_address(address = '10.0.0.1', prefix_len = 24,
broadcast = '10.0.0.255')
......@@ -124,7 +124,7 @@ class TestWithDummy(unittest.TestCase):
test_util.get_linux_ver() >= test_util.make_linux_ver("2.6.35"),
"Test trigger a kernel bug on 2.6.34")
def test_interface_migration(self):
node = netns.Node()
node = nemu.Node()
self.dummyname = "dummy%d" % os.getpid()
self.assertEquals(os.system("%s link add name %s type dummy" %
(ip_path, self.dummyname)), 0)
......
#!/usr/bin/env python
# vim:ts=4:sw=4:et:ai:sts=4
import netns, netns.environ, test_util
import nemu, nemu.environ, test_util
import os, signal, subprocess, sys, time
import unittest
class TestNode(unittest.TestCase):
@test_util.skipUnless(os.getuid() == 0, "Test requires root privileges")
def test_node(self):
node = netns.Node()
node = nemu.Node()
self.failIfEqual(node.pid, os.getpid())
self.failIfEqual(node.pid, None)
# check if it really exists
os.kill(node.pid, 0)
nodes = netns.get_nodes()
nodes = nemu.get_nodes()
self.assertEquals(nodes, [node])
self.assertTrue(node.get_interface("lo").up)
@test_util.skip("Not implemented")
def test_detect_fork(self):
# Test that netns recognises a fork
# Test that nemu recognises a fork
chld = os.fork()
if chld == 0:
if len(netns.get_nodes()) == 0:
if len(nemu.get_nodes()) == 0:
os._exit(0)
os._exit(1)
(pid, exitcode) = os.waitpid(chld, 0)
......@@ -33,25 +33,25 @@ class TestNode(unittest.TestCase):
@test_util.skipUnless(os.getuid() == 0, "Test requires root privileges")
def test_cleanup(self):
def create_stuff():
a = netns.Node()
b = netns.Node()
a = nemu.Node()
b = nemu.Node()
ifa = a.add_if()
ifb = b.add_if()
switch = netns.Switch()
switch = nemu.Switch()
switch.connect(ifa)
switch.connect(ifb)
# Test automatic destruction
orig_devs = len(test_util.get_devs())
create_stuff()
self.assertEquals(netns.get_nodes(), [])
self.assertEquals(nemu.get_nodes(), [])
self.assertEquals(orig_devs, len(test_util.get_devs()))
# Test at_exit hooks
orig_devs = len(test_util.get_devs())
chld = os.fork()
if chld == 0:
netns.set_cleanup_hooks(on_exit = True, on_signals = [])
nemu.set_cleanup_hooks(on_exit = True, on_signals = [])
create_stuff()
os._exit(0)
os.waitpid(chld, 0)
......@@ -61,7 +61,7 @@ class TestNode(unittest.TestCase):
orig_devs = len(test_util.get_devs())
chld = os.fork()
if chld == 0:
netns.set_cleanup_hooks(on_exit = False,
nemu.set_cleanup_hooks(on_exit = False,
on_signals = [signal.SIGTERM])
create_stuff()
while True:
......
#!/usr/bin/env python
# vim:ts=4:sw=4:et:ai:sts=4
import netns.protocol
import nemu.protocol
import os, socket, sys, threading, unittest
class TestServer(unittest.TestCase):
......@@ -22,10 +22,10 @@ class TestServer(unittest.TestCase):
break
def run_server():
srv = netns.protocol.Server(s0, s0)
srv = nemu.protocol.Server(s0, s0)
srv.run()
srv = netns.protocol.Server(s2.fileno(), s2.fileno())
srv = nemu.protocol.Server(s2.fileno(), s2.fileno())
srv.run()
t = threading.Thread(target = run_server)
t.start()
......@@ -47,11 +47,11 @@ class TestServer(unittest.TestCase):
(s0, s1) = socket.socketpair(socket.AF_UNIX, socket.SOCK_STREAM, 0)
def run_server():
netns.protocol.Server(s0, s0).run()
nemu.protocol.Server(s0, s0).run()
t = threading.Thread(target = run_server)
t.start()
cli = netns.protocol.Client(s1, s1)
cli = nemu.protocol.Client(s1, s1)
# make PROC SIN fail
self.assertRaises(OSError, cli.spawn, "/bin/true", stdin = -1)
......@@ -69,7 +69,7 @@ class TestServer(unittest.TestCase):
def test_basic_stuff(self):
(s0, s1) = socket.socketpair(socket.AF_UNIX, socket.SOCK_STREAM, 0)
srv = netns.protocol.Server(s0, s0)
srv = nemu.protocol.Server(s0, s0)
s1 = s1.makefile("r+", 1)
def check_error(self, cmd, code = 500):
......@@ -120,7 +120,7 @@ class TestServer(unittest.TestCase):
check_error(self, "proc crte =a") # invalid b64
# simulate proc mode
srv._commands = netns.protocol._proc_commands
srv._commands = nemu.protocol._proc_commands
check_error(self, "proc crte foo")
check_error(self, "proc poll 0")
check_error(self, "proc wait 0")
......
#!/usr/bin/env python
# vim:ts=4:sw=4:et:ai:sts=4
import netns, test_util
import nemu, test_util
import os, unittest
class TestRouting(unittest.TestCase):
@test_util.skip("Programatic detection of duplicate routes not implemented")
def test_base_routing(self):
node = netns.Node(nonetns = True)
node = nemu.Node(nonetns = True)
routes = node.get_routes() # main netns routes!
if(len(routes)):
self.assertRaises(RuntimeError, node.add_route, routes[0])
......@@ -16,7 +16,7 @@ class TestRouting(unittest.TestCase):
@test_util.skipUnless(os.getuid() == 0, "Test requires root privileges")
def test_routing(self):
node = netns.Node()
node = nemu.Node()
self.assertEquals(len(node.get_routes()), 0)
if0 = node.add_if()
......
#!/usr/bin/env python
# vim:ts=4:sw=4:et:ai:sts=4
import netns, netns.subprocess_, test_util
import nemu, nemu.subprocess_, test_util
import grp, os, pwd, signal, socket, sys, time, unittest
from netns.subprocess_ import *
from nemu.subprocess_ import *
def _stat(path):
try:
......@@ -79,7 +79,7 @@ class TestSubprocess(unittest.TestCase):
@test_util.skipUnless(os.getuid() == 0, "Test requires root privileges")
def test_Subprocess_chuser(self):
node = netns.Node(nonetns = True)
node = nemu.Node(nonetns = True)
user = 'nobody'
p = Subprocess(node, ['/bin/sleep', '1000'], user = user)
self._check_ownership(user, p.pid)
......@@ -123,7 +123,7 @@ class TestSubprocess(unittest.TestCase):
self.assertEquals(wait(p), 0)
def test_Subprocess_basic(self):
node = netns.Node(nonetns = True)
node = nemu.Node(nonetns = True)
# User does not exist
self.assertRaises(ValueError, Subprocess, node,
['/bin/sleep', '1000'], user = self.nouser)
......@@ -201,7 +201,7 @@ class TestSubprocess(unittest.TestCase):
self.assertEquals(p.wait(), -signal.SIGTERM)
def test_Popen(self):
node = netns.Node(nonetns = True)
node = nemu.Node(nonetns = True)
# repeat test with Popen interface
r0, w0 = os.pipe()
......@@ -291,7 +291,7 @@ class TestSubprocess(unittest.TestCase):
self.assertEquals(p.communicate(_longstring), (_longstring, ) * 2)
def test_backticks(self):
node = netns.Node(nonetns = True)
node = nemu.Node(nonetns = True)
self.assertEquals(backticks(node, "echo hello world"), "hello world\n")
self.assertEquals(backticks(node, r"echo hello\ \ world"),
"hello world\n")
......@@ -303,7 +303,7 @@ class TestSubprocess(unittest.TestCase):
self.assertRaises(RuntimeError, backticks_raise, node, "kill $$")
def test_system(self):
node = netns.Node(nonetns = True)
node = nemu.Node(nonetns = True)
self.assertEquals(system(node, "true"), 0)
self.assertEquals(system(node, "false"), 1)
......
......@@ -2,16 +2,16 @@
# vim:ts=4:sw=4:et:ai:sts=4
import os, unittest
import netns, test_util, netns.environ
import nemu, test_util, nemu.environ
class TestSwitch(unittest.TestCase):
@test_util.skipUnless(os.getuid() == 0, "Test requires root privileges")
def setUp(self):
n1 = netns.Node()
n2 = netns.Node()
n1 = nemu.Node()
n2 = nemu.Node()
i1 = n1.add_if()
i2 = n2.add_if()
l = netns.Switch()
l = nemu.Switch()
l.connect(i1)
l.connect(i2)
self.stuff = (n1, n2, i1, i2, l)
......@@ -20,7 +20,7 @@ class TestSwitch(unittest.TestCase):
def test_switch_base(self):
(n1, n2, i1, i2, l) = self.stuff
l.mtu = 3000
ifdata = netns.iproute.get_if_data()[0]
ifdata = nemu.iproute.get_if_data()[0]
self.assertEquals(ifdata[l.index].mtu, 3000)
self.assertEquals(ifdata[i1.control.index].mtu, 3000,
"MTU propagation")
......@@ -35,11 +35,11 @@ class TestSwitch(unittest.TestCase):
"UP propagation")
l.up = True
ifdata = netns.iproute.get_if_data()[0]
ifdata = nemu.iproute.get_if_data()[0]
self.assertEquals(ifdata[i1.control.index].up, True, "UP propagation")
self.assertEquals(ifdata[i2.control.index].up, True, "UP propagation")
tcdata = netns.iproute.get_tc_data()[0]
tcdata = nemu.iproute.get_tc_data()[0]
self.assertEquals(tcdata[i1.control.index], {"qdiscs": {}})
self.assertEquals(tcdata[i2.control.index], {"qdiscs": {}})
......@@ -50,11 +50,11 @@ class TestSwitch(unittest.TestCase):
# Test strange rules handling
os.system(("%s qd add dev %s root prio bands 3 " +
"priomap 1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1") %
(netns.environ.tc_path, i1.control.name))
tcdata = netns.iproute.get_tc_data()[0]
(nemu.environ.tc_path, i1.control.name))
tcdata = nemu.iproute.get_tc_data()[0]
self.assertEquals(tcdata[i1.control.index], "foreign")
l.set_parameters(bandwidth = 13107200) # 100 mbits
tcdata = netns.iproute.get_tc_data()[0]
tcdata = nemu.iproute.get_tc_data()[0]
self.assertEquals(tcdata[i1.control.index],
{"bandwidth": 13107000, "qdiscs": {"tbf": "1"}})
......@@ -76,14 +76,14 @@ class TestSwitch(unittest.TestCase):
def _test_none(self):
(n1, n2, i1, i2, l) = self.stuff
l.set_parameters()
tcdata = netns.iproute.get_tc_data()[0]
tcdata = nemu.iproute.get_tc_data()[0]
self.assertEquals(tcdata[i1.control.index], {"qdiscs": {}})
self.assertEquals(tcdata[i2.control.index], {"qdiscs": {}})
def _test_tbf(self):
(n1, n2, i1, i2, l) = self.stuff
l.set_parameters(bandwidth = 13107200) # 100 mbits
tcdata = netns.iproute.get_tc_data()[0]
tcdata = nemu.iproute.get_tc_data()[0]
self.assertEquals(tcdata[i1.control.index],
# adjust for tc rounding
{"bandwidth": 13107000, "qdiscs": {"tbf": "1"}})
......@@ -93,7 +93,7 @@ class TestSwitch(unittest.TestCase):
def _test_netem(self):
(n1, n2, i1, i2, l) = self.stuff
l.set_parameters(delay = 0.001) # 1ms
tcdata = netns.iproute.get_tc_data()[0]
tcdata = nemu.iproute.get_tc_data()[0]
self.assertEquals(tcdata[i1.control.index],
{"delay": 0.001, "qdiscs": {"netem": "2"}})
self.assertEquals(tcdata[i2.control.index],
......@@ -102,7 +102,7 @@ class TestSwitch(unittest.TestCase):
def _test_both(self):
(n1, n2, i1, i2, l) = self.stuff
l.set_parameters(bandwidth = 13107200, delay = 0.001) # 100 mbits, 1ms
tcdata = netns.iproute.get_tc_data()[0]
tcdata = nemu.iproute.get_tc_data()[0]
self.assertEquals(tcdata[i1.control.index],
{"bandwidth": 13107000, "delay": 0.001,
"qdiscs": {"tbf": "1", "netem": "2"}})
......
......@@ -2,8 +2,8 @@
# vim:ts=4:sw=4:et:ai:sts=4
import os, re, subprocess, sys
import netns.subprocess_
from netns.environ import *
import nemu.subprocess_
from nemu.environ import *
def process_ipcmd(str):
cur = None
......@@ -58,7 +58,7 @@ def get_devs():
return process_ipcmd(outdata)
def get_devs_netns(node):
out = netns.subprocess_.backticks_raise(node, [ip_path, "addr", "list"])
out = nemu.subprocess_.backticks_raise(node, [ip_path, "addr", "list"])
return process_ipcmd(out)
def make_linux_ver(string):
......
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