Merge "Remove xtr id mappings on mapping overwrite"
authorVina Ermagan <vermagan@cisco.com>
Tue, 31 Jan 2017 02:04:53 +0000 (02:04 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Tue, 31 Jan 2017 02:04:53 +0000 (02:04 +0000)
mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/MappingSystem.java

index 5ea3887b5e70b016f93dece1b0b88c509649f9b7..cb3b85cf983df3f076821da249a2d92c43cf6e76 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.