diff options
author | Jan Srnicek <jsrnicek@cisco.com> | 2016-10-04 16:44:47 +0200 |
---|---|---|
committer | Maros Marsalek <mmarsale@cisco.com> | 2016-10-05 11:52:37 +0000 |
commit | 6e92b4740d62b5977590f8a247b08eb945b9e5b7 (patch) | |
tree | 366c1f8536528637d58ba55088b3a3c90b522283 /lisp/lisp2vpp/src/test/java/io/fd | |
parent | 4cd8aad5217a5225a2a33b448478dd81548e38b1 (diff) |
HONEYCOMB-138 - Lisp L2 Support
Change-Id: Idff4776a64a88be2e0a45ab1927978e40876ea92
Signed-off-by: Jan Srnicek <jsrnicek@cisco.com>
Diffstat (limited to 'lisp/lisp2vpp/src/test/java/io/fd')
27 files changed, 1637 insertions, 206 deletions
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/LispModuleTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/LispModuleTest.java index 76cebc882..6d1e05ce8 100644 --- a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/LispModuleTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/LispModuleTest.java @@ -47,6 +47,10 @@ public class LispModuleTest { @Bind private NamingContext interfaceContext; + @Named("bridge-domain-context") + @Bind + private NamingContext bridgeDomainContext; + @Named("honeycomb-context") @Bind @Mock @@ -71,6 +75,7 @@ public class LispModuleTest { public void setUp() throws Exception { initMocks(this); interfaceContext = new NamingContext("interfaceContext", "interfaceContext"); + bridgeDomainContext = new NamingContext("bridgeDomainContext", "bridgeDomainContext"); Guice.createInjector(new LispModule(), BoundFieldModule.of(this)).injectMembers(this); } diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/context/util/EidMappingContextTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/context/util/EidMappingContextTest.java index 710477a70..1691a9e87 100644 --- a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/context/util/EidMappingContextTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/context/util/EidMappingContextTest.java @@ -19,62 +19,76 @@ package io.fd.honeycomb.lisp.context.util; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.when; -import com.google.common.base.Optional; +import io.fd.honeycomb.lisp.util.EidMappingContextHelper; import io.fd.honeycomb.translate.MappingContext; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; -import org.mockito.Mockito; import org.mockito.MockitoAnnotations; -import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.eid.mapping.context.mappings.MappingBuilder; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Builder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.MappingId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.local.mappings.local.mapping.Eid; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.local.mappings.local.mapping.EidBuilder; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.local.mapping.Eid; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.local.mapping.EidBuilder; -public class EidMappingContextTest { +public class EidMappingContextTest implements EidMappingContextHelper { - private EidMappingContext eidMappingContext; + private static final String EID_MAPPING_CONTEXT_NAME = "eidMappingContext"; @Mock private MappingContext mappingContext; + private EidMappingContext eidMappingContext; + private Eid localEid; + private org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.Eid + remoteEid; + private org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.eid.mapping.context.mappings.mapping.Eid + mappingEid; + private MappingId mappingId; + @Before public void init() { MockitoAnnotations.initMocks(this); - eidMappingContext = new EidMappingContext("eid-eidMappingContext"); - } + eidMappingContext = new EidMappingContext(EID_MAPPING_CONTEXT_NAME); - @Test - public void testStoreAndGet() { - Eid eid = + localEid = new EidBuilder().setAddress(new Ipv4Builder().setIpv4(new Ipv4Address("192.168.2.1")).build()).build(); - MappingId id = new MappingId("first"); - - eidMappingContext.addEid(id, eid, mappingContext); - when(mappingContext.read(Mockito.any(InstanceIdentifier.class))) - .thenReturn(Optional.of( - new MappingBuilder().setId(id).setEid(copyEid(eid)).build() - )); + remoteEid = fromLocalToRemoteEid(localEid); + mappingEid = fromLocalToMappingEid(localEid); + mappingId = new MappingId("mapping"); - Eid sameEid = - new EidBuilder().setAddress(new Ipv4Builder().setIpv4(new Ipv4Address("192.168.2.1")).build()).build(); - MappingId sameId = new MappingId("first"); - - assertTrue(eidMappingContext.containsEid(sameId, mappingContext)); + defineMapping(mappingContext, mappingEid, mappingId, EID_MAPPING_CONTEXT_NAME); + } + @Test + public void testContainsEid() { + assertTrue(eidMappingContext.containsEid(mappingId, mappingContext)); org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.eid.mapping.context.mappings.mapping.Eid - loadedEid = eidMappingContext.getEid(sameId, mappingContext); + loadedEid = eidMappingContext.getEid(mappingId, mappingContext); assertEquals("192.168.2.1", ((Ipv4) (loadedEid.getAddress())).getIpv4().getValue()); } - private org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.eid.mapping.context.mappings.mapping.Eid copyEid( + @Test + public void testContainsId() { + assertTrue(eidMappingContext.containsId(localEid, mappingContext)); + assertTrue(eidMappingContext.containsId(remoteEid, mappingContext)); + } + + @Test + public void testGetEid() { + assertEquals(mappingEid, eidMappingContext.getEid(mappingId, mappingContext)); + } + + @Test + public void testGetId() { + assertEquals(mappingId, eidMappingContext.getId(localEid, mappingContext)); + assertEquals(mappingId, eidMappingContext.getId(remoteEid, mappingContext)); + } + + private org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.eid.mapping.context.mappings.mapping.Eid fromLocalToMappingEid( Eid eid) { return new org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.eid.mapping.context.mappings.mapping.EidBuilder() .setAddress(eid.getAddress()) @@ -82,4 +96,13 @@ public class EidMappingContextTest { .setVirtualNetworkId(eid.getVirtualNetworkId()) .build(); } + + private org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.Eid fromLocalToRemoteEid( + Eid eid) { + return new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.EidBuilder() + .setAddress(eid.getAddress()) + .setAddressType(eid.getAddressType()) + .setVirtualNetworkId(eid.getVirtualNetworkId()) + .build(); + } } diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/initializers/LispInitializerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/initializers/LispInitializerTest.java index 087f2cdee..4da6593e0 100644 --- a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/initializers/LispInitializerTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/initializers/LispInitializerTest.java @@ -9,10 +9,7 @@ import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.Lisp; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.LispState; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.LispStateBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.EidTableBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.locator.sets.grouping.LocatorSetsBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.map.resolvers.grouping.MapResolversBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.pitr.cfg.grouping.PitrCfgBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.lisp.feature.data.grouping.LispFeatureDataBuilder; public class LispInitializerTest { @@ -22,21 +19,14 @@ public class LispInitializerTest { final LispInitializer initializer = new LispInitializer(mock(DataBroker.class)); final LispState state = new LispStateBuilder() .setEnable(true) - .setEidTable(new EidTableBuilder().build()) - .setLocatorSets(new LocatorSetsBuilder().build()) - .setMapResolvers(new MapResolversBuilder().build()) - .setPitrCfg(new PitrCfgBuilder().build()) + .setLispFeatureData(new LispFeatureDataBuilder().build()) .build(); final Lisp operational = initializer.convert(state); assertNotNull(operational); - assertEquals(operational.getPitrCfg(), state.getPitrCfg()); assertEquals(operational.isEnable(), state.isEnable()); - assertEquals(operational.getEidTable(), state.getEidTable()); - assertEquals(operational.getLocatorSets(), state.getLocatorSets()); - assertEquals(operational.getMapResolvers(), state.getMapResolvers()); - + assertEquals(operational.getLispFeatureData(), state.getLispFeatureData()); } }
\ No newline at end of file diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/AdjacencyCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/AdjacencyCustomizerTest.java index 0a88f946c..861fff67c 100644 --- a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/AdjacencyCustomizerTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/AdjacencyCustomizerTest.java @@ -7,10 +7,10 @@ import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; import io.fd.honeycomb.vpp.test.read.ListReaderCustomizerTest; import org.junit.Before; import org.junit.Test; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.AdjacenciesBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.adjacencies.Adjacency; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.adjacencies.AdjacencyBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.adjacencies.AdjacencyKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.adjacencies.grouping.AdjacenciesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.adjacencies.grouping.adjacencies.Adjacency; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.adjacencies.grouping.adjacencies.AdjacencyBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.adjacencies.grouping.adjacencies.AdjacencyKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/BridgeDomainSubtableCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/BridgeDomainSubtableCustomizerTest.java new file mode 100644 index 000000000..5902028fe --- /dev/null +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/BridgeDomainSubtableCustomizerTest.java @@ -0,0 +1,104 @@ +package io.fd.honeycomb.lisp.translate.read; + + +import static io.fd.honeycomb.lisp.translate.read.dump.executor.params.SubtableDumpParams.MapLevel.L2; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import io.fd.honeycomb.lisp.translate.read.trait.SubtableReaderTestCase; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.i.DumpCallFailedException; +import io.fd.honeycomb.translate.vpp.util.NamingContext; +import io.fd.vpp.jvpp.VppCallbackException; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.EidTable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTableBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTableKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.BridgeDomainSubtable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.BridgeDomainSubtableBuilder; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class BridgeDomainSubtableCustomizerTest + extends SubtableReaderTestCase<BridgeDomainSubtable, BridgeDomainSubtableBuilder> { + + private InstanceIdentifier<BridgeDomainSubtable> validId; + private NamingContext bridgeDomainContext; + + public BridgeDomainSubtableCustomizerTest() { + super(BridgeDomainSubtable.class, VniTableBuilder.class); + } + + @Override + protected void setUp() throws Exception { + bridgeDomainContext = new NamingContext("br", "br-domain-context"); + validId = InstanceIdentifier.create(EidTable.class).child(VniTable.class, new VniTableKey(expectedVni)) + .child(BridgeDomainSubtable.class); + + defineMapping(mappingContext, "br-domain", expectedTableId, "br-domain-context"); + } + + @Test + public void testReadCurrentSuccessfull() throws ReadFailedException { + doReturnValidNonEmptyDataOnDump(); + BridgeDomainSubtableBuilder builder = new BridgeDomainSubtableBuilder(); + customizer.readCurrentAttributes(validId, builder, ctx); + + verifyLispEidTableMapDumpCalled(L2); + + final BridgeDomainSubtable subtable = builder.build(); + assertNotNull(subtable); + assertEquals("br-domain", subtable.getBridgeDomainRef()); + } + + + @Test + public void testReadCurrentEmptyDump() throws ReadFailedException { + doReturnEmptyDataOnDump(); + BridgeDomainSubtableBuilder builder = new BridgeDomainSubtableBuilder(); + customizer.readCurrentAttributes(validId, builder, ctx); + + verifyLispEidTableMapDumpCalled(L2); + + final BridgeDomainSubtable subtable = builder.build(); + assertNotNull(subtable); + assertNull(subtable.getBridgeDomainRef()); + } + + @Test + public void testReadCurrentFailed() { + doThrowOnDump(); + BridgeDomainSubtableBuilder builder = new BridgeDomainSubtableBuilder(); + try { + customizer.readCurrentAttributes(validId, builder, ctx); + } catch (ReadFailedException e) { + assertTrue(e.getCause() instanceof DumpCallFailedException); + assertTrue(e.getCause().getCause() instanceof VppCallbackException); + assertNull(builder.getBridgeDomainRef()); + verifyLispEidTableMapDumpNotCalled(); + + return; + } + + fail("Test should throw ReadFailedException"); + } + + @Test + public void testGetBuilder() { + final BridgeDomainSubtableBuilder builder = customizer.getBuilder(validId); + + assertNotNull(builder); + assertNull(builder.getLocalMappings()); + assertNull(builder.getRemoteMappings()); + assertNull(builder.getBridgeDomainRef()); + } + + @Override + protected ReaderCustomizer<BridgeDomainSubtable, BridgeDomainSubtableBuilder> initCustomizer() { + return new BridgeDomainSubtableCustomizer(api, bridgeDomainContext); + } +} diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/ItrRemoteLocatorSetCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/ItrRemoteLocatorSetCustomizerTest.java new file mode 100644 index 000000000..a1688ae35 --- /dev/null +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/ItrRemoteLocatorSetCustomizerTest.java @@ -0,0 +1,150 @@ +package io.fd.honeycomb.lisp.translate.read; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.i.DumpCallFailedException; +import io.fd.honeycomb.vpp.test.read.ReaderCustomizerTest; +import io.fd.vpp.jvpp.VppCallbackException; +import io.fd.vpp.jvpp.core.dto.LispGetMapRequestItrRlocs; +import io.fd.vpp.jvpp.core.dto.LispGetMapRequestItrRlocsReply; +import java.nio.charset.StandardCharsets; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import org.junit.Before; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.itr.remote.locator.sets.grouping.ItrRemoteLocatorSet; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.itr.remote.locator.sets.grouping.ItrRemoteLocatorSetBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.lisp.feature.data.grouping.LispFeatureDataBuilder; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + + +public class ItrRemoteLocatorSetCustomizerTest + extends ReaderCustomizerTest<ItrRemoteLocatorSet, ItrRemoteLocatorSetBuilder> { + + private static final String EXPECTED_LOCATOR_SET_NAME = "loc-set"; + + private InstanceIdentifier<ItrRemoteLocatorSet> validId; + private ItrRemoteLocatorSetBuilder builder; + + public ItrRemoteLocatorSetCustomizerTest() { + super(ItrRemoteLocatorSet.class, LispFeatureDataBuilder.class); + } + + @Before + public void setUp() throws Exception { + validId = InstanceIdentifier.create(ItrRemoteLocatorSet.class); + builder = new ItrRemoteLocatorSetBuilder(); + } + + @Override + protected ReaderCustomizer<ItrRemoteLocatorSet, ItrRemoteLocatorSetBuilder> initCustomizer() { + return new ItrRemoteLocatorSetCustomizer(api); + } + + @Test + public void getBuilder() throws Exception { + final ItrRemoteLocatorSetBuilder itrRemoteLocatorSetBuilder = getCustomizer().getBuilder(validId); + + assertNotNull(itrRemoteLocatorSetBuilder); + assertNull(itrRemoteLocatorSetBuilder.getRemoteLocatorSetName()); + } + + @Test + public void readCurrentAttributesSuccess() throws Exception { + doReturnValidDataOnDump(); + + getCustomizer().readCurrentAttributes(validId, builder, ctx); + + assertNotNull(builder); + assertEquals(EXPECTED_LOCATOR_SET_NAME, builder.getRemoteLocatorSetName()); + verifyLispGetMapRequestItrRlocsInvokedOnce(); + } + + @Test + public void readCurrentAttributesEmptyData() throws Exception { + doReturnEmptyDataOnDump(); + getCustomizer().readCurrentAttributes(validId, builder, ctx); + verifyInvalidDataCase(builder); + } + + @Test + public void readCurrentAttributesFailedCallHalted() { + doThrowExceptionOnDump(); + try { + getCustomizer().readCurrentAttributes(validId, builder, ctx); + } catch (ReadFailedException e) { + assertTrue(e.getCause() instanceof DumpCallFailedException); + assertTrue(e.getCause().getCause() instanceof VppCallbackException); + assertNotNull(builder); + assertNull(builder.getRemoteLocatorSetName()); + + verifyLispGetMapRequestItrRlocsInvokedOnce(); + return; + } + + fail("Test should have thrown exception"); + } + + @Test + public void merge() throws Exception { + LispFeatureDataBuilder builder = new LispFeatureDataBuilder(); + ItrRemoteLocatorSet set = new ItrRemoteLocatorSetBuilder().setRemoteLocatorSetName("loc-set").build(); + getCustomizer().merge(builder, set); + + assertNotNull(builder); + assertEquals(set, builder.getItrRemoteLocatorSet()); + } + + + private void doReturnValidDataOnDump() { + LispGetMapRequestItrRlocsReply reply = new LispGetMapRequestItrRlocsReply(); + reply.locatorSetName = EXPECTED_LOCATOR_SET_NAME.getBytes(StandardCharsets.UTF_8); + + when(api.lispGetMapRequestItrRlocs(any(LispGetMapRequestItrRlocs.class))) + .thenReturn(CompletableFuture.completedFuture(reply)); + } + + private void doReturnNullDataOnDump() { + when(api.lispGetMapRequestItrRlocs(any(LispGetMapRequestItrRlocs.class))) + .thenReturn(CompletableFuture.completedFuture(null)); + } + + private void doReturnEmptyDataOnDump() { + when(api.lispGetMapRequestItrRlocs(any(LispGetMapRequestItrRlocs.class))) + .thenReturn(CompletableFuture.completedFuture(new LispGetMapRequestItrRlocsReply())); + } + + private void doThrowExceptionOnDump() { + when(api.lispGetMapRequestItrRlocs(any(LispGetMapRequestItrRlocs.class))). + thenReturn(new CompletableFuture<LispGetMapRequestItrRlocsReply>() { + @Override + public LispGetMapRequestItrRlocsReply get(final long l, final TimeUnit timeUnit) + throws InterruptedException, ExecutionException, TimeoutException { + throw new ExecutionException(new VppCallbackException("lispGetMapRequestItrRlocs", 1, -2)); + } + }); + } + + private void verifyLispGetMapRequestItrRlocsInvokedOnce() { + verify(api, times(1)).lispGetMapRequestItrRlocs(any(LispGetMapRequestItrRlocs.class)); + } + + private void verifyInvalidDataCase(final ItrRemoteLocatorSetBuilder builder) { + assertNotNull(builder); + assertNull(builder.getRemoteLocatorSetName()); + + verifyLispGetMapRequestItrRlocsInvokedOnce(); + } +}
\ No newline at end of file diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/LocalMappingCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/LocalMappingCustomizerTest.java index 3b1506e39..a7317b9cc 100644 --- a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/LocalMappingCustomizerTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/LocalMappingCustomizerTest.java @@ -1,5 +1,6 @@ package io.fd.honeycomb.lisp.translate.read; +import static io.fd.honeycomb.lisp.translate.read.dump.executor.params.MappingsDumpParams.EidType.IPV4; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.mockito.Matchers.any; @@ -7,6 +8,7 @@ import static org.mockito.Mockito.when; import com.google.common.collect.ImmutableList; import io.fd.honeycomb.lisp.context.util.EidMappingContext; +import io.fd.honeycomb.lisp.translate.read.dump.executor.params.MappingsDumpParams; import io.fd.honeycomb.lisp.translate.util.EidTranslator; import io.fd.honeycomb.translate.MappingContext; import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; @@ -20,15 +22,17 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types. import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Builder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.MappingId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.LocalMappings; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.LocalMappingsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.LocalMapping; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.LocalMappingBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.LocalMappingKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.local.mapping.Eid; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.EidTable; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTable; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTableKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.LocalMappings; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.LocalMappingsBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.local.mappings.LocalMapping; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.local.mappings.LocalMappingBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.local.mappings.LocalMappingKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.local.mappings.local.mapping.Eid; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.BridgeDomainSubtable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.VrfSubtable; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import io.fd.vpp.jvpp.core.dto.LispEidTableDetails; import io.fd.vpp.jvpp.core.dto.LispEidTableDetailsReplyDump; @@ -53,11 +57,13 @@ public class LocalMappingCustomizerTest extends public void setUp() { emptyIdentifier = InstanceIdentifier.create(EidTable.class) .child(VniTable.class, new VniTableKey(12L)) + .child(VrfSubtable.class) .child(LocalMappings.class) .child(LocalMapping.class); validIdentifier = InstanceIdentifier.create(EidTable.class) .child(VniTable.class, new VniTableKey(12L)) + .child(VrfSubtable.class) .child(LocalMappings.class) .child(LocalMapping.class, new LocalMappingKey(new MappingId("local-mapping"))); @@ -73,6 +79,7 @@ public class LocalMappingCustomizerTest extends detail.context = 4; detail.eid = new byte[]{-64, -88, 2, 1}; detail.eidPrefixLen = 32; + detail.eidType = (byte) IPV4.getValue(); detail.isLocal = 1; detail.locatorSetIndex = 1; detail.ttl = 7; diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/MapResolverCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/MapResolverCustomizerTest.java index 7afd8dd4f..112350676 100644 --- a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/MapResolverCustomizerTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/MapResolverCustomizerTest.java @@ -8,6 +8,8 @@ import static org.mockito.Mockito.when; import com.google.common.collect.ImmutableList; import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; import io.fd.honeycomb.vpp.test.read.ListReaderCustomizerTest; +import io.fd.vpp.jvpp.core.dto.LispMapResolverDetails; +import io.fd.vpp.jvpp.core.dto.LispMapResolverDetailsReplyDump; import java.util.List; import org.junit.Before; import org.junit.Test; @@ -19,14 +21,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.map.resolvers.grouping.map.resolvers.MapResolverBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.map.resolvers.grouping.map.resolvers.MapResolverKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.core.dto.LispMapResolverDetails; -import io.fd.vpp.jvpp.core.dto.LispMapResolverDetailsReplyDump; public class MapResolverCustomizerTest extends ListReaderCustomizerTest<MapResolver, MapResolverKey, MapResolverBuilder> { - private static final IpAddress IP_ADDRESS = new IpAddress(new Ipv4AddressNoZone("192.168.2.1")); private static final IpAddress IP_ADDRESS_REVERTED = new IpAddress(new Ipv4AddressNoZone("1.2.168.192")); @@ -64,7 +63,7 @@ public class MapResolverCustomizerTest final MapResolverKey key = keys.get(0); assertNotNull(key); - assertEquals("192.168.2.1", new String(key.getIpAddress().getValue())); + assertEquals("1.2.168.192", new String(key.getIpAddress().getValue())); } diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/PitrCfgCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/PitrCfgCustomizerTest.java index c46d1f454..6c345223e 100644 --- a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/PitrCfgCustomizerTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/PitrCfgCustomizerTest.java @@ -11,6 +11,7 @@ import java.nio.charset.StandardCharsets; import org.junit.Before; import org.junit.Test; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.LispStateBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.lisp.feature.data.grouping.LispFeatureDataBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.pitr.cfg.grouping.PitrCfg; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.pitr.cfg.grouping.PitrCfgBuilder; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; @@ -22,16 +23,14 @@ public class PitrCfgCustomizerTest extends ReaderCustomizerTest<PitrCfg, PitrCfg private static final byte[] LOC_SET_NAME_BYTES = "loc-set".getBytes(StandardCharsets.UTF_8); private InstanceIdentifier<PitrCfg> emptyId; - private PitrCfg validData; public PitrCfgCustomizerTest() { - super(PitrCfg.class, LispStateBuilder.class); + super(PitrCfg.class, LispFeatureDataBuilder.class); } @Before public void init() { emptyId = InstanceIdentifier.create(PitrCfg.class); - validData = new PitrCfgBuilder().setLocatorSet("loc-set").build(); mockDumpData(); } diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/RemoteMappingCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/RemoteMappingCustomizerTest.java index a431d224c..5ab8e5996 100644 --- a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/RemoteMappingCustomizerTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/RemoteMappingCustomizerTest.java @@ -2,6 +2,7 @@ package io.fd.honeycomb.lisp.translate.read; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.any; import static org.mockito.Mockito.when; @@ -11,6 +12,11 @@ import io.fd.honeycomb.lisp.translate.util.EidTranslator; import io.fd.honeycomb.translate.MappingContext; import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; import io.fd.honeycomb.vpp.test.read.ListReaderCustomizerTest; +import io.fd.vpp.jvpp.core.dto.LispEidTableDetails; +import io.fd.vpp.jvpp.core.dto.LispEidTableDetailsReplyDump; +import io.fd.vpp.jvpp.core.dto.LispLocatorDetails; +import io.fd.vpp.jvpp.core.dto.LispLocatorDetailsReplyDump; +import java.util.Collections; import java.util.List; import org.junit.Before; import org.junit.Test; @@ -19,19 +25,22 @@ import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Builder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.MapReplyAction; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.MappingId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.RemoteMappings; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.RemoteMappingsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.RemoteMapping; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.RemoteMappingBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.RemoteMappingKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.Eid; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.locator.list.NegativeMapping; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.locator.list.PositiveMapping; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.locator.list.positive.mapping.rlocs.Locator; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.EidTable; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTable; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTableKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.RemoteMappings; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.RemoteMappingsBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.RemoteMapping; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.RemoteMappingBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.RemoteMappingKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.remote.mapping.Eid; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.VrfSubtable; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.core.dto.LispEidTableDetails; -import io.fd.vpp.jvpp.core.dto.LispEidTableDetailsReplyDump; public class RemoteMappingCustomizerTest extends ListReaderCustomizerTest<RemoteMapping, RemoteMappingKey, RemoteMappingBuilder> @@ -43,7 +52,6 @@ public class RemoteMappingCustomizerTest @Mock private EidMappingContext eidMappingContext; - private InstanceIdentifier<RemoteMapping> emptyId; private InstanceIdentifier<RemoteMapping> validId; public RemoteMappingCustomizerTest() { @@ -53,22 +61,56 @@ public class RemoteMappingCustomizerTest @Before public void init() { - emptyId = InstanceIdentifier.create(EidTable.class) - .child(VniTable.class, new VniTableKey(12L)) - .child(RemoteMappings.class) - .child(RemoteMapping.class); - validId = InstanceIdentifier.create(EidTable.class) .child(VniTable.class, new VniTableKey(12L)) + .child(VrfSubtable.class) .child(RemoteMappings.class) .child(RemoteMapping.class, new RemoteMappingKey(new MappingId("remote-mapping"))); - - mockDumpData(); mockMappings(); } - private void mockDumpData() { + private void mockDumpDataActionZero() { + LispEidTableDetailsReplyDump replyDump = new LispEidTableDetailsReplyDump(); + LispEidTableDetails detail = new LispEidTableDetails(); + detail.action = 0; + detail.authoritative = 1; + detail.context = 4; + detail.eid = new byte[]{-64, -88, 2, 1}; + detail.eidPrefixLen = 32; + detail.isLocal = 0; + detail.locatorSetIndex = 1; + detail.ttl = 7; + detail.vni = 12; + + replyDump.lispEidTableDetails = ImmutableList.of(detail); + + when(api.lispEidTableDump(any())).thenReturn(future(replyDump)); + + LispLocatorDetailsReplyDump rlocs = new LispLocatorDetailsReplyDump(); + rlocs.lispLocatorDetails = Collections.emptyList(); + when(api.lispLocatorDump(any())).thenReturn(future(rlocs)); + } + + private void mockDumpDataActionOne() { + LispEidTableDetailsReplyDump replyDump = new LispEidTableDetailsReplyDump(); + LispEidTableDetails detail = new LispEidTableDetails(); + detail.action = 1; + detail.authoritative = 1; + detail.context = 4; + detail.eid = new byte[]{-64, -88, 2, 1}; + detail.eidPrefixLen = 32; + detail.isLocal = 0; + detail.locatorSetIndex = 1; + detail.ttl = 7; + detail.vni = 12; + + replyDump.lispEidTableDetails = ImmutableList.of(detail); + + when(api.lispEidTableDump(any())).thenReturn(future(replyDump)); + } + + private void mockDumpDataActionZeroWithRemotes() { LispEidTableDetailsReplyDump replyDump = new LispEidTableDetailsReplyDump(); LispEidTableDetails detail = new LispEidTableDetails(); detail.action = 0; @@ -84,8 +126,20 @@ public class RemoteMappingCustomizerTest replyDump.lispEidTableDetails = ImmutableList.of(detail); when(api.lispEidTableDump(any())).thenReturn(future(replyDump)); + + LispLocatorDetailsReplyDump rlocs = new LispLocatorDetailsReplyDump(); + LispLocatorDetails rloc = new LispLocatorDetails(); + rloc.ipAddress = new byte[]{-64, -88, 2, 1}; + rloc.isIpv6 = 0; + rloc.priority = 1; + rloc.weight = 2; + + rlocs.lispLocatorDetails = ImmutableList.of(rloc); + + when(api.lispLocatorDump(any())).thenReturn(future(rlocs)); } + private void mockMappings() { when(eidMappingContext.getId(any(Eid.class), any(MappingContext.class))) @@ -96,7 +150,41 @@ public class RemoteMappingCustomizerTest } @Test - public void readCurrentAttributes() throws Exception { + public void readCurrentAttributesNegativeMappingOne() throws Exception { + mockDumpDataActionOne(); + RemoteMappingBuilder builder = new RemoteMappingBuilder(); + getCustomizer().readCurrentAttributes(validId, builder, ctx); + + RemoteMapping mapping = builder.build(); + + assertNotNull(mapping); + assertEquals(true, compareAddresses(EID_ADDRESS, mapping.getEid().getAddress())); + assertEquals(true, mapping.getAuthoritative().isA()); + assertEquals(7L, mapping.getTtl().longValue()); + assertTrue(mapping.getLocatorList() instanceof NegativeMapping); + assertEquals(MapReplyAction.NativelyForward, + ((NegativeMapping) mapping.getLocatorList()).getMapReply().getMapReplyAction()); + } + + @Test + public void readCurrentAttributesNegativeMappingZero() throws Exception { + mockDumpDataActionZero(); + RemoteMappingBuilder builder = new RemoteMappingBuilder(); + getCustomizer().readCurrentAttributes(validId, builder, ctx); + + RemoteMapping mapping = builder.build(); + + assertNotNull(mapping); + assertEquals(true, compareAddresses(EID_ADDRESS, mapping.getEid().getAddress())); + assertEquals(true, mapping.getAuthoritative().isA()); + assertEquals(7L, mapping.getTtl().longValue()); + assertEquals(MapReplyAction.NoAction, + ((NegativeMapping) mapping.getLocatorList()).getMapReply().getMapReplyAction()); + } + + @Test + public void readCurrentAttributesPositiveMapping() throws Exception { + mockDumpDataActionZeroWithRemotes(); RemoteMappingBuilder builder = new RemoteMappingBuilder(); getCustomizer().readCurrentAttributes(validId, builder, ctx); @@ -106,11 +194,20 @@ public class RemoteMappingCustomizerTest assertEquals(true, compareAddresses(EID_ADDRESS, mapping.getEid().getAddress())); assertEquals(true, mapping.getAuthoritative().isA()); assertEquals(7L, mapping.getTtl().longValue()); + assertTrue(mapping.getLocatorList() instanceof PositiveMapping); + + final List<Locator> locators = ((PositiveMapping) mapping.getLocatorList()).getRlocs().getLocator(); + assertEquals(1, locators.size()); + final Locator locator = locators.get(0); + assertEquals("192.168.2.1", locator.getAddress().getIpv4Address().getValue()); + assertEquals(1, locator.getPriority().shortValue()); + assertEquals(2, locator.getWeight().shortValue()); } @Test public void getAllIds() throws Exception { + mockDumpDataActionOne(); final List<RemoteMappingKey> keys = getCustomizer().getAllIds(validId, ctx); assertNotNull(keys); diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/VniTableCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/VniTableCustomizerTest.java index f4fe52c5d..fe967e486 100644 --- a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/VniTableCustomizerTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/VniTableCustomizerTest.java @@ -1,25 +1,34 @@ package io.fd.honeycomb.lisp.translate.read; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.mockito.Matchers.any; +import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; import com.google.common.collect.ImmutableList; +import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.i.DumpCallFailedException; import io.fd.honeycomb.vpp.test.read.ListReaderCustomizerTest; +import io.fd.vpp.jvpp.VppCallbackException; +import io.fd.vpp.jvpp.core.dto.LispEidTableVniDetails; +import io.fd.vpp.jvpp.core.dto.LispEidTableVniDetailsReplyDump; import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import org.junit.Before; import org.junit.Test; +import org.mockito.Mockito; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.EidTable; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.EidTableBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTable; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTableBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTableKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.core.dto.LispEidTableMapDetails; -import io.fd.vpp.jvpp.core.dto.LispEidTableMapDetailsReplyDump; - public class VniTableCustomizerTest extends ListReaderCustomizerTest<VniTable, VniTableKey, VniTableBuilder> { @@ -31,41 +40,72 @@ public class VniTableCustomizerTest extends ListReaderCustomizerTest<VniTable, V @Before public void init() { - validId = InstanceIdentifier.create(EidTable.class).child(VniTable.class, new VniTableKey(2L)); - - final LispEidTableMapDetailsReplyDump replyDump = new LispEidTableMapDetailsReplyDump(); - final LispEidTableMapDetails detail = new LispEidTableMapDetails(); - detail.dpTable = 3; - detail.vni = 2; - detail.context = 4; - replyDump.lispEidTableMapDetails = ImmutableList.of(detail); - - when(api.lispEidTableMapDump(any())).thenReturn(future(replyDump)); + validId = InstanceIdentifier.create(EidTable.class).child(VniTable.class, new VniTableKey(12L)); } @Test - public void getAllIds() throws Exception { + public void testReadAllSuccessfull() throws ReadFailedException { + whenLispEidTableVniDumpReturnValid(); final List<VniTableKey> keys = getCustomizer().getAllIds(validId, ctx); - assertEquals(1, keys.size()); + assertNotNull(keys); + assertEquals(3, keys.size()); + assertTrue(keys.contains(new VniTableKey(12L))); + assertTrue(keys.contains(new VniTableKey(14L))); + assertTrue(keys.contains(new VniTableKey(16L))); + } - final VniTableKey key = keys.get(0); - assertNotNull(key); - //due to ambigous call (long,long) vs (Object,Object) - assertEquals(2L, key.getVirtualNetworkIdentifier().longValue()); + @Test + public void testReadAllFailed() { + whenLispEidTableVniDumpThrowException(); + try { + getCustomizer().getAllIds(validId, ctx); + } catch (ReadFailedException e) { + assertTrue(e instanceof ReadFailedException); + assertTrue(e.getCause() instanceof DumpCallFailedException); + assertTrue(e.getCause().getCause() instanceof VppCallbackException); + } } @Test - public void readCurrentAttributes() throws Exception { + public void testReadAttributes() throws ReadFailedException { + whenLispEidTableVniDumpReturnValid(); VniTableBuilder builder = new VniTableBuilder(); - getCustomizer().readCurrentAttributes(validId, builder, ctx); - final VniTable table = builder.build(); + customizer.readCurrentAttributes(validId, builder, ctx); + final VniTable table = builder.build(); assertNotNull(table); - assertEquals(3L, table.getTableId().longValue()); - assertEquals(2L, table.getVirtualNetworkIdentifier().longValue()); + assertEquals(12L, table.getVirtualNetworkIdentifier().longValue()); + } + + private void whenLispEidTableVniDumpReturnValid() { + + LispEidTableVniDetailsReplyDump dump = new LispEidTableVniDetailsReplyDump(); + LispEidTableVniDetails details1 = new LispEidTableVniDetails(); + details1.vni = 14; + + LispEidTableVniDetails details2 = new LispEidTableVniDetails(); + details2.vni = 12; + + LispEidTableVniDetails details3 = new LispEidTableVniDetails(); + details3.vni = 16; + + dump.lispEidTableVniDetails = ImmutableList.of(details1, details2, details3); + + when(api.lispEidTableVniDump(Mockito.any())).thenReturn(CompletableFuture.completedFuture(dump)); + } + + private void whenLispEidTableVniDumpThrowException() { + when(api.lispEidTableVniDump(Mockito.any())) + .thenReturn(new CompletableFuture<LispEidTableVniDetailsReplyDump>() { + @Override + public LispEidTableVniDetailsReplyDump get(final long l, final TimeUnit timeUnit) + throws InterruptedException, ExecutionException, TimeoutException { + throw new ExecutionException(new VppCallbackException("lispEidTableVniDump", 1, -2)); + } + }); } @Override diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/VrfSubtableCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/VrfSubtableCustomizerTest.java new file mode 100644 index 000000000..f18f349d8 --- /dev/null +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/VrfSubtableCustomizerTest.java @@ -0,0 +1,107 @@ +package io.fd.honeycomb.lisp.translate.read; + + +import static io.fd.honeycomb.lisp.translate.read.dump.executor.params.SubtableDumpParams.MapLevel.L3; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import io.fd.honeycomb.lisp.translate.read.trait.SubtableReaderTestCase; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.i.DumpCallFailedException; +import io.fd.vpp.jvpp.VppCallbackException; +import org.junit.Before; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.EidTable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTableBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTableKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.VrfSubtable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.VrfSubtableBuilder; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class VrfSubtableCustomizerTest extends SubtableReaderTestCase<VrfSubtable, VrfSubtableBuilder> { + + private InstanceIdentifier<VrfSubtable> validId; + + public VrfSubtableCustomizerTest() { + super(VrfSubtable.class, VrfSubtableBuilder.class); + } + + @Before + public void init() { + validId = InstanceIdentifier.create(EidTable.class).child(VniTable.class, new VniTableKey(expectedVni)) + .child(VrfSubtable.class); + } + + @Test + public void testReadCurrentSuccessfull() throws ReadFailedException { + doReturnValidNonEmptyDataOnDump(); + VrfSubtableBuilder builder = new VrfSubtableBuilder(); + customizer.readCurrentAttributes(validId, builder, ctx); + + verifyLispEidTableMapDumpCalled(L3); + + final VrfSubtable subtable = builder.build(); + assertNotNull(subtable); + assertEquals(expectedTableId, subtable.getTableId().longValue()); + } + + @Test + public void testReadCurrentEmptyDump() throws ReadFailedException { + doReturnEmptyDataOnDump(); + VrfSubtableBuilder builder = new VrfSubtableBuilder(); + customizer.readCurrentAttributes(validId, builder, ctx); + + verifyLispEidTableMapDumpCalled(L3); + + final VrfSubtable subtable = builder.build(); + assertNotNull(subtable); + assertNull(subtable.getTableId()); + } + + @Test + public void testReadCurrentFailed() { + doThrowOnDump(); + VrfSubtableBuilder builder = new VrfSubtableBuilder(); + try { + customizer.readCurrentAttributes(validId, builder, ctx); + } catch (ReadFailedException e) { + assertTrue(e.getCause() instanceof DumpCallFailedException); + assertTrue(e.getCause().getCause() instanceof VppCallbackException); + assertTrue(builder.getTableId() == null); + verifyLispEidTableMapDumpNotCalled(); + + return; + } + + fail("Test should throw ReadFailedException"); + } + + @Override + protected ReaderCustomizer<VrfSubtable, VrfSubtableBuilder> initCustomizer() { + return new VrfSubtableCustomizer(api); + } + + @Test + public void testGetBuilder() { + final VrfSubtableBuilder builder = customizer.getBuilder(validId); + + assertNotNull(builder); + assertNull(builder.getLocalMappings()); + assertNull(builder.getRemoteMappings()); + assertNull(builder.getTableId()); + } + + @Test + public void testMerge() { + VniTableBuilder parentBuilder = new VniTableBuilder(); + VrfSubtable subtable = new VrfSubtableBuilder().build(); + + customizer.merge(parentBuilder, subtable); + assertEquals(subtable, parentBuilder.getVrfSubtable()); + } +} diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/dump/executor/VniTableDumpExecutorTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/dump/executor/VniTableDumpExecutorTest.java index 3bc95d52b..b955609c5 100644 --- a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/dump/executor/VniTableDumpExecutorTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/dump/executor/VniTableDumpExecutorTest.java @@ -12,6 +12,8 @@ import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.DumpExecut import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.i.DumpCallFailedException; import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.i.DumpTimeoutException; import io.fd.honeycomb.vpp.test.read.JvppDumpExecutorTest; +import io.fd.vpp.jvpp.core.dto.LispEidTableVniDetails; +import io.fd.vpp.jvpp.core.dto.LispEidTableVniDetailsReplyDump; import java.util.concurrent.TimeoutException; import org.junit.Before; import org.junit.Test; @@ -22,28 +24,27 @@ import io.fd.vpp.jvpp.core.dto.LispEidTableMapDetailsReplyDump; public class VniTableDumpExecutorTest extends JvppDumpExecutorTest<VniTableDumpExecutor> { - private LispEidTableMapDetailsReplyDump validDump; + private LispEidTableVniDetailsReplyDump validDump; @Before public void init() { - validDump = new LispEidTableMapDetailsReplyDump(); - LispEidTableMapDetails detail = new LispEidTableMapDetails(); - detail.dpTable = 1; + validDump = new LispEidTableVniDetailsReplyDump(); + LispEidTableVniDetails detail = new LispEidTableVniDetails(); detail.vni = 2; detail.context = 4; - validDump.lispEidTableMapDetails = ImmutableList.of(detail); + validDump.lispEidTableVniDetails = ImmutableList.of(detail); } @Test(expected = DumpCallFailedException.class) public void testExecuteDumpFail() throws DumpExecutionFailedException { - doThrowFailExceptionWhen().lispEidTableMapDump(Mockito.any()); + doThrowFailExceptionWhen().lispEidTableVniDump(Mockito.any()); getExecutor().executeDump(EntityDumpExecutor.NO_PARAMS); } @Test public void testExecuteDumpTimeout() throws Exception { - doThrowTimeoutExceptionWhen().lispEidTableMapDump(Mockito.any()); + doThrowTimeoutExceptionWhen().lispEidTableVniDump(Mockito.any()); try { getExecutor().executeDump(EntityDumpExecutor.NO_PARAMS); } catch (Exception e) { @@ -57,15 +58,14 @@ public class VniTableDumpExecutorTest extends JvppDumpExecutorTest<VniTableDumpE @Test public void testExecuteDump() throws DumpExecutionFailedException { - doReturnResponseWhen(validDump).lispEidTableMapDump(Mockito.any()); - final LispEidTableMapDetailsReplyDump reply = getExecutor().executeDump(EntityDumpExecutor.NO_PARAMS); + doReturnResponseWhen(validDump).lispEidTableVniDump(Mockito.any()); + final LispEidTableVniDetailsReplyDump reply = getExecutor().executeDump(EntityDumpExecutor.NO_PARAMS); assertNotNull(reply); - assertEquals(1, reply.lispEidTableMapDetails.size()); - final LispEidTableMapDetails detail = reply.lispEidTableMapDetails.get(0); + assertEquals(1, reply.lispEidTableVniDetails.size()); + final LispEidTableVniDetails detail = reply.lispEidTableVniDetails.get(0); assertEquals(4, detail.context); - assertEquals(1, detail.dpTable); assertEquals(2, detail.vni); } diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/trait/MappingFilterProviderTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/trait/MappingFilterProviderTest.java new file mode 100644 index 000000000..6a7c3b7e7 --- /dev/null +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/trait/MappingFilterProviderTest.java @@ -0,0 +1,79 @@ +package io.fd.honeycomb.lisp.translate.read.trait; + + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.LocalMappings; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.RemoteMappings; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.LocalMapping; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.RemoteMapping; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.BridgeDomainSubtable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.VrfSubtable; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class MappingFilterProviderTest implements MappingFilterProvider { + + private InstanceIdentifier<LocalMapping> validVrfLocal; + private InstanceIdentifier<LocalMapping> validBdLocal; + private InstanceIdentifier<LocalMapping> invalidLocal; + + private InstanceIdentifier<RemoteMapping> validVrfRemote; + private InstanceIdentifier<RemoteMapping> validBdRemote; + private InstanceIdentifier<RemoteMapping> invalidRemote; + + + @Before + public void init() { + validVrfLocal = InstanceIdentifier.create(VrfSubtable.class) + .child(LocalMappings.class) + .child(LocalMapping.class); + + validBdLocal = InstanceIdentifier.create(BridgeDomainSubtable.class) + .child(LocalMappings.class) + .child(LocalMapping.class); + + invalidLocal = InstanceIdentifier.create(LocalMapping.class); + + validVrfRemote = InstanceIdentifier.create(VrfSubtable.class) + .child(RemoteMappings.class) + .child(RemoteMapping.class); + + validBdRemote = InstanceIdentifier.create(BridgeDomainSubtable.class) + .child(RemoteMappings.class) + .child(RemoteMapping.class); + + invalidRemote = InstanceIdentifier.create(RemoteMapping.class); + } + + @Test + public void testVrfLocalValid() { + assertEquals(VRF_MAPPINGS_ONLY, subtableFilterForLocalMappings(validVrfLocal)); + } + + @Test + public void testBridgeDomainLocalValid() { + assertEquals(BRIDGE_DOMAIN_MAPPINGS_ONLY, subtableFilterForLocalMappings(validBdLocal)); + } + + @Test(expected = IllegalArgumentException.class) + public void testLocalInvalid() { + subtableFilterForLocalMappings(invalidLocal); + } + + @Test + public void testVrfRemoteValid() { + assertEquals(VRF_MAPPINGS_ONLY, subtableFilterForRemoteMappings(validVrfRemote)); + } + + @Test + public void testBridgeDomainRemoteValid() { + assertEquals(BRIDGE_DOMAIN_MAPPINGS_ONLY, subtableFilterForRemoteMappings(validBdRemote)); + } + + @Test(expected = IllegalArgumentException.class) + public void testRemoteInvalid() { + subtableFilterForRemoteMappings(invalidRemote); + } +}
\ No newline at end of file diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/trait/MappingProducerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/trait/MappingProducerTest.java new file mode 100644 index 000000000..89eab3c5e --- /dev/null +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/trait/MappingProducerTest.java @@ -0,0 +1,170 @@ +package io.fd.honeycomb.lisp.translate.read.trait; + + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import io.fd.honeycomb.translate.write.WriteFailedException; +import org.junit.Before; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv4Afi; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv6Afi; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.MacAfi; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.LocalMappings; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.RemoteMappings; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.LocalMapping; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.LocalMappingBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.local.mapping.EidBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.RemoteMapping; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.RemoteMappingBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.BridgeDomainSubtable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.VrfSubtable; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class MappingProducerTest implements MappingProducer { + + private InstanceIdentifier<LocalMapping> validVrfLocalMappingId; + private InstanceIdentifier<LocalMapping> validBridgeDomainLocalMappingId; + private InstanceIdentifier<RemoteMapping> validVrfRemoteMappingId; + private InstanceIdentifier<RemoteMapping> validBridgeDomainRemoteMappingId; + + private LocalMapping ipv4LocalMapping; + private LocalMapping ipv6LocalMapping; + private LocalMapping macLocalMapping; + + private RemoteMapping ipv4RemoteMapping; + private RemoteMapping ipv6RemoteMapping; + private RemoteMapping macRemoteMapping; + + @Before + public void init() { + validVrfLocalMappingId = InstanceIdentifier.create(VrfSubtable.class) + .child(LocalMappings.class) + .child(LocalMapping.class); + + validBridgeDomainLocalMappingId = InstanceIdentifier.create(BridgeDomainSubtable.class) + .child(LocalMappings.class) + .child(LocalMapping.class); + + validVrfRemoteMappingId = InstanceIdentifier.create(VrfSubtable.class) + .child(RemoteMappings.class) + .child(RemoteMapping.class); + + validBridgeDomainRemoteMappingId = InstanceIdentifier.create(BridgeDomainSubtable.class) + .child(RemoteMappings.class) + .child(RemoteMapping.class); + + ipv4LocalMapping = new LocalMappingBuilder() + .setEid(new EidBuilder() + .setAddressType(Ipv4Afi.class) + .build()).build(); + + ipv6LocalMapping = new LocalMappingBuilder() + .setEid(new EidBuilder() + .setAddressType(Ipv6Afi.class) + .build()).build(); + macLocalMapping = new LocalMappingBuilder() + .setEid(new EidBuilder() + .setAddressType(MacAfi.class) + .build()).build(); + + ipv4RemoteMapping = new RemoteMappingBuilder() + .setEid(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.EidBuilder() + .setAddressType(Ipv4Afi.class).build()).build(); + + ipv6RemoteMapping = new RemoteMappingBuilder() + .setEid(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.EidBuilder() + .setAddressType(Ipv6Afi.class).build()).build(); + + macRemoteMapping = new RemoteMappingBuilder() + .setEid(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.EidBuilder() + .setAddressType(MacAfi.class).build()).build(); + } + + @Test + public void testValidVrfLocal() { + testPositiveCase(validVrfLocalMappingId, ipv4LocalMapping); + testPositiveCase(validVrfLocalMappingId, ipv6LocalMapping); + } + + @Test + public void testValidBridgeDomainLocal() { + testPositiveCase(validBridgeDomainLocalMappingId, macLocalMapping); + } + + @Test + public void testInvalidVrfLocal() { + testNegativeCase(validVrfLocalMappingId, macLocalMapping); + } + + @Test + public void testInvalidBridgeDomainLocal() { + testNegativeCase(validBridgeDomainLocalMappingId, ipv4LocalMapping); + testNegativeCase(validBridgeDomainLocalMappingId, ipv6LocalMapping); + } + + + @Test + public void testValidVrfRemote() { + testPositiveCase(validVrfRemoteMappingId, ipv4RemoteMapping); + testPositiveCase(validVrfRemoteMappingId, ipv6RemoteMapping); + } + + @Test + public void testValidBridgeDomainRemote() { + testPositiveCase(validBridgeDomainRemoteMappingId, macRemoteMapping); + } + + @Test + public void testInvalidVrfRemote() { + testNegativeCase(validVrfRemoteMappingId, macRemoteMapping); + } + + @Test + public void testInvalidBridgeDomainRemote() { + testNegativeCase(validBridgeDomainRemoteMappingId, ipv4RemoteMapping); + testNegativeCase(validBridgeDomainRemoteMappingId, ipv6RemoteMapping); + } + + private void testNegativeCase(final InstanceIdentifier<LocalMapping> identifier, final LocalMapping data) { + try { + checkAllowedCombination(identifier, data); + } catch (WriteFailedException e) { + assertTrue(e instanceof WriteFailedException.CreateFailedException); + assertTrue(e.getCause() instanceof IllegalArgumentException); + return; + } + + fail("Test should have failed"); + } + + + private void testPositiveCase(final InstanceIdentifier<LocalMapping> identifier, final LocalMapping data) { + try { + checkAllowedCombination(identifier, data); + } catch (WriteFailedException e) { + fail("Test should have passed"); + } + } + + private void testNegativeCase(final InstanceIdentifier<RemoteMapping> identifier, final RemoteMapping data) { + try { + checkAllowedCombination(identifier, data); + } catch (WriteFailedException e) { + assertTrue(e instanceof WriteFailedException.CreateFailedException); + assertTrue(e.getCause() instanceof IllegalArgumentException); + return; + } + + fail("Test should have failed"); + } + + + private void testPositiveCase(final InstanceIdentifier<RemoteMapping> identifier, final RemoteMapping data) { + try { + checkAllowedCombination(identifier, data); + } catch (WriteFailedException e) { + fail("Test should have passed"); + } + } +} diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/trait/SubtableReaderTestCase.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/trait/SubtableReaderTestCase.java new file mode 100644 index 000000000..f40d72951 --- /dev/null +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/read/trait/SubtableReaderTestCase.java @@ -0,0 +1,81 @@ +package io.fd.honeycomb.lisp.translate.read.trait; + + +import static io.fd.honeycomb.lisp.translate.read.dump.executor.params.SubtableDumpParams.MapLevel; +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; + +import com.google.common.collect.ImmutableList; +import io.fd.honeycomb.vpp.test.read.ReaderCustomizerTest; +import io.fd.vpp.jvpp.VppCallbackException; +import io.fd.vpp.jvpp.core.dto.LispEidTableMapDetails; +import io.fd.vpp.jvpp.core.dto.LispEidTableMapDetailsReplyDump; +import io.fd.vpp.jvpp.core.dto.LispEidTableMapDump; +import java.util.Collections; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import javax.annotation.Nonnull; +import org.junit.Before; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; + +public abstract class SubtableReaderTestCase<D extends DataObject, B extends Builder<D>> + extends ReaderCustomizerTest<D, B> + implements SubtableReader { + + protected final long expectedVni = 12; + protected final int expectedTableId = 14; + + @Captor + protected ArgumentCaptor<LispEidTableMapDump> requestCaptor; + + public SubtableReaderTestCase(final Class<D> dataObjectClass, + final Class<? extends Builder<? extends DataObject>> parentBuilderClass) { + super(dataObjectClass, parentBuilderClass); + } + + protected void doReturnValidNonEmptyDataOnDump() { + LispEidTableMapDetailsReplyDump reply = new LispEidTableMapDetailsReplyDump(); + LispEidTableMapDetails detailFirst = new LispEidTableMapDetails(); + detailFirst.vni = Long.valueOf(expectedVni).intValue(); + detailFirst.dpTable = expectedTableId; + + LispEidTableMapDetails detailSecond = new LispEidTableMapDetails(); + detailSecond.vni = 13; + detailSecond.dpTable = 15; + + reply.lispEidTableMapDetails = ImmutableList.of(detailFirst, detailSecond); + + when(api.lispEidTableMapDump(any(LispEidTableMapDump.class))) + .thenReturn(future(reply)); + } + + protected void doReturnEmptyDataOnDump() { + LispEidTableMapDetailsReplyDump reply = new LispEidTableMapDetailsReplyDump(); + reply.lispEidTableMapDetails = Collections.emptyList(); + when(api.lispEidTableMapDump(any(LispEidTableMapDump.class))) + .thenReturn(future(reply)); + } + + protected void doThrowOnDump() { + when(api.lispEidTableMapDump(any(LispEidTableMapDump.class))) + .thenReturn(failedFuture()); + } + + protected void verifyLispEidTableMapDumpCalled(@Nonnull final MapLevel expectedLevel) { + verify(api, times(1)).lispEidTableMapDump(requestCaptor.capture()); + assertEquals(expectedLevel.getValue(), requestCaptor.getValue().isL2); + } + + protected void verifyLispEidTableMapDumpNotCalled() { + verify(api, times(1)).lispEidTableMapDump(any()); + } +} diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/util/EidTranslatorTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/util/EidTranslatorTest.java index 88ad10970..956a6cabf 100755 --- a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/util/EidTranslatorTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/util/EidTranslatorTest.java @@ -18,7 +18,7 @@ public class EidTranslatorTest implements EidTranslator { @Test public void testGetEidType() { assertEquals(IPV4, getEidType( - new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.remote.mapping.EidBuilder() + new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.EidBuilder() .setAddress( new Ipv4Builder().setIpv4( new Ipv4Address("192.168.2.1")) @@ -26,7 +26,7 @@ public class EidTranslatorTest implements EidTranslator { .build())); assertEquals(IPV6, getEidType( - new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.remote.mapping.EidBuilder() + new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.EidBuilder() .setAddress( new Ipv6Builder().setIpv6( new Ipv6Address("2001:0db8:0a0b:12f0:0000:0000:0000:0001")) @@ -34,7 +34,7 @@ public class EidTranslatorTest implements EidTranslator { .build())); assertEquals(MAC, getEidType( - new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.remote.mapping.EidBuilder() + new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.EidBuilder() .setAddress( new MacBuilder().setMac( new MacAddress("aa:bb:cc:dd:ee:ff")) diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/AdjacencyCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/AdjacencyCustomizerTest.java index b32b0bbe2..30c84cc9f 100644 --- a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/AdjacencyCustomizerTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/AdjacencyCustomizerTest.java @@ -4,37 +4,53 @@ import static io.fd.honeycomb.lisp.translate.read.dump.executor.params.MappingsD import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; import static org.mockito.Matchers.any; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import io.fd.honeycomb.lisp.context.util.EidMappingContext; +import io.fd.honeycomb.translate.MappingContext; import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest; +import io.fd.vpp.jvpp.core.dto.LispAddDelAdjacency; +import io.fd.vpp.jvpp.core.dto.LispAddDelAdjacencyReply; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Captor; +import org.mockito.Mock; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.InstanceIdType; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv4Afi; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.MacAfi; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Builder; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.MacBuilder; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.adjacencies.grouping.Adjacencies; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.adjacencies.grouping.adjacencies.Adjacency; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.adjacencies.grouping.adjacencies.AdjacencyBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.adjacencies.grouping.adjacencies.adjacency.LocalEidBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.adjacencies.grouping.adjacencies.adjacency.RemoteEidBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.RemoteMappings; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.RemoteMapping; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.EidTable; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTable; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTableKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.Adjacencies; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.adjacencies.Adjacency; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.adjacencies.AdjacencyBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.adjacencies.adjacency.LocalEidBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.adjacencies.adjacency.RemoteEidBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.BridgeDomainSubtable; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.core.dto.LispAddDelAdjacency; -import io.fd.vpp.jvpp.core.dto.LispAddDelAdjacencyReply; public class AdjacencyCustomizerTest extends WriterCustomizerTest { @Captor private ArgumentCaptor<LispAddDelAdjacency> requestCaptor; + @Mock + private EidMappingContext localMappingContext; + + @Mock + private EidMappingContext remoteMappingContext; + private AdjacencyCustomizer customizer; private InstanceIdentifier<Adjacency> emptyId; @@ -46,58 +62,142 @@ public class AdjacencyCustomizerTest extends WriterCustomizerTest { @Before public void init() { - customizer = new AdjacencyCustomizer(api); + customizer = new AdjacencyCustomizer(api, localMappingContext, remoteMappingContext); emptyId = InstanceIdentifier.create(Adjacency.class); validId = InstanceIdentifier.create(EidTable.class) .child(VniTable.class, new VniTableKey(2L)) + .child(BridgeDomainSubtable.class) + .child(RemoteMappings.class) + .child(RemoteMapping.class) .child(Adjacencies.class) .child(Adjacency.class); emptyData = new AdjacencyBuilder().build(); invalidData = new AdjacencyBuilder().setId("ID").setLocalEid( - new LocalEidBuilder().setAddress(new Ipv4Builder().setIpv4(new Ipv4Address("192.168.2.1")).build()) + new LocalEidBuilder() + .setVirtualNetworkId(new InstanceIdType(12L)) + .setAddressType(Ipv4Afi.class) + .setAddress(new Ipv4Builder().setIpv4(new Ipv4Address("192.168.2.1")).build()) .build()).setRemoteEid( - new RemoteEidBuilder().setAddress(new MacBuilder().setMac(new MacAddress("aa:aa:aa:aa:aa:aa")).build()) + new RemoteEidBuilder() + .setVirtualNetworkId(new InstanceIdType(12L)) + .setAddressType(MacAfi.class) + .setAddress(new MacBuilder().setMac(new MacAddress("aa:aa:aa:aa:aa:aa")).build()) .build()) .build(); validData = new AdjacencyBuilder().setId("ID").setLocalEid( - new LocalEidBuilder().setAddress(new Ipv4Builder().setIpv4(new Ipv4Address("192.168.2.1")).build()) + new LocalEidBuilder() + .setVirtualNetworkId(new InstanceIdType(12L)) + .setAddressType(Ipv4Afi.class) + .setAddress(new Ipv4Builder().setIpv4(new Ipv4Address("192.168.2.1")).build()) .build()).setRemoteEid( new RemoteEidBuilder() + .setVirtualNetworkId(new InstanceIdType(12L)) + .setAddressType(Ipv4Afi.class) .setAddress(new Ipv4Builder().setIpv4(new Ipv4Address("192.168.5.2")).build()).build()).build(); when(api.lispAddDelAdjacency(any())).thenReturn(future(new LispAddDelAdjacencyReply())); } - @Test(expected = IllegalStateException.class) + @Test public void writeCurrentAttributesNoKey() throws Exception { - customizer.writeCurrentAttributes(emptyId, emptyData, writeContext); + try { + customizer.writeCurrentAttributes(emptyId, emptyData, writeContext); + } catch (NullPointerException e) { + verify(api, times(0)).lispAddDelAdjacency(any()); + return; + } + + fail("Test should have failed while reading parent vni table id"); } - @Test(expected = IllegalStateException.class) + @Test public void writeCurrentAttributesInvalidCombination() throws Exception { - customizer.writeCurrentAttributes(emptyId, invalidData, writeContext); + try { + customizer.writeCurrentAttributes(emptyId, invalidData, writeContext); + } catch (NullPointerException e) { + verify(api, times(0)).lispAddDelAdjacency(any()); + return; + } + + fail("Test should have failed while reading parent vni table id"); } + @Test public void writeCurrentAttributes() throws Exception { + when(localMappingContext.containsId( + any(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.local.mapping.Eid.class), + any( + MappingContext.class))).thenReturn(true); + + when(remoteMappingContext.containsId( + any(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.Eid.class), + any( + MappingContext.class))).thenReturn(true); + customizer.writeCurrentAttributes(validId, validData, writeContext); verify(api, times(1)).lispAddDelAdjacency(requestCaptor.capture()); verifyRequest(requestCaptor.getValue(), 1, new byte[]{-64, -88, 2, 1}, 32, new byte[]{-64, -88, 5, 2}, 32, IPV4.getValue(), 2); } + @Test + public void writeCurrentAttributesNonExistingLocalMapping() throws Exception { + when(localMappingContext.containsId( + any(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.local.mapping.Eid.class), + any(MappingContext.class))).thenReturn(false); + + when(remoteMappingContext.containsId( + any(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.Eid.class), + any(MappingContext.class))).thenReturn(true); + try { + customizer.writeCurrentAttributes(validId, validData, writeContext); + } catch (IllegalStateException e) { + verify(api, times(0)).lispAddDelAdjacency(any()); + return; + } + + fail("Test should have failed while verifying local eid"); + } + + @Test + public void writeCurrentAttributesNonExistingRemoteMapping() throws Exception { + when(localMappingContext.containsId( + any(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.local.mapping.Eid.class), + any(MappingContext.class))).thenReturn(true); + + when(remoteMappingContext.containsId( + any(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.Eid.class), + any(MappingContext.class))).thenReturn(false); + try { + customizer.writeCurrentAttributes(validId, validData, writeContext); + } catch (IllegalStateException e) { + verify(api, times(0)).lispAddDelAdjacency(any()); + return; + } + + fail("Test should have failed while verifying remote eid"); + } + @Test(expected = UnsupportedOperationException.class) public void updateCurrentAttributes() throws Exception { customizer.updateCurrentAttributes(emptyId, emptyData, emptyData, writeContext); } - @Test(expected = IllegalStateException.class) + @Test public void deleteCurrentAttributesNoKey() throws Exception { - customizer.deleteCurrentAttributes(emptyId, emptyData, writeContext); + try { + customizer.deleteCurrentAttributes(emptyId, emptyData, writeContext); + } catch (NullPointerException e) { + verify(api, times(0)).lispAddDelAdjacency(any()); + return; + } + + fail("Test should have failed while reading parent vni table id"); } @Test(expected = IllegalArgumentException.class) diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/BridgeDomainCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/BridgeDomainCustomizerTest.java new file mode 100644 index 000000000..189570cb1 --- /dev/null +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/BridgeDomainCustomizerTest.java @@ -0,0 +1,92 @@ +package io.fd.honeycomb.lisp.translate.write; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import io.fd.honeycomb.lisp.translate.write.trait.SubtableWriterTestCase; +import io.fd.honeycomb.translate.vpp.util.NamingContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.vpp.jvpp.VppCallbackException; +import org.junit.Before; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.EidTable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTableKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.BridgeDomainSubtable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.BridgeDomainSubtableBuilder; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class BridgeDomainCustomizerTest extends SubtableWriterTestCase { + + private BridgeDomainSubtableCustomizer customizer; + private InstanceIdentifier<BridgeDomainSubtable> validId; + private BridgeDomainSubtable validData; + private NamingContext bridgeDomainContext; + + @Before + public void init() { + bridgeDomainContext = new NamingContext("br", "bridge-domain-context"); + customizer = new BridgeDomainSubtableCustomizer(api, bridgeDomainContext); + validId = InstanceIdentifier.create(EidTable.class).child(VniTable.class, new VniTableKey(12L)) + .child(BridgeDomainSubtable.class); + validData = new BridgeDomainSubtableBuilder().setBridgeDomainRef("br-domain").build(); + defineMapping(mappingContext, "br-domain", 10, "bridge-domain-context"); + } + + @Test + public void testWriteSuccessfull() throws WriteFailedException { + whenAddDelEidTableAddDelMapSuccess(); + customizer.writeCurrentAttributes(validId, validData, writeContext); + verifyAddDelEidTableAddDelMapInvokedCorrectly(1, 12, 10, 1); + } + + @Test + public void testWriteFailed() throws WriteFailedException { + whenAddDelEidTableAddDelMapFail(); + + try { + customizer.writeCurrentAttributes(validId, validData, writeContext); + } catch (Exception e) { + assertTrue(e instanceof WriteFailedException); + + final WriteFailedException realException = ((WriteFailedException) e); + assertEquals(validId, realException.getFailedId()); + assertTrue(e.getCause() instanceof VppCallbackException); + return; + } + + fail("Test should throw exception"); + } + + @Test(expected = UnsupportedOperationException.class) + public void testUpdate() throws WriteFailedException { + customizer.updateCurrentAttributes(validId, validData, validData, writeContext); + } + + @Test + public void testDeleteSuccessfull() throws WriteFailedException { + whenAddDelEidTableAddDelMapSuccess(); + customizer.deleteCurrentAttributes(validId, validData, writeContext); + verifyAddDelEidTableAddDelMapInvokedCorrectly(0, 12, 10, 1); + } + + @Test + public void testDeleteFailed() { + whenAddDelEidTableAddDelMapFail(); + + try { + customizer.deleteCurrentAttributes(validId, validData, writeContext); + } catch (Exception e) { + assertTrue(e instanceof WriteFailedException); + + final WriteFailedException realException = ((WriteFailedException) e); + assertEquals(validId, realException.getFailedId()); + assertTrue(e.getCause() instanceof VppCallbackException); + return; + } + + fail("Test should throw exception"); + } + +} diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/InterfaceCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/InterfaceCustomizerTest.java index 8abd07e7e..e68c97674 100755 --- a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/InterfaceCustomizerTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/InterfaceCustomizerTest.java @@ -32,6 +32,7 @@ import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.Lisp; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.lisp.feature.data.grouping.LispFeatureData; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.locator.sets.grouping.LocatorSets; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.locator.sets.grouping.locator.sets.LocatorSet; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.locator.sets.grouping.locator.sets.LocatorSetKey; @@ -58,6 +59,7 @@ public class InterfaceCustomizerTest extends WriterCustomizerTest implements Byt defineMapping(mappingContext, interfaceName, 5, ifcCtxName); id = InstanceIdentifier.builder(Lisp.class) + .child(LispFeatureData.class) .child(LocatorSets.class) .child(LocatorSet.class, new LocatorSetKey("Locator")) .child(Interface.class, new InterfaceKey(interfaceName)) diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/ItrRemoteLocatorSetCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/ItrRemoteLocatorSetCustomizerTest.java new file mode 100644 index 000000000..97806c542 --- /dev/null +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/ItrRemoteLocatorSetCustomizerTest.java @@ -0,0 +1,130 @@ +package io.fd.honeycomb.lisp.translate.write; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; + +import io.fd.honeycomb.translate.vpp.util.ByteDataTranslator; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest; +import io.fd.vpp.jvpp.VppCallbackException; +import io.fd.vpp.jvpp.core.dto.LispAddDelMapRequestItrRlocs; +import io.fd.vpp.jvpp.core.dto.LispAddDelMapRequestItrRlocsReply; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import org.junit.Before; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.itr.remote.locator.sets.grouping.ItrRemoteLocatorSet; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.itr.remote.locator.sets.grouping.ItrRemoteLocatorSetBuilder; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class ItrRemoteLocatorSetCustomizerTest extends WriterCustomizerTest implements ByteDataTranslator { + + private static final String VALID_NAME = "loc-set"; + + @Captor + private ArgumentCaptor<LispAddDelMapRequestItrRlocs> requestCaptor; + + private ItrRemoteLocatorSetCustomizer customizer; + private InstanceIdentifier<ItrRemoteLocatorSet> validId; + private ItrRemoteLocatorSet validData; + + @Before + public void setUp() throws Exception { + initMocks(this); + customizer = new ItrRemoteLocatorSetCustomizer(api); + validId = InstanceIdentifier.create(ItrRemoteLocatorSet.class); + validData = new ItrRemoteLocatorSetBuilder().setRemoteLocatorSetName(VALID_NAME).build(); + } + + @Test + public void writeCurrentAttributesSuccess() throws Exception { + onWriteSuccess(); + customizer.writeCurrentAttributes(validId, validData, writeContext); + verifyWriteInvoked(true, VALID_NAME); + } + + @Test + public void writeCurrentAttributesFailed() { + onWriteThrow(); + + try { + customizer.writeCurrentAttributes(validId, validData, writeContext); + } catch (WriteFailedException e) { + assertTrue(e.getCause() instanceof VppCallbackException); + verifyWriteInvoked(true, VALID_NAME); + return; + } + + fail("Test should have thrown exception"); + } + + @Test + public void updateCurrentAttributes() { + try { + customizer.updateCurrentAttributes(validId, validData, validData, writeContext); + } catch (WriteFailedException e) { + assertTrue(e.getCause() instanceof UnsupportedOperationException); + return; + } + + fail("Test should have thrown exception"); + } + + @Test + public void deleteCurrentAttributesSuccess() throws Exception { + onWriteSuccess(); + customizer.deleteCurrentAttributes(validId, validData, writeContext); + verifyWriteInvoked(false, VALID_NAME); + } + + @Test + public void deleteCurrentAttributesFailed() throws Exception { + onWriteThrow(); + + try { + customizer.writeCurrentAttributes(validId, validData, writeContext); + } catch (WriteFailedException e) { + assertTrue(e.getCause() instanceof VppCallbackException); + verifyWriteInvoked(true, VALID_NAME); + return; + } + + fail("Test should have thrown exception"); + } + + private void onWriteSuccess() { + when(api.lispAddDelMapRequestItrRlocs(any(LispAddDelMapRequestItrRlocs.class))) + .thenReturn(CompletableFuture.completedFuture(new LispAddDelMapRequestItrRlocsReply())); + } + + private void onWriteThrow() { + when(api.lispAddDelMapRequestItrRlocs(any(LispAddDelMapRequestItrRlocs.class))) + .thenReturn(new CompletableFuture<LispAddDelMapRequestItrRlocsReply>() { + @Override + public LispAddDelMapRequestItrRlocsReply get(final long l, final TimeUnit timeUnit) + throws InterruptedException, ExecutionException, TimeoutException { + throw new ExecutionException(new VppCallbackException("lispAddDelMapRequestItrRlocs", 1, -2)); + } + }); + } + + private void verifyWriteInvoked(final boolean add, final String name) { + verify(api, times(1)).lispAddDelMapRequestItrRlocs(requestCaptor.capture()); + + final LispAddDelMapRequestItrRlocs request = requestCaptor.getValue(); + assertNotNull(request); + assertEquals(booleanToByte(add), request.isAdd); + assertEquals(name, toString(request.locatorSetName)); + } +}
\ No newline at end of file diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/LocalMappingCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/LocalMappingCustomizerTest.java index 14867f049..4e24b3f3f 100755 --- a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/LocalMappingCustomizerTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/LocalMappingCustomizerTest.java @@ -36,18 +36,21 @@ import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv4Afi; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Builder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.Lisp; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.MappingId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.LocalMappings; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.LocalMapping; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.LocalMappingBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.LocalMappingKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.local.mapping.Eid; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.local.mappings.local.mapping.EidBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.EidTable; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTable; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTableKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.LocalMappings; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.local.mappings.LocalMapping; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.local.mappings.LocalMappingBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.local.mappings.LocalMappingKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.local.mappings.local.mapping.Eid; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.local.mappings.local.mapping.EidBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.VrfSubtable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.lisp.feature.data.grouping.LispFeatureData; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import io.fd.vpp.jvpp.core.dto.LispAddDelLocalEid; import io.fd.vpp.jvpp.core.dto.LispAddDelLocalEidReply; @@ -66,10 +69,12 @@ public class LocalMappingCustomizerTest extends WriterCustomizerTest implements @Override public void setUp() { final Eid - eid = new EidBuilder().setAddress( - new Ipv4Builder().setIpv4( - new Ipv4Address("192.168.2.1")) - .build()) + eid = new EidBuilder() + .setAddressType(Ipv4Afi.class) + .setAddress( + new Ipv4Builder().setIpv4( + new Ipv4Address("192.168.2.1")) + .build()) .build(); mapping = new LocalMappingBuilder() @@ -78,8 +83,10 @@ public class LocalMappingCustomizerTest extends WriterCustomizerTest implements .build(); id = InstanceIdentifier.builder(Lisp.class) + .child(LispFeatureData.class) .child(EidTable.class) .child(VniTable.class, new VniTableKey(25L)) + .child(VrfSubtable.class) .child(LocalMappings.class) .child(LocalMapping.class, new LocalMappingKey(new MappingId("local"))) .build(); diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/RemoteMappingCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/RemoteMappingCustomizerTest.java index 6afce0113..a1f0dc792 100755 --- a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/RemoteMappingCustomizerTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/RemoteMappingCustomizerTest.java @@ -29,28 +29,32 @@ import io.fd.honeycomb.lisp.context.util.EidMappingContext; import io.fd.honeycomb.translate.vpp.util.Ipv4Translator; import io.fd.honeycomb.translate.write.WriteFailedException; import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest; +import io.fd.vpp.jvpp.core.dto.LispAddDelRemoteMapping; +import io.fd.vpp.jvpp.core.dto.LispAddDelRemoteMappingReply; import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.Ipv4Afi; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Builder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.Lisp; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.MapReplyAction; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.MappingId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.RemoteMappings; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.RemoteMapping; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.RemoteMappingBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.RemoteMappingKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.Eid; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.EidBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.locator.list.NegativeMappingBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.dp.subtable.grouping.remote.mappings.remote.mapping.locator.list.negative.mapping.MapReplyBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.EidTable; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTable; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTableKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.RemoteMappings; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.RemoteMapping; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.RemoteMappingBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.RemoteMappingKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.remote.mapping.Eid; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.remote.mapping.EidBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.remote.mappings.remote.mapping.locator.list.NegativeMappingBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.VrfSubtable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.lisp.feature.data.grouping.LispFeatureData; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.core.dto.LispAddDelRemoteMapping; -import io.fd.vpp.jvpp.core.dto.LispAddDelRemoteMappingReply; public class RemoteMappingCustomizerTest extends WriterCustomizerTest implements Ipv4Translator { @@ -67,10 +71,12 @@ public class RemoteMappingCustomizerTest extends WriterCustomizerTest implements @Override public void setUp() { - final Eid eid = new EidBuilder().setAddress( - new Ipv4Builder().setIpv4( - new Ipv4Address("192.168.2.1")) - .build()) + final Eid eid = new EidBuilder() + .setAddressType(Ipv4Afi.class) + .setAddress( + new Ipv4Builder().setIpv4( + new Ipv4Address("192.168.2.1")) + .build()) .build(); mappingId = new MappingId("REMOTE"); @@ -79,11 +85,15 @@ public class RemoteMappingCustomizerTest extends WriterCustomizerTest implements intf = new RemoteMappingBuilder() .setEid( eid) - .setLocatorList(new NegativeMappingBuilder().setMapReplyAction(MapReplyAction.Drop).build()) + .setLocatorList(new NegativeMappingBuilder() + .setMapReply(new MapReplyBuilder().setMapReplyAction(MapReplyAction.Drop).build()).build()) .build(); - id = InstanceIdentifier.builder(Lisp.class).child(EidTable.class) + id = InstanceIdentifier.builder(Lisp.class) + .child(LispFeatureData.class) + .child(EidTable.class) .child(VniTable.class, new VniTableKey(25L)) + .child(VrfSubtable.class) .child(RemoteMappings.class) .child(RemoteMapping.class, key).build(); diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/VniTableCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/VniTableCustomizerTest.java index 126498304..4df89dfa3 100644 --- a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/VniTableCustomizerTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/VniTableCustomizerTest.java @@ -1,86 +1,87 @@ package io.fd.honeycomb.lisp.translate.write; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; + +import static org.junit.Assert.fail; import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; +import com.google.common.base.Optional; +import io.fd.honeycomb.translate.write.WriteFailedException; import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest; import org.junit.Before; import org.junit.Test; -import org.mockito.ArgumentCaptor; -import org.mockito.Captor; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTable; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTableBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.VrfSubtableBuilder; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import io.fd.vpp.jvpp.core.dto.LispEidTableAddDelMap; -import io.fd.vpp.jvpp.core.dto.LispEidTableAddDelMapReply; - public class VniTableCustomizerTest extends WriterCustomizerTest { - @Captor - private ArgumentCaptor<LispEidTableAddDelMap> requestCaptor; - private VniTableCustomizer customizer; - private InstanceIdentifier<VniTable> emptyId; - - private VniTable emptyData; + private InstanceIdentifier<VniTable> validId; private VniTable validData; @Before public void init() { + initMocks(this); customizer = new VniTableCustomizer(api); - emptyId = InstanceIdentifier.create(VniTable.class); - - emptyData = new VniTableBuilder().build(); - validData = new VniTableBuilder().setTableId(2L).setVirtualNetworkIdentifier(3L).build(); + validId = InstanceIdentifier.create(VniTable.class); + validData = new VniTableBuilder() + .setVrfSubtable(new VrfSubtableBuilder() + .build()).build(); + } - when(api.lispEidTableAddDelMap(any())).thenReturn(future(new LispEidTableAddDelMapReply())); + @Test + public void testWriteSuccessfull() { + whenReadAfterReturnValid(); + try { + customizer.writeCurrentAttributes(validId, validData, writeContext); + } catch (Exception e) { + fail("Test should pass without exception"); + } } - @Test(expected = NullPointerException.class) - public void testWriteCurrentAttributesEmptyData() throws Exception { - customizer.writeCurrentAttributes(emptyId, emptyData, writeContext); + @Test(expected = IllegalStateException.class) + public void testWriteFailed() throws WriteFailedException { + whenReadAfterReturnInvalid(); + customizer.writeCurrentAttributes(validId, validData, writeContext); } + @Test(expected = UnsupportedOperationException.class) + public void testUpdate() throws WriteFailedException { + customizer.updateCurrentAttributes(validId, validData, validData, writeContext); + } @Test - public void testWriteCurrentAttributes() throws Exception { - customizer.writeCurrentAttributes(emptyId, validData, writeContext); - verify(api, times(1)).lispEidTableAddDelMap(requestCaptor.capture()); - verifyRequest(requestCaptor.getValue(), (byte) 1, 2L, 3L); + public void testDeleteSuccessfull() { + whenReadBeforeReturnValid(); + try { + customizer.deleteCurrentAttributes(validId, validData, writeContext); + } catch (Exception e) { + fail("Test should pass without exception"); + } } - - @Test(expected = UnsupportedOperationException.class) - public void testUpdateCurrentAttributes() throws Exception { - customizer.updateCurrentAttributes(emptyId, emptyData, emptyData, writeContext); + @Test(expected = IllegalStateException.class) + public void testDeleteFailed() throws WriteFailedException { + whenReadBeforeReturnInvalid(); + customizer.deleteCurrentAttributes(validId, validData, writeContext); } - @Test(expected = NullPointerException.class) - public void testDeleteCurrentAttributesEmptyData() throws Exception { - customizer.deleteCurrentAttributes(emptyId, emptyData, writeContext); + private void whenReadBeforeReturnValid() { + when(writeContext.readBefore(validId)).thenReturn(Optional.of(validData)); } - @Test - public void testDeleteCurrentAttributes() throws Exception { - customizer.deleteCurrentAttributes(emptyId, validData, writeContext); - verify(api, times(1)).lispEidTableAddDelMap(requestCaptor.capture()); - verifyRequest(requestCaptor.getValue(), (byte) 0, 2L, 3L); + private void whenReadBeforeReturnInvalid() { + when(writeContext.readBefore(validId)).thenReturn(Optional.absent()); } - private static void verifyRequest(final LispEidTableAddDelMap request, final byte isAdd, - final long dpTable, - final long vni) { - assertNotNull(request); - assertEquals(isAdd, request.isAdd); - assertEquals(dpTable, request.dpTable); - assertEquals(vni, request.vni); - + private void whenReadAfterReturnValid() { + when(writeContext.readAfter(validId)).thenReturn(Optional.of(validData)); } + private void whenReadAfterReturnInvalid() { + when(writeContext.readAfter(validId)).thenReturn(Optional.absent()); + } }
\ No newline at end of file diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/VrfSubtableCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/VrfSubtableCustomizerTest.java new file mode 100644 index 000000000..a6c530430 --- /dev/null +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/VrfSubtableCustomizerTest.java @@ -0,0 +1,89 @@ +package io.fd.honeycomb.lisp.translate.write; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import io.fd.honeycomb.lisp.translate.write.trait.SubtableWriterTestCase; +import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.vpp.jvpp.VppCallbackException; +import org.junit.Before; +import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.EidTable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.VniTableKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.VrfSubtable; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.eid.table.grouping.eid.table.vni.table.VrfSubtableBuilder; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class VrfSubtableCustomizerTest extends SubtableWriterTestCase { + + private VrfSubtableCustomizer customizer; + private InstanceIdentifier<VrfSubtable> validId; + private VrfSubtable validData; + + @Before + public void init() { + customizer = new VrfSubtableCustomizer(api); + validId = InstanceIdentifier.create(EidTable.class).child(VniTable.class, new VniTableKey(12L)) + .child(VrfSubtable.class); + validData = new VrfSubtableBuilder().setTableId(10L).build(); + } + + @Test + public void testWriteSuccessfull() throws WriteFailedException { + whenAddDelEidTableAddDelMapSuccess(); + + customizer.writeCurrentAttributes(validId, validData, writeContext); + verifyAddDelEidTableAddDelMapInvokedCorrectly(1, 12, 10, 0); + } + + @Test + public void testWriteFailed() { + whenAddDelEidTableAddDelMapFail(); + + try { + customizer.writeCurrentAttributes(validId, validData, writeContext); + } catch (Exception e) { + assertTrue(e instanceof WriteFailedException); + + final WriteFailedException realException = ((WriteFailedException) e); + assertEquals(validId, realException.getFailedId()); + assertTrue(e.getCause() instanceof VppCallbackException); + return; + } + + fail("Test should throw exception"); + } + + @Test(expected = UnsupportedOperationException.class) + public void testUpdate() throws WriteFailedException { + customizer.updateCurrentAttributes(validId, validData, validData, writeContext); + } + + @Test + public void testDeleteSuccessfull() throws WriteFailedException { + whenAddDelEidTableAddDelMapSuccess(); + + customizer.deleteCurrentAttributes(validId, validData, writeContext); + verifyAddDelEidTableAddDelMapInvokedCorrectly(0, 12, 10, 0); + } + + @Test + public void testDeleteFailed() { + whenAddDelEidTableAddDelMapFail(); + + try { + customizer.deleteCurrentAttributes(validId, validData, writeContext); + } catch (Exception e) { + assertTrue(e instanceof WriteFailedException); + + final WriteFailedException realException = ((WriteFailedException) e); + assertEquals(validId, realException.getFailedId()); + assertTrue(e.getCause() instanceof VppCallbackException); + return; + } + + fail("Test should throw exception"); + } +} diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/trait/SubtableWriterTestCase.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/trait/SubtableWriterTestCase.java new file mode 100644 index 000000000..453add9f0 --- /dev/null +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/translate/write/trait/SubtableWriterTestCase.java @@ -0,0 +1,43 @@ +package io.fd.honeycomb.lisp.translate.write.trait; + + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import io.fd.honeycomb.vpp.test.write.WriterCustomizerTest; +import io.fd.vpp.jvpp.core.dto.LispEidTableAddDelMap; +import io.fd.vpp.jvpp.core.dto.LispEidTableAddDelMapReply; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.mockito.Mockito; + +public class SubtableWriterTestCase extends WriterCustomizerTest implements SubtableWriter { + @Captor + protected ArgumentCaptor<LispEidTableAddDelMap> requestCaptor; + + + protected void verifyAddDelEidTableAddDelMapInvokedCorrectly(final int addDel, final int vni, final int tableId, + final int isL2) { + verify(api, times(1)).lispEidTableAddDelMap(requestCaptor.capture()); + + final LispEidTableAddDelMap request = requestCaptor.getValue(); + assertNotNull(request); + assertEquals(addDel, request.isAdd); + assertEquals(vni, request.vni); + assertEquals(tableId, request.dpTable); + assertEquals(isL2, request.isL2); + } + + protected void whenAddDelEidTableAddDelMapSuccess() { + when(api.lispEidTableAddDelMap(Mockito.any(LispEidTableAddDelMap.class))) + .thenReturn(future(new LispEidTableAddDelMapReply())); + } + + protected void whenAddDelEidTableAddDelMapFail() { + when(api.lispEidTableAddDelMap(Mockito.any(LispEidTableAddDelMap.class))) + .thenReturn(failedFuture()); + } +} diff --git a/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/util/EidMappingContextHelper.java b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/util/EidMappingContextHelper.java new file mode 100644 index 000000000..436cd6c25 --- /dev/null +++ b/lisp/lisp2vpp/src/test/java/io/fd/honeycomb/lisp/util/EidMappingContextHelper.java @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.lisp.util; + + +import static org.mockito.Mockito.doReturn; + +import com.google.common.base.Optional; +import com.google.common.collect.Lists; +import io.fd.honeycomb.translate.MappingContext; +import java.util.List; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.Contexts; +import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.EidMappingContext; +import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.EidMappingContextKey; +import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.eid.mapping.context.Mappings; +import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.eid.mapping.context.MappingsBuilder; +import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.eid.mapping.context.mappings.Mapping; +import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.eid.mapping.context.mappings.MappingBuilder; +import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.eid.mapping.context.mappings.MappingKey; +import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.eid.mapping.context.mappings.mapping.Eid; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev160520.MappingId; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; + +/** + * Utility class to stub {@link EidMappingContext} + * + * TODO - HONEYCOMB-237 - generalize logic for naming context and eid mapping context helper utils if possible + */ +public interface EidMappingContextHelper { + + /** + * Creates {@link Mapping} for given data. + * + * @param eid to be mapped + * @param id to be mapped @return eid to id mapping + */ + default Optional<Mapping> mapping(@Nonnull final Eid eid, final MappingId id) { + return Optional.of(new MappingBuilder().setEid(eid).setId(id).build()); + } + + /** + * Creates {@link KeyedInstanceIdentifier} for {@link Mapping} in {@link EidMappingContext}. + * + * @param id identificator of the mapping + * @param mappingContextName identificator of the mapping context + * @return identifier for the mapping + */ + default KeyedInstanceIdentifier<Mapping, MappingKey> mappingIid(@Nonnull final MappingId id, + @Nonnull final String mappingContextName) { + return InstanceIdentifier.create(Contexts.class).child(EidMappingContext.class, + new EidMappingContextKey(mappingContextName)).child(Mappings.class) + .child(Mapping.class, new MappingKey(id)); + } + + /** + * Stubs {@link MappingContext#read} to include given mapping in {@link EidMappingContext}. + * + * @param mappingContext mock instance of {@link MappingContext} + * @param eid name of the mapping + * @param mappingName index to be mapped + * @param namingContextName name of the naming context + */ + default void defineMapping(@Nonnull final MappingContext mappingContext, @Nonnull final Eid eid, + final MappingId mappingName, @Nonnull final String namingContextName) { + final KeyedInstanceIdentifier<Mapping, MappingKey> mappingIid = mappingIid(mappingName, namingContextName); + final InstanceIdentifier<Mappings> mappingsIid = mappingIid.firstIdentifierOf(Mappings.class); + + final Optional<Mapping> singleMapping = mapping(eid, mappingName); + final List<Mapping> list = Common.getMappingList(mappingContext, mappingsIid); + list.add(singleMapping.get()); + + doReturn(Optional.of(new MappingsBuilder().setMapping(list).build())).when(mappingContext).read(mappingsIid); + doReturn(singleMapping).when(mappingContext).read(mappingIid); + } + + final class Common { + private static List<Mapping> getMappingList(@Nonnull final MappingContext mappingContext, + @Nonnull final InstanceIdentifier<Mappings> mappingsIid) { + final Optional<Mappings> previousMappings = mappingContext.read(mappingsIid); + final MappingsBuilder mappingsBuilder; + if (previousMappings != null && previousMappings.isPresent()) { + mappingsBuilder = new MappingsBuilder(previousMappings.get()); + } else { + mappingsBuilder = new MappingsBuilder(); + mappingsBuilder.setMapping(Lists.newArrayList()); + } + return mappingsBuilder.getMapping(); + } + } +} |