examples/ipsec-secgw: add scapy based tests
[dpdk.git] / examples / ipsec-secgw / test / common_defs_secgw.sh
1 #!/bin/bash
2
3 # check required parameters
4 SGW_REQ_VARS="SGW_PATH SGW_PORT_CFG SGW_WAIT_DEV"
5 for reqvar in ${SGW_REQ_VARS}
6 do
7         if [[ -z "${!reqvar}" ]]; then
8                 echo "Required parameter ${reqvar} is empty"
9                 exit 127
10         fi
11 done
12
13 # check if SGW_PATH point to an executable
14 if [[ ! -x ${SGW_PATH} ]]; then
15         echo "${SGW_PATH} is not executable"
16         exit 127
17 fi
18
19 # setup SGW_LCORE
20 SGW_LCORE=${SGW_LCORE:-0}
21
22 # setup config and output filenames
23 SGW_OUT_FILE=./ipsec-secgw.out1
24 SGW_CFG_FILE=$(mktemp)
25
26 # setup secgw parameters
27 SGW_CMD_EAL_PRM="--lcores=${SGW_LCORE} -n 4"
28 SGW_CMD_CFG="(0,0,${SGW_LCORE}),(1,0,${SGW_LCORE})"
29 SGW_CMD_PRM="-p 0x3 -u 1 -P --config=\"${SGW_CMD_CFG}\""
30
31 # start ipsec-secgw
32 secgw_start()
33 {
34         SGW_EXEC_FILE=$(mktemp)
35         cat <<EOF > ${SGW_EXEC_FILE}
36 stdbuf -o0 ${SGW_PATH} ${SGW_CMD_EAL_PRM} ${CRYPTO_DEV} \
37 ${SGW_PORT_CFG} ${SGW_EAL_XPRM} \
38 -- ${SGW_CMD_PRM} ${SGW_CMD_XPRM} -f ${SGW_CFG_FILE} > \
39 ${SGW_OUT_FILE} 2>&1 &
40 p=\$!
41 echo \$p
42 EOF
43
44         cat ${SGW_EXEC_FILE}
45         cat ${SGW_CFG_FILE}
46         SGW_PID=`/bin/bash -x ${SGW_EXEC_FILE}`
47
48         # wait till ipsec-secgw start properly
49         i=0
50         st=1
51         while [[ $i -ne 10 && $st -ne 0 ]]; do
52                 sleep 1
53                 ifconfig ${SGW_WAIT_DEV}
54                 st=$?
55                 let i++
56         done
57 }
58
59 # stop ipsec-secgw and cleanup
60 secgw_stop()
61 {
62         kill ${SGW_PID}
63         rm -f ${SGW_EXEC_FILE}
64         rm -f ${SGW_CFG_FILE}
65 }