diff --git a/qa/self/api/receive.py b/qa/self/api/receive.py index afec9f86e..1190ed2d0 100755 --- a/qa/self/api/receive.py +++ b/qa/self/api/receive.py @@ -3,47 +3,48 @@ import sys match = { - 0: ['neighbor 127.0.0.1 update start',] * 20, - 1: \ - ['neighbor 127.0.0.1 announced route %d%d.0.0.0/8 next-hop 1.1.1.1 origin igp as-path [ 1 2 3 4 ] med 100' % - (number,number) for number in range(1,10) - ] \ - + \ - ['neighbor 127.0.0.1 announced route eor %d/%d (%s)' % (afi,safi,text) for (afi,safi,text) in \ - ( - (1,1,'ipv4 unicast'), - (1,2,'ipv4 multicast'), - (1,4,'ipv4 nlri-mpls'), - (1,128,'ipv4 mpls-vpn'), - (1,133,'ipv4 flow'), - (1,134,'ipv4 flow-vpn'), - (2,1,'ipv6 unicast'), - (2,128,'ipv6 mpls-vpn'), - (2,133,'ipv6 flow'), - (2,134,'ipv6 flow-vpn'), - (25,65,'l2vpn vpls') - ) - ], - 2: ['neighbor 127.0.0.1 update end',] * 20, - 3: ['',] * 20, + 0: ['neighbor 127.0.0.1 update start',] * 20, + 1: [ + 'neighbor 127.0.0.1 announced route %d%d.0.0.0/8 next-hop 1.1.1.1 origin igp as-path [ 1 2 3 4 ] med 100' + % (number, number) + for number in range(1, 10) + ] + + [ + 'neighbor 127.0.0.1 announced route eor %d/%d (%s)' % (afi, safi, text) + for (afi, safi, text) in ( + (1, 1, 'ipv4 unicast'), + (1, 2, 'ipv4 multicast'), + (1, 4, 'ipv4 nlri-mpls'), + (1, 128, 'ipv4 mpls-vpn'), + (1, 133, 'ipv4 flow'), + (1, 134, 'ipv4 flow-vpn'), + (2, 1, 'ipv6 unicast'), + (2, 128, 'ipv6 mpls-vpn'), + (2, 133, 'ipv6 flow'), + (2, 134, 'ipv6 flow-vpn'), + (25, 65, 'l2vpn vpls'), + ) + ], + 2: ['neighbor 127.0.0.1 update end',] * 20, + 3: ['',] * 20, } count = 0 while True: - line = sys.stdin.readline().strip() - #print >> sys.stderr, '[%s]' % line.replace('\n','\\n'), start, end + line = sys.stdin.readline().strip() + # print >> sys.stderr, '[%s]' % line.replace('\n','\\n'), start, end - options = match[count % 4] + options = match[count % 4] - if line in options: - sys.stderr.write('%-3d ok %s\n' % (count,line)) - sys.stderr.flush() - count += 1 - continue + if line in options: + sys.stderr.write('%-3d ok %s\n' % (count, line)) + sys.stderr.flush() + count += 1 + continue - sys.stderr.write('%-3d failed %s\n' % (count,line)) - # sys.stderr.write("---" + line + "---\n") - # sys.stderr.write("---" + str(options) + "---\n") - sys.stderr.flush() - count += 1 + sys.stderr.write('%-3d failed %s\n' % (count, line)) + # sys.stderr.write("---" + line + "---\n") + # sys.stderr.write("---" + str(options) + "---\n") + sys.stderr.flush() + count += 1 diff --git a/qa/self/attribute/api-internet.py b/qa/self/attribute/api-internet.py index 66e5b10ed..f7827d16f 100755 --- a/qa/self/attribute/api-internet.py +++ b/qa/self/attribute/api-internet.py @@ -3,23 +3,28 @@ import sys import time -def write (data): - sys.stdout.write(data + '\n') - sys.stdout.flush() -def main (): - msg = 'announce attribute next-hop 1.2.3.4 med 100 as-path [ 100 101 102 103 104 105 106 107 108 109 110 ] nlri %s' - write(msg % ' '.join('%d.0.0.0/8' % ip for ip in range(0,224))) - write(msg % ' '.join('10.%d.0.0/16' % ip for ip in range(0,256))) +def write(data): + sys.stdout.write(data + '\n') + sys.stdout.flush() - time.sleep(2) - write('withdraw attribute next-hop 1.2.3.4 med 100 as-path [ 100 101 102 103 104 105 106 107 108 109 110 ] nlri 0.0.0.0/8 1.0.0.0/8') +def main(): + msg = 'announce attribute next-hop 1.2.3.4 med 100 as-path [ 100 101 102 103 104 105 106 107 108 109 110 ] nlri %s' + write(msg % ' '.join('%d.0.0.0/8' % ip for ip in range(0, 224))) + write(msg % ' '.join('10.%d.0.0/16' % ip for ip in range(0, 256))) + + time.sleep(2) + + write( + 'withdraw attribute next-hop 1.2.3.4 med 100 as-path [ 100 101 102 103 104 105 106 107 108 109 110 ] nlri 0.0.0.0/8 1.0.0.0/8' + ) + + time.sleep(10000) - time.sleep(10000) if __name__ == '__main__': - try: - main() - except KeyboardInterrupt: - pass + try: + main() + except KeyboardInterrupt: + pass diff --git a/qa/self/big/api-internet.py b/qa/self/big/api-internet.py index e6d93f7a8..d9f2bf7c9 100755 --- a/qa/self/big/api-internet.py +++ b/qa/self/big/api-internet.py @@ -4,37 +4,40 @@ import time import random -def write (data): - sys.stdout.write(data + '\n') - sys.stdout.flush() -def main (): - count = 0 +def write(data): + sys.stdout.write(data + '\n') + sys.stdout.flush() - ip = {} - nexthop="1.2.3.4" - for ip1 in range(0,223): - generated = '%d.0.0.0/8' % (ip1) - ip[generated] = nexthop +def main(): + count = 0 - for ip1 in range(0,223): - for ip2 in range(0,256): - generated = '%d.%d.0.0/16' % (ip1,ip2) - ip[generated] = nexthop + ip = {} + nexthop = "1.2.3.4" - # initial table dump - for k,v in ip.iteritems(): - count += 1 - write('announce route %s next-hop %s med 100 as-path [ 100 101 102 103 104 105 106 107 108 109 110 ]' % (k,v)) - if count % 100 == 0: - sys.stderr.write('initial : announced %d\n' % count) + for ip1 in range(0, 223): + generated = '%d.0.0.0/8' % (ip1) + ip[generated] = nexthop + + for ip1 in range(0, 223): + for ip2 in range(0, 256): + generated = '%d.%d.0.0/16' % (ip1, ip2) + ip[generated] = nexthop + + # initial table dump + for k, v in ip.iteritems(): + count += 1 + write('announce route %s next-hop %s med 100 as-path [ 100 101 102 103 104 105 106 107 108 109 110 ]' % (k, v)) + if count % 100 == 0: + sys.stderr.write('initial : announced %d\n' % count) + + count &= 0xFFFFFFFE + time.sleep(10000) - count &= 0xFFFFFFFe - time.sleep(10000) if __name__ == '__main__': - try: - main() - except KeyboardInterrupt: - pass + try: + main() + except KeyboardInterrupt: + pass diff --git a/qa/self/big/dump-all.py b/qa/self/big/dump-all.py index 12f157401..55c759fec 100755 --- a/qa/self/big/dump-all.py +++ b/qa/self/big/dump-all.py @@ -5,6 +5,6 @@ count = 0 while True: - line = sys.stdin.readline() - sys.stderr.write(line) - sys.stderr.flush() + line = sys.stdin.readline() + sys.stderr.write(line) + sys.stderr.flush() diff --git a/qa/self/big/dump-number.py b/qa/self/big/dump-number.py index 280c1a0b3..1a9de2164 100755 --- a/qa/self/big/dump-number.py +++ b/qa/self/big/dump-number.py @@ -5,9 +5,9 @@ count = 0 while True: - line = sys.stdin.readline() - if ' route' in line: - count += 1 - if count % 100 == 0: - sys.stderr.write('received %-10d\n' % count) - sys.stderr.flush() + line = sys.stdin.readline() + if ' route' in line: + count += 1 + if count % 100 == 0: + sys.stderr.write('received %-10d\n' % count) + sys.stderr.flush() diff --git a/qa/self/big/dump-to-screen.py b/qa/self/big/dump-to-screen.py index 280c1a0b3..1a9de2164 100755 --- a/qa/self/big/dump-to-screen.py +++ b/qa/self/big/dump-to-screen.py @@ -5,9 +5,9 @@ count = 0 while True: - line = sys.stdin.readline() - if ' route' in line: - count += 1 - if count % 100 == 0: - sys.stderr.write('received %-10d\n' % count) - sys.stderr.flush() + line = sys.stdin.readline() + if ' route' in line: + count += 1 + if count % 100 == 0: + sys.stderr.write('received %-10d\n' % count) + sys.stderr.flush() diff --git a/qa/self/flow/flow-change.py b/qa/self/flow/flow-change.py index dc33a8193..846ed2e26 100755 --- a/qa/self/flow/flow-change.py +++ b/qa/self/flow/flow-change.py @@ -5,7 +5,7 @@ import sys import time -flow="flow route { match { source 10.0.0.1/32; destination 10.0.0.2/32; destination-port =3128; protocol tcp; } then { discard; } }" +flow = "flow route { match { source 10.0.0.1/32; destination 10.0.0.2/32; destination-port =3128; protocol tcp; } then { discard; } }" # When the parent dies we are seeing continual newlines, so we only access so many before stopping counter = 1 @@ -15,17 +15,17 @@ time.sleep(1) while True: - try: - time.sleep(1) - if counter % 2: - print('announce', flow) - sys.stdout.flush() - else: - print('withdraw', flow) - sys.stdout.flush() + try: + time.sleep(1) + if counter % 2: + print('announce', flow) + sys.stdout.flush() + else: + print('withdraw', flow) + sys.stdout.flush() - counter += 1 - except KeyboardInterrupt: - pass - except IOError: - break + counter += 1 + except KeyboardInterrupt: + pass + except IOError: + break diff --git a/qa/self/flow/log-syslog.py b/qa/self/flow/log-syslog.py index 94f6e9c0e..fd3dc8882 100755 --- a/qa/self/flow/log-syslog.py +++ b/qa/self/flow/log-syslog.py @@ -5,9 +5,11 @@ import time import syslog -def _prefixed (level, message): - now = time.strftime('%a, %d %b %Y %H:%M:%S',time.localtime()) - return "%s %-8s %-6d %s" % (now,level,os.getpid(),message) + +def _prefixed(level, message): + now = time.strftime('%a, %d %b %Y %H:%M:%S', time.localtime()) + return "%s %-8s %-6d %s" % (now, level, os.getpid(), message) + syslog.openlog("ExaBGP") @@ -15,20 +17,20 @@ def _prefixed (level, message): counter = 0 while True: - try: - line = sys.stdin.readline().strip() - if line == "": - counter += 1 - if counter > 100: - break - continue - - counter = 0 - - print >> sys.stderr, line - syslog.syslog(syslog.LOG_ALERT, _prefixed('INFO',line)) - except KeyboardInterrupt: - pass - except IOError: - # most likely a signal during readline - pass + try: + line = sys.stdin.readline().strip() + if line == "": + counter += 1 + if counter > 100: + break + continue + + counter = 0 + + print >>sys.stderr, line + syslog.syslog(syslog.LOG_ALERT, _prefixed('INFO', line)) + except KeyboardInterrupt: + pass + except IOError: + # most likely a signal during readline + pass diff --git a/qa/self/json/receive.py b/qa/self/json/receive.py index cc75bce62..34b699ba7 100755 --- a/qa/self/json/receive.py +++ b/qa/self/json/receive.py @@ -7,18 +7,17 @@ exit = False while True: - line = sys.stdin.readline().strip() + line = sys.stdin.readline().strip() - if not line: - if exit: - sys.exit(0) - exit = True - else: - exit = False - + if not line: + if exit: + sys.exit(0) + exit = True + else: + exit = False - print >> sys.stderr, '\n=====\n' - print >> sys.stderr, line - print >> sys.stderr, '\n---\n' - print >> sys.stderr, pprint.pformat(json.loads(line),indent=3).replace("u'","'") - sys.stderr.flush() + print >>sys.stderr, '\n=====\n' + print >>sys.stderr, line + print >>sys.stderr, '\n---\n' + print >>sys.stderr, pprint.pformat(json.loads(line), indent=3).replace("u'", "'") + sys.stderr.flush() diff --git a/qa/self/load/api-internet.py b/qa/self/load/api-internet.py index 99fd302e2..d756fd79d 100755 --- a/qa/self/load/api-internet.py +++ b/qa/self/load/api-internet.py @@ -5,82 +5,96 @@ import time import random -def write (data): - sys.stdout.write(data + '\n') - sys.stdout.flush() -def main (): - if len(sys.argv) < 2: - print("%s ") - sys.exit(1) +def write(data): + sys.stdout.write(data + '\n') + sys.stdout.flush() + + +def main(): + if len(sys.argv) < 2: + print("%s ") + sys.exit(1) + + initial = sys.argv[1] + thereafter = sys.argv[2] + + if not initial.isdigit() or not thereafter.isdigit(): + write('please give valid numbers') + sys.exit(1) + + # Limit to sane numbers :-) + number = int(initial) & 0x00FFFFFF + after = int(thereafter) & 0x0000FFFF + + range1 = (number >> 16) & 0xFF + range2 = (number >> 8) & 0xFF + range3 = (number) & 0xFF + + ip = {} + nexthop = [ + '%d.%d.%d.%d' % (random.randint(1, 200), random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) + for _ in range(200) + ] + + for ip1 in range(0, range1): + for ip2 in range(0, 256): + for ip3 in range(0, 256): + generated = '%d.%d.%d.%d' % (random.randint(1, 200), ip1, ip2, ip3) + ip[generated] = random.choice(nexthop) + + for ip2 in range(0, range2): + for ip3 in range(0, 256): + generated = '%d.%d.%d.%d' % (random.randint(1, 200), range1, ip2, ip3) + ip[generated] = random.choice(nexthop) + + for ip3 in range(0, range3): + generated = '%d.%d.%d.%d' % (random.randint(1, 200), range1, range2, ip3) + ip[generated] = random.choice(nexthop) + + count = 0 + + # initial table dump + for k, v in ip.iteritems(): + count += 1 + write( + 'announce route %s next-hop %s med 1%02d as-path [ 100 101 102 103 104 105 106 107 108 109 110 ]' + % (k, v, len(k)) + ) + if count % 10000 == 0: + sys.stderr.write('initial : announced %d\n' % count) + + count &= 0xFFFFFFFE + + # modify routes forever + while True: + now = time.time() + changed = {} + + for k, v in ip.iteritems(): + changed[k] = v + if not random.randint(0, after): + break + + for k, v in changed.iteritems(): + count += 2 + write( + 'withdraw route %s next-hop %s med 1%02d as-path [ 100 101 102 103 104 105 106 107 108 109 110 ]' + % (k, v, len(k)) + ) + ip[k] = random.choice(nexthop) + write( + 'announce route %s next-hop %s med 1%02d as-path [ 100 101 102 103 104 105 106 107 108 109 110 ]' + % (k, ip[k], len(k)) + ) + if count % 100 == 0: + sys.stderr.write('updates : announced %d\n' % count) + + time.sleep(time.time() - now + 1.0) - initial = sys.argv[1] - thereafter = sys.argv[2] - - if not initial.isdigit() or not thereafter.isdigit(): - write('please give valid numbers') - sys.exit(1) - - # Limit to sane numbers :-) - number = int(initial) & 0x00FFFFFF - after = int(thereafter) & 0x0000FFFF - - range1 = (number >> 16) & 0xFF - range2 = (number >> 8) & 0xFF - range3 = (number ) & 0xFF - - ip = {} - nexthop = ['%d.%d.%d.%d' % (random.randint(1,200),random.randint(0,255),random.randint(0,255),random.randint(0,255)) for _ in range(200)] - - for ip1 in range(0,range1): - for ip2 in range(0,256): - for ip3 in range(0,256): - generated = '%d.%d.%d.%d' % (random.randint(1,200),ip1,ip2,ip3) - ip[generated] = random.choice(nexthop) - - for ip2 in range (0,range2): - for ip3 in range (0,256): - generated = '%d.%d.%d.%d' % (random.randint(1,200),range1,ip2,ip3) - ip[generated] = random.choice(nexthop) - - for ip3 in range (0,range3): - generated = '%d.%d.%d.%d' % (random.randint(1,200),range1,range2,ip3) - ip[generated] = random.choice(nexthop) - - count = 0 - - # initial table dump - for k,v in ip.iteritems(): - count += 1 - write('announce route %s next-hop %s med 1%02d as-path [ 100 101 102 103 104 105 106 107 108 109 110 ]' % (k,v,len(k))) - if count % 10000 == 0: - sys.stderr.write('initial : announced %d\n' % count) - - count &= 0xFFFFFFFe - - # modify routes forever - while True: - now = time.time() - changed = {} - - for k,v in ip.iteritems(): - changed[k] = v - if not random.randint(0,after): - break - - for k,v in changed.iteritems(): - count += 2 - write('withdraw route %s next-hop %s med 1%02d as-path [ 100 101 102 103 104 105 106 107 108 109 110 ]' % (k,v,len(k))) - ip[k] = random.choice(nexthop) - write('announce route %s next-hop %s med 1%02d as-path [ 100 101 102 103 104 105 106 107 108 109 110 ]' % (k,ip[k],len(k))) - if count % 100 == 0: - sys.stderr.write('updates : announced %d\n' % count) - - - time.sleep(time.time()-now+1.0) if __name__ == '__main__': - try: - main() - except KeyboardInterrupt: - pass + try: + main() + except KeyboardInterrupt: + pass diff --git a/qa/self/load/dump-all.py b/qa/self/load/dump-all.py index 12f157401..55c759fec 100755 --- a/qa/self/load/dump-all.py +++ b/qa/self/load/dump-all.py @@ -5,6 +5,6 @@ count = 0 while True: - line = sys.stdin.readline() - sys.stderr.write(line) - sys.stderr.flush() + line = sys.stdin.readline() + sys.stderr.write(line) + sys.stderr.flush() diff --git a/qa/self/load/dump-number.py b/qa/self/load/dump-number.py index 280c1a0b3..1a9de2164 100755 --- a/qa/self/load/dump-number.py +++ b/qa/self/load/dump-number.py @@ -5,9 +5,9 @@ count = 0 while True: - line = sys.stdin.readline() - if ' route' in line: - count += 1 - if count % 100 == 0: - sys.stderr.write('received %-10d\n' % count) - sys.stderr.flush() + line = sys.stdin.readline() + if ' route' in line: + count += 1 + if count % 100 == 0: + sys.stderr.write('received %-10d\n' % count) + sys.stderr.flush() diff --git a/qa/self/load/dump-to-screen.py b/qa/self/load/dump-to-screen.py index 280c1a0b3..1a9de2164 100755 --- a/qa/self/load/dump-to-screen.py +++ b/qa/self/load/dump-to-screen.py @@ -5,9 +5,9 @@ count = 0 while True: - line = sys.stdin.readline() - if ' route' in line: - count += 1 - if count % 100 == 0: - sys.stderr.write('received %-10d\n' % count) - sys.stderr.flush() + line = sys.stdin.readline() + if ' route' in line: + count += 1 + if count % 100 == 0: + sys.stderr.write('received %-10d\n' % count) + sys.stderr.flush() diff --git a/qa/self/operational/operational-print.py b/qa/self/operational/operational-print.py index 8c15c32c6..925f52f59 100755 --- a/qa/self/operational/operational-print.py +++ b/qa/self/operational/operational-print.py @@ -8,21 +8,21 @@ counter = 0 while True: - try: - line = sys.stdin.readline().strip() - if line == "": - counter += 1 - if counter > 100: - break - continue + try: + line = sys.stdin.readline().strip() + if line == "": + counter += 1 + if counter > 100: + break + continue - counter = 0 + counter = 0 - send = '\n%s %s %s\n' % ( '-'*10, line, '-'*10 ) - print >> sys.stderr, send - sys.stderr.flush() - except KeyboardInterrupt: - pass - except IOError: - # most likely a signal during readline - pass + send = '\n%s %s %s\n' % ('-' * 10, line, '-' * 10) + print >>sys.stderr, send + sys.stderr.flush() + except KeyboardInterrupt: + pass + except IOError: + # most likely a signal during readline + pass diff --git a/qa/self/operational/operational-send.py b/qa/self/operational/operational-send.py index 845a174ff..eab66205f 100755 --- a/qa/self/operational/operational-send.py +++ b/qa/self/operational/operational-send.py @@ -29,17 +29,17 @@ time.sleep(1) while True: - try: - time.sleep(1) - if counter % 2: - print('announce operational adm afi ipv4 safi unicast advisory "this is dynamic message #%d"' % counter) - sys.stdout.flush() - else: - print('announce operational asm afi ipv4 safi unicast advisory "we SHOULD not send asm from the API"') - sys.stdout.flush() - - counter += 1 - except KeyboardInterrupt: - pass - except IOError: - break + try: + time.sleep(1) + if counter % 2: + print('announce operational adm afi ipv4 safi unicast advisory "this is dynamic message #%d"' % counter) + sys.stdout.flush() + else: + print('announce operational asm afi ipv4 safi unicast advisory "we SHOULD not send asm from the API"') + sys.stdout.flush() + + counter += 1 + except KeyboardInterrupt: + pass + except IOError: + break diff --git a/qa/self/refresh/re-ask.py b/qa/self/refresh/re-ask.py index 2a6696a18..55594adba 100755 --- a/qa/self/refresh/re-ask.py +++ b/qa/self/refresh/re-ask.py @@ -4,23 +4,27 @@ import sys import signal -class TimeError (Exception): pass -def handler (signum, frame): - raise TimeError() +class TimeError(Exception): + pass + + +def handler(signum, frame): + raise TimeError() + count = 0 while True: - try: - signal.signal(signal.SIGALRM, handler) - signal.alarm(4) - - line = sys.stdin.readline() - sys.stderr.write('received %s\n' % line.strip()) - sys.stderr.flush() - except TimeError: - print('announce route-refresh ipv4 unicast') - sys.stdout.flush() - print('announce route-refresh ipv4 unicast', file=sys.stderr) - sys.stderr.flush() + try: + signal.signal(signal.SIGALRM, handler) + signal.alarm(4) + + line = sys.stdin.readline() + sys.stderr.write('received %s\n' % line.strip()) + sys.stderr.flush() + except TimeError: + print('announce route-refresh ipv4 unicast') + sys.stdout.flush() + print('announce route-refresh ipv4 unicast', file=sys.stderr) + sys.stderr.flush() diff --git a/qa/self/simple/log-syslog.py b/qa/self/simple/log-syslog.py index ecbcf98cb..e15212f42 100755 --- a/qa/self/simple/log-syslog.py +++ b/qa/self/simple/log-syslog.py @@ -5,9 +5,11 @@ import time import syslog -def _prefixed (level, message): - now = time.strftime('%a, %d %b %Y %H:%M:%S',time.localtime()) - return "%s %-8s %-6d %s" % (now,level,os.getpid(),message) + +def _prefixed(level, message): + now = time.strftime('%a, %d %b %Y %H:%M:%S', time.localtime()) + return "%s %-8s %-6d %s" % (now, level, os.getpid(), message) + syslog.openlog("ExaBGP") @@ -15,19 +17,19 @@ def _prefixed (level, message): counter = 0 while True: - try: - line = sys.stdin.readline().strip() - if line == "": - counter += 1 - if counter > 100: - break - continue - - counter = 0 - - syslog.syslog(syslog.LOG_ALERT, _prefixed('INFO',line)) - except KeyboardInterrupt: - pass - except IOError: - # most likely a signal during readline - pass + try: + line = sys.stdin.readline().strip() + if line == "": + counter += 1 + if counter > 100: + break + continue + + counter = 0 + + syslog.syslog(syslog.LOG_ALERT, _prefixed('INFO', line)) + except KeyboardInterrupt: + pass + except IOError: + # most likely a signal during readline + pass diff --git a/qa/self/update/update-receive.py b/qa/self/update/update-receive.py index 8c15c32c6..925f52f59 100755 --- a/qa/self/update/update-receive.py +++ b/qa/self/update/update-receive.py @@ -8,21 +8,21 @@ counter = 0 while True: - try: - line = sys.stdin.readline().strip() - if line == "": - counter += 1 - if counter > 100: - break - continue + try: + line = sys.stdin.readline().strip() + if line == "": + counter += 1 + if counter > 100: + break + continue - counter = 0 + counter = 0 - send = '\n%s %s %s\n' % ( '-'*10, line, '-'*10 ) - print >> sys.stderr, send - sys.stderr.flush() - except KeyboardInterrupt: - pass - except IOError: - # most likely a signal during readline - pass + send = '\n%s %s %s\n' % ('-' * 10, line, '-' * 10) + print >>sys.stderr, send + sys.stderr.flush() + except KeyboardInterrupt: + pass + except IOError: + # most likely a signal during readline + pass diff --git a/qa/self/update/update-send.py b/qa/self/update/update-send.py index 86ea8fb7b..d7e14a952 100755 --- a/qa/self/update/update-send.py +++ b/qa/self/update/update-send.py @@ -14,22 +14,22 @@ while True: - try: - if counter % 2: - print('announce route 10.0.%d.%d next-hop 1.2.3.4' % (counter >> 8, counter %256)) - sys.stdout.flush() - time.sleep(1) - print('withdraw route 10.0.%d.%d next-hop 1.2.3.4' % (counter >> 8, counter %256)) - sys.stdout.flush() - else: - print('announce route 2001:%d:: next-hop ::1' % counter) - sys.stdout.flush() - time.sleep(1) - print('withdraw route 2001:%d:: next-hop ::1' % counter) - sys.stdout.flush() + try: + if counter % 2: + print('announce route 10.0.%d.%d next-hop 1.2.3.4' % (counter >> 8, counter % 256)) + sys.stdout.flush() + time.sleep(1) + print('withdraw route 10.0.%d.%d next-hop 1.2.3.4' % (counter >> 8, counter % 256)) + sys.stdout.flush() + else: + print('announce route 2001:%d:: next-hop ::1' % counter) + sys.stdout.flush() + time.sleep(1) + print('withdraw route 2001:%d:: next-hop ::1' % counter) + sys.stdout.flush() - counter += 1 - except KeyboardInterrupt: - pass - except IOError: - break + counter += 1 + except KeyboardInterrupt: + pass + except IOError: + break diff --git a/qa/tests/bgpls_test.py b/qa/tests/bgpls_test.py index a44b7b35a..b4149a736 100644 --- a/qa/tests/bgpls_test.py +++ b/qa/tests/bgpls_test.py @@ -8,7 +8,6 @@ class TestTlvs(unittest.TestCase): - def test_ip_reach_ipv4(self,): data = b'\n\n\x00' @@ -18,7 +17,9 @@ def test_ip_reach_ipv4(self,): def test_ip_reach_ipv6(self,): data = b'\x7f \x01\x07\x00\x00\x00\x80' tlv = IpReach.unpack(data, 4) - self.assertEqual(tlv.json(), '"ip-reachability-tlv": "2001:700:0:8000::", "ip-reach-prefix": "2001:700:0:8000::/127"') + self.assertEqual( + tlv.json(), '"ip-reachability-tlv": "2001:700:0:8000::", "ip-reach-prefix": "2001:700:0:8000::/127"' + ) def test_igp_tags(self,): data = b'\x00\x00\xff\xfe' @@ -37,7 +38,6 @@ def test_ospf_route_type(self,): class TestDescriptors(unittest.TestCase): - def test_node_descriptor(self,): data = b'\x02\x00\x00\x04\x00\x00\xff\xfd\x02\x01\x00\x04\x00\x00\x00\x00\x02\x03\x00\x04\nq?\xf0' igp_type = 3 diff --git a/qa/tests/cache_test.py b/qa/tests/cache_test.py index d67027413..3a8dc943e 100755 --- a/qa/tests/cache_test.py +++ b/qa/tests/cache_test.py @@ -17,114 +17,114 @@ from exabgp.vendoring.six.moves import xrange -class TestCache (unittest.TestCase): - def test_speed (self): - class klass1: - def __init__ (self, data): - pass - - class klass2 (object): - def __init__ (self, data): - pass - - class klass3: - def __init__ (self, data): - self.a = data[0] - self.b = data[1] - self.c = data[2] - self.d = data[3] - self.e = data[4] - - class klass4: - def __init__ (self, data): - self.a = data[0] - self.b = data[1] - self.c = data[2] - self.d = data[3] - self.e = data[4] - - class _kparent1: - def __init__ (self, data): - self.a = data[0] - self.b = data[1] - - class _kparent2 (object): - def __init__ (self, data): - self.a = data[0] - self.b = data[1] - - class klass5 (_kparent1): - def __init__ (self, data): - _kparent1.__init__(self,data) - self.c = data[2] - self.d = data[3] - self.e = data[4] - - class klass6 (_kparent2): - def __init__ (self, data): - _kparent2.__init__(self,data) - self.c = data[2] - self.d = data[3] - self.e = data[4] - - class klass7 (klass6): - pass - - class klass8 (klass6): - def __init__ (self, data): - klass6.__init__(self,data) - self.s = self.a + self.b + self.c + self.d + self.e - - class klass9 (klass6): - def __init__ (self, data): - klass6.__init__(self,data) - self.s1 = self.a + self.b + self.c + self.d + self.e - self.s2 = self.b + self.c + self.d + self.e - self.s3 = self.c + self.d + self.e - self.s4 = self.d + self.e - self.s5 = self.a + self.b + self.c + self.d - self.s6 = self.a + self.b + self.c - self.s7 = self.a + self.b - - COUNT = 100000 - UNIQUE = 5000 - - samples = set() - chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:"|;<>?,./[]{}-=_+!@£$%^&*()' - - from random import choice - - while len(samples) != UNIQUE: - samples.add(choice(chars)+choice(chars)+choice(chars)+choice(chars)+choice(chars)) - - samples = list(samples) - - for klass in [klass1,klass2,klass3,klass4,klass5,klass6,klass7,klass8,klass9]: - cache = {} - - start = time.time() - for val in xrange(COUNT): - val %= UNIQUE - _ = klass(samples[val]) - end = time.time() - time1 = end-start - - print(COUNT,'iterations of',klass.__name__,'with',UNIQUE,'uniques classes') - print("time instance %d" % time1) - - cache = Cache() - start = time.time() - for val in xrange(COUNT): - val %= UNIQUE - - if val in cache: - _ = cache.retrieve(val) - else: - _ = cache.cache(val, klass(samples[val])) - - end = time.time() - time2 = end-start - - print("time cached %d" % time2) - print("speedup %.3f" % (time1/time2)) - print() +class TestCache(unittest.TestCase): + def test_speed(self): + class klass1: + def __init__(self, data): + pass + + class klass2(object): + def __init__(self, data): + pass + + class klass3: + def __init__(self, data): + self.a = data[0] + self.b = data[1] + self.c = data[2] + self.d = data[3] + self.e = data[4] + + class klass4: + def __init__(self, data): + self.a = data[0] + self.b = data[1] + self.c = data[2] + self.d = data[3] + self.e = data[4] + + class _kparent1: + def __init__(self, data): + self.a = data[0] + self.b = data[1] + + class _kparent2(object): + def __init__(self, data): + self.a = data[0] + self.b = data[1] + + class klass5(_kparent1): + def __init__(self, data): + _kparent1.__init__(self, data) + self.c = data[2] + self.d = data[3] + self.e = data[4] + + class klass6(_kparent2): + def __init__(self, data): + _kparent2.__init__(self, data) + self.c = data[2] + self.d = data[3] + self.e = data[4] + + class klass7(klass6): + pass + + class klass8(klass6): + def __init__(self, data): + klass6.__init__(self, data) + self.s = self.a + self.b + self.c + self.d + self.e + + class klass9(klass6): + def __init__(self, data): + klass6.__init__(self, data) + self.s1 = self.a + self.b + self.c + self.d + self.e + self.s2 = self.b + self.c + self.d + self.e + self.s3 = self.c + self.d + self.e + self.s4 = self.d + self.e + self.s5 = self.a + self.b + self.c + self.d + self.s6 = self.a + self.b + self.c + self.s7 = self.a + self.b + + COUNT = 100000 + UNIQUE = 5000 + + samples = set() + chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:"|;<>?,./[]{}-=_+!@£$%^&*()' + + from random import choice + + while len(samples) != UNIQUE: + samples.add(choice(chars) + choice(chars) + choice(chars) + choice(chars) + choice(chars)) + + samples = list(samples) + + for klass in [klass1, klass2, klass3, klass4, klass5, klass6, klass7, klass8, klass9]: + cache = {} + + start = time.time() + for val in xrange(COUNT): + val %= UNIQUE + _ = klass(samples[val]) + end = time.time() + time1 = end - start + + print(COUNT, 'iterations of', klass.__name__, 'with', UNIQUE, 'uniques classes') + print("time instance %d" % time1) + + cache = Cache() + start = time.time() + for val in xrange(COUNT): + val %= UNIQUE + + if val in cache: + _ = cache.retrieve(val) + else: + _ = cache.cache(val, klass(samples[val])) + + end = time.time() + time2 = end - start + + print("time cached %d" % time2) + print("speedup %.3f" % (time1 / time2)) + print() diff --git a/qa/tests/connection.py b/qa/tests/connection.py index 5bebaf3f0..1586daf57 100755 --- a/qa/tests/connection.py +++ b/qa/tests/connection.py @@ -17,55 +17,62 @@ from exabgp.util.od import od from exabgp.vendoring import six -def test (): - OPEN = ''.join([chr(int(_,16)) for _ in "FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 00 1D 01 04 78 14 00 5A 52 DB 00 45 00".split()]) - KEEP = ''.join([chr(int(_,16)) for _ in "FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 00 00 04".split()]) - from exabgp.reactor.network.outgoing import Outgoing - connection = Outgoing(1,'82.219.0.69','82.219.212.34') - writer = connection.writer(OPEN) - while six.next(writer) is False: - pass - writer = connection.writer(KEEP) - while six.next(writer) is False: - pass +def test(): + OPEN = ''.join( + [ + chr(int(_, 16)) + for _ in "FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 00 1D 01 04 78 14 00 5A 52 DB 00 45 00".split() + ] + ) + KEEP = ''.join([chr(int(_, 16)) for _ in "FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 00 00 04".split()]) - reader = connection.reader() + from exabgp.reactor.network.outgoing import Outgoing - for size,msg,header,body,notification in reader: - if size: - print(od(header+body)) - else: - sys.stdout.write('-') + connection = Outgoing(1, '82.219.0.69', '82.219.212.34') + writer = connection.writer(OPEN) + while six.next(writer) is False: + pass + writer = connection.writer(KEEP) + while six.next(writer) is False: + pass - reader = connection.reader() + reader = connection.reader() - for size,msg,header,body,notification in reader: - if size: - print(od(header+body)) - else: - sys.stdout.write('+') + for size, msg, header, body, notification in reader: + if size: + print(od(header + body)) + else: + sys.stdout.write('-') - connection.close() + reader = connection.reader() + for size, msg, header, body, notification in reader: + if size: + print(od(header + body)) + else: + sys.stdout.write('+') -class TestData (unittest.TestCase): + connection.close() - def test_1 (self): - # if not os.environ.get('profile',False): - # result = test() - # if result: - # self.fail(result) - pass - def test_2 (self): - # if not not os.environ.get('profile',False): - # cProfile.run('test()') - pass +class TestData(unittest.TestCase): + def test_1(self): + # if not os.environ.get('profile',False): + # result = test() + # if result: + # self.fail(result) + pass + + def test_2(self): + # if not not os.environ.get('profile',False): + # cProfile.run('test()') + pass + if __name__ == '__main__': - unittest.main() + unittest.main() - # import cProfile - # print 'profiling' - # cProfile.run('unittest.main()','profile.info') + # import cProfile + # print 'profiling' + # cProfile.run('unittest.main()','profile.info') diff --git a/qa/tests/control_test.py b/qa/tests/control_test.py index 49f38aa7b..2c6ecc01e 100755 --- a/qa/tests/control_test.py +++ b/qa/tests/control_test.py @@ -14,64 +14,66 @@ from exabgp.configuration.setup import environment + environment.setup('') -def speak (name, data): - time.sleep(0.005) - try: - sock = socket.socket(socket.AF_UNIX,socket.SOCK_STREAM) - sock.connect(name) - sock.sendall(data) - except socket.error: - pass - - -class TestControl (unittest.TestCase): - def setUp (self): - pass - - def test_failed_creation (self): - pass - # control = Control() - # try: - # result = control.init() - # self.assertFalse(result) - # except IOError: - # # could not write in the location - # pass - # finally: - # control.cleanup() - - def validate (self, message, check): - pass - # name = tempfile.mktemp() - # control = Control(name,False) - # try: - # result = control.init() - # self.assertTrue(result) - # - # p = Process(target=speak, args=(name,message)) - # p.start() - # - # string = control.loop() - # self.assertEqual(string, check) - # p.join() - # finally: - # control.cleanup() - # del control - - def test_no_newline (self): - self.validate('x','') - - def test_one_newline (self): - self.validate('x\n','x') - - def test_two_newline (self): - self.validate('-\nx\n','x') - - def test_leftover (self): - self.validate('-\nx\n-','x') +def speak(name, data): + time.sleep(0.005) + try: + sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + sock.connect(name) + sock.sendall(data) + except socket.error: + pass + + +class TestControl(unittest.TestCase): + def setUp(self): + pass + + def test_failed_creation(self): + pass + # control = Control() + # try: + # result = control.init() + # self.assertFalse(result) + # except IOError: + # # could not write in the location + # pass + # finally: + # control.cleanup() + + def validate(self, message, check): + pass + # name = tempfile.mktemp() + # control = Control(name,False) + # try: + # result = control.init() + # self.assertTrue(result) + # + # p = Process(target=speak, args=(name,message)) + # p.start() + # + # string = control.loop() + # self.assertEqual(string, check) + # p.join() + # finally: + # control.cleanup() + # del control + + def test_no_newline(self): + self.validate('x', '') + + def test_one_newline(self): + self.validate('x\n', 'x') + + def test_two_newline(self): + self.validate('-\nx\n', 'x') + + def test_leftover(self): + self.validate('-\nx\n-', 'x') + if __name__ == '__main__': - unittest.main() + unittest.main() diff --git a/qa/tests/datatype.py b/qa/tests/datatype.py index ec5c4eb85..ca4d87e51 100755 --- a/qa/tests/datatype.py +++ b/qa/tests/datatype.py @@ -11,62 +11,65 @@ import unittest from exabgp.configuration.environment import environment + environment.setup('') # from exabgp.protocol.family import AFI # from exabgp.protocol.family import SAFI -class TestData (unittest.TestCase): - def setUp (self): - pass - # def test_1_nlri_1 (self): - # self.assertEqual(''.join([chr(c) for c in [32,1,2,3,4]]),to_NLRI('1.2.3.4','32').pack()) - # def test_1_nlri_2 (self): - # self.assertEqual(''.join([chr(c) for c in [24,1,2,3]]),to_NLRI('1.2.3.4','24').pack()) - # def test_1_nlri_3 (self): - # self.assertEqual(''.join([chr(c) for c in [20,1,2,3]]),to_NLRI('1.2.3.4','20').pack()) - # - # def test_2_ip_2 (self): - # self.assertEqual(str(InetIP('::ffff:192.168.1.26')),'::ffff:192.168.1.26/128') - # self.assertEqual(str(InetIP('::ffff:192.168.1.26').ip),'::ffff:192.168.1.26') - # - # def test_3_ipv6_1 (self): - # default = InetIP('::') - # self.assertEqual(str(default),'::/128') - # self.assertEqual(default.ip,'::') - # self.assertEqual(default.packedip(),'\0'*16) - # - # def test_3_ipv6_2 (self): - # default = InetIP('1234:5678::') - # self.assertEqual(str(default),'1234:5678::/128') - # self.assertEqual(default.ip,'1234:5678::') - # self.assertEqual(default.packedip(),'\x12\x34\x56\x78'+'\0'*12) - # - # def test_3_ipv6_3 (self): - # default = InetIP('1234:5678::1') - # self.assertEqual(str(default),'1234:5678::1/128') - # self.assertEqual(default.ip,'1234:5678::1') - # self.assertEqual(default.packedip(),'\x12\x34\x56\x78'+'\0'*11 + '\x01') - # - # def test_xxx (self): - # ip = "192.0.2.0" - # net = chr (192) + chr(0) + chr(2) +chr(0) - # bnt = chr(24) + chr (192) + chr(0) + chr(2) - # - # pfx = Prefix(AFI.ipv4,ip,24) - # bgp = BGPNLRI(AFI.ipv4,bnt) - # - # self.assertEqual(str(pfx),"%s/24" % ip) - # self.assertEqual(str(afi),"%s/24" % ip) - # self.assertEqual(str(bgp),"%s/24" % ip) - # - # self.assertEqual(pfx.pack(),bnt) - # self.assertEqual(afi.pack(),bnt) - # self.assertEqual(bgp.pack(),bnt) - # - # # README: NEED To add ASN test - # # README: NEED To add NLRI test +class TestData(unittest.TestCase): + def setUp(self): + pass + + # def test_1_nlri_1 (self): + # self.assertEqual(''.join([chr(c) for c in [32,1,2,3,4]]),to_NLRI('1.2.3.4','32').pack()) + # def test_1_nlri_2 (self): + # self.assertEqual(''.join([chr(c) for c in [24,1,2,3]]),to_NLRI('1.2.3.4','24').pack()) + # def test_1_nlri_3 (self): + # self.assertEqual(''.join([chr(c) for c in [20,1,2,3]]),to_NLRI('1.2.3.4','20').pack()) + # + # def test_2_ip_2 (self): + # self.assertEqual(str(InetIP('::ffff:192.168.1.26')),'::ffff:192.168.1.26/128') + # self.assertEqual(str(InetIP('::ffff:192.168.1.26').ip),'::ffff:192.168.1.26') + # + # def test_3_ipv6_1 (self): + # default = InetIP('::') + # self.assertEqual(str(default),'::/128') + # self.assertEqual(default.ip,'::') + # self.assertEqual(default.packedip(),'\0'*16) + # + # def test_3_ipv6_2 (self): + # default = InetIP('1234:5678::') + # self.assertEqual(str(default),'1234:5678::/128') + # self.assertEqual(default.ip,'1234:5678::') + # self.assertEqual(default.packedip(),'\x12\x34\x56\x78'+'\0'*12) + # + # def test_3_ipv6_3 (self): + # default = InetIP('1234:5678::1') + # self.assertEqual(str(default),'1234:5678::1/128') + # self.assertEqual(default.ip,'1234:5678::1') + # self.assertEqual(default.packedip(),'\x12\x34\x56\x78'+'\0'*11 + '\x01') + # + # def test_xxx (self): + # ip = "192.0.2.0" + # net = chr (192) + chr(0) + chr(2) +chr(0) + # bnt = chr(24) + chr (192) + chr(0) + chr(2) + # + # pfx = Prefix(AFI.ipv4,ip,24) + # bgp = BGPNLRI(AFI.ipv4,bnt) + # + # self.assertEqual(str(pfx),"%s/24" % ip) + # self.assertEqual(str(afi),"%s/24" % ip) + # self.assertEqual(str(bgp),"%s/24" % ip) + # + # self.assertEqual(pfx.pack(),bnt) + # self.assertEqual(afi.pack(),bnt) + # self.assertEqual(bgp.pack(),bnt) + # + # # README: NEED To add ASN test + # # README: NEED To add NLRI test + if __name__ == '__main__': - unittest.main() + unittest.main() diff --git a/qa/tests/decode_test.py b/qa/tests/decode_test.py index 448e858a6..7dcf55aaa 100755 --- a/qa/tests/decode_test.py +++ b/qa/tests/decode_test.py @@ -44,294 +44,296 @@ bodies = [] +# fmt: off body = [ - 0x0, 0x0, # len withdrawn routes - # No routes to remove - # Attributes - 0x0, 0x30, # len attributes (48) - 0x40, # Flag Transitive - 0x1, # Code : Attribute ID Origin - 0x1, # len - 0x0, # Origin : IGP - 0x50, # Flag Transitive + extended length - 0x2, # Code : AS Path - 0x0, 0x16, # len 22 - 0x2, # Type (AS_Sequence) - 0x5, # length (in ASes as every asn is 0x0 0x0 prefixed ASN4 must have been negotiated) - 0x0, 0x0, 0xfe, 0xb0, # ASN 65200 - 0x0, 0x0, 0x78, 0x14, # ASN 30740 - 0x0, 0x0, 0x19, 0x35, # ASN 6453 - 0x0, 0x0, 0xb, 0x62, # ASN 2914 - 0x0, 0x0, 0x9, 0xd7, # ASN 2519 - 0x40, # Flag Transitive - 0x3, # Code: Next HOP - 0x4, # len - 0x7f, 0x0, 0x0, 0x1, # 127.0.0.1 - 0xc0, # 0x40 + 0x80 (Transitive Optional) - 0x08, # Community - 0x8, # Size 8 - 0x78, 0x14, 0x19, 0x35, # 30740:6453 - 0x78, 0x14, 0xfd, 0xeb, # 30740:65003 - # routes : - 0x18, 0x1, 0x0, 0x19, # 1.0.25.0/24 - 0x10, 0xde, 0xe6, # 222.330.0.0/16 - 0x11, 0xde, 0xe5, 0x80, - 0x12, 0xde, 0xe5, 0x0, - 0x10, 0xde, 0xe4, - 0x11, 0xdc, 0xf7, 0x0, - 0x11, 0xdc, 0x9e, 0x0, - 0x18, 0xdb, 0x79, 0xff, - 0x18, 0xdb, 0x79, 0xf9, - 0x16, 0xd8, 0xb3, 0xcc, - 0x18, 0xd8, 0xb3, 0xb6, - 0x17, 0xd8, 0xb3, 0xb4, - 0x16, 0xd8, 0xb3, 0xb0, - 0x18, 0xd8, 0xb3, 0x99, - 0x12, 0xd2, 0xaa, 0x0, - 0x11, 0xd2, 0x92, 0x80, - 0x11, 0xd2, 0x83, 0x80, - 0x13, 0xcb, 0x8c, 0x20, - 0x18, 0xca, 0xf5, 0xfe, - 0x18, 0xca, 0xf5, 0x8e, - 0x18, 0xca, 0xf3, 0xba, - 0x18, 0xca, 0xf0, 0x8d, - 0x12, 0xca, 0xef, 0xc0, - 0x12, 0xca, 0xe7, 0x40, - 0x10, 0xca, 0xd7, - 0x18, 0xca, 0xd2, 0x8, - 0x13, 0xca, 0xbd, 0xc0, - 0x14, 0xca, 0x58, 0x30, - 0x18, 0xca, 0x22, 0xbf, - 0x17, 0xca, 0x22, 0x96, - 0x18, 0xc0, 0x32, 0x6e, - 0x10, 0xb7, 0xb4, - 0x11, 0xb7, 0xb1, 0x80, - 0x10, 0xa3, 0x8b, - 0x11, 0x9d, 0x78, 0x80, - 0x15, 0x7c, 0xf1, 0x78, - 0x10, 0x7c, 0x6e, - 0x10, 0x7a, 0x67, - 0x10, 0x78, 0x33, - 0x10, 0x74, 0x5b, - 0x15, 0x73, 0xbb, 0x48, - 0x16, 0x73, 0xbb, 0x44, - 0x10, 0x73, 0xb3, - 0x11, 0x72, 0x45, 0x0, - 0x14, 0x71, 0x34, 0xf0, - 0x15, 0x70, 0x6d, 0x18, - 0x18, 0x67, 0xf6, 0xb3, - 0x17, 0x67, 0xb, 0x6, - 0x18, 0x67, 0x5, 0x75, - 0x18, 0x67, 0x5, 0x74, - 0x18, 0x67, 0x3, 0x10, - 0x13, 0x65, 0x37, 0xc0, - 0x11, 0x65, 0x32, 0x80, - 0x18, 0x65, 0x0, 0x1f, - 0x18, 0x65, 0x0, 0x1e, - 0x18, 0x65, 0x0, 0x1d, - 0x18, 0x65, 0x0, 0x1c, - 0xf, 0x24, 0x2, - 0x11, 0x1b, 0x79, 0x80, - 0x13, 0x1b, 0x60, 0x20, - 0x15, 0x1b, 0x60, 0x10, - 0x10, 0x1, 0x15, - 0x16, 0x1, 0x0, 0x1c, - 0x17, 0x1, 0x0, 0x1a + 0x0, 0x0, # len withdrawn routes + # No routes to remove + # Attributes + 0x0, 0x30, # len attributes (48) + 0x40, # Flag Transitive + 0x1, # Code : Attribute ID Origin + 0x1, # len + 0x0, # Origin : IGP + 0x50, # Flag Transitive + extended length + 0x2, # Code : AS Path + 0x0, 0x16, # len 22 + 0x2, # Type (AS_Sequence) + 0x5, # length (in ASes as every asn is 0x0 0x0 prefixed ASN4 must have been negotiated) + 0x0, 0x0, 0xfe, 0xb0, # ASN 65200 + 0x0, 0x0, 0x78, 0x14, # ASN 30740 + 0x0, 0x0, 0x19, 0x35, # ASN 6453 + 0x0, 0x0, 0xb, 0x62, # ASN 2914 + 0x0, 0x0, 0x9, 0xd7, # ASN 2519 + 0x40, # Flag Transitive + 0x3, # Code: Next HOP + 0x4, # len + 0x7f, 0x0, 0x0, 0x1, # 127.0.0.1 + 0xc0, # 0x40 + 0x80 (Transitive Optional) + 0x08, # Community + 0x8, # Size 8 + 0x78, 0x14, 0x19, 0x35, # 30740:6453 + 0x78, 0x14, 0xfd, 0xeb, # 30740:65003 + # routes : + 0x18, 0x1, 0x0, 0x19, # 1.0.25.0/24 + 0x10, 0xde, 0xe6, # 222.330.0.0/16 + 0x11, 0xde, 0xe5, 0x80, + 0x12, 0xde, 0xe5, 0x0, + 0x10, 0xde, 0xe4, + 0x11, 0xdc, 0xf7, 0x0, + 0x11, 0xdc, 0x9e, 0x0, + 0x18, 0xdb, 0x79, 0xff, + 0x18, 0xdb, 0x79, 0xf9, + 0x16, 0xd8, 0xb3, 0xcc, + 0x18, 0xd8, 0xb3, 0xb6, + 0x17, 0xd8, 0xb3, 0xb4, + 0x16, 0xd8, 0xb3, 0xb0, + 0x18, 0xd8, 0xb3, 0x99, + 0x12, 0xd2, 0xaa, 0x0, + 0x11, 0xd2, 0x92, 0x80, + 0x11, 0xd2, 0x83, 0x80, + 0x13, 0xcb, 0x8c, 0x20, + 0x18, 0xca, 0xf5, 0xfe, + 0x18, 0xca, 0xf5, 0x8e, + 0x18, 0xca, 0xf3, 0xba, + 0x18, 0xca, 0xf0, 0x8d, + 0x12, 0xca, 0xef, 0xc0, + 0x12, 0xca, 0xe7, 0x40, + 0x10, 0xca, 0xd7, + 0x18, 0xca, 0xd2, 0x8, + 0x13, 0xca, 0xbd, 0xc0, + 0x14, 0xca, 0x58, 0x30, + 0x18, 0xca, 0x22, 0xbf, + 0x17, 0xca, 0x22, 0x96, + 0x18, 0xc0, 0x32, 0x6e, + 0x10, 0xb7, 0xb4, + 0x11, 0xb7, 0xb1, 0x80, + 0x10, 0xa3, 0x8b, + 0x11, 0x9d, 0x78, 0x80, + 0x15, 0x7c, 0xf1, 0x78, + 0x10, 0x7c, 0x6e, + 0x10, 0x7a, 0x67, + 0x10, 0x78, 0x33, + 0x10, 0x74, 0x5b, + 0x15, 0x73, 0xbb, 0x48, + 0x16, 0x73, 0xbb, 0x44, + 0x10, 0x73, 0xb3, + 0x11, 0x72, 0x45, 0x0, + 0x14, 0x71, 0x34, 0xf0, + 0x15, 0x70, 0x6d, 0x18, + 0x18, 0x67, 0xf6, 0xb3, + 0x17, 0x67, 0xb, 0x6, + 0x18, 0x67, 0x5, 0x75, + 0x18, 0x67, 0x5, 0x74, + 0x18, 0x67, 0x3, 0x10, + 0x13, 0x65, 0x37, 0xc0, + 0x11, 0x65, 0x32, 0x80, + 0x18, 0x65, 0x0, 0x1f, + 0x18, 0x65, 0x0, 0x1e, + 0x18, 0x65, 0x0, 0x1d, + 0x18, 0x65, 0x0, 0x1c, + 0xf, 0x24, 0x2, + 0x11, 0x1b, 0x79, 0x80, + 0x13, 0x1b, 0x60, 0x20, + 0x15, 0x1b, 0x60, 0x10, + 0x10, 0x1, 0x15, + 0x16, 0x1, 0x0, 0x1c, + 0x17, 0x1, 0x0, 0x1a ] # asn4, data bodies.append((True,body)) body = [ - 0x0, 0x0, - 0x0, 0x38, - 0x40, - 0x1, - 0x1, - 0x0, - 0x50, - 0x2, - 0x0, 0x12, - 0x2, - 0x4, - 0x0, 0x0, 0xc7, 0x9d, - 0x0, 0x0, 0x9b, 0xbd, - 0x0, 0x0, 0xb, 0x62, - 0x0, 0x0, 0x9, 0xd7, - 0x40, - 0x3, - 0x4, - 0xb2, 0xd9, 0x76, 0x1, - 0xc0, - 0x8, - 0x14, - 0xb, 0x62, 0x1, 0x9a, - 0xb, 0x62, 0x5, 0x7b, - 0xb, 0x62, 0x9, 0x61, - 0xb, 0x62, 0xd, 0x48, - 0x9b, 0xbd, 0x1d, 0x1a, - 0x18, 0x1, 0x0, 0x19, - 0x10, 0xde, 0xe6, - 0x11, 0xde, 0xe5, 0x80, - 0x12, 0xde, 0xe5, 0x0, - 0x18, 0xdb, 0x79, 0xff, - 0x18, 0xdb, 0x79, 0xf9, - 0x16, 0xd8, 0xb3, 0xcc, - 0x18, 0xd8, 0xb3, 0xb6, - 0x17, 0xd8, 0xb3, 0xb4, - 0x16, 0xd8, 0xb3, 0xb0, - 0x18, 0xd8, 0xb3, 0x99, - 0x12, 0xd2, 0xaa, 0x0, - 0x11, 0xd2, 0x92, 0x80, - 0x11, 0xd2, 0x83, 0x80, - 0x13, 0xcb, 0x8c, 0x20, - 0x18, 0xca, 0xf5, 0xfe, - 0x18, 0xca, 0xf5, 0x8e, - 0x18, 0xca, 0xf3, 0xba, - 0x18, 0xca, 0xf0, 0x8d, - 0x12, 0xca, 0xef, 0xc0, - 0x12, 0xca, 0xe7, 0x40, - 0x18, 0xca, 0xd2, 0x8, - 0x13, 0xca, 0xbd, 0xc0, - 0x14, 0xca, 0x58, 0x30, - 0x18, 0xca, 0x22, 0xbf, - 0x17, 0xca, 0x22, 0x96, - 0x18, 0xc0, 0x32, 0x6e, - 0x10, 0xb7, 0xb4, - 0x11, 0x9d, 0x78, 0x80, - 0x15, 0x7c, 0xf1, 0x78, - 0x10, 0x7a, 0x67, - 0x15, 0x73, 0xbb, 0x48, - 0x16, 0x73, 0xbb, 0x44, - 0x11, 0x72, 0x45, 0x0, - 0x14, 0x71, 0x34, 0xf0, - 0x15, 0x70, 0x6d, 0x18, - 0x18, 0x67, 0xf6, 0xb3, - 0x17, 0x67, 0xb, 0x6, - 0x18, 0x67, 0x5, 0x75, - 0x18, 0x67, 0x5, 0x74, - 0x18, 0x67, 0x3, 0x10, - 0x13, 0x65, 0x37, 0xc0, - 0x11, 0x65, 0x32, 0x80, - 0x18, 0x65, 0x0, 0x1f, - 0x18, 0x65, 0x0, 0x1e, - 0x18, 0x65, 0x0, 0x1d, - 0x18, 0x65, 0x0, 0x1c, - 0xf, 0x24, 0x2, - 0x11, 0x1b, 0x79, 0x80, - 0x13, 0x1b, 0x60, 0x20, - 0x15, 0x1b, 0x60, 0x10, - 0x10, 0x1, 0x15, - 0x16, 0x1, 0x0, 0x1c, - 0x17, 0x1, 0x0, 0x1a + 0x0, 0x0, + 0x0, 0x38, + 0x40, + 0x1, + 0x1, + 0x0, + 0x50, + 0x2, + 0x0, 0x12, + 0x2, + 0x4, + 0x0, 0x0, 0xc7, 0x9d, + 0x0, 0x0, 0x9b, 0xbd, + 0x0, 0x0, 0xb, 0x62, + 0x0, 0x0, 0x9, 0xd7, + 0x40, + 0x3, + 0x4, + 0xb2, 0xd9, 0x76, 0x1, + 0xc0, + 0x8, + 0x14, + 0xb, 0x62, 0x1, 0x9a, + 0xb, 0x62, 0x5, 0x7b, + 0xb, 0x62, 0x9, 0x61, + 0xb, 0x62, 0xd, 0x48, + 0x9b, 0xbd, 0x1d, 0x1a, + 0x18, 0x1, 0x0, 0x19, + 0x10, 0xde, 0xe6, + 0x11, 0xde, 0xe5, 0x80, + 0x12, 0xde, 0xe5, 0x0, + 0x18, 0xdb, 0x79, 0xff, + 0x18, 0xdb, 0x79, 0xf9, + 0x16, 0xd8, 0xb3, 0xcc, + 0x18, 0xd8, 0xb3, 0xb6, + 0x17, 0xd8, 0xb3, 0xb4, + 0x16, 0xd8, 0xb3, 0xb0, + 0x18, 0xd8, 0xb3, 0x99, + 0x12, 0xd2, 0xaa, 0x0, + 0x11, 0xd2, 0x92, 0x80, + 0x11, 0xd2, 0x83, 0x80, + 0x13, 0xcb, 0x8c, 0x20, + 0x18, 0xca, 0xf5, 0xfe, + 0x18, 0xca, 0xf5, 0x8e, + 0x18, 0xca, 0xf3, 0xba, + 0x18, 0xca, 0xf0, 0x8d, + 0x12, 0xca, 0xef, 0xc0, + 0x12, 0xca, 0xe7, 0x40, + 0x18, 0xca, 0xd2, 0x8, + 0x13, 0xca, 0xbd, 0xc0, + 0x14, 0xca, 0x58, 0x30, + 0x18, 0xca, 0x22, 0xbf, + 0x17, 0xca, 0x22, 0x96, + 0x18, 0xc0, 0x32, 0x6e, + 0x10, 0xb7, 0xb4, + 0x11, 0x9d, 0x78, 0x80, + 0x15, 0x7c, 0xf1, 0x78, + 0x10, 0x7a, 0x67, + 0x15, 0x73, 0xbb, 0x48, + 0x16, 0x73, 0xbb, 0x44, + 0x11, 0x72, 0x45, 0x0, + 0x14, 0x71, 0x34, 0xf0, + 0x15, 0x70, 0x6d, 0x18, + 0x18, 0x67, 0xf6, 0xb3, + 0x17, 0x67, 0xb, 0x6, + 0x18, 0x67, 0x5, 0x75, + 0x18, 0x67, 0x5, 0x74, + 0x18, 0x67, 0x3, 0x10, + 0x13, 0x65, 0x37, 0xc0, + 0x11, 0x65, 0x32, 0x80, + 0x18, 0x65, 0x0, 0x1f, + 0x18, 0x65, 0x0, 0x1e, + 0x18, 0x65, 0x0, 0x1d, + 0x18, 0x65, 0x0, 0x1c, + 0xf, 0x24, 0x2, + 0x11, 0x1b, 0x79, 0x80, + 0x13, 0x1b, 0x60, 0x20, + 0x15, 0x1b, 0x60, 0x10, + 0x10, 0x1, 0x15, + 0x16, 0x1, 0x0, 0x1c, + 0x17, 0x1, 0x0, 0x1a ] # asn4, data bodies.append((True,body)) # BGP-LS with draft-gredler-idr-bgp-ls-segment-routing-ext body = [0x00, 0x00, # withdrawn routes length 0 - 0x00, 0xdc, # Path Attribute Length 220 - 0x90, 0x0e, - 0x00, 0x62, - 0x40, 0x04, 0x47, 0x04, - 0xac, 0x18, 0xf8, 0x4f, - 0x00, 0x00, 0x02, 0x00, - 0x55, 0x02, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x01, 0x00, - 0x00, 0x1a, 0x02, 0x00, - 0x00, 0x04, 0x00, 0x00, - 0xfd, 0xe8, 0x02, 0x01, - 0x00, 0x04, 0xac, 0x10, - 0x00, 0x58, 0x02, 0x03, - 0x00, 0x06, 0x17, 0x20, - 0x00, 0x16, 0x00, 0x02, - 0x01, 0x01, 0x00, 0x1a, - 0x02, 0x00, 0x00, 0x04, - 0x00, 0x00, 0xfd, 0xe8, - 0x02, 0x01, 0x00, 0x04, - 0xac, 0x10, 0x00, 0x58, - 0x02, 0x03, 0x00, 0x06, - 0x17, 0x20, 0x00, 0x16, - 0x00, 0x01, 0x01, 0x03, - 0x00, 0x04, 0x0a, 0x00, - 0x00, 0x07, 0x01, 0x04, - 0x00, 0x04, 0x0a, 0x00, - 0x00, 0x06, 0x40, 0x01, - 0x01, 0x00, 0x40, 0x02, - 0x06, 0x02, 0x01, 0x00, - 0x00, 0xfd, 0xe8, - 0x80, 0x1d, # Link State Attribute Code 29 - 0x66, # Length - 0x04, 0x04, 0x00, 0x04, # Type 1028, Length 4 - 0xac, 0x10, 0x00, 0x02, # IPv4 Router-ID 172.16.0.2 - 0x04, 0x06, # Type 1030 - 0x00, 0x04, - 0xac, 0x10, 0x00, 0x01, # IPv4 Router ID 172.16.0.1 - 0x04, 0x40, # Type 1088 - 0x00, 0x04, - 0x00, 0x00, 0x00, 0x00, # SRLG = 0 - 0x04, 0x41, # Type 1089 - 0x00, 0x04, - 0x4c, 0xee, 0x6b, 0x28, # 1000.00 Mbps Maximum Link bandwidth - 0x04, 0x42, # Type 1090 - 0x00, 0x04, - 0x4c, 0xee, 0x6b, 0x28, # 1000.00 Mbps Maximum reservable link bandwidth - 0x04, 0x43, # Type 1091 - 0x00, 0x20, - 0x4c, 0xee, 0x6b, 0x28, # 1000.00 Mbps Unreserved Bandwidth P0 - 0x4c, 0xee, 0x6b, 0x28, # 1000.00 Mbps Unreserved Bandwidth P1 - 0x4c, 0xee, 0x6b, 0x28, # 1000.00 Mbps Unreserved Bandwidth P2 - 0x4c, 0xee, 0x6b, 0x28, # 1000.00 Mbps Unreserved Bandwidth P3 - 0x4c, 0xee, 0x6b, 0x28, # 1000.00 Mbps Unreserved Bandwidth P4 - 0x4c, 0xee, 0x6b, 0x28, # 1000.00 Mbps Unreserved Bandwidth P5 - 0x4c, 0xee, 0x6b, 0x28, # 1000.00 Mbps Unreserved Bandwidth P6 - 0x4c, 0xee, 0x6b, 0x28, # 1000.00 Mbps Unreserved Bandwidth P7 - 0x04, 0x44, # Type 1092 - 0x00, 0x04, # Length 4 - 0x00, 0x00, 0x00, 0x0a, # 10 - 0x04, 0x47, # Type 1095 Metric TLV - 0x00, 0x03, # Length 3 - 0x00, 0x00, 0x0a, # 10 - 0x04, 0x4b, # Type 1099 Adjacency Segment TLV - 0x00, 0x07, # Length 7 - 0x30, # Flags 0011 0000 - 0x00, # Weigth 0 - 0x00, 0x00, # Reserved 0x0 - 0x04, 0x93, 0x1e] # SID/Label 299806 - + 0x00, 0xdc, # Path Attribute Length 220 + 0x90, 0x0e, + 0x00, 0x62, + 0x40, 0x04, 0x47, 0x04, + 0xac, 0x18, 0xf8, 0x4f, + 0x00, 0x00, 0x02, 0x00, + 0x55, 0x02, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x01, 0x00, + 0x00, 0x1a, 0x02, 0x00, + 0x00, 0x04, 0x00, 0x00, + 0xfd, 0xe8, 0x02, 0x01, + 0x00, 0x04, 0xac, 0x10, + 0x00, 0x58, 0x02, 0x03, + 0x00, 0x06, 0x17, 0x20, + 0x00, 0x16, 0x00, 0x02, + 0x01, 0x01, 0x00, 0x1a, + 0x02, 0x00, 0x00, 0x04, + 0x00, 0x00, 0xfd, 0xe8, + 0x02, 0x01, 0x00, 0x04, + 0xac, 0x10, 0x00, 0x58, + 0x02, 0x03, 0x00, 0x06, + 0x17, 0x20, 0x00, 0x16, + 0x00, 0x01, 0x01, 0x03, + 0x00, 0x04, 0x0a, 0x00, + 0x00, 0x07, 0x01, 0x04, + 0x00, 0x04, 0x0a, 0x00, + 0x00, 0x06, 0x40, 0x01, + 0x01, 0x00, 0x40, 0x02, + 0x06, 0x02, 0x01, 0x00, + 0x00, 0xfd, 0xe8, + 0x80, 0x1d, # Link State Attribute Code 29 + 0x66, # Length + 0x04, 0x04, 0x00, 0x04, # Type 1028, Length 4 + 0xac, 0x10, 0x00, 0x02, # IPv4 Router-ID 172.16.0.2 + 0x04, 0x06, # Type 1030 + 0x00, 0x04, + 0xac, 0x10, 0x00, 0x01, # IPv4 Router ID 172.16.0.1 + 0x04, 0x40, # Type 1088 + 0x00, 0x04, + 0x00, 0x00, 0x00, 0x00, # SRLG = 0 + 0x04, 0x41, # Type 1089 + 0x00, 0x04, + 0x4c, 0xee, 0x6b, 0x28, # 1000.00 Mbps Maximum Link bandwidth + 0x04, 0x42, # Type 1090 + 0x00, 0x04, + 0x4c, 0xee, 0x6b, 0x28, # 1000.00 Mbps Maximum reservable link bandwidth + 0x04, 0x43, # Type 1091 + 0x00, 0x20, + 0x4c, 0xee, 0x6b, 0x28, # 1000.00 Mbps Unreserved Bandwidth P0 + 0x4c, 0xee, 0x6b, 0x28, # 1000.00 Mbps Unreserved Bandwidth P1 + 0x4c, 0xee, 0x6b, 0x28, # 1000.00 Mbps Unreserved Bandwidth P2 + 0x4c, 0xee, 0x6b, 0x28, # 1000.00 Mbps Unreserved Bandwidth P3 + 0x4c, 0xee, 0x6b, 0x28, # 1000.00 Mbps Unreserved Bandwidth P4 + 0x4c, 0xee, 0x6b, 0x28, # 1000.00 Mbps Unreserved Bandwidth P5 + 0x4c, 0xee, 0x6b, 0x28, # 1000.00 Mbps Unreserved Bandwidth P6 + 0x4c, 0xee, 0x6b, 0x28, # 1000.00 Mbps Unreserved Bandwidth P7 + 0x04, 0x44, # Type 1092 + 0x00, 0x04, # Length 4 + 0x00, 0x00, 0x00, 0x0a, # 10 + 0x04, 0x47, # Type 1095 Metric TLV + 0x00, 0x03, # Length 3 + 0x00, 0x00, 0x0a, # 10 + 0x04, 0x4b, # Type 1099 Adjacency Segment TLV + 0x00, 0x07, # Length 7 + 0x30, # Flags 0011 0000 + 0x00, # Weigth 0 + 0x00, 0x00, # Reserved 0x0 + 0x04, 0x93, 0x1e] # SID/Label 299806 +# fmt: on # asn4, data -bodies.append((True,body)) +bodies.append((True, body)) + + +class FakeNeighbor(object): + description = 'a test neighbor' + router_id = RouterID('127.0.0.1') + local_address = IPv4('127.0.0.1') + peer_address = IPv4('127.0.0.1') + host_name = 'localhost' + domain_name = 'localdomain' + peer_as = ASN('65500') + local_as = ASN('65500') + hold_time = HoldTime(180) + asn4 = False + add_path = 0 + extended_message = False + nexthop = None + + # capability + route_refresh = False + graceful_restart = False + multisession = None + add_path = None + aigp = None + operational = None + + @staticmethod + def families(): + return NLRI.known_families() -class FakeNeighbor (object): - description = 'a test neighbor' - router_id = RouterID('127.0.0.1') - local_address = IPv4('127.0.0.1') - peer_address = IPv4('127.0.0.1') - host_name = 'localhost' - domain_name = 'localdomain' - peer_as = ASN('65500') - local_as = ASN('65500') - hold_time = HoldTime(180) - asn4 = False - add_path = 0 - extended_message = False - nexthop = None - - # capability - route_refresh = False - graceful_restart = False - multisession = None - add_path = None - aigp = None - operational = None - - @staticmethod - def families (): - return NLRI.known_families() - import unittest # from contextlib import contextmanager @@ -347,50 +349,51 @@ def families (): # os.chdir(old_cwd) -class TestUpdateDecoding (unittest.TestCase): - def setUp (self): - self.negotiated = {} +class TestUpdateDecoding(unittest.TestCase): + def setUp(self): + self.negotiated = {} + + for asn4 in (True, False): + neighbor = FakeNeighbor() + neighbor.asn4 = asn4 - for asn4 in (True,False): - neighbor = FakeNeighbor() - neighbor.asn4 = asn4 + capa = Capabilities().new(neighbor, False) + capa[Capability.CODE.MULTIPROTOCOL] = neighbor.families() - capa = Capabilities().new(neighbor,False) - capa[Capability.CODE.MULTIPROTOCOL] = neighbor.families() + # path = {} + # for f in NLRI.known_families(): + # if neighbor.add_path: + # path[f] = neighbor.add_path + # capa[Capability.CODE.ADD_PATH] = path - # path = {} - # for f in NLRI.known_families(): - # if neighbor.add_path: - # path[f] = neighbor.add_path - # capa[Capability.CODE.ADD_PATH] = path + routerid_1 = str(neighbor.router_id) + routerid_2 = '.'.join(str((int(_) + 1) % 250) for _ in str(neighbor.router_id).split('.', -1)) - routerid_1 = str(neighbor.router_id) - routerid_2 = '.'.join(str((int(_)+1) % 250) for _ in str(neighbor.router_id).split('.',-1)) + o1 = Open(Version(4), ASN(neighbor.local_as), HoldTime(180), RouterID(routerid_1), capa) + o2 = Open(Version(4), ASN(neighbor.peer_as), HoldTime(180), RouterID(routerid_2), capa) - o1 = Open(Version(4),ASN(neighbor.local_as),HoldTime(180),RouterID(routerid_1),capa) - o2 = Open(Version(4),ASN(neighbor.peer_as),HoldTime(180),RouterID(routerid_2),capa) + negotiated = Negotiated(neighbor) + negotiated.sent(o1) + negotiated.received(o2) - negotiated = Negotiated(neighbor) - negotiated.sent(o1) - negotiated.received(o2) + self.negotiated[asn4] = negotiated - self.negotiated[asn4] = negotiated + # size = len(body)+19 + # header = [0xFF,]*16 + [size >> 8] + [size & 0xFF] + [0x02] + # print ''.join('%02X' % _ for _ in header+body - # size = len(body)+19 - # header = [0xFF,]*16 + [size >> 8] + [size & 0xFF] + [0x02] - # print ''.join('%02X' % _ for _ in header+body + def test_decoding_udpate_asn(self): + for asn4, body in bodies: + if asn4: + continue + Update.unpack_message(data_from_body(body), self.negotiated[asn4]) - def test_decoding_udpate_asn (self): - for asn4,body in bodies: - if asn4: - continue - Update.unpack_message(data_from_body(body),self.negotiated[asn4]) + def test_decoding_udpate_asn4(self): + for asn4, body in bodies: + if not asn4: + continue + Update.unpack_message(data_from_body(body), self.negotiated[asn4]) - def test_decoding_udpate_asn4 (self): - for asn4,body in bodies: - if not asn4: - continue - Update.unpack_message(data_from_body(body),self.negotiated[asn4]) if __name__ == '__main__': - unittest.main() + unittest.main() diff --git a/qa/tests/flow_test.py b/qa/tests/flow_test.py index d5b47488c..c9039b416 100755 --- a/qa/tests/flow_test.py +++ b/qa/tests/flow_test.py @@ -21,6 +21,7 @@ from exabgp.bgp.message.update.nlri.flow import FlowAnyPort from exabgp.bgp.message.update.nlri.flow import NumericOperator + # from exabgp.bgp.message.update.attribute.community import * from exabgp.protocol.ip import IPv4 @@ -28,107 +29,108 @@ from exabgp.util.test import data_from_body from exabgp.configuration.environment import environment + environment.setup('') -class TestFlow (unittest.TestCase): - - def setUp (self): - pass - - def test_rule (self): - components = { - 'destination': Flow4Destination(IPv4.pton("192.0.2.0"),24), - 'source': Flow4Source(IPv4.pton("10.1.2.0"),24), - 'anyport_1': FlowAnyPort(NumericOperator.EQ,25), - } - messages = { - 'destination': [0x01, 0x18, 0xc0, 0x00, 0x02], - 'source': [0x02, 0x18, 0x0a, 0x01, 0x02], - 'anyport_1': [0x04, 0x01, 0x19], - } - - for key in ['destination','source','anyport_1']: - component = components[key].pack() - message = data_from_body(messages[key]) - # if component != message: - # self.fail('content mismatch\n%s\n%s' % (['0x%02X' % ord(_) for _ in component],['0x%02X' % ord(_) for _ in message])) - - def test_rule_and (self): - components = { - 'destination': Flow4Destination(IPv4.pton("192.0.2.0"),24), - 'source': Flow4Source(IPv4.pton("10.1.2.0"),24), - 'anyport_1': FlowAnyPort(NumericOperator.EQ | NumericOperator.GT,25), - 'anyport_2': FlowAnyPort(NumericOperator.EQ | NumericOperator.LT,80), - } - messages = { - 'destination': [0x01, 0x18, 0xc0, 0x00, 0x02], - 'source': [0x02, 0x18, 0x0a, 0x01, 0x02], - 'anyport_1': [0x04, 0x43, 0x19], - 'anyport_2': [0x04, 0x85, 0x50], - } - - flow = Flow() - message = b"" - for key in ['destination','source','anyport_1','anyport_2']: - flow.add(components[key]) - message += data_from_body(messages[key]) - message = character(len(message)) + message - # flow.add(to_FlowAction(65000,False,False)) - flow.pack() - # print [hex(ord(_)) for _ in flow] - - def test_nlri (self): - components = { - 'destination': Flow4Destination(IPv4.pton("192.0.2.0"),24), - 'source': Flow4Source(IPv4.pton("10.1.2.0"),24), - 'anyport_1': FlowAnyPort(NumericOperator.EQ | NumericOperator.GT,25), - 'anyport_2': FlowAnyPort(NumericOperator.EQ | NumericOperator.LT,80), - } - messages = { - 'destination': [0x01, 0x18, 0xc0, 0x00, 0x02], - 'source': [0x02, 0x18, 0x0a, 0x01, 0x02], - 'anyport_1': [0x04, 0x43, 0x19], - 'anyport_2': [0x85, 0x50], - } - - flow = Flow() - message = b"" - for key in ['destination','source','anyport_1','anyport_2']: - flow.add(components[key]) - message += data_from_body(messages[key]) - message = character(len(message)) + message - # policy.add(to_FlowAction(65000,False,False)) - flow = flow.pack() - if message[0] != flow[0]: - self.fail('size mismatch %s %s\n' % (ordinal(flow[0]),ordinal(message[0]))) - if len(flow) != ordinal(flow[0]) + 1: - self.fail('invalid size for message') - # if message[1:] != flow[1:]: - # self.fail('content mismatch\n%s\n%s' % (['0x%02X' % ord(_) for _ in flow],['0x%02X' % ord(_) for _ in message])) - - def test_compare (self): - components = { - 'destination': Flow4Destination(IPv4.pton("192.0.2.0"),24), - 'source': Flow4Source(IPv4.pton("10.1.2.0"),24), - 'anyport_1': FlowAnyPort(NumericOperator.EQ | NumericOperator.GT,25), - 'anyport_2': FlowAnyPort(NumericOperator.EQ | NumericOperator.LT,80), - 'anyport_3': FlowAnyPort(NumericOperator.EQ,80), - } - - flow1 = Flow() - for key in ['destination','source','anyport_1','anyport_2']: - flow1.add(components[key]) - - flow2 = Flow() - for key in ['destination','source','anyport_3']: - flow2.add(components[key]) - - if flow1 != flow1: - self.fail('the flows are the same') - - if flow1 == flow2: - self.fail('the flows are not the same') +class TestFlow(unittest.TestCase): + def setUp(self): + pass + + def test_rule(self): + components = { + 'destination': Flow4Destination(IPv4.pton("192.0.2.0"), 24), + 'source': Flow4Source(IPv4.pton("10.1.2.0"), 24), + 'anyport_1': FlowAnyPort(NumericOperator.EQ, 25), + } + messages = { + 'destination': [0x01, 0x18, 0xC0, 0x00, 0x02], + 'source': [0x02, 0x18, 0x0A, 0x01, 0x02], + 'anyport_1': [0x04, 0x01, 0x19], + } + + for key in ['destination', 'source', 'anyport_1']: + component = components[key].pack() + message = data_from_body(messages[key]) + # if component != message: + # self.fail('content mismatch\n%s\n%s' % (['0x%02X' % ord(_) for _ in component],['0x%02X' % ord(_) for _ in message])) + + def test_rule_and(self): + components = { + 'destination': Flow4Destination(IPv4.pton("192.0.2.0"), 24), + 'source': Flow4Source(IPv4.pton("10.1.2.0"), 24), + 'anyport_1': FlowAnyPort(NumericOperator.EQ | NumericOperator.GT, 25), + 'anyport_2': FlowAnyPort(NumericOperator.EQ | NumericOperator.LT, 80), + } + messages = { + 'destination': [0x01, 0x18, 0xC0, 0x00, 0x02], + 'source': [0x02, 0x18, 0x0A, 0x01, 0x02], + 'anyport_1': [0x04, 0x43, 0x19], + 'anyport_2': [0x04, 0x85, 0x50], + } + + flow = Flow() + message = b"" + for key in ['destination', 'source', 'anyport_1', 'anyport_2']: + flow.add(components[key]) + message += data_from_body(messages[key]) + message = character(len(message)) + message + # flow.add(to_FlowAction(65000,False,False)) + flow.pack() + # print [hex(ord(_)) for _ in flow] + + def test_nlri(self): + components = { + 'destination': Flow4Destination(IPv4.pton("192.0.2.0"), 24), + 'source': Flow4Source(IPv4.pton("10.1.2.0"), 24), + 'anyport_1': FlowAnyPort(NumericOperator.EQ | NumericOperator.GT, 25), + 'anyport_2': FlowAnyPort(NumericOperator.EQ | NumericOperator.LT, 80), + } + messages = { + 'destination': [0x01, 0x18, 0xC0, 0x00, 0x02], + 'source': [0x02, 0x18, 0x0A, 0x01, 0x02], + 'anyport_1': [0x04, 0x43, 0x19], + 'anyport_2': [0x85, 0x50], + } + + flow = Flow() + message = b"" + for key in ['destination', 'source', 'anyport_1', 'anyport_2']: + flow.add(components[key]) + message += data_from_body(messages[key]) + message = character(len(message)) + message + # policy.add(to_FlowAction(65000,False,False)) + flow = flow.pack() + if message[0] != flow[0]: + self.fail('size mismatch %s %s\n' % (ordinal(flow[0]), ordinal(message[0]))) + if len(flow) != ordinal(flow[0]) + 1: + self.fail('invalid size for message') + # if message[1:] != flow[1:]: + # self.fail('content mismatch\n%s\n%s' % (['0x%02X' % ord(_) for _ in flow],['0x%02X' % ord(_) for _ in message])) + + def test_compare(self): + components = { + 'destination': Flow4Destination(IPv4.pton("192.0.2.0"), 24), + 'source': Flow4Source(IPv4.pton("10.1.2.0"), 24), + 'anyport_1': FlowAnyPort(NumericOperator.EQ | NumericOperator.GT, 25), + 'anyport_2': FlowAnyPort(NumericOperator.EQ | NumericOperator.LT, 80), + 'anyport_3': FlowAnyPort(NumericOperator.EQ, 80), + } + + flow1 = Flow() + for key in ['destination', 'source', 'anyport_1', 'anyport_2']: + flow1.add(components[key]) + + flow2 = Flow() + for key in ['destination', 'source', 'anyport_3']: + flow2.add(components[key]) + + if flow1 != flow1: + self.fail('the flows are the same') + + if flow1 == flow2: + self.fail('the flows are not the same') + if __name__ == '__main__': - unittest.main() + unittest.main() diff --git a/qa/tests/l2vpn_test.py b/qa/tests/l2vpn_test.py index 97bcbf37c..312a6d3f8 100755 --- a/qa/tests/l2vpn_test.py +++ b/qa/tests/l2vpn_test.py @@ -14,88 +14,89 @@ from exabgp.bgp.message.update.nlri.qualifier import RouteDistinguisher -class TestL2VPN (unittest.TestCase): - @staticmethod - def generate_rd (rd): - """only ip:num is supported atm.code from configure.file""" - separator = rd.find(':') - prefix = rd[:separator] - suffix = int(rd[separator+1:]) - data = [chr(0),chr(1)] - data.extend([chr(int(_)) for _ in prefix.split('.')]) - data.extend([chr(suffix >> 8),chr(suffix & 0xFF)]) - bin_rd = ''.join(data) - return RouteDistinguisher(bin_rd) +class TestL2VPN(unittest.TestCase): + @staticmethod + def generate_rd(rd): + """only ip:num is supported atm.code from configure.file""" + separator = rd.find(':') + prefix = rd[:separator] + suffix = int(rd[separator + 1 :]) + data = [chr(0), chr(1)] + data.extend([chr(int(_)) for _ in prefix.split('.')]) + data.extend([chr(suffix >> 8), chr(suffix & 0xFF)]) + bin_rd = ''.join(data) + return RouteDistinguisher(bin_rd) - def setUp (self): - """ + def setUp(self): + """ setUp unittesting l2vpn:endpoint:3:base:262145:offset:1:size:8: route-distinguisher 172.30.5.4:13 l2vpn:endpoint:3:base:262145:offset:1:size:8: route-distinguisher 172.30.5.3:11 """ - self.encoded_l2vpn_nlri1 = bytearray.fromhex(u'0011 0001 AC1E 0504 000D 0003 0001 0008 4000 11') - self.encoded_l2vpn_nlri2 = bytearray.fromhex(u'0011 0001 AC1E 0503 000B 0003 0001 0008 4000 11') - self.decoded_l2vpn_nlri1 = VPLS(TestL2VPN.generate_rd('172.30.5.4:13'),3,262145,1,8) - self.decoded_l2vpn_nlri2 = VPLS(TestL2VPN.generate_rd('172.30.5.3:11'),3,262145,1,8) - """ + self.encoded_l2vpn_nlri1 = bytearray.fromhex(u'0011 0001 AC1E 0504 000D 0003 0001 0008 4000 11') + self.encoded_l2vpn_nlri2 = bytearray.fromhex(u'0011 0001 AC1E 0503 000B 0003 0001 0008 4000 11') + self.decoded_l2vpn_nlri1 = VPLS(TestL2VPN.generate_rd('172.30.5.4:13'), 3, 262145, 1, 8) + self.decoded_l2vpn_nlri2 = VPLS(TestL2VPN.generate_rd('172.30.5.3:11'), 3, 262145, 1, 8) + """ output from Juniper Communities: target:54591:6 Layer2-info: encaps: VPLS, control flags:[0x0] , mtu: 0, site preference: 100 """ - self.encoded_ext_community = bytearray.fromhex(u'0002 D53F 0000 0006 800A 1300 0000 0064') + self.encoded_ext_community = bytearray.fromhex(u'0002 D53F 0000 0006 800A 1300 0000 0064') - def test_l2vpn_decode (self): - """ + def test_l2vpn_decode(self): + """ decode and test against known data we do know what routes Juniper sends us and we testing decoded values against it """ - # l2vpn_route1 = VPLS.unpack(str(self.encoded_l2vpn_nlri1)) - # l2vpn_route2 = VPLS.unpack(str(self.encoded_l2vpn_nlri2)) - # self.assertEqual(l2vpn_route1.endpoint,3) - # self.assertEqual(l2vpn_route1.rd._str(),'172.30.5.4:13') - # self.assertEqual(l2vpn_route1.offset,1) - # self.assertEqual(l2vpn_route1.base,262145) - # self.assertEqual(l2vpn_route1.size,8) - # self.assertEqual(l2vpn_route2.endpoint,3) - # self.assertEqual(l2vpn_route2.rd._str(),'172.30.5.3:11') - # self.assertEqual(l2vpn_route2.offset,1) - # self.assertEqual(l2vpn_route2.base,262145) - # self.assertEqual(l2vpn_route2.size,8) + # l2vpn_route1 = VPLS.unpack(str(self.encoded_l2vpn_nlri1)) + # l2vpn_route2 = VPLS.unpack(str(self.encoded_l2vpn_nlri2)) + # self.assertEqual(l2vpn_route1.endpoint,3) + # self.assertEqual(l2vpn_route1.rd._str(),'172.30.5.4:13') + # self.assertEqual(l2vpn_route1.offset,1) + # self.assertEqual(l2vpn_route1.base,262145) + # self.assertEqual(l2vpn_route1.size,8) + # self.assertEqual(l2vpn_route2.endpoint,3) + # self.assertEqual(l2vpn_route2.rd._str(),'172.30.5.3:11') + # self.assertEqual(l2vpn_route2.offset,1) + # self.assertEqual(l2vpn_route2.base,262145) + # self.assertEqual(l2vpn_route2.size,8) - def test_l2vpn_encode (self): - """ + def test_l2vpn_encode(self): + """ encode and test against known data we are encoding routes and testing em against what we have recvd from Juniper """ - # encoded_l2vpn = VPLS(None,None,None,None,None) - # encoded_l2vpn = self.decoded_l2vpn_nlri1 - # self.assertEqual( - # encoded_l2vpn.pack().encode('hex'), - # str(self.encoded_l2vpn_nlri1).encode('hex') - # ) - # - # encoded_l2vpn.nlri = self.decoded_l2vpn_nlri2 - # encoded_l2vpn.rd = self.decoded_l2vpn_nlri2.rd - # self.assertEqual( - # encoded_l2vpn.pack().encode('hex'), - # str(self.encoded_l2vpn_nlri2).encode('hex') - # ) + # encoded_l2vpn = VPLS(None,None,None,None,None) + # encoded_l2vpn = self.decoded_l2vpn_nlri1 + # self.assertEqual( + # encoded_l2vpn.pack().encode('hex'), + # str(self.encoded_l2vpn_nlri1).encode('hex') + # ) + # + # encoded_l2vpn.nlri = self.decoded_l2vpn_nlri2 + # encoded_l2vpn.rd = self.decoded_l2vpn_nlri2.rd + # self.assertEqual( + # encoded_l2vpn.pack().encode('hex'), + # str(self.encoded_l2vpn_nlri2).encode('hex') + # ) + + # Disable until we refactor the configuation code + # + # def test_l2info_community_decode (self): + # ''' + # Juniper sends us both target and l2info; so we test only against + # l2info. + # ''' + # l2info_com = ExtendedCommunity.unpack(str(self.encoded_ext_community)[8:16]) + # self.assertEqual(l2info_com,to_ExtendedCommunity('l2info:19:0:0:100')) - # Disable until we refactor the configuation code - # - # def test_l2info_community_decode (self): - # ''' - # Juniper sends us both target and l2info; so we test only against - # l2info. - # ''' - # l2info_com = ExtendedCommunity.unpack(str(self.encoded_ext_community)[8:16]) - # self.assertEqual(l2info_com,to_ExtendedCommunity('l2info:19:0:0:100')) + # def test_l2info_community_encode (self): + # l2info_com_encoded = to_ExtendedCommunity('l2info:19:0:0:100') + # self.assertEqual(l2info_com_encoded.pack(),str(self.encoded_ext_community)[8:16]) - # def test_l2info_community_encode (self): - # l2info_com_encoded = to_ExtendedCommunity('l2info:19:0:0:100') - # self.assertEqual(l2info_com_encoded.pack(),str(self.encoded_ext_community)[8:16]) if __name__ == '__main__': - unittest.main() + unittest.main() diff --git a/qa/tests/nlri_tests.py b/qa/tests/nlri_tests.py index db7cd6205..067fc0e44 100755 --- a/qa/tests/nlri_tests.py +++ b/qa/tests/nlri_tests.py @@ -17,14 +17,10 @@ from exabgp.bgp.message.update import Attributes from exabgp.bgp.message.update.attribute.localpref import LocalPreference -from exabgp.bgp.message.update.attribute.community.extended.communities \ - import ExtendedCommunities -from exabgp.bgp.message.update.attribute.community.extended \ - import RouteTargetASN2Number as RouteTarget -from exabgp.bgp.message.update.attribute.community.extended.encapsulation \ - import Encapsulation -from exabgp.bgp.message.update.attribute.community.extended \ - import RTRecord +from exabgp.bgp.message.update.attribute.community.extended.communities import ExtendedCommunities +from exabgp.bgp.message.update.attribute.community.extended import RouteTargetASN2Number as RouteTarget +from exabgp.bgp.message.update.attribute.community.extended.encapsulation import Encapsulation +from exabgp.bgp.message.update.attribute.community.extended import RTRecord from exabgp.bgp.message.update.nlri.ipvpn import IPVPN @@ -46,6 +42,7 @@ from exabgp.bgp.message import OUT from exabgp.configuration.setup import environment + environment.setup('') @@ -55,14 +52,17 @@ class TestNLRIs(unittest.TestCase): def test200_IPVPNCreatePackUnpack(self): '''Test pack/unpack for IPVPN routes''' - nlri = IPVPN.new(AFI.ipv4, SAFI.mpls_vpn, - IP.pton("1.2.3.0"), 24, - Labels([42], True), - RouteDistinguisher.fromElements("42.42.42.42", 5)) + nlri = IPVPN.new( + AFI.ipv4, + SAFI.mpls_vpn, + IP.pton("1.2.3.0"), + 24, + Labels([42], True), + RouteDistinguisher.fromElements("42.42.42.42", 5), + ) packed = nlri.pack() - unpacked,leftover = IPVPN.unpack_nlri(AFI.ipv4, SAFI.mpls_vpn, - packed, OUT.UNSET, None) + unpacked, leftover = IPVPN.unpack_nlri(AFI.ipv4, SAFI.mpls_vpn, packed, OUT.UNSET, None) self.assertEqual(0, len(leftover)) @@ -80,17 +80,19 @@ def test200_IPVPNCreatePackUnpack(self): def test99_EVPNMACCreatePackUnpack(self): '''Test pack/unpack for E-VPN MAC routes''' - nlri = EVPNMAC(RouteDistinguisher.fromElements("42.42.42.42", 5), - ESI(), - EthernetTag(111), - MAC("01:02:03:04:05:06"), 6*8, - Labels([42], True), - IP.create("1.1.1.1")) + nlri = EVPNMAC( + RouteDistinguisher.fromElements("42.42.42.42", 5), + ESI(), + EthernetTag(111), + MAC("01:02:03:04:05:06"), + 6 * 8, + Labels([42], True), + IP.create("1.1.1.1"), + ) packed = nlri.pack() - unpacked,leftover = EVPN.unpack_nlri(AFI.l2vpn, SAFI.evpn, - packed, OUT.UNSET, None) + unpacked, leftover = EVPN.unpack_nlri(AFI.l2vpn, SAFI.evpn, packed, OUT.UNSET, None) self.assertEqual(0, len(leftover)) @@ -112,14 +114,11 @@ def test99_EVPNMACCreatePackUnpack(self): def test99_EVPNMulticastCreatePackUnpack(self): '''Test pack/unpack for E-VPN Multicast routes''' - nlri = EVPNMulticast(RouteDistinguisher.fromElements("42.42.42.42", 5), - EthernetTag(111), - IP.create("1.1.1.1")) + nlri = EVPNMulticast(RouteDistinguisher.fromElements("42.42.42.42", 5), EthernetTag(111), IP.create("1.1.1.1")) packed = nlri.pack() - unpacked,leftover = EVPN.unpack_nlri(AFI.l2vpn, SAFI.evpn, - packed, OUT.UNSET, None) + unpacked, leftover = EVPN.unpack_nlri(AFI.l2vpn, SAFI.evpn, packed, OUT.UNSET, None) self.assertEqual(0, len(leftover)) @@ -135,18 +134,19 @@ def test99_EVPNMulticastCreatePackUnpack(self): def test99_EVPNPrefixCreatePackUnpack(self): '''Test pack/unpack for E-VPN Prefix routes''' - nlri = EVPNPrefix(RouteDistinguisher.fromElements("42.42.42.42", 5), - ESI(), - EthernetTag(111), - Labels([42], True), - IP.create("1.1.1.0"),24, - IP.create("2.2.2.2"), - ) + nlri = EVPNPrefix( + RouteDistinguisher.fromElements("42.42.42.42", 5), + ESI(), + EthernetTag(111), + Labels([42], True), + IP.create("1.1.1.0"), + 24, + IP.create("2.2.2.2"), + ) packed = nlri.pack() - unpacked,leftover = EVPN.unpack_nlri(AFI.l2vpn, SAFI.evpn, - packed, OUT.UNSET, None) + unpacked, leftover = EVPN.unpack_nlri(AFI.l2vpn, SAFI.evpn, packed, OUT.UNSET, None) self.assertEqual(0, len(leftover)) @@ -170,19 +170,25 @@ def test100_EVPNMACHashEqual(self): hash to the same value, and be equal ''' - nlri1 = EVPNMAC(RouteDistinguisher.fromElements("42.42.42.42", 5), - ESI(), - EthernetTag(111), - MAC("01:02:03:04:05:06"), 6*8, - Labels([42], True), - IP.create("1.1.1.1")) - - nlri2 = EVPNMAC(RouteDistinguisher.fromElements("42.42.42.42", 5), - ESI(), - EthernetTag(111), - MAC("01:02:03:04:05:06"), 6*8, - Labels([42], True), - IP.create("1.1.1.1")) + nlri1 = EVPNMAC( + RouteDistinguisher.fromElements("42.42.42.42", 5), + ESI(), + EthernetTag(111), + MAC("01:02:03:04:05:06"), + 6 * 8, + Labels([42], True), + IP.create("1.1.1.1"), + ) + + nlri2 = EVPNMAC( + RouteDistinguisher.fromElements("42.42.42.42", 5), + ESI(), + EthernetTag(111), + MAC("01:02:03:04:05:06"), + 6 * 8, + Labels([42], True), + IP.create("1.1.1.1"), + ) self.assertEqual(hash(nlri1), hash(nlri2)) self.assertEqual(nlri1, nlri2) @@ -194,52 +200,70 @@ def test101_EVPNHashEqual_somefieldsvary(self): and be equal ''' - nlri0 = EVPNMAC(RouteDistinguisher.fromElements("42.42.42.42", 5), - ESI(), - EthernetTag(111), - MAC("01:02:03:04:05:06"), 6*8, - Labels([42], True), - IP.create("1.1.1.1")) + nlri0 = EVPNMAC( + RouteDistinguisher.fromElements("42.42.42.42", 5), + ESI(), + EthernetTag(111), + MAC("01:02:03:04:05:06"), + 6 * 8, + Labels([42], True), + IP.create("1.1.1.1"), + ) # ESI - nlri1 = EVPNMAC(RouteDistinguisher.fromElements("42.42.42.42", 5), - ESI(b''.join(character(1) for _ in range(0,10))), - EthernetTag(111), - MAC("01:02:03:04:05:06"), 6*8, - Labels([42], True), - IP.create("1.1.1.1")) + nlri1 = EVPNMAC( + RouteDistinguisher.fromElements("42.42.42.42", 5), + ESI(b''.join(character(1) for _ in range(0, 10))), + EthernetTag(111), + MAC("01:02:03:04:05:06"), + 6 * 8, + Labels([42], True), + IP.create("1.1.1.1"), + ) # label - nlri2 = EVPNMAC(RouteDistinguisher.fromElements("42.42.42.42", 5), - ESI(), - EthernetTag(111), - MAC("01:02:03:04:05:06"), 6*8, - Labels([4444], True), - IP.create("1.1.1.1")) + nlri2 = EVPNMAC( + RouteDistinguisher.fromElements("42.42.42.42", 5), + ESI(), + EthernetTag(111), + MAC("01:02:03:04:05:06"), + 6 * 8, + Labels([4444], True), + IP.create("1.1.1.1"), + ) # IP: different IPs, but same MACs: different route - nlri3 = EVPNMAC(RouteDistinguisher.fromElements("42.42.42.42", 5), - ESI(), - EthernetTag(111), - MAC("01:02:03:04:05:06"), 6*8, - Labels([42], True), - IP.create("2.2.2.2")) + nlri3 = EVPNMAC( + RouteDistinguisher.fromElements("42.42.42.42", 5), + ESI(), + EthernetTag(111), + MAC("01:02:03:04:05:06"), + 6 * 8, + Labels([42], True), + IP.create("2.2.2.2"), + ) # with a next hop... - nlri4 = EVPNMAC(RouteDistinguisher.fromElements("42.42.42.42", 5), - ESI(), - EthernetTag(111), - MAC("01:02:03:04:05:06"), 6*8, - Labels([42], True), - IP.create("1.1.1.1"), - IP.pton("10.10.10.10")) - nlri5 = EVPNMAC(RouteDistinguisher.fromElements("42.42.42.42", 5), - ESI(), - EthernetTag(111), - MAC("01:02:03:04:05:06"), 6*8, - Labels([42], True), - IP.create("1.1.1.1"), - IP.pton("11.11.11.11")) + nlri4 = EVPNMAC( + RouteDistinguisher.fromElements("42.42.42.42", 5), + ESI(), + EthernetTag(111), + MAC("01:02:03:04:05:06"), + 6 * 8, + Labels([42], True), + IP.create("1.1.1.1"), + IP.pton("10.10.10.10"), + ) + nlri5 = EVPNMAC( + RouteDistinguisher.fromElements("42.42.42.42", 5), + ESI(), + EthernetTag(111), + MAC("01:02:03:04:05:06"), + 6 * 8, + Labels([42], True), + IP.create("1.1.1.1"), + IP.pton("11.11.11.11"), + ) self.assertEqual(hash(nlri0), hash(nlri1)) self.assertEqual(hash(nlri0), hash(nlri2)) @@ -263,13 +287,10 @@ def test101_EVPNHashEqual_somefieldsvary(self): def test99_RTCCreatePackUnpack(self): '''Test pack/unpack for RTC routes''' - nlri = RTC.new(AFI.ipv4, SAFI.rtc, - 64512, - RouteTarget(64577,123)) + nlri = RTC.new(AFI.ipv4, SAFI.rtc, 64512, RouteTarget(64577, 123)) packed = nlri.pack() - unpacked,leftover = RTC.unpack_nlri(AFI.ipv4, SAFI.mpls_vpn, - packed, OUT.UNSET, None) + unpacked, leftover = RTC.unpack_nlri(AFI.ipv4, SAFI.mpls_vpn, packed, OUT.UNSET, None) self.assertEqual(0, len(leftover)) @@ -287,12 +308,10 @@ def test99_RTCCreatePackUnpack(self): def test98_RTCWildcardPackUnpack(self): '''Test pack/unpack for RTC routes''' - nlri = RTC.new(AFI.ipv4, SAFI.rtc, - 0, None) + nlri = RTC.new(AFI.ipv4, SAFI.rtc, 0, None) packed = nlri.pack() - unpacked,leftover = RTC.unpack_nlri(AFI.ipv4, SAFI.mpls_vpn, - packed, OUT.UNSET, None) + unpacked, leftover = RTC.unpack_nlri(AFI.ipv4, SAFI.mpls_vpn, packed, OUT.UNSET, None) self.assertEqual(0, len(leftover)) @@ -305,7 +324,6 @@ def test98_RTCWildcardPackUnpack(self): self.assertIsNone(unpacked.rt) - # tests on attributes def test4_DistinctAttributes(self): @@ -381,5 +399,6 @@ def test12_RTRecord(self): rt = RouteTarget(64512, 22) rt_record = RTRecord.from_rt(rt) + if __name__ == '__main__': unittest.main() diff --git a/qa/tests/open_test.py b/qa/tests/open_test.py index e2444c43d..d1543e909 100755 --- a/qa/tests/open_test.py +++ b/qa/tests/open_test.py @@ -26,41 +26,86 @@ from exabgp.util.test import data_from_body from exabgp.configuration.environment import environment + environment.setup('') -open_body = [0x4, 0xff, 0xfe, 0x0, 0xb4, 0x0, 0x0, 0x0, 0x0, 0x20, 0x2, 0x6, 0x1, 0x4, 0x0, 0x1, 0x0, 0x1, 0x2, 0x6, 0x1, 0x4, 0x0, 0x2, 0x0, 0x1, 0x2, 0x2, 0x80, 0x0, 0x2, 0x2, 0x2, 0x0, 0x2, 0x6, 0x41, 0x4, 0x0, 0x0, 0xff, 0xfe] +open_body = [ + 0x4, + 0xFF, + 0xFE, + 0x0, + 0xB4, + 0x0, + 0x0, + 0x0, + 0x0, + 0x20, + 0x2, + 0x6, + 0x1, + 0x4, + 0x0, + 0x1, + 0x0, + 0x1, + 0x2, + 0x6, + 0x1, + 0x4, + 0x0, + 0x2, + 0x0, + 0x1, + 0x2, + 0x2, + 0x80, + 0x0, + 0x2, + 0x2, + 0x2, + 0x0, + 0x2, + 0x6, + 0x41, + 0x4, + 0x0, + 0x0, + 0xFF, + 0xFE, +] + -class TestData (unittest.TestCase): +class TestData(unittest.TestCase): + def test_1_open(self): + check_capa = { + 1: [(AFI.ipv4, SAFI.unicast), (AFI.ipv6, SAFI.unicast)], + 2: RouteRefresh(), + 65: 65534, + 128: RouteRefresh(), + } - def test_1_open (self): - check_capa = { - 1: [(AFI.ipv4, SAFI.unicast), (AFI.ipv6, SAFI.unicast)], - 2: RouteRefresh(), - 65: 65534, - 128: RouteRefresh(), - } + message_id = 1 + negotiated = {'invalid': 'test'} - message_id = 1 - negotiated = {'invalid':'test'} + o = Message.unpack(message_id, data_from_body(open_body), negotiated) - o = Message.unpack(message_id,data_from_body(open_body),negotiated) + self.assertEqual(o.version, 4) + self.assertEqual(o.asn, 65534) + self.assertEqual(o.router_id, RouterID('0.0.0.0')) + self.assertEqual(o.hold_time, 180) + for k, v in o.capabilities.items(): + self.assertEqual(v, check_capa[k]) - self.assertEqual(o.version,4) - self.assertEqual(o.asn,65534) - self.assertEqual(o.router_id,RouterID('0.0.0.0')) - self.assertEqual(o.hold_time,180) - for k,v in o.capabilities.items(): - self.assertEqual(v,check_capa[k]) + def test_2_open(self): + capabilities = Capabilities() + o = Open(Version(4), ASN(65500), HoldTime(180), RouterID('127.0.0.1'), capabilities) + self.assertEqual(o.version, 4) + self.assertEqual(o.asn, 65500) + self.assertEqual(o.router_id, RouterID('127.0.0.1')) + self.assertEqual(o.hold_time, 180) + self.assertEqual(o.capabilities, {}) - def test_2_open (self): - capabilities = Capabilities() - o = Open(Version(4),ASN(65500),HoldTime(180),RouterID('127.0.0.1'),capabilities) - self.assertEqual(o.version,4) - self.assertEqual(o.asn,65500) - self.assertEqual(o.router_id,RouterID('127.0.0.1')) - self.assertEqual(o.hold_time,180) - self.assertEqual(o.capabilities, {}) if __name__ == '__main__': - unittest.main() + unittest.main() diff --git a/qa/tests/parsing_test.py b/qa/tests/parsing_test.py index a48c430c3..42d1b3d5d 100755 --- a/qa/tests/parsing_test.py +++ b/qa/tests/parsing_test.py @@ -18,6 +18,7 @@ from exabgp.configuration.check import check_neighbor from exabgp.configuration.setup import environment + environ = environment.setup('') environ.log.enable = True environ.log.all = False @@ -25,26 +26,27 @@ environ.log.parser = False -class TestControl (unittest.TestCase): - def setUp (self): - location = os.path.abspath(os.path.join(os.path.dirname(__file__),'..','conf','*.conf')) - self.files = glob.glob(location) +class TestControl(unittest.TestCase): + def setUp(self): + location = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'conf', '*.conf')) + self.files = glob.glob(location) + + # These files contains invalid attribute we can not parse + skip = 'attributes.conf' - # These files contains invalid attribute we can not parse - skip = 'attributes.conf' + def test_all_configuration(self): + for filename in self.files: + if filename.endswith(self.skip): + continue + print('-' * 80) + print(filename) + print('=' * 80) + sys.stdout.flush() + configuration = Configuration([filename,]) + configuration.reload() + self.assertEqual(check_neighbor(configuration.neighbors), True) + del configuration - def test_all_configuration (self): - for filename in self.files: - if filename.endswith(self.skip): - continue - print('-'*80) - print(filename) - print('='*80) - sys.stdout.flush() - configuration = Configuration([filename,]) - configuration.reload() - self.assertEqual(check_neighbor(configuration.neighbors),True) - del configuration if __name__ == '__main__': - unittest.main() + unittest.main() diff --git a/qa/tests/protocol.py b/qa/tests/protocol.py index 45edb431a..67e8e2184 100755 --- a/qa/tests/protocol.py +++ b/qa/tests/protocol.py @@ -14,6 +14,7 @@ from exabgp.bgp.message import Open from exabgp.bgp.message.open import Capabilities + # from exabgp.bgp.message import Notification from exabgp.bgp.message import KeepAlive from exabgp.bgp.message import Update @@ -26,12 +27,13 @@ from exabgp.vendoring.six.moves import StringIO from exabgp.configuration.environment import environment + environment.setup('') -class Network (StringIO): - def pending (self): - return True +class Network(StringIO): + def pending(self): + return True # route1 = Update([],[to_NLRI('10.0.0.1','32')],Attributes()) @@ -50,89 +52,89 @@ def pending (self): # routes.sort() -class TestProtocol (unittest.TestCase): - - def setUp (self): - self.neighbor = Neighbor() - self.neighbor.local_as = ASN(65000) - self.neighbor.peer_as = ASN(65000) - # self.neighbor.peer_address = InetIP('1.2.3.4') - # self.neighbor.local_address = InetIP('5.6.7.8') - - def test_1_selfparse_open (self): - # ds = Open(4,65000,'1.2.3.4',Capabilities().default(),30) - # - # txt = ds.message() - # network = Network(txt) - # print [hex(ord(c)) for c in txt] - # bgp = Protocol(self.neighbor,network) - # bgp.follow = False - - # o = bgp.read_open('127.0.0.1') - # self.assertEqual(o.version,4) - # self.assertEqual(o.asn,65000) - # self.assertEqual(o.hold_time,30) - # self.assertEqual(str(o.router_id),'1.2.3.4') - pass - - def test_2_selfparse_KeepAlive (self): - # ds = KeepAlive() - # - # txt = ds.message() - # network = Network(txt) - # bgp = Protocol(self.neighbor,network) - - # message = bgp.read_message() - # self.assertEqual(message.TYPE,KeepAlive.TYPE) - pass - - def test_3_parse_update (self): - # txt = ''.join([chr(c) for c in [0x0, 0x0, 0x0, 0x1c, 0x40, 0x1, 0x1, 0x2, 0x40, 0x2, 0x0, 0x40, 0x3, 0x4, 0xc0, 0x0, 0x2, 0xfe, 0x80, 0x4, 0x4, 0x0, 0x0, 0x0, 0x0, 0x40, 0x5, 0x4, 0x0, 0x0, 0x1, 0x23, 0x20, 0x52, 0xdb, 0x0, 0x7, 0x20, 0x52, 0xdb, 0x0, 0x45, 0x20, 0x52, 0xdb, 0x0, 0x47]]) - # updates = new_Update(txt) - # - # routes = [str(route) for route in updates.added()] - # routes.sort() - # self.assertEqual(routes[0],'82.219.0.69/32 next-hop 192.0.2.254') - # self.assertEqual(routes[1],'82.219.0.7/32 next-hop 192.0.2.254') - # self.assertEqual(routes[2],'82.219.0.71/32 next-hop 192.0.2.254') - pass - - def test_4_parse_update (self): - # txt = ''.join([chr(c) for c in [0x0, 0x0, 0x0, 0x12, 0x40, 0x1, 0x1, 0x0, 0x40, 0x2, 0x4, 0x2, 0x1, 0x78, 0x14, 0x40, 0x3, 0x4, 0x52, 0xdb, 0x2, 0xb5, 0x0]]) - # updates = new_Update(txt) - # self.assertEqual(str(updates.added()[0]),'0.0.0.0/0 next-hop 82.219.2.181') - pass - - def test_6_holdtime (self): - # class MyPeer(Network): - # _data = StringIO(Open(4,65000,'1.2.3.4',Capabilities().default(),90).message()) - # def read (self, l): - # return self._data.read(l) - # - # network = MyPeer('') - # - # bgp = Protocol(self.neighbor,network) - # bgp.follow = False - # - # before = bgp.neighbor.hold_time - # bgp.new_open() - # bgp.read_open('127.0.0.1') - # after = bgp.neighbor.hold_time - # - # self.assertEqual(after,min(before,90)) - pass - - def test_7_message (self): - # txt = ''.join([chr(_) for _ in [0x0, 0x0, 0x0, 0x30, 0x40, 0x1, 0x1, 0x0, 0x50, 0x2, 0x0, 0x4, 0x2, 0x1, 0xff, 0xfe, 0x80, 0x4, 0x4, 0x0, 0x0, 0x0, 0x0, 0x80, 0xe, 0x1a, 0x0, 0x2, 0x1, 0x10, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x20, 0x12, 0x34, 0x56, 0x78]]) - # updates = new_Update(txt) - # print updates - # self.assertEqual(str(updates.added()[0]),'1234:5678::/32 next-hop ::') - pass - - def test_7_ipv6 (self): - # txt = ''.join([chr(_) for _ in [0x0, 0x0, 0x0, 0x25, 0x40, 0x1, 0x1, 0x0, 0x40, 0x2, 0x4, 0x2, 0x1, 0xfd, 0xe8, 0xc0, 0x8, 0x8, 0x78, 0x14, 0x0, 0x0, 0x78, 0x14, 0x78, 0x14, 0x40, 0xf, 0xc, 0x0, 0x2, 0x1, 0x40, 0x2a, 0x2, 0xb, 0x80, 0x0, 0x0, 0x0, 0x1]]) - # updates = new_Update(txt) - pass +class TestProtocol(unittest.TestCase): + def setUp(self): + self.neighbor = Neighbor() + self.neighbor.local_as = ASN(65000) + self.neighbor.peer_as = ASN(65000) + # self.neighbor.peer_address = InetIP('1.2.3.4') + # self.neighbor.local_address = InetIP('5.6.7.8') + + def test_1_selfparse_open(self): + # ds = Open(4,65000,'1.2.3.4',Capabilities().default(),30) + # + # txt = ds.message() + # network = Network(txt) + # print [hex(ord(c)) for c in txt] + # bgp = Protocol(self.neighbor,network) + # bgp.follow = False + + # o = bgp.read_open('127.0.0.1') + # self.assertEqual(o.version,4) + # self.assertEqual(o.asn,65000) + # self.assertEqual(o.hold_time,30) + # self.assertEqual(str(o.router_id),'1.2.3.4') + pass + + def test_2_selfparse_KeepAlive(self): + # ds = KeepAlive() + # + # txt = ds.message() + # network = Network(txt) + # bgp = Protocol(self.neighbor,network) + + # message = bgp.read_message() + # self.assertEqual(message.TYPE,KeepAlive.TYPE) + pass + + def test_3_parse_update(self): + # txt = ''.join([chr(c) for c in [0x0, 0x0, 0x0, 0x1c, 0x40, 0x1, 0x1, 0x2, 0x40, 0x2, 0x0, 0x40, 0x3, 0x4, 0xc0, 0x0, 0x2, 0xfe, 0x80, 0x4, 0x4, 0x0, 0x0, 0x0, 0x0, 0x40, 0x5, 0x4, 0x0, 0x0, 0x1, 0x23, 0x20, 0x52, 0xdb, 0x0, 0x7, 0x20, 0x52, 0xdb, 0x0, 0x45, 0x20, 0x52, 0xdb, 0x0, 0x47]]) + # updates = new_Update(txt) + # + # routes = [str(route) for route in updates.added()] + # routes.sort() + # self.assertEqual(routes[0],'82.219.0.69/32 next-hop 192.0.2.254') + # self.assertEqual(routes[1],'82.219.0.7/32 next-hop 192.0.2.254') + # self.assertEqual(routes[2],'82.219.0.71/32 next-hop 192.0.2.254') + pass + + def test_4_parse_update(self): + # txt = ''.join([chr(c) for c in [0x0, 0x0, 0x0, 0x12, 0x40, 0x1, 0x1, 0x0, 0x40, 0x2, 0x4, 0x2, 0x1, 0x78, 0x14, 0x40, 0x3, 0x4, 0x52, 0xdb, 0x2, 0xb5, 0x0]]) + # updates = new_Update(txt) + # self.assertEqual(str(updates.added()[0]),'0.0.0.0/0 next-hop 82.219.2.181') + pass + + def test_6_holdtime(self): + # class MyPeer(Network): + # _data = StringIO(Open(4,65000,'1.2.3.4',Capabilities().default(),90).message()) + # def read (self, l): + # return self._data.read(l) + # + # network = MyPeer('') + # + # bgp = Protocol(self.neighbor,network) + # bgp.follow = False + # + # before = bgp.neighbor.hold_time + # bgp.new_open() + # bgp.read_open('127.0.0.1') + # after = bgp.neighbor.hold_time + # + # self.assertEqual(after,min(before,90)) + pass + + def test_7_message(self): + # txt = ''.join([chr(_) for _ in [0x0, 0x0, 0x0, 0x30, 0x40, 0x1, 0x1, 0x0, 0x50, 0x2, 0x0, 0x4, 0x2, 0x1, 0xff, 0xfe, 0x80, 0x4, 0x4, 0x0, 0x0, 0x0, 0x0, 0x80, 0xe, 0x1a, 0x0, 0x2, 0x1, 0x10, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x20, 0x12, 0x34, 0x56, 0x78]]) + # updates = new_Update(txt) + # print updates + # self.assertEqual(str(updates.added()[0]),'1234:5678::/32 next-hop ::') + pass + + def test_7_ipv6(self): + # txt = ''.join([chr(_) for _ in [0x0, 0x0, 0x0, 0x25, 0x40, 0x1, 0x1, 0x0, 0x40, 0x2, 0x4, 0x2, 0x1, 0xfd, 0xe8, 0xc0, 0x8, 0x8, 0x78, 0x14, 0x0, 0x0, 0x78, 0x14, 0x78, 0x14, 0x40, 0xf, 0xc, 0x0, 0x2, 0x1, 0x40, 0x2a, 0x2, 0xb, 0x80, 0x0, 0x0, 0x0, 0x1]]) + # updates = new_Update(txt) + pass + if __name__ == '__main__': - unittest.main() + unittest.main()