Enhance the logic for retrieving peer router mac to come up with the case that the switch interface is disabled.

Change-Id: Ide10c44e88c2312ba2bcb86afbf23a26b36c0d02
diff --git a/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/KubevirtRoutingArpHandler.java b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/KubevirtRoutingArpHandler.java
index a1c1415..9ba10b4 100644
--- a/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/KubevirtRoutingArpHandler.java
+++ b/apps/kubevirt-networking/app/src/main/java/org/onosproject/kubevirtnetworking/impl/KubevirtRoutingArpHandler.java
@@ -27,6 +27,7 @@
 import org.onosproject.cluster.NodeId;
 import org.onosproject.core.ApplicationId;
 import org.onosproject.core.CoreService;
+
 import org.onosproject.kubevirtnetworking.api.KubevirtFlowRuleService;
 import org.onosproject.kubevirtnetworking.api.KubevirtNetworkAdminService;
 import org.onosproject.kubevirtnetworking.api.KubevirtPeerRouter;
@@ -57,6 +58,8 @@
 
 import java.nio.ByteBuffer;
 import java.util.Objects;
+import java.util.Timer;
+import java.util.TimerTask;
 import java.util.concurrent.ExecutorService;
 
 import static java.util.concurrent.Executors.newSingleThreadExecutor;
@@ -108,6 +111,9 @@
 
     private final InternalRouterEventListener kubevirtRouterlistener = new InternalRouterEventListener();
 
+    private final Timer timer = new Timer("kubevirtcni-routing-arphandler");
+    private static final long SECONDS = 1000L;
+
     private ApplicationId appId;
     private NodeId localNodeId;
 
@@ -284,9 +290,16 @@
                         router.peerRouter().ipAddress(), gatewayNode.hostname(), true);
 
                 retrievePeerRouterMac(router, router.peerRouter().ipAddress());
+                checkPeerRouterMacRetrieved(router);
+
             }
         }
 
+        private void checkPeerRouterMacRetrieved(KubevirtRouter router) {
+            InternalTimerTask task = new InternalTimerTask(router.name(), router.peerRouter().ipAddress());
+            timer.schedule(task, 5 * SECONDS, 60 * SECONDS);
+        }
+
         private void processRouterExternalNetDetached(KubevirtRouter router, String routerSnatIp,
                                                       String peerRouterIp) {
             log.info("processRouterRemovedOrExternalNetDetached called");
@@ -405,4 +418,31 @@
             kubevirtRouterService.updatePeerRouterMac(router.name(), sha);
         }
     }
+
+    private class InternalTimerTask extends TimerTask {
+        String routerName;
+        IpAddress routerIpAddress;
+
+        public InternalTimerTask(String routerName, IpAddress routerIpAddress) {
+            this.routerName = routerName;
+            this.routerIpAddress = routerIpAddress;
+        }
+
+        @Override
+        public void run() {
+            KubevirtRouter router = kubevirtRouterService.router(routerName);
+
+            if (router == null) {
+                return;
+            }
+
+            if (router.peerRouter().macAddress() != null) {
+                log.info("Peer Router Mac for {} is retrieved. Stop this task..", routerName);
+                this.cancel();
+                return;
+            }
+
+            retrievePeerRouterMac(router, routerIpAddress);
+        }
+    }
 }