Commit 1ef90733 authored by Ondřej Zajíček's avatar Ondřej Zajíček

Tests: Add script to sort output of show route command

There are several nondeterministic aspects affecting the order of items
in output of show route command. Link local addresses affect order of
next hops, order of convergence affects order of routes, and hash
function details affects order of nets. We sort it (hierarchically on
multiple levels) to keep it stable.
parent c1e11023
#!/bin/sh
. tests/strip_output
cd $1 && ./birdc -l show route $2 $3 \
| strip_version \
| strip_timestamp \
| strip_addresses \
| strip_interfaces_on
\ No newline at end of file
| ../tests/sort_show_route
#!/usr/bin/env python3
# Sort output of BIRD 'show route' command
#
# Process lines to a list of networks. Each network is a tuple of a opening line
# and a list of routes. Each route is a tuple of an opening line and a list of
# nexthops. Keep list of currently parsed nets / rtes / nhs, and sort them when
# respective part is done. Note that na opening line of the best route of each
# network is empty string, as the route description is in the opening line of
# the net.
import sys
import re
active_net = '';
active_rte = '';
nets = []
rtes = []
nhs = []
g = sys.modules[__name__]
def first(a):
(f,_) = a
return f
def end_rte():
nhs.sort()
rtes.append((active_rte, nhs))
g.active_rte = ''
g.nhs = []
def end_net():
end_rte()
rtes.sort(key=first)
nets.append((active_net, rtes))
g.active_net = ''
g.rtes = []
def end_nets():
end_net()
nets.sort(key=first)
print_nets(nets)
g.nets = []
def rcv_net(s):
if active_net:
end_net()
g.active_net = s
def rcv_rte(s):
if active_rte or active_net:
end_rte()
g.active_rte = s
def rcv_nh(s):
nhs.append(s)
def rcv_rest(s):
if active_net:
end_nets()
print(s)
def print_nets(nets):
for (net, rtes) in nets:
print(net)
for (rte, nhs) in rtes:
if rte:
print(rte)
for nh in nhs:
print(nh)
for line in sys.stdin:
line = line.rstrip('\n')
if re.match("^[0-9a-f]", line):
rcv_net(line)
elif re.match("^ {20}", line):
rcv_rte(line)
elif re.match("^\t(via|dev)", line):
rcv_nh(line)
else:
rcv_rest(line)
if active_net:
end_nets()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment