2 # Copyright (c) 2018 Cisco and/or its affiliates.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at:
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 function dpdk_utils.dpdk_delete {
16 # Deletes the DPDK directory
17 # DPDK install directory
19 # DPDK install version
22 [ -d ${dpdk_install_dir}/${dpdk_install_ver} ] && \
23 sudo rm -r ${dpdk_install_dir}/${dpdk_install_ver} && \
24 echo "${dpdk_install_dir}/${dpdk_install_ver} removed"
27 function dpdk_utils.dpdk_install {
28 # Downloads and installs DPDK
29 # DPDK install directory
31 # DPDK install version
34 dpdk_target=x86_64-native-linuxapp-gcc
35 # Force install (if true then remove previous installation; default false)
36 force_install=${3:-false}
38 if [ "$force_install" = true ]; then
40 dpdk_utils.dpdk_delete ${dpdk_install_dir} ${dpdk_install_ver}
42 # Test if DPDK was installed previously
43 test -d ${dpdk_install_dir}/${dpdk_install_ver} && \
44 { echo "DPDK ${dpdk_install_ver} ready"; exit 0; }
47 # Download the DPDK package if no local copy exists
48 if [ ! -f ${dpdk_install_dir}/${dpdk_install_ver}.tar.xz ]; then
49 sudo wget -e use_proxy=yes -P ${dpdk_install_dir} -q \
50 fast.dpdk.org/rel/${dpdk_install_ver}.tar.xz || \
51 { echo "Failed to download ${dpdk_install_ver}"; exit 1; }
54 # Create DPDK install dir if not exists and extract
55 sudo mkdir -p ${dpdk_install_dir} || \
56 { echo "Failed to create ${dpdk_install_dir}"; exit 1; }
57 sudo tar -xJf ${dpdk_install_dir}/${dpdk_install_ver}.tar.xz \
58 -C ${dpdk_install_dir} || \
59 { echo "Failed to extract ${dpdk_install_ver}.tar.xz"; exit 1; }
61 cd ${dpdk_install_dir}/${dpdk_install_ver}
63 # Compile and install the DPDK
64 sudo make install T=${dpdk_target} -j DESTDIR=install || \
65 { echo "Installation of ${dpdk_install_ver} failed"; exit 1; }
67 echo "DPDK ${dpdk_install_ver} ready"
70 function dpdk_utils.load_modules {
71 # Loads kernel modules and bind interfaces to drivers
72 # Use igb_uio [true|false]
73 use_igb_uio=${1:-false}
74 # DPDK install directory
76 # DPDK install version
80 sudo modprobe uio_pci_generic
82 if [ "${use_igb_uio}" = true ]; then
84 # Try to insert IGB_UIO module
85 sudo insmod ${dpdk_install_dir}/${dpdk_install_ver}/x86_64-native-linuxapp-gcc/kmod/igb_uio.ko
86 # If failed then download/compile DPDK
88 dpdk_utils.dpdk_install ${dpdk_install_dir} ${dpdk_install_ver} true
89 sudo insmod ${dpdk_install_dir}/${dpdk_install_ver}/x86_64-native-linuxapp-gcc/kmod/igb_uio.ko