Commit b893608e authored by Killian Lufau's avatar Killian Lufau

demo: add test to detect network mixing

A new test can be enabled in the demo with the option -t to perform
traceroute between every machines to verify that machines on the same
LAN but on a different re6st network don't communicate directly via
the local links, they must use their registry which act as their
border gateway.
parent d868f09a
import argparse, subprocess, time
'''
This script logs the output of traceroute with ICMP to several machines
passed as arguments, it is used to check if a machine from one re6st
network contacts a machine from another re6st network via its BGP
(its registry) and therefore internet or directly via a machine from
its own re6st network (which is not ok).
The log file 'traceroute.csv' follows this pattern:
timestamp | first hop->...->last hop (destination) | ok OR error
The script will fail traceroute while re6st initializes (~30s)
'''
parser = argparse.ArgumentParser()
parser.add_argument('n', help = 'my machine name (m1,m2...)')
parser.add_argument('a', nargs = '+', help = 'addresses to check routes to')
args = parser.parse_args()
me = args.n
addrs = args.a
csv = open(me + '/traceroute.csv','w')
while True:
for add in addrs:
try:
hops = subprocess.check_output(['traceroute6', '-n', '-I', add])
if '* * *' in hops:
break
hops = [ hop for hop in hops.split() if '2001' in hop ]
if hops:
#the first two occurences are verbose of traceroute
#that says who we want to reach, they're not hops
hops = '->'.join(hops[2:])
else:
break
csv.write('%r,%s,%s\n' % (time.time(), hops,
'ok' if '2001:db8::1' in hops else 'error'))
csv.flush()
time.sleep(1)
except:
print('Traceroute failed, trying again in 10s')
time.sleep(10)
......@@ -60,6 +60,8 @@ parser.add_argument('-d', '--duration', type = int,
help = 'time of the demo execution in seconds')
parser.add_argument('-p', '--ping', action = 'store_true',
help = 'execute ping utility')
parser.add_argument('-t', '--traceroute', action = 'store_true',
help = 'execute traceroute utility')
args = parser.parse_args()
def handler(signum, frame):
......@@ -297,6 +299,23 @@ if args.ping:
name = machine.name if machine.short[0] == 'R' else 'm' + machine.short
machine.screen('python ping.py {} {}'.format(name, ' '.join(ips)))
if args.traceroute:
for j, machine in enumerate(nodes):
ips = [
'2001:db8:42::1' if i == 0 else
'2001:db8:42:2::' if i == 2 else
# Only 1 address for machine2 because prefix_len = 80,+48 = 128
'2001:db8:42:%s::1' % i
for i in xrange(9)
if i != j] if j > 8 else ['2001:db8:43:1::1',' 2001:db8:43::1']
if machine.short == 'R':
name = 'registry'
elif machine.short == 'R2':
name = 'registry2'
else:
name = 'm' + machine.short
machine.screen('python check_routes.py %s %s' % (name, ' '.join(ips)))
_ll = {}
def node_by_ll(addr):
try:
......
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