2018-04-04 13:46:41 +00:00
|
|
|
# Network configuration
|
|
|
|
TARGET_INTERFACE="spdk_tgt_int"
|
|
|
|
INITIATOR_INTERFACE="spdk_init_int"
|
2018-04-25 16:16:08 +00:00
|
|
|
TARGET_NAMESPACE="spdk_iscsi_ns"
|
2020-02-20 10:24:53 +00:00
|
|
|
TARGET_NS_CMD=(ip netns exec "$TARGET_NAMESPACE")
|
2018-04-04 13:46:41 +00:00
|
|
|
|
2018-03-27 13:17:53 +00:00
|
|
|
# iSCSI target configuration
|
2018-04-04 13:46:41 +00:00
|
|
|
TARGET_IP=10.0.0.1
|
|
|
|
INITIATOR_IP=10.0.0.2
|
2018-03-27 13:17:53 +00:00
|
|
|
ISCSI_PORT=3260
|
2018-04-25 16:16:08 +00:00
|
|
|
NETMASK=$INITIATOR_IP/32
|
2018-03-27 13:17:53 +00:00
|
|
|
INITIATOR_TAG=2
|
|
|
|
INITIATOR_NAME=ANY
|
2018-03-27 13:56:16 +00:00
|
|
|
PORTAL_TAG=1
|
2020-02-20 10:24:53 +00:00
|
|
|
ISCSI_APP=("${TARGET_NS_CMD[@]}" "${ISCSI_APP[@]}")
|
2018-06-25 12:44:59 +00:00
|
|
|
if [ $SPDK_TEST_VPP -eq 1 ]; then
|
2020-02-20 10:24:53 +00:00
|
|
|
ISCSI_APP+=(-L sock_vpp)
|
2018-06-25 12:44:59 +00:00
|
|
|
fi
|
2018-03-27 13:17:53 +00:00
|
|
|
ISCSI_TEST_CORE_MASK=0xFF
|
2018-04-04 13:46:41 +00:00
|
|
|
|
|
|
|
function create_veth_interfaces() {
|
2018-04-23 07:04:15 +00:00
|
|
|
# $1 = test type (posix/vpp)
|
2018-04-25 16:16:08 +00:00
|
|
|
ip netns del $TARGET_NAMESPACE || true
|
2018-04-04 13:46:41 +00:00
|
|
|
ip link delete $INITIATOR_INTERFACE || true
|
|
|
|
|
2019-08-09 08:46:01 +00:00
|
|
|
trap 'cleanup_veth_interfaces $1; exit 1' SIGINT SIGTERM EXIT
|
2018-06-22 12:15:59 +00:00
|
|
|
|
2018-04-04 13:46:41 +00:00
|
|
|
# Create veth (Virtual ethernet) interface pair
|
|
|
|
ip link add $INITIATOR_INTERFACE type veth peer name $TARGET_INTERFACE
|
|
|
|
ip addr add $INITIATOR_IP/24 dev $INITIATOR_INTERFACE
|
|
|
|
ip link set $INITIATOR_INTERFACE up
|
|
|
|
|
2018-04-25 16:16:08 +00:00
|
|
|
# Create and add interface for target to network namespace
|
|
|
|
ip netns add $TARGET_NAMESPACE
|
|
|
|
ip link set $TARGET_INTERFACE netns $TARGET_NAMESPACE
|
|
|
|
|
2018-08-10 13:21:42 +00:00
|
|
|
# Accept connections from veth interface
|
|
|
|
iptables -I INPUT 1 -i $INITIATOR_INTERFACE -p tcp --dport $ISCSI_PORT -j ACCEPT
|
|
|
|
|
2020-02-20 10:24:53 +00:00
|
|
|
"${TARGET_NS_CMD[@]}" ip link set $TARGET_INTERFACE up
|
2018-04-04 13:46:41 +00:00
|
|
|
|
2018-06-25 12:44:59 +00:00
|
|
|
if [ "$1" == "posix" ]; then
|
2020-02-20 10:24:53 +00:00
|
|
|
"${TARGET_NS_CMD[@]}" ip link set lo up
|
|
|
|
"${TARGET_NS_CMD[@]}" ip addr add $TARGET_IP/24 dev $TARGET_INTERFACE
|
2018-06-25 12:44:59 +00:00
|
|
|
|
|
|
|
# Verify connectivity
|
|
|
|
ping -c 1 $TARGET_IP
|
|
|
|
ip netns exec $TARGET_NAMESPACE ping -c 1 $INITIATOR_IP
|
|
|
|
else
|
|
|
|
start_vpp
|
|
|
|
fi
|
2018-04-04 13:46:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function cleanup_veth_interfaces() {
|
2018-04-23 07:04:15 +00:00
|
|
|
# $1 = test type (posix/vpp)
|
2018-06-25 12:44:59 +00:00
|
|
|
if [ "$1" == "vpp" ]; then
|
|
|
|
kill_vpp
|
|
|
|
fi
|
2018-04-23 07:04:15 +00:00
|
|
|
|
2018-04-25 16:16:08 +00:00
|
|
|
# Cleanup veth interfaces and network namespace
|
2018-04-04 13:46:41 +00:00
|
|
|
# Note: removing one veth, removes the pair
|
|
|
|
ip link delete $INITIATOR_INTERFACE
|
2018-04-25 16:16:08 +00:00
|
|
|
ip netns del $TARGET_NAMESPACE
|
2018-04-04 13:46:41 +00:00
|
|
|
}
|
2019-05-06 22:46:30 +00:00
|
|
|
|
|
|
|
function iscsitestinit() {
|
|
|
|
if [ "$1" == "iso" ]; then
|
|
|
|
$rootdir/scripts/setup.sh
|
2019-07-25 13:01:09 +00:00
|
|
|
if [ -n "$2" ]; then
|
2019-05-06 22:46:30 +00:00
|
|
|
create_veth_interfaces $2
|
|
|
|
else
|
|
|
|
# default to posix
|
|
|
|
create_veth_interfaces "posix"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-06-17 07:23:20 +00:00
|
|
|
function waitforiscsidevices() {
|
|
|
|
local num=$1
|
|
|
|
|
|
|
|
for ((i=1; i<=20; i++)); do
|
2019-11-05 13:21:11 +00:00
|
|
|
n=$( iscsiadm -m session -P 3 | grep -c "Attached scsi disk sd[a-z]*" || true)
|
2019-06-17 07:23:20 +00:00
|
|
|
if [ $n -ne $num ]; then
|
|
|
|
sleep 0.1
|
|
|
|
else
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2019-05-06 22:46:30 +00:00
|
|
|
function iscsitestfini() {
|
|
|
|
if [ "$1" == "iso" ]; then
|
2019-07-25 13:01:09 +00:00
|
|
|
if [ -n "$2" ]; then
|
2019-05-06 22:46:30 +00:00
|
|
|
cleanup_veth_interfaces $2
|
|
|
|
else
|
|
|
|
# default to posix
|
|
|
|
cleanup_veth_interfaces "posix"
|
|
|
|
fi
|
|
|
|
$rootdir/scripts/setup.sh reset
|
|
|
|
fi
|
|
|
|
}
|
2018-06-25 12:44:59 +00:00
|
|
|
|
|
|
|
function start_vpp() {
|
|
|
|
# We need to make sure that posix side doesn't send jumbo packets while
|
|
|
|
# for VPP side maximal size of MTU for TCP is 1460 and tests doesn't work
|
|
|
|
# stable with larger packets
|
|
|
|
MTU=1460
|
2020-03-10 12:25:29 +00:00
|
|
|
MTU_W_HEADER=$((MTU+20))
|
2018-06-25 12:44:59 +00:00
|
|
|
ip link set dev $INITIATOR_INTERFACE mtu $MTU
|
|
|
|
ethtool -K $INITIATOR_INTERFACE tso off
|
|
|
|
ethtool -k $INITIATOR_INTERFACE
|
|
|
|
|
|
|
|
# Start VPP process in SPDK target network namespace
|
2020-02-20 10:24:53 +00:00
|
|
|
"${TARGET_NS_CMD[@]}" vpp \
|
2018-06-25 12:44:59 +00:00
|
|
|
unix { nodaemon cli-listen /run/vpp/cli.sock } \
|
2019-06-19 14:14:50 +00:00
|
|
|
dpdk { no-pci } \
|
2018-06-25 12:44:59 +00:00
|
|
|
session { evt_qs_memfd_seg } \
|
|
|
|
socksvr { socket-name /run/vpp-api.sock } \
|
|
|
|
plugins { \
|
|
|
|
plugin default { disable } \
|
|
|
|
plugin dpdk_plugin.so { enable } \
|
|
|
|
} &
|
|
|
|
|
|
|
|
vpp_pid=$!
|
|
|
|
echo "VPP Process pid: $vpp_pid"
|
|
|
|
|
2019-06-10 10:23:02 +00:00
|
|
|
gdb_attach $vpp_pid &
|
|
|
|
|
2018-06-25 12:44:59 +00:00
|
|
|
# Wait until VPP starts responding
|
|
|
|
xtrace_disable
|
|
|
|
counter=40
|
|
|
|
while [ $counter -gt 0 ] ; do
|
2020-03-10 12:25:29 +00:00
|
|
|
vppctl show version | grep -E "vpp v[0-9]+\.[0-9]+" && break
|
2019-11-05 09:28:35 +00:00
|
|
|
counter=$(( counter - 1 ))
|
2018-06-25 12:44:59 +00:00
|
|
|
sleep 0.5
|
|
|
|
done
|
|
|
|
xtrace_restore
|
|
|
|
if [ $counter -eq 0 ] ; then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2020-03-10 12:25:29 +00:00
|
|
|
# Below VPP commands are masked with "|| true" for the sake of
|
|
|
|
# running the test in the CI system. For reasons unknown when
|
|
|
|
# run via CI these commands result in 141 return code (pipefail)
|
|
|
|
# even despite producing valid output.
|
|
|
|
# Using "|| true" does not impact the "-e" flag used in test scripts
|
|
|
|
# because vppctl cli commands always return with 0, even if
|
|
|
|
# there was an error.
|
|
|
|
# As a result - grep checks on command outputs must be used to
|
|
|
|
# verify vpp configuration and connectivity.
|
|
|
|
|
2018-06-25 12:44:59 +00:00
|
|
|
# Setup host interface
|
2020-03-10 12:25:29 +00:00
|
|
|
vppctl create host-interface name $TARGET_INTERFACE || true
|
2018-06-25 12:44:59 +00:00
|
|
|
VPP_TGT_INT="host-$TARGET_INTERFACE"
|
2020-03-10 12:25:29 +00:00
|
|
|
vppctl set interface state $VPP_TGT_INT up || true
|
|
|
|
vppctl set interface ip address $VPP_TGT_INT $TARGET_IP/24 || true
|
|
|
|
vppctl set interface mtu $MTU $VPP_TGT_INT || true
|
2018-06-25 12:44:59 +00:00
|
|
|
|
2020-03-10 12:25:29 +00:00
|
|
|
vppctl show interface | tr -s " " | grep -E "host-$TARGET_INTERFACE [0-9]+ up $MTU/0/0/0"
|
2018-06-25 12:44:59 +00:00
|
|
|
|
|
|
|
# Disable session layer
|
|
|
|
# NOTE: VPP net framework should enable it itself.
|
2020-03-10 12:25:29 +00:00
|
|
|
vppctl session disable || true
|
2018-06-25 12:44:59 +00:00
|
|
|
|
|
|
|
# Verify connectivity
|
2020-03-10 12:25:29 +00:00
|
|
|
vppctl show int addr | grep -E "$TARGET_IP/24"
|
2018-06-25 12:44:59 +00:00
|
|
|
ip addr show $INITIATOR_INTERFACE
|
|
|
|
ip netns exec $TARGET_NAMESPACE ip addr show $TARGET_INTERFACE
|
|
|
|
sleep 3
|
2019-08-30 09:46:58 +00:00
|
|
|
# SC1010: ping -M do - in this case do is an option not bash special word
|
|
|
|
# shellcheck disable=SC1010
|
2019-11-05 09:28:35 +00:00
|
|
|
ping -c 1 $TARGET_IP -s $(( MTU - 28 )) -M do
|
2020-03-10 12:25:29 +00:00
|
|
|
vppctl ping $INITIATOR_IP repeat 1 size $(( MTU - (28 + 8) )) verbose | grep -E "$MTU_W_HEADER bytes from $INITIATOR_IP"
|
2018-06-25 12:44:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function kill_vpp() {
|
2020-03-10 12:25:29 +00:00
|
|
|
vppctl delete host-interface name $TARGET_INTERFACE || true
|
2018-06-25 12:44:59 +00:00
|
|
|
|
|
|
|
# Dump VPP configuration before kill
|
2020-03-10 12:25:29 +00:00
|
|
|
vppctl show api clients || true
|
|
|
|
vppctl show session || true
|
|
|
|
vppctl show errors || true
|
2018-06-25 12:44:59 +00:00
|
|
|
|
|
|
|
killprocess $vpp_pid
|
|
|
|
}
|