Skip to content

Commit 2a719b7

Browse files
pmachatakuba-moo
authored andcommitted
selftests: forwarding: lib: Move smcrouted helpers here
router_multicast.sh has several helpers for work with smcrouted. Extract them to lib.sh so that other selftests can use them as well. Convert the helpers to defer in the process, because that simplifies the interface quite a bit. Therefore have router_multicast.sh invoke defer_scopes_cleanup() in its cleanup() function. Signed-off-by: Petr Machata <[email protected]> Link: https://patch.msgid.link/410411c1a81225ce6e44542289b9c3ec21e5786c.1750113335.git.petrm@nvidia.com Signed-off-by: Jakub Kicinski <[email protected]>
1 parent f8337ef commit 2a719b7

File tree

2 files changed

+39
-29
lines changed

2 files changed

+39
-29
lines changed

tools/testing/selftests/net/forwarding/lib.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ declare -A NETIFS=(
3737
: "${TEAMD:=teamd}"
3838
: "${MCD:=smcrouted}"
3939
: "${MC_CLI:=smcroutectl}"
40+
: "${MCD_TABLE_NAME:=selftests}"
4041

4142
# Constants for netdevice bring-up:
4243
# Default time in seconds to wait for an interface to come up before giving up
@@ -1757,6 +1758,38 @@ mc_send()
17571758
msend -g $groups -I $if_name -c 1 > /dev/null 2>&1
17581759
}
17591760

1761+
adf_mcd_start()
1762+
{
1763+
local table_name="$MCD_TABLE_NAME"
1764+
local smcroutedir
1765+
local pid
1766+
local i
1767+
1768+
check_command "$MCD" || return 1
1769+
check_command "$MC_CLI" || return 1
1770+
1771+
smcroutedir=$(mktemp -d)
1772+
defer rm -rf "$smcroutedir"
1773+
1774+
for ((i = 1; i <= NUM_NETIFS; ++i)); do
1775+
echo "phyint ${NETIFS[p$i]} enable" >> \
1776+
"$smcroutedir/$table_name.conf"
1777+
done
1778+
1779+
"$MCD" -N -I "$table_name" -f "$smcroutedir/$table_name.conf" \
1780+
-P "$smcroutedir/$table_name.pid"
1781+
busywait "$BUSYWAIT_TIMEOUT" test -e "$smcroutedir/$table_name.pid"
1782+
pid=$(cat "$smcroutedir/$table_name.pid")
1783+
defer kill_process "$pid"
1784+
}
1785+
1786+
mc_cli()
1787+
{
1788+
local table_name="$MCD_TABLE_NAME"
1789+
1790+
"$MC_CLI" -I "$table_name" "$@"
1791+
}
1792+
17601793
start_ip_monitor()
17611794
{
17621795
local mtype=$1; shift

tools/testing/selftests/net/forwarding/router_multicast.sh

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ NUM_NETIFS=6
3333
source lib.sh
3434
source tc_common.sh
3535

36-
require_command $MCD
37-
require_command $MC_CLI
38-
table_name=selftests
39-
4036
h1_create()
4137
{
4238
simple_if_init $h1 198.51.100.2/28 2001:db8:1::2/64
@@ -149,25 +145,6 @@ router_destroy()
149145
ip link set dev $rp1 down
150146
}
151147

152-
start_mcd()
153-
{
154-
SMCROUTEDIR="$(mktemp -d)"
155-
156-
for ((i = 1; i <= $NUM_NETIFS; ++i)); do
157-
echo "phyint ${NETIFS[p$i]} enable" >> \
158-
$SMCROUTEDIR/$table_name.conf
159-
done
160-
161-
$MCD -N -I $table_name -f $SMCROUTEDIR/$table_name.conf \
162-
-P $SMCROUTEDIR/$table_name.pid
163-
}
164-
165-
kill_mcd()
166-
{
167-
pkill $MCD
168-
rm -rf $SMCROUTEDIR
169-
}
170-
171148
setup_prepare()
172149
{
173150
h1=${NETIFS[p1]}
@@ -179,7 +156,7 @@ setup_prepare()
179156
rp3=${NETIFS[p5]}
180157
h3=${NETIFS[p6]}
181158

182-
start_mcd
159+
adf_mcd_start || exit "$EXIT_STATUS"
183160

184161
vrf_prepare
185162

@@ -206,27 +183,27 @@ cleanup()
206183

207184
vrf_cleanup
208185

209-
kill_mcd
186+
defer_scopes_cleanup
210187
}
211188

212189
create_mcast_sg()
213190
{
214191
local if_name=$1; shift
215192
local s_addr=$1; shift
216193
local mcast=$1; shift
217-
local dest_ifs=${@}
194+
local dest_ifs=("${@}")
218195

219-
$MC_CLI -I $table_name add $if_name $s_addr $mcast $dest_ifs
196+
mc_cli add "$if_name" "$s_addr" "$mcast" "${dest_ifs[@]}"
220197
}
221198

222199
delete_mcast_sg()
223200
{
224201
local if_name=$1; shift
225202
local s_addr=$1; shift
226203
local mcast=$1; shift
227-
local dest_ifs=${@}
204+
local dest_ifs=("${@}")
228205

229-
$MC_CLI -I $table_name remove $if_name $s_addr $mcast $dest_ifs
206+
mc_cli remove "$if_name" "$s_addr" "$mcast" "${dest_ifs[@]}"
230207
}
231208

232209
mcast_v4()

0 commit comments

Comments
 (0)