use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.add.bundle.messages.input.messages.Message 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.openflowplugin.extension.onf.bundle.service.rev170124.add.bundle.messages.input.messages.Message 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;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.add.bundle.messages.input.messages.Message in project lispflowmapping by opendaylight.
the class LispSouthboundHandlerTest method cacheTest.
/**
* It tests whether map register message is stored to local cache.
*/
public void cacheTest(byte[] eidPrefixAfi, byte[] eidPrefix, byte[] authenticationData) throws InterruptedException {
final MapRegisterCacheKey mapRegisterCacheKey = MapRegisterCacheTestUtil.createMapRegisterCacheKey(eidPrefix);
MapRegisterCacheTestUtil.beforeMapRegisterInvocationValidation(mapRegisterCacheKey, mapRegisterCache);
ArgumentCaptor<AddMapping> captor = ArgumentCaptor.forClass(AddMapping.class);
mapRegisterInvocationForCacheTest(eidPrefixAfi, eidPrefix, authenticationData);
Mockito.verify(mockLispSouthboundPlugin).sendNotificationIfPossible(captor.capture());
MapRegisterCacheTestUtil.afterMapRegisterInvocationValidation(mapRegisterCacheKey, mapRegisterCache, eidPrefixAfi, eidPrefix);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.add.bundle.messages.input.messages.Message in project lispflowmapping by opendaylight.
the class LispSouthboundHandlerTest method mapRegister_isMappingKeepAliveAndMapNotifyGenerated.
/**
* Tests whether handling of map-register message will generate mapping-keep-alive notification.
*/
@Test
public void mapRegister_isMappingKeepAliveAndMapNotifyGenerated() throws InterruptedException, UnknownHostException {
byte[] eidPrefixAfi = new byte[] { // eid-prefix-afi
0x00, 0x01 };
byte[] eidPrefix = new byte[] { // ipv4 address
0x0a, 0x0a, 0x0a, 0x0a };
// send stream of byte -> map register message
InOrder inOrder = Mockito.inOrder(mockLispSouthboundPlugin);
final MapRegisterCacheKey cacheKey = MapRegisterCacheTestUtil.createMapRegisterCacheKey(eidPrefix);
MapRegisterCacheTestUtil.beforeMapRegisterInvocationValidation(cacheKey, mapRegisterCache);
ArgumentCaptor<AddMapping> captor = ArgumentCaptor.forClass(AddMapping.class);
mapRegisterInvocationForCacheTest(eidPrefixAfi, eidPrefix);
inOrder.verify(mockLispSouthboundPlugin).sendNotificationIfPossible(captor.capture());
MapRegisterCacheTestUtil.afterMapRegisterInvocationValidation(cacheKey, mapRegisterCache, eidPrefixAfi, eidPrefix);
// sending the same byte stream -> map register second time
captor = ArgumentCaptor.forClass(AddMapping.class);
mapRegisterInvocationForCacheTest(eidPrefixAfi, eidPrefix);
inOrder.verify(mockLispSouthboundPlugin).sendNotificationIfPossible(captor.capture());
// mapping-keep-alive message should be generated
MapRegisterCacheTestUtil.afterSecondMapRegisterInvocationValidation(mockLispSouthboundPlugin, eidPrefixAfi, eidPrefix);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.add.bundle.messages.input.messages.Message in project lispflowmapping by opendaylight.
the class MappingService method addKey.
@Override
public Future<RpcResult<Void>> addKey(AddKeyInput input) {
Preconditions.checkNotNull(input, "add-key RPC input must be not null!");
LOG.trace("RPC received to add the following key: " + input.toString());
RpcResultBuilder<Void> rpcResultBuilder;
MappingAuthkey key = mappingSystem.getAuthenticationKey(convertToBinaryIfNecessary(input.getEid()));
if (key != null) {
String message = "Key already exists! Please use update-key if you want to change it.";
rpcResultBuilder = RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.PROTOCOL, DATA_EXISTS_TAG, message);
return Futures.immediateFuture(rpcResultBuilder.build());
}
dsbe.addAuthenticationKey(RPCInputConvertorUtil.toAuthenticationKey(input));
rpcResultBuilder = RpcResultBuilder.success();
return Futures.immediateFuture(rpcResultBuilder.build());
}
Aggregations