3 SCRIPT_VERSION=$(cat /opt/config/script_version.txt)
4 CLOUD_ENV=$(cat /opt/config/cloud_env.txt)
7 # Convert Network CIDR to Netmask
9 # Number of args to shift, 255..255, first non-255 byte, zeroes
10 set -- $(( 5 - ($1 / 8) )) 255 255 255 255 $(( (255 << (8 - ($1 % 8))) & 255 )) 0 0 0
11 [ $1 -gt 1 ] && shift $1 || shift
12 echo ${1-0}.${2-0}.${3-0}.${4-0}
15 # OpenStack network configuration
16 if [[ $CLOUD_ENV == "openstack" ]]
18 echo 127.0.0.1 $(hostname) >> /etc/hosts
20 # Allow remote login as root
21 mv /root/.ssh/authorized_keys /root/.ssh/authorized_keys.bk
22 cp /home/ubuntu/.ssh/authorized_keys /root/.ssh
26 # Auto-start configuration for the VPP
27 cat > /etc/vpp/startup.conf << EOF
33 cli-listen localhost:5002
34 startup-config /etc/vpp/setup.gate
46 ## In the VPP there is one main thread and optionally the user can create worker(s)
47 ## The main thread and worker thread(s) can be pinned to CPU core(s) manually or automatically
49 ## Manual pinning of thread(s) to CPU core(s)
51 ## Set logical CPU core where main thread runs
54 ## Set logical CPU core(s) where worker threads are running
55 # corelist-workers 2-3,18-19
57 ## Automatic pinning of thread(s) to CPU core(s)
59 ## Sets number of CPU core(s) to be skipped (1 ... N-1)
60 ## Skipped CPU core(s) are not used for pinning main thread and working thread(s).
61 ## The main thread is automatically pinned to the first available CPU core and worker(s)
62 ## are pinned to next free CPU core(s) after core assigned to main thread
65 ## Specify a number of workers to be created
66 ## Workers are pinned to N consecutive CPU cores while skipping "skip-cores" CPU core(s)
67 ## and main thread's CPU core
70 ## Set scheduling policy and priority of main and worker threads
72 ## Scheduling policy options are: other (SCHED_OTHER), batch (SCHED_BATCH)
73 ## idle (SCHED_IDLE), fifo (SCHED_FIFO), rr (SCHED_RR)
74 # scheduler-policy fifo
76 ## Scheduling priority is used only for "real-time policies (fifo and rr),
77 ## and has to be in the range of priorities supported for a particular policy
78 # scheduler-priority 50
82 ## Change default settings for all intefaces
84 ## Number of receive queues, enables RSS
88 ## Number of transmit queues, Default is equal
89 ## to number of worker threads or 1 if no workers treads
92 ## Number of descriptors in transmit and receive rings
93 ## increasing or reducing number can impact performance
94 ## Default is 1024 for both rx and tx
98 ## VLAN strip offload mode for interface
100 # vlan-strip-offload on
103 ## Whitelist specific interface by specifying PCI address
105 ## Whitelist specific interface by specifying PCI address and in
106 ## addition specify custom parameters for this interface
111 ## Change UIO driver used by VPP, Options are: igb_uio, vfio-pci
112 ## and uio_pci_generic (default)
113 # uio-driver vfio-pci
115 ## Disable mutli-segment buffers, improves performance but
116 ## disables Jumbo MTU support
119 ## Increase number of buffers allocated, needed only in scenarios with
120 ## large number of interfaces and worker threads. Value is per CPU socket.
124 ## Change hugepages allocation per-socket, needed only if there is need for
125 ## larger number of mbufs. Default is 256M on each detected CPU socket
126 # socket-mem 2048,2048
131 #Get list of network device PCI bus addresses
133 while read -r line ; do
134 if [ "$line" != "${line#*network device}" ];
136 echo -n "${line%% *} "
141 NICS=$(get_nic_pci_list)
142 NICS=`echo ${NICS} | sed 's/[0]\+\([0-9]\)/\1/g' | sed 's/[.:]/\//g'`
144 BRG_BNG_NIC=GigabitEthernet`echo ${NICS} | cut -d " " -f 2` # second interface in list
145 echo $BRG_BNG_NIC > /opt/config/brg_nic.txt
148 cat > /etc/vpp/setup.gate << EOF
149 set int state ${BRG_BNG_NIC} up
150 set dhcp client intfc ${BRG_BNG_NIC} hostname brg-emulator
153 echo "sdnc_ip: $(cat /opt/config/sdnc_ip.txt)" > /opt/config/ip.txt
154 echo "hcip: 192.168.4.20" >> /opt/config/ip.txt
157 cat > /opt/bind_nic.sh << 'EOF'
161 if [[ ! $(ps -aux | grep [[:alnum:]]*/vpp/startup.conf | wc -l) = 2 ]];
163 echo "vpp not running"
170 BRG_BNG_NIC=$(cat /opt/config/brg_nic.txt)
171 sdnc_ip=$(cat /opt/config/sdnc_ip.txt)
173 lstack_tap=$(vppctl tap connect lstack)
174 vppctl set int state $lstack_tap up
176 vppctl set interface l2 bridge $lstack_tap 10 0
177 vppctl set bridge-domain arp term 10
179 tap0_tap=$(vppctl tap connect tap0)
181 vppctl set int state $tap0_tap up
182 vppctl set int ip addr $tap0_tap 20.0.0.40/24
183 ifconfig tap0 192.168.4.20/24
184 route add -host $sdnc_ip tap0
185 route add -host 20.0.0.40 tap0
186 vppctl ip route add 192.168.4.0/24 via $tap0_tap
187 vppctl set interface snat in $tap0_tap out ${BRG_BNG_NIC}
188 vppctl snat add interface address ${BRG_BNG_NIC}
190 #Get HW addr of $tap0_tap
193 if [[ "$hw" = $tap0_tap* ]];
199 done < <(vppctl show hardware)
201 arp -s $sdnc_ip $hw_addr
202 arp -s 20.0.0.40 $hw_addr
208 tap0_addr=${var%inet*}
210 vppctl set ip arp $tap0_tap 192.168.4.20 $tap0_addr
213 chmod +x /opt/bind_nic.sh
216 cat > /opt/set_nat.sh << 'EOF'
221 if [[ ! $(ps -aux | grep [[:alnum:]]*/vpp/startup.conf | wc -l) = 2 ]];
223 #echo "vpp not running"
232 re=${line#*/[0-9]/[0-9]}
233 if [ "$line" != "$re" ];
242 if [[ $ip = *\.*\.*\.* ]];
244 #echo "ip address is $ip"
245 if [ ! -f /opt/config/ip.txt ];
247 echo "file /opt/config/ip.txt doesn't exists"
252 if [[ $tap_ip = hcip* ]];
254 tap_ip=${tap_ip#*" "}
255 echo "hc tap ip address is $tap_ip"
256 vppctl snat add static mapping tcp local $tap_ip 8183 external $ip 8183
259 done < /opt/config/ip.txt
261 if [[ ! $ip = */[0-9] ]];
268 done < <(vppctl show int addr)
273 chmod +x /opt/set_nat.sh
275 #Create script to run bind_nic.sh and set_nat.sh
276 cat > /opt/nat_service.sh << 'EOF'
284 chmod +x /opt/nat_service.sh
287 # Create systemctl service for Honeycomb
288 cat > /etc/systemd/system/honeycomb.service << EOF
290 Description=Honeycomb Agent for the VPP control plane
291 Documentation=https://wiki.fd.io/view/Honeycomb
296 ExecStart=/opt/honeycomb/honeycomb
301 WantedBy=multi-user.target
303 systemctl enable /etc/systemd/system/honeycomb.service
306 # Create systemctl service for nat script
307 cat > /etc/systemd/system/nat.service << EOF
309 Description=Runs vbrg scripts for nat configuration
315 ExecStart=/opt/nat_service.sh
319 WantedBy=multi-user.target
321 systemctl enable /etc/systemd/system/nat.service
323 # Download DHCP config files
325 unzip -p -j /opt/vcpe-scripts-$SCRIPT_VERSION.zip v_brgemu_init.sh > /opt/v_brgemu_init.sh
326 unzip -p -j /opt/vcpe-scripts-$SCRIPT_VERSION.zip v_brgemu.sh > /opt/v_brgemu.sh
327 sed -i '/# Provides:/c\# Provides: vbrg ' /opt/v_brgemu.sh
328 chmod +x v_brgemu_init.sh
330 mv v_brgemu.sh /etc/init.d
331 update-rc.d v_brgemu.sh defaults
333 # Rename network interface in openstack Ubuntu 16.04 images. Then, reboot the VM to pick up changes
334 if [[ $CLOUD_ENV != "rackspace" ]]
336 sed -i "s/GRUB_CMDLINE_LINUX=.*/GRUB_CMDLINE_LINUX=\"net.ifnames=0 biosdevname=0\"/g" /etc/default/grub
337 grub-mkconfig -o /boot/grub/grub.cfg
338 sed -i "s/ens[0-9]*/eth0/g" /etc/network/interfaces.d/*.cfg
339 sed -i "s/ens[0-9]*/eth0/g" /etc/udev/rules.d/70-persistent-net.rules
340 echo 'network: {config: disabled}' >> /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
346 # Indicate script has finished executing
347 echo 'Execution of vBRG install script completed' > /opt/script_status.txt