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 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.lfm.lisp.proto.rev151105.map.register.cache.key.container.MapRegisterCacheKey in project lispflowmapping by opendaylight.
the class MapRegisterCacheTestUtil method afterMapRegisterInvocationValidation.
static void afterMapRegisterInvocationValidation(final MapRegisterCacheKey mapRegisterCacheKey, final MapRegisterCache mapRegisterCache, final byte[] eidPrefixAfi, byte[] eidPrefix) throws InterruptedException {
Assert.assertEquals(1, mapRegisterCache.cacheSize());
final MapRegisterCacheValue currentMapRegisterCacheValue = mapRegisterCache.getEntry(mapRegisterCacheKey);
Assert.assertNotNull(currentMapRegisterCacheValue);
final byte[] currentMapRegisterMsg = currentMapRegisterCacheValue.getPacketData();
final byte[] expectedMapRegisterMsg = joinArrays(DATA1, KEY_ID, DATA2, eidPrefixAfi, eidPrefix, DATA3, XTR_ID, SITE_ID);
Assert.assertArrayEquals(expectedMapRegisterMsg, currentMapRegisterMsg);
}
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 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.key.container.MapRegisterCacheKey in project lispflowmapping by opendaylight.
the class MapRegisterCacheTestUtil method createMapRegisterCacheKey.
static MapRegisterCacheKey createMapRegisterCacheKey(final byte[] eidPrefix) {
final MapRegisterCacheKeyBuilder mapRegisterCacheKeyBuilder = new MapRegisterCacheKeyBuilder();
mapRegisterCacheKeyBuilder.setXtrId(XTR_ID);
mapRegisterCacheKeyBuilder.setSiteId(SITE_ID);
mapRegisterCacheKeyBuilder.setEidPrefix(eidPrefix);
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 LispSouthboundHandler method refreshEntry.
private MapRegisterCacheValue refreshEntry(final MapRegisterCacheKey cacheKey) {
MapRegisterCacheValue mapRegisterCacheValue = lispSbPlugin.getMapRegisterCache().refreshEntry(cacheKey);
if (mapRegisterCacheValue != null) {
mapRegisterCacheValue = refreshAuthKeyIfNecessary(mapRegisterCacheValue);
lispSbPlugin.getMapRegisterCache().addEntry(cacheKey, mapRegisterCacheValue);
return mapRegisterCacheValue;
}
return null;
}
Aggregations