use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.map.register.cache.metadata.container.MapRegisterCacheMetadataBuilder 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.map.register.cache.metadata.container.MapRegisterCacheMetadataBuilder 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.metadata.container.MapRegisterCacheMetadataBuilder in project lispflowmapping by opendaylight.
the class LispSouthboundHandlerTest method cacheRecordExpirationTest.
private void cacheRecordExpirationTest(boolean cacheRecordTimeouted) throws InterruptedException {
mapRegisterCache = Mockito.mock(MapRegisterCache.class);
Mockito.when(mockLispSouthboundPlugin.getMapRegisterCache()).thenReturn(mapRegisterCache);
final byte[] eidPrefixAfi = new byte[] { 0x00, 0x01 };
final byte[] eidPrefix = new byte[] { 0x0a, 0x0a, 0x0a, 0x0a };
MapRegisterCacheKeyBuilder cacheKeyBld = new MapRegisterCacheKeyBuilder();
cacheKeyBld.setXtrId(XTR_ID);
cacheKeyBld.setEidPrefix(eidPrefix);
cacheKeyBld.setSiteId(SITE_ID);
MapRegisterCacheMetadataBuilder cacheMetadataBld = new MapRegisterCacheMetadataBuilder();
cacheMetadataBld.setTimestamp(System.currentTimeMillis() - (cacheRecordTimeouted ? CACHE_RECORD_TIMEOUT : 0L));
cacheMetadataBld.setWantMapNotify(false);
MapRegisterCacheValueBuilder cacheValueBld = new MapRegisterCacheValueBuilder();
cacheValueBld.setMapRegisterCacheMetadata(cacheMetadataBld.build());
cacheValueBld.setPacketData(MapRegisterCacheTestUtil.joinArrays(DATA1, KEY_ID, DATA2, eidPrefixAfi, eidPrefix, DATA3, XTR_ID, SITE_ID));
final MapRegisterCacheKey cacheKey = cacheKeyBld.build();
final MapRegisterCacheValue cacheValue = cacheValueBld.build();
Mockito.when(mapRegisterCache.getEntry(Mockito.eq(cacheKey))).thenReturn(cacheRecordTimeouted ? null : cacheValue);
Mockito.when(mapRegisterCache.refreshEntry(Mockito.eq(cacheKey))).thenReturn(cacheValue);
mapRegisterInvocationForCacheTest(eidPrefixAfi, eidPrefix);
Mockito.verify(mockLispSouthboundPlugin, Mockito.atLeastOnce()).sendNotificationIfPossible(Mockito.any(AddMapping.class));
InOrder inOrder = Mockito.inOrder(mapRegisterCache);
inOrder.verify(mapRegisterCache).getEntry(Mockito.eq(cacheKey));
if (cacheRecordTimeouted) {
inOrder.verify(mapRegisterCache).addEntry(Mockito.eq(cacheKey), AdditionalMatchers.not(Mockito.eq(cacheValue)));
} else {
inOrder.verify(mapRegisterCache).refreshEntry(Mockito.eq(cacheKey));
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.map.register.cache.metadata.container.MapRegisterCacheMetadataBuilder in project lispflowmapping by opendaylight.
the class MapRegisterCache method refreshEntry.
public synchronized MapRegisterCacheValue refreshEntry(final MapRegisterCacheKey mapRegisterCacheKey) {
final MapRegisterCacheValue mapRegisterCacheValueOld = getEntry(mapRegisterCacheKey);
final MapRegisterCacheMetadata mapRegisterCacheMetadataOld = mapRegisterCacheValueOld.getMapRegisterCacheMetadata();
final MapRegisterCacheMetadataBuilder mapRegisterCacheMetadataBuilderNew = new MapRegisterCacheMetadataBuilder(mapRegisterCacheMetadataOld);
mapRegisterCacheMetadataBuilderNew.setTimestamp(System.currentTimeMillis());
final MapRegisterCacheValueBuilder mapRegisterCacheValueBuilderNew = new MapRegisterCacheValueBuilder();
mapRegisterCacheValueBuilderNew.setPacketData(mapRegisterCacheValueOld.getPacketData());
mapRegisterCacheValueBuilderNew.setMappingAuthkey(mapRegisterCacheValueOld.getMappingAuthkey());
mapRegisterCacheValueBuilderNew.setMapRegisterCacheMetadata(mapRegisterCacheMetadataBuilderNew.build());
return mapRegisterCacheValueBuilderNew.build();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.map.register.cache.metadata.container.MapRegisterCacheMetadataBuilder in project lispflowmapping by opendaylight.
the class LispMappingServiceTest method getDefaultMapRegisterCacheMetadata.
private static MapRegisterCacheMetadata getDefaultMapRegisterCacheMetadata() {
final EidLispAddress eidLispAddress_1 = new EidLispAddressBuilder().setEidLispAddressId("id-1").setEid(IPV4_EID_1).build();
final EidLispAddress eidLispAddress_2 = new EidLispAddressBuilder().setEidLispAddressId("id-2").setEid(IPV4_EID_2).build();
return new MapRegisterCacheMetadataBuilder().setEidLispAddress(Lists.newArrayList(eidLispAddress_1, eidLispAddress_2)).setTimestamp(TIMESTAMP).build();
}
Aggregations