1 # Network configuration
2 TARGET_INTERFACE
="spdk_tgt_int"
3 INITIATOR_INTERFACE
="spdk_init_int"
4 TARGET_NAMESPACE
="spdk_iscsi_ns"
5 TARGET_NS_CMD
=(ip netns
exec "$TARGET_NAMESPACE")
7 # iSCSI target configuration
11 NETMASK
=$INITIATOR_IP/32
15 ISCSI_APP
=("${TARGET_NS_CMD[@]}" "${ISCSI_APP[@]}")
16 if [ $SPDK_TEST_VPP -eq 1 ]; then
17 ISCSI_APP
+=(-L sock_vpp
)
19 ISCSI_TEST_CORE_MASK
=0xFF
21 function create_veth_interfaces
() {
22 # $1 = test type (posix/vpp)
23 ip netns del
$TARGET_NAMESPACE || true
24 ip link delete
$INITIATOR_INTERFACE || true
26 trap 'cleanup_veth_interfaces $1; exit 1' SIGINT SIGTERM EXIT
28 # Create veth (Virtual ethernet) interface pair
29 ip link add
$INITIATOR_INTERFACE type veth peer name
$TARGET_INTERFACE
30 ip addr add
$INITIATOR_IP/24 dev
$INITIATOR_INTERFACE
31 ip link
set $INITIATOR_INTERFACE up
33 # Create and add interface for target to network namespace
34 ip netns add
$TARGET_NAMESPACE
35 ip link
set $TARGET_INTERFACE netns
$TARGET_NAMESPACE
37 # Accept connections from veth interface
38 iptables
-I INPUT
1 -i $INITIATOR_INTERFACE -p tcp
--dport $ISCSI_PORT -j ACCEPT
40 "${TARGET_NS_CMD[@]}" ip link
set $TARGET_INTERFACE up
42 if [ "$1" == "posix" ]; then
43 "${TARGET_NS_CMD[@]}" ip link
set lo up
44 "${TARGET_NS_CMD[@]}" ip addr add
$TARGET_IP/24 dev
$TARGET_INTERFACE
48 ip netns
exec $TARGET_NAMESPACE ping -c 1 $INITIATOR_IP
54 function cleanup_veth_interfaces
() {
55 # $1 = test type (posix/vpp)
56 if [ "$1" == "vpp" ]; then
60 # Cleanup veth interfaces and network namespace
61 # Note: removing one veth, removes the pair
62 ip link delete
$INITIATOR_INTERFACE
63 ip netns del
$TARGET_NAMESPACE
66 function iscsitestinit
() {
67 if [ "$1" == "iso" ]; then
68 $rootdir/scripts
/setup.sh
70 create_veth_interfaces
$2
73 create_veth_interfaces
"posix"
78 function waitforiscsidevices
() {
81 for ((i
= 1; i
<= 20; i
++)); do
82 n
=$
(iscsiadm
-m session
-P 3 |
grep -c "Attached scsi disk sd[a-z]*" || true
)
83 if [ $n -ne $num ]; then
93 function iscsitestfini
() {
94 if [ "$1" == "iso" ]; then
96 cleanup_veth_interfaces
$2
99 cleanup_veth_interfaces
"posix"
101 $rootdir/scripts
/setup.sh
reset
105 function start_vpp
() {
106 # We need to make sure that posix side doesn't send jumbo packets while
107 # for VPP side maximal size of MTU for TCP is 1460 and tests doesn't work
108 # stable with larger packets
110 MTU_W_HEADER
=$
((MTU
+ 20))
111 ip link
set dev
$INITIATOR_INTERFACE mtu
$MTU
112 ethtool
-K $INITIATOR_INTERFACE tso off
113 ethtool
-k $INITIATOR_INTERFACE
115 # Start VPP process in SPDK target network namespace
116 "${TARGET_NS_CMD[@]}" vpp \
117 unix
{ nodaemon cli-listen
/run
/vpp
/cli.sock
} \
119 session
{ evt_qs_memfd_seg
} \
120 socksvr
{ socket-name
/run
/vpp-api.sock
} \
122 plugin default
{ disable
} \
123 plugin dpdk_plugin.so
{ enable } \
127 echo "VPP Process pid: $vpp_pid"
129 gdb_attach
$vpp_pid &
131 # Wait until VPP starts responding
134 while [ $counter -gt 0 ]; do
135 vppctl show version |
grep -E "vpp v[0-9]+\.[0-9]+" && break
136 counter
=$
((counter
- 1))
140 if [ $counter -eq 0 ]; then
144 # Below VPP commands are masked with "|| true" for the sake of
145 # running the test in the CI system. For reasons unknown when
146 # run via CI these commands result in 141 return code (pipefail)
147 # even despite producing valid output.
148 # Using "|| true" does not impact the "-e" flag used in test scripts
149 # because vppctl cli commands always return with 0, even if
150 # there was an error.
151 # As a result - grep checks on command outputs must be used to
152 # verify vpp configuration and connectivity.
154 # Setup host interface
155 vppctl create host-interface name
$TARGET_INTERFACE || true
156 VPP_TGT_INT
="host-$TARGET_INTERFACE"
157 vppctl
set interface state
$VPP_TGT_INT up || true
158 vppctl
set interface ip address
$VPP_TGT_INT $TARGET_IP/24 || true
159 vppctl
set interface mtu
$MTU $VPP_TGT_INT || true
161 vppctl show interface |
tr -s " " |
grep -E "host-$TARGET_INTERFACE [0-9]+ up $MTU/0/0/0"
163 # Disable session layer
164 # NOTE: VPP net framework should enable it itself.
165 vppctl session disable || true
167 # Verify connectivity
168 vppctl show int addr |
grep -E "$TARGET_IP/24"
169 ip addr show
$INITIATOR_INTERFACE
170 ip netns
exec $TARGET_NAMESPACE ip addr show
$TARGET_INTERFACE
172 # SC1010: ping -M do - in this case do is an option not bash special word
173 # shellcheck disable=SC1010
174 ping -c 1 $TARGET_IP -s $
((MTU
- 28)) -M do
175 vppctl
ping $INITIATOR_IP repeat
1 size $
((MTU
- (28 + 8))) verbose |
grep -E "$MTU_W_HEADER bytes from $INITIATOR_IP"
178 function kill_vpp
() {
179 vppctl delete host-interface name
$TARGET_INTERFACE || true
181 # Dump VPP configuration before kill
182 vppctl show api clients || true
183 vppctl show session || true
184 vppctl show errors || true
188 function initiator_json_config
() {
189 # Prepare config file for iSCSI initiator
197 "method": "bdev_iscsi_create",
200 "url": "iscsi://$TARGET_IP/iqn.2016-06.io.spdk:disk1/0",
201 "initiator_iqn": "iqn.2016-06.io.spdk:disk1/0"