Search in sources :

Example 16 with MappingRecordBuilder

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);
    }
}
Also used : Rloc(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.Rloc) ArrayList(java.util.ArrayList) LocatorRecord(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord) LinkedHashMap(java.util.LinkedHashMap)

Example 17 with MappingRecordBuilder

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();
}
Also used : MappingRecordBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder)

Example 18 with MappingRecordBuilder

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));
}
Also used : MappingRecordBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder) MappingRecord(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord) MappingData(org.opendaylight.lispflowmapping.lisp.type.MappingData) Date(java.util.Date) XtrId(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.XtrId)

Example 19 with MappingRecordBuilder

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();
}
Also used : MappingBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.MappingBuilder) MappingRecordBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder) EidUri(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.EidUri)

Example 20 with MappingRecordBuilder

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);
}
Also used : LocatorRecordBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder) MappingRecordItemBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder) Subscriber(org.opendaylight.lispflowmapping.interfaces.dao.Subscriber) MappingRecordBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder) MappingData(org.opendaylight.lispflowmapping.lisp.type.MappingData) MapReplyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapreplymessage.MapReplyBuilder) EidItemBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.list.EidItemBuilder) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

MappingRecordBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder)57 Test (org.junit.Test)30 MappingRecordItemBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder)27 MappingRecordItem (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem)20 LocatorRecord (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord)16 ByteBuffer (java.nio.ByteBuffer)14 MappingData (org.opendaylight.lispflowmapping.lisp.type.MappingData)14 MapReplyBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapreplymessage.MapReplyBuilder)14 LocatorRecordBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder)13 ArrayList (java.util.ArrayList)8 SiteId (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.SiteId)8 MapRegisterBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapregisternotification.MapRegisterBuilder)8 MapNotifyBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapnotifymessage.MapNotifyBuilder)7 ItrRloc (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRloc)7 Rloc (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.Rloc)6 MappingBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.MappingBuilder)6 Subscriber (org.opendaylight.lispflowmapping.interfaces.dao.Subscriber)5 Eid (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid)5 EidItemBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.list.EidItemBuilder)5 MappingRecord (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord)5