diff options
Diffstat (limited to 'lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read')
3 files changed, 188 insertions, 24 deletions
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/AdjacencyCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/AdjacencyCustomizerTest.java index ad65a7604..92c5abcfe 100644 --- a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/AdjacencyCustomizerTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/AdjacencyCustomizerTest.java @@ -19,8 +19,12 @@ package io.fd.hc2vpp.lisp.translate.read; import static io.fd.hc2vpp.lisp.translate.AdjacencyData.ADDRESS_ONE; import static io.fd.hc2vpp.lisp.translate.AdjacencyData.ADDRESS_THREE; import static io.fd.hc2vpp.lisp.translate.AdjacencyData.LOCAL_EID_ONE; +import static io.fd.hc2vpp.lisp.translate.AdjacencyData.LOCAL_EID_PREFIX_ONE; +import static io.fd.hc2vpp.lisp.translate.AdjacencyData.LOCAL_EID_PREFIX_TWO; import static io.fd.hc2vpp.lisp.translate.AdjacencyData.LOCAL_EID_TWO; import static io.fd.hc2vpp.lisp.translate.AdjacencyData.REMOTE_EID_ONE; +import static io.fd.hc2vpp.lisp.translate.AdjacencyData.REMOTE_EID_PREFIX_ONE; +import static io.fd.hc2vpp.lisp.translate.AdjacencyData.REMOTE_EID_PREFIX_TWO; import static io.fd.hc2vpp.lisp.translate.AdjacencyData.REMOTE_EID_TWO; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; @@ -43,6 +47,7 @@ import java.util.List; 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.lisp.address.address.Ipv4; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Prefix; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.MappingId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.adjacencies.grouping.Adjacencies; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.adjacencies.grouping.AdjacenciesBuilder; @@ -63,6 +68,8 @@ public class AdjacencyCustomizerTest extends ListReaderCustomizerTest<Adjacency, AdjacencyKey, AdjacencyBuilder> implements ByteDataTranslator, EidMetadataProvider, EidMappingContextHelper, AdjacencyMappingContextTestHelper { + public static final String NORMALIZED_PREFIX_ONE = "192.168.2.0/24"; + public static final String NORMALIZED_PREFIX_THREE = "192.168.0.0/16"; private InstanceIdentifier<Adjacency> identifier; public AdjacencyCustomizerTest() { @@ -78,23 +85,30 @@ public class AdjacencyCustomizerTest .child(RemoteMapping.class, new RemoteMappingKey(new MappingId("remote-mapping"))) .child(Adjacencies.class) .child(Adjacency.class, new AdjacencyKey("adj-one")); + defineAdjacencyMapping(mappingContext, "local-eid-one", "remote-eid-one", "adj-one", + "adjacencies-mapping-context"); + defineAdjacencyMapping(mappingContext, "local-eid-two", "remote-eid-two", "adj-two", + "adjacencies-mapping-context"); + } - - mockApi(); + private void defineEidAddressMapping() { defineEidMapping(mappingContext, LOCAL_EID_ONE, new MappingId("local-eid-one"), "local-mapping-context"); defineEidMapping(mappingContext, LOCAL_EID_TWO, new MappingId("local-eid-two"), "local-mapping-context"); defineEidMapping(mappingContext, REMOTE_EID_ONE, new MappingId("remote-eid-one"), "remote-mapping-context"); defineEidMapping(mappingContext, REMOTE_EID_TWO, new MappingId("remote-eid-two"), "remote-mapping-context"); + } - defineAdjacencyMapping(mappingContext, "local-eid-one", "remote-eid-one", "adj-one", - "adjacencies-mapping-context"); - defineAdjacencyMapping(mappingContext, "local-eid-two", "remote-eid-two", "adj-two", - "adjacencies-mapping-context"); - mockApi(); + private void defineEidPrefixMapping() { + defineEidMapping(mappingContext, LOCAL_EID_PREFIX_ONE, new MappingId("local-eid-one"), "local-mapping-context"); + defineEidMapping(mappingContext, LOCAL_EID_PREFIX_TWO, new MappingId("local-eid-two"), "local-mapping-context"); + defineEidMapping(mappingContext, REMOTE_EID_PREFIX_ONE, new MappingId("remote-eid-one"), "remote-mapping-context"); + defineEidMapping(mappingContext, REMOTE_EID_PREFIX_TWO, new MappingId("remote-eid-two"), "remote-mapping-context"); } @Test public void getAllIds() throws Exception { + mockAddressDump(); + defineEidAddressMapping(); final List<AdjacencyKey> keys = getCustomizer().getAllIds(identifier, ctx); assertThat(keys, hasSize(2)); @@ -103,6 +117,8 @@ public class AdjacencyCustomizerTest @Test public void readCurrentAttributes() throws Exception { + mockAddressDump(); + defineEidAddressMapping(); final AdjacencyBuilder builder = new AdjacencyBuilder(); getCustomizer().readCurrentAttributes(identifier, builder, ctx); @@ -113,6 +129,21 @@ public class AdjacencyCustomizerTest Ipv4.class.cast(builder.getRemoteEid().getAddress()).getIpv4().getValue()); } + @Test + public void readCurrentAttributesPrefixBased() throws Exception { + mockPrefixDump(); + defineEidPrefixMapping(); + final AdjacencyBuilder builder = new AdjacencyBuilder(); + getCustomizer().readCurrentAttributes(identifier, builder, ctx); + + assertEquals("adj-one", builder.getId()); + assertEquals(new AdjacencyKey("adj-one"), builder.getKey()); + assertEquals(NORMALIZED_PREFIX_ONE, + Ipv4Prefix.class.cast(builder.getLocalEid().getAddress()).getIpv4Prefix().getValue()); + assertEquals(NORMALIZED_PREFIX_THREE, + Ipv4Prefix.class.cast(builder.getRemoteEid().getAddress()).getIpv4Prefix().getValue()); + } + @Override protected ReaderCustomizer<Adjacency, AdjacencyBuilder> initCustomizer() { return new AdjacencyCustomizer(api, new EidMappingContext("local-mapping-context", "local-mapping-"), @@ -121,7 +152,7 @@ public class AdjacencyCustomizerTest } - private void mockApi() { + private void mockAddressDump() { OneAdjacency adjacencyOne = new OneAdjacency(); adjacencyOne.eidType = 0; adjacencyOne.leid = new byte[]{-64, -88, 2, 1}; @@ -142,4 +173,26 @@ public class AdjacencyCustomizerTest when(api.oneAdjacenciesGet(any())).thenReturn(future(reply)); } + + private void mockPrefixDump() { + OneAdjacency adjacencyOne = new OneAdjacency(); + adjacencyOne.eidType = 0; + adjacencyOne.leid = new byte[]{-64, -88, 2, 1}; + adjacencyOne.leidPrefixLen = 24; + adjacencyOne.reid = new byte[]{-64, -88, 2, 3}; + adjacencyOne.reidPrefixLen = 16; + + + OneAdjacency adjacencyTwo = new OneAdjacency(); + adjacencyTwo.eidType = 0; + adjacencyTwo.leid = new byte[]{-64, -88, 2, 2}; + adjacencyTwo.leidPrefixLen = 28; + adjacencyTwo.reid = new byte[]{-64, -88, 2, 4}; + adjacencyTwo.reidPrefixLen = 8; + + OneAdjacenciesGetReply reply = new OneAdjacenciesGetReply(); + reply.adjacencies = new OneAdjacency[]{adjacencyOne, adjacencyTwo}; + + when(api.oneAdjacenciesGet(any())).thenReturn(future(reply)); + } }
\ No newline at end of file diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/LocalMappingCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/LocalMappingCustomizerTest.java index 53fbc568b..11fe30dc5 100644 --- a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/LocalMappingCustomizerTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/LocalMappingCustomizerTest.java @@ -17,6 +17,7 @@ package io.fd.hc2vpp.lisp.translate.read; import static io.fd.hc2vpp.lisp.translate.read.dump.executor.params.MappingsDumpParams.EidType.IPV4; +import static io.fd.hc2vpp.lisp.translate.read.dump.executor.params.MappingsDumpParams.EidType.IPV4_PREFIX; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.mockito.Matchers.any; @@ -40,6 +41,8 @@ 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.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Prefix; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4PrefixBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.HmacKeyType; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.MappingId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.dp.subtable.grouping.LocalMappings; @@ -61,6 +64,9 @@ public class LocalMappingCustomizerTest extends private static final Ipv4 EID_ADDRESS = new Ipv4Builder().setIpv4(new Ipv4Address("192.168.2.1")).build(); + private static final Ipv4Prefix + EID_V4_PREFIX_ADDRESS = new Ipv4PrefixBuilder().setIpv4Prefix(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix("192.168.2.1/28")).build(); + @Mock private EidMappingContext localMappingContext; @@ -84,11 +90,9 @@ public class LocalMappingCustomizerTest extends .child(VrfSubtable.class) .child(LocalMappings.class) .child(LocalMapping.class, new LocalMappingKey(new MappingId("local-mapping"))); - - defineMappings(); } - private void defineDumpData() { + private void defineV4AddressDumpData() { OneEidTableDetailsReplyDump replyDump = new OneEidTableDetailsReplyDump(); OneEidTableDetails detail = new OneEidTableDetails(); detail.action = 0; @@ -96,7 +100,27 @@ public class LocalMappingCustomizerTest extends detail.context = 4; detail.eid = new byte[]{-64, -88, 2, 1}; detail.eidPrefixLen = 32; - detail.eidType = (byte) IPV4.getValue(); + detail.eidType = (byte) IPV4.getVppTypeBinding(); + detail.isLocal = 1; + detail.locatorSetIndex = 1; + detail.ttl = 7; + detail.vni = 12; + detail.key = "abcdefgh".getBytes(StandardCharsets.UTF_8); + detail.keyId = 1; + + replyDump.oneEidTableDetails = ImmutableList.of(detail); + when(api.oneEidTableDump(any())).thenReturn(future(replyDump)); + } + + private void defineV4PrefixDumpData() { + OneEidTableDetailsReplyDump replyDump = new OneEidTableDetailsReplyDump(); + OneEidTableDetails detail = new OneEidTableDetails(); + detail.action = 0; + detail.authoritative = 1; + detail.context = 4; + detail.eid = new byte[]{-64, -88, 2, 1}; + detail.eidPrefixLen = 28; + detail.eidType = (byte) IPV4_PREFIX.getVppTypeBinding(); detail.isLocal = 1; detail.locatorSetIndex = 1; detail.ttl = 7; @@ -116,7 +140,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.eidType = (byte) IPV4.getVppTypeBinding(); detail.isLocal = 1; detail.locatorSetIndex = 1; detail.ttl = 7; @@ -126,7 +150,7 @@ public class LocalMappingCustomizerTest extends when(api.oneEidTableDump(any())).thenReturn(future(replyDump)); } - private void defineMappings() { + private void defineAddressMappings() { //eid mapping when(localMappingContext.getId(any(Eid.class), any(MappingContext.class))) @@ -138,8 +162,21 @@ public class LocalMappingCustomizerTest extends defineMapping(mappingContext, "loc-set", 1, "locator-set-context"); } + private void definePrefixMappings() { + //eid mapping + + when(localMappingContext.getId(any(Eid.class), any(MappingContext.class))) + .thenReturn(new MappingId("local-mapping")); + when(localMappingContext.containsEid(new MappingId("local-mapping"), mappingContext)).thenReturn(true); + when(localMappingContext.getEid(new MappingId("local-mapping"), mappingContext)).thenReturn(new EidBuilder() + .setAddress(EID_V4_PREFIX_ADDRESS).build()); + //naming context for locator + defineMapping(mappingContext, "loc-set", 1, "locator-set-context"); + } + @Test public void readCurrentAttributesNoHmacKey() throws ReadFailedException { + defineAddressMappings(); defineDumpDataNoHmacKey(); LocalMappingBuilder builder = new LocalMappingBuilder(); @@ -155,7 +192,8 @@ public class LocalMappingCustomizerTest extends @Test public void readCurrentAttributes() throws Exception { - defineDumpData(); + defineAddressMappings(); + defineV4AddressDumpData(); LocalMappingBuilder builder = new LocalMappingBuilder(); getCustomizer().readCurrentAttributes(validIdentifier, builder, ctx); @@ -171,8 +209,27 @@ public class LocalMappingCustomizerTest extends } @Test + public void readCurrentAttributesPrefixBased() throws Exception { + definePrefixMappings(); + defineV4PrefixDumpData(); + LocalMappingBuilder builder = new LocalMappingBuilder(); + getCustomizer().readCurrentAttributes(validIdentifier, builder, ctx); + + final LocalMapping mapping = builder.build(); + + assertNotNull(mapping); + assertEquals(true, compareAddresses(EID_V4_PREFIX_ADDRESS, mapping.getEid().getAddress())); + assertEquals("loc-set", mapping.getLocatorSet()); + + final HmacKey hmacKey = mapping.getHmacKey(); + assertEquals("abcdefgh", hmacKey.getKey()); + assertEquals(HmacKeyType.Sha196Key, hmacKey.getKeyType()); + } + + @Test public void getAllIds() throws Exception { - defineDumpData(); + defineAddressMappings(); + defineV4AddressDumpData(); final List<LocalMappingKey> keys = getCustomizer().getAllIds(emptyIdentifier, ctx); assertEquals(1, keys.size()); diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/RemoteMappingCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/RemoteMappingCustomizerTest.java index 59caeb03a..d239f379b 100644 --- a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/RemoteMappingCustomizerTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/read/RemoteMappingCustomizerTest.java @@ -42,6 +42,8 @@ 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.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4Prefix; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4PrefixBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.MapReplyAction; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.MappingId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.dp.subtable.grouping.RemoteMappings; @@ -66,6 +68,9 @@ public class RemoteMappingCustomizerTest private static final Ipv4 EID_ADDRESS = new Ipv4Builder().setIpv4(new Ipv4Address("192.168.2.1")).build(); + private static final Ipv4Prefix + EID_V4_PREFIX_ADDRESS = new Ipv4PrefixBuilder().setIpv4Prefix(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix("192.168.2.1/24")).build(); + @Mock private EidMappingContext eidMappingContext; @@ -83,12 +88,11 @@ public class RemoteMappingCustomizerTest .child(VrfSubtable.class) .child(RemoteMappings.class) .child(RemoteMapping.class, new RemoteMappingKey(new MappingId("remote-mapping"))); - mockMappings(); defineMapping(mappingContext,"loc-set",1,"loc-set-context"); } - private void mockDumpDataActionZero() { + private void mockDumpDataAddressActionZero() { OneEidTableDetailsReplyDump replyDump = new OneEidTableDetailsReplyDump(); OneEidTableDetails detail = new OneEidTableDetails(); detail.action = 0; @@ -110,7 +114,29 @@ public class RemoteMappingCustomizerTest when(api.oneLocatorDump(any())).thenReturn(future(rlocs)); } - private void mockDumpDataActionOne() { + private void mockDumpDataPrefixActionZero() { + OneEidTableDetailsReplyDump replyDump = new OneEidTableDetailsReplyDump(); + OneEidTableDetails detail = new OneEidTableDetails(); + detail.action = 0; + detail.authoritative = 1; + detail.context = 4; + detail.eid = new byte[]{-64, -88, 2, 1}; + detail.eidPrefixLen = 24; + detail.isLocal = 0; + detail.locatorSetIndex = -1; + detail.ttl = 7; + detail.vni = 12; + + replyDump.oneEidTableDetails = ImmutableList.of(detail); + + when(api.oneEidTableDump(any())).thenReturn(future(replyDump)); + + OneLocatorDetailsReplyDump rlocs = new OneLocatorDetailsReplyDump(); + rlocs.oneLocatorDetails = Collections.emptyList(); + when(api.oneLocatorDump(any())).thenReturn(future(rlocs)); + } + + private void mockDumpDataAddressActionOne() { OneEidTableDetailsReplyDump replyDump = new OneEidTableDetailsReplyDump(); OneEidTableDetails detail = new OneEidTableDetails(); detail.action = 1; @@ -158,19 +184,28 @@ public class RemoteMappingCustomizerTest } - private void mockMappings() { + private void mockAddressMappings() { when(eidMappingContext.getId(any(Eid.class), any(MappingContext.class))) .thenReturn(new MappingId("remote-mapping")); when(eidMappingContext.containsEid(new MappingId("remote-mapping"), mappingContext)).thenReturn(true); when(eidMappingContext.getEid(new MappingId("remote-mapping"), mappingContext)) .thenReturn(new EidBuilder().setAddress(EID_ADDRESS).build()); + } + + private void mockPrefixMappings() { + when(eidMappingContext.getId(any(Eid.class), any(MappingContext.class))) + .thenReturn(new MappingId("remote-mapping")); + when(eidMappingContext.containsEid(new MappingId("remote-mapping"), mappingContext)).thenReturn(true); + when(eidMappingContext.getEid(new MappingId("remote-mapping"), mappingContext)) + .thenReturn(new EidBuilder().setAddress(EID_V4_PREFIX_ADDRESS).build()); } @Test public void readCurrentAttributesNegativeMappingOne() throws Exception { - mockDumpDataActionOne(); + mockAddressMappings(); + mockDumpDataAddressActionOne(); RemoteMappingBuilder builder = new RemoteMappingBuilder(); getCustomizer().readCurrentAttributes(validId, builder, ctx); @@ -187,7 +222,8 @@ public class RemoteMappingCustomizerTest @Test public void readCurrentAttributesNegativeMappingZero() throws Exception { - mockDumpDataActionZero(); + mockAddressMappings(); + mockDumpDataAddressActionZero(); RemoteMappingBuilder builder = new RemoteMappingBuilder(); getCustomizer().readCurrentAttributes(validId, builder, ctx); @@ -202,7 +238,25 @@ public class RemoteMappingCustomizerTest } @Test + public void readCurrentAttributesPrefixBasedNegativeMappingZero() throws Exception { + mockPrefixMappings(); + mockDumpDataPrefixActionZero(); + RemoteMappingBuilder builder = new RemoteMappingBuilder(); + getCustomizer().readCurrentAttributes(validId, builder, ctx); + + RemoteMapping mapping = builder.build(); + + assertNotNull(mapping); + assertEquals(true, compareAddresses(EID_V4_PREFIX_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 { + mockAddressMappings(); mockDumpDataActionZeroWithRemotes(); RemoteMappingBuilder builder = new RemoteMappingBuilder(); getCustomizer().readCurrentAttributes(validId, builder, ctx); @@ -223,10 +277,10 @@ public class RemoteMappingCustomizerTest assertEquals(2, locator.getWeight().shortValue()); } - @Test public void getAllIds() throws Exception { - mockDumpDataActionOne(); + mockAddressMappings(); + mockDumpDataAddressActionOne(); final List<RemoteMappingKey> keys = getCustomizer().getAllIds(validId, ctx); assertNotNull(keys); |