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

working on creating testbed

parent 66ab304d
No related branches found
No related tags found
No related merge requests found
...@@ -10,3 +10,9 @@ just going to run the command ...@@ -10,3 +10,9 @@ just going to run the command
This will never exit, while it waits for more output to be appended This will never exit, while it waits for more output to be appended
to the file. to the file.
Before running start_testbed.py, you must run:
sudo mkdir -p /var/run/netns
This only needs to be done once for your VM.
#! /usr/bin/env python #! /usr/bin/env python
import os
import subprocess import subprocess
import yaml import yaml
from argparse import ArgumentParser from argparse import ArgumentParser
parser = ArgumentParser() parser = ArgumentParser()
parser.add_argument('-f', '--file', parser.add_argument(
dest='file', '-f', '--file',
default='example.yml', dest='file',
help='YML file containing the testbed configuration' default='example.yml',
) help='YML file containing the testbed configuration'
)
args = parser.parse_args() args = parser.parse_args()
with open(args.file) as cfile: with open(args.file) as cfile:
conf = yaml.load(cfile) conf = yaml.load(cfile)
ntwk = conf['network']
base_addr = reduce(
lambda a,b : a*256+b,
[ int(q) for q in ntwk['subnet_addr'].split('.') ]
)
nodelist = list()
retval = subprocess.call(['docker','pull',conf['image']]) retval = subprocess.call(['docker','pull',conf['image']])
def make_ip(i):
addr = base_addr + i
masks = [ 24, 16, 8, 0 ]
return '.'.join([ str((addr>>mask)&0xFF) for mask in masks ])
def connect_nodes(node1, node2):
ctr1 = nodelist[node1]
ctr2 = nodelist[node2]
print ctr1, ctr2
def make_mesh(): def make_mesh():
pass global nodelist
num_nodes = len(nodelist)
[ connect_nodes(n1,n2)
for n1 in range(num_nodes-1)
for n2 in range(n1+1,num_nodes) ]
def make_star(): def make_star():
pass pass
ntwk = conf['network'] def start_node(base_name,i):
global nodelist
def start_node(name,i): name = base_name + str(i)
ctr_name = '{name}{i}'.format(name=name,i=i)
command = ['docker', command = ['docker',
'run', 'run',
'-d', '-d',
'--name', '--name',
ctr_name, name,
conf['image'] conf['image']
] ]
command.extend(conf['image_cmd'].split()) command.extend(conf['image_cmd'].split())
retval = subprocess.call(command) retval = subprocess.call(command)
entry = dict()
entry['name'] = name
entry['addr'] = make_ip(i)
entry['pid'] = subprocess.check_output([
'docker',
'inspect',
'-f',
'{{.State.Pid}}',
name
]).strip()
subprocess.call([
'sudo',
'ln',
'-s',
'/proc/{pid}/ns/net'.format(pid=entry['pid'],
'/var/run/netns/{name}'.format(name=name)
])
nodelist.append(entry)
for n in range(ntwk['num_nodes']):
start_node(ntwk['name'],n)
for i in range(ntwk['num_nodes']): make_mesh()
start_node(ntwk['name'],i)
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