[CORD-1305] PPPoE Client

Change-Id: Id5ae5ba0ce0cbb89d434fb34d4c42796c61c059e
diff --git a/extensions/pppoe/scripts/vsg_vcpe_gwbr_setup.sh b/extensions/pppoe/scripts/vsg_vcpe_gwbr_setup.sh
new file mode 100755
index 0000000..693c785
--- /dev/null
+++ b/extensions/pppoe/scripts/vsg_vcpe_gwbr_setup.sh
@@ -0,0 +1,59 @@
+#!/usr/bin/env bash
+#************************************************************/
+#** File:         vsg_vcpe_gwbr_setup.sh                    */
+#** Contents:     Contains shell script to setup vcpe_gwbr  */
+#**               in VSG to allow traffic to flow between   */
+#**               VCPE, VSG and nova-compute nodes.         */ 
+#************************************************************/
+
+date
+echo "vsg_vcpe_gwbr_setup.sh: Begin"
+
+function setup_vcpe_gwbr_in_vsg() {
+  if brctl show $VCPEGW_BR_NAME ; then
+    echo "$VCPEGW_BR_NAME already exists...delete and recreate it again"
+    sudo -E ip link set dev $VCPEGW_BR_NAME down
+    sleep 1
+    sudo -E brctl delbr $VCPEGW_BR_NAME
+  fi
+
+  sleep 1
+  sudo -E brctl addbr $VCPEGW_BR_NAME
+  sleep 1
+  sudo -E ip link set dev $VCPEGW_BR_NAME dynamic off
+  sleep 1
+  sudo -E ip link set dev $VCPEGW_BR_NAME up
+  echo "Setting vcpe_gwbr IP in VSG ($vsg_id) as $vcpe_gwbr_ip"
+  sudo -E ip addr add $vcpe_gwbr_ip/$VCPEGW_NETMASK_BITS dev $VCPEGW_BR_NAME 
+  ifconfig $VCPEGW_BR_NAME
+  sudo -E brctl addif $VCPEGW_BR_NAME $NETCFG_UP_IFACE
+  echo "$VCPEGW_BR_NAME successfully setup.."
+}
+#
+# Setup the NAT rules to allow VCPE GW instances to
+# access the internet. The vcpe docker instances created
+# by XOS go directly through br-wan. So, there is no need
+# to setup any NAT rules. In the case of VCPE GW instance,
+# the traffic will go through vcpe_gwbr and get NAT'd and
+# sent through br-wan. So, we need to setup the NAT rules
+# in VSG to make this work.
+#
+
+function setup_dnat_for_vcpegw_traffic() {
+
+    sudo /sbin/iptables -t nat -A POSTROUTING -s $VCPEGW_BR_SUBNET/$VCPEGW_NETMASK_BITS -o $VSG_WAN_BR_NAME -j MASQUERADE
+    sudo /sbin/iptables -A FORWARD -i $VCPEGW_BR_NAME -o $VSG_WAN_BR_NAME -m state --state RELATED,ESTABLISHED -j ACCEPT
+    sudo /sbin/iptables -A FORWARD -i $VSG_WAN_BR_NAME -o $VCPEGW_BR_NAME -j ACCEPT
+} 
+
+if [ -z $HOME_DIR ]; then
+   HOME_DIR=`pwd`
+   echo "WARNING>>>>HOME_DIR was not setup properly...!!!"
+   echo "Using $HOME_DIR as the home directory"
+fi
+
+setup_vcpe_gwbr_in_vsg
+setup_dnat_for_vcpegw_traffic
+date
+echo "vsg_vcpe_gwbr_setup.sh: End"
+