TEP is part of old and new TZ when tz is updated after del-manager 14/90914/3
authorNishchya Gupta <nishchyag@altencalsoftlabs.com>
Fri, 3 Jul 2020 12:09:11 +0000 (17:39 +0530)
committerHema Gopalakrishnan <hema.gopalkrishnan@ericsson.com>
Sun, 26 Jul 2020 10:47:30 +0000 (10:47 +0000)
Issue observed:
1. TZA was present and TEPs were part of it.
2. ovsdb connection is removed by running delete-manager command on
switch
3. Change transport-zone of TEPs from TZA to TZC
4. ovsdb connection is set again by running set-manager command on
switch
5. TEPs go under teps-not-hosted since TZC is not yet present. It is
noted here that TEPs are still part of TZA in ITM config DS.
6. TZC is created from northbound
7. TEPs are moved from teps-not-hosted to TZC.
8. In the end, TEPs are part of TZA and TZC both. This is issue.

Fix provided:
When TEPs add notification come again with updated TZC, then
check if same TEP (key: dpid) is already present in any other TZ.
If present, then remove TEP from old TZ and then add TEP into newly
configured TZ.

Signed-off-by: Nishchya Gupta <nishchyag@altencalsoftlabs.com>
Change-Id: I98c3c89f70e60676ea9c5f73d90b1a750943e7a5

itm/itm-impl/src/main/java/org/opendaylight/genius/itm/confighelpers/OvsdbTepAddConfigHelper.java
itm/itm-impl/src/main/java/org/opendaylight/genius/itm/impl/ItmUtils.java
itm/itm-impl/src/test/java/org/opendaylight/genius/itm/tests/ItmTepAutoConfigTestUtil.java

index afcf15c65013ae178d8c9c3aef10636ffd1aef8e..96e61f12a32e379788a324d44fe22f09787accc2 100644 (file)
@@ -66,8 +66,8 @@ public final class OvsdbTepAddConfigHelper {
 
     public static List<ListenableFuture<Void>> addTepReceivedFromOvsdb(String tepIp, String strDpnId, String tzName,
                                                                        boolean ofTunnel, DataBroker dataBroker,
-                                                                       ManagedNewTransactionRunner txRunner) {
-        List<ListenableFuture<Void>> futures = new ArrayList<>();
+                                                                       ManagedNewTransactionRunner txRunner)
+                                                                       throws Exception {
         Uint64 dpnId = Uint64.ZERO;
 
         if (strDpnId != null && !strDpnId.isEmpty()) {
@@ -78,6 +78,19 @@ public final class OvsdbTepAddConfigHelper {
         IpAddress tepIpAddress = IpAddressBuilder.getDefaultInstance(tepIp);
         TransportZone tzone = null;
 
+        // check if TEP received is already present in any other TZ.
+        TransportZone transportZone = ItmUtils.getTransportZoneOfVtep(dpnId, dataBroker);
+        if (transportZone != null) {
+            LOG.trace("Vtep (tep-ip: {} and dpid: {}) is already present in transport-zone: {}",
+                    tepIpAddress, dpnId, transportZone.getZoneName());
+            if (!transportZone.getZoneName().equals(tzName)) {
+                // remove TEP from TZ because TZ is updated for TEP from southbound in this case
+                OvsdbTepRemoveWorker ovsdbTepRemoveWorkerObj = new OvsdbTepRemoveWorker(tepIp, strDpnId,
+                        transportZone.getZoneName(), dataBroker);
+                ovsdbTepRemoveWorkerObj.call();
+            }
+        }
+
         // Case: TZ name is not given with OVS TEP.
         if (tzName == null) {
             tzName = ITMConstants.DEFAULT_TRANSPORT_ZONE;
@@ -103,7 +116,7 @@ public final class OvsdbTepAddConfigHelper {
             }
         }
 
-
+        List<ListenableFuture<Void>> futures = new ArrayList<>();
         final Uint64 id = dpnId;
         final String name = tzName;
         futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(Datastore.CONFIGURATION,
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)) {
index 96edf055b3e79d081a9b6dc7c3df88654902c49b..6368dd90f47322d6dfe3801fc151f5cbb8347f8f 100644 (file)
@@ -37,7 +37,8 @@ public final class ItmTepAutoConfigTestUtil {
 
     /* transaction methods */
     public static ListenableFuture<Void> addTep(String tepIp, String strDpnId, String tzName, boolean ofTunnel,
-                                                DataBroker dataBroker, ManagedNewTransactionRunner tx) {
+                                                DataBroker dataBroker, ManagedNewTransactionRunner tx)
+                                                throws Exception {
         return
             OvsdbTepAddConfigHelper.addTepReceivedFromOvsdb(tepIp, strDpnId, tzName, ofTunnel, dataBroker, tx).get(0);
     }