Implement MultiCloud proxyed Designate
[demo.git] / vnfs / vCPE / scripts / v_bng_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 CLOUD_ENV=$(cat /opt/config/cloud_env.txt)
11
12 # Convert Network CIDR to Netmask
13 cdr2mask () {
14         # Number of args to shift, 255..255, first non-255 byte, zeroes
15         set -- $(( 5 - ($1 / 8) )) 255 255 255 255 $(( (255 << (8 - ($1 % 8))) & 255 )) 0 0 0
16         [ $1 -gt 1 ] && shift $1 || shift
17         echo ${1-0}.${2-0}.${3-0}.${4-0}
18 }
19
20 # OpenStack network configuration
21 if [[ $CLOUD_ENV == "openstack" ]]
22 then
23         echo 127.0.0.1 $(hostname) >> /etc/hosts
24
25         # Allow remote login as root
26         mv /root/.ssh/authorized_keys /root/.ssh/authorized_keys.bk
27         cp /home/ubuntu/.ssh/authorized_keys /root/.ssh
28
29         MTU=$(/sbin/ifconfig | grep MTU | sed 's/.*MTU://' | sed 's/ .*//' | sort -n | head -1)
30
31         IP=$(cat /opt/config/brgemu_bng_net_ipaddr.txt)
32         BITS=$(cat /opt/config/brgemu_bng_net_cidr.txt | cut -d"/" -f2)
33         NETMASK=$(cdr2mask $BITS)
34         echo "auto eth1" >> /etc/network/interfaces
35         echo "iface eth1 inet static" >> /etc/network/interfaces
36         echo "    address $IP" >> /etc/network/interfaces
37         echo "    netmask $NETMASK" >> /etc/network/interfaces
38         echo "    mtu $MTU" >> /etc/network/interfaces
39
40         IP=$(cat /opt/config/oam_ipaddr.txt)
41         BITS=$(cat /opt/config/oam_cidr.txt | cut -d"/" -f2)
42         NETMASK=$(cdr2mask $BITS)
43         echo "auto eth2" >> /etc/network/interfaces
44         echo "iface eth2 inet static" >> /etc/network/interfaces
45         echo "    address $IP" >> /etc/network/interfaces
46         echo "    netmask $NETMASK" >> /etc/network/interfaces
47         echo "    mtu $MTU" >> /etc/network/interfaces
48
49         IP=$(cat /opt/config/cpe_signal_net_ipaddr.txt)
50         BITS=$(cat /opt/config/cpe_signal_net_cidr.txt | cut -d"/" -f2)
51         NETMASK=$(cdr2mask $BITS)
52         echo "auto eth3" >> /etc/network/interfaces
53         echo "iface eth3 inet static" >> /etc/network/interfaces
54         echo "    address $IP" >> /etc/network/interfaces
55         echo "    netmask $NETMASK" >> /etc/network/interfaces
56         echo "    mtu $MTU" >> /etc/network/interfaces
57
58         IP=$(cat /opt/config/bng_gmux_net_ipaddr.txt)
59         BITS=$(cat /opt/config/bng_gmux_net_cidr.txt | cut -d"/" -f2)
60         NETMASK=$(cdr2mask $BITS)
61         echo "auto eth4" >> /etc/network/interfaces
62         echo "iface eth4 inet static" >> /etc/network/interfaces
63         echo "    address $IP" >> /etc/network/interfaces
64         echo "    netmask $NETMASK" >> /etc/network/interfaces
65         echo "    mtu $MTU" >> /etc/network/interfaces
66
67         ifup eth1
68         ifup eth2
69         ifup eth3
70         ifup eth4
71 fi
72
73 # Download required dependencies
74 echo "deb http://ppa.launchpad.net/openjdk-r/ppa/ubuntu $(lsb_release -c -s) main" >>  /etc/apt/sources.list.d/java.list
75 echo "deb-src http://ppa.launchpad.net/openjdk-r/ppa/ubuntu $(lsb_release -c -s) main" >>  /etc/apt/sources.list.d/java.list
76 apt-get update
77 apt-get install --allow-unauthenticated -y wget openjdk-8-jdk apt-transport-https ca-certificates g++ libcurl4-gnutls-dev
78 sleep 1
79
80 # Install the tools required for download codes
81 apt-get install -y expect git patch
82
83 #Download and build the VPP codes
84 cd /opt
85 git clone ${VPP_SOURCE_REPO_URL} -b ${VPP_SOURCE_REPO_BRANCH} vpp
86 wget -O Vpp-Integrate-FreeRADIUS-Client-for-vBNG.patch ${VPP_PATCH_URL}
87
88 cd vpp
89 patch -p1 < Vpp-Integrate-FreeRADIUS-Client-for-vBNG.patch
90 expect -c "
91         set timeout 60;
92         spawn make install-dep;
93         expect {
94                 \"Do you want to continue?*\" {send \"Y\r\"; interact}
95         }
96 "
97
98 cd build-root
99 ./bootstrap.sh
100 make V=0 PLATFORM=vpp TAG=vpp install-deb
101
102 # Install the FreeRADIUS client since we need the lib
103 cd /opt
104 git clone https://github.com/FreeRADIUS/freeradius-client.git
105 cd freeradius-client
106 ./configure
107 make && make install
108 cd /usr/local/lib && ln -s -f libfreeradius-client.so.2.0.0 libfreeradiusclient.so
109 ldconfig
110
111 # Install the VPP package
112 cd /opt/vpp/build-root
113 dpkg -i *.deb
114 systemctl stop vpp
115
116 # Auto-start configuration for the VPP
117 cat > /etc/vpp/startup.conf << EOF
118
119 unix {
120   nodaemon
121   log /tmp/vpp.log
122   full-coredump
123   cli-listen localhost:5002
124   startup-config /etc/vpp/setup.gate
125 }
126
127 api-trace {
128   on
129 }
130
131 api-segment {
132   gid vpp
133 }
134
135 cpu {
136         ## In the VPP there is one main thread and optionally the user can create worker(s)
137         ## The main thread and worker thread(s) can be pinned to CPU core(s) manually or automatically
138
139         ## Manual pinning of thread(s) to CPU core(s)
140
141         ## Set logical CPU core where main thread runs
142         # main-core 1
143
144         ## Set logical CPU core(s) where worker threads are running
145         # corelist-workers 2-3,18-19
146
147         ## Automatic pinning of thread(s) to CPU core(s)
148
149         ## Sets number of CPU core(s) to be skipped (1 ... N-1)
150         ## Skipped CPU core(s) are not used for pinning main thread and working thread(s).
151         ## The main thread is automatically pinned to the first available CPU core and worker(s)
152         ## are pinned to next free CPU core(s) after core assigned to main thread
153         # skip-cores 4
154
155         ## Specify a number of workers to be created
156         ## Workers are pinned to N consecutive CPU cores while skipping "skip-cores" CPU core(s)
157         ## and main thread's CPU core
158         # workers 2
159
160         ## Set scheduling policy and priority of main and worker threads
161
162         ## Scheduling policy options are: other (SCHED_OTHER), batch (SCHED_BATCH)
163         ## idle (SCHED_IDLE), fifo (SCHED_FIFO), rr (SCHED_RR)
164         # scheduler-policy fifo
165
166         ## Scheduling priority is used only for "real-time policies (fifo and rr),
167         ## and has to be in the range of priorities supported for a particular policy
168         # scheduler-priority 50
169 }
170
171 # dpdk {
172         ## Change default settings for all intefaces
173         # dev default {
174                 ## Number of receive queues, enables RSS
175                 ## Default is 1
176                 # num-rx-queues 3
177
178                 ## Number of transmit queues, Default is equal
179                 ## to number of worker threads or 1 if no workers treads
180                 # num-tx-queues 3
181
182                 ## Number of descriptors in transmit and receive rings
183                 ## increasing or reducing number can impact performance
184                 ## Default is 1024 for both rx and tx
185                 # num-rx-desc 512
186                 # num-tx-desc 512
187
188                 ## VLAN strip offload mode for interface
189                 ## Default is off
190                 # vlan-strip-offload on
191         # }
192
193         ## Whitelist specific interface by specifying PCI address
194         # dev 0000:02:00.0
195
196         ## Whitelist specific interface by specifying PCI address and in
197         ## addition specify custom parameters for this interface
198         # dev 0000:02:00.1 {
199         #       num-rx-queues 2
200         # }
201
202         ## Change UIO driver used by VPP, Options are: igb_uio, vfio-pci
203         ## and uio_pci_generic (default)
204         # uio-driver vfio-pci
205
206         ## Disable mutli-segment buffers, improves performance but
207         ## disables Jumbo MTU support
208         # no-multi-seg
209
210         ## Increase number of buffers allocated, needed only in scenarios with
211         ## large number of interfaces and worker threads. Value is per CPU socket.
212         ## Default is 16384
213         # num-mbufs 128000
214
215         ## Change hugepages allocation per-socket, needed only if there is need for
216         ## larger number of mbufs. Default is 256M on each detected CPU socket
217         # socket-mem 2048,2048
218 # }
219
220 EOF
221
222 cat > /etc/vpp/setup.gate << EOF
223 set int state GigabitEthernet0/8/0 up
224 set interface ip address GigabitEthernet0/8/0 10.4.0.4/24
225
226 set int state GigabitEthernet0/9/0 up
227 set interface ip address GigabitEthernet0/9/0 10.4.0.3/24
228
229 set vbng dhcp4 remote 10.4.0.1 local 10.4.0.3
230 set vbng aaa config /etc/vpp/vbng-aaa.cfg nas-port 5060
231 EOF
232
233 cat > /etc/vpp/vbng-aaa.cfg << EOF
234 # General settings
235
236 # specify which authentication comes first respectively which
237 # authentication is used. possible values are: "radius" and "local".
238 # if you specify "radius,local" then the RADIUS server is asked
239 # first then the local one. if only one keyword is specified only
240 # this server is asked.
241 auth_order      radius,local
242
243 # maximum login tries a user has
244 login_tries     2
245
246 # timeout for all login tries
247 # if this time is exceeded the user is kicked out
248 login_timeout   5
249
250 # name of the nologin file which when it exists disables logins.
251 # it may be extended by the ttyname which will result in
252 # a terminal specific lock (e.g. /etc/nologin.ttyS2 will disable
253 # logins on /dev/ttyS2)
254 nologin /etc/nologin
255
256 # name of the issue file. it's only display when no username is passed
257 # on the radlogin command line
258 issue   /usr/local/etc/radiusclient/issue
259
260 # RADIUS settings
261
262 # RADIUS server to use for authentication requests. this config
263 # item can appear more then one time. if multiple servers are
264 # defined they are tried in a round robin fashion if one
265 # server is not answering.
266 # optionally you can specify a the port number on which is remote
267 # RADIUS listens separated by a colon from the hostname. if
268 # no port is specified /etc/services is consulted of the radius
269 # service. if this fails also a compiled in default is used.
270 #authserver     10.4.0.2
271 authserver      localhost
272
273 # RADIUS server to use for accouting requests. All that I
274 # said for authserver applies, too. 
275 #
276 #acctserver     10.4.0.2
277 acctserver      localhost
278
279 # file holding shared secrets used for the communication
280 # between the RADIUS client and server
281 servers         /usr/local/etc/radiusclient/servers
282
283 # dictionary of allowed attributes and values
284 # just like in the normal RADIUS distributions
285 dictionary      /usr/local/etc/radiusclient/dictionary
286
287 # program to call for a RADIUS authenticated login
288 login_radius    /usr/local/sbin/login.radius
289
290 # file which holds sequence number for communication with the
291 # RADIUS server
292 seqfile         /var/run/radius.seq
293
294 # file which specifies mapping between ttyname and NAS-Port attribute
295 mapfile         /usr/local/etc/radiusclient/port-id-map
296
297 # default authentication realm to append to all usernames if no
298 # realm was explicitly specified by the user
299 # the radiusd directly form Livingston doesnt use any realms, so leave
300 # it blank then
301 default_realm
302
303 # time to wait for a reply from the RADIUS server
304 radius_timeout  10
305
306 # resend request this many times before trying the next server
307 radius_retries  3
308
309 # The length of time in seconds that we skip a nonresponsive RADIUS
310 # server for transaction requests.  Server(s) being in the "dead" state
311 # are tried only after all other non-dead servers have been tried and
312 # failed or timeouted.  The deadtime interval starts when the server
313 # does not respond to an authentication/accounting request transmissions. 
314 # When the interval expires, the "dead" server would be re-tried again,
315 # and if it's still down then it will be considered "dead" for another
316 # such interval and so on. This option is no-op if there is only one
317 # server in the list. Set to 0 in order to disable the feature.
318 radius_deadtime 0
319
320 # local address from which radius packets have to be sent
321 bindaddr *
322
323 # LOCAL settings
324
325 # program to execute for local login
326 # it must support the -f flag for preauthenticated login
327 login_local     /bin/login
328 EOF
329
330 cat >> /usr/local/etc/radiusclient/dictionary << EOF
331
332 #
333 #       DHCP Proxy/Relay attributes
334 #
335 ATTRIBUTE       DHCP-Agent-Circuit-Id   82.1    integer
336 ATTRIBUTE       DHCP-Agent-Remote-Id    82.2    string
337 ATTRIBUTE       DHCP-Relay-Circuit-Id   82.1    integer
338 ATTRIBUTE       DHCP-Relay-Remote-Id    82.2    string
339
340 EOF
341
342 cat >> /usr/local/etc/radiusclient/servers << EOF
343 10.4.0.2                                        testing123
344 localhost/localhost                             testing123
345
346 EOF
347
348 # Download DHCP config files
349 cd /opt
350 wget $REPO_URL_BLOB/org.onap.demo/vnfs/vcpe/$INSTALL_SCRIPT_VERSION/v_bng_init.sh
351 wget $REPO_URL_BLOB/org.onap.demo/vnfs/vcpe/$INSTALL_SCRIPT_VERSION/v_bng.sh
352 chmod +x v_bng_init.sh
353 chmod +x v_bng.sh
354 mv v_bng.sh /etc/init.d
355 update-rc.d v_bng.sh defaults
356
357 # Rename network interface in openstack Ubuntu 16.04 images. Then, reboot the VM to pick up changes
358 if [[ $CLOUD_ENV != "rackspace" ]]
359 then
360         sed -i "s/GRUB_CMDLINE_LINUX=.*/GRUB_CMDLINE_LINUX=\"net.ifnames=0 biosdevname=0\"/g" /etc/default/grub
361         grub-mkconfig -o /boot/grub/grub.cfg
362         sed -i "s/ens[0-9]*/eth0/g" /etc/network/interfaces.d/*.cfg
363         sed -i "s/ens[0-9]*/eth0/g" /etc/udev/rules.d/70-persistent-net.rules
364         echo 'network: {config: disabled}' >> /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
365         echo "APT::Periodic::Unattended-Upgrade \"0\";" >> /etc/apt/apt.conf.d/10periodic
366         reboot
367 fi
368
369 ./v_bng_init.sh