TEP is part of old and new TZ when tz is updated after del-manager
[genius.git] / itm / itm-impl / src / main / java / org / opendaylight / genius / itm / impl / ItmUtils.java
index 469ded5f96b0cdbdc7862c8c983a1a6ebca73b0a..f1e6b4052d080a161ad6961262d6a3cba399bb1d 100644 (file)
@@ -1097,6 +1097,33 @@ public final class ItmUtils {
         return null;
     }
 
+    /**
+     * Returns the transport zone of vtep from Configuration datastore.
+     *
+     * @param dpid datapath id of vtep
+     * @param dataBroker data broker handle to perform operations on datastore
+     * @return the TransportZone object in Config DS
+     */
+    public static TransportZone getTransportZoneOfVtep(Uint64 dpid, DataBroker dataBroker) {
+        InstanceIdentifier<TransportZones> path = InstanceIdentifier.builder(TransportZones.class).build();
+        Optional<TransportZones> transportZonesOptional = ItmUtils.read(LogicalDatastoreType.CONFIGURATION,
+                path, dataBroker);
+        if (transportZonesOptional.isPresent()) {
+            TransportZones tzones = transportZonesOptional.get();
+            for (TransportZone tzone : tzones.getTransportZone()) {
+                List<Vteps> vtepList = new ArrayList<Vteps>(tzone.nonnullVteps().values());
+                if (vtepList != null && !vtepList.isEmpty()) {
+                    for (Vteps vtep : vtepList) {
+                        if (vtep.getDpnId().equals(dpid)) {
+                            return tzone;
+                        }
+                    }
+                }
+            }
+        }
+        return null;
+    }
+
     public static Class<? extends TunnelTypeBase> convertStringToTunnelType(String tunnelType) {
         Class<? extends TunnelTypeBase> tunType = TunnelTypeVxlan.class;
         if (STRING_CLASS_IMMUTABLE_BI_MAP.containsKey(tunnelType)) {