Merge "Fixed invalid vfw/vacl rulw config issues"
[yardstick.git] / nsb_setup.sh
1 #! /bin/bash
2 # Copyright (c) 2016-2017 Intel Corporation
3 #
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 #
17 # Change to yardstick directory ( <current-dir>/.. ), and export it as REPO_DIR
18 #
19 cd "$(dirname "${BASH_SOURCE[0]}")"
20 export REPO_DIR=$PWD
21 echo "------------------------------------------------------------------------------"
22 echo " REPO_DIR exported as $REPO_DIR"
23 echo "------------------------------------------------------------------------------"
24
25 if [ "$(whoami)" != "root" ]; then
26     echo "Must be root to run $0"
27     exit 1;
28 fi
29
30 INSTALL_BIN_PATH="/opt/nsb_bin"
31 TREX_VERSION="v2.28"
32 TREX_DOWNLOAD="https://trex-tgn.cisco.com/trex/release/$TREX_VERSION.tar.gz"
33 DPDK_DOWNLOAD="http://dpdk.org/browse/dpdk/snapshot/dpdk-16.07.zip"
34 VIRTUAL_VENV="$INSTALL_BIN_PATH/yardstick_venv"
35
36 #
37 # Install libs needed for NSB
38 #
39 install_libs()
40 {
41     echo "Install libs needed to build and run NSB Testing..."
42     apt-get update > /dev/null 2>&1
43     pkg=(git build-essential python-dev virtualenv python-virtualenv virtualenv linux-headers-$(uname -r) unzip  python-pip libpcap-dev cmake)
44     for i in "${pkg[@]}"; do
45     dpkg-query -W --showformat='${Status}\n' "${i}"|grep "install ok installed"
46     if [  "$?" -eq "1" ]; then
47         apt-get -y install "${i}";
48     fi
49     done
50     echo "Done"
51 }
52
53 install_yardstick()
54 {
55     echo "Create install directory... $INSTALL_BIN_PATH"
56     mkdir -p $INSTALL_BIN_PATH
57     echo "Install yardstick dependencies and build Yardstick in venv..."
58     pushd .
59     rm -rf $VIRTUAL_VENV
60     echo $VIRTUAL_VENV
61     virtualenv $VIRTUAL_VENV
62     if [ ! -f "$INSTALL_BIN_PATH/yardstick_venv/bin/activate" ]; then
63          echo "Installation Error. Failed to create yardstick virtual env..."
64          exit 1
65     fi
66     source $VIRTUAL_VENV/bin/activate
67     bash ./install.sh
68     python setup.py install
69     popd
70
71     pushd .
72     echo "Copying yardstick sample conf & pod file to /etc/yardstick/nodes"
73     mkdir -p /etc/yardstick/nodes
74     cp "$REPO_DIR/etc/yardstick/yardstick.conf.sample" "/etc/yardstick/yardstick.conf"
75     cp "$REPO_DIR/etc/yardstick/nodes/pod.yaml.nsb.sample" "/etc/yardstick/nodes/"
76     popd
77 }
78
79 #
80 # Install trex for TH setup
81 #
82 install_trex()
83 {
84     TREX_DIR=$INSTALL_BIN_PATH/trex/scripts
85     if [ -d "$TREX_DIR" ]; then
86         echo "Trex $TREX_VERSION already installed."
87     else
88         echo "Build TRex and installing Trex TG in $INSTALL_BIN_PATH/trex"
89         rm -rf ${TREX_DOWNLOAD##*/}
90         if [ ! -e ${TREX_DOWNLOAD##*/} ] ; then
91             wget $TREX_DOWNLOAD
92         fi
93         tar zxvf ${TREX_DOWNLOAD##*/}
94         pushd .
95         rm -rf trex
96         mkdir -p trex
97         mv $TREX_VERSION trex/scripts
98         rm -rf $TREX_VERSION.tar.gz
99         cd trex/scripts/ko/src/
100         make
101         make install
102         ln -s $TREX_DIR/automation/trex_control_plane $INSTALL_BIN_PATH/trex_client
103         popd
104     fi
105     echo "Done."
106 }
107
108 install_dpdk()
109 {
110     if [ -d "$INSTALL_BIN_PATH/dpdk-16.07" ]; then
111         echo "DPDK already installed make sure.. igb_uio is loaded."
112     else
113         echo "Build DPDK 16.07..."
114         pushd .
115         rm -rf ${DPDK_DOWNLOAD##*/}
116         rm -rf "$REPO_DIR/dpdk-16.07/"
117         if [ ! -e ${DPDK_DOWNLOAD##*/} ] ; then
118             wget ${DPDK_DOWNLOAD}
119         fi
120         unzip -o ${DPDK_DOWNLOAD##*/}
121
122         cd dpdk-16.07
123         make config T=x86_64-native-linuxapp-gcc O=x86_64-native-linuxapp-gcc
124         cd x86_64-native-linuxapp-gcc
125         echo "Enable Port Stats..."
126         sed -i -e 's/CONFIG_RTE_PORT_STATS_COLLECT=n/CONFIG_RTE_PORT_STATS_COLLECT=y/g' .config
127         sed -i -e 's/CONFIG_RTE_PORT_PCAP=n/CONFIG_RTE_PORT_PCAP=y/g' .config
128         sed -i -e 's/CONFIG_RTE_TABLE_STATS_COLLECT=n/CONFIG_RTE_TABLE_STATS_COLLECT=y/g' .config
129         sed -i -e 's/CONFIG_RTE_PIPELINE_STATS_COLLECT=n/CONFIG_RTE_PIPELINE_STATS_COLLECT=y/g' .config
130         make
131
132         echo "Load DPDK modules and setup hugepages"
133         modprobe uio
134         mkdir -p "/lib/modules/$(uname -r)/extra"
135         cp -r "kmod/igb_uio.ko" "/lib/modules/$(uname -r)/extra"
136         depmod -a
137         modprobe igb_uio
138         sh -c "echo 'uio\nigb_uio\n' > /etc/modules-load.d/nsb.conf"
139
140         HUGEPGSZ=$(cat < /proc/meminfo  | grep Hugepagesize | cut -d : -f 2 | tr -d ' ')
141         Pages=16
142         if [[ "$HUGEPGSZ" = "2048kB" ]] ; then
143             Pages=16384
144         fi
145         grep nr_hugepages /etc/sysctl.conf
146         if [[ "$?" -eq '1' ]] ; then
147             sh -c "echo 'vm.nr_hugepages=$Pages' >> /etc/sysctl.conf"
148         fi
149             echo "echo $Pages > /sys/kernel/mm/hugepages/hugepages-${HUGEPGSZ}/nr_hugepages" > .echo_tmp
150             echo "Reserving hugepages"
151             sudo sh .echo_tmp
152             rm -f .echo_tmp
153
154             service procps start
155             echo "Creating /mnt/huge and mounting as hugetlbfs"
156             sudo mkdir -p /mnt/huge
157
158             grep -s '/mnt/huge' /proc/mounts > /dev/null
159             if [ $? -ne 0 ] ; then
160                 sudo mount -t hugetlbfs nodev /mnt/huge
161             fi
162             popd
163             mv "$REPO_DIR/dpdk-16.07" "$INSTALL_BIN_PATH"
164             rm dpdk-16.07.zip
165     fi
166     export RTE_SDK="$INSTALL_BIN_PATH/dpdk-16.07"
167     export RTE_TARGET=x86_64-native-linuxapp-gcc
168
169     if [ ! -f "$INSTALL_BIN_PATH/vPE_vnf" ]; then
170         pushd .
171         echo "Building vPE VNF..."
172         cd $INSTALL_BIN_PATH/dpdk-16.07/examples/ip_pipeline/
173         make clean
174         make
175         cp build/ip_pipeline $INSTALL_BIN_PATH/vPE_vnf
176         popd
177     fi
178     echo "Done"
179 }
180
181
182 push_nsb_binary()
183 {
184     if [ ! -d "$INSTALL_BIN_PATH/trex/scripts" ]; then
185         cp -fr "$REPO_DIR/trex" "$INSTALL_BIN_PATH"
186     fi
187     rm -rf "$REPO_DIR/trex"
188
189     if [ -d "$INSTALL_BIN_PATH/trex" ]; then
190         echo "Setup Environment variables for Test Harness...."
191         PYTHONPATH="$INSTALL_BIN_PATH/trex/scripts/automation/trex_control_plane:$INSTALL_BIN_PATH/trex/scripts/automation/trex_control_plane/stl"
192         PY_PATH=$(grep PYTHONPATH ~/.bash_profile)
193         if [ "$PY_PATH" = "" ] ; then
194             sh -c "echo export PYTHONPATH=$PYTHONPATH >> ~/.bash_profile" > /dev/null
195         else
196             echo "Your ~/.bash_profile already contains a PYTHONPATH definition."
197             echo "Make sure it contains $PYTHONPATH which is required to run TRex"
198         fi
199     fi
200     cp "$REPO_DIR/yardstick/network_services/nfvi/collectd.sh" "$INSTALL_BIN_PATH"
201     cp "$REPO_DIR/yardstick/network_services/nfvi/collectd.conf" "$INSTALL_BIN_PATH"
202     cp "$REPO_DIR/nsb_setup.sh" "$INSTALL_BIN_PATH"
203
204     # Get "dpdk-devbind.py" to find the ports for VNF to run
205     wget http://dpdk.org/browse/dpdk/plain/usertools/dpdk-devbind.py?h=v17.05 -O dpdk-devbind.py
206     chmod 777 dpdk-devbind.py
207     mv dpdk-devbind.py "$INSTALL_BIN_PATH"
208     ln "$INSTALL_BIN_PATH"/dpdk-devbind.py "$INSTALL_BIN_PATH"/dpdk_nic_bind.py
209     echo "Done"
210 }
211
212 check_installed_files()
213 {
214     if [ ! -f "$INSTALL_BIN_PATH/yardstick_venv/bin/activate" ]; then
215         echo "Installation Error. Failed to create yardstick virtual env..."
216         exit 1
217     fi
218
219     if [ ! -d "$INSTALL_BIN_PATH/dpdk-16.07" ]; then
220         echo "Installation Error. Failed to download and install dpdk-16.07..."
221         exit 1
222     fi
223
224     if [ ! -d "$INSTALL_BIN_PATH/trex" ]; then
225         echo "Installation Error. Failed to download and configure Trex"
226         exit 1
227     fi
228
229     if [ ! -f "$INSTALL_BIN_PATH/vPE_vnf" ]; then
230         echo "Installation Error. vPE VNF not present in install dir $INSTALL_BIN_PATH"
231         exit 1
232     fi
233 }
234
235 if [ "$1" == "dpdk" ]; then
236    install_libs
237    install_dpdk
238 else
239    install_libs
240    install_yardstick
241    install_dpdk
242    install_trex
243    push_nsb_binary
244    check_installed_files
245 clear
246 echo "Installation completed..."
247 echo "Virtual Environment : $INSTALL_BIN_PATH/yardstick_venv"
248 echo "Please refer to Chapter 13 of the Yardstick User Guide for how to get started with VNF testing."
249 fi