package org.opendaylight.lispflowmapping.implementation;
-import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.ArrayList;
import java.util.Date;
import java.util.EnumMap;
dsbe.removeXtrIdMapping(DSBEInputUtil.toXtrIdMapping(mappingData));
}
+ @SuppressWarnings("unchecked")
private void removeSbMapping(Eid key, MappingData mappingData) {
if (mappingData != null && mappingData.getXtrId() != null) {
removeSbXtrIdSpecificMapping(key, mappingData.getXtrId(), mappingData);
}
+
removeFromSbTimeoutService(key);
+ Set<Subscriber> subscribers = (Set<Subscriber>) getData(MappingOrigin.Southbound, key, SubKeys.SUBSCRIBERS);
smc.removeMapping(key);
dsbe.removeMapping(DSBEInputUtil.toMapping(MappingOrigin.Southbound, key, mappingData));
+ notifyChange(mappingData, subscribers, null, MappingChange.Removed);
}
private void removeFromSbTimeoutService(Eid key) {
MappingData mapping = (MappingData) tableMap.get(origin).getMapping(null, key);
if (mapping != null) {
+ MappingData notificationMapping = mapping;
subscribers = (Set<Subscriber>) getData(MappingOrigin.Southbound, key, SubKeys.SUBSCRIBERS);
// For SrcDst LCAF also send SMRs to Dst prefix
if (key.getAddress() instanceof SourceDestKey) {
Eid dstAddr = SourceDestKeyHelper.getDstBinary(key);
dstSubscribers = (Set<Subscriber>) getData(MappingOrigin.Southbound, dstAddr, SubKeys.SUBSCRIBERS);
if (!(mapping.getRecord().getEid().getAddress() instanceof SourceDestKey)) {
- mapping = new MappingData(new MappingRecordBuilder().setEid(key).build());
+ notificationMapping = new MappingData(new MappingRecordBuilder().setEid(key).build());
}
}
- notifyChange(mapping, subscribers, dstSubscribers, MappingChange.Removed);
+ notifyChange(notificationMapping, subscribers, dstSubscribers, MappingChange.Removed);
}
if (origin == MappingOrigin.Northbound) {
if (origin == MappingOrigin.Southbound) {
removeFromSbTimeoutService(key);
if (mapping != null && mapping.isPositive().or(false)) {
- SimpleImmutableEntry<Eid, Set<Subscriber>> mergedNegativePrefix = computeMergedNegativePrefix(key);
- if (mergedNegativePrefix != null) {
- addNegativeMapping(mergedNegativePrefix.getKey());
- subscribers = mergedNegativePrefix.getValue();
- notifyChange(mapping, subscribers, null, MappingChange.Created);
- }
+ mergeNegativePrefixes(key);
}
}
tableMap.get(origin).removeMapping(key);
}
- @SuppressWarnings("unchecked")
/*
- * Returns the "merged" prefix and the subscribers of the prefixes that were merged.
+ * Merges adjacent negative prefixes and notifies their subscribers.
*/
- private SimpleImmutableEntry<Eid, Set<Subscriber>> computeMergedNegativePrefix(Eid eid) {
- // Variable to hold subscribers we collect along the way
- Set<Subscriber> subscribers = null;
-
+ private void mergeNegativePrefixes(Eid eid) {
// If prefix sibling has a negative mapping, save its subscribers
Eid sibling = smc.getSiblingPrefix(eid);
MappingData mapping = (MappingData) smc.getMapping(null, sibling);
if (mapping != null && mapping.isNegative().or(false)) {
- subscribers = (Set<Subscriber>) getData(MappingOrigin.Southbound, eid, SubKeys.SUBSCRIBERS);
+ removeSbMapping(sibling, mapping);
} else {
- return null;
+ return;
}
Eid currentNode = sibling;
while ((currentNode = smc.getVirtualParentSiblingPrefix(currentNode)) != null) {
mapping = (MappingData) smc.getMapping(null, currentNode);
if (mapping != null && mapping.isNegative().or(false)) {
- subscribers.addAll((Set<Subscriber>)
- getData(MappingOrigin.Southbound, currentNode, SubKeys.SUBSCRIBERS));
removeSbMapping(currentNode, mapping);
} else {
break;
}
previousNode = currentNode;
}
- return new SimpleImmutableEntry<>(getVirtualParent(previousNode), subscribers);
+ addNegativeMapping(getVirtualParent(previousNode));
}
private static Eid getVirtualParent(Eid eid) {
buildMapCaches();
}
- /*
- * XXX Mappings and keys should be separated for this to work properly, as is it will remove northbound originated
- * authentication keys too, since they are currently stored in smc.
- */
public void cleanSBMappings() {
smc = new SimpleMapCache(sdao);
}
import com.google.common.base.Preconditions;
import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import java.net.InetAddress;
import java.net.NetworkInterface;
@SuppressWarnings("unchecked")
public void handleMapRegister(MapRegister mapRegister) {
boolean mappingUpdated = false;
- boolean oldMappingRemoved = false;
boolean merge = ConfigIni.getInstance().mappingMergeIsSet() && mapRegister.isMergeEnabled();
- Set<Subscriber> subscribers = null;
+ Set<Subscriber> subscribers = Sets.newConcurrentHashSet();
MappingRecord oldMapping;
if (merge) {
oldMapping = getMappingRecord(mapService.getMapping(MappingOrigin.Southbound, eid));
mapService.addMapping(MappingOrigin.Southbound, eid, getSiteId(mapRegister), mappingData);
- if (oldMapping != null && MappingRecordUtil.isNegativeMapping(oldMapping)) {
+ if (oldMapping != null
+ && MappingRecordUtil.isNegativeMapping(oldMapping)
+ && !oldMapping.getEid().equals(eid)) {
+ if (subscriptionService) {
+ // Here we save the subscribers of the OLD mapping before removing. We will add to this set the
+ // subscribers of the NEW mapping below (since the EIDs are different, the result of
+ // mappingChanged() will be true, and then send an SMR to all subscribers with the EID of the NEW
+ // mapping only.
+ Set<Subscriber> oldMappingSubscribers = getSubscribers(oldMapping.getEid());
+ if (oldMappingSubscribers != null) {
+ subscribers.addAll(oldMappingSubscribers);
+ LoggingUtil.logSubscribers(LOG, oldMapping.getEid(), subscribers);
+ }
+ }
mapService.removeMapping(MappingOrigin.Southbound, oldMapping.getEid());
- oldMappingRemoved = true;
}
if (subscriptionService) {
if (mappingChanged(oldMapping, newMapping)) {
if (LOG.isDebugEnabled()) {
LOG.debug("Mapping update occured for {} SMRs will be sent for its subscribers.",
- LispAddressStringifier.getString(mapping.getEid()));
+ LispAddressStringifier.getString(eid));
}
- subscribers = getSubscribers(eid);
+ Set<Subscriber> newMappingSubscribers = getSubscribers(eid);
if (oldMapping != null && !oldMapping.getEid().equals(eid)) {
- subscribers = addParentSubscribers(eid, subscribers);
+ newMappingSubscribers = addParentSubscribers(eid, newMappingSubscribers);
}
- LoggingUtil.logSubscribers(LOG, eid, subscribers);
- handleSmr(eid, subscribers);
- if (oldMapping != null && oldMappingRemoved && !oldMapping.getEid().equals(eid)) {
- subscribers = getSubscribers(oldMapping.getEid());
- LoggingUtil.logSubscribers(LOG, oldMapping.getEid(), subscribers);
- handleSmr(oldMapping.getEid(), subscribers);
+ if (newMappingSubscribers != null) {
+ subscribers.addAll(newMappingSubscribers);
+ LoggingUtil.logSubscribers(LOG, eid, subscribers);
}
+ handleSmr(eid, subscribers);
mappingUpdated = true;
}
}