From fb0ab72a382aa9d44546c3cc3628169dd06ae7c5 Mon Sep 17 00:00:00 2001 From: Lorand Jakab Date: Sat, 10 May 2014 12:01:16 +0300 Subject: [PATCH] Only send SMR when there is a change in mapping Change-Id: Ib82061a0028dcfa016eb6472ab07e79c5e4226e2 Signed-off-by: Lorand Jakab --- .../dao/MappingServiceRLOCGroup.java | 5 - .../implementation/lisp/MapResolver.java | 72 +----------- .../implementation/lisp/MapServer.java | 18 ++- .../implementation/util/DAOMappingUtil.java | 106 ++++++++++++++++++ 4 files changed, 124 insertions(+), 77 deletions(-) create mode 100644 mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/util/DAOMappingUtil.java diff --git a/mappingservice/api/src/main/java/org/opendaylight/lispflowmapping/interfaces/dao/MappingServiceRLOCGroup.java b/mappingservice/api/src/main/java/org/opendaylight/lispflowmapping/interfaces/dao/MappingServiceRLOCGroup.java index ce431b4de..e58270015 100644 --- a/mappingservice/api/src/main/java/org/opendaylight/lispflowmapping/interfaces/dao/MappingServiceRLOCGroup.java +++ b/mappingservice/api/src/main/java/org/opendaylight/lispflowmapping/interfaces/dao/MappingServiceRLOCGroup.java @@ -113,11 +113,6 @@ public class MappingServiceRLOCGroup { return false; } else if (!records.equals(other.records)) return false; - if (registerdDate == null) { - if (other.registerdDate != null) - return false; - } else if (!registerdDate.equals(other.registerdDate)) - return false; if (ttl != other.ttl) return false; return true; diff --git a/mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/lisp/MapResolver.java b/mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/lisp/MapResolver.java index 4edccb284..2cea7f285 100644 --- a/mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/lisp/MapResolver.java +++ b/mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/lisp/MapResolver.java @@ -11,11 +11,10 @@ package org.opendaylight.lispflowmapping.implementation.lisp; import java.util.ArrayList; import java.util.HashSet; import java.util.List; -import java.util.Map; import org.opendaylight.lispflowmapping.implementation.dao.MappingServiceKeyUtil; +import org.opendaylight.lispflowmapping.implementation.util.DAOMappingUtil; import org.opendaylight.lispflowmapping.implementation.util.LispNotificationHelper; -import org.opendaylight.lispflowmapping.implementation.util.MaskUtil; import org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO; import org.opendaylight.lispflowmapping.interfaces.dao.IMappingServiceKey; import org.opendaylight.lispflowmapping.interfaces.dao.MappingEntry; @@ -29,7 +28,6 @@ import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.eidrecords.EidReco import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.eidtolocatorrecords.EidToLocatorRecord; import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.eidtolocatorrecords.EidToLocatorRecordBuilder; import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.lispaddress.LispAddressContainer; -import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.lispaddress.LispAddressContainerBuilder; import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.locatorrecords.LocatorRecord; import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.locatorrecords.LocatorRecordBuilder; import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.mapreplymessage.MapReplyBuilder; @@ -58,7 +56,7 @@ public class MapResolver extends AbstractLispComponent implements IMapResolverAs if (request.isPitr()) { if (request.getEidRecord().size() > 0) { EidRecord eid = request.getEidRecord().get(0); - Object result = getLocatorsSpecific(eid, ADDRESS_SUBKEY); + Object result = DAOMappingUtil.getLocatorsSpecificByEidRecord(eid, dao, ADDRESS_SUBKEY, shouldIterateMask()); if (result != null && result instanceof MappingServiceRLOCGroup) { MappingServiceRLOCGroup locatorsGroup = (MappingServiceRLOCGroup) result; if (locatorsGroup != null && locatorsGroup.getRecords().size() > 0) { @@ -84,7 +82,7 @@ public class MapResolver extends AbstractLispComponent implements IMapResolverAs recordBuilder.setMaskLength(eid.getMask()); recordBuilder.setLispAddressContainer(eid.getLispAddressContainer()); recordBuilder.setLocatorRecord(new ArrayList()); - List locators = getLocators(eid); + List locators = DAOMappingUtil.getLocatorsByEidRecord(eid, dao, shouldIterateMask()); if (locators != null && locators.size() > 0) { addLocatorGroups(recordBuilder, locators); if (request.getItrRloc() != null && request.getItrRloc().size() > 0) { @@ -125,70 +123,6 @@ public class MapResolver extends AbstractLispComponent implements IMapResolverAs } } - private List getLocators(EidRecord eid) { - IMappingServiceKey key = MappingServiceKeyUtil.generateMappingServiceKey(eid.getLispAddressContainer(), eid.getMask()); - Map locators = dao.get(key); - List result = aggregateLocators(locators); - if (shouldIterateMask() && result.isEmpty() && MaskUtil.isMaskable(key.getEID().getAddress())) { - result = findMaskLocators(key); - } - return result; - } - - private List aggregateLocators(Map locators) { - List result = new ArrayList(); - if (locators != null) { - for (Object value : locators.values()) { - if (value != null && value instanceof MappingServiceRLOCGroup) { - if (!((MappingServiceRLOCGroup) value).getRecords().isEmpty()) { - result.add((MappingServiceRLOCGroup) value); - } - } - } - } - return result; - } - - private Object getLocatorsSpecific(EidRecord eid, String subkey) { - IMappingServiceKey key = MappingServiceKeyUtil.generateMappingServiceKey(eid.getLispAddressContainer(), eid.getMask()); - Object locators = dao.getSpecific(key, subkey); - if (shouldIterateMask() && locators == null && MaskUtil.isMaskable(key.getEID().getAddress())) { - locators = findMaskLocatorsSpecific(key, subkey); - } - return locators; - } - - private Object findMaskLocatorsSpecific(IMappingServiceKey key, String subkey) { - int mask = key.getMask(); - while (mask > 0) { - key = MappingServiceKeyUtil.generateMappingServiceKey( - new LispAddressContainerBuilder().setAddress(MaskUtil.normalize(key.getEID().getAddress(), mask)).build(), mask); - mask--; - Object locators = dao.getSpecific(key, subkey); - if (locators != null) { - return locators; - } - } - return null; - } - - private List findMaskLocators(IMappingServiceKey key) { - int mask = key.getMask(); - while (mask > 0) { - key = MappingServiceKeyUtil.generateMappingServiceKey( - new LispAddressContainerBuilder().setAddress(MaskUtil.normalize(key.getEID().getAddress(), mask)).build(), mask); - mask--; - Map locators = dao.get(key); - if (locators != null) { - List result = aggregateLocators(locators); - if (result != null && !result.isEmpty()) { - return result; - } - } - } - return null; - } - private void addLocatorGroups(EidToLocatorRecordBuilder recordBuilder, List rlocs) { for (MappingServiceRLOCGroup rloc : rlocs) { addLocators(recordBuilder, rloc); 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 4b374c4ec..efe02f56f 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 @@ -23,6 +23,7 @@ import org.apache.commons.lang3.BooleanUtils; import org.opendaylight.lispflowmapping.implementation.authentication.LispAuthenticationUtil; import org.opendaylight.lispflowmapping.implementation.config.ConfigIni; import org.opendaylight.lispflowmapping.implementation.dao.MappingServiceKeyUtil; +import org.opendaylight.lispflowmapping.implementation.util.DAOMappingUtil; import org.opendaylight.lispflowmapping.implementation.util.MapNotifyBuilderHelper; import org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO; import org.opendaylight.lispflowmapping.interfaces.dao.IMappingServiceKey; @@ -143,9 +144,9 @@ public class MapServer extends AbstractLispComponent implements IMapServerAsync break; } } - saveRlocs(eidRecord); + boolean mappingChanged = saveRlocs(eidRecord, smr); - if (smr) { + if (smr && mappingChanged) { HashSet subscribers = getSubscribers(eidRecord.getLispAddressContainer(), eidRecord.getMaskLength()); if (subscribers != null) { MapRequest mapRequest = buildSMR(eidRecord); @@ -179,7 +180,8 @@ public class MapServer extends AbstractLispComponent implements IMapServerAsync } } - public void saveRlocs(EidToLocatorRecord eidRecord) { + public boolean saveRlocs(EidToLocatorRecord eidRecord, boolean checkForChanges) { + List oldLocators = null, newLocators = null; IMappingServiceKey key = MappingServiceKeyUtil.generateMappingServiceKey(eidRecord.getLispAddressContainer(), eidRecord.getMaskLength()); Map rlocGroups = new HashMap(); if (eidRecord.getLocatorRecord() != null) { @@ -195,7 +197,17 @@ public class MapServer extends AbstractLispComponent implements IMapServerAsync for (String subkey : rlocGroups.keySet()) { entries.add(new MappingEntry<>(subkey, rlocGroups.get(subkey))); } + if (checkForChanges) { + oldLocators = DAOMappingUtil.getLocatorsByEidToLocatorRecord(eidRecord, dao, shouldIterateMask()); + } dao.put(key, entries.toArray(new MappingEntry[entries.size()])); + if (checkForChanges) { + newLocators = DAOMappingUtil.getLocatorsByEidToLocatorRecord(eidRecord, dao, shouldIterateMask()); + if (!newLocators.equals(oldLocators)) { + return true; + } + } + return false; } private String getLocatorKey(LocatorRecord locatorRecord) { diff --git a/mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/util/DAOMappingUtil.java b/mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/util/DAOMappingUtil.java new file mode 100644 index 000000000..74c249eb7 --- /dev/null +++ b/mappingservice/implementation/src/main/java/org/opendaylight/lispflowmapping/implementation/util/DAOMappingUtil.java @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2014 Contextream, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.lispflowmapping.implementation.util; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.opendaylight.lispflowmapping.implementation.dao.MappingServiceKeyUtil; +import org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO; +import org.opendaylight.lispflowmapping.interfaces.dao.IMappingServiceKey; +import org.opendaylight.lispflowmapping.interfaces.dao.MappingServiceRLOCGroup; +import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.eidrecords.EidRecord; +import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.eidtolocatorrecords.EidToLocatorRecord; +import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.lispaddress.LispAddressContainerBuilder; + +public class DAOMappingUtil { + + public static List getLocatorsByEidRecord(EidRecord eid, ILispDAO dao, boolean iterateMask) { + IMappingServiceKey key = MappingServiceKeyUtil.generateMappingServiceKey(eid.getLispAddressContainer(), eid.getMask()); + return getLocators(key, dao, iterateMask); + } + + public static Object getLocatorsSpecificByEidRecord(EidRecord eid, ILispDAO dao, String subkey, boolean iterateMask) { + IMappingServiceKey key = MappingServiceKeyUtil.generateMappingServiceKey(eid.getLispAddressContainer(), eid.getMask()); + return getLocatorsSpecific(key, dao, subkey, iterateMask); + } + + public static List getLocatorsByEidToLocatorRecord(EidToLocatorRecord eid, ILispDAO dao, boolean iterateMask) { + IMappingServiceKey key = MappingServiceKeyUtil.generateMappingServiceKey(eid.getLispAddressContainer(), eid.getMaskLength()); + return getLocators(key, dao, iterateMask); + } + + public static Object getLocatorsSpecificByEidtoLocatorRecord(EidToLocatorRecord eid, ILispDAO dao, String subkey, boolean iterateMask) { + IMappingServiceKey key = MappingServiceKeyUtil.generateMappingServiceKey(eid.getLispAddressContainer(), eid.getMaskLength()); + return getLocatorsSpecific(key, dao, subkey, iterateMask); + } + + public static List getLocators(IMappingServiceKey key, ILispDAO dao, boolean iterateMask) { + Map locators = dao.get(key); + List result = aggregateLocators(locators); + if (iterateMask && result.isEmpty() && MaskUtil.isMaskable(key.getEID().getAddress())) { + result = findMaskLocators(dao, key); + } + return result; + } + + private static List aggregateLocators(Map locators) { + List result = new ArrayList(); + if (locators != null) { + for (Object value : locators.values()) { + if (value != null && value instanceof MappingServiceRLOCGroup) { + if (!((MappingServiceRLOCGroup) value).getRecords().isEmpty()) { + result.add((MappingServiceRLOCGroup) value); + } + } + } + } + return result; + } + + public static Object getLocatorsSpecific(IMappingServiceKey key, ILispDAO dao, String subkey, boolean iterateMask) { + Object locators = dao.getSpecific(key, subkey); + if (iterateMask && locators == null && MaskUtil.isMaskable(key.getEID().getAddress())) { + locators = findMaskLocatorsSpecific(key, dao, subkey); + } + return locators; + } + + private static Object findMaskLocatorsSpecific(IMappingServiceKey key, ILispDAO dao, String subkey) { + int mask = key.getMask(); + while (mask > 0) { + key = MappingServiceKeyUtil.generateMappingServiceKey( + new LispAddressContainerBuilder().setAddress(MaskUtil.normalize(key.getEID().getAddress(), mask)).build(), mask); + mask--; + Object locators = dao.getSpecific(key, subkey); + if (locators != null) { + return locators; + } + } + return null; + } + + private static List findMaskLocators(ILispDAO dao, IMappingServiceKey key) { + int mask = key.getMask(); + while (mask > 0) { + key = MappingServiceKeyUtil.generateMappingServiceKey( + new LispAddressContainerBuilder().setAddress(MaskUtil.normalize(key.getEID().getAddress(), mask)).build(), mask); + mask--; + Map locators = dao.get(key); + if (locators != null) { + List result = aggregateLocators(locators); + if (result != null && !result.isEmpty()) { + return result; + } + } + } + return null; + } +} -- 2.36.6