From: Rafael Zalamena Date: Mon, 3 Jul 2017 18:57:20 +0000 (-0300) Subject: topotest: implement 'ip route' functions X-Git-Tag: frr-7.1-dev~151^2~260 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=99a7a912fd475ff953587f8cefa4585596bb306f;p=matthieu%2Ffrr.git topotest: implement 'ip route' functions Implement an abstraction to the commands 'ip route' to get the node current routing table state. --- diff --git a/tests/topotests/lib/topotest.py b/tests/topotests/lib/topotest.py index fba0407970..1b5f7eed49 100644 --- a/tests/topotests/lib/topotest.py +++ b/tests/topotests/lib/topotest.py @@ -287,6 +287,83 @@ def version_cmp(v1, v2): return -1 return 0 +def ip4_route(node): + """ + Gets a structured return of the command 'ip route'. It can be used in + conjuction with json_cmp() to provide accurate assert explanations. + + Return example: + { + '10.0.1.0/24': { + 'dev': 'eth0', + 'via': '172.16.0.1', + 'proto': '188', + }, + '10.0.2.0/24': { + 'dev': 'eth1', + 'proto': 'kernel', + } + } + """ + output = normalize_text(node.run('ip route')).splitlines() + result = {} + for line in output: + columns = line.split(' ') + route = result[columns[0]] = {} + prev = None + for column in columns: + if prev == 'dev': + route['dev'] = column + if prev == 'via': + route['via'] = column + if prev == 'proto': + route['proto'] = column + if prev == 'metric': + route['metric'] = column + if prev == 'scope': + route['scope'] = column + prev = column + + return result + +def ip6_route(node): + """ + Gets a structured return of the command 'ip -6 route'. It can be used in + conjuction with json_cmp() to provide accurate assert explanations. + + Return example: + { + '2001:db8:1::/64': { + 'dev': 'eth0', + 'proto': '188', + }, + '2001:db8:2::/64': { + 'dev': 'eth1', + 'proto': 'kernel', + } + } + """ + output = normalize_text(node.run('ip -6 route')).splitlines() + result = {} + for line in output: + columns = line.split(' ') + route = result[columns[0]] = {} + prev = None + for column in columns: + if prev == 'dev': + route['dev'] = column + if prev == 'via': + route['via'] = column + if prev == 'proto': + route['proto'] = column + if prev == 'metric': + route['metric'] = column + if prev == 'pref': + route['pref'] = column + prev = column + + return result + def checkAddressSanitizerError(output, router, component): "Checks for AddressSanitizer in output. If found, then logs it and returns true, false otherwise"