use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.map.register.cache.key.container.MapRegisterCacheKey in project lispflowmapping by opendaylight.
the class LispSouthboundHandler method resolveCacheValue.
private MapRegisterCacheValue resolveCacheValue(Map.Entry<MapRegisterCacheKey, byte[]> entry) {
if (entry != null) {
final MapRegisterCacheValue mapRegisterCacheValue = lispSbPlugin.getMapRegisterCache().getEntry(entry.getKey());
if (mapRegisterCacheValue != null) {
final long creationTime = mapRegisterCacheValue.getMapRegisterCacheMetadata().getTimestamp();
final long currentTime = System.currentTimeMillis();
if (currentTime - creationTime > lispSbPlugin.getMapRegisterCacheTimeout()) {
lispSbPlugin.getMapRegisterCache().removeEntry(entry.getKey());
return null;
} else if (Arrays.equals(mapRegisterCacheValue.getPacketData(), entry.getValue())) {
return mapRegisterCacheValue;
}
}
}
return null;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.map.register.cache.key.container.MapRegisterCacheKey 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.map.register.cache.key.container.MapRegisterCacheKey in project lispflowmapping by opendaylight.
the class MapRegisterPartialDeserializer method deserializePartially.
public static Map.Entry<MapRegisterCacheKey, byte[]> deserializePartially(final ByteBuffer buffer, final InetAddress sourceRloc) {
final byte thirdByte = buffer.get(2);
// if merge bit is set to 1, not store to cache.
final boolean isMergeBitSet = ByteUtil.extractBit(thirdByte, MERGE_ENABLED_BIT_POSITION);
if (isMergeBitSet) {
return null;
}
final int authDataLength = ByteUtil.getUnsignedShort(buffer, NUM_OF_BYTES_FROM_START_TO_AUTH_DATA_LENGTH_POS);
MapRegisterCacheKey mapRegisterCacheKey = createKeyFromBytes(buffer, authDataLength);
if (mapRegisterCacheKey == null) {
return null;
}
final byte[] relevantPayloadData = createValueFromBytes(buffer, authDataLength);
buffer.position(0);
return new HashMap.SimpleEntry<>(mapRegisterCacheKey, relevantPayloadData);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.map.register.cache.key.container.MapRegisterCacheKey in project lispflowmapping by opendaylight.
the class MapRegisterPartialDeserializer method createKeyFromBytes.
private static MapRegisterCacheKey createKeyFromBytes(final ByteBuffer buffer, int authDataLength) {
byte typeAndFlags = buffer.get();
buffer.position(0);
boolean xtrSiteIdPresent = ByteUtil.extractBit(typeAndFlags, XTR_SITE_ID);
if (!xtrSiteIdPresent) {
return null;
}
final MapRegisterCacheKeyBuilder mapRegisterCacheKeyBuilder = new MapRegisterCacheKeyBuilder();
final byte[] eidPrefix = extractEidPrefix(buffer, authDataLength);
if (eidPrefix == null) {
return null;
}
mapRegisterCacheKeyBuilder.setEidPrefix(eidPrefix);
if (xtrSiteIdPresent) {
buffer.position(0);
final int bufferLength = buffer.remaining();
buffer.position(bufferLength - MapRegisterSerializer.Length.XTRID_SIZE - MapRegisterSerializer.Length.SITEID_SIZE);
byte[] xtrId = new byte[MapRegisterSerializer.Length.XTRID_SIZE];
buffer.get(xtrId);
mapRegisterCacheKeyBuilder.setXtrId(xtrId);
byte[] siteId = new byte[MapRegisterSerializer.Length.SITEID_SIZE];
buffer.get(siteId);
mapRegisterCacheKeyBuilder.setSiteId(siteId);
}
return mapRegisterCacheKeyBuilder.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.map.register.cache.key.container.MapRegisterCacheKey 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);
}
Aggregations