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:
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.
88 die "Get CPU architecture failed."
91 # DPDK prefers "arm64" to "aarch64" and does not allow arm64 native target.
92 if [ ${arch} == "aarch64" ]; then
100 sed_mlx="s/^CONFIG_RTE_LIBRTE_MLX5_PMD=n/CONFIG_RTE_LIBRTE_MLX5_PMD=y/g"
101 sed_i40e="s/^CONFIG_RTE_LIBRTE_I40E_16BYTE_RX_DESC=n/CONFIG_RTE_LIBRTE_I40E_16BYTE_RX_DESC=y/g"
102 sed_file="./config/common_base"
104 pushd "${DPDK_DIR}" || die "Pushd failed"
105 if ( lsmod || die ) | fgrep mlx; then
106 sed -i "${sed_mlx}" "${sed_file}" || die
109 sed -i "${sed_i40e}" "${sed_file}" || die "Patch failed"
112 make install T="${arch}"-"${machine}"-linuxapp-gcc -j || {
113 die "Failed to compile DPDK!"
115 popd || die "Popd failed"
118 export RTE_SDK="${DPDK_DIR}/"
119 export RTE_TARGET="${arch}-${machine}-linuxapp-gcc"
121 sed_rxd="s/^#define RTE_TEST_RX_DESC_DEFAULT 128/#define RTE_TEST_RX_DESC_DEFAULT 1024/g"
122 sed_txd="s/^#define RTE_TEST_TX_DESC_DEFAULT 512/#define RTE_TEST_TX_DESC_DEFAULT 1024/g"
124 pushd "${RTE_SDK}"/examples/l3fwd || die "Pushd failed"
125 sed -i "${sed_rxd}" "${sed_file}" || die "Patch failed"
126 sed -i "${sed_txd}" "${sed_file}" || die "Patch failed"
127 make clean || die "Failed to compile l3fwd"
128 make -j || die "Failed to compile l3fwd"
129 popd || die "Popd failed"
133 function dpdk_extract () {
135 # Extract DPDK framework.
138 # - DPDK_DIR - Path to DPDK framework.
139 # - CSIT_DIR - Path to CSIT framework.
141 # - die - Print to stderr and exit.
145 pushd "${CSIT_DIR}" || die "Pushd failed"
146 tar -xvf download_dir/dpdk*.tar.xz --strip=1 --directory "${DPDK_DIR}" || {
147 die "Failed to extract DPDK!"
152 function dpdk_kill () {
154 # Kill testpmd and/or l3fwd if running.
156 # Function will be noisy and requires custom error handling.
160 # Try to kill the testpmd.
162 if [ $? -eq "0" ]; then
165 for attempt in {1..60}; do
166 echo "Checking if testpmd is still alive, attempt nr ${attempt}"
168 if [ $? -eq "1" ]; then
172 echo "testpmd is still alive, waiting 1 second"
175 if [ "$success" = false ]; then
176 echo "The command sudo pkill testpmd failed"
177 sudo pkill -9 testpmd
181 echo "testpmd is not running"
184 # Try to kill the l3fwd.
185 l3fwd_pid="$(pgrep l3fwd)"
186 if [ ! -z "${l3fwd_pid}" ]; then
188 sudo kill -15 "${l3fwd_pid}"
189 for attempt in {1..60}; do
190 echo "Checking if l3fwd is still alive, attempt nr ${attempt}"
191 l3fwd_pid="$(pgrep l3fwd)"
192 if [ -z "${l3fwd_pid}" ]; then
196 echo "l3fwd is still alive, waiting 1 second"
199 if [ "${success}" = false ]; then
200 echo "The command sudo kill -15 l3fwd failed"
201 sudo kill -9 "${l3fwd_pid}"
205 echo "l3fwd is not running"
209 sudo rm -f /dev/hugepages/* || die "Removing hugepages failed!"
213 function dpdk_l3fwd_compile () {
215 # Compile DPDK l3fwd sample app.
218 # - DPDK_DIR - Path to DPDK framework.
219 # - CSIT_DIR - Path to CSIT framework.
221 # - die - Print to stderr and exit.
225 arch=$(uname -m) || {
226 die "Get CPU architecture failed."
229 # DPDK prefers "arm64" to "aarch64" and does not allow arm64 native target.
230 if [ ${arch} == "aarch64" ]; then
238 export RTE_SDK="${DPDK_DIR}/"
239 export RTE_TARGET="${arch}-${machine}-linuxapp-gcc"
241 sed_rxd="s/^#define RTE_TEST_RX_DESC_DEFAULT 128/#define RTE_TEST_RX_DESC_DEFAULT 2048/g"
242 sed_txd="s/^#define RTE_TEST_TX_DESC_DEFAULT 512/#define RTE_TEST_TX_DESC_DEFAULT 2048/g"
244 pushd "${RTE_SDK}"/examples/l3fwd || die "Pushd failed"
245 sed -i "${sed_rxd}" "${sed_file}" || die "Patch failed"
246 sed -i "${sed_txd}" "${sed_file}" || die "Patch failed"
247 chmod +x ${1} && source ${1} || die "Patch failed"
248 make clean || die "Failed to compile l3fwd"
249 make -j || die "Failed to compile l3fwd"
250 popd || die "Popd failed"
254 function dpdk_l3fwd () {
259 # - DPDK_DIR - Path to DPDK framework.
261 # - die - Print to stderr and exit.
265 arch=$(uname -m) || {
266 die "Get CPU architecture failed."
269 # DPDK prefers "arm64" to "aarch64" and does not allow arm64 native target.
270 if [ ${arch} == "aarch64" ]; then
277 rm -f screenlog.0 || true
278 binary="${DPDK_DIR}/examples/l3fwd/build/app/l3fwd"
280 sudo sh -c "screen -dmSL DPDK-test ${binary} ${@}" || {
281 die "Failed to start l3fwd"
284 for attempt in {1..60}; do
285 echo "Checking if l3fwd is alive, attempt nr ${attempt}"
286 if fgrep "L3FWD: entering main loop on lcore" screenlog.0; then
297 function dpdk_precheck () {
299 # Precheck system settings (nr_hugepages, max_map_count).
302 # - die - Print to stderr and exit.
306 sys_hugepage="$(< /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages)"
307 node0="/sys/devices/system/node/node0/hugepages/hugepages-2048kB/"
308 node1="/sys/devices/system/node/node1/hugepages/hugepages-2048kB/"
309 if [ ${sys_hugepage} -lt 4096 ]; then
310 echo 2048 | sudo tee "${node0}"/nr_hugepages || die
311 echo 2048 | sudo tee "${node1}"/nr_hugepages || die
314 sys_map="$(< /proc/sys/vm/max_map_count)"
315 if [ ${sys_map} -lt 200000 ]; then
316 echo 200000 | sudo tee /proc/sys/vm/max_map_count || die
321 function dpdk_testpmd () {
326 # - DPDK_DIR - Path to DPDK framework.
328 # - die - Print to stderr and exit.
332 arch=$(uname -m) || {
333 die "Get CPU architecture failed."
336 # DPDK prefers "arm64" to "aarch64" and does not allow arm64 native target.
337 if [ ${arch} == "aarch64" ]; then
344 rm -f screenlog.0 || true
345 binary="${DPDK_DIR}/${arch}-${machine}-linuxapp-gcc/app/testpmd"
347 sudo sh -c "screen -dmSL DPDK-test ${binary} ${@}" || {
348 die "Failed to start testpmd"
351 for attempt in {1..60}; do
352 echo "Checking if testpmd is alive, attempt nr ${attempt}"
353 if fgrep "Press enter to exit" screenlog.0; then