Search in sources :

Example 6 with MapRegisterCacheKey

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);
}
Also used : InOrder(org.mockito.InOrder) MapRegisterCacheKey(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.map.register.cache.key.container.MapRegisterCacheKey) AddMapping(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.AddMapping) Test(org.junit.Test)

Example 7 with MapRegisterCacheKey

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);
}
Also used : MapRegisterCacheValue(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.map.register.cache.value.grouping.MapRegisterCacheValue)

Example 8 with MapRegisterCacheKey

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));
    }
}
Also used : MapRegisterCacheKeyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.map.register.cache.key.container.MapRegisterCacheKeyBuilder) MapRegisterCacheKey(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.map.register.cache.key.container.MapRegisterCacheKey) InOrder(org.mockito.InOrder) MapRegisterCacheMetadataBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.map.register.cache.metadata.container.MapRegisterCacheMetadataBuilder) AddMapping(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.AddMapping) MapRegisterCacheValueBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.map.register.cache.value.grouping.MapRegisterCacheValueBuilder) MapRegisterCache(org.opendaylight.lispflowmapping.southbound.lisp.cache.MapRegisterCache) MapRegisterCacheValue(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.map.register.cache.value.grouping.MapRegisterCacheValue)

Example 9 with MapRegisterCacheKey

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();
}
Also used : MapRegisterCacheKeyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.map.register.cache.key.container.MapRegisterCacheKeyBuilder)

Example 10 with MapRegisterCacheKey

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;
}
Also used : MapRegisterCacheValue(org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.map.register.cache.value.grouping.MapRegisterCacheValue)

Aggregations

MapRegisterCacheValue (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.map.register.cache.value.grouping.MapRegisterCacheValue)6 MapRegisterCacheKey (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.map.register.cache.key.container.MapRegisterCacheKey)5 AddMapping (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.AddMapping)3 MapRegisterCacheKeyBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.map.register.cache.key.container.MapRegisterCacheKeyBuilder)3 MapRegisterCacheMetadataBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.map.register.cache.metadata.container.MapRegisterCacheMetadataBuilder)3 MapRegisterCacheValueBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.map.register.cache.value.grouping.MapRegisterCacheValueBuilder)3 InOrder (org.mockito.InOrder)2 MapRegisterCacheMetadata (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.map.register.cache.metadata.container.MapRegisterCacheMetadata)2 Map (java.util.Map)1 Test (org.junit.Test)1 MapRegisterCache (org.opendaylight.lispflowmapping.southbound.lisp.cache.MapRegisterCache)1 LispMalformedPacketException (org.opendaylight.lispflowmapping.southbound.lisp.exception.LispMalformedPacketException)1 PortNumber (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber)1 AddMappingBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.AddMappingBuilder)1 MapRegister (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRegister)1 MappingAuthkey (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.mapping.authkey.container.MappingAuthkey)1 TransportAddressBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.transport.address.TransportAddressBuilder)1