Tomasz Zawadzki 5bafc240e5 test/iscsi: utilize network namespaces in iSCSI tests
Network namespaces are used to assure that kernel
is not routing packets within host stack,
but they go through veth interfaces.

This patch serves as a base for future VPP test changes,
where namespaces are used as well.

Change-Id: Ic7b82b0a0837bca2e16774fde244348a691fe056
Signed-off-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-on: https://review.gerrithub.io/405641
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
2018-04-26 17:10:36 +00:00

44 lines
1.3 KiB
Bash

# Network configuration
TARGET_INTERFACE="spdk_tgt_int"
INITIATOR_INTERFACE="spdk_init_int"
TARGET_NAMESPACE="spdk_iscsi_ns"
TARGET_NS_CMD="ip netns exec $TARGET_NAMESPACE"
# iSCSI target configuration
TARGET_IP=10.0.0.1
INITIATOR_IP=10.0.0.2
ISCSI_PORT=3260
NETMASK=$INITIATOR_IP/32
INITIATOR_TAG=2
INITIATOR_NAME=ANY
PORTAL_TAG=1
ISCSI_APP="$TARGET_NS_CMD ./app/iscsi_tgt/iscsi_tgt -i 0"
ISCSI_TEST_CORE_MASK=0xFF
function create_veth_interfaces() {
ip netns del $TARGET_NAMESPACE || true
ip link delete $INITIATOR_INTERFACE || true
# 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
# Create and add interface for target to network namespace
ip netns add $TARGET_NAMESPACE
ip link set $TARGET_INTERFACE netns $TARGET_NAMESPACE
$TARGET_NS_CMD ip link set lo up
$TARGET_NS_CMD ip addr add $TARGET_IP/24 dev $TARGET_INTERFACE
$TARGET_NS_CMD ip link set $TARGET_INTERFACE up
trap "cleanup_veth_interfaces; exit 1" SIGINT SIGTERM EXIT
}
function cleanup_veth_interfaces() {
# Cleanup veth interfaces and network namespace
# Note: removing one veth, removes the pair
ip link delete $INITIATOR_INTERFACE
ip netns del $TARGET_NAMESPACE
}