Search in sources :

Example 46 with MappingData

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));
        }
    }
}
Also used : MappingData(org.opendaylight.lispflowmapping.lisp.type.MappingData) Date(java.util.Date)

Example 47 with MappingData

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));
}
Also used : Eid(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) MappingData(org.opendaylight.lispflowmapping.lisp.type.MappingData)

Example 48 with MappingData

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());
}
Also used : Eid(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid) MappingRecordItemBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder) ItrRloc(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRloc) IpAddressBinary(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.inet.binary.types.rev160303.IpAddressBinary) SmrEvent(org.opendaylight.lispflowmapping.interfaces.lisp.SmrEvent) MappingRecord(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord) Rloc(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.Rloc) ItrRloc(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRloc) MappingData(org.opendaylight.lispflowmapping.lisp.type.MappingData) MapReplyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapreplymessage.MapReplyBuilder) EidItem(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.list.EidItem)

Example 49 with MappingData

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);
    }
}
Also used : Eid(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid) MappingRecordItemBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder) Set(java.util.Set) HashSet(java.util.HashSet) MappingRecordItem(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem) TransportAddress(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.transport.address.TransportAddress) ArrayList(java.util.ArrayList) IpAddressBinary(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.inet.binary.types.rev160303.IpAddressBinary) MappingRecord(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord) MappingAuthkey(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkey) MappingData(org.opendaylight.lispflowmapping.lisp.type.MappingData) MapNotifyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapnotifymessage.MapNotifyBuilder) HashSet(java.util.HashSet)

Example 50 with MappingData

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));
}
Also used : MappingRecord(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord) MappingData(org.opendaylight.lispflowmapping.lisp.type.MappingData) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

MappingData (org.opendaylight.lispflowmapping.lisp.type.MappingData)69 Test (org.junit.Test)40 MappingRecord (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord)30 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)17 MappingRecordBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder)14 Eid (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid)11 LocatorRecordBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder)9 MappingRecordItemBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItemBuilder)9 Subscriber (org.opendaylight.lispflowmapping.interfaces.dao.Subscriber)7 MapReplyBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapreplymessage.MapReplyBuilder)7 ArrayList (java.util.ArrayList)5 Ignore (org.junit.Ignore)5 Date (java.util.Date)4 InstanceIdType (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.InstanceIdType)4 ItrRloc (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.maprequest.ItrRloc)4 Rloc (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.Rloc)4 Mapping (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.Mapping)4 Set (java.util.Set)3 DataTreeModification (org.opendaylight.controller.md.sal.binding.api.DataTreeModification)3 IRowVisitor (org.opendaylight.lispflowmapping.interfaces.dao.IRowVisitor)3