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));
}
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;
}
}
}
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();
}
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!");
}
}
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;
}
Aggregations