aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rumba/testbeds/dockertb.py63
1 files changed, 49 insertions, 14 deletions
diff --git a/rumba/testbeds/dockertb.py b/rumba/testbeds/dockertb.py
index 5dcbb16..f58ab92 100644
--- a/rumba/testbeds/dockertb.py
+++ b/rumba/testbeds/dockertb.py
@@ -82,23 +82,29 @@ class Testbed(mod.Testbed):
# Pull image
if self.pull_image:
- docker_client.images.pull(self.base_image_repo,
- self.base_image_tag)
+ logger.info("Fetching image...")
+ docker_client.images.pull(self.base_image_repo,
+ self.base_image_tag)
docker_client.images.get("%s:%s" % (self.base_image_repo,
self.base_image_tag))
+ logger.info("Starting nodes...")
+
# Start all nodes
for node in experiment.nodes:
+ logger.debug('Starting node %s', node.name)
self.running_containers[node.name] = docker_client.containers.run(
self.base_image, command=node.startup_command,
name='node-' + node.name, detach=True, network="none",
privileged=True, devices=["/dev/fuse"])
- logger.info("Nodes starting")
+ cmd = 'sudo mkdir /var/run/netns'
+
+ logger.debug('executing >> %s', cmd)
if not os.path.exists("/var/run/netns"):
- subprocess.check_call('sudo mkdir /var/run/netns'.split())
+ subprocess.check_call(cmd.split())
for shim in experiment.dif_ordering:
if not isinstance(shim, mod.ShimEthDIF):
@@ -114,9 +120,12 @@ class Testbed(mod.Testbed):
self.active_bridges.add(shim.name)
+ logger.debug('executing >> %s', cmd)
+
subprocess.check_call(cmd.split())
if not self.use_ovs:
+ logger.debug('executing >> %s', cmd)
cmd = 'sudo ip link set dev %(shim)s up' % {'shim': shim.name}
subprocess.check_call(cmd.split())
for node in experiment.nodes:
@@ -133,17 +142,27 @@ class Testbed(mod.Testbed):
pid = state["Pid"]
- subprocess.check_call(('sudo ln -s /proc/%(pid)i/ns/net '
- '/var/run/netns/%(pid)i' % {'pid': pid}).split())
+ cmd = ('sudo ln -s /proc/%(pid)i/ns/net '
+ '/var/run/netns/%(pid)i' % {'pid': pid})
+
+ logger.debug('executing >> %s', cmd)
+
+ subprocess.check_call(cmd.split())
for ipcp in node.ipcps:
if isinstance(ipcp, mod.ShimEthIPCP):
if ipcp.ifname is None:
- ipcp.ifname = "eth%i" % node.ipcps.index(ipcp)
+ ipcp.ifname = "e%i" % node.ipcps.index(ipcp)
+
+ # Linux has a limit on the length of interface names
+ node_name = node.name[0:11]
cmd = ('sudo ip link add %(node)s.%(ifname)s type veth '
'peer name _%(node)s.%(ifname)s'\
- % {'node': node.name, 'ifname': ipcp.ifname})
+ % {'node': node_name, 'ifname': ipcp.ifname})
+
+ logger.debug('executing >> %s', cmd)
+
subprocess.check_call(cmd.split())
cmd = ""
@@ -154,27 +173,33 @@ class Testbed(mod.Testbed):
cmd += ('sudo ip link set %(node)s.%(ifname)s master '
'%(dif)s')
- cmd = (cmd % {'node': node.name,
+ cmd = (cmd % {'node': node_name,
'ifname': ipcp.ifname,
'dif': ipcp.dif.name})
+ logger.debug('executing >> %s', cmd)
+
subprocess.check_call(cmd.split())
cmd = ('sudo ip link set _%(node)s.%(ifname)s '
'netns %(pid)i '
'name %(ifname)s'
- % {'node': node.name,
+ % {'node': node_name,
'pid': pid,
'ifname': ipcp.ifname})
+
+ logger.debug('executing >> %s', cmd)
subprocess.check_call(cmd.split())
cmd = ('sudo ip link set dev %(node)s.%(ifname)s up'
- % {'node': node.name, 'ifname': ipcp.ifname})
+ % {'node': node_name, 'ifname': ipcp.ifname})
+ logger.debug('executing >> %s', cmd)
subprocess.check_call(cmd.split())
cmd = ('sudo ip netns exec %(pid)i ip link set dev '
'%(ifname)s up'
% {'pid': pid, 'ifname': ipcp.ifname})
+ logger.debug('executing >> %s', cmd)
subprocess.check_call(cmd.split())
self.active_ipcps.add(ipcp)
@@ -183,10 +208,12 @@ class Testbed(mod.Testbed):
def _swap_out(self, experiment):
for name, container in self.running_containers.items():
+ logger.debug('Stopping node %s' % name)
container.remove(force=True)
for shim in experiment.dif_ordering:
- if isinstance(shim, mod.ShimEthDIF) and shim.name in self.active_bridges:
+ if isinstance(shim, mod.ShimEthDIF) \
+ and shim.name in self.active_bridges:
cmd = ""
if self.use_ovs:
cmd += 'sudo ovs-vsctl del-br %(shim)s'
@@ -194,6 +221,8 @@ class Testbed(mod.Testbed):
cmd += 'sudo ip link del %(shim)s'
cmd = cmd % {'shim': shim.name}
+ logger.debug('executing >> %s', cmd)
+
subprocess.check_call(cmd.split())
self.active_bridges.remove(shim.name)
@@ -201,8 +230,14 @@ class Testbed(mod.Testbed):
for name, container in self.running_containers.items():
pid = container.attrs["State"]["Pid"]
- cmd = 'sudo rm /var/run/netns/%(pid)i' % {'pid': pid}
- subprocess.check_call(cmd.split())
+ if pid == 0:
+ continue
+
+ path = '/var/run/netns/%d' % pid
+ if os.path.islink(path):
+ cmd = 'sudo rm '+ path
+ logger.debug('executing >> %s', cmd)
+ subprocess.check_call(cmd.split())
self.running_containers = {}