3 # Copyright (c) 2021 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:
8 # http://www.apache.org/licenses/LICENSE-2.0
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.
19 function common_dirs () {
21 # Set global variables, create some directories (without touching content).
22 # This function assumes running in remote testbed. It might override other
23 # functions if included from common.sh.
26 # - BASH_FUNCTION_DIR - Path to existing directory this file is located in.
27 # - DPDK_DIR - Path to DPDK framework.
28 # - CSIT_DIR - Path to CSIT framework.
30 # - die - Print to stderr and exit.
34 this_file=$(readlink -e "${BASH_SOURCE[0]}") || {
35 die "Some error during locating of this source file."
37 BASH_FUNCTION_DIR=$(dirname "${this_file}") || {
38 die "Some error during dirname call."
40 CSIT_DIR=$(readlink -e "/tmp/openvpp-testing") || {
41 die "Readlink failed."
43 mkdir -p "${CSIT_DIR}/dpdk" || die "Mkdir failed."
44 DPDK_DIR=$(readlink -e "${CSIT_DIR}/dpdk") || {
45 die "Readlink failed."
50 function dpdk_bind () {
52 # Bind interfaces to driver.
55 # - DPDK_DIR - Path to DPDK framework.
56 # - @ - Script cli arguments.
58 # - die - Print to stderr and exit.
62 pushd "${DPDK_DIR}/" || die "Pushd failed"
64 sudo ./usertools/dpdk-devbind.py -b "${@}" || {
65 die "Bind ${@} failed"
68 popd || die "Popd failed"
72 function dpdk_compile () {
74 # Compile DPDK archive.
77 # - DPDK_DIR - Path to DPDK framework.
78 # - CSIT_DIR - Path to CSIT framework.
80 # - RTE_SDK - DPDK directory.
81 # - RTE_TARGET - Make targed of DPDK framework.
83 # - die - Print to stderr and exit.
87 pushd "${DPDK_DIR}" || die "Pushd failed"
90 meson_options="-Dexamples=l3fwd "
92 # i40e specific options
93 meson_options="${meson_options} \
94 -Dc_args=-DRTE_LIBRTE_I40E_16BYTE_RX_DESC=y"
96 # Configure generic build - the same used by VPP
97 meson_options="${meson_options} -Dplatform=generic"
100 sed_rxd="s/^#define RTE_TEST_RX_DESC_DEFAULT 128"
101 sed_rxd+="/#define RTE_TEST_RX_DESC_DEFAULT 1024/g"
102 sed_txd="s/^#define RTE_TEST_TX_DESC_DEFAULT 512"
103 sed_txd+="/#define RTE_TEST_TX_DESC_DEFAULT 1024/g"
105 pushd examples/l3fwd || die "Pushd failed"
106 sed -i "${sed_rxd}" "${sed_file}" || die "Patch failed"
107 sed -i "${sed_txd}" "${sed_file}" || die "Patch failed"
108 popd || die "Popd failed"
110 # Compile using Meson and Ninja.
111 meson ${meson_options} build || {
112 die "Failed to compile DPDK!"
114 ninja -C build || die "Failed to compile DPDK!"
118 function dpdk_extract () {
120 # Extract DPDK framework.
123 # - DPDK_DIR - Path to DPDK framework.
124 # - CSIT_DIR - Path to CSIT framework.
126 # - die - Print to stderr and exit.
130 pushd "${CSIT_DIR}" || die "Pushd failed"
131 tar -xvf download_dir/dpdk*.tar.xz --strip=1 --directory "${DPDK_DIR}" || {
132 die "Failed to extract DPDK!"
137 function dpdk_kill () {
139 # Kill testpmd and/or l3fwd if running.
141 # Function will be noisy and requires custom error handling.
145 # Try to kill the testpmd.
147 if [ $? -eq "0" ]; then
150 for attempt in {1..60}; do
151 echo "Checking if testpmd is still alive, attempt nr ${attempt}"
153 if [ $? -eq "1" ]; then
157 echo "testpmd is still alive, waiting 1 second"
160 if [ "$success" = false ]; then
161 echo "The command sudo pkill testpmd failed"
162 sudo pkill -9 testpmd
166 echo "testpmd is not running"
169 # Try to kill the l3fwd.
170 l3fwd_pid="$(pgrep l3fwd)"
171 if [ ! -z "${l3fwd_pid}" ]; then
173 sudo kill -15 "${l3fwd_pid}"
174 for attempt in {1..60}; do
175 echo "Checking if l3fwd is still alive, attempt nr ${attempt}"
176 l3fwd_pid="$(pgrep l3fwd)"
177 if [ -z "${l3fwd_pid}" ]; then
181 echo "l3fwd is still alive, waiting 1 second"
184 if [ "${success}" = false ]; then
185 echo "The command sudo kill -15 l3fwd failed"
186 sudo kill -9 "${l3fwd_pid}"
190 echo "l3fwd is not running"
194 sudo rm -rf /dev/hugepages/* || die "Removing hugepages failed!"
198 function dpdk_l3fwd_compile () {
200 # Compile DPDK l3fwd sample app.
203 # - DPDK_DIR - Path to DPDK framework.
204 # - CSIT_DIR - Path to CSIT framework.
206 # - die - Print to stderr and exit.
210 pushd "${DPDK_DIR}" || die "Pushd failed"
212 sed_rxd="s/^#define RTE_TEST_RX_DESC_DEFAULT 128"
213 sed_rxd+="/#define RTE_TEST_RX_DESC_DEFAULT 2048/g"
214 sed_txd="s/^#define RTE_TEST_TX_DESC_DEFAULT 512"
215 sed_txd+="/#define RTE_TEST_TX_DESC_DEFAULT 2048/g"
217 pushd examples/l3fwd || die "Pushd failed"
218 sed -i "${sed_rxd}" "${sed_file}" || die "Patch failed"
219 sed -i "${sed_txd}" "${sed_file}" || die "Patch failed"
220 chmod +x ${1} && source ${1} || die "Patch failed"
221 popd || die "Popd failed"
223 ninja -C build || die "Failed to compile DPDK!"
227 function dpdk_l3fwd () {
232 # - DPDK_DIR - Path to DPDK framework.
234 # - die - Print to stderr and exit.
238 rm -f screenlog.0 || true
239 binary="${DPDK_DIR}/build/examples/dpdk-l3fwd"
241 sudo sh -c "screen -dmSL DPDK-test ${binary} ${@}" || {
242 die "Failed to start l3fwd"
245 for attempt in {1..60}; do
246 echo "Checking if l3fwd is alive, attempt nr ${attempt}"
247 if fgrep "L3FWD: entering main loop on lcore" screenlog.0; then
258 function dpdk_precheck () {
260 # Precheck system settings (nr_hugepages, max_map_count).
263 # - die - Print to stderr and exit.
267 sys_hugepage="$(< /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages)"
268 node0="/sys/devices/system/node/node0/hugepages/hugepages-2048kB/"
269 node1="/sys/devices/system/node/node1/hugepages/hugepages-2048kB/"
270 if [ ${sys_hugepage} -lt 4096 ]; then
271 echo 2048 | sudo tee "${node0}"/nr_hugepages || die
272 echo 2048 | sudo tee "${node1}"/nr_hugepages || die
275 sys_map="$(< /proc/sys/vm/max_map_count)"
276 if [ ${sys_map} -lt 200000 ]; then
277 echo 200000 | sudo tee /proc/sys/vm/max_map_count || die
282 function dpdk_testpmd () {
287 # - DPDK_DIR - Path to DPDK framework.
289 # - die - Print to stderr and exit.
293 rm -f screenlog.0 || true
294 binary="${DPDK_DIR}/build/app/dpdk-testpmd"
296 sudo sh -c "screen -dmSL DPDK-test ${binary} ${@}" || {
297 die "Failed to start testpmd"
300 for attempt in {1..60}; do
301 echo "Checking if testpmd is alive, attempt nr ${attempt}"
302 if fgrep "Press enter to exit" screenlog.0; then