ONOS-4086 to ONOS-4091, ONOS-4098 to ONOS-4100:JUNIT for ISIS controller

Change-Id: If3501a55fcbf994cd69facfd97f43b4a4f0f7812
diff --git a/protocols/isis/ctl/src/main/java/org/onosproject/isis/controller/impl/DefaultIsisNeighbor.java b/protocols/isis/ctl/src/main/java/org/onosproject/isis/controller/impl/DefaultIsisNeighbor.java
index 3180c5d..7fac0cb 100755
--- a/protocols/isis/ctl/src/main/java/org/onosproject/isis/controller/impl/DefaultIsisNeighbor.java
+++ b/protocols/isis/ctl/src/main/java/org/onosproject/isis/controller/impl/DefaultIsisNeighbor.java
@@ -45,7 +45,8 @@
     private String neighborSystemId;
     private Ip4Address interfaceIp;
     private MacAddress neighborMacAddress;
-    private int holdingTime;
+    private volatile int holdingTime;
+    private int neighborDownInterval;
     private IsisRouterType routerType;
     private String l1LanId;
     private String l2LanId;
@@ -54,6 +55,8 @@
     private IsisInterfaceState neighborState = IsisInterfaceState.INITIAL;
     private InternalInactivityTimeCheck inActivityTimeCheckTask;
     private ScheduledExecutorService exServiceInActivity;
+    private InternalHoldingTimeCheck holdingTimeCheckTask;
+    private ScheduledExecutorService exServiceHoldingTimeCheck;
     private boolean inActivityTimerScheduled = false;
     private IsisInterface isisInterface;
 
@@ -72,6 +75,7 @@
         this.interfaceIp = (helloMessage.interfaceIpAddresses() != null) ?
                 interfaceIpAddresses.get(0) : IsisConstants.DEFAULTIP;
         this.holdingTime = helloMessage.holdingTime();
+        neighborDownInterval = holdingTime;
         this.routerType = IsisRouterType.get(helloMessage.circuitType());
         if (helloMessage instanceof L1L2HelloPdu) {
             if (IsisPduType.L1HELLOPDU == helloMessage.isisPduType()) {
@@ -83,6 +87,7 @@
             this.localCircuitId = ((P2PHelloPdu) helloMessage).localCircuitId();
         }
         this.isisInterface = isisInterface;
+        startHoldingTimeCheck();
     }
 
     /**
@@ -244,7 +249,7 @@
      * @param l2LanId L2 lan ID
      */
     public void setL2LanId(String l2LanId) {
-        this.l1LanId = l1LanId;
+        this.l2LanId = l2LanId;
     }
 
     /**
@@ -293,6 +298,25 @@
     }
 
     /**
+     * Starts the holding time check timer.
+     */
+    public void startHoldingTimeCheck() {
+        log.debug("IsisNeighbor::startHoldingTimeCheck");
+        holdingTimeCheckTask = new InternalHoldingTimeCheck();
+        exServiceHoldingTimeCheck = Executors.newSingleThreadScheduledExecutor();
+        exServiceHoldingTimeCheck.scheduleAtFixedRate(holdingTimeCheckTask, 1,
+                                                      1, TimeUnit.SECONDS);
+    }
+
+    /**
+     * Stops the holding time check timer.
+     */
+    public void stopHoldingTimeCheck() {
+        log.debug("IsisNeighbor::stopHoldingTimeCheck ");
+        exServiceHoldingTimeCheck.shutdown();
+    }
+
+    /**
      * Starts the inactivity timer.
      */
     public void startInactivityTimeCheck() {
@@ -300,8 +324,8 @@
             log.debug("IsisNeighbor::startInactivityTimeCheck");
             inActivityTimeCheckTask = new InternalInactivityTimeCheck();
             exServiceInActivity = Executors.newSingleThreadScheduledExecutor();
-            exServiceInActivity.scheduleAtFixedRate(inActivityTimeCheckTask, holdingTime,
-                                                    holdingTime, TimeUnit.SECONDS);
+            exServiceInActivity.scheduleAtFixedRate(inActivityTimeCheckTask, neighborDownInterval,
+                                                    neighborDownInterval, TimeUnit.SECONDS);
             inActivityTimerScheduled = true;
         }
     }
@@ -328,6 +352,8 @@
         isisInterface.setL2LanId(IsisConstants.DEFAULTLANID);
 
         neighborState = IsisInterfaceState.DOWN;
+        stopInactivityTimeCheck();
+        stopHoldingTimeCheck();
         isisInterface.removeNeighbor(this);
     }
 
@@ -347,4 +373,20 @@
             neighborDown();
         }
     }
+
+    /**
+     * Represents a Task which will decrement holding time for this neighbor.
+     */
+    private class InternalHoldingTimeCheck implements Runnable {
+        /**
+         * Creates an instance.
+         */
+        InternalHoldingTimeCheck() {
+        }
+
+        @Override
+        public void run() {
+            holdingTime--;
+        }
+    }
 }
\ No newline at end of file