Search in sources :

Example 41 with MappingData

use of org.opendaylight.lispflowmapping.lisp.type.MappingData in project lispflowmapping by opendaylight.

the class MappingSystem method restoreDaoFromDatastore.

/**
 * Restore all mappings and keys from mdsal datastore.
 */
private void restoreDaoFromDatastore() {
    List<AuthenticationKey> authKeys = dsbe.getAllAuthenticationKeys();
    List<Mapping> mappings = dsbe.getAllMappings(LogicalDatastoreType.CONFIGURATION);
    /*
         * XXX By default, the operational datastore is not persisted to disk, either at run-time, or on shutdown,
         * so the following will have no effect (getLastUpdateTimestamp() will fail, since it's reading from
         * the operational datastore, and even if it didn't getAllMappings() will fail anyway). According to rovarga it
         * should be possible to turn on persistence for the operational datastore editing
         * etc/opendaylight/karaf/05-clustering.xml, by setting <persistence>true</persistence>. At the time of writing
         * the below code block that didn't seem to work though.
         */
    Long lastUpdateTimestamp = dsbe.getLastUpdateTimestamp();
    if (lastUpdateTimestamp != null && System.currentTimeMillis() - lastUpdateTimestamp > ConfigIni.getInstance().getRegistrationValiditySb()) {
        LOG.warn("Restore threshold passed, not restoring operational datastore into DAO");
    } else {
        mappings.addAll(dsbe.getAllMappings(LogicalDatastoreType.OPERATIONAL));
    }
    dsbe.removeLastUpdateTimestamp();
    LOG.info("Restoring {} mappings and {} keys from datastore into DAO", mappings.size(), authKeys.size());
    for (Mapping mapping : mappings) {
        addMapping(mapping.getOrigin(), mapping.getMappingRecord().getEid(), new MappingData(mapping.getMappingRecord()));
    }
    for (AuthenticationKey authKey : authKeys) {
        addAuthenticationKey(authKey.getEid(), authKey.getMappingAuthkey());
    }
}
Also used : AuthenticationKey(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.AuthenticationKey) MappingData(org.opendaylight.lispflowmapping.lisp.type.MappingData) Mapping(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.Mapping)

Example 42 with MappingData

use of org.opendaylight.lispflowmapping.lisp.type.MappingData in project lispflowmapping by opendaylight.

the class MappingSystem method addNegativeMapping.

@Override
public MappingData addNegativeMapping(Eid key) {
    MappingRecord mapping = buildNegativeMapping(key);
    MappingData mappingData = new MappingData(mapping);
    LOG.debug("Adding negative mapping for EID {}", LispAddressStringifier.getString(mapping.getEid()));
    LOG.trace(mappingData.getString());
    smc.addMapping(mapping.getEid(), mappingData);
    dsbe.addMapping(DSBEInputUtil.toMapping(MappingOrigin.Southbound, mapping.getEid(), null, mappingData));
    return mappingData;
}
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)

Example 43 with MappingData

use of org.opendaylight.lispflowmapping.lisp.type.MappingData in project lispflowmapping by opendaylight.

the class MappingSystem method handleMergedMapping.

private MappingData handleMergedMapping(Eid key) {
    LOG.trace("Merging mappings for EID {}", LispAddressStringifier.getString(key));
    List<MappingData> expiredMappingDataList = new ArrayList<>();
    Set<IpAddressBinary> sourceRlocs = new HashSet<>();
    MappingData mergedMappingData = MappingMergeUtil.mergeXtrIdMappings(smc.getAllXtrIdMappings(key), expiredMappingDataList, sourceRlocs);
    for (MappingData mappingData : expiredMappingDataList) {
        removeSbXtrIdSpecificMapping(key, mappingData.getXtrId(), mappingData);
    }
    if (mergedMappingData != null) {
        smc.addMapping(key, mergedMappingData, sourceRlocs);
        dsbe.addMapping(DSBEInputUtil.toMapping(MappingOrigin.Southbound, key, mergedMappingData));
        addOrRefreshMappingInTimeoutService(key, mergedMappingData);
    } else {
        removeSbMapping(key, mergedMappingData);
    }
    return mergedMappingData;
}
Also used : IpAddressBinary(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.inet.binary.types.rev160303.IpAddressBinary) ArrayList(java.util.ArrayList) MappingData(org.opendaylight.lispflowmapping.lisp.type.MappingData) HashSet(java.util.HashSet)

Example 44 with MappingData

use of org.opendaylight.lispflowmapping.lisp.type.MappingData in project lispflowmapping by opendaylight.

the class MappingSystem method removeMapping.

@Override
public void removeMapping(MappingOrigin origin, Eid key) {
    Eid dstAddr = null;
    Set<Subscriber> subscribers = null;
    Set<Subscriber> dstSubscribers = null;
    MappingData mapping = (MappingData) tableMap.get(origin).getMapping(null, key);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Removing mapping for EID {} from {}", LispAddressStringifier.getString(key), origin);
    }
    if (LOG.isTraceEnabled() && mapping != null) {
        LOG.trace(mapping.getString());
    }
    MappingRecord notificationMapping = null;
    if (mapping != null) {
        notificationMapping = mapping.getRecord();
        subscribers = getSubscribers(key);
        // For SrcDst LCAF also send SMRs to Dst prefix
        if (key.getAddress() instanceof SourceDestKey) {
            dstAddr = SourceDestKeyHelper.getDstBinary(key);
            dstSubscribers = getSubscribers(dstAddr);
        }
    }
    removeSubscribersConditionally(origin, key);
    if (origin == MappingOrigin.Southbound) {
        removeFromSbTimeoutService(key);
    }
    if (origin == MappingOrigin.Southbound && mapping != null && mapping.isPositive().or(false)) {
        mergeNegativePrefixes(key);
    } else {
        // mergeNegativePrefixes() above removes the mapping, so addNegativeMapping() will work correctly
        tableMap.get(origin).removeMapping(key);
    }
    if (notificationMapping != null) {
        publishNotification(notificationMapping, key, subscribers, dstSubscribers, MappingChange.Removed);
        notifyChildren(key, notificationMapping, MappingChange.Removed);
        if (dstAddr != null) {
            notifyChildren(dstAddr, notificationMapping, MappingChange.Removed);
        }
    }
}
Also used : Eid(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid) Subscriber(org.opendaylight.lispflowmapping.interfaces.dao.Subscriber) MappingRecord(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord) SourceDestKey(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.SourceDestKey) MappingData(org.opendaylight.lispflowmapping.lisp.type.MappingData)

Example 45 with MappingData

use of org.opendaylight.lispflowmapping.lisp.type.MappingData in project lispflowmapping by opendaylight.

the class MappingSystem method updateServicePathMappingRecord.

private MappingData updateServicePathMappingRecord(MappingData mappingData, Eid eid) {
    // keep properties of original record
    MappingRecordBuilder recordBuilder = new MappingRecordBuilder(mappingData.getRecord());
    recordBuilder.setLocatorRecord(new ArrayList<LocatorRecord>());
    // there should only be one locator record
    if (mappingData.getRecord().getLocatorRecord().size() != 1) {
        LOG.warn("MappingRecord associated to ServicePath EID has more than one locator!");
        return mappingData;
    }
    LocatorRecord locatorRecord = mappingData.getRecord().getLocatorRecord().get(0);
    long serviceIndex = ((ServicePath) eid.getAddress()).getServicePath().getServiceIndex();
    int index = LispAddressUtil.STARTING_SERVICE_INDEX - (int) serviceIndex;
    Rloc rloc = locatorRecord.getRloc();
    if (rloc.getAddress() instanceof Ipv4 || rloc.getAddress() instanceof Ipv6) {
        if (index != 0) {
            LOG.warn("Service Index should be 255 for simple IP RLOCs!");
        }
        return mappingData;
    } else if (rloc.getAddress() instanceof ExplicitLocatorPath) {
        ExplicitLocatorPath elp = (ExplicitLocatorPath) rloc.getAddress();
        List<Hop> hops = elp.getExplicitLocatorPath().getHop();
        if (index < 0 || index > hops.size()) {
            LOG.warn("Service Index out of bounds!");
            return mappingData;
        }
        SimpleAddress nextHop = hops.get(index).getAddress();
        LocatorRecordBuilder lrb = new LocatorRecordBuilder(locatorRecord);
        lrb.setRloc(LispAddressUtil.toRloc(nextHop));
        recordBuilder.getLocatorRecord().add(lrb.build());
        return new MappingData(recordBuilder.build());
    } else {
        LOG.warn("Nothing to do with ServicePath mapping record");
        return mappingData;
    }
}
Also used : LocatorRecordBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecordBuilder) Ipv6(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6) MappingRecordBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecordBuilder) Ipv4(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4) Rloc(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.Rloc) LocatorRecord(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.locatorrecords.LocatorRecord) MappingData(org.opendaylight.lispflowmapping.lisp.type.MappingData) List(java.util.List) ArrayList(java.util.ArrayList) SimpleAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.SimpleAddress) ExplicitLocatorPath(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.ExplicitLocatorPath)

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