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