test: Add show routes (ipv4 and ipv6) to test CLI test suite

This commit is contained in:
Mattias Walström
2024-01-09 03:56:17 +01:00
committed by Joachim Wiberg
parent 35d74cecd4
commit 7cce19d45c
9 changed files with 298 additions and 28 deletions
@@ -399,7 +399,6 @@ def ietf_routing(json, ip="ipv4"):
if rib["name"] != ip:
continue;
routes = get_json_data(None, rib, "routes", "route")
if routes:
for r in routes:
route = Route(r, ip)
+13 -7
View File
@@ -129,7 +129,6 @@ def get_routes(routes, proto, data):
host_prefix_length="128"
for d in data:
new = {}
if(d['dst'] == "default"):
d['dst'] = default
if(d['dst'].find('/') == -1):
@@ -167,13 +166,20 @@ def get_routes(routes, proto, data):
out['route'].append(new)
insert(routes, 'routes', out)
def add_ipv4_route(routes):
cmd = ['ip', '-4', '-s', '-d', '-j', 'route']
def add_ipv4_route(routes, test):
if test:
cmd = ['cat', f"{test}/ip-4-route.json"]
else:
cmd = ['ip', '-4', '-s', '-d', '-j', 'route']
data = run_json_cmd(cmd)
get_routes(routes, "ipv4", data)
def add_ipv6_route(routes):
cmd = ['ip', '-6', '-s', '-d', '-j', 'route']
def add_ipv6_route(routes, test):
if test:
cmd = ['cat', f"{test}/ip-6-route.json"]
else:
cmd = ['ip', '-6', '-s', '-d', '-j', 'route']
data = run_json_cmd(cmd)
get_routes(routes, "ipv6", data)
@@ -526,8 +532,8 @@ if __name__ == "__main__":
ipv4routes = yang_data['ietf-routing:routing']['ribs']['rib'][0]
ipv6routes = yang_data['ietf-routing:routing']['ribs']['rib'][1]
add_ipv4_route(ipv4routes)
add_ipv6_route(ipv6routes)
add_ipv4_route(ipv4routes, args.test)
add_ipv6_route(ipv6routes, args.test)
elif (args.model == 'ietf-ospf'):
yang_data= {
"ietf-routing:routing": {
@@ -0,0 +1,13 @@
PREFIX NEXT-HOP PREF PROTOCOL 
10.0.0.1/32 10.0.13.1 20 ospf
10.0.0.2/32 10.0.23.1 20 ospf
10.0.0.4/32 10.0.13.1 20 ospf
10.0.23.1
10.0.12.0/30 10.0.13.1 20 ospf
10.0.23.1
10.0.13.0/30 eth3 0 kernel
10.0.23.0/30 eth4 0 kernel
10.0.24.0/30 10.0.23.1 20 ospf
10.0.41.0/30 10.0.13.1 20 ospf
192.168.4.0/24 10.0.13.1 20 ospf
10.0.23.1
@@ -0,0 +1,10 @@
PREFIX NEXT-HOP PREF PROTOCOL 
2001:db8:3c4d:50::/64 eth4 256 kernel
2001:db8:3c4d:200::1/128 lo 256 kernel
fe80::/64 eth5 256 kernel
fe80::/64 eth3 256 kernel
fe80::/64 eth2 256 kernel
fe80::/64 eth1 256 kernel
fe80::/64 eth0 256 kernel
fe80::/64 eth4 256 kernel
::/0 2001:db8:3c4d:50::1 20 static
+41 -10
View File
@@ -33,7 +33,7 @@ print_update_txt() {
echo "# the template file."
echo
echo "# Here's how you update the CLI output templates:"
echo "# $SCRIPT_PATH/run.sh update"
echo "# $SCRIPT_PATH/run.sh update <model>"
echo
echo "# Check the result"
echo "# git diff"
@@ -47,28 +47,58 @@ if [ ! -e "$CLI_PRETTY_TOOL" ]; then
exit 1
fi
if [ $# -eq 1 ] && [ $1 = "update" ]; then
"$SR_EMULATOR_TOOL" | "$CLI_PRETTY_TOOL" "ietf-interfaces" > "$CLI_OUTPUT_PATH/show-interfaces.txt"
for iface in "br0" "e0" "e1" "e2" "e3" "e4"; do
"$SR_EMULATOR_TOOL" | "$CLI_PRETTY_TOOL" "ietf-interfaces" -n "$iface" \
> "$CLI_OUTPUT_PATH/show-interface-${iface}.txt"
done
echo "All files updated. Check git diff and commit if they look OK"
if [ $# -eq 2 ] && [ $1 = "update" ]; then
if [ $2 = "ietf-interfaces" ]; then
"$SR_EMULATOR_TOOL" | "$CLI_PRETTY_TOOL" "ietf-interfaces" > "$CLI_OUTPUT_PATH/show-interfaces.txt"
for iface in "br0" "e0" "e1" "e2" "e3" "e4"; do
"$SR_EMULATOR_TOOL" | "$CLI_PRETTY_TOOL" "ietf-interfaces" -n "$iface" \
> "$CLI_OUTPUT_PATH/show-interface-${iface}.txt"
done
elif [ $2 = "ietf-routing" ]; then
"$SR_EMULATOR_TOOL" | "$CLI_PRETTY_TOOL" "ietf-routing" -n "ipv4" > "$CLI_OUTPUT_PATH/show-routes-ipv4.txt"
"$SR_EMULATOR_TOOL" | "$CLI_PRETTY_TOOL" "ietf-routing" -n "ipv6" > "$CLI_OUTPUT_PATH/show-routes-ipv6.txt"
else
echo "Unsupported model $2"
exit 1
fi
echo "All files updated. Check git diff and commit if they look OK"
exit 0
fi
echo "1..7"
echo "1..9"
echo "# Running:"
# Show interfaces
echo "# Running:"
echo "# $SR_EMULATOR_TOOL | $CLI_PRETTY_TOOL ietf-interfaces"
"$SR_EMULATOR_TOOL" | "$CLI_PRETTY_TOOL" "ietf-interfaces" > "$CLI_OUTPUT_FILE"
# Show routes
if ! diff -u "$CLI_OUTPUT_PATH/show-interfaces.txt" "$CLI_OUTPUT_FILE"; then
print_update_txt
fail "\"show interfaces\" output has changed"
fi
ok "\"show interfaces\" output looks intact"
# Show ipv4 routes
echo "# $SR_EMULATOR_TOOL | $CLI_PRETTY_TOOL ietf-routing -n ipv4"
"$SR_EMULATOR_TOOL" | "$CLI_PRETTY_TOOL" "ietf-routing" -n "ipv4" > "$CLI_OUTPUT_FILE"
# Show routes
if ! diff -u "$CLI_OUTPUT_PATH/show-routes-ipv4.txt" "$CLI_OUTPUT_FILE"; then
print_update_txt
fail "\"show routes ipv4\" output has changed"
fi
ok "\"show routes ipv4\" output looks intact"
# Show ipv6 routes
echo "# $SR_EMULATOR_TOOL | $CLI_PRETTY_TOOL ietf-routing -n ipv6"
"$SR_EMULATOR_TOOL" | "$CLI_PRETTY_TOOL" "ietf-routing" -n "ipv6" > "$CLI_OUTPUT_FILE"
# Show routes
if ! diff -u "$CLI_OUTPUT_PATH/show-routes-ipv6.txt" "$CLI_OUTPUT_FILE"; then
print_update_txt
fail "\"show routes ipv6\" output has changed"
fi
ok "\"show routes ipv6\" output looks intact"
# Show detailed interfaces
for iface in "br0" "e0" "e1" "e2" "e3" "e4"; do
"$SR_EMULATOR_TOOL" | "$CLI_PRETTY_TOOL" "ietf-interfaces" -n "$iface" > "$CLI_OUTPUT_FILE"
@@ -78,3 +108,4 @@ for iface in "br0" "e0" "e1" "e2" "e3" "e4"; do
fi
ok "\"show interface name $iface\" output looks intact"
done
+13 -5
View File
@@ -7,10 +7,12 @@ YANGER_TOOL="$ROOT_PATH/board/netconf/rootfs/libexec/infix/yanger"
INTERFACES="br0 e0 e1 e2 e3 e4"
YANGER_OUTPUT_FILE="$(mktemp)"
INTERFACE_OUTPUT_FILE="$(mktemp)"
INTERFACES_OUTPUT_FILE="$(mktemp)"
ROUTES_OUTPUT_FILE="$(mktemp)"
cleanup() {
rm -f "$YANGER_OUTPUT_FILE"
rm -f "$INTERFACE_OUTPUT_FILE"
rm -f "$ROUTES_OUTPUT_FILE"
}
trap cleanup EXIT
@@ -19,10 +21,11 @@ if [ ! -e "$YANGER_TOOL" ]; then
exit 1
fi
for iface in $INTERFACES; do
if ! "$YANGER_TOOL" "ietf-interfaces" \
-t "$SCRIPT_PATH/system-output/" \
-p "$iface" >> "$YANGER_OUTPUT_FILE"; then
-p "$iface" >> "$INTERFACE_OUTPUT_FILE"; then
echo "Error, running yanger for interface $iface" >&2
exit 1
fi
@@ -31,7 +34,12 @@ done
if ! jq -s 'reduce .[] as $item
({}; .["ietf-interfaces:interfaces"].interface +=
$item["ietf-interfaces:interfaces"].interface)' \
"$YANGER_OUTPUT_FILE"; then
"$INTERFACE_OUTPUT_FILE" >> $INTERFACES_OUTPUT_FILE; then
echo "Error, merging yanger output data" >&2
exit 1
fi
$YANGER_TOOL "ietf-routing" -t "$SCRIPT_PATH/system-output/" > "$ROUTES_OUTPUT_FILE"
# Merge all module files
jq -s '.[0] * .[1]' $ROUTES_OUTPUT_FILE $INTERFACES_OUTPUT_FILE
+207
View File
@@ -0,0 +1,207 @@
[
{
"type": "unicast",
"dst": "10.0.0.1",
"nhid": 33,
"gateway": "10.0.13.1",
"dev": "eth3",
"protocol": "ospf",
"scope": "global",
"metric": 20,
"flags": [],
"nh_info": {
"id": 33,
"gateway": "10.0.13.1",
"dev": "eth3",
"scope": "link",
"protocol": "zebra",
"flags": []
}
},
{
"type": "unicast",
"dst": "10.0.0.2",
"nhid": 34,
"gateway": "10.0.23.1",
"dev": "eth4",
"protocol": "ospf",
"scope": "global",
"metric": 20,
"flags": [],
"nh_info": {
"id": 34,
"gateway": "10.0.23.1",
"dev": "eth4",
"scope": "link",
"protocol": "zebra",
"flags": []
}
},
{
"type": "unicast",
"dst": "10.0.0.4",
"nhid": 35,
"protocol": "ospf",
"scope": "global",
"metric": 20,
"flags": [],
"nh_info": {
"id": 35,
"group": [
{
"id": 33
},
{
"id": 34
}
],
"scope": "global",
"protocol": "zebra",
"flags": []
},
"nexthops": [
{
"gateway": "10.0.13.1",
"dev": "eth3",
"weight": 1,
"flags": []
},
{
"gateway": "10.0.23.1",
"dev": "eth4",
"weight": 1,
"flags": []
}
]
},
{
"type": "unicast",
"dst": "10.0.12.0/30",
"nhid": 35,
"protocol": "ospf",
"scope": "global",
"metric": 20,
"flags": [],
"nh_info": {
"id": 35,
"group": [
{
"id": 33
},
{
"id": 34
}
],
"scope": "global",
"protocol": "zebra",
"flags": []
},
"nexthops": [
{
"gateway": "10.0.13.1",
"dev": "eth3",
"weight": 1,
"flags": []
},
{
"gateway": "10.0.23.1",
"dev": "eth4",
"weight": 1,
"flags": []
}
]
},
{
"type": "unicast",
"dst": "10.0.13.0/30",
"dev": "eth3",
"protocol": "kernel",
"scope": "link",
"prefsrc": "10.0.13.2",
"flags": []
},
{
"type": "unicast",
"dst": "10.0.23.0/30",
"dev": "eth4",
"protocol": "kernel",
"scope": "link",
"prefsrc": "10.0.23.2",
"flags": []
},
{
"type": "unicast",
"dst": "10.0.24.0/30",
"nhid": 34,
"gateway": "10.0.23.1",
"dev": "eth4",
"protocol": "ospf",
"scope": "global",
"metric": 20,
"flags": [],
"nh_info": {
"id": 34,
"gateway": "10.0.23.1",
"dev": "eth4",
"scope": "link",
"protocol": "zebra",
"flags": []
}
},
{
"type": "unicast",
"dst": "10.0.41.0/30",
"nhid": 33,
"gateway": "10.0.13.1",
"dev": "eth3",
"protocol": "ospf",
"scope": "global",
"metric": 20,
"flags": [],
"nh_info": {
"id": 33,
"gateway": "10.0.13.1",
"dev": "eth3",
"scope": "link",
"protocol": "zebra",
"flags": []
}
},
{
"type": "unicast",
"dst": "192.168.4.0/24",
"nhid": 35,
"protocol": "ospf",
"scope": "global",
"metric": 20,
"flags": [],
"nh_info": {
"id": 35,
"group": [
{
"id": 33
},
{
"id": 34
}
],
"scope": "global",
"protocol": "zebra",
"flags": []
},
"nexthops": [
{
"gateway": "10.0.13.1",
"dev": "eth3",
"weight": 1,
"flags": []
},
{
"gateway": "10.0.23.1",
"dev": "eth4",
"weight": 1,
"flags": []
}
]
}
]
@@ -0,0 +1 @@
[{"type":"unicast","dst":"2001:db8:3c4d:50::/64","dev":"eth4","protocol":"kernel","scope":"global","metric":256,"flags":[],"pref":"medium"},{"type":"unicast","dst":"2001:db8:3c4d:200::1","dev":"lo","protocol":"kernel","scope":"global","metric":256,"flags":[],"pref":"medium"},{"type":"unicast","dst":"fe80::/64","dev":"eth5","protocol":"kernel","scope":"global","metric":256,"flags":[],"pref":"medium"},{"type":"unicast","dst":"fe80::/64","dev":"eth3","protocol":"kernel","scope":"global","metric":256,"flags":[],"pref":"medium"},{"type":"unicast","dst":"fe80::/64","dev":"eth2","protocol":"kernel","scope":"global","metric":256,"flags":[],"pref":"medium"},{"type":"unicast","dst":"fe80::/64","dev":"eth1","protocol":"kernel","scope":"global","metric":256,"flags":[],"pref":"medium"},{"type":"unicast","dst":"fe80::/64","dev":"eth0","protocol":"kernel","scope":"global","metric":256,"flags":[],"pref":"medium"},{"type":"unicast","dst":"fe80::/64","dev":"eth4","protocol":"kernel","scope":"global","metric":256,"flags":[],"pref":"medium"},{"type":"unicast","dst":"default","nhid":23,"gateway":"2001:db8:3c4d:50::1","dev":"eth4","protocol":"static","scope":"global","metric":20,"flags":[],"pref":"medium","nh_info":{"id":23,"gateway":"2001:db8:3c4d:50::1","dev":"eth4","scope":"link","protocol":"zebra","flags":[]}}]
-5
View File
@@ -37,8 +37,3 @@
- "json/bloated.json"
- "ietf-interfaces"
- "-n br0"
- case: run.sh
name: "routing"
opts:
- "json/bloated.json"
- "ietf-routing"