Commit 59cac2ef authored by Hangbin Liu's avatar Hangbin Liu Committed by Jakub Kicinski

selftests/net: convert srv6_end_dt46_l3vpn_test.sh to run it in unique namespace

As the name \${rt-${rt}} may make reader confuse, convert the variable
hs/rt in setup_rt/hs to hid, rid. Here is the test result after conversion.

 ]# ./srv6_end_dt46_l3vpn_test.sh

 ################################################################################
 TEST SECTION: IPv6 routers connectivity test
 ################################################################################

     TEST: Routers connectivity: rt-1 -> rt-2                            [ OK ]

     TEST: Routers connectivity: rt-2 -> rt-1                            [ OK ]

 ...

     TEST: IPv4 Hosts isolation: hs-t200-4 -X-> hs-t100-2                [ OK ]

 Tests passed:  34
 Tests failed:   0
Signed-off-by: default avatarHangbin Liu <liuhangbin@gmail.com>
Link: https://lore.kernel.org/r/20231213060856.4030084-3-liuhangbin@gmail.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent b6925b4e
...@@ -193,8 +193,7 @@ ...@@ -193,8 +193,7 @@
# +---------------------------------------------------+ # +---------------------------------------------------+
# #
# Kselftest framework requirement - SKIP code is 4. source lib.sh
ksft_skip=4
readonly LOCALSID_TABLE_ID=90 readonly LOCALSID_TABLE_ID=90
readonly IPv6_RT_NETWORK=fd00 readonly IPv6_RT_NETWORK=fd00
...@@ -250,26 +249,22 @@ cleanup() ...@@ -250,26 +249,22 @@ cleanup()
ip link del veth-rt-1 2>/dev/null || true ip link del veth-rt-1 2>/dev/null || true
ip link del veth-rt-2 2>/dev/null || true ip link del veth-rt-2 2>/dev/null || true
# destroy routers rt-* and hosts hs-* cleanup_all_ns
for ns in $(ip netns show | grep -E 'rt-*|hs-*'); do
ip netns del ${ns} || true
done
} }
# Setup the basic networking for the routers # Setup the basic networking for the routers
setup_rt_networking() setup_rt_networking()
{ {
local rt=$1 local id=$1
local nsname=rt-${rt} eval local nsname=\${rt_${id}}
ip netns add ${nsname} ip link set veth-rt-${id} netns ${nsname}
ip link set veth-rt-${rt} netns ${nsname} ip -netns ${nsname} link set veth-rt-${id} name veth0
ip -netns ${nsname} link set veth-rt-${rt} name veth0
ip netns exec ${nsname} sysctl -wq net.ipv6.conf.all.accept_dad=0 ip netns exec ${nsname} sysctl -wq net.ipv6.conf.all.accept_dad=0
ip netns exec ${nsname} sysctl -wq net.ipv6.conf.default.accept_dad=0 ip netns exec ${nsname} sysctl -wq net.ipv6.conf.default.accept_dad=0
ip -netns ${nsname} addr add ${IPv6_RT_NETWORK}::${rt}/64 dev veth0 nodad ip -netns ${nsname} addr add ${IPv6_RT_NETWORK}::${id}/64 dev veth0 nodad
ip -netns ${nsname} link set veth0 up ip -netns ${nsname} link set veth0 up
ip -netns ${nsname} link set lo up ip -netns ${nsname} link set lo up
...@@ -279,16 +274,14 @@ setup_rt_networking() ...@@ -279,16 +274,14 @@ setup_rt_networking()
setup_hs() setup_hs()
{ {
local hs=$1 local hid=$1
local rt=$2 local rid=$2
local tid=$3 local tid=$3
local hsname=hs-t${tid}-${hs} eval local hsname=\${hs_t${tid}_${hid}}
local rtname=rt-${rt} eval local rtname=\${rt_${rid}}
local rtveth=veth-t${tid} local rtveth=veth-t${tid}
# set the networking for the host # set the networking for the host
ip netns add ${hsname}
ip netns exec ${hsname} sysctl -wq net.ipv6.conf.all.accept_dad=0 ip netns exec ${hsname} sysctl -wq net.ipv6.conf.all.accept_dad=0
ip netns exec ${hsname} sysctl -wq net.ipv6.conf.default.accept_dad=0 ip netns exec ${hsname} sysctl -wq net.ipv6.conf.default.accept_dad=0
...@@ -299,8 +292,8 @@ setup_hs() ...@@ -299,8 +292,8 @@ setup_hs()
ip -netns ${hsname} link add veth0 type veth peer name ${rtveth} ip -netns ${hsname} link add veth0 type veth peer name ${rtveth}
ip -netns ${hsname} link set ${rtveth} netns ${rtname} ip -netns ${hsname} link set ${rtveth} netns ${rtname}
ip -netns ${hsname} addr add ${IPv6_HS_NETWORK}::${hs}/64 dev veth0 nodad ip -netns ${hsname} addr add ${IPv6_HS_NETWORK}::${hid}/64 dev veth0 nodad
ip -netns ${hsname} addr add ${IPv4_HS_NETWORK}.${hs}/24 dev veth0 ip -netns ${hsname} addr add ${IPv4_HS_NETWORK}.${hid}/24 dev veth0
ip -netns ${hsname} link set veth0 up ip -netns ${hsname} link set veth0 up
ip -netns ${hsname} link set lo up ip -netns ${hsname} link set lo up
...@@ -332,10 +325,8 @@ setup_vpn_config() ...@@ -332,10 +325,8 @@ setup_vpn_config()
local rtdst=$4 local rtdst=$4
local tid=$5 local tid=$5
local hssrc_name=hs-t${tid}-${hssrc} eval local rtsrc_name=\${rt_${rtsrc}}
local hsdst_name=hs-t${tid}-${hsdst} eval local rtdst_name=\${rt_${rtdst}}
local rtsrc_name=rt-${rtsrc}
local rtdst_name=rt-${rtdst}
local rtveth=veth-t${tid} local rtveth=veth-t${tid}
local vpn_sid=${VPN_LOCATOR_SERVICE}:${hssrc}${hsdst}:${tid}::6046 local vpn_sid=${VPN_LOCATOR_SERVICE}:${hssrc}${hsdst}:${tid}::6046
...@@ -379,18 +370,21 @@ setup() ...@@ -379,18 +370,21 @@ setup()
{ {
ip link add veth-rt-1 type veth peer name veth-rt-2 ip link add veth-rt-1 type veth peer name veth-rt-2
# setup the networking for router rt-1 and router rt-2 # setup the networking for router rt-1 and router rt-2
setup_ns rt_1 rt_2
setup_rt_networking 1 setup_rt_networking 1
setup_rt_networking 2 setup_rt_networking 2
# setup two hosts for the tenant 100. # setup two hosts for the tenant 100.
# - host hs-1 is directly connected to the router rt-1; # - host hs-1 is directly connected to the router rt-1;
# - host hs-2 is directly connected to the router rt-2. # - host hs-2 is directly connected to the router rt-2.
setup_ns hs_t100_1 hs_t100_2
setup_hs 1 1 100 #args: host router tenant setup_hs 1 1 100 #args: host router tenant
setup_hs 2 2 100 setup_hs 2 2 100
# setup two hosts for the tenant 200 # setup two hosts for the tenant 200
# - host hs-3 is directly connected to the router rt-1; # - host hs-3 is directly connected to the router rt-1;
# - host hs-4 is directly connected to the router rt-2. # - host hs-4 is directly connected to the router rt-2.
setup_ns hs_t200_3 hs_t200_4
setup_hs 3 1 200 setup_hs 3 1 200
setup_hs 4 2 200 setup_hs 4 2 200
...@@ -409,8 +403,9 @@ check_rt_connectivity() ...@@ -409,8 +403,9 @@ check_rt_connectivity()
{ {
local rtsrc=$1 local rtsrc=$1
local rtdst=$2 local rtdst=$2
eval local nsname=\${rt_${rtsrc}}
ip netns exec rt-${rtsrc} ping -c 1 -W 1 ${IPv6_RT_NETWORK}::${rtdst} \ ip netns exec ${nsname} ping -c 1 -W 1 ${IPv6_RT_NETWORK}::${rtdst} \
>/dev/null 2>&1 >/dev/null 2>&1
} }
...@@ -428,8 +423,9 @@ check_hs_ipv6_connectivity() ...@@ -428,8 +423,9 @@ check_hs_ipv6_connectivity()
local hssrc=$1 local hssrc=$1
local hsdst=$2 local hsdst=$2
local tid=$3 local tid=$3
eval local nsname=\${hs_t${tid}_${hssrc}}
ip netns exec hs-t${tid}-${hssrc} ping -c 1 -W ${PING_TIMEOUT_SEC} \ ip netns exec ${nsname} ping -c 1 -W ${PING_TIMEOUT_SEC} \
${IPv6_HS_NETWORK}::${hsdst} >/dev/null 2>&1 ${IPv6_HS_NETWORK}::${hsdst} >/dev/null 2>&1
} }
...@@ -438,8 +434,9 @@ check_hs_ipv4_connectivity() ...@@ -438,8 +434,9 @@ check_hs_ipv4_connectivity()
local hssrc=$1 local hssrc=$1
local hsdst=$2 local hsdst=$2
local tid=$3 local tid=$3
eval local nsname=\${hs_t${tid}_${hssrc}}
ip netns exec hs-t${tid}-${hssrc} ping -c 1 -W ${PING_TIMEOUT_SEC} \ ip netns exec ${nsname} ping -c 1 -W ${PING_TIMEOUT_SEC} \
${IPv4_HS_NETWORK}.${hsdst} >/dev/null 2>&1 ${IPv4_HS_NETWORK}.${hsdst} >/dev/null 2>&1
} }
......
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