From: Lorand Jakab Date: Thu, 4 Feb 2016 13:07:47 +0000 (+0200) Subject: Bug 5228: Use custom comparator for mappings X-Git-Tag: release/boron~213 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F75%2F34075%2F1;p=lispflowmapping.git Bug 5228: Use custom comparator for mappings Change-Id: If44444dded1027c2d31e78815df77d88ca8a4cb3 Signed-off-by: Lorand Jakab --- diff --git a/mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/lisp/MapServer.java b/mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/lisp/MapServer.java index 75857aa62..e7e4974f7 100644 --- a/mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/lisp/MapServer.java +++ b/mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/lisp/MapServer.java @@ -12,9 +12,11 @@ import java.net.InetAddress; import java.net.NetworkInterface; import java.net.SocketException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Enumeration; import java.util.HashSet; import java.util.List; +import java.util.Objects; import java.util.Set; import org.apache.commons.lang3.BooleanUtils; @@ -117,12 +119,12 @@ public class MapServer implements IMapServerAsync, OdlMappingserviceListener { break; } } - oldMapping = (MappingRecord) mapService.getMapping(MappingOrigin.Southbound, - mapping.getEid()); + oldMapping = (MappingRecord) mapService.getMapping(MappingOrigin.Southbound, mapping.getEid()); - if (subscriptionService && !mapping.equals(oldMapping)) { + if (subscriptionService && mappingChanged(oldMapping, mapping)) { if (LOG.isDebugEnabled()){ - LOG.debug("Mapping update occured for {} SMRs will be sent for its subscribers.", LispAddressStringifier.getString(mapping.getEid())); + LOG.debug("Mapping update occured for {} SMRs will be sent for its subscribers.", + LispAddressStringifier.getString(mapping.getEid())); } subscribers = getSubscribers(mapping.getEid()); updated = true; @@ -188,6 +190,38 @@ public class MapServer implements IMapServerAsync, OdlMappingserviceListener { } } + private static boolean mappingChanged(MappingRecord oldMapping, MappingRecord newMapping) { + // We only check for fields we care about + // XXX: This code needs to be checked and updated when the YANG model is modified + Preconditions.checkNotNull(newMapping, "The new mapping should never be null"); + if (oldMapping == null) { + LOG.trace("mappingChanged(): old mapping is null"); + return true; + } else if (!Objects.equals(oldMapping.getEid(), newMapping.getEid())) { + LOG.trace("mappingChanged(): EID"); + return true; + } else if (!Objects.equals(oldMapping.getLocatorRecord(), newMapping.getLocatorRecord())) { + LOG.trace("mappingChanged(): RLOC"); + return true; + } else if (!Objects.equals(oldMapping.getAction(), newMapping.getAction())) { + LOG.trace("mappingChanged(): action"); + return true; + } else if (!Objects.equals(oldMapping.getRecordTtl(), newMapping.getRecordTtl())) { + LOG.trace("mappingChanged(): TTL"); + return true; + } else if (!Arrays.equals(oldMapping.getXtrId(), newMapping.getXtrId())) { + LOG.trace("mappingChanged(): xTR-ID"); + return true; + } else if (!Arrays.equals(oldMapping.getSiteId(), newMapping.getSiteId())) { + LOG.trace("mappingChanged(): site-ID"); + return true; + } else if (!Objects.equals(oldMapping.getMapVersion(), newMapping.getMapVersion())) { + LOG.trace("mappingChanged(): mapping version"); + return true; + } + return false; + } + private void sendSmrs(MappingRecord record, Set subscribers) { Eid eid = record.getEid(); handleSmr(record, subscribers, notifyHandler);