FIX: Detection if l2fwd/l3fwd is up/down
[csit.git] / tests / dpdk / dpdk_scripts / run_l3fwd.sh
1 #!/usr/bin/env bash
2
3 # Copyright (c) 2020 Cisco and/or its affiliates.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 set -xuo pipefail
17
18 # Setting variables.
19 DPDK_DIR="dpdk"
20 ROOTDIR="/tmp/openvpp-testing"
21 L3FWDLOG="screenlog.0"
22 PWDDIR="$(pwd)"
23
24 # Setting command line arguments.
25 cpu_corelist="${1}"
26 port_config="${2}"
27 adj_mac0="${3}"
28 adj_mac1="${4}"
29 jumbo_frames="${5}"
30
31 SCRIPT_NAME="$(basename $0)"
32
33 # define a function to get the l3fwd PID.
34 function get_l3fwd_pid()
35 {
36     pid_l3fwd=`sudo ps -elf | grep l3fwd | grep -v grep | grep -v SCREEN | grep -v ${SCRIPT_NAME} | awk '{print $4}'`
37     echo "${pid_l3fwd}"
38 }
39
40 # Try to kill the l3fwd.
41 # Don't use the pgrep and pkill.
42 l3fwd_pid=`get_l3fwd_pid`
43 echo "${l3fwd_pid}"
44 if [ ! -z "${l3fwd_pid}" ]; then
45     success=false
46     sudo kill -15 "${l3fwd_pid}"
47     echo "RC = ${?}"
48     for attempt in {1..60}; do
49         echo "Checking if l3fwd is still alive, attempt nr ${attempt}"
50         l3fwd_pid=`get_l3fwd_pid`
51         if [ -z "${l3fwd_pid}" ]; then
52             echo "l3fwd is dead"
53             success=true
54             break
55         fi
56         echo "l3fwd is still alive, waiting 1 second"
57         sleep 1
58     done
59     if [ "${success}" = false ]; then
60         echo "The command sudo kill -15 l3fwd failed"
61         sudo kill -9 "${l3fwd_pid}"
62         echo "RC = ${?}"
63         exit 1
64     fi
65 else
66     echo "l3fwd is not running"
67 fi
68
69 # Try to kill the testpmd.
70 sudo pgrep testpmd
71 if [ ${?} -eq "0" ]; then
72     success=false
73     sudo pkill testpmd
74     echo "RC = ${?}"
75     for attempt in {1..60}; do
76         echo "Checking if testpmd is still alive, attempt nr ${attempt}"
77         sudo pgrep testpmd
78         if [ ${?} -eq "1" ]; then
79             echo "testpmd is dead"
80             success=true
81             break
82         fi
83         echo "testpmd is still alive, waiting 1 second"
84         sleep 1
85     done
86     if [ "${success}" = false ]; then
87         echo "The command sudo pkill testpmd failed"
88         sudo pkill -9 testpmd
89         echo "RC = ${?}"
90         exit 1
91     fi
92 else
93     echo "testpmd is not running"
94 fi
95
96 # Remove hugepages.
97 sudo rm -f /dev/hugepages/*
98
99 sleep 2
100
101 cd "${ROOTDIR}/${DPDK_DIR}/"
102 rm -f "${L3FWDLOG}"
103 if [ "${jumbo_frames}" = "yes" ]; then
104     sudo sh -c "screen -dmSL DPDK-test ./examples/l3fwd/build/app/l3fwd \
105     -l ${cpu_corelist} -n 4 --log-level 8 -- \
106     -P -L -p 0x3 --config='${port_config}' \
107     --enable-jumbo --max-pkt-len=9000 --eth-dest=0,${adj_mac0} \
108     --eth-dest=1,${adj_mac1} --parse-ptype"
109 else
110     sudo sh -c "screen -dmSL DPDK-test ./examples/l3fwd/build/app/l3fwd \
111     -l ${cpu_corelist} -n 4 --log-level 8 -- \
112     -P -L -p 0x3 --config='${port_config}' \
113     --eth-dest=0,${adj_mac0} --eth-dest=1,${adj_mac1} --parse-ptype"
114 fi
115
116 for attempt in {1..60}; do
117     echo "Checking if l3fwd is alive, attempt nr ${attempt}"
118     fgrep "L3FWD: entering main loop on lcore" "${L3FWDLOG}"
119     if [ "${?}" -eq "0" ]; then
120         cat "${L3FWDLOG}"
121         exit 0
122     fi
123     sleep 1
124 done
125
126 exit 1