Fixes for DVR
[groupbasedpolicy.git] / renderers / vpp / src / main / java / org / opendaylight / groupbasedpolicy / renderer / vpp / lisp / info / container / HostRelatedInfoContainer.java
index 1e07a7eba4ca7d3543f963276457a089180dd42a..bb6a08a674c50f0c3a79c07e97de0354d925ea47 100644 (file)
@@ -11,8 +11,20 @@ import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.info.container.states
 import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.info.container.states.LispState;
 import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.info.container.states.PhysicalInterfaces;
 import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.info.container.states.VrfHolder;
+import org.opendaylight.groupbasedpolicy.renderer.vpp.listener.VppEndpointListener;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.HashBasedTable;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
+import com.google.common.collect.Table;
 
 import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
 
 /**
  * Created by Shakib Ahmed on 7/13/17.
@@ -23,6 +35,9 @@ public class HostRelatedInfoContainer {
     private HashMap<String, PortInterfaces> hostNameToPortInterfacesMapper;
     private HashMap<String, VrfHolder> hostNameToVrfHolderMapper;
 
+    //route IDs on an interface on a host 
+    private Table<String, String, Set<Long>> routeIdsByHostByVrf = HashBasedTable.create();
+    
     private static final HostRelatedInfoContainer INSTANCE = new HostRelatedInfoContainer();
 
     private HostRelatedInfoContainer() {
@@ -32,6 +47,40 @@ public class HostRelatedInfoContainer {
         this.hostNameToVrfHolderMapper = new HashMap<>();
     }
 
+    public void addRouteToIntfc(String hostname, String intfName, Long routeId) {
+        Preconditions.checkNotNull(hostname);
+        Preconditions.checkNotNull(intfName);
+        Preconditions.checkNotNull(routeId);
+        if (routeIdsByHostByVrf.get(hostname, intfName) != null) {
+            routeIdsByHostByVrf.get(hostname, intfName).add(routeId);
+            return;
+        }
+        routeIdsByHostByVrf.put(hostname, intfName, Sets.newHashSet(routeId));
+    }
+
+    public void deleteRouteFromIntfc(String hostname, String intfName, Long routeId) {
+        Preconditions.checkNotNull(hostname);
+        Preconditions.checkNotNull(intfName);
+        Preconditions.checkNotNull(routeId);
+        if (routeIdsByHostByVrf.get(hostname, intfName) != null) {
+            routeIdsByHostByVrf.get(hostname, intfName).remove(routeId);
+        }
+    }
+
+    private static final Logger LOG = LoggerFactory.getLogger(VppEndpointListener.class);
+    
+    public boolean intfcIsBusy(String hostname, String intfName) {
+        Preconditions.checkNotNull(hostname);
+        Preconditions.checkNotNull(intfName);
+        if (routeIdsByHostByVrf.get(hostname, intfName) != null) {
+            int size = routeIdsByHostByVrf.get(hostname, intfName).size();
+            LOG.trace("ISPORTBUSY -> hostname: {}, inftName: {}, entries: {}", hostname, intfName, routeIdsByHostByVrf.get(hostname, intfName));
+            return (size == 0) ? false : true;
+        }
+        LOG.trace("ISPORTBUSY -> not busy interface on hostname: {}, inftName: {}", hostname, intfName);
+        return false;
+    }
+
     public static HostRelatedInfoContainer getInstance() {
         return INSTANCE;
     }
@@ -73,9 +122,18 @@ public class HostRelatedInfoContainer {
     }
 
     public VrfHolder getVrfStateOfHost(String hostName) {
+        return hostNameToVrfHolderMapper.get(hostName);
+    }
+
+    public VrfHolder initializeVrfStateOfHost(String hostName) {
         return hostNameToVrfHolderMapper.computeIfAbsent(hostName, key -> new VrfHolder());
     }
 
+    public int getVrfStateOfHostCount(String hostName) {
+        VrfHolder vrfHolder = hostNameToVrfHolderMapper.get(hostName);
+        return vrfHolder != null ? vrfHolder.vrfStateCount() : 0;
+    }
+
     public void removeVrfStateOfHost(String hostName) {
         hostNameToVrfHolderMapper.remove(hostName);
     }