Remove xtr id mappings on mapping overwrite 09/50909/5
authorShakib Ahmed <sheikahm@cisco.com>
Mon, 23 Jan 2017 21:43:29 +0000 (13:43 -0800)
committerShakib Ahmed <sheikahm@cisco.com>
Fri, 27 Jan 2017 23:48:27 +0000 (15:48 -0800)
If there are 2 xtrs with different merge mapping configuration
registers same eid, we may or may not have merged mapping for
the eid in Map Cache but we will have xtr id specific mapping
in XTRID_RECORDS all the time. When we have xtr id specific
mapping from the xtr with merge configuration, but overwritten
mapping record in RECORD, then the xtr id specific mappings
may become untracked and hence not removed ever.

This patch removes previous xtrid specific mappings too when
mapping records are being overwritten.

Change-Id: Iaf8686367fb881b5794a3bf232e6c2e12d5ec6f8
Signed-off-by: Shakib Ahmed <sheikahm@cisco.com>
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/MappingSystem.java

index 3294e493908c773379895f041102aa893fc84c67..297379846bbb16566d4e0f436c419e2660161ee0 100644 (file)
@@ -14,6 +14,7 @@ import java.util.EnumMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
+
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.lispflowmapping.config.ConfigIni;
 import org.opendaylight.lispflowmapping.dsbackend.DataStoreBackEnd;
@@ -128,10 +129,13 @@ public class MappingSystem implements IMappingSystem {
                 return;
             }
             if (xtrId != null && mappingMerge) {
-                smc.addMapping(key, xtrId, mappingData);
                 if (mappingData.isMergeEnabled()) {
+                    smc.addMapping(key, xtrId, mappingData);
                     mergeMappings(key);
                     return;
+                } else {
+                    clearPresentXtrIdMappings(key);
+                    smc.addMapping(key, xtrId, mappingData);
                 }
             }
         }
@@ -139,6 +143,19 @@ public class MappingSystem implements IMappingSystem {
         tableMap.get(origin).addMapping(key, mappingData);
     }
 
+    private void clearPresentXtrIdMappings(Eid key) {
+        List<MappingData> allXtrMappingList = (List<MappingData>) (List<?>) smc.getAllXtrIdMappings(key);
+
+        if (((MappingData) smc.getMapping(key, (XtrId) null)).isMergeEnabled()) {
+            LOG.trace("Different xTRs have different merge configuration!");
+        }
+
+        for (MappingData mappingData : allXtrMappingList) {
+            smc.removeMapping(key, mappingData.getXtrId());
+            dsbe.removeXtrIdMapping(DSBEInputUtil.toXtrIdMapping(mappingData));
+        }
+    }
+
     /*
      * Since this method is only called when there is a hit in the southbound Map-Register cache, and that cache is
      * not used when merge is on, it's OK to ignore the effects of timestamp changes on merging for now.