AyumuUeha | 76a01bc | 2017-05-18 13:34:13 +0900 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | #************************************************************/ |
| 3 | #** File: vsg_vcpe_gwbr_setup.sh */ |
| 4 | #** Contents: Contains shell script to setup vcpe_gwbr */ |
| 5 | #** in VSG to allow traffic to flow between */ |
| 6 | #** VCPE, VSG and nova-compute nodes. */ |
| 7 | #************************************************************/ |
| 8 | |
| 9 | date |
| 10 | echo "vsg_vcpe_gwbr_setup.sh: Begin" |
| 11 | |
| 12 | function setup_vcpe_gwbr_in_vsg() { |
| 13 | if brctl show $VCPEGW_BR_NAME ; then |
| 14 | echo "$VCPEGW_BR_NAME already exists...delete and recreate it again" |
| 15 | sudo -E ip link set dev $VCPEGW_BR_NAME down |
| 16 | sleep 1 |
| 17 | sudo -E brctl delbr $VCPEGW_BR_NAME |
| 18 | fi |
| 19 | |
| 20 | sleep 1 |
| 21 | sudo -E brctl addbr $VCPEGW_BR_NAME |
| 22 | sleep 1 |
| 23 | sudo -E ip link set dev $VCPEGW_BR_NAME dynamic off |
| 24 | sleep 1 |
| 25 | sudo -E ip link set dev $VCPEGW_BR_NAME up |
| 26 | echo "Setting vcpe_gwbr IP in VSG ($vsg_id) as $vcpe_gwbr_ip" |
| 27 | sudo -E ip addr add $vcpe_gwbr_ip/$VCPEGW_NETMASK_BITS dev $VCPEGW_BR_NAME |
| 28 | ifconfig $VCPEGW_BR_NAME |
| 29 | sudo -E brctl addif $VCPEGW_BR_NAME $NETCFG_UP_IFACE |
| 30 | echo "$VCPEGW_BR_NAME successfully setup.." |
| 31 | } |
| 32 | # |
| 33 | # Setup the NAT rules to allow VCPE GW instances to |
| 34 | # access the internet. The vcpe docker instances created |
| 35 | # by XOS go directly through br-wan. So, there is no need |
| 36 | # to setup any NAT rules. In the case of VCPE GW instance, |
| 37 | # the traffic will go through vcpe_gwbr and get NAT'd and |
| 38 | # sent through br-wan. So, we need to setup the NAT rules |
| 39 | # in VSG to make this work. |
| 40 | # |
| 41 | |
| 42 | function setup_dnat_for_vcpegw_traffic() { |
| 43 | |
| 44 | sudo /sbin/iptables -t nat -A POSTROUTING -s $VCPEGW_BR_SUBNET/$VCPEGW_NETMASK_BITS -o $VSG_WAN_BR_NAME -j MASQUERADE |
| 45 | sudo /sbin/iptables -A FORWARD -i $VCPEGW_BR_NAME -o $VSG_WAN_BR_NAME -m state --state RELATED,ESTABLISHED -j ACCEPT |
| 46 | sudo /sbin/iptables -A FORWARD -i $VSG_WAN_BR_NAME -o $VCPEGW_BR_NAME -j ACCEPT |
| 47 | } |
| 48 | |
| 49 | if [ -z $HOME_DIR ]; then |
| 50 | HOME_DIR=`pwd` |
| 51 | echo "WARNING>>>>HOME_DIR was not setup properly...!!!" |
| 52 | echo "Using $HOME_DIR as the home directory" |
| 53 | fi |
| 54 | |
| 55 | setup_vcpe_gwbr_in_vsg |
| 56 | setup_dnat_for_vcpegw_traffic |
| 57 | date |
| 58 | echo "vsg_vcpe_gwbr_setup.sh: End" |
| 59 | |