Skip to content

Commit

Permalink
use setup_ns
Browse files Browse the repository at this point in the history
Signed-off-by: Geliang Tang <[email protected]>
  • Loading branch information
Geliang Tang committed May 24, 2024
1 parent 03958fc commit 0cc494b
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 45 deletions.
16 changes: 7 additions & 9 deletions tools/testing/selftests/net/big_tcp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@
# Testing For IPv4 and IPv6 BIG TCP.
# TOPO: CLIENT_NS (link0)<--->(link1) ROUTER_NS (link2)<--->(link3) SERVER_NS

CLIENT_NS=$(mktemp -u client-XXXXXXXX)
source lib.sh

CLIENT_NS=""
CLIENT_IP4="198.51.100.1"
CLIENT_IP6="2001:db8:1::1"

SERVER_NS=$(mktemp -u server-XXXXXXXX)
SERVER_NS=""
SERVER_IP4="203.0.113.1"
SERVER_IP6="2001:db8:2::1"

ROUTER_NS=$(mktemp -u router-XXXXXXXX)
ROUTER_NS=""
SERVER_GW4="203.0.113.2"
CLIENT_GW4="198.51.100.2"
SERVER_GW6="2001:db8:2::2"
Expand All @@ -25,9 +27,7 @@ CHK_SIZE=65535
ksft_skip=4

setup() {
ip netns add $CLIENT_NS
ip netns add $SERVER_NS
ip netns add $ROUTER_NS
setup_ns CLIENT_NS SERVER_NS ROUTER_NS
ip -net $ROUTER_NS link add link1 type veth peer name link0 netns $CLIENT_NS
ip -net $ROUTER_NS link add link2 type veth peer name link3 netns $SERVER_NS

Expand Down Expand Up @@ -83,9 +83,7 @@ cleanup() {
ip net exec $SERVER_NS pkill netserver
ip -net $ROUTER_NS link del link1
ip -net $ROUTER_NS link del link2
ip netns del "$CLIENT_NS"
ip netns del "$SERVER_NS"
ip netns del "$ROUTER_NS"
cleanup_all_ns
}

start_counter() {
Expand Down
14 changes: 6 additions & 8 deletions tools/testing/selftests/net/io_uring_zerocopy_tx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
# Send data between two processes across namespaces
# Run twice: once without and once with zerocopy

source lib.sh

set -e

readonly DEV="veth0"
readonly DEV_MTU=65535
readonly BIN_TX="./io_uring_zerocopy_tx"
readonly BIN_RX="./msg_zerocopy"

readonly RAND="$(mktemp -u XXXXXX)"
readonly NSPREFIX="ns-${RAND}"
readonly NS1="${NSPREFIX}1"
readonly NS2="${NSPREFIX}2"
NS1=""
NS2=""

readonly SADDR4='192.168.1.1'
readonly DADDR4='192.168.1.2'
Expand Down Expand Up @@ -78,15 +78,13 @@ esac
# Start of state changes: install cleanup handler

cleanup() {
ip netns del "${NS2}"
ip netns del "${NS1}"
cleanup_ns "${NS1}" "${NS2}"
}

trap cleanup EXIT

# Create virtual ethernet pair between network namespaces
ip netns add "${NS1}"
ip netns add "${NS2}"
setup_ns NS1 NS2

# Configure system settings
ip netns exec "${NS1}" sysctl -w -q "${path_sysctl_mem}=1000000"
Expand Down
9 changes: 5 additions & 4 deletions tools/testing/selftests/net/rps_default_mask.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0

source lib.sh

readonly ksft_skip=4
readonly cpus=$(nproc)
ret=0
Expand All @@ -10,16 +12,15 @@ ret=0
readonly INITIAL_RPS_DEFAULT_MASK=$(cat /proc/sys/net/core/rps_default_mask)
readonly TAG="$(mktemp -u XXXXXX)"
readonly VETH="veth${TAG}"
readonly NETNS="ns-${TAG}"
NETNS=""

setup() {
ip netns add "${NETNS}"
ip -netns "${NETNS}" link set lo up
setup_ns NETNS
}

cleanup() {
echo $INITIAL_RPS_DEFAULT_MASK > /proc/sys/net/core/rps_default_mask
ip netns del $NETNS
cleanup_all_ns
}

chk_rps() {
Expand Down
18 changes: 6 additions & 12 deletions tools/testing/selftests/net/so_txtime.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,26 @@
#
# Regression tests for the SO_TXTIME interface

source lib.sh

set -e

readonly ksft_skip=4
readonly DEV="veth0"
readonly BIN="./so_txtime"

readonly RAND="$(mktemp -u XXXXXX)"
readonly NSPREFIX="ns-${RAND}"
readonly NS1="${NSPREFIX}1"
readonly NS2="${NSPREFIX}2"
NS1=""
NS2=""

readonly SADDR4='192.168.1.1'
readonly DADDR4='192.168.1.2'
readonly SADDR6='fd::1'
readonly DADDR6='fd::2'

cleanup() {
ip netns del "${NS2}"
ip netns del "${NS1}"
}

trap cleanup EXIT
trap cleanup_all_ns EXIT

# Create virtual ethernet pair between network namespaces
ip netns add "${NS1}"
ip netns add "${NS2}"
setup_ns NS1 NS2

ip link add "${DEV}" netns "${NS1}" type veth \
peer name "${DEV}" netns "${NS2}"
Expand Down
20 changes: 12 additions & 8 deletions tools/testing/selftests/net/srv6_end_flavors_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@
# after the IPv6 header. At this point, the packet with IPv6 DA=cafe::1 is sent
# to the destination, i.e. hs-1.

source lib.sh

# Kselftest framework requirement - SKIP code is 4.
readonly ksft_skip=4

Expand Down Expand Up @@ -778,14 +780,15 @@ test_kernel_supp_or_ksft_skip()
{
local flavor="$1"
local test_netns
local kflv

test_netns="kflv-$(mktemp -u XXXXXXXX)"

if ! ip netns add "${test_netns}"; then
if ! setup_ns kflv; then
echo "SKIP: Cannot set up netns to test kernel support for flavors"
exit "${ksft_skip}"
fi

test_netns=${kflv}

if ! ip -netns "${test_netns}" link \
add "${DUMMY_DEVNAME}" type dummy; then
echo "SKIP: Cannot set up dummy dev to test kernel support for flavors"
Expand All @@ -811,20 +814,21 @@ test_kernel_supp_or_ksft_skip()
exit "${ksft_skip}"
fi

ip netns del "${test_netns}"
cleanup_ns "${test_netns}"
}

test_dummy_dev_or_ksft_skip()
{
local test_netns
local dummy

test_netns="dummy-$(mktemp -u XXXXXXXX)"

if ! ip netns add "${test_netns}"; then
if ! setup_ns dummy; then
echo "SKIP: Cannot set up netns for testing dummy dev support"
exit "${ksft_skip}"
fi

test_netns=${dummy}

modprobe dummy &>/dev/null || true
if ! ip -netns "${test_netns}" link \
add "${DUMMY_DEVNAME}" type dummy; then
Expand All @@ -834,7 +838,7 @@ test_dummy_dev_or_ksft_skip()
exit "${ksft_skip}"
fi

ip netns del "${test_netns}"
cleanup_ns "${test_netns}"
}

if [ "$(id -u)" -ne 0 ]; then
Expand Down
11 changes: 7 additions & 4 deletions tools/testing/selftests/net/srv6_end_x_next_csid_l3vpn_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@
# packet using the SRv6 End.DT46 behavior (associated with the SID fcff:1::d46)
# and sends it to the host hs-1.

source lib.sh

# Kselftest framework requirement - SKIP code is 4.
readonly ksft_skip=4

Expand Down Expand Up @@ -1153,14 +1155,15 @@ test_iproute2_supp_or_ksft_skip()
test_dummy_dev_or_ksft_skip()
{
local test_netns
local dummy=""

test_netns="dummy-$(mktemp -u XXXXXXXX)"

if ! ip netns add "${test_netns}"; then
if ! setup_ns dummy; then
echo "SKIP: Cannot set up netns for testing dummy dev support"
exit "${ksft_skip}"
fi

test_netns=${dummy}

modprobe dummy &>/dev/null || true
if ! ip -netns "${test_netns}" link \
add "${DUMMY_DEVNAME}" type dummy; then
Expand All @@ -1170,7 +1173,7 @@ test_dummy_dev_or_ksft_skip()
exit "${ksft_skip}"
fi

ip netns del "${test_netns}"
cleanup_ns "${test_netns}"
}

test_vrf_or_ksft_skip()
Expand Down

0 comments on commit 0cc494b

Please sign in to comment.