f15461e254800b0790993beff974f2037e2cc6ae
[csit.git] / tests / dpdk / dpdk_scripts / run_l2fwd.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 TESTPMDLOG="screenlog.0"
22 PWDDIR="$(pwd)"
23
24 # Setting command line arguments.
25 cpu_corelist="${1}"
26 nb_cores="${2}"
27 queue_nums="${3}"
28 jumbo_frames="${4}"
29 arch="$(uname -m)"
30
31 # DPDK prefers "arm64" to "aarch64" and does not allow arm64 native target.
32 if [ "${arch}" == "aarch64" ]; then
33     arch="arm64"
34     machine="armv8a"
35 else
36     machine="native"
37 fi
38
39 # Try to kill the testpmd.
40 sudo pgrep testpmd
41 if [ ${?} -eq "0" ]; then
42     success=false
43     sudo pkill testpmd
44     echo "RC = ${?}"
45     for attempt in {1..60}; do
46         echo "Checking if testpmd is still alive, attempt nr ${attempt}"
47         sudo pgrep testpmd
48         if [ ${?} -eq "1" ]; then
49             echo "testpmd is dead"
50             success=true
51             break
52         fi
53         echo "testpmd is still alive, waiting 1 second"
54         sleep 1
55     done
56     if [ "${success}" = false ]; then
57         echo "The command sudo pkill testpmd failed"
58         sudo pkill -9 testpmd
59         echo "RC = ${?}"
60         exit 1
61     fi
62 else
63     echo "testpmd is not running"
64 fi
65
66 # Try to kill the l3fwd.
67 sudo pgrep l3fwd
68 if [ ${?} -eq "0" ]; then
69     success=false
70     sudo pkill l3fwd
71     echo "RC = ${?}"
72     for attempt in {1..60}; do
73         echo "Checking if l3fwd is still alive, attempt nr ${attempt}"
74         sudo pgrep l3fwd
75         if [ ${?} -eq "1" ]; then
76             echo "l3fwd is dead"
77             success=true
78             break
79         fi
80         echo "l3fwd is still alive, waiting 1 second"
81         sleep 1
82     done
83     if [ "${success}" = false ]; then
84         echo "The command sudo pkill l3fwd failed"
85         sudo pkill -9 l3fwd
86         echo "RC = ${?}"
87         exit 1
88     fi
89 else
90     echo "l3fwd is not running"
91 fi
92
93 # Remove hugepages.
94 sudo rm -f /dev/hugepages/*
95
96 sleep 2
97
98 cd "${ROOTDIR}/${DPDK_DIR}/"
99 rm -f "${TESTPMDLOG}"
100 TESTPMD_BIN="./${arch}-${machine}-linuxapp-gcc/app/testpmd"
101
102 if [ "${jumbo_frames}" = "yes" ]; then
103     sudo sh -c "screen -dmSL DPDK-test ${TESTPMD_BIN} \
104         -l ${cpu_corelist} -n 4 --log-level 8 -v -- \
105         --numa \
106         --nb-ports=2 \
107         --portmask=0x3 \
108         --nb-cores=${nb_cores} \
109         --max-pkt-len=9000 \
110         --tx-offloads=0x7FFFFFFF \
111         --forward-mode=io \
112         --rxq=${queue_nums} \
113         --txq=$((${nb_cores} + 1)) \
114         --burst=64 \
115         --rxd=1024 \
116         --txd=1024 \
117         --disable-link-check \
118         --auto-start"
119 else
120     sudo sh -c "screen -dmSL DPDK-test ${TESTPMD_BIN} \
121         -l ${cpu_corelist} -n 4 --log-level 8 -v -- \
122         --numa \
123         --nb-ports=2 \
124         --portmask=0x3 \
125         --nb-cores=${nb_cores} \
126         --forward-mode=io \
127         --rxq=${queue_nums} \
128         --txq=$((${nb_cores} + 1)) \
129         --burst=64 \
130         --rxd=1024 \
131         --txd=1024 \
132         --disable-link-check \
133         --auto-start"
134 fi
135
136 for attempt in {1..60}; do
137     echo "Checking if testpmd is alive, attempt nr ${attempt}"
138     fgrep "Port 1: link state change event" "${TESTPMDLOG}"
139     if [ "${?}" -eq "0" ]; then
140         cat "${TESTPMDLOG}"
141         exit 0
142     fi
143     sleep 1
144 done
145
146 exit 1