summaryrefslogtreecommitdiffstats
path: root/tools/ubuntu-server-cloudimg-dpdk-samplevnf-modify.sh
blob: fa5e6aa4bfe6bd075e6671d53e85a0dd4eb25560 (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#!/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.

# installs required packages
# must be run from inside the image (either chrooted or running)

set -ex

if [ $# -eq 1 ]; then
    nameserver_ip=$1

    # /etc/resolv.conf is a symbolic link to /run, restore at end
    rm /etc/resolv.conf
    echo "nameserver $nameserver_ip" > /etc/resolv.conf
    echo "nameserver 8.8.8.8" >> /etc/resolv.conf
    echo "nameserver 8.8.4.4" >> /etc/resolv.conf
fi

INSTALL_BIN_PATH="/opt/nsb_bin"
BIN_PATH="/usr/sbin/"
TREX_VERSION="v2.20"
TREX_DOWNLOAD="https://trex-tgn.cisco.com/trex/release/$TREX_VERSION.tar.gz"
TREX_DIR=$INSTALL_BIN_PATH/trex/scripts

enable_proxy()
{
       echo $https_proxy
       echo $http_proxy
       if [[ "$http_proxy" != "" ]]; then
           echo 'Acquire::http::Proxy "$http_proxy";' > /etc/apt/apt.conf
       fi
}

install_trex()
{

	INSTALL_BIN_PATH="/opt/nsb_bin"
	DPDK_DOWNLOAD="http://dpdk.org/browse/dpdk/snapshot/dpdk-16.07.zip"
	TREX_VERSION="v2.20"
	TREX_DOWNLOAD="https://trex-tgn.cisco.com/trex/release/$TREX_VERSION.tar.gz"
	TREX_DIR=$INSTALL_BIN_PATH/trex/scripts
        pushd .
	cd $INSTALL_BIN_PATH
	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 $INSTALL_BIN_PATH/trex
	mkdir -p $INSTALL_BIN_PATH/trex
	mv $TREX_VERSION trex/scripts
	rm -rf $TREX_VERSION.tar.gz
	cd $INSTALL_BIN_PATH/trex/scripts/ko/src/
	make
	make install
	touch "$INSTALL_BIN_PATH/trex/scripts/automation/trex_control_plane/stl/__init__.py"
	cp "$INSTALL_BIN_PATH/trex/scripts/dpdk_nic_bind.py" "$INSTALL_BIN_PATH"
        popd
}
install_sample_vnf()
{
	      mkdir -p $INSTALL_BIN_PATH
        echo "Install Sample VNFs"
        pushd .
        cd $INSTALL_BIN_PATH
        git clone https://git.opnfv.org/samplevnf
        cd samplevnf
        VNF_CORE=$INSTALL_BIN_PATH/samplevnf
        ./tools/vnf_build.sh -s -d='17.02'
        cp $VNF_CORE/VNFs/vACL/build/vACL $INSTALL_BIN_PATH
        cp $VNF_CORE/VNFs/vCGNAPT/build/vCGNAPT $INSTALL_BIN_PATH
        cp $VNF_CORE/VNFs/vFW/build/vFW $INSTALL_BIN_PATH
        cp $VNF_CORE/VNFs/DPPD-PROX/build/prox $INSTALL_BIN_PATH
        cp $VNF_CORE/VNFs/UDP_Replay/build/UDP_Replay $INSTALL_BIN_PATH
        cp $VNF_CORE/VNFs/vFW/vnf_template.txt $INSTALL_BIN_PATH

				# copy to standard path
        cp $VNF_CORE/VNFs/vACL/build/vACL $BIN_PATH
        cp $VNF_CORE/VNFs/vCGNAPT/build/vCGNAPT $BIN_PATH
        cp $VNF_CORE/VNFs/vFW/build/vFW $BIN_PATH
        cp $VNF_CORE/VNFs/DPPD-PROX/build/prox $BIN_PATH
        cp $VNF_CORE/VNFs/UDP_Replay/build/UDP_Replay $BIN_PATH

        # build vpe
        cd $VNF_CORE/dpdk/examples/ip_pipeline
        export RTE_SDK= $VNF_CORE/dpdk
        make
        cp $VNF_CORE/build/ip_pipeline $INSTALL_BIN_PATH/vPE_vnf

	      echo "Done"
        popd
}
# iperf3 only available for trusty in backports
if grep -q trusty /etc/apt/sources.list ; then
    if [ "${YARD_IMG_ARCH}" = "arm64" ]; then
        echo "deb [arch=${YARD_IMG_ARCH}] http://ports.ubuntu.com/ trusty-backports main restricted universe multiverse" >> /etc/apt/sources.list
    else
        echo "deb http://archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse" >> /etc/apt/sources.list
    fi
fi

# Workaround for building on CentOS (apt-get is not working with http sources)
# sed -i 's/http/ftp/' /etc/apt/sources.list

# Force apt to use ipv4 due to build problems on LF POD.
echo 'Acquire::ForceIPv4 "true";' > /etc/apt/apt.conf.d/99force-ipv4

echo 'GRUB_CMDLINE_LINUX="resume=/dev/sda1 default_hugepagesz=1G hugepagesz=1G hugepages=4 iommu=on iommu=pt intel_iommu=on"' >> /etc/default/grub
echo 'huge /mnt/huge hugetlbfs defaults 0 0' >> vi /etc/fstab

mkdir /mnt/huge
chmod 777 /mnt/huge

for i in {1..2}
do
    touch /etc/network/interfaces.d/eth$i.cfg
    chmod 777 /etc/network/interfaces.d/eth$i.cfg
    echo "auto eth$i" >> /etc/network/interfaces.d/eth$i.cfg
    echo "iface eth$i inet dhcp" >> /etc/network/interfaces.d/eth$i.cfg
done

# this needs for checking dpdk status, adding interfaces to dpdk, bind, unbind etc..

# Add hostname to /etc/hosts.
# Allow console access via pwd
cat <<EOF >/etc/cloud/cloud.cfg.d/10_etc_hosts.cfg
manage_etc_hosts: True
#password: RANDOM
password: password
chpasswd: { expire: False }
ssh_pwauth: True
EOF

linuxheadersversion=$(echo ls boot/vmlinuz* | cut -d- -f2-)

apt-get update
apt-get install -y \
    bc \
    fio \
    gcc \
    git \
    iperf3 \
    iproute2 \
    ethtool \
    linux-tools-common \
    linux-tools-generic \
    lmbench \
    make \
    netperf \
    patch \
    perl \
    rt-tests \
    stress \
    sysstat \
    linux-headers-"${linuxheadersversion}" \
    libpcap-dev \
    chpasswd \
    lua5.2

# Build dpdk vPE VNF
pushd .
echo "root:root" | chpasswd
enable_proxy
install_sample_vnf
install_trex
popd .
cd /root

sed -i -e 's/PermitRootLogin without-password/PermitRootLogin yes/g'  /etc/ssh/sshd_config
sed -i -e 's/prohibit-password/yes/g' /etc/ssh/sshd_config
passwd

CLONE_DEST=/opt/tempT
# remove before cloning
rm -rf -- "${CLONE_DEST}"
git clone https://github.com/kdlucas/byte-unixbench.git "${CLONE_DEST}"
make --directory "${CLONE_DEST}/UnixBench/"

git clone https://github.com/beefyamoeba5/ramspeed.git "${CLONE_DEST}/RAMspeed"
cd "${CLONE_DEST}/RAMspeed/ramspeed-2.6.0"
mkdir temp
bash build.sh

git clone https://github.com/beefyamoeba5/cachestat.git "${CLONE_DEST}"/Cachestat

# restore symlink
ln -sfrT /run/resolvconf/resolv.conf /etc/resolv.conf