blob: 17ac2c1e51e756e1a3838d91c4e53692a0d22594 [file] [log] [blame]
Matteo Scandoloaca86652017-08-08 13:05:27 -07001
2# Copyright 2017-present Open Networking Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16
AyumuUeha76a01bc2017-05-18 13:34:13 +090017#!/usr/bin/env bash
18#************************************************************/
19#** File: vsg_vcpe_proxy_setup.sh */
20#** Contents: Contains shell script to setup packages & */
21#** applications inside the VCPE. */
22#************************************************************/
23
24time_begin=`date`
25echo $time_begin
26echo "vsg_vcpe_proxy_setup.sh: Begin"
27
28function extract_stag_ctag() {
29 echo "Entering extract_stag_ctag function.."
30 VCPE_NAME=$VCPEPROXY_NAME
31 echo "Input String $VCPE_NAME"
32 vcpe_substrings=$( echo $VCPE_NAME | tr "-" "\n" )
33 i=0
34 for str in $vcpe_substrings
35 do
36 echo "i=$i str=$str"
37 if [ $i -eq 1 ]; then
38 stag=$str
39 fi
40 if [ $i -eq 2 ]; then
41 ctag=$str
42 fi
43 i=$(( i + 1 ))
44 done
45
46 echo "Parsed String output: stag=$stag ctag=$ctag "
47 STAG=$stag; export STAG
48 CTAG=$ctag; export CTAG
49}
50
51function install_restserver() {
52 echo "install_rest(): Installing REST artifacts in docker instance: $VCPEPROXY_NAME"
53 time sudo docker exec -t $VCPEPROXY_NAME apt-get update
54 echo "Installing npm.."
55 time sudo docker exec -t $VCPEPROXY_NAME apt-get install npm -y
56 echo "Installing json-server.."
57 time sudo docker exec -t $VCPEPROXY_NAME npm install -g json-server@0.9.6
58 echo "Installing line-reader.."
59 time sudo docker exec -t $VCPEPROXY_NAME npm install -g line-reader
60 echo "Installing bluebird.."
61 time sudo docker exec -t $VCPEPROXY_NAME npm install -g bluebird
62#PPPoE http server
63 echo "Installing express.."
64 time sudo docker exec -t $VCPEPROXY_NAME npm install -g express
65 echo "Installing body-parser.."
66 time sudo docker exec -t $VCPEPROXY_NAME npm install -g body-parser
67#PPPoE http server end
68}
69
70function install_pppoe_soft() {
71 echo "install_pppoe_soft(): Installing PPPoE software in $VCPEPROXY_NAME"
72 time sudo docker exec -t $VCPEPROXY_NAME apt-get update
73 echo "Installing ppp.."
74 time sudo docker exec -t $VCPEPROXY_NAME apt-get install ppp -y
75 echo "Installing pppoe.."
76 time sudo docker exec -t $VCPEPROXY_NAME apt-get install pppoe -y
77}
78
79function install_ipv6_soft() {
80 echo "install_pppoe_soft(): Installing IPv6 software in $VCPEPROXY_NAME"
81 time sudo docker exec -t $VCPEPROXY_NAME apt-get update
82 echo "Installing DHCPv6.."
83 time sudo docker exec -t $VCPEPROXY_NAME apt-get install radvd -y
84}
85
86function install_network_soft() {
87 echo "install_soft(): Installing required software in $VCPEPROXY_NAME"
88 time sudo docker exec -t $VCPEPROXY_NAME apt-get update
89 echo "Installing iptables.."
90 time sudo docker exec -t $VCPEPROXY_NAME apt-get install iptables -y
91 echo "Installing tcpdump..."
92 time sudo docker exec -t $VCPEPROXY_NAME apt-get install tcpdump -y
93 echo "installing Node Js.."
94 time sudo docker exec -t $VCPEPROXY_NAME apt-get install nodejs -y
95 echo "installing...sshpass.."
96 time sudo docker exec -t $VCPEPROXY_NAME apt-get install sshpass -y
97}
98
99function get_vcpeproxy_wan_ip() {
100 echo "Entering get_vcpeproxy_wan_ip function.."
101 addr=`sudo docker exec -t $VCPEPROXY_NAME ifconfig $VCPEPROXY_WAN_IFACE|grep "inet addr"| awk '{ print $2 }'`
102
103 addr=`echo $addr|tr ":" "\n"`
104 i=1
105 for str in $addr
106 do
107 echo "i=$i str=$str"
108 if [ $i -eq 2 ]; then
109 VCPEPROXY_WAN_IP=$str; export VCPEPROXY_WAN_IP
110 fi
111 i=$(( i + 1 ))
112 done
113 echo "Returning $VCPEPROXY_WAN_IP"
114}
115
116function install_and_spinup_apmgmt() {
117 if [ -z $VCPEPROXY_DOCKER_HOME ]; then
118 echo "cleaning up $VCPEPROXY_DOCKER_HOME directory"
119 sudo -E docker exec -t $VCPEPROXY_NAME rm -rf $VCPEPROXY_DOCKER_HOME
120 fi
121 sudo -E docker exec -t $VCPEPROXY_NAME mkdir -p $VCPEPROXY_DOCKER_HOME
122 sudo docker cp $vsg_home_dir/$vsg_env_file $VCPEPROXY_NAME:$VCPEPROXY_DOCKER_HOME
123 echo "VCPEPROXY_WAN_IP=$VCPEPROXY_WAN_IP"
124
125 # VLAN information
126 echo "{\"s-vlan\":\"$STAG\",\"c-vlan\":\"$CTAG\"}" > $vsg_home_dir/$PPPOE_AP_MGMT_DIR/info.txt
127 # Information on device for ONOS network configuration
128 echo "curl -X POST http://$NETCFG_CONSOLIDATOR_IP:$NETCFG_RESTAPI_PORT/rest:$VCPEPROXY_WAN_IP:$AP_RESTAPI_PORT" > $vsg_home_dir/$PPPOE_AP_MGMT_DIR/$AP_REST_NETCFG
129 chmod +x $vsg_home_dir/$PPPOE_AP_MGMT_DIR/$AP_REST_NETCFG
130
131 echo "Archiving it to $APMGMT_TAR_FILE"
132 cd $vsg_home_dir/$PPPOE_AP_MGMT_DIR; tar -cvf - . >$APMGMT_TAR_FILE
133 sudo docker cp $APMGMT_TAR_FILE $VCPEPROXY_NAME:$NODEJS_MODULES_DIR
134 echo "Archiving it to $IPV6_TAR_FILE"
135 cd $vsg_home_dir/$IPV6_AP_DIR; tar -cvf - . >$IPV6_TAR_FILE
136 sudo docker cp $IPV6_TAR_FILE $VCPEPROXY_NAME:$VCPEPROXY_DOCKER_HOME
137 sudo docker cp $vsg_home_dir/$proxy_ap_mgmt_start_script $VCPEPROXY_NAME:$VCPEPROXY_DOCKER_HOME
138 sudo docker cp $vsg_home_dir/$proxy_ap_mgmt_stop_script $VCPEPROXY_NAME:$VCPEPROXY_DOCKER_HOME
139 sudo docker cp $vsg_home_dir/$proxy_ipv6_setup $VCPEPROXY_NAME:$VCPEPROXY_DOCKER_HOME
140 sudo docker exec $VCPEPROXY_NAME chmod +x $VCPEPROXY_DOCKER_HOME/$proxy_ap_mgmt_start_script
141 sudo docker exec $VCPEPROXY_NAME chmod +x $VCPEPROXY_DOCKER_HOME/$proxy_ap_mgmt_stop_script
142 sudo docker exec $VCPEPROXY_NAME chmod +x $VCPEPROXY_DOCKER_HOME/$proxy_ipv6_setup
143 if [[ "x$VSG_DOCKER_IPV4" != "xipv4" ]]; then
144 echo "Setup and start IPv6 apps"
145 sudo docker exec $VCPEPROXY_NAME $VCPEPROXY_DOCKER_HOME/$proxy_ipv6_setup
146 fi
147
148 echo "mv json-server:/usr/local/lib/node_modules/json-server/lib/server/public"
149 sudo docker exec $VCPEPROXY_NAME mv /usr/local/lib/node_modules/json-server/lib/server/public/index.html /usr/local/lib/node_modules/json-server/lib/server/public/index.html_sav
150
151 echo "Starting proxy_ap_mgmt_start_script"
152 sudo docker exec $VCPEPROXY_NAME $VCPEPROXY_DOCKER_HOME/$proxy_ap_mgmt_start_script $VSG_DOCKER_IPV4
153 echo "Started proxy_ap_mgmt_start_script"
154 echo "check whether nodejs is running"
155 sudo docker exec $VCPEPROXY_NAME ps -fade|grep nodejs
156}
157
158function send_device_info_to_consolidator () {
159 sudo docker exec $VCPEPROXY_NAME ps -fade|grep nodejs|grep cController > /dev/null 2>&1
160 if [ "$?" == 0 ]; then
161 echo "Posting rest:$VCPEPROXY_WAN_IP:$AP_RESTAPI_PORT to consolidator..."
162 sudo docker exec $VCPEPROXY_NAME bash $NODEJS_MODULES_DIR$AP_REST_NETCFG
163 fi
164}
165
166VCPEPROXY_NAME=$1; export VCPEPROXY_NAME
167VSG_ID=$2; export VSG_ID
168VCPE_PROXY_ID=$3; export VCPE_PROXY_ID
169
170if [ -z $VCPEPROXY_NAME ]; then
171 echo " Missing Argument: VCPEPROXY_NAME...."
172 exit 1
173fi
174if [ -z $VSG_ID ]; then
175 echo " Missing Argument: VSG_ID...."
176 exit 1
177fi
178if [ -z $VCPE_PROXY_ID ]; then
179 echo " Missing Argument: VCPE_PROXY_ID...."
180 exit 1
181fi
182echo "Reinitializing $VCPEPROXY_NAME docker as vcpe proxy"
183extract_stag_ctag
184sudo -E $vsg_home_dir/$respin_vcpeproxy_docker_script
185
186# Check whethere necessary packages are installed in VCPE
187sudo docker exec $VCPEPROXY_NAME which nodejs > /dev/null 2>&1
188if [ "$?" == 1 ]; then
189 # VCPE docker image may be from repository, then install necessary packages
190 echo "Continuing the installation of vcpe_proxy docker"
191 install_network_soft
192 echo "Installing rest servcer"
193 install_restserver
194 echo "Installing pppoe soft"
195 install_pppoe_soft
196 echo "Installing ipv6 soft"
197 install_ipv6_soft
198fi
199echo "Extracting vcpeproxy_wan_ip"
200get_vcpeproxy_wan_ip
201echo "Before AP mgmt spinup...VCEPROXY_WAN_IP=$VCPEPROXY_WAN_IP"
202install_and_spinup_apmgmt
203echo "Before sending device info to consolidator..."
204send_device_info_to_consolidator
205
206# To indicate VCPE setup completion
207time_end=`date`
208echo "Begin $time_begin" > $vsg_home_dir/$VCPEPROXY_NAME
209echo $VCPEPROXY_NAME >> $vsg_home_dir/$VCPEPROXY_NAME
210echo "End $time_end" >> $vsg_home_dir/$VCPEPROXY_NAME
211echo $time_end
212echo "vsg_vcpe_proxy_setup.sh: End"