Merge "Initial version vCPE TOSCA infra template"
[demo.git] / vnfs / vCPE / scripts / v_gw_install.sh
1 #!/bin/bash
2
3 REPO_URL_BLOB=$(cat /opt/config/repo_url_blob.txt)
4 REPO_URL_ARTIFACTS=$(cat /opt/config/repo_url_artifacts.txt)
5 DEMO_ARTIFACTS_VERSION=$(cat /opt/config/demo_artifacts_version.txt)
6 INSTALL_SCRIPT_VERSION=$(cat /opt/config/install_script_version.txt)
7 VPP_SOURCE_REPO_URL=$(cat /opt/config/vpp_source_repo_url.txt)
8 VPP_SOURCE_REPO_BRANCH=$(cat /opt/config/vpp_source_repo_branch.txt)
9 HC2VPP_SOURCE_REPO_URL=$(cat /opt/config/hc2vpp_source_repo_url.txt)
10 HC2VPP_SOURCE_REPO_BRANCH=$(cat /opt/config/hc2vpp_source_repo_branch.txt)
11 CLOUD_ENV=$(cat /opt/config/cloud_env.txt)
12
13 # Convert Network CIDR to Netmask
14 cdr2mask () {
15         # Number of args to shift, 255..255, first non-255 byte, zeroes
16         set -- $(( 5 - ($1 / 8) )) 255 255 255 255 $(( (255 << (8 - ($1 % 8))) & 255 )) 0 0 0
17         [ $1 -gt 1 ] && shift $1 || shift
18         echo ${1-0}.${2-0}.${3-0}.${4-0}
19 }
20
21 # OpenStack network configuration
22 if [[ $CLOUD_ENV == "openstack" ]]
23 then
24         echo 127.0.0.1 $(hostname) >> /etc/hosts
25
26         # Allow remote login as root
27         mv /root/.ssh/authorized_keys /root/.ssh/authorized_keys.bk
28         cp /home/ubuntu/.ssh/authorized_keys /root/.ssh
29
30         MTU=$(/sbin/ifconfig | grep MTU | sed 's/.*MTU://' | sed 's/ .*//' | sort -n | head -1)
31
32         IP=$(cat /opt/config/mux_gw_private_net_ipaddr.txt)
33         BITS=$(cat /opt/config/mux_gw_private_net_cidr.txt | cut -d"/" -f2)
34         NETMASK=$(cdr2mask $BITS)
35         echo "auto eth1" >> /etc/network/interfaces
36         echo "iface eth1 inet static" >> /etc/network/interfaces
37         echo "    address $IP" >> /etc/network/interfaces
38         echo "    netmask $NETMASK" >> /etc/network/interfaces
39         echo "    mtu $MTU" >> /etc/network/interfaces
40
41         IP=$(cat /opt/config/oam_ipaddr.txt)
42         BITS=$(cat /opt/config/oam_cidr.txt | cut -d"/" -f2)
43         NETMASK=$(cdr2mask $BITS)
44         echo "auto eth2" >> /etc/network/interfaces
45         echo "iface eth2 inet static" >> /etc/network/interfaces
46         echo "    address $IP" >> /etc/network/interfaces
47         echo "    netmask $NETMASK" >> /etc/network/interfaces
48         echo "    mtu $MTU" >> /etc/network/interfaces
49
50         ifup eth1
51         ifup eth2
52 fi
53
54 # Download required dependencies
55 echo "deb http://ppa.launchpad.net/openjdk-r/ppa/ubuntu $(lsb_release -c -s) main" >>  /etc/apt/sources.list.d/java.list
56 echo "deb-src http://ppa.launchpad.net/openjdk-r/ppa/ubuntu $(lsb_release -c -s) main" >>  /etc/apt/sources.list.d/java.list
57 apt-get update
58 apt-get install --allow-unauthenticated -y wget openjdk-8-jdk apt-transport-https ca-certificates g++ libcurl4-gnutls-dev
59 sleep 1
60
61 # Install the tools required for download codes
62 apt-get install -y expect git
63
64 #Download and build the VPP codes
65 cd /opt
66 git clone ${VPP_SOURCE_REPO_URL} -b ${VPP_SOURCE_REPO_BRANCH} vpp
67
68 cd vpp
69 expect -c "
70         set timeout 60;
71         spawn make install-dep;
72         expect {
73                 \"Do you want to continue?*\" {send \"Y\r\"; interact}
74         }
75 "
76
77 cd build-root
78 ./bootstrap.sh
79 make V=0 PLATFORM=vpp TAG=vpp install-deb
80
81 # Install the VPP package
82 dpkg -i *.deb
83 systemctl stop vpp
84
85 # Auto-start configuration for the VPP
86 cat > /etc/vpp/startup.conf << EOF
87
88 unix {
89   nodaemon
90   log /tmp/vpp.log
91   full-coredump
92   cli-listen localhost:5002
93   startup-config /etc/vpp/setup.gate
94 }
95
96 api-trace {
97   on
98 }
99
100 api-segment {
101   gid vpp
102 }
103
104 cpu {
105         ## In the VPP there is one main thread and optionally the user can create worker(s)
106         ## The main thread and worker thread(s) can be pinned to CPU core(s) manually or automatically
107
108         ## Manual pinning of thread(s) to CPU core(s)
109
110         ## Set logical CPU core where main thread runs
111         # main-core 1
112
113         ## Set logical CPU core(s) where worker threads are running
114         # corelist-workers 2-3,18-19
115
116         ## Automatic pinning of thread(s) to CPU core(s)
117
118         ## Sets number of CPU core(s) to be skipped (1 ... N-1)
119         ## Skipped CPU core(s) are not used for pinning main thread and working thread(s).
120         ## The main thread is automatically pinned to the first available CPU core and worker(s)
121         ## are pinned to next free CPU core(s) after core assigned to main thread
122         # skip-cores 4
123
124         ## Specify a number of workers to be created
125         ## Workers are pinned to N consecutive CPU cores while skipping "skip-cores" CPU core(s)
126         ## and main thread's CPU core
127         # workers 2
128
129         ## Set scheduling policy and priority of main and worker threads
130
131         ## Scheduling policy options are: other (SCHED_OTHER), batch (SCHED_BATCH)
132         ## idle (SCHED_IDLE), fifo (SCHED_FIFO), rr (SCHED_RR)
133         # scheduler-policy fifo
134
135         ## Scheduling priority is used only for "real-time policies (fifo and rr),
136         ## and has to be in the range of priorities supported for a particular policy
137         # scheduler-priority 50
138 }
139
140 # dpdk {
141         ## Change default settings for all intefaces
142         # dev default {
143                 ## Number of receive queues, enables RSS
144                 ## Default is 1
145                 # num-rx-queues 3
146
147                 ## Number of transmit queues, Default is equal
148                 ## to number of worker threads or 1 if no workers treads
149                 # num-tx-queues 3
150
151                 ## Number of descriptors in transmit and receive rings
152                 ## increasing or reducing number can impact performance
153                 ## Default is 1024 for both rx and tx
154                 # num-rx-desc 512
155                 # num-tx-desc 512
156
157                 ## VLAN strip offload mode for interface
158                 ## Default is off
159                 # vlan-strip-offload on
160         # }
161
162         ## Whitelist specific interface by specifying PCI address
163         # dev 0000:02:00.0
164
165         ## Whitelist specific interface by specifying PCI address and in
166         ## addition specify custom parameters for this interface
167         # dev 0000:02:00.1 {
168         #       num-rx-queues 2
169         # }
170
171         ## Change UIO driver used by VPP, Options are: igb_uio, vfio-pci
172         ## and uio_pci_generic (default)
173         # uio-driver vfio-pci
174
175         ## Disable mutli-segment buffers, improves performance but
176         ## disables Jumbo MTU support
177         # no-multi-seg
178
179         ## Increase number of buffers allocated, needed only in scenarios with
180         ## large number of interfaces and worker threads. Value is per CPU socket.
181         ## Default is 16384
182         # num-mbufs 128000
183
184         ## Change hugepages allocation per-socket, needed only if there is need for
185         ## larger number of mbufs. Default is 256M on each detected CPU socket
186         # socket-mem 2048,2048
187 # }
188
189 EOF
190
191 cat > /etc/vpp/setup.gate << EOF
192 set int state GigabitEthernet0/8/0 up
193 set int ip address GigabitEthernet0/8/0 10.5.0.21/24
194
195 set int state GigabitEthernet0/9/0 up
196 set dhcp client intfc GigabitEthernet0/9/0 hostname vg-1
197
198 tap connect lstack address 192.168.1.1/24
199 set int state tap-0 up
200
201 create vxlan tunnel src 10.5.0.21 dst 10.5.0.20 vni 100
202
203 set interface l2 bridge tap-0 10 0
204 set interface l2 bridge vxlan_tunnel0 10 1
205 set bridge-domain arp term 10
206
207 set int ip address vxlan_tunnel0 192.168.1.254/24
208 set interface snat in vxlan_tunnel0 out GigabitEthernet0/9/0
209 EOF
210
211 # Download and install HC2VPP from source
212 cd /opt
213 git clone ${HC2VPP_SOURCE_REPO_URL} -b ${HC2VPP_SOURCE_REPO_BRANCH} hc2vpp
214
215 apt-get install -y maven
216 cat > ~/.m2/settings.xml << EOF
217 <?xml version="1.0" encoding="UTF-8"?>
218 <!-- vi: set et smarttab sw=2 tabstop=2: -->
219 <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
220   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
221   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
222
223   <profiles>
224     <profile>
225       <id>fd.io-release</id>
226       <repositories>
227         <repository>
228           <id>fd.io-mirror</id>
229           <name>fd.io-mirror</name>
230           <url>https://nexus.fd.io/content/groups/public/</url>
231           <releases>
232             <enabled>true</enabled>
233             <updatePolicy>never</updatePolicy>
234           </releases>
235           <snapshots>
236             <enabled>false</enabled>
237           </snapshots>
238         </repository>
239       </repositories>
240       <pluginRepositories>
241         <pluginRepository>
242           <id>fd.io-mirror</id>
243           <name>fd.io-mirror</name>
244           <url>https://nexus.fd.io/content/repositories/public/</url>
245           <releases>
246             <enabled>true</enabled>
247             <updatePolicy>never</updatePolicy>
248           </releases>
249           <snapshots>
250             <enabled>false</enabled>
251           </snapshots>
252         </pluginRepository>
253       </pluginRepositories>
254     </profile>
255
256     <profile>
257       <id>fd.io-snapshots</id>
258       <repositories>
259         <repository>
260           <id>fd.io-snapshot</id>
261           <name>fd.io-snapshot</name>
262           <url>https://nexus.fd.io/content/repositories/fd.io.snapshot/</url>
263           <releases>
264             <enabled>false</enabled>
265           </releases>
266           <snapshots>
267             <enabled>true</enabled>
268           </snapshots>
269         </repository>
270       </repositories>
271       <pluginRepositories>
272         <pluginRepository>
273           <id>fd.io-snapshot</id>
274           <name>fd.io-snapshot</name>
275           <url>https://nexus.fd.io/content/repositories/fd.io.snapshot/</url>
276           <releases>
277             <enabled>false</enabled>
278           </releases>
279           <snapshots>
280             <enabled>true</enabled>
281           </snapshots>
282         </pluginRepository>
283       </pluginRepositories>
284     </profile>
285     <profile>
286       <id>opendaylight-snapshots</id>
287       <repositories>
288         <repository>
289           <id>opendaylight-snapshot</id>
290           <name>opendaylight-snapshot</name>
291           <url>https://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/</url>
292           <releases>
293             <enabled>false</enabled>
294           </releases>
295           <snapshots>
296             <enabled>true</enabled>
297           </snapshots>
298         </repository>
299       </repositories>
300       <pluginRepositories>
301         <pluginRepository>
302           <id>opendaylight-shapshot</id>
303           <name>opendaylight-snapshot</name>
304           <url>https://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/</url>
305           <releases>
306             <enabled>false</enabled>
307           </releases>
308           <snapshots>
309             <enabled>true</enabled>
310           </snapshots>
311         </pluginRepository>
312       </pluginRepositories>
313     </profile>
314   </profiles>
315
316   <activeProfiles>
317     <activeProfile>fd.io-release</activeProfile>
318     <activeProfile>fd.io-snapshots</activeProfile>
319     <activeProfile>opendaylight-snapshots</activeProfile>
320   </activeProfiles>
321 </settings>
322 EOF
323
324 cd hc2vpp
325 mvn clean install
326 l_version=$(cat pom.xml | grep "<version>" | head -1)
327 l_version=$(echo "${l_version%<*}")
328 l_version=$(echo "${l_version#*>}")
329 mv vpp-integration/minimal-distribution/target/vpp-integration-distribution-${l_version}-hc/vpp-integration-distribution-${l_version} /opt/honeycomb
330 sed -i 's/127.0.0.1/0.0.0.0/g' /opt/honeycomb/config/honeycomb.json
331
332 # Create systemctl service for Honeycomb
333 cat > /etc/systemd/system/honeycomb.service << EOF
334 [Unit]
335 Description=Honeycomb Agent for the VPP control plane
336 Documentation=https://wiki.fd.io/view/Honeycomb
337 Requires=vpp.service
338 After=vpp.service
339
340 [Service]
341 ExecStart=/opt/honeycomb/honeycomb
342 Restart=always
343 RestartSec=10
344
345 [Install]
346 WantedBy=multi-user.target
347 EOF
348 systemctl enable /etc/systemd/system/honeycomb.service
349
350 # Install the DHCP server and config
351 apt-get install -y isc-dhcp-server
352 cat >> /etc/dhcp/dhcpd.conf << EOF
353 subnet 192.168.1.0 netmask 255.255.255.0 {
354   range 192.168.1.2 192.168.1.253;
355   option subnet-mask 255.255.255.0;
356   option routers 192.168.1.254;
357   option broadcast-address 192.168.1.255;
358   default-lease-time 600;
359   max-lease-time 7200;
360 }
361 EOF
362
363 # Download DHCP config files
364 cd /opt
365 wget $REPO_URL_BLOB/org.onap.demo/vnfs/vcpe/$INSTALL_SCRIPT_VERSION/v_gw_init.sh
366 wget $REPO_URL_BLOB/org.onap.demo/vnfs/vcpe/$INSTALL_SCRIPT_VERSION/v_gw.sh
367 chmod +x v_gw_init.sh
368 chmod +x v_gw.sh
369 mv v_gw.sh /etc/init.d
370 update-rc.d v_gw.sh defaults
371
372 # Rename network interface in openstack Ubuntu 16.04 images. Then, reboot the VM to pick up changes
373 if [[ $CLOUD_ENV != "rackspace" ]]
374 then
375         sed -i "s/GRUB_CMDLINE_LINUX=.*/GRUB_CMDLINE_LINUX=\"net.ifnames=0 biosdevname=0\"/g" /etc/default/grub
376         grub-mkconfig -o /boot/grub/grub.cfg
377         sed -i "s/ens[0-9]*/eth0/g" /etc/network/interfaces.d/*.cfg
378         sed -i "s/ens[0-9]*/eth0/g" /etc/udev/rules.d/70-persistent-net.rules
379         echo 'network: {config: disabled}' >> /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
380         echo "APT::Periodic::Unattended-Upgrade \"0\";" >> /etc/apt/apt.conf.d/10periodic
381         reboot
382 fi
383
384 ./v_gw_init.sh