use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder in project lispflowmapping by opendaylight.
the class MappingMergeUtil method mergeLocatorRecords.
private static void mergeLocatorRecords(MappingRecordBuilder mrb, MappingRecord newRecord) {
List<LocatorRecord> locators = mrb.getLocatorRecord();
// We assume locators are unique and sorted and don't show up several times (with different or identical
// p/w/mp/mw), so we create a LinkedHashMap (which preserves order) of the locators from the existing merged
// record, keyed by the Rloc
Map<Rloc, LocatorRecord> locatorMap = new LinkedHashMap<Rloc, LocatorRecord>();
// All locators to be added to the merge set are first stored in this list
List<LocatorRecord> newLocatorList = new ArrayList<LocatorRecord>();
for (LocatorRecord locator : locators) {
locatorMap.put(locator.getRloc(), locator);
}
for (LocatorRecord newLocator : newRecord.getLocatorRecord()) {
Rloc newRloc = newLocator.getRloc();
if (locatorMap.containsKey(newRloc)) {
// overlapping locator
if (!locatorMap.get(newRloc).equals(newLocator)) {
LocatorRecord mergedLocator = mergeLocators(locatorMap.get(newRloc), newLocator);
newLocatorList.add(mergedLocator);
}
} else {
// new locator
newLocatorList.add(newLocator);
}
}
// Build new merged and sorted locator set if need be
if (!newLocatorList.isEmpty()) {
List<LocatorRecord> mergedLocators = new ArrayList<LocatorRecord>();
int mlocIt = 0;
int locIt = 0;
while (mlocIt < newLocatorList.size() && locIt < locators.size()) {
int cmp = compareLocators(locators.get(locIt), newLocatorList.get(mlocIt));
if (cmp < 0) {
mergedLocators.add(locators.get(locIt));
locIt++;
} else if (cmp > 0) {
mergedLocators.add(newLocatorList.get(mlocIt));
mlocIt++;
} else {
// when a locator appears in both lists, keep the new (merged) one and skip the old
mergedLocators.add(newLocatorList.get(mlocIt));
mlocIt++;
locIt++;
}
}
while (locIt < locators.size()) {
mergedLocators.add(locators.get(locIt));
locIt++;
}
while (mlocIt < newLocatorList.size()) {
mergedLocators.add(newLocatorList.get(mlocIt));
mlocIt++;
}
mrb.setLocatorRecord(mergedLocators);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder in project lispflowmapping by opendaylight.
the class MappingMergeUtil method mergeMappings.
public static MappingRecord mergeMappings(MappingRecord currentMergedMapping, MappingRecord newMapping, XtrId xtrId, Date regdate) {
if (currentMergedMapping == null) {
return newMapping;
}
MappingRecordBuilder mrb = new MappingRecordBuilder(currentMergedMapping);
mergeCommonMappingRecordFields(mrb, newMapping);
mergeLocatorRecords(mrb, newMapping);
if (xtrId != null) {
mrb.setXtrId(xtrId);
mrb.setTimestamp(regdate.getTime());
}
return mrb.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder in project lispflowmapping by opendaylight.
the class MappingMergeUtil method mergeXtrIdMappings.
public static MappingData mergeXtrIdMappings(List<Object> mappingDataList, List<MappingData> expiredMappingDataList, Set<IpAddressBinary> sourceRlocs) {
MappingRecordBuilder mrb = null;
XtrId xtrId = null;
Long timestamp = Long.MAX_VALUE;
for (int i = 0; i < mappingDataList.size(); i++) {
MappingData mappingData = (MappingData) mappingDataList.get(i);
MappingRecord record = mappingData.getRecord();
// Skip expired mappings and add them to a list to be returned to the caller
if (timestampIsExpired(mappingData.getTimestamp())) {
expiredMappingDataList.add(mappingData);
continue;
}
if (mrb == null) {
mrb = new MappingRecordBuilder(record);
}
// Save the oldest valid timestamp
if (mappingData.getTimestamp().getTime() < timestamp) {
timestamp = mappingData.getTimestamp().getTime();
xtrId = mappingData.getXtrId();
}
// Merge record fields and locators
mergeCommonMappingRecordFields(mrb, record);
mergeLocatorRecords(mrb, record);
// Save source locator for use in Map-Notify
sourceRlocs.add(record.getSourceRloc());
}
if (mrb == null) {
LOG.warn("All mappings expired when merging! Unexpected!");
return null;
}
mrb.setXtrId(xtrId);
return new MappingData(mrb.build(), new Date(timestamp));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder in project lispflowmapping by opendaylight.
the class RPCInputConvertorUtil method toMapping.
private static Mapping toMapping(Eid eid) {
MappingBuilder mb = new MappingBuilder();
mb.setEidUri(new EidUri(LispAddressStringifier.getURIString(eid)));
mb.setOrigin(MappingOrigin.Northbound);
mb.setMappingRecord(new MappingRecordBuilder().setEid(eid).build());
return mb.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder in project lispflowmapping by opendaylight.
the class MapResolverTest method handleMapRequest__withSubscribersToRemove.
/**
* Tests {@link MapResolver#handleMapRequest} method.
*/
@Test
@Ignore
public void handleMapRequest__withSubscribersToRemove() {
// input mapping
final LocatorRecordBuilder locatorRecordBuilder = getDefaultLocatorBuilder();
final MappingRecordBuilder mappingRecordBuilder = getDefaultMappingRecordBuilder();
mappingRecordBuilder.getLocatorRecord().add(locatorRecordBuilder.build());
MappingData mappingData = getDefaultMappingData(mappingRecordBuilder.build());
Mockito.when(mapServiceMock.getMapping(mapRequestBuilder.getSourceEid().getEid(), IPV4_PREFIX_EID_1)).thenReturn(mappingData);
Mockito.when(mapServiceMock.getData(MappingOrigin.Southbound, IPV4_PREFIX_EID_1, SubKeys.SUBSCRIBERS)).thenReturn(subscriberSetMock);
Subscriber subscriberMock = new Subscriber(mapRequestBuilder.getItrRloc().get(0).getRloc(), mapRequestBuilder.getSourceEid().getEid(), Subscriber.DEFAULT_SUBSCRIBER_TIMEOUT);
subscriberMock.setSubscriberTtlByRecordTtl(mappingRecordBuilder.getRecordTtl());
Mockito.when(subscriberSetMock.contains(subscriberMock)).thenReturn(true);
// result
final MapReplyBuilder mapReplyBuilder = getDefaultMapReplyBuilder();
mapReplyBuilder.getMappingRecordItem().add(new MappingRecordItemBuilder().setMappingRecord(mappingRecordBuilder.build()).build());
// check if a subscriber is re-instantiating when there already is one in the subscriber set
mapResolver.handleMapRequest(mapRequestBuilder.build());
Mockito.verify(subscriberSetMock).remove(subscriberMock);
Mockito.verify(subscriberSetMock).add(subscriberMock);
Mockito.verify(lispMappingServiceMock).handleMapReply(mapReplyBuilder.build());
Mockito.verify(mapServiceMock).addData(MappingOrigin.Southbound, IPV4_PREFIX_EID_1, SubKeys.SUBSCRIBERS, subscriberSetMock);
// verify that itrRloc is subscribed to dst address
mappingRecordBuilder.setEid(SOURCE_DEST_KEY_EID);
mapRequestBuilder.getEidItem().add(new EidItemBuilder().setEid(IPV4_PREFIX_EID_2).build());
mappingData = getDefaultMappingData(mappingRecordBuilder.build());
Mockito.when(mapServiceMock.getMapping(mapRequestBuilder.getSourceEid().getEid(), IPV4_PREFIX_EID_2)).thenReturn(mappingData);
mapResolver.handleMapRequest(mapRequestBuilder.build());
Mockito.verify(mapServiceMock).getData(MappingOrigin.Southbound, SourceDestKeyHelper.getDstBinary(SOURCE_DEST_KEY_EID), SubKeys.SUBSCRIBERS);
}
Aggregations