aboutsummaryrefslogtreecommitdiff
path: root/tools/testing/selftests/rdma/rxe_ipv6.sh
blob: b7059bfd6d7c51d19c8f1370fbe36de1e98fcdc0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/bash

# Configuration
NS_NAME="net6"
VETH_HOST="veth0"
VETH_NS="veth1"
RXE_NAME="rxe6"
PORT=4791
IP6_ADDR="2001:db8::1/64"

exec > /dev/null

# Cleanup function to run on exit (even on failure)
cleanup() {
    ip netns del "$NS_NAME" 2>/dev/null
    modprobe -r rdma_rxe 2>/dev/null
    echo "Done."
}
trap cleanup EXIT

# 1. Prerequisites check
for mod in tun veth rdma_rxe; do
    if ! modinfo "$mod" >/dev/null 2>&1; then
        echo "Error: Kernel module '$mod' not found."
        exit 1
    fi
done

modprobe rdma_rxe

# 2. Setup Namespace and Networking
echo "Setting up IPv6 network namespace..."
ip netns add "$NS_NAME"
ip link add "$VETH_HOST" type veth peer name "$VETH_NS"
ip link set "$VETH_NS" netns "$NS_NAME"
ip netns exec "$NS_NAME" ip addr add "$IP6_ADDR" dev "$VETH_NS"
ip netns exec "$NS_NAME" ip link set "$VETH_NS" up
ip link set "$VETH_HOST" up

# 3. Add RDMA Link
echo "Adding RDMA RXE link..."
if ! ip netns exec "$NS_NAME" rdma link add "$RXE_NAME" type rxe netdev "$VETH_NS"; then
    echo "Error: Failed to create RXE link."
    exit 1
fi

# 4. Verification: Port should be listening
# Using -H to skip headers and -q for quiet exit codes
if ! ip netns exec "$NS_NAME" ss -Hul6n sport = :$PORT | grep -q ":$PORT"; then
    echo "Error: UDP port $PORT is NOT listening after link creation."
    exit 1
fi
echo "Verified: Port $PORT is active."

# 5. Removal and Verification
echo "Deleting RDMA link..."
ip netns exec "$NS_NAME" rdma link del "$RXE_NAME"

if ip netns exec "$NS_NAME" ss -Hul6n sport = :$PORT | grep -q ":$PORT"; then
    echo "Error: UDP port $PORT still active after link deletion."
    exit 1
fi
echo "Verified: Port $PORT closed successfully."