summaryrefslogtreecommitdiffstats
path: root/nsb_setup.sh
blob: 332c0345ca9cabf271d6308d0bc6eca2d7f8eb33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
@media only all and (prefers-color-scheme: dark) {
.highlight .hll { background-color: #49483e }
.highlight .c { color: #75715e } /* Comment */
.highlight .err { color: #960050; background-color: #1e0010 } /* Error */
.highlight .k { color: #66d9ef } /* Keyword */
.highlight .l { color: #ae81ff } /* Literal */
.highlight .n { color: #f8f8f2 } /* Name */
.highlight .o { color: #f92672 } /* Operator */
.highlight .p { color: #f8f8f2 } /* Punctuation */
.highlight .ch { color: #75715e } /* Comment.Hashbang */
.highlight .cm { color: #75715e } /* Comment.Multiline */
.highlight .cp { color: #75715e } /* Comment.Preproc */
.highlight .cpf { color: #75715e } /* Comment.PreprocFile */
.highlight .c1 { color: #75715e } /* Comment.Single */
.highlight .cs { color: #75715e } /* Comment.Special */
.highlight .gd { color: #f92672 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gi { color: #a6e22e } /* Generic.Inserted */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #75715e } /* Generic.Subheading */
.highlight .kc { color: #66d9ef } /* Keyword.Constant */
.highlight .kd { color: #66d9ef } /* Keyword.Declaration */
.highlight .kn { color: #f92672 } /* Keyword.Namespace */
.highlight .kp { color: #66d9ef } /* Keyword.Pseudo */
.highlight .kr { color: #66d9ef } /* Keyword.Reserved */
.highlight .kt { color: #66d9ef } /* Keyword.Type */
.highlight .ld { color: #e6db74 } /* Literal.Date */
.highlight .m { color: #ae81ff } /* Literal.Number */
.highlight .s { color: #e6db74 } /* Literal.String */
.highlight .na { color: #a6e22e } /* Name.Attribute */
.highlight .nb { color: #f8f8f2 } /* Name.Builtin */
.highlight .nc { color: #a6e22e } /* Name.Class */
.highlight .no { color: #66d9ef } /* Name.Constant */
.highlight .nd { color: #a6e22e } /* Name.Decorator */
.highlight .ni { color: #f8f8f2 } /* Name.Entity */
.highlight .ne { color: #a6e22e } /* Name.Exception */
.highlight .nf { color: #a6e22e } /* Name.Function */
.highlight .nl { color: #f8f8f2 } /* Name.Label */
.highlight .nn { color: #f8f8f2 } /* Name.Namespace */
.highlight .nx { color: #a6e22e } /* Name.Other */
.highlight .py { color: #f8f8f2 } /* Name.Property */
.highlight .nt { color: #f92672 } /* Name.Tag */
.highlight .nv { color: #f8f8f2 } /* Name.Variable */
.highlight .ow { color: #f92672 } /* Operator.Word */
.highlight .w { color: #f8f8f2 } /* Text.Whitespace */
.highlight .mb { color: #ae81ff } /* Literal.Number.Bin */
.highlight .mf { color: #ae81ff } /* Literal.Number.Float */
.highlight .mh { color: #ae81ff } /* Literal.Number.Hex */
.highlight .mi { color: #ae81ff } /* Literal.Number.Integer */
.highlight .mo { color: #ae81ff } /* Literal.Number.Oct */
.highlight .sa { color: #e6db74 } /* Literal.String.Affix */
.highlight .sb { color: #e6db74 } /* Literal.String.Backtick */
.highlight .sc { color: #e6db74 } /* Literal.String.Char */
.highlight .dl { color: #e6db74 } /* Literal.String.Delimiter */
.highlight .sd { color: #e6db74 } /* Literal.String.Doc */
.highlight .s2 { color: #e6db74 } /* Literal.String.Double */
.highlight .se { color: #ae81ff } /* Literal.String.Escape */
.highlight .sh { color: #e6db74 } /* Literal.String.Heredoc */
.highlight .si { color: #e6db74 } /* Literal.String.Interpol */
.highlight .sx { color: #e6db74 } /* Literal.String.Other */
.highlight .sr { color: #e6db74 } /* Literal.String.Regex */
.highlight .s1 { color: #e6db74 } /* Literal.String.Single */
.highlight .ss { color: #e6db74 } /* Literal.String.Symbol */
.highlight .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #a6e22e } /* Name.Function.Magic */
.highlight .vc { color: #f8f8f2 } /* Name.Variable.Class */
.highlight .vg { color: #f8f8f2 } /* Name.Variable.Global */
.highlight .vi { color: #f8f8f2 } /* Name.Variable.Instance */
.highlight .vm { color: #f8f8f2 } /* Name.Variable.Magic */
.highlight .il { color: #ae81ff } /* Literal.Number.Integer.Long */
}
@media (prefers-color-scheme: light) {
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-we
#! /bin/bash
# Copyright (c) 2016-2017 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#
# Change to yardstick directory ( <current-dir>/.. ), and export it as REPO_DIR
#
cd "$(dirname "${BASH_SOURCE[0]}")"
export REPO_DIR=$PWD
echo "------------------------------------------------------------------------------"
echo " REPO_DIR exported as $REPO_DIR"
echo "------------------------------------------------------------------------------"

if [ "$(whoami)" != "root" ]; then
    echo "Must be root to run $0"
    exit 1;
fi

INSTALL_BIN_PATH="/opt/nsb_bin"
TREX_VERSION="v2.20"
TREX_DOWNLOAD="https://trex-tgn.cisco.com/trex/release/$TREX_VERSION.tar.gz"
DPDK_DOWNLOAD="http://dpdk.org/browse/dpdk/snapshot/dpdk-16.07.zip"
VIRTUAL_VENV="$INSTALL_BIN_PATH/yardstick_venv"

#
# Install libs needed for NSB
#
install_libs()
{
    echo "Install libs needed to build and run NSB Testing..."
    apt-get update > /dev/null 2>&1
    pkg=(git build-essential python-dev virtualenv python-virtualenv virtualenv linux-headers-$(uname -r) unzip  python-pip libpcap-dev)
    for i in "${pkg[@]}"; do
    dpkg-query -W --showformat='${Status}\n' "${i}"|grep "install ok installed"
    if [  "$?" -eq "1" ]; then
        apt-get -y install "${i}";
    fi
    done
    echo "Done"
}

install_yardstick()
{
    echo "Create install directory... $INSTALL_BIN_PATH"
    mkdir -p $INSTALL_BIN_PATH
    echo "Install yardstick dependencies and build Yardstick in venv..."
    pushd .
    rm -rf $VIRTUAL_VENV
    echo $VIRTUAL_VENV
    virtualenv $VIRTUAL_VENV
    if [ ! -f "$INSTALL_BIN_PATH/yardstick_venv/bin/activate" ]; then
         echo "Installation Error. Failed to create yardstick virtual env..."
         exit 1
    fi
    source $VIRTUAL_VENV/bin/activate
    bash ./install.sh
    python setup.py install
    popd

    pushd .
    echo "Copying yardstick sample conf & pod file to /etc/yardstick/nodes"
    mkdir -p /etc/yardstick/nodes
    cp "$REPO_DIR/etc/yardstick/yardstick.conf.sample" "/etc/yardstick/yardstick.conf"
    cp "$REPO_DIR/etc/yardstick/nodes/pod.yaml.nsb.sample" "/etc/yardstick/nodes/"
    popd
}

#
# Install trex for TH setup
#
install_trex()
{
    TREX_DIR=$INSTALL_BIN_PATH/trex/scripts
    if [ -d "$TREX_DIR" ]; then
        echo "Trex v2.20 already installed. Make sure it contains PYTHONPATH which is required to run TRex"
    else
        echo "Build TRex and installing Trex TG in $INSTALL_BIN_PATH/trex"
        rm -rf ${TREX_DOWNLOAD##*/}
        if [ ! -e ${TREX_DOWNLOAD##*/} ] ; then
            wget $TREX_DOWNLOAD
        fi
        tar zxvf ${TREX_DOWNLOAD##*/}
        pushd .
        rm -rf trex
        mkdir -p trex
        mv $TREX_VERSION trex/scripts
        rm -rf $TREX_VERSION.tar.gz
        cd trex/scripts/ko/src/
        make
        make install
        # workaround trex module issue
        touch "$REPO_DIR/trex/scripts/automation/trex_control_plane/stl/__init__.py"
        cp "$REPO_DIR/trex/scripts/dpdk_nic_bind.py" "$INSTALL_BIN_PATH"
        popd
    fi
    echo "Done."
}

install_dpdk()
{
    if [ -d "$INSTALL_BIN_PATH/dpdk-16.07" ]; then
        echo "DPDK already installed make sure.. igb_uio is loaded."
    else
        echo "Build DPDK 16.07..."
        pushd .
        rm -rf ${DPDK_DOWNLOAD##*/}
        rm -rf "$REPO_DIR/dpdk-16.07/"
        if [ ! -e ${DPDK_DOWNLOAD##*/} ] ; then
            wget ${DPDK_DOWNLOAD}
        fi
        unzip -o ${DPDK_DOWNLOAD##*/}

        cd dpdk-16.07
        make config T=x86_64-native-linuxapp-gcc O=x86_64-native-linuxapp-gcc
        cd x86_64-native-linuxapp-gcc
        echo "Enable Port Stats..."
        sed -i -e 's/CONFIG_RTE_PORT_STATS_COLLECT=n/CONFIG_RTE_PORT_STATS_COLLECT=y/g' .config
        sed -i -e 's/CONFIG_RTE_PORT_PCAP=n/CONFIG_RTE_PORT_PCAP=y/g' .config
        sed -i -e 's/CONFIG_RTE_TABLE_STATS_COLLECT=n/CONFIG_RTE_TABLE_STATS_COLLECT=y/g' .config
        sed -i -e 's/CONFIG_RTE_PIPELINE_STATS_COLLECT=n/CONFIG_RTE_PIPELINE_STATS_COLLECT=y/g' .config
        make

        echo "Load DPDK modules and setup hugepages"
        modprobe uio
        mkdir -p "/lib/modules/$(uname -r)/extra"
        cp -r "kmod/igb_uio.ko" "/lib/modules/$(uname -r)/extra"
        depmod -a
        modprobe igb_uio
        sh -c "echo 'uio\nigb_uio\n' > /etc/modules-load.d/nsb.conf"

        HUGEPGSZ=$(cat < /proc/meminfo  | grep Hugepagesize | cut -d : -f 2 | tr -d ' ')
        Pages=16
        if [[ "$HUGEPGSZ" = "2048kB" ]] ; then
            Pages=16384
        fi
        grep nr_hugepages /etc/sysctl.conf
        if [[ "$?" -eq '1' ]] ; then
            sh -c "echo 'vm.nr_hugepages=$Pages' >> /etc/sysctl.conf"
        fi
            echo "echo $Pages > /sys/kernel/mm/hugepages/hugepages-${HUGEPGSZ}/nr_hugepages" > .echo_tmp
            echo "Reserving hugepages"
            sudo sh .echo_tmp
            rm -f .echo_tmp

            service procps start
            echo "Creating /mnt/huge and mounting as hugetlbfs"
            sudo mkdir -p /mnt/huge

            grep -s '/mnt/huge' /proc/mounts > /dev/null
            if [ $? -ne 0 ] ; then
                sudo mount -t hugetlbfs nodev /mnt/huge
            fi
            popd
            mv "$REPO_DIR/dpdk-16.07" "$INSTALL_BIN_PATH"
            rm dpdk-16.07.zip
    fi
    export RTE_SDK="$INSTALL_BIN_PATH/dpdk-16.07"
    export RTE_TARGET=x86_64-native-linuxapp-gcc

    if [ ! -f "$INSTALL_BIN_PATH/vPE_vnf" ]; then
        pushd .
        echo "Building vPE VNF..."
        cd $INSTALL_BIN_PATH/dpdk-16.07/examples/ip_pipeline/
        make clean
        make
        cp build/ip_pipeline $INSTALL_BIN_PATH/vPE_vnf
        popd
    fi
    echo "Done"
}


push_nsb_binary()
{
    if [ ! -d "$INSTALL_BIN_PATH/trex/scripts" ]; then
        cp -fr "$REPO_DIR/trex" "$INSTALL_BIN_PATH"
    fi
    rm -rf "$REPO_DIR/trex"

    if [ -d "$INSTALL_BIN_PATH/trex" ]; then
        echo "Setup Environment variables for Test Harness...."
        PYTHONPATH="$INSTALL_BIN_PATH/trex/scripts/automation/trex_control_plane:$INSTALL_BIN_PATH/trex/scripts/automation/trex_control_plane/stl"
        PY_PATH=$(grep PYTHONPATH ~/.bash_profile)
        if [ "$PY_PATH" = "" ] ; then
            sh -c "echo export PYTHONPATH=$PYTHONPATH >> ~/.bash_profile" > /dev/null
        else
            echo "Your ~/.bash_profile already contains a PYTHONPATH definition."
            echo "Make sure it contains $PYTHONPATH which is required to run TRex"
        fi
    fi
    cp "$REPO_DIR/yardstick/network_services/nfvi/collectd.sh" "$INSTALL_BIN_PATH"
    cp "$REPO_DIR/yardstick/network_services/nfvi/collectd.conf" "$INSTALL_BIN_PATH"
    cp "$REPO_DIR/nsb_setup.sh" "$INSTALL_BIN_PATH"
    echo "Done"
}

check_installed_files()
{
    if [ ! -f "$INSTALL_BIN_PATH/yardstick_venv/bin/activate" ]; then
        echo "Installation Error. Failed to create yardstick virtual env..."
        exit 1
    fi

    if [ ! -d "$INSTALL_BIN_PATH/dpdk-16.07" ]; then
        echo "Installation Error. Failed to download and install dpdk-16.07..."
        exit 1
    fi

    if [ ! -d "$INSTALL_BIN_PATH/trex" ]; then
        echo "Installation Error. Failed to download and configure Trex"
        exit 1
    fi

    if [ ! -f "$INSTALL_BIN_PATH/vPE_vnf" ]; then
        echo "Installation Error. vPE VNF not present in install dir $INSTALL_BIN_PATH"
        exit 1
    fi
}

if [ "$1" == "dpdk" ]; then
   install_libs
   install_dpdk
else
   install_libs
   install_yardstick
   install_dpdk
   install_trex
   push_nsb_binary
   check_installed_files
clear
echo "Installation completed..."
echo "Virtual Environment : $INSTALL_BIN_PATH/yardstick_venv"
echo "Please Refer README.NSB.rst document on how to get started on VNF testing."
fi