Skip to content

Commit

Permalink
test: refactor mrcache.sh to handle both IPv4 and IPv6
Browse files Browse the repository at this point in the history
This change does not only reduce the number of test files, it removes a
hardcoded limitation of expected VIF values for interfaces.  Achieved by
moving from the /proc interface to `ip [-6] mroute` instead.

Signed-off-by: Joachim Wiberg <[email protected]>
  • Loading branch information
troglobit committed Jul 28, 2023
1 parent 5c05368 commit cd79cc3
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 77 deletions.
3 changes: 1 addition & 2 deletions test/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
EXTRA_DIST = adv.sh basic.sh batch.sh bridge.sh dyn.sh expire.sh gre.sh ipv6.sh
EXTRA_DIST += include.sh isolated.sh join.sh joinlen.sh lib.sh lost.sh
EXTRA_DIST += multi.sh mem.sh mrcache.sh mrcache6.sh mrdisc.sh poison.sh
EXTRA_DIST += multi.sh mem.sh mrcache.sh mrdisc.sh poison.sh
EXTRA_DIST += reload.sh reload6.sh vlan.sh vrfy.sh
CLEANFILES = *~ *.trs *.log
TEST_EXTENSIONS = .sh
Expand All @@ -21,7 +21,6 @@ TESTS += joinlen.sh
TESTS += lost.sh
TESTS += mem.sh
TESTS += mrcache.sh
TESTS += mrcache6.sh
TESTS += mrdisc.sh
TESTS += multi.sh
TESTS += poison.sh
Expand Down
5 changes: 5 additions & 0 deletions test/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ FAIL()
exit 99
}

CHECK()
{
[ "$@" ] || FAIL "$*"
}

OK()
{
print "TEST: OK"
Expand Down
81 changes: 58 additions & 23 deletions test/mrcache.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,75 @@
#!/bin/sh
# Verifies IPv4 (S,G) add and remove route via IPC bites in kernel.
# Twist: uses only one interface, inteded to mimic Debian test.
# Verifies both IPv4 and IPv6 (S,G) add, including remove route via IPC bites in kernel.
# Twist: uses only one interface, inteded to mimic Debian tests.
#set -x

# shellcheck source=/dev/null
. "$(dirname "$0")/lib.sh"

debug()
{
echo "/proc/net/ip_mr_cache -------------------------------------------------------DEBUG-"
cat /proc/net/ip_mr_cache
echo "ip mroute -------------------------------------------------------------------DEBUG-"
ip mroute
echo "-----------------------------------------------------------------------------------"
echo "smcroutectl -----------------------------------------------------------------DEBUG-"
../src/smcroutectl -pd -u "/tmp/$NM/sock"
echo "-----------------------------------------------------------------------------DEBUG/"
}

check_add()
{
s=$1
g=$2
input=$3
output=$4

print "Adding IPC route ($s,$g) inbound $input outbound $output ..."
../src/smcroutectl -u "/tmp/$NM/sock" add "$input" "$s" "$g" "$output"
# sleep 1

print "Verifying kernel route ($s,$g) Iif: $input Oif: $output ..."
# debug
ip mroute > "/tmp/$NM/routes"
ip -6 mroute >> "/tmp/$NM/routes"
sg=$(awk "/$s,$g/{print \$1}" "/tmp/$NM/routes")
iif=$(awk "/$s,$g/{print \$3}" "/tmp/$NM/routes")
oif=$(awk "/$s,$g/{print \$5}" "/tmp/$NM/routes")
state=$(awk "/$s,$g/{print \$7}" "/tmp/$NM/routes")
CHECK "$sg" = "($s,$g)"
CHECK "$iif" = "$input"
CHECK "$oif" = "$output"
CHECK "$state" = "resolved"
}

check_del()
{
s=$1
g=$2
input=$3
output=$4

print "Removing IPC route ($s,$g) inbound $input outbound $output ..."
../src/smcroutectl -u "/tmp/$NM/sock" del "$input" "$s" "$g"
# sleep 1

print "Verifying kernel route for ($s,$g) has been removed ..."
#debug
ip mroute > "/tmp/$NM/routes2"
sg=$(awk "/$s,$g/{print \$1}" "/tmp/$NM/routes2")
CHECK -z "$sg"
}

test_one()
{
check_add $1 $2 $3 $4
check_del $1 $2 $3 $4
}

print "Creating world ..."
topo basic
ip addr add 10.0.0.1/24 dev a1
ip addr add fc01::1/64 dev a1
ip -br a

print "Creating config ..."
Expand All @@ -29,24 +82,6 @@ print "Starting smcrouted ..."
../src/smcrouted -f "/tmp/$NM/conf" -n -P "/tmp/$NM/pid" -l debug -u "/tmp/$NM/sock" &
sleep 1

print "Adding IPC route ..."
../src/smcroutectl -u "/tmp/$NM/sock" add a1 10.0.0.1 224.0.1.20 a1
sleep 1

print "Verifying kernel route ..."
debug
if ! grep "140100E0 0100000A 2 0 0 0 2:1" /proc/net/ip_mr_cache; then
FAIL
fi

print "Removing IPC route ..."
../src/smcroutectl -u "/tmp/$NM/sock" del a1 10.0.0.1 224.0.1.20
sleep 1

print "Verifying kernel route ..."
debug
if grep "140100E0 0100000A" /proc/net/ip_mr_cache; then
FAIL
fi

test_one 10.0.0.1 224.0.1.20 a1 a1
test_one fc01::1 ff01::114 a1 a1
OK
52 changes: 0 additions & 52 deletions test/mrcache6.sh

This file was deleted.

0 comments on commit cd79cc3

Please sign in to comment.