Skip to content
Snippets Groups Projects
Commit 66ab304d authored by Mike Marsh's avatar Mike Marsh
Browse files

putting together testbed

parent a9ecefd2
No related branches found
No related tags found
No related merge requests found
---
# Modify these to suit your needs.
image: "gizmonic.cs.umd.edu:8080/baseline"
image_cmd: "tail -f /etc/issue"
image_cmd: "/usr/bin/tail -f /etc/issue"
# Here's how you define the network you want.
# The topology can be "mesh" or "star". The
# latter will designate the first node as the
# center of the star.
# center of the star. Containers will be named
# <name>0 through <name><num-nodes - 1>.
network:
name: test
num_nodes: 4
topology: mesh
subnet_addr: 186.192.0.0
......
#! /usr/bin/env python
import subprocess
import yaml
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument('-f', '--file',
dest='file',
default='example.yml',
help='YML file containing the testbed configuration'
)
args = parser.parse_args()
with open(args.file) as cfile:
conf = yaml.load(cfile)
retval = subprocess.call(['docker','pull',conf['image']])
def make_mesh():
pass
def make_star():
pass
ntwk = conf['network']
def start_node(name,i):
ctr_name = '{name}{i}'.format(name=name,i=i)
command = ['docker',
'run',
'-d',
'--name',
ctr_name,
conf['image']
]
command.extend(conf['image_cmd'].split())
retval = subprocess.call(command)
for i in range(ntwk['num_nodes']):
start_node(ntwk['name'],i)
#! /usr/bin/env python
import subprocess
import yaml
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument('-f', '--file',
dest='file',
default='example.yml',
help='YML file containing the testbed configuration'
)
args = parser.parse_args()
with open(args.file) as cfile:
conf = yaml.load(cfile)
retval = subprocess.call(['docker','pull',conf['image']])
ntwk = conf['network']
def stop_node(name,i):
ctr_name = '{name}{i}'.format(name=name,i=i)
command = ['docker', 'kill', ctr_name ]
retval = subprocess.call(command)
command = ['docker', 'rm', ctr_name ]
retval = subprocess.call(command)
for i in range(ntwk['num_nodes']):
stop_node(ntwk['name'],i)
#! /usr/bin/env python
import json
import docker.client
import time
import os
d = docker.Client()
fd = open("manifest.json")
j = json.load(fd)
def extract_name(ctr):
if 'Name' not in ctr: return None
slashed_name = ctr['Name']
return slashed_name.replace("/","")
def remove(name):
if name is None: return
try:
d.kill(name)
except:
None
try:
d.remove_container(name)
except:
None
os.system("sudo ip netns delete %s" % name)
for k in j:
subnet = j[k]
# First, kill the bridges. We do this because otherwise any tcpdumps we leave
# running will not terminate properly.
if 'gateways' in subnet:
gateways = subnet['gateways']
for g in gateways:
if 'bridge' in g:
gname = g['name']
gdev = g['bridge']
os.system("sudo ip netns exec {} ip link delete {} type bridge".format(gname,gdev))
if 'containers' in subnet:
containers = subnet['containers']
if 'gateways' in containers:
gateways = containers['gateways']
for g in gateways:
remove(extract_name(g))
if 'nodes' in containers:
nodes = containers['nodes']
for n in nodes:
remove(extract_name(n))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment