Search in sources :

Example 1 with MappingAuthkey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkey in project lispflowmapping by opendaylight.

the class AuthKeyDb method addAuthenticationKey.

@Override
public void addAuthenticationKey(Eid eid, MappingAuthkey authKey) {
    Eid key = MaskUtil.normalize(eid);
    ILispDAO table = getOrInstantiateVniTable(key);
    table.put(key, new MappingEntry<>(SubKeys.AUTH_KEY, authKey));
}
Also used : Eid(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid) ILispDAO(org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO)

Example 2 with MappingAuthkey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkey in project lispflowmapping by opendaylight.

the class AuthKeyDb method getAuthenticationKey.

/*
     * Retrieves authentication key from the database. As opposed to the mapping cache, Source/Dest keys are treated as
     * exact match keys here, and a two level longest prefix match is NOT performed.
     */
@Override
public MappingAuthkey getAuthenticationKey(Eid eid) {
    ILispDAO table = getVniTable(eid);
    if (table == null) {
        return null;
    }
    if (MaskUtil.isMaskable(eid.getAddress()) && !(eid.getAddress() instanceof SourceDestKey)) {
        return getAuthKeyLpm(eid, table);
    } else {
        Eid key = MaskUtil.normalize(eid);
        Object password = table.getSpecific(key, SubKeys.AUTH_KEY);
        if (password != null && password instanceof MappingAuthkey) {
            return (MappingAuthkey) password;
        } else {
            LOG.warn("Failed to find password!");
            return null;
        }
    }
}
Also used : Eid(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid) SourceDestKey(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.SourceDestKey) MappingAuthkey(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkey) ILispDAO(org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO)

Example 3 with MappingAuthkey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkey in project lispflowmapping by opendaylight.

the class LispSouthboundHandler method refreshAuthKeyIfNecessary.

private MapRegisterCacheValue refreshAuthKeyIfNecessary(MapRegisterCacheValue mapRegisterCacheValue) {
    final List<EidLispAddress> eids = mapRegisterCacheValue.getMapRegisterCacheMetadata().getEidLispAddress();
    if (lispSbPlugin.getAuthenticationKeyDataListener().authKeysForEidsUnchanged(eids, lispSbPlugin.getMapRegisterCacheTimeout())) {
        return mapRegisterCacheValue;
    }
    final MappingAuthkey mappingAuthkey = provideAuthenticateKey(eids);
    final MapRegisterCacheValueBuilder newMapRegisterCacheValueBuilder = new MapRegisterCacheValueBuilder(mapRegisterCacheValue);
    final MapRegisterCacheMetadataBuilder newMapRegisterCacheMetadataBuilder = new MapRegisterCacheMetadataBuilder(mapRegisterCacheValue.getMapRegisterCacheMetadata());
    newMapRegisterCacheValueBuilder.setMappingAuthkey(mappingAuthkey);
    newMapRegisterCacheValueBuilder.setMapRegisterCacheMetadata(newMapRegisterCacheMetadataBuilder.build());
    return newMapRegisterCacheValueBuilder.build();
}
Also used : MapRegisterCacheMetadataBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.map.register.cache.metadata.container.MapRegisterCacheMetadataBuilder) EidLispAddress(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.map.register.cache.metadata.container.map.register.cache.metadata.EidLispAddress) MappingAuthkey(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkey) MapRegisterCacheValueBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.map.register.cache.value.grouping.MapRegisterCacheValueBuilder)

Example 4 with MappingAuthkey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkey in project lispflowmapping by opendaylight.

the class LispSouthboundHandler method handleMapRegister.

@SuppressWarnings("checkstyle:IllegalCatch")
private void handleMapRegister(ByteBuffer inBuffer, InetAddress sourceAddress, int port) {
    try {
        Map.Entry<MapRegisterCacheKey, byte[]> artificialEntry = null;
        MapRegisterCacheKey cacheKey = null;
        MapRegisterCacheValue cacheValue = null;
        if (lispSbPlugin.isMapRegisterCacheEnabled()) {
            artificialEntry = MapRegisterPartialDeserializer.deserializePartially(inBuffer, sourceAddress);
            cacheKey = artificialEntry == null ? null : artificialEntry.getKey();
            cacheValue = resolveCacheValue(artificialEntry);
        }
        if (cacheValue != null) {
            lispSbPlugin.getStats().incrementCacheHits();
            MapRegisterCacheMetadata mapRegisterMeta = cacheValue.getMapRegisterCacheMetadata();
            LOG.debug("Map register message site-ID: {} xTR-ID: {} from cache.", mapRegisterMeta.getSiteId(), mapRegisterMeta.getXtrId());
            cacheValue = refreshEntry(cacheKey);
            if (cacheValue != null) {
                lispSbPlugin.sendNotificationIfPossible(createMappingKeepAlive(cacheValue));
                if (cacheValue.getMapRegisterCacheMetadata().isWantMapNotify()) {
                    sendMapNotifyMsg(inBuffer, sourceAddress, port, cacheValue);
                }
            }
        } else {
            lispSbPlugin.getStats().incrementCacheMisses();
            MapRegister mapRegister = MapRegisterSerializer.getInstance().deserialize(inBuffer, sourceAddress);
            MappingAuthkey mappingAuthkey = null;
            if (authenticationEnabled) {
                mappingAuthkey = tryToAuthenticateMessage(mapRegister, inBuffer);
                if (mappingAuthkey == null) {
                    return;
                }
            }
            AddMappingBuilder addMappingBuilder = new AddMappingBuilder();
            addMappingBuilder.setMapRegister(LispNotificationHelper.convertMapRegister(mapRegister));
            TransportAddressBuilder transportAddressBuilder = new TransportAddressBuilder();
            transportAddressBuilder.setIpAddress(LispNotificationHelper.getIpAddressBinaryFromInetAddress(sourceAddress));
            transportAddressBuilder.setPort(new PortNumber(port));
            addMappingBuilder.setTransportAddress(transportAddressBuilder.build());
            lispSbPlugin.sendNotificationIfPossible(addMappingBuilder.build());
            if (artificialEntry != null) {
                final MapRegisterCacheMetadataBuilder cacheMetadataBldNew = new MapRegisterCacheMetadataBuilder();
                cacheMetadataBldNew.setEidLispAddress(provideEidPrefixesFromMessage(mapRegister));
                cacheMetadataBldNew.setXtrId(mapRegister.getXtrId());
                cacheMetadataBldNew.setSiteId(mapRegister.getSiteId());
                cacheMetadataBldNew.setWantMapNotify(mapRegister.isWantMapNotify());
                cacheMetadataBldNew.setMergeEnabled(mapRegister.isMergeEnabled());
                cacheMetadataBldNew.setTimestamp(System.currentTimeMillis());
                final MapRegisterCacheValueBuilder cacheValueBldNew = new MapRegisterCacheValueBuilder();
                cacheValueBldNew.setPacketData(artificialEntry.getValue());
                cacheValueBldNew.setMappingAuthkey(mappingAuthkey);
                cacheValueBldNew.setMapRegisterCacheMetadata(cacheMetadataBldNew.build());
                lispSbPlugin.getMapRegisterCache().addEntry(cacheKey, cacheValueBldNew.build());
            }
        }
    } catch (RuntimeException re) {
        throw new LispMalformedPacketException("Couldn't deserialize Map-Register (len=" + inBuffer.capacity() + ")", re);
    } catch (InterruptedException e) {
        LOG.warn("Notification publication interrupted!");
    }
}
Also used : AddMappingBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.AddMappingBuilder) MapRegisterCacheKey(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.map.register.cache.key.container.MapRegisterCacheKey) MapRegisterCacheMetadataBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.map.register.cache.metadata.container.MapRegisterCacheMetadataBuilder) LispMalformedPacketException(org.opendaylight.lispflowmapping.southbound.lisp.exception.LispMalformedPacketException) MapRegisterCacheValue(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.map.register.cache.value.grouping.MapRegisterCacheValue) MapRegisterCacheMetadata(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.map.register.cache.metadata.container.MapRegisterCacheMetadata) MappingAuthkey(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkey) MapRegisterCacheValueBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.map.register.cache.value.grouping.MapRegisterCacheValueBuilder) MapRegister(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRegister) PortNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber) Map(java.util.Map) TransportAddressBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.transport.address.TransportAddressBuilder)

Example 5 with MappingAuthkey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkey in project lispflowmapping by opendaylight.

the class LispSouthboundHandler method tryToAuthenticateMessage.

/**
 * Checks whether authentication data is valid.
 *
 * <p>Methods pass through all records from map register message. For the EID of the first record it gets
 * authentication key and does validation of authentication data again this authentication key. If it pass
 * it just checks for remaining records (and its EID) whether they have the same authentication key stored in
 * the authentication key database.
 *
 * @return Returns authentication key if all of EIDs have the same authentication key or null otherwise
 */
private MappingAuthkey tryToAuthenticateMessage(final MapRegister mapRegister, final ByteBuffer byteBuffer) {
    if (lispSbPlugin.getAkdb() == null) {
        LOG.debug("Simple map cache wasn't instantieted and set.");
        return null;
    }
    MappingAuthkey firstAuthKey = null;
    final List<MappingRecordItem> mappingRecords = mapRegister.getMappingRecordItem();
    for (int i = 0; i < mappingRecords.size(); i++) {
        final MappingRecordItem recordItem = mappingRecords.get(i);
        final MappingRecord mappingRecord = recordItem.getMappingRecord();
        if (i == 0) {
            firstAuthKey = lispSbPlugin.getAkdb().getAuthenticationKey(mappingRecord.getEid());
            if (!LispAuthenticationUtil.validate(mapRegister, byteBuffer, mappingRecord.getEid(), firstAuthKey)) {
                return null;
            }
        } else {
            final Eid eid = mappingRecord.getEid();
            final MappingAuthkey authKey = lispSbPlugin.getAkdb().getAuthenticationKey(eid);
            if (!firstAuthKey.equals(authKey)) {
                LOG.debug("Map register packet contained several eids. Authentication keys for first one and for " + "{} are different.", LispAddressStringifier.getString(eid));
                return null;
            }
        }
    }
    return firstAuthKey;
}
Also used : Eid(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid) MappingRecordItem(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem) 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)

Aggregations

MappingAuthkey (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkey)16 Eid (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid)9 Test (org.junit.Test)6 MappingAuthkeyBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkeyBuilder)4 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)4 AddKeyInput (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.AddKeyInput)3 AddKeyInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.AddKeyInputBuilder)3 AuthenticationKeyBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.AuthenticationKeyBuilder)3 RpcError (org.opendaylight.yangtools.yang.common.RpcError)3 ILispDAO (org.opendaylight.lispflowmapping.interfaces.dao.ILispDAO)2 MappingData (org.opendaylight.lispflowmapping.lisp.type.MappingData)2 MapRegisterCacheMetadataBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.map.register.cache.metadata.container.MapRegisterCacheMetadataBuilder)2 MapRegisterCacheValueBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.map.register.cache.value.grouping.MapRegisterCacheValueBuilder)2 MappingRecord (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.container.MappingRecord)2 MappingRecordItem (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.record.list.MappingRecordItem)2 EidUri (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.EidUri)2 AuthenticationKey (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.mappingservice.rev150906.db.instance.AuthenticationKey)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1