VOL-3403: OLT goes into reboot in in-band mode even when in-band interface has valid IP
- Bug fix in watchdog script
- Logging enhancements in watchdog script
- copy watchdog script config file into debian package

Change-Id: Ic7dbfc614120fe49301980cea51044637772e966
diff --git a/agent/device/asfvolt16/mkdebian/debian/asfvolt16.postinst b/agent/device/asfvolt16/mkdebian/debian/asfvolt16.postinst
index 87a0d19..50e8d89 100644
--- a/agent/device/asfvolt16/mkdebian/debian/asfvolt16.postinst
+++ b/agent/device/asfvolt16/mkdebian/debian/asfvolt16.postinst
@@ -20,7 +20,7 @@
 tar zxf /tmp/release_asfvolt16_V3.4.3.3.202002100101.tar.gz -C / 2>&1 > /dev/null
 grep -q '\/opt\/bcm68620\/svk_init.sh' /etc/rc.local || sed -i -e '$i \/opt\/bcm68620\/svk_init.sh' /etc/rc.local
 rm -f /run/bcm68620
-mkdir -p /opt/openolt && cp /tmp/watchdog/openolt_dev_mgmt_daemon_process_watchdog /opt/openolt
+mkdir -p /opt/openolt && cp /tmp/watchdog/openolt_dev_mgmt_daemon_process_watchdog /opt/openolt && cp /tmp/watchdog/watchdog.config /opt/openolt
 [ -f /opt/openolt/openolt_dev_mgmt_daemon_process_watchdog ] && grep -q '\/opt\/openolt\/openolt_dev_mgmt_daemon_process_watchdog' /etc/rc.local || sed -i -e '$i nohup bash \/opt\/openolt\/openolt_dev_mgmt_daemon_process_watchdog &' /etc/rc.local
 cp /tmp/init.d/dev_mgmt_daemon /etc/init.d
 cp /tmp/init.d/openolt /etc/init.d
diff --git a/agent/device/asgvolt64/mkdebian/debian/asgvolt64.postinst b/agent/device/asgvolt64/mkdebian/debian/asgvolt64.postinst
index 72b4b19..6ce8b44 100644
--- a/agent/device/asgvolt64/mkdebian/debian/asgvolt64.postinst
+++ b/agent/device/asgvolt64/mkdebian/debian/asgvolt64.postinst
@@ -20,7 +20,7 @@
 tar zxf /tmp/release_asgvolt64_V3.4.3.3.202002100101.tar.gz -C / 2>&1 > /dev/null
 grep -q '\/opt\/bcm68620\/svk_init.sh' /etc/rc.local || sed -i -e '$i \/opt\/bcm68620\/svk_init.sh' /etc/rc.local
 rm -f /run/bcm68620
-mkdir -p /opt/openolt && cp /tmp/watchdog/openolt_dev_mgmt_daemon_process_watchdog /opt/openolt
+mkdir -p /opt/openolt && cp /tmp/watchdog/openolt_dev_mgmt_daemon_process_watchdog /opt/openolt && cp /tmp/watchdog/watchdog.config /opt/openolt
 [ -f /opt/openolt/openolt_dev_mgmt_daemon_process_watchdog ] && grep -q '\/opt\/openolt\/openolt_dev_mgmt_daemon_process_watchdog' /etc/rc.local || sed -i -e '$i nohup bash \/opt\/openolt\/openolt_dev_mgmt_daemon_process_watchdog &' /etc/rc.local
 cp /tmp/init.d/dev_mgmt_daemon /etc/init.d
 cp /tmp/init.d/openolt /etc/init.d
diff --git a/agent/inband/config/inband.config b/agent/inband/config/inband.config
index eb737a4..6dddb0b 100644
--- a/agent/inband/config/inband.config
+++ b/agent/inband/config/inband.config
@@ -16,3 +16,6 @@
 
 # enable out of band connection to OLT?
 enable_out_of_band_connection=no
+
+# wait time before configuring in-band on BAL
+wait_time_bal_ready=45
diff --git a/agent/inband/scripts/start_inband_oltservices.sh b/agent/inband/scripts/start_inband_oltservices.sh
index 016c1b7..cf59334 100644
--- a/agent/inband/scripts/start_inband_oltservices.sh
+++ b/agent/inband/scripts/start_inband_oltservices.sh
@@ -78,7 +78,7 @@
 OPENOLT_ARG_INPUT_FILE=/etc/default/openolt
 
 # Wait time for BAL to get ready
-WAIT_TIME_BAL_READY=80
+WAIT_TIME_BAL_READY=$(awk '/wait_time_bal_ready/{print $0}' ${INBAND_CONFIG_FILE} | awk -F "=" '{print $2}')
 
 #------------------------------------------------------------------------------
 # Function Name: does_logger_exist
@@ -532,7 +532,7 @@
                     else
                         info_message "Inband interface ${interface} is not up, continuously retrying for DHCP IP assignment"
                         info_message "Inband interface ${interface} is not up with valid IP hence not starting openolt service"
-                        sleep 10
+                        sleep 5
                         continue
                     fi
                 fi
diff --git a/agent/scripts/watchdog/openolt_dev_mgmt_daemon_process_watchdog b/agent/scripts/watchdog/openolt_dev_mgmt_daemon_process_watchdog
index 54d1f82..45d9374 100755
--- a/agent/scripts/watchdog/openolt_dev_mgmt_daemon_process_watchdog
+++ b/agent/scripts/watchdog/openolt_dev_mgmt_daemon_process_watchdog
@@ -27,6 +27,8 @@
 
 WATCHDOG_LOG_FILE="/var/log/openolt_process_watchdog.log"
 
+BRCM_DIR="/broadcom"
+
 # inband config file
 INBAND_CONFIG_FILE="${BRCM_DIR}/inband.config"
 
@@ -84,7 +86,7 @@
             ASGVOLT64_VLAN_ID_ETH1=$(awk '/asgvolt64_vlan_id_eth1/{print $0}' ${INBAND_CONFIG_FILE} | awk -F "=" '{print $2}')
         fi
 
-        if [ -z ${ASFVOLT16_VLAN_ID_ETH2} ] || [ -z ${ASGVOLT64_VLAN_ID_ETH1} ]; then
+        if [ -z ${ASFVOLT16_VLAN_ID_ETH2} ] && [ -z ${ASGVOLT64_VLAN_ID_ETH1} ]; then
             LOG "ERROR: vlan ids not valid"
             exit 1
         fi
@@ -111,11 +113,17 @@
 monitor_openolt_and_dev_mgmt_daemon_process() {
     LOG "start monitor openolt and dev_mgmt_daemon processes"
 
+    if [ "${OLT_MODEL}" = ${ASF16_MODEL} ]; then
+        INBAND_IF="eth2.${ASFVOLT16_VLAN_ID_ETH2}"
+    else
+        INBAND_IF="eth1.${ASGVOLT64_VLAN_ID_ETH1}"
+    fi
+
     # This is builtin bash variable that tracks the number of seconds
     # elapsed since the shell started. We can reset to 0 and the timer
     # starts from here
     SECONDS=0
-
+    get_vlan_ids
     while true; do
 
         DEV_MGMT_DAEMON_PID=`pidof /broadcom/dev_mgmt_daemon`
@@ -138,15 +146,11 @@
         sleep ${PID_MONITOR_INTERVAL}
 
         if [ $(is_olt_in_inband_mode; echo $?) -eq 1 ]; then
-            if [ "${OLT_MODEL}" = ${ASF16_MODEL} ]; then
-                INBAND_IF_IP_ADDR=`ip -o -4 addr list eth2.${ASFVOLT16_VLAN_ID_ETH2} | awk '{print $4}' | cut -d/ -f1`
-            else
-                INBAND_IF_IP_ADDR=`ip -o -4 addr list eth1.${ASGVOLT64_VLAN_ID_ETH1} | awk '{print $4}' | cut -d/ -f1`
-            fi
+            INBAND_IF_IP_ADDR=`ip -o -4 addr list ${INBAND_IF} | awk '{print $4}' | cut -d/ -f1`
 
             if [ -z ${INBAND_IF_IP_ADDR} ] && [ ${SECONDS} -gt 60 ]; then
                 # If the in-band interface does not have an IP for more than 60s, reboot the OLT
-                LOG "in-band interface does not have IP for more than 60s, rebooting OLT"
+                LOG "in-band interface ${INBAND_IF} does not have IP for more than 60s, rebooting OLT"
                 reboot -n
                 exit 1
             elif [ ${#INBAND_IF_IP_ADDR} -gt 0 ]; then