3 SCRIPT_VERSION=$(cat /opt/config/script_version.txt)
4 CLOUD_ENV=$(cat /opt/config/cloud_env.txt)
5 MUX_GW_IP=$(cat /opt/config/mux_gw_net_ipaddr.txt)
6 MUX_GW_CIDR=$(cat /opt/config/mux_gw_net_cidr.txt)
7 MUX_TO_BNG_IP=$(cat /opt/config/mux_to_bng_net_ipaddr.txt)
8 BNG_MUX_CIDR=$(cat /opt/config/bng_mux_net_cidr.txt)
9 BRG_BNG_CIDR=$(cat /opt/config/brg_bng_net_cidr.txt)
10 BNG_TO_MUX_IP=$(cat /opt/config/bng_to_mux_net_ipaddr.txt)
12 # Convert Network CIDR to Netmask
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}
20 # OpenStack network configuration
21 if [[ $CLOUD_ENV == "openstack" ]]
23 echo 127.0.0.1 $(hostname) >> /etc/hosts
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
29 MTU=$(/sbin/ifconfig | grep MTU | sed 's/.*MTU://' | sed 's/ .*//' | sort -n | head -1)
31 IP=$(cat /opt/config/oam_ipaddr.txt)
32 BITS=$(cat /opt/config/oam_cidr.txt | cut -d"/" -f2)
33 NETMASK=$(cdr2mask $BITS)
34 echo "auto eth2" >> /etc/network/interfaces
35 echo "iface eth2 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
43 # Auto-start configuration for the VPP
44 cat > /etc/vpp/startup.conf << EOF
50 cli-listen localhost:5002
51 startup-config /etc/vpp/setup.gate
63 ## In the VPP there is one main thread and optionally the user can create worker(s)
64 ## The main thread and worker thread(s) can be pinned to CPU core(s) manually or automatically
66 ## Manual pinning of thread(s) to CPU core(s)
68 ## Set logical CPU core where main thread runs
71 ## Set logical CPU core(s) where worker threads are running
72 # corelist-workers 2-3,18-19
74 ## Automatic pinning of thread(s) to CPU core(s)
76 ## Sets number of CPU core(s) to be skipped (1 ... N-1)
77 ## Skipped CPU core(s) are not used for pinning main thread and working thread(s).
78 ## The main thread is automatically pinned to the first available CPU core and worker(s)
79 ## are pinned to next free CPU core(s) after core assigned to main thread
82 ## Specify a number of workers to be created
83 ## Workers are pinned to N consecutive CPU cores while skipping "skip-cores" CPU core(s)
84 ## and main thread's CPU core
87 ## Set scheduling policy and priority of main and worker threads
89 ## Scheduling policy options are: other (SCHED_OTHER), batch (SCHED_BATCH)
90 ## idle (SCHED_IDLE), fifo (SCHED_FIFO), rr (SCHED_RR)
91 # scheduler-policy fifo
93 ## Scheduling priority is used only for "real-time policies (fifo and rr),
94 ## and has to be in the range of priorities supported for a particular policy
95 # scheduler-priority 50
99 ## Change default settings for all intefaces
101 ## Number of receive queues, enables RSS
105 ## Number of transmit queues, Default is equal
106 ## to number of worker threads or 1 if no workers treads
109 ## Number of descriptors in transmit and receive rings
110 ## increasing or reducing number can impact performance
111 ## Default is 1024 for both rx and tx
115 ## VLAN strip offload mode for interface
117 # vlan-strip-offload on
120 ## Whitelist specific interface by specifying PCI address
123 ## Whitelist specific interface by specifying PCI address and in
124 ## addition specify custom parameters for this interface
129 ## Change UIO driver used by VPP, Options are: igb_uio, vfio-pci
130 ## and uio_pci_generic (default)
131 # uio-driver vfio-pci
133 ## Disable mutli-segment buffers, improves performance but
134 ## disables Jumbo MTU support
137 ## Increase number of buffers allocated, needed only in scenarios with
138 ## large number of interfaces and worker threads. Value is per CPU socket.
142 ## Change hugepages allocation per-socket, needed only if there is need for
143 ## larger number of mbufs. Default is 256M on each detected CPU socket
144 # socket-mem 2048,2048
149 # Get list of network device PCI bus addresses
151 while read -r line ; do
152 if [ "$line" != "${line#*network device}" ]; then
153 echo -n "${line%% *} "
158 NICS=$(get_nic_pci_list)
159 NICS=`echo ${NICS} | sed 's/[0]\+\([0-9]\)/\1/g' | sed 's/[.:]/\//g'`
161 BNG_MUX_NIC=GigabitEthernet`echo ${NICS} | cut -d " " -f 2` # second interface in list
162 MUX_GW_NIC=GigabitEthernet`echo ${NICS} | cut -d " " -f 4` # fourth interface in list
164 cat > /etc/vpp/setup.gate << EOF
165 set int state ${BNG_MUX_NIC} up
166 set int ip address ${BNG_MUX_NIC} ${MUX_TO_BNG_IP}/${BNG_MUX_CIDR#*/}
168 set int state ${MUX_GW_NIC} up
169 set int ip address ${MUX_GW_NIC} ${MUX_GW_IP}/${MUX_GW_CIDR#*/}
170 ip route add ${BRG_BNG_CIDR} via ${BNG_TO_MUX_IP} ${BNG_MUX_NIC}
174 # Create systemctl service for Honeycomb
175 cat > /etc/systemd/system/honeycomb.service << EOF
177 Description=Honeycomb Agent for the VPP control plane
178 Documentation=https://wiki.fd.io/view/Honeycomb
183 ExecStart=/opt/honeycomb/honeycomb
184 ExecStop=/opt/reset_ves_mode.sh
189 WantedBy=multi-user.target
191 systemctl enable /etc/systemd/system/honeycomb.service
193 # Create script that is used to reset the ves mode configuration
194 # when the honeycomb service is stopped
195 cat > /opt/reset_ves_mode.sh << EOF
197 mode_data=\$(curl -X GET -u admin:admin http://127.0.0.1:8183/restconf/config/vesagent:vesagent/mode 2>/dev/null | sed s/\"base-packet-loss\":[0-9]\*,/\"base-packet-loss\":0,/)
198 if [[ "\${mode_data}" != "" ]]
200 curl -X DELETE -u admin:admin http://127.0.0.1:8183/restconf/config/vesagent:vesagent/mode
201 curl -H "Content-Type:application/json" --data "\${mode_data}" -X POST -u admin:admin http://127.0.0.1:8183/restconf/config/vesagent:vesagent
204 chmod a+x /opt/reset_ves_mode.sh
206 #Create a systemd service for auto-save
207 cat > /usr/bin/save_config << EOF
210 #########################################################################
212 # Copyright (c) 2017 Intel and/or its affiliates.
214 # Licensed under the Apache License, Version 2.0 (the "License");
215 # you may not use this file except in compliance with the License.
216 # You may obtain a copy of the License at:
218 # http://www.apache.org/licenses/LICENSE-2.0
220 # Unless required by applicable law or agreed to in writing, software
221 # distributed under the License is distributed on an "AS IS" BASIS,
222 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
223 # See the License for the specific language governing permissions and
224 # limitations under the License.
226 ##########################################################################
228 ############################### Variables ################################
229 VPP_SETUP_GATE=/etc/vpp/setup.gate
231 ############################### Functions ################################
233 # Write the commands to the startup scripts.
235 # We could set VPP configuration to the startup.conf.
236 # Write the configuration to the startup scripts so we could
237 # restore the system after rebooting.
239 write_startup_scripts()
244 if [[ \${is_add} == add ]] ;then
247 if [[ \${line} == \${cmd} ]] ;then
250 done < \${VPP_SETUP_GATE}
252 echo "\${cmd}" >> \${VPP_SETUP_GATE}
256 if [[ \${line} == \${cmd} ]] ;then
257 sed -i "/\${line}/d" \${VPP_SETUP_GATE}
260 done < \${VPP_SETUP_GATE}
264 # Save the VxLAN Tunnel Configuration to the startup script.
266 # Get the current VxLAN tunnel configuration with bash command:
267 # \$vppctl show vxlan tunnel
268 # [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
269 # [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
270 # Set the VxLAN Tunnel with the bash command:
271 # \$vppctl create vxlan tunnel src 10.3.0.2 dst 10.1.0.20 vni 100
279 vppctl show vxlan tunnel | while read line
281 if [ "\${line}" != "" ] ;then
282 src=\`echo \${line} | awk '{ print \$3 }'\`
283 dst=\`echo \${line} | awk '{ print \$5 }'\`
284 vni=\`echo \${line} | awk '{ print \$7 }'\`
286 write_startup_scripts add "create vxlan tunnel src \${src} dst \${dst} vni \${vni}"
291 # Save the VxLAN tunnel L2 xconnect configuration to the startup script.
293 # Get the Current L2 Address configuration with bash command:
294 # \$vppctl show int addr
296 # vxlan_tunnel0 (up):
297 # l2 xconnect vxlan_tunnel1
298 # vxlan_tunnel1 (up):
299 # l2 xconnect vxlan_tunnel0
300 # Save the VxLAN tunnel L2 xconnect configuration with bash command:
301 # \$vppctl set interface l2 xconnect vxlan_tunnel0 vxlan_tunnel1
303 save_vxlan_xconnect()
308 vppctl show int addr | while read line
310 if [[ \${line} == vxlan_tunnel* ]] ;then
312 while [[ \${next} != l2* ]] || [[ \${next} == "" ]]
314 line=\`echo \${next}\`
317 if [[ \${next} == l2* ]] ;then
318 ingress=\`echo \${line} | awk '{ print \$1 }'\`
319 egress=\`echo \${next} | awk '{ print \$3 }'\`
320 write_startup_scripts add "set interface l2 xconnect \${ingress} \${egress}"
326 ################################# MAIN ###################################
333 chmod a+x /usr/bin/save_config
334 cat > /etc/systemd/system/autosave.service << EOF
336 Description=Run Scripts at Start and Stop
343 ExecStop=/usr/bin/save_config
346 WantedBy=multi-user.target
348 systemctl enable /etc/systemd/system/autosave.service
350 # Download DHCP config files
352 unzip -p -j /opt/vcpe-scripts-$SCRIPT_VERSION.zip v_gmux_init.sh > /opt/v_gmux_init.sh
353 unzip -p -j /opt/vcpe-scripts-$SCRIPT_VERSION.zip v_gmux.sh > /opt/v_gmux.sh
354 chmod +x v_gmux_init.sh
356 mv v_gmux.sh /etc/init.d
357 update-rc.d v_gmux.sh defaults
359 # Rename network interface in openstack Ubuntu 16.04 images. Then, reboot the VM to pick up changes
360 if [[ $CLOUD_ENV != "rackspace" ]]
362 sed -i "s/GRUB_CMDLINE_LINUX=.*/GRUB_CMDLINE_LINUX=\"net.ifnames=0 biosdevname=0\"/g" /etc/default/grub
363 grub-mkconfig -o /boot/grub/grub.cfg
364 sed -i "s/ens[0-9]*/eth0/g" /etc/network/interfaces.d/*.cfg
365 sed -i "s/ens[0-9]*/eth0/g" /etc/udev/rules.d/70-persistent-net.rules
366 echo 'network: {config: disabled}' >> /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
367 echo 'Execution of vG-MUX install script completed' > /opt/script_status.txt
372 echo 'Execution of vG-MUX install script completed' > /opt/script_status.txt