From b893608e4d48917a538f074dcce459477c094e03 Mon Sep 17 00:00:00 2001 From: Killian Lufau Date: Tue, 16 Apr 2019 09:17:55 +0200 Subject: [PATCH] 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. --- demo/check_routes.py | 40 ++++++++++++++++++++++++++++++++++++++++ demo/demo | 19 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 demo/check_routes.py diff --git a/demo/check_routes.py b/demo/check_routes.py new file mode 100644 index 0000000..6a48953 --- /dev/null +++ b/demo/check_routes.py @@ -0,0 +1,40 @@ +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) diff --git a/demo/demo b/demo/demo index fad7a31..146c3d1 100755 --- a/demo/demo +++ b/demo/demo @@ -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: -- 2.30.9