use of org.opendaylight.lispflowmapping.lisp.type.MappingData in project lispflowmapping by opendaylight.
the class MappingSystem method refreshMappingRegistration.
/*
* 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.
*/
public void refreshMappingRegistration(Eid key, XtrId xtrId, Long timestamp) {
sbMappingTimeoutService.removeExpiredMappings();
if (timestamp == null) {
timestamp = System.currentTimeMillis();
}
MappingData mappingData = (MappingData) smc.getMapping(null, key);
if (mappingData != null) {
mappingData.setTimestamp(new Date(timestamp));
addOrRefreshMappingInTimeoutService(key, mappingData);
} else {
LOG.warn("Could not update timestamp for EID {}, no mapping found", LispAddressStringifier.getString(key));
}
if (mappingMerge && xtrId != null) {
MappingData xtrIdMappingData = (MappingData) smc.getMapping(key, xtrId);
if (xtrIdMappingData != null) {
xtrIdMappingData.setTimestamp(new Date(timestamp));
} else {
LOG.warn("Could not update timestamp for EID {} xTR-ID {}, no mapping found", LispAddressStringifier.getString(key), LispAddressStringifier.getString(xtrId));
}
}
}
use of org.opendaylight.lispflowmapping.lisp.type.MappingData in project lispflowmapping by opendaylight.
the class MappingSystem method mergeNegativePrefixes.
/*
* Merges adjacent negative prefixes and notifies their subscribers.
*/
private void mergeNegativePrefixes(Eid eid) {
LOG.debug("Merging negative prefixes starting from EID {}", LispAddressStringifier.getString(eid));
// If we delete nodes while we walk up the radix trie the algorithm will give incorrect results, because
// removals rearrange relationships in the trie. So we save prefixes to be removed into a HashMap.
Map<Eid, MappingData> mergedMappings = new HashMap<>();
Eid currentNode = smc.getSiblingPrefix(eid);
MappingData mapping = (MappingData) smc.getMapping(null, currentNode);
if (mapping != null && mapping.isNegative().or(false)) {
mergedMappings.put(currentNode, mapping);
} else {
return;
}
Eid previousNode = currentNode;
currentNode = smc.getVirtualParentSiblingPrefix(currentNode);
while (currentNode != null) {
mapping = (MappingData) smc.getMapping(null, currentNode);
if (mapping != null && mapping.isNegative().or(false)) {
mergedMappings.put(currentNode, mapping);
} else {
break;
}
previousNode = currentNode;
currentNode = smc.getVirtualParentSiblingPrefix(previousNode);
}
for (Eid key : mergedMappings.keySet()) {
removeSbMapping(key, mergedMappings.get(key));
}
smc.removeMapping(eid);
addNegativeMapping(getVirtualParent(previousNode));
}
use of org.opendaylight.lispflowmapping.lisp.type.MappingData in project lispflowmapping by opendaylight.
the class MapResolver method handleMapRequest.
public void handleMapRequest(MapRequest request) {
LOG.trace("Map-Request received: {}", request);
// SMRs and RLOC probes are directed towards xTRs and we're a Map-Resolver here, so ignore them
if (request.isSmr() != null && request.isSmr()) {
LOG.debug("Map-Resolver ignoring incoming SMR control message.");
return;
}
if (request.isProbe() != null && request.isProbe()) {
LOG.debug("Map-Resolver ignoring incoming RLOC probe control message.");
return;
}
if (request.isSmrInvoked()) {
LOG.debug("SMR-invoked request received.");
LOG.trace("Map-Request object: {}", request);
for (EidItem eidItem : request.getEidItem()) {
final SmrEvent event = new SmrEvent(subscriberListFromItrRlocs(request.getItrRloc(), request.getSourceEid().getEid()), eidItem.getEid(), request.getNonce());
smrNotificationListener.onSmrInvokedReceived(event);
}
}
Eid srcEid = null;
if (request.getSourceEid() != null) {
srcEid = request.getSourceEid().getEid();
}
MapReplyBuilder replyBuilder = new MapReplyBuilder();
replyBuilder.setEchoNonceEnabled(false);
replyBuilder.setProbe(false);
replyBuilder.setSecurityEnabled(false);
replyBuilder.setNonce(request.getNonce());
replyBuilder.setMappingRecordItem(new ArrayList<>());
List<ItrRloc> itrRlocs = request.getItrRloc();
final IpAddressBinary sourceRloc = request.getSourceRloc();
for (EidItem eidRecord : request.getEidItem()) {
MappingData mappingData = mapService.getMapping(srcEid, eidRecord.getEid());
MappingRecord mapping;
if (mappingData == null) {
mapping = mapService.addNegativeMapping(eidRecord.getEid()).getRecord();
} else {
mapping = mappingData.getRecord();
}
if (itrRlocs != null && itrRlocs.size() != 0) {
if (subscriptionService && isValidSourceEidForSubscriber(srcEid)) {
final Rloc resolvedRloc = resolveRloc(itrRlocs, sourceRloc);
updateSubscribers(resolvedRloc, eidRecord.getEid(), mapping.getEid(), srcEid, mapping.getRecordTtl());
}
mapping = updateLocators(mapping, itrRlocs);
}
mapping = fixIfNotSDRequest(mapping, eidRecord.getEid());
mapping = fixTtlIfSmrInvoked(request, mapping);
replyBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(mapping).build());
}
requestHandler.handleMapReply(replyBuilder.build());
}
use of org.opendaylight.lispflowmapping.lisp.type.MappingData in project lispflowmapping by opendaylight.
the class MapServer method handleMapRegister.
@SuppressWarnings("unchecked")
public void handleMapRegister(MapRegister mapRegister) {
boolean mappingUpdated = false;
boolean merge = ConfigIni.getInstance().mappingMergeIsSet() && mapRegister.isMergeEnabled();
MappingRecord oldMapping;
if (merge) {
if (!mapRegister.isXtrSiteIdPresent() || mapRegister.getXtrId() == null) {
LOG.error("Merge bit is set in Map-Register, but xTR-ID is not present. Will not merge.");
merge = false;
} else if (Arrays.equals(mapRegister.getXtrId().getValue(), ALL_ZEROES_XTR_ID)) {
LOG.warn("Merge bit is set in Map-Register, but xTR-ID is all zeroes.");
}
}
for (MappingRecordItem record : mapRegister.getMappingRecordItem()) {
MappingRecord mapping = record.getMappingRecord();
Eid eid = mapping.getEid();
MappingData mappingData = new MappingData(mapping, System.currentTimeMillis());
mappingData.setMergeEnabled(merge);
mappingData.setXtrId(mapRegister.getXtrId());
oldMapping = getMappingRecord(mapService.getMapping(MappingOrigin.Southbound, eid));
mapService.addMapping(MappingOrigin.Southbound, eid, getSiteId(mapRegister), mappingData);
if (merge) {
MappingRecord newMapping = getMappingRecord(mapService.getMapping(MappingOrigin.Southbound, eid));
if (MappingRecordUtil.mappingChanged(oldMapping, newMapping)) {
// If there is a SB mapping change with merge on, Map-Notify will be sent to ALL xTRs, not jus the
// one registering (merging is done in the MappingSystem code)
mappingUpdated = true;
}
}
}
if (BooleanUtils.isTrue(mapRegister.isWantMapNotify())) {
LOG.trace("MapRegister wants MapNotify");
MapNotifyBuilder builder = new MapNotifyBuilder();
List<TransportAddress> rlocs = null;
if (merge) {
Set<IpAddressBinary> notifyRlocs = new HashSet<IpAddressBinary>();
List<MappingRecordItem> mergedMappings = new ArrayList<MappingRecordItem>();
for (MappingRecordItem record : mapRegister.getMappingRecordItem()) {
MappingRecord mapping = record.getMappingRecord();
MappingRecord currentRecord = getMappingRecord(mapService.getMapping(MappingOrigin.Southbound, mapping.getEid()));
mergedMappings.add(new MappingRecordItemBuilder().setMappingRecord(currentRecord).build());
Set<IpAddressBinary> sourceRlocs = (Set<IpAddressBinary>) mapService.getData(MappingOrigin.Southbound, mapping.getEid(), SubKeys.SRC_RLOCS);
if (sourceRlocs != null) {
notifyRlocs.addAll(sourceRlocs);
}
}
MapNotifyBuilderHelper.setFromMapRegisterAndMappingRecordItems(builder, mapRegister, mergedMappings);
// send map-notify to merge group only when mapping record is changed
if (mappingUpdated) {
rlocs = getTransportAddresses(notifyRlocs);
}
} else {
MapNotifyBuilderHelper.setFromMapRegister(builder, mapRegister);
}
List<MappingRecordItem> mappings = builder.getMappingRecordItem();
if (mappings != null && mappings.get(0) != null && mappings.get(0).getMappingRecord() != null && mappings.get(0).getMappingRecord().getEid() != null) {
MappingAuthkey authkey = mapService.getAuthenticationKey(mappings.get(0).getMappingRecord().getEid());
if (authkey != null) {
builder.setAuthenticationData(LispAuthenticationUtil.createAuthenticationData(builder.build(), authkey.getKeyString()));
}
}
notifyHandler.handleMapNotify(builder.build(), rlocs);
}
}
use of org.opendaylight.lispflowmapping.lisp.type.MappingData in project lispflowmapping by opendaylight.
the class MappingSystemTest method getMappingTest_NbSbIntersection_mergeMappings.
/**
* Tests {@link MappingSystem#getMapping} method, northbound and southbound intersection with single Ipv4 type
* locator, southbound non-null. Returns the merged mapping.
*/
@Test
public void getMappingTest_NbSbIntersection_mergeMappings() throws NoSuchFieldException, IllegalAccessException {
setLookupPolicy(IMappingService.LookupPolicy.NB_AND_SB);
final MappingRecord mappingRecord = getDefaultMappingRecordBuilder().setLocatorRecord(Lists.newArrayList(getDefaultLocatorRecordBuilder().build())).build();
final MappingData nbMappingData = getDefaultMappingData(mappingRecord);
final MappingData sbMappingData = getDefaultMappingData(mappingRecord);
// this mock will be ultimately returned when MappingMergeUtil.computeNbSbIntersection is called
final MappingData resultMock = Mockito.mock(MappingData.class);
PowerMockito.mockStatic(MappingMergeUtil.class);
Mockito.when(pmcMock.getMapping(EID_IPV4_SRC, EID_IPV4_DST)).thenReturn(nbMappingData);
Mockito.when(smcMock.getMapping(EID_IPV4_DST, (XtrId) null)).thenReturn(sbMappingData);
PowerMockito.when(MappingMergeUtil.computeNbSbIntersection(nbMappingData, sbMappingData)).thenReturn(resultMock);
assertEquals(resultMock, mappingSystem.getMapping(EID_IPV4_SRC, EID_IPV4_DST));
}
Aggregations