Merge "Correct portal apps property directory name"
[demo.git] / vnfs / vCPE / scripts / v_gmux_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 VPP_PATCH_URL=$(cat /opt/config/vpp_patch_url.txt)
10 HC2VPP_SOURCE_REPO_URL=$(cat /opt/config/hc2vpp_source_repo_url.txt)
11 HC2VPP_SOURCE_REPO_BRANCH=$(cat /opt/config/hc2vpp_source_repo_branch.txt)
12 HC2VPP_PATCH_URL=$(cat /opt/config/hc2vpp_patch_url.txt)
13 CLOUD_ENV=$(cat /opt/config/cloud_env.txt)
14
15 # Convert Network CIDR to Netmask
16 cdr2mask () {
17         # Number of args to shift, 255..255, first non-255 byte, zeroes
18         set -- $(( 5 - ($1 / 8) )) 255 255 255 255 $(( (255 << (8 - ($1 % 8))) & 255 )) 0 0 0
19         [ $1 -gt 1 ] && shift $1 || shift
20         echo ${1-0}.${2-0}.${3-0}.${4-0}
21 }
22
23 # OpenStack network configuration
24 if [[ $CLOUD_ENV == "openstack" ]]
25 then
26         echo 127.0.0.1 $(hostname) >> /etc/hosts
27
28         # Allow remote login as root
29         mv /root/.ssh/authorized_keys /root/.ssh/authorized_keys.bk
30         cp /home/ubuntu/.ssh/authorized_keys /root/.ssh
31
32         MTU=$(/sbin/ifconfig | grep MTU | sed 's/.*MTU://' | sed 's/ .*//' | sort -n | head -1)
33
34         IP=$(cat /opt/config/bng_mux_net_ipaddr.txt)
35         BITS=$(cat /opt/config/bng_mux_net_cidr.txt | cut -d"/" -f2)
36         NETMASK=$(cdr2mask $BITS)
37         echo "auto eth1" >> /etc/network/interfaces
38         echo "iface eth1 inet static" >> /etc/network/interfaces
39         echo "    address $IP" >> /etc/network/interfaces
40         echo "    netmask $NETMASK" >> /etc/network/interfaces
41         echo "    mtu $MTU" >> /etc/network/interfaces
42
43         IP=$(cat /opt/config/oam_ipaddr.txt)
44         BITS=$(cat /opt/config/oam_cidr.txt | cut -d"/" -f2)
45         NETMASK=$(cdr2mask $BITS)
46         echo "auto eth2" >> /etc/network/interfaces
47         echo "iface eth2 inet static" >> /etc/network/interfaces
48         echo "    address $IP" >> /etc/network/interfaces
49         echo "    netmask $NETMASK" >> /etc/network/interfaces
50         echo "    mtu $MTU" >> /etc/network/interfaces
51
52         IP=$(cat /opt/config/mux_gw_net_ipaddr.txt)
53         BITS=$(cat /opt/config/mux_gw_net_cidr.txt | cut -d"/" -f2)
54         NETMASK=$(cdr2mask $BITS)
55         echo "auto eth3" >> /etc/network/interfaces
56         echo "iface eth3 inet static" >> /etc/network/interfaces
57         echo "    address $IP" >> /etc/network/interfaces
58         echo "    netmask $NETMASK" >> /etc/network/interfaces
59         echo "    mtu $MTU" >> /etc/network/interfaces
60
61         ifup eth1
62         ifup eth2
63         ifup eth3
64 fi
65
66 # Download required dependencies
67 echo "deb http://ppa.launchpad.net/openjdk-r/ppa/ubuntu $(lsb_release -c -s) main" >>  /etc/apt/sources.list.d/java.list
68 echo "deb-src http://ppa.launchpad.net/openjdk-r/ppa/ubuntu $(lsb_release -c -s) main" >>  /etc/apt/sources.list.d/java.list
69 apt-get update
70 apt-get install --allow-unauthenticated -y wget openjdk-8-jdk apt-transport-https ca-certificates g++ libcurl4-gnutls-dev
71 sleep 1
72
73 # Install the tools required for download codes
74 apt-get install -y expect git patch make
75
76 #Download and build the VPP codes
77 cd /opt
78 git clone ${VPP_SOURCE_REPO_URL} -b ${VPP_SOURCE_REPO_BRANCH} vpp
79 wget -O Vpp-Add-VES-agent-for-vG-MUX.patch ${VPP_PATCH_URL} 
80
81 cd vpp
82 patch -p1 < ../Vpp-Add-VES-agent-for-vG-MUX.patch
83 expect -c "
84         spawn make install-dep;
85         expect {
86                 \"Do you want to continue?*\" {send \"Y\r\"; interact}
87         }
88 "
89
90 # Install the evel-library first since we need the lib
91 cd /opt
92 apt-get install -y libcurl4-openssl-dev
93 git clone http://gerrit.onap.org/r/demo
94 cd demo/vnfs/VES5.0/evel/evel-library/bldjobs 
95 make
96 cp ../libs/x86_64/libevel.so /usr/lib
97 ldconfig
98
99 cd /opt/vpp/build-root
100 ./bootstrap.sh
101 make V=0 PLATFORM=vpp TAG=vpp install-deb
102
103 # Install the VPP package
104 apt install -y python-ply-lex-3.5 python-ply-yacc-3.5 python-pycparser python-cffi
105 dpkg -i *.deb
106 systemctl stop vpp
107
108 # Auto-start configuration for the VPP
109 cat > /etc/vpp/startup.conf << EOF
110
111 unix {
112   nodaemon
113   log /tmp/vpp.log
114   full-coredump
115   cli-listen localhost:5002
116   startup-config /etc/vpp/setup.gate
117 }
118
119 api-trace {
120   on
121 }
122
123 api-segment {
124   gid vpp
125 }
126
127 cpu {
128         ## In the VPP there is one main thread and optionally the user can create worker(s)
129         ## The main thread and worker thread(s) can be pinned to CPU core(s) manually or automatically
130
131         ## Manual pinning of thread(s) to CPU core(s)
132
133         ## Set logical CPU core where main thread runs
134         # main-core 1
135
136         ## Set logical CPU core(s) where worker threads are running
137         # corelist-workers 2-3,18-19
138
139         ## Automatic pinning of thread(s) to CPU core(s)
140
141         ## Sets number of CPU core(s) to be skipped (1 ... N-1)
142         ## Skipped CPU core(s) are not used for pinning main thread and working thread(s).
143         ## The main thread is automatically pinned to the first available CPU core and worker(s)
144         ## are pinned to next free CPU core(s) after core assigned to main thread
145         # skip-cores 4
146
147         ## Specify a number of workers to be created
148         ## Workers are pinned to N consecutive CPU cores while skipping "skip-cores" CPU core(s)
149         ## and main thread's CPU core
150         # workers 2
151
152         ## Set scheduling policy and priority of main and worker threads
153
154         ## Scheduling policy options are: other (SCHED_OTHER), batch (SCHED_BATCH)
155         ## idle (SCHED_IDLE), fifo (SCHED_FIFO), rr (SCHED_RR)
156         # scheduler-policy fifo
157
158         ## Scheduling priority is used only for "real-time policies (fifo and rr),
159         ## and has to be in the range of priorities supported for a particular policy
160         # scheduler-priority 50
161 }
162
163 # dpdk {
164         ## Change default settings for all intefaces
165         # dev default {
166                 ## Number of receive queues, enables RSS
167                 ## Default is 1
168                 # num-rx-queues 3
169
170                 ## Number of transmit queues, Default is equal
171                 ## to number of worker threads or 1 if no workers treads
172                 # num-tx-queues 3
173
174                 ## Number of descriptors in transmit and receive rings
175                 ## increasing or reducing number can impact performance
176                 ## Default is 1024 for both rx and tx
177                 # num-rx-desc 512
178                 # num-tx-desc 512
179
180                 ## VLAN strip offload mode for interface
181                 ## Default is off
182                 # vlan-strip-offload on
183         # }
184
185         ## Whitelist specific interface by specifying PCI address
186         # dev 0000:02:00.0
187
188         ## Whitelist specific interface by specifying PCI address and in
189         ## addition specify custom parameters for this interface
190         # dev 0000:02:00.1 {
191         #       num-rx-queues 2
192         # }
193
194         ## Change UIO driver used by VPP, Options are: igb_uio, vfio-pci
195         ## and uio_pci_generic (default)
196         # uio-driver vfio-pci
197
198         ## Disable mutli-segment buffers, improves performance but
199         ## disables Jumbo MTU support
200         # no-multi-seg
201
202         ## Increase number of buffers allocated, needed only in scenarios with
203         ## large number of interfaces and worker threads. Value is per CPU socket.
204         ## Default is 16384
205         # num-mbufs 128000
206
207         ## Change hugepages allocation per-socket, needed only if there is need for
208         ## larger number of mbufs. Default is 256M on each detected CPU socket
209         # socket-mem 2048,2048
210 # }
211
212 EOF
213
214 cat > /etc/vpp/setup.gate << EOF
215 set int state GigabitEthernet0/8/0 up
216 set int ip address GigabitEthernet0/8/0 10.1.0.20/24
217
218 set int state GigabitEthernet0/9/0 up
219 set int ip address GigabitEthernet0/9/0 10.5.0.20/24
220
221 create vxlan tunnel src 10.5.0.20 dst 10.5.0.21 vni 100
222 EOF
223
224 # Download and install HC2VPP from source
225 cd /opt
226 git clone ${HC2VPP_SOURCE_REPO_URL} -b ${HC2VPP_SOURCE_REPO_BRANCH} hc2vpp
227 wget -O Hc2vpp-Add-VES-agent-for-vG-MUX.patch ${HC2VPP_PATCH_URL}
228
229 apt-get install -y maven
230 mkdir -p ~/.m2
231 cat > ~/.m2/settings.xml << EOF
232 <?xml version="1.0" encoding="UTF-8"?>
233 <!-- vi: set et smarttab sw=2 tabstop=2: -->
234 <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
235   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
236   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
237
238   <profiles>
239     <profile>
240       <id>fd.io-release</id>
241       <repositories>
242         <repository>
243           <id>fd.io-mirror</id>
244           <name>fd.io-mirror</name>
245           <url>https://nexus.fd.io/content/groups/public/</url>
246           <releases>
247             <enabled>true</enabled>
248             <updatePolicy>never</updatePolicy>
249           </releases>
250           <snapshots>
251             <enabled>false</enabled>
252           </snapshots>
253         </repository>
254       </repositories>
255       <pluginRepositories>
256         <pluginRepository>
257           <id>fd.io-mirror</id>
258           <name>fd.io-mirror</name>
259           <url>https://nexus.fd.io/content/repositories/public/</url>
260           <releases>
261             <enabled>true</enabled>
262             <updatePolicy>never</updatePolicy>
263           </releases>
264           <snapshots>
265             <enabled>false</enabled>
266           </snapshots>
267         </pluginRepository>
268       </pluginRepositories>
269     </profile>
270
271     <profile>
272       <id>fd.io-snapshots</id>
273       <repositories>
274         <repository>
275           <id>fd.io-snapshot</id>
276           <name>fd.io-snapshot</name>
277           <url>https://nexus.fd.io/content/repositories/fd.io.snapshot/</url>
278           <releases>
279             <enabled>false</enabled>
280           </releases>
281           <snapshots>
282             <enabled>true</enabled>
283           </snapshots>
284         </repository>
285       </repositories>
286       <pluginRepositories>
287         <pluginRepository>
288           <id>fd.io-snapshot</id>
289           <name>fd.io-snapshot</name>
290           <url>https://nexus.fd.io/content/repositories/fd.io.snapshot/</url>
291           <releases>
292             <enabled>false</enabled>
293           </releases>
294           <snapshots>
295             <enabled>true</enabled>
296           </snapshots>
297         </pluginRepository>
298       </pluginRepositories>
299     </profile>
300     <profile>
301       <id>opendaylight-snapshots</id>
302       <repositories>
303         <repository>
304           <id>opendaylight-snapshot</id>
305           <name>opendaylight-snapshot</name>
306           <url>https://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/</url>
307           <releases>
308             <enabled>false</enabled>
309           </releases>
310           <snapshots>
311             <enabled>true</enabled>
312           </snapshots>
313         </repository>
314       </repositories>
315       <pluginRepositories>
316         <pluginRepository>
317           <id>opendaylight-shapshot</id>
318           <name>opendaylight-snapshot</name>
319           <url>https://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/</url>
320           <releases>
321             <enabled>false</enabled>
322           </releases>
323           <snapshots>
324             <enabled>true</enabled>
325           </snapshots>
326         </pluginRepository>
327       </pluginRepositories>
328     </profile>
329   </profiles>
330
331   <activeProfiles>
332     <activeProfile>fd.io-release</activeProfile>
333     <activeProfile>fd.io-snapshots</activeProfile>
334     <activeProfile>opendaylight-snapshots</activeProfile>
335   </activeProfiles>
336 </settings>
337 EOF
338
339 cd hc2vpp
340 patch -p1 < ../Hc2vpp-Add-VES-agent-for-vG-MUX.patch
341 mvn clean install
342 l_version=$(cat pom.xml | grep "<version>" | head -1)
343 l_version=$(echo "${l_version%<*}")
344 l_version=$(echo "${l_version#*>}")
345 mv vpp-integration/minimal-distribution/target/vpp-integration-distribution-${l_version}-hc/vpp-integration-distribution-${l_version} /opt/honeycomb
346 sed -i 's/127.0.0.1/0.0.0.0/g' /opt/honeycomb/config/honeycomb.json
347
348 # Create systemctl service for Honeycomb
349 cat > /etc/systemd/system/honeycomb.service << EOF
350 [Unit]
351 Description=Honeycomb Agent for the VPP control plane
352 Documentation=https://wiki.fd.io/view/Honeycomb
353 Requires=vpp.service
354 After=vpp.service
355
356 [Service]
357 ExecStart=/opt/honeycomb/honeycomb
358 Restart=always
359 RestartSec=10
360
361 [Install]
362 WantedBy=multi-user.target
363 EOF
364 systemctl enable /etc/systemd/system/honeycomb.service
365
366 #Create a systemd service for auto-save
367 cat > /usr/bin/save_config << EOF
368 #!/bin/bash
369
370 #########################################################################
371 #
372 #  Copyright (c) 2017 Intel and/or its affiliates.
373
374 #  Licensed under the Apache License, Version 2.0 (the "License");
375 #  you may not use this file except in compliance with the License.
376 #  You may obtain a copy of the License at:
377
378 #      http://www.apache.org/licenses/LICENSE-2.0
379
380 #  Unless required by applicable law or agreed to in writing, software
381 #  distributed under the License is distributed on an "AS IS" BASIS,
382 #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
383 #  See the License for the specific language governing permissions and
384 #  limitations under the License.
385 #
386 ##########################################################################
387
388 ############################### Variables ################################
389 VPP_SETUP_GATE=/etc/vpp/setup.gate
390
391 ############################### Functions ################################
392
393 # Write the commands to the startup scripts.
394 #
395 # We could set VPP configuration to the startup.conf.
396 # Write the configuration to the startup scripts so we could
397 # restore the system after rebooting.
398 #
399 write_startup_scripts()
400 {
401         local cmd=${2}
402         local is_add=${1}
403
404         if [[ ${is_add} == add ]] ;then
405                 while read -r line
406                 do
407                         if [[ ${line} == ${cmd} ]] ;then
408                                 return 0
409                         fi
410                 done < ${VPP_SETUP_GATE}
411
412                 echo "${cmd}" >> ${VPP_SETUP_GATE}
413         else
414                 while read -r line
415                 do
416                         if [[ ${line} == ${cmd} ]] ;then
417                                 sed -i "/${line}/d" ${VPP_SETUP_GATE}
418                                 return 0
419                         fi
420                 done < ${VPP_SETUP_GATE}
421         fi
422 }
423
424 # Saves the VES agent configuration to the startup script.
425 #
426 # Get the current VES agent configuration from the bash command:
427 # $vppctl show ves agent
428 #    Server Addr    Server Port Interval Enabled
429 #    127.0.0.1        8080         10    True
430 # Set the VES agent configuration with the bash command:
431 # $vppctl set ves agent server 127.0.0.1 port 8080 intval 10
432 #
433 save_ves_config()
434 {
435         local server=""
436         local port=""
437         local intval=""
438
439         local ves_config=`vppctl show ves agent | head -2 | tail -1`
440         if [ "${ves_config}" != "" ] ;then
441                 server=`echo ${ves_config} | awk '{ print $1 }'`
442                 port=`echo ${ves_config} | awk '{ print $2 }'`
443                 intval=`echo ${ves_config} | awk '{ print $3 }'`
444                 write_startup_scripts add "set ves agent server ${server} port ${port} intval ${intval}"
445         fi
446 }
447
448 # Save the VxLAN Tunnel Configuration to the startup script.
449 #
450 # Get the current VxLAN tunnel configuration with bash command:
451 # $vppctl show vxlan tunnel
452 #  [0] src 10.3.0.2 dst 10.1.0.20 vni 100 sw_if_index 1 encap_fib_index 0 fib_entry_index 7 decap_next l2
453 #  [1] src 10.5.0.20 dst 10.5.0.21 vni 100 sw_if_index 2 encap_fib_index 0 fib_entry_index 8 decap_next l2
454 # Set the VxLAN Tunnel with the bash command:
455 # $vppctl create vxlan tunnel src 10.3.0.2 dst 10.1.0.20 vni 100
456 # vxlan_tunnel0
457 save_vxlan_tunnel()
458 {
459         local src=""
460         local dst=""
461         local vni=""
462
463         vppctl show vxlan tunnel | while read line
464         do
465                 if [ "${line}" != "" ] ;then
466                         src=`echo ${line} | awk '{ print $3 }'`
467                         dst=`echo ${line} | awk '{ print $5 }'`
468                         vni=`echo ${line} | awk '{ print $7 }'`
469
470                         write_startup_scripts add "create vxlan tunnel src ${src} dst ${dst} vni ${vni}"
471                 fi
472         done
473 }
474
475 # Save the VxLAN tunnel L2 xconnect configuration to the startup script.
476 #
477 # Get the Current L2 Address configuration with bash command:
478 # $vppctl show int addr
479 # local0 (dn):
480 # vxlan_tunnel0 (up):
481 #   l2 xconnect vxlan_tunnel1
482 # vxlan_tunnel1 (up):
483 #   l2 xconnect vxlan_tunnel0
484 # Save the VxLAN tunnel L2 xconnect configuration with bash command:
485 # $vppctl set interface l2 xconnect vxlan_tunnel0 vxlan_tunnel1
486 #
487 save_vxlan_xconnect()
488 {
489         local ingress=""
490         local egress=""
491
492         vppctl show int addr | while read line
493         do
494                 if [[ ${line} == vxlan_tunnel* ]] ;then
495                         read next
496                         while [[ ${next} != l2* ]] || [[ ${next} == "" ]]
497                         do
498                                 line=`echo ${next}`
499                                 read next
500                         done
501                         if [[ ${next} == l2* ]] ;then
502                                 ingress=`echo ${line} | awk '{ print $1 }'`
503                                 egress=`echo ${next} | awk '{ print $3 }'`
504                                 write_startup_scripts add "set interface l2 xconnect ${ingress} ${egress}"
505                         fi
506                 fi
507         done
508 }
509
510 ################################# MAIN ###################################
511
512 save_ves_config
513
514 save_vxlan_tunnel
515
516 save_vxlan_xconnect
517
518 EOF
519 chmod a+x /usr/bin/save_config
520 cat > /etc/systemd/system/autosave.service << EOF
521 [Unit]
522 Description=Run Scripts at Start and Stop
523 Requires=vpp.service
524 After=vpp.service
525
526 [Service]
527 Type=oneshot
528 RemainAfterExit=true
529 ExecStop=/usr/bin/save_config
530
531 [Install]
532 WantedBy=multi-user.target
533 EOF
534 systemctl enable /etc/systemd/system/autosave.service
535
536 # Download DHCP config files
537 cd /opt
538 wget $REPO_URL_BLOB/org.onap.demo/vnfs/vcpe/$INSTALL_SCRIPT_VERSION/v_gmux_init.sh
539 wget $REPO_URL_BLOB/org.onap.demo/vnfs/vcpe/$INSTALL_SCRIPT_VERSION/v_gmux.sh
540 chmod +x v_gmux_init.sh
541 chmod +x v_gmux.sh
542 mv v_gmux.sh /etc/init.d
543 update-rc.d v_gmux.sh defaults
544
545 # Rename network interface in openstack Ubuntu 16.04 images. Then, reboot the VM to pick up changes
546 if [[ $CLOUD_ENV != "rackspace" ]]
547 then
548         sed -i "s/GRUB_CMDLINE_LINUX=.*/GRUB_CMDLINE_LINUX=\"net.ifnames=0 biosdevname=0\"/g" /etc/default/grub
549         grub-mkconfig -o /boot/grub/grub.cfg
550         sed -i "s/ens[0-9]*/eth0/g" /etc/network/interfaces.d/*.cfg
551         sed -i "s/ens[0-9]*/eth0/g" /etc/udev/rules.d/70-persistent-net.rules
552         echo 'network: {config: disabled}' >> /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
553         echo "APT::Periodic::Unattended-Upgrade \"0\";" >> /etc/apt/apt.conf.d/10periodic
554         reboot
555 fi
556
557 ./v_gmux_init.sh