atf_test_case create cleanup
create_head()
{
atf_set "descr" "Create a lagg and assign an address"
atf_set "require.user" "root"
}
create_body()
{
local TAP0 TAP1 LAGG MAC
ADDR="192.0.2.2"
MASK="24"
TAP0=`get_tap`
TAP1=`get_tap`
LAGG=`get_lagg`
ifconfig $TAP0 up
ifconfig $TAP1 up
atf_check ifconfig $LAGG up laggport $TAP0 laggport $TAP1 \
${ADDR}/${MASK}
atf_check -o match:"inet ${ADDR}" ifconfig $LAGG
atf_check -o match:"laggport: ${TAP0}" ifconfig $LAGG
atf_check -o match:"laggport: ${TAP1}" ifconfig $LAGG
MAC=`ifconfig $LAGG | awk '/ether/ {print $2}'`
atf_check -o match:"ether ${MAC}" ifconfig $TAP0
atf_check -o match:"ether ${MAC}" ifconfig $TAP1
atf_check -o not-match:"inet6 fe80:" ifconfig $TAP0
atf_check -o not-match:"inet6 fe80:" ifconfig $TAP1
}
create_cleanup()
{
cleanup_tap_and_lagg
}
atf_test_case status_stress cleanup
status_stress_head()
{
atf_set "descr" "Simultaneously query a lagg while also creating or destroying it."
atf_set "require.user" "root"
}
status_stress_body()
{
local TAP0 TAP1 LAGG MAC
ADDR="192.0.2.2"
MASK="24"
TAP0=`get_tap`
TAP1=`get_tap`
TAP2=`get_tap`
TAP3=`get_tap`
LAGG=`get_lagg`
ifconfig $TAP0 inet6 ifdisabled up
ifconfig $TAP1 inet6 ifdisabled up
ifconfig $TAP2 inet6 ifdisabled up
ifconfig $TAP3 inet6 ifdisabled up
while true; do
ifconfig $LAGG destroy 2>&1
ifconfig $LAGG create 2>/dev/null
ifconfig $LAGG inet6 ifdisabled
ifconfig $LAGG up laggport $TAP0 laggport $TAP1 laggport $TAP2\
laggport $TAP3 ${ADDR}/${MASK} 2>/dev/null
echo -n . >> creator_count.txt
done &
CREATOR_PID=$!
while true; do
ifconfig -am 2> /dev/null > /dev/null
echo -n . >> querier_count.txt
done &
QUERIER_PID=$!
sleep 60
kill $CREATOR_PID
kill $QUERIER_PID
echo "Created the lagg `stat -f %z creator_count.txt` times."
echo "Queried its status `stat -f %z querier_count.txt` times"
}
status_stress_cleanup()
{
cleanup_tap_and_lagg
}
atf_test_case create_destroy_stress cleanup
create_destroy_stress_head()
{
atf_set "descr" "Simultaneously create and destroy a lagg"
atf_set "require.user" "root"
}
create_destroy_stress_body()
{
local TAP0 TAP1 LAGG MAC
TAP0=`get_tap`
TAP1=`get_tap`
TAP2=`get_tap`
TAP3=`get_tap`
LAGG=`get_lagg`
ifconfig $TAP0 inet6 ifdisabled up
ifconfig $TAP1 inet6 ifdisabled up
ifconfig $TAP2 inet6 ifdisabled up
ifconfig $TAP3 inet6 ifdisabled up
while true; do
ifconfig $LAGG create 2>/dev/null && \
echo -n . >> creator_count.txt
done &
CREATOR_PID=$!
while true; do
ifconfig $LAGG destroy 2>/dev/null && \
echo -n . >> destroyer_count.txt
done &
DESTROYER_PID=$!
sleep 60
kill $CREATOR_PID
kill $DESTROYER_PID
echo "Created the lagg `stat -f %z creator_count.txt` times."
echo "Destroyed it `stat -f %z destroyer_count.txt` times."
}
create_destroy_stress_cleanup()
{
cleanup_tap_and_lagg
}
atf_test_case lacp_linkstate_destroy_stress cleanup
lacp_linkstate_destroy_stress_head()
{
atf_set "descr" "Simultaneously destroy an LACP lagg and change its childrens link states"
atf_set "require.user" "root"
}
lacp_linkstate_destroy_stress_body()
{
local TAP0 TAP1 LAGG MAC SRCDIR
ADDR="192.0.2.2"
MASK="24"
MEAN_SLEEP_SECONDS=.005
MAX_SLEEP_USECS=10000
TAP0=`get_tap`
TAP1=`get_tap`
LAGG=`get_lagg`
ifconfig $TAP0 inet6 ifdisabled up
ifconfig $TAP1 inet6 ifdisabled up
SRCDIR=$( atf_get_srcdir )
while true; do
ifconfig $LAGG inet6 ifdisabled
cat /dev/$TAP0 > /dev/null &
CAT0_PID=$!
cat /dev/$TAP1 > /dev/null &
CAT1_PID=$!
ifconfig $LAGG up laggport $TAP0 laggport $TAP1 \
${ADDR}/${MASK} 2> /dev/null &&
{ sleep ${MEAN_SLEEP_SECONDS} && \
kill $CAT0_PID &&
kill $CAT1_PID &&
echo -n . >> linkstate_count.txt ; } &
{ ${SRCDIR}/randsleep ${MAX_SLEEP_USECS} && \
ifconfig $LAGG destroy &&
echo -n . >> destroy_count.txt ; } &
wait
ifconfig $LAGG create
done &
LOOP_PID=$!
sleep 60
kill $LOOP_PID
echo "Disconnected the children `stat -f %z linkstate_count.txt` times."
echo "Destroyed the lagg `stat -f %z destroy_count.txt` times."
}
lacp_linkstate_destroy_stress_cleanup()
{
cleanup_tap_and_lagg
}
atf_test_case up_destroy_stress cleanup
up_destroy_stress_head()
{
atf_set "descr" "Simultaneously up and destroy a lagg"
atf_set "require.user" "root"
}
up_destroy_stress_body()
{
local TAP0 TAP1 LAGG MAC SRCDIR
ADDR="192.0.2.2"
MASK="24"
MEAN_SLEEP_SECONDS=.005
MAX_SLEEP_USECS=10000
TAP0=`get_tap`
TAP1=`get_tap`
TAP2=`get_tap`
TAP3=`get_tap`
LAGG=`get_lagg`
ifconfig $TAP0 inet6 ifdisabled up
ifconfig $TAP1 inet6 ifdisabled up
ifconfig $TAP2 inet6 ifdisabled up
ifconfig $TAP3 inet6 ifdisabled up
SRCDIR=$( atf_get_srcdir )
while true; do
ifconfig $LAGG inet6 ifdisabled
{ sleep ${MEAN_SLEEP_SECONDS} && \
ifconfig $LAGG up laggport $TAP0 laggport $TAP1 \
laggport $TAP2 laggport $TAP3 \
${ADDR}/${MASK} 2> /dev/null &&
echo -n . >> up_count.txt ; } &
{ ${SRCDIR}/randsleep ${MAX_SLEEP_USECS} && \
ifconfig $LAGG destroy &&
echo -n . >> destroy_count.txt ; } &
wait
ifconfig $LAGG create
done &
LOOP_PID=$!
sleep 60
kill $LOOP_PID
echo "Upped the lagg `stat -f %z up_count.txt` times."
echo "Destroyed it `stat -f %z destroy_count.txt` times."
}
up_destroy_stress_cleanup()
{
cleanup_tap_and_lagg
}
atf_test_case set_ether cleanup
set_ether_head()
{
atf_set "descr" "Set a lagg's ethernet address"
atf_set "require.user" "root"
}
set_ether_body()
{
local TAP0 TAP1 LAGG MAC
ADDR="192.0.2.2"
MASK="24"
MAC="00:11:22:33:44:55"
TAP0=`get_tap`
TAP1=`get_tap`
LAGG=`get_lagg`
ifconfig $TAP0 up
ifconfig $TAP1 up
atf_check ifconfig $LAGG up laggport $TAP0 laggport $TAP1 \
${ADDR}/${MASK}
atf_check ifconfig $LAGG ether ${MAC}
atf_check -o match:"ether ${MAC}" ifconfig $LAGG
atf_check -o match:"ether ${MAC}" ifconfig $TAP0
atf_check -o match:"ether ${MAC}" ifconfig $TAP1
}
set_ether_cleanup()
{
cleanup_tap_and_lagg
}
atf_test_case updown cleanup
updown_head()
{
atf_set "descr" "upping or downing a lagg ups or downs its children"
atf_set "require.user" "root"
}
updown_body()
{
local TAP0 TAP1 LAGG MAC
ADDR="192.0.2.2"
MASK="24"
MAC="00:11:22:33:44:55"
TAP0=`get_tap`
TAP1=`get_tap`
LAGG=`get_lagg`
ifconfig $TAP0 up
ifconfig $TAP1 up
atf_check ifconfig $LAGG up laggport $TAP0 laggport $TAP1 \
${ADDR}/${MASK}
ifconfig $LAGG down
atf_check -o not-match:"flags=.*\<UP\>" ifconfig $LAGG
atf_check -o not-match:"flags=.*\<UP\>" ifconfig $TAP0
atf_check -o not-match:"flags=.*\<UP\>" ifconfig $TAP1
ifconfig $LAGG up
atf_check -o match:"flags=.*\<UP\>" ifconfig $LAGG
atf_check -o match:"flags=.*\<UP\>" ifconfig $TAP0
atf_check -o match:"flags=.*\<UP\>" ifconfig $TAP1
atf_check -o not-match:"inet6 fe80:" ifconfig $TAP0
atf_check -o not-match:"inet6 fe80:" ifconfig $TAP1
}
updown_cleanup()
{
cleanup_tap_and_lagg
}
atf_test_case witness
witness_head()
{
atf_set "descr" "Check witness(4) for lock-order reversals in if_lagg"
}
witness_body()
{
if [ "$(atf_config_get ci false)" = "true" ]; then
atf_skip "https://bugs.freebsd.org/244163 and https://bugs.freebsd.org/251726"
fi
if [ `sysctl -n debug.witness.watch` -ne 1 ]; then
atf_skip "witness(4) is not enabled"
fi
if `sysctl -n debug.witness.badstacks | grep -q 'at lagg_'`; then
sysctl debug.witness.badstacks
atf_fail "Lock-order reversals involving if_lagg.c detected"
fi
}
atf_init_test_cases()
{
atf_add_test_case create
atf_add_test_case create_destroy_stress
atf_add_test_case lacp_linkstate_destroy_stress
atf_add_test_case set_ether
atf_add_test_case status_stress
atf_add_test_case up_destroy_stress
atf_add_test_case updown
atf_add_test_case witness
}
get_tap()
{
local TAPN=0
while ! ifconfig tap${TAPN} create > /dev/null 2>&1; do
if [ "$TAPN" -ge 8 ]; then
atf_skip "Could not create a tap(4) interface"
else
TAPN=$(($TAPN + 1))
fi
done
local TAPD=tap${TAPN}
echo ${TAPD} >> "devices_to_cleanup"
echo ${TAPD}
}
get_lagg()
{
local LAGGN=0
while ! ifconfig lagg${LAGGN} create > /dev/null 2>&1; do
if [ "$LAGGN" -ge 8 ]; then
atf_skip "Could not create a lagg(4) interface"
else
LAGGN=$(($LAGGN + 1))
fi
done
local LAGGD=lagg${LAGGN}
echo ${LAGGD} >> "devices_to_cleanup"
echo ${LAGGD}
}
cleanup_tap_and_lagg()
{
local DEV
for DEV in `cat "devices_to_cleanup"`; do
ifconfig ${DEV} destroy
done
true
}