Update release note for Danube.3.2
[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.20"
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)
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 v2.20 already installed. Make sure it contains PYTHONPATH which is required to run TRex"
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         # workaround trex module issue
103         touch "$REPO_DIR/trex/scripts/automation/trex_control_plane/stl/__init__.py"
104         cp "$REPO_DIR/trex/scripts/dpdk_nic_bind.py" "$INSTALL_BIN_PATH"
105         popd
106     fi
107     echo "Done."
108 }
109
110 install_dpdk()
111 {
112     if [ -d "$INSTALL_BIN_PATH/dpdk-16.07" ]; then
113         echo "DPDK already installed make sure.. igb_uio is loaded."
114     else
115         echo "Build DPDK 16.07..."
116         pushd .
117         rm -rf ${DPDK_DOWNLOAD##*/}
118         rm -rf "$REPO_DIR/dpdk-16.07/"
119         if [ ! -e ${DPDK_DOWNLOAD##*/} ] ; then
120             wget ${DPDK_DOWNLOAD}
121         fi
122         unzip -o ${DPDK_DOWNLOAD##*/}
123
124         cd dpdk-16.07
125         make config T=x86_64-native-linuxapp-gcc O=x86_64-native-linuxapp-gcc
126         cd x86_64-native-linuxapp-gcc
127         echo "Enable Port Stats..."
128         sed -i -e 's/CONFIG_RTE_PORT_STATS_COLLECT=n/CONFIG_RTE_PORT_STATS_COLLECT=y/g' .config
129         sed -i -e 's/CONFIG_RTE_PORT_PCAP=n/CONFIG_RTE_PORT_PCAP=y/g' .config
130         sed -i -e 's/CONFIG_RTE_TABLE_STATS_COLLECT=n/CONFIG_RTE_TABLE_STATS_COLLECT=y/g' .config
131         sed -i -e 's/CONFIG_RTE_PIPELINE_STATS_COLLECT=n/CONFIG_RTE_PIPELINE_STATS_COLLECT=y/g' .config
132         make
133
134         echo "Load DPDK modules and setup hugepages"
135         modprobe uio
136         mkdir -p "/lib/modules/$(uname -r)/extra"
137         cp -r "kmod/igb_uio.ko" "/lib/modules/$(uname -r)/extra"
138         depmod -a
139         modprobe igb_uio
140         sh -c "echo 'uio\nigb_uio\n' > /etc/modules-load.d/nsb.conf"
141
142         HUGEPGSZ=$(cat < /proc/meminfo  | grep Hugepagesize | cut -d : -f 2 | tr -d ' ')
143         Pages=16
144         if [[ "$HUGEPGSZ" = "2048kB" ]] ; then
145             Pages=16384
146         fi
147         grep nr_hugepages /etc/sysctl.conf
148         if [[ "$?" -eq '1' ]] ; then
149             sh -c "echo 'vm.nr_hugepages=$Pages' >> /etc/sysctl.conf"
150         fi
151             echo "echo $Pages > /sys/kernel/mm/hugepages/hugepages-${HUGEPGSZ}/nr_hugepages" > .echo_tmp
152             echo "Reserving hugepages"
153             sudo sh .echo_tmp
154             rm -f .echo_tmp
155
156             service procps start
157             echo "Creating /mnt/huge and mounting as hugetlbfs"
158             sudo mkdir -p /mnt/huge
159
160             grep -s '/mnt/huge' /proc/mounts > /dev/null
161             if [ $? -ne 0 ] ; then
162                 sudo mount -t hugetlbfs nodev /mnt/huge
163             fi
164             popd
165             mv "$REPO_DIR/dpdk-16.07" "$INSTALL_BIN_PATH"
166             rm dpdk-16.07.zip
167     fi
168     export RTE_SDK="$INSTALL_BIN_PATH/dpdk-16.07"
169     export RTE_TARGET=x86_64-native-linuxapp-gcc
170
171     if [ ! -f "$INSTALL_BIN_PATH/vPE_vnf" ]; then
172         pushd .
173         echo "Building vPE VNF..."
174         cd $INSTALL_BIN_PATH/dpdk-16.07/examples/ip_pipeline/
175         make clean
176         make
177         cp build/ip_pipeline $INSTALL_BIN_PATH/vPE_vnf
178         popd
179     fi
180     echo "Done"
181 }
182
183
184 push_nsb_binary()
185 {
186     if [ ! -d "$INSTALL_BIN_PATH/trex/scripts" ]; then
187         cp -fr "$REPO_DIR/trex" "$INSTALL_BIN_PATH"
188     fi
189     rm -rf "$REPO_DIR/trex"
190
191     if [ -d "$INSTALL_BIN_PATH/trex" ]; then
192         echo "Setup Environment variables for Test Harness...."
193         PYTHONPATH="$INSTALL_BIN_PATH/trex/scripts/automation/trex_control_plane:$INSTALL_BIN_PATH/trex/scripts/automation/trex_control_plane/stl"
194         PY_PATH=$(grep PYTHONPATH ~/.bash_profile)
195         if [ "$PY_PATH" = "" ] ; then
196             sh -c "echo export PYTHONPATH=$PYTHONPATH >> ~/.bash_profile" > /dev/null
197         else
198             echo "Your ~/.bash_profile already contains a PYTHONPATH definition."
199             echo "Make sure it contains $PYTHONPATH which is required to run TRex"
200         fi
201     fi
202     cp "$REPO_DIR/yardstick/network_services/nfvi/collectd.sh" "$INSTALL_BIN_PATH"
203     cp "$REPO_DIR/yardstick/network_services/nfvi/collectd.conf" "$INSTALL_BIN_PATH"
204     cp "$REPO_DIR/nsb_setup.sh" "$INSTALL_BIN_PATH"
205     echo "Done"
206 }
207
208 check_installed_files()
209 {
210     if [ ! -f "$INSTALL_BIN_PATH/yardstick_venv/bin/activate" ]; then
211         echo "Installation Error. Failed to create yardstick virtual env..."
212         exit 1
213     fi
214
215     if [ ! -d "$INSTALL_BIN_PATH/dpdk-16.07" ]; then
216         echo "Installation Error. Failed to download and install dpdk-16.07..."
217         exit 1
218     fi
219
220     if [ ! -d "$INSTALL_BIN_PATH/trex" ]; then
221         echo "Installation Error. Failed to download and configure Trex"
222         exit 1
223     fi
224
225     if [ ! -f "$INSTALL_BIN_PATH/vPE_vnf" ]; then
226         echo "Installation Error. vPE VNF not present in install dir $INSTALL_BIN_PATH"
227         exit 1
228     fi
229 }
230
231 if [ "$1" == "dpdk" ]; then
232    install_libs
233    install_dpdk
234 else
235    install_libs
236    install_yardstick
237    install_dpdk
238    install_trex
239    push_nsb_binary
240    check_installed_files
241 clear
242 echo "Installation completed..."
243 echo "Virtual Environment : $INSTALL_BIN_PATH/yardstick_venv"
244 echo "Please Refer README.NSB.rst document on how to get started on VNF testing."
245 fi