diff --git a/start_testbed.py b/start_testbed.py index f8653742627f3be79394c477bc7cdaf1d929651b..7da30860ed4810f4e98281c1f198879c15aa8e82 100755 --- a/start_testbed.py +++ b/start_testbed.py @@ -23,6 +23,7 @@ base_addr = reduce( lambda a,b : a*256+b, [ int(q) for q in ntwk['subnet_addr'].split('.') ] ) +subnet = ntwk['subnet_addr']+'/'+str(ntwk['subnet_len']) nodelist = list() @@ -33,6 +34,14 @@ def make_ip(i): masks = [ 24, 16, 8, 0 ] return '.'.join([ str((addr>>mask)&0xFF) for mask in masks ]) +def make_route(f,net,fdev): + subprocess.call([ + 'sudo', 'ip', 'netns', 'exec', f['name'], + 'ip', 'route', 'add', net, + 'dev', fdev, 'proto', 'static', 'scope', 'global', + 'src', f['addr'] + ]) + def connect_nodes(node1, node2): ctr1 = nodelist[node1] ctr2 = nodelist[node2] @@ -73,13 +82,7 @@ def connect_nodes(node1, node2): # Set initial routes. def route_from_to(f,t,fdev): - # $ctx ip route add $net dev $dev proto static scope global src $addr - subprocess.call([ - 'sudo', 'ip', 'netns', 'exec', f['name'], - 'ip', 'route', 'add', t['addr']+'/32', - 'dev', fdev, 'proto', 'static', 'scope', 'global', - 'src', f['addr'] - ]) + make_route(f,t['addr']+'/32',fdev) route_from_to(ctr1,ctr2,dev_1) route_from_to(ctr2,ctr1,dev_2) @@ -92,7 +95,12 @@ def make_mesh(): for n2 in range(n1+1,num_nodes) ] def make_star(): - pass + global nodelist + def get_dev(i): + return 'bac0_{i}_0'.format(i=i) + num_nodes = len(nodelist) + [ connect_nodes(0,n) for n in range(1,num_nodes) ] + [ make_route(n,subnet,get_dev(n)) for n in range(1,num_nodes) ] def start_node(base_name,i): global nodelist @@ -137,6 +145,8 @@ def start_node(base_name,i): for n in range(ntwk['num_nodes']): start_node(ntwk['name'],n) -# XXX - need to check if we're a star or mesh network, and call the appropriate function -make_mesh() +if ntwk['topology'] == 'mesh': + make_mesh() +else: + make_star() diff --git a/stop_testbed.py b/stop_testbed.py index 2d3556d426ea4d653f819ae5215a5e64ff3ad791..a9fc2ac1312c41be36804e21016d4cda888a42ff 100755 --- a/stop_testbed.py +++ b/stop_testbed.py @@ -26,6 +26,8 @@ def stop_node(name,i): retval = subprocess.call(command) command = ['docker', 'rm', ctr_name ] retval = subprocess.call(command) + command = ['sudo', 'rm', '/var/run/netns/'+ctr_name] + retval = subprocess.call(command) for i in range(ntwk['num_nodes']): stop_node(ntwk['name'],i)