diff options
author | Jan Srnicek <jsrnicek@cisco.com> | 2017-05-16 12:48:47 +0200 |
---|---|---|
committer | Marek Gradzki <mgradzki@cisco.com> | 2017-05-18 09:32:02 +0000 |
commit | f1189488bce92471d6e5e5a666befa2340bd20ae (patch) | |
tree | 020200cab38d98cec1dd6f45db018b6bca44efe0 /lisp/lisp2vpp/src/test/java | |
parent | b4b8fba02e15dd061f0bc05fb87f121980893ca1 (diff) |
HC2VPP-90 - Ipv4/Ipv6 prefix based eid's support
- adds full support for prefix based eid's ,both in
non-normalized and normalized form
Change-Id: I22451d20e0f9b540da447c8f120b917e0b30a6b7
Signed-off-by: Jan Srnicek <jsrnicek@cisco.com>
Diffstat (limited to 'lisp/lisp2vpp/src/test/java')
9 files changed, 588 insertions, 62 deletions
diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/context/util/EidMappingContextTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/context/util/EidMappingContextTest.java index f4325b00c..4dafb2176 100644 --- a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/context/util/EidMappingContextTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/context/util/EidMappingContextTest.java @@ -29,6 +29,8 @@ import org.mockito.MockitoAnnotations; 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.MappingId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.dp.subtable.grouping.local.mappings.local.mapping.Eid; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.dp.subtable.grouping.local.mappings.local.mapping.EidBuilder; @@ -42,11 +44,20 @@ public class EidMappingContextTest implements EidMappingContextHelper { private EidMappingContext eidMappingContext; private Eid localEid; + private Eid localPrefixBasedEid; + private Eid localPrefixBasedEidNormalized; private org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.dp.subtable.grouping.remote.mappings.remote.mapping.Eid remoteEid; + private org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.dp.subtable.grouping.remote.mappings.remote.mapping.Eid + remoteEidPrefixBased; + private org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.dp.subtable.grouping.remote.mappings.remote.mapping.Eid + remoteEidPrefixBasedNormalized; 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 org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.eid.mapping.context.mappings.mapping.Eid + mappingEidPrefixBased; private MappingId mappingId; + private MappingId mappingIdPrefixBased; @Before public void init() { @@ -55,11 +66,24 @@ public class EidMappingContextTest implements EidMappingContextHelper { localEid = new EidBuilder().setAddress(new Ipv4Builder().setIpv4(new Ipv4Address("192.168.2.1")).build()).build(); + + localPrefixBasedEid = new EidBuilder().setAddress(new Ipv4PrefixBuilder() + .setIpv4Prefix(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix("192.168.2.2/24")) + .build()).build(); + + localPrefixBasedEidNormalized = new EidBuilder().setAddress(new Ipv4PrefixBuilder() + .setIpv4Prefix(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix("192.168.2.0/24")) + .build()).build(); + remoteEid = fromLocalToRemoteEid(localEid); + remoteEidPrefixBased = fromLocalToRemoteEid(localPrefixBasedEid); + remoteEidPrefixBasedNormalized = fromLocalToRemoteEid(localPrefixBasedEidNormalized); + mappingEidPrefixBased = fromLocalToMappingEid(localPrefixBasedEidNormalized); mappingEid = fromLocalToMappingEid(localEid); mappingId = new MappingId("mapping"); - + mappingIdPrefixBased = new MappingId("mappingIdPrefixBased"); defineEidMapping(mappingContext, mappingEid, mappingId, EID_MAPPING_CONTEXT_NAME); + defineEidMapping(mappingContext, mappingEidPrefixBased, mappingIdPrefixBased, EID_MAPPING_CONTEXT_NAME); } @Test @@ -72,20 +96,36 @@ public class EidMappingContextTest implements EidMappingContextHelper { } @Test + public void testContainsEidPrefixBased() { + assertTrue(eidMappingContext.containsEid(mappingIdPrefixBased, 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(mappingIdPrefixBased, mappingContext); + + assertEquals("192.168.2.0/24", ((Ipv4Prefix) (loadedEid.getAddress())).getIpv4Prefix().getValue()); + } + + @Test public void testContainsId() { assertTrue(eidMappingContext.containsId(localEid, mappingContext)); assertTrue(eidMappingContext.containsId(remoteEid, mappingContext)); + // detects both normalized and non-normalized form + assertTrue(eidMappingContext.containsId(localPrefixBasedEid, mappingContext)); + assertTrue(eidMappingContext.containsId(localPrefixBasedEidNormalized, mappingContext)); } @Test public void testGetEid() { assertEquals(mappingEid, eidMappingContext.getEid(mappingId, mappingContext)); + assertEquals(mappingEidPrefixBased, eidMappingContext.getEid(mappingIdPrefixBased, mappingContext)); } @Test public void testGetId() { assertEquals(mappingId, eidMappingContext.getId(localEid, mappingContext)); assertEquals(mappingId, eidMappingContext.getId(remoteEid, mappingContext)); + // detects both normalized and non-normalized form + assertEquals(mappingIdPrefixBased, eidMappingContext.getId(localPrefixBasedEid, mappingContext)); + assertEquals(mappingIdPrefixBased, eidMappingContext.getId(localPrefixBasedEidNormalized, mappingContext)); } @Test @@ -98,6 +138,17 @@ public class EidMappingContextTest implements EidMappingContextHelper { } @Test + public void testAddEidLocalPrefixBased() { + eidMappingContext.addEid(mappingIdPrefixBased, localPrefixBasedEid, mappingContext); + final org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.eid.mapping.context.mappings.mapping.Eid eid = eidMappingContext.getEid(mappingIdPrefixBased, mappingContext); + + // verify if normalized + assertEquals(localPrefixBasedEidNormalized.getAddress(), eid.getAddress()); + assertEquals(localEid.getAddressType(), eid.getAddressType()); + assertEquals(localEid.getVirtualNetworkId(), eid.getVirtualNetworkId()); + } + + @Test public void testAddEidRemote() { eidMappingContext.addEid(mappingId, remoteEid, mappingContext); final org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.eid.mapping.context.mappings.mapping.Eid eid = eidMappingContext.getEid(mappingId, mappingContext); @@ -106,6 +157,17 @@ public class EidMappingContextTest implements EidMappingContextHelper { assertEquals(remoteEid.getVirtualNetworkId(), eid.getVirtualNetworkId()); } + @Test + public void testAddEidRemotePrefixBased() { + eidMappingContext.addEid(mappingIdPrefixBased, remoteEidPrefixBased, mappingContext); + final org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.eid.mapping.context.rev160801.contexts.eid.mapping.context.mappings.mapping.Eid eid = eidMappingContext.getEid(mappingIdPrefixBased, mappingContext); + + // verify if normalized + assertEquals(remoteEidPrefixBasedNormalized.getAddress(), eid.getAddress()); + assertEquals(remoteEid.getAddressType(), eid.getAddressType()); + assertEquals(remoteEid.getVirtualNetworkId(), eid.getVirtualNetworkId()); + } + 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() diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/AdjacencyData.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/AdjacencyData.java index cc3581ae4..6e011fd48 100644 --- a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/AdjacencyData.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/AdjacencyData.java @@ -22,6 +22,7 @@ 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.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.lisp.address.address.Ipv4Builder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv4PrefixBuilder; public class AdjacencyData { @@ -32,6 +33,11 @@ public class AdjacencyData { public static final Ipv4Address ADDRESS_THREE = new Ipv4Address("192.168.2.3"); public static final Ipv4Address ADDRESS_FOUR = new Ipv4Address("192.168.2.4"); + public static final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix PREFIX_ADDRESS_ONE = new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix("192.168.2.1/24"); + public static final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix PREFIX_ADDRESS_TWO = new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix("192.168.2.2/28"); + public static final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix PREFIX_ADDRESS_THREE = new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix("192.168.2.3/16"); + public static final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix PREFIX_ADDRESS_FOUR = new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix("192.168.2.4/8"); + public static final Eid LOCAL_EID_ONE = new EidBuilder() .setAddressType(Ipv4Afi.class) .setVirtualNetworkId(new InstanceIdType(VNI)) @@ -55,5 +61,26 @@ public class AdjacencyData { .setAddress(new Ipv4Builder().setIpv4(ADDRESS_FOUR).build()) .build(); + public static final Eid LOCAL_EID_PREFIX_ONE = new EidBuilder() + .setAddressType(Ipv4Afi.class) + .setVirtualNetworkId(new InstanceIdType(VNI)) + .setAddress(new Ipv4PrefixBuilder().setIpv4Prefix(PREFIX_ADDRESS_ONE).build()) + .build(); + + public static final Eid LOCAL_EID_PREFIX_TWO = new EidBuilder() + .setAddressType(Ipv4Afi.class) + .setVirtualNetworkId(new InstanceIdType(VNI)) + .setAddress(new Ipv4PrefixBuilder().setIpv4Prefix(PREFIX_ADDRESS_TWO).build()) + .build(); + public static final Eid REMOTE_EID_PREFIX_ONE = new EidBuilder() + .setAddressType(Ipv4Afi.class) + .setVirtualNetworkId(new InstanceIdType(VNI)) + .setAddress(new Ipv4PrefixBuilder().setIpv4Prefix(PREFIX_ADDRESS_THREE).build()) + .build(); + public static final Eid REMOTE_EID_PREFIX_TWO = new EidBuilder() + .setAddressType(Ipv4Afi.class) + .setVirtualNetworkId(new InstanceIdType(VNI)) + .setAddress(new Ipv4PrefixBuilder().setIpv4Prefix(PREFIX_ADDRESS_FOUR).build()) + .build(); } 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); diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/util/EidTranslatorTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/util/EidTranslatorTest.java index 096eca7fd..6e09f2faa 100755 --- a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/util/EidTranslatorTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/util/EidTranslatorTest.java @@ -16,23 +16,39 @@ package io.fd.hc2vpp.lisp.translate.util; +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 io.fd.hc2vpp.lisp.translate.read.dump.executor.params.MappingsDumpParams.EidType.IPV6; +import static io.fd.hc2vpp.lisp.translate.read.dump.executor.params.MappingsDumpParams.EidType.IPV6_PREFIX; +import static io.fd.hc2vpp.lisp.translate.read.dump.executor.params.MappingsDumpParams.EidType.MAC; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.Arrays; import org.junit.Test; 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.inet.types.rev130715.Ipv6Address; 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.Ipv4PrefixAfi; 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.Ipv6PrefixAfi; 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.*; +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.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6Builder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6Prefix; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6PrefixBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Mac; +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.rev170315.adjacencies.grouping.adjacencies.adjacency.LocalEid; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.adjacencies.grouping.adjacencies.adjacency.RemoteEid; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.dp.subtable.grouping.remote.mappings.remote.mapping.Eid; -import java.util.Arrays; - -import static io.fd.hc2vpp.lisp.translate.read.dump.executor.params.MappingsDumpParams.EidType.*; -import static org.junit.Assert.*; - public class EidTranslatorTest implements EidTranslator { private static final String MAC_STRING = "bf:bf:bf:bf:bf:bf"; @@ -50,6 +66,8 @@ public class EidTranslatorTest implements EidTranslator { new Ipv4Address(IPV4_STRING)) .build(); private static final byte[] IPV_ADDRESS_BYTES = {-64, -88, 2, 1}; + private static final String NORMALIZED_V6_PREFIX = "2001:db8:a0b:12f0::/64"; + private static final String NORMALIZED_V4_PREFIX = "192.168.2.0/24"; @Test public void testGetEidType() { @@ -68,33 +86,53 @@ public class EidTranslatorTest implements EidTranslator { @Test public void testGetPrefixLength() { - assertEquals(32, getPrefixLength(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.dp.subtable.grouping.local.mappings.local.mapping.EidBuilder() - .setAddress(IPV4_ADDRESS).build())); - assertEquals(-128, getPrefixLength(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.dp.subtable.grouping.local.mappings.local.mapping.EidBuilder() - .setAddress(IPV6_ADDRESS).build())); - assertEquals(0, getPrefixLength(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.dp.subtable.grouping.local.mappings.local.mapping.EidBuilder() - .setAddress(MAC_ADDRES).build())); + assertEquals(32, getPrefixLength( + new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.dp.subtable.grouping.local.mappings.local.mapping.EidBuilder() + .setAddress(IPV4_ADDRESS).build())); + assertEquals(-128, getPrefixLength( + new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.dp.subtable.grouping.local.mappings.local.mapping.EidBuilder() + .setAddress(IPV6_ADDRESS).build())); + assertEquals(0, getPrefixLength( + new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.dp.subtable.grouping.local.mappings.local.mapping.EidBuilder() + .setAddress(MAC_ADDRES).build())); } @Test public void testGetArrayAsEidRemoteIpv4() { - final Eid eid = getArrayAsEidRemote(IPV4, IPV_ADDRESS_BYTES, 10); + final Eid eid = getArrayAsEidRemote(IPV4, IPV_ADDRESS_BYTES, DEFAULT_V4_PREFIX, 10); assertEquals(IPV4_STRING, ((Ipv4) eid.getAddress()).getIpv4().getValue()); assertEquals(10, eid.getVirtualNetworkId().getValue().intValue()); assertEquals(Ipv4Afi.class, eid.getAddressType()); } @Test + public void testGetArrayAsEidRemoteIpv4Prefix() { + final Eid eid = getArrayAsEidRemote(IPV4_PREFIX, IPV_ADDRESS_BYTES, (byte) 24, 10); + assertEquals(NORMALIZED_V4_PREFIX, ((Ipv4Prefix) eid.getAddress()).getIpv4Prefix().getValue()); + assertEquals(10, eid.getVirtualNetworkId().getValue().intValue()); + assertEquals(Ipv4PrefixAfi.class, eid.getAddressType()); + } + + @Test public void testGetArrayAsEidRemoteIpv6() { - final Eid eid = getArrayAsEidRemote(IPV6, IPV6_ADDRESS_BYTES, 12); + final Eid eid = getArrayAsEidRemote(IPV6, IPV6_ADDRESS_BYTES, DEFAULT_V6_PREFIX, 12); assertEquals(IPV6_STRING, ((Ipv6) eid.getAddress()).getIpv6().getValue()); assertEquals(12, eid.getVirtualNetworkId().getValue().intValue()); assertEquals(Ipv6Afi.class, eid.getAddressType()); } @Test + public void testGetArrayAsEidRemoteIpv6Prefix() { + final Eid eid = getArrayAsEidRemote(IPV6_PREFIX, IPV6_ADDRESS_BYTES, (byte) 64, 12); + assertEquals(NORMALIZED_V6_PREFIX, ((Ipv6Prefix) eid.getAddress()).getIpv6Prefix().getValue()); + assertEquals(12, eid.getVirtualNetworkId().getValue().intValue()); + assertEquals(Ipv6PrefixAfi.class, eid.getAddressType()); + } + + + @Test public void testGetArrayAsEidRemoteMac() { - final Eid eid = getArrayAsEidRemote(MAC, MAC_ADDRESS_BYTES, 13); + final Eid eid = getArrayAsEidRemote(MAC, MAC_ADDRESS_BYTES, (byte) 0, 13); assertEquals(MAC_STRING, ((Mac) eid.getAddress()).getMac().getValue()); assertEquals(13, eid.getVirtualNetworkId().getValue().intValue()); assertEquals(MacAfi.class, eid.getAddressType()); @@ -102,23 +140,39 @@ public class EidTranslatorTest implements EidTranslator { @Test public void testGetArrayAsLocalEidIpv4() { - final LocalEid eid = getArrayAsLocalEid(IPV4, IPV_ADDRESS_BYTES, 10); + final LocalEid eid = getArrayAsLocalEid(IPV4, IPV_ADDRESS_BYTES, DEFAULT_V4_PREFIX, 10); assertEquals(IPV4_STRING, ((Ipv4) eid.getAddress()).getIpv4().getValue()); assertEquals(10, eid.getVirtualNetworkId().getValue().intValue()); assertEquals(Ipv4Afi.class, eid.getAddressType()); } @Test + public void testGetArrayAsLocalEidIpv4Prefix() { + final LocalEid eid = getArrayAsLocalEid(IPV4_PREFIX, IPV_ADDRESS_BYTES, (byte) 24, 10); + assertEquals(NORMALIZED_V4_PREFIX, ((Ipv4Prefix) eid.getAddress()).getIpv4Prefix().getValue()); + assertEquals(10, eid.getVirtualNetworkId().getValue().intValue()); + assertEquals(Ipv4PrefixAfi.class, eid.getAddressType()); + } + + @Test public void testGetArrayAsLocalEidIpv6() { - final LocalEid eid = getArrayAsLocalEid(IPV6, IPV6_ADDRESS_BYTES, 12); + final LocalEid eid = getArrayAsLocalEid(IPV6, IPV6_ADDRESS_BYTES, DEFAULT_V6_PREFIX, 12); assertEquals(IPV6_STRING, ((Ipv6) eid.getAddress()).getIpv6().getValue()); assertEquals(12, eid.getVirtualNetworkId().getValue().intValue()); assertEquals(Ipv6Afi.class, eid.getAddressType()); } @Test + public void testGetArrayAsLocalEidIpv6Prefix() { + final LocalEid eid = getArrayAsLocalEid(IPV6_PREFIX, IPV6_ADDRESS_BYTES, (byte) 64, 12); + assertEquals(NORMALIZED_V6_PREFIX, ((Ipv6Prefix) eid.getAddress()).getIpv6Prefix().getValue()); + assertEquals(12, eid.getVirtualNetworkId().getValue().intValue()); + assertEquals(Ipv6PrefixAfi.class, eid.getAddressType()); + } + + @Test public void testGetArrayAsLocalEidMac() { - final LocalEid eid = getArrayAsLocalEid(MAC, MAC_ADDRESS_BYTES, 13); + final LocalEid eid = getArrayAsLocalEid(MAC, MAC_ADDRESS_BYTES, (byte) 0, 13); assertEquals(MAC_STRING, ((Mac) eid.getAddress()).getMac().getValue()); assertEquals(13, eid.getVirtualNetworkId().getValue().intValue()); assertEquals(MacAfi.class, eid.getAddressType()); @@ -126,23 +180,39 @@ public class EidTranslatorTest implements EidTranslator { @Test public void testGetArrayAsRemoteEidIpv4() { - final RemoteEid eid = getArrayAsRemoteEid(IPV4, IPV_ADDRESS_BYTES, 10); + final RemoteEid eid = getArrayAsRemoteEid(IPV4, IPV_ADDRESS_BYTES, DEFAULT_V4_PREFIX, 10); assertEquals(IPV4_STRING, ((Ipv4) eid.getAddress()).getIpv4().getValue()); assertEquals(10, eid.getVirtualNetworkId().getValue().intValue()); assertEquals(Ipv4Afi.class, eid.getAddressType()); } @Test + public void testGetArrayAsRemoteEidIpv4Prefix() { + final RemoteEid eid = getArrayAsRemoteEid(IPV4_PREFIX, IPV_ADDRESS_BYTES, (byte) 24, 10); + assertEquals(NORMALIZED_V4_PREFIX, ((Ipv4Prefix) eid.getAddress()).getIpv4Prefix().getValue()); + assertEquals(10, eid.getVirtualNetworkId().getValue().intValue()); + assertEquals(Ipv4PrefixAfi.class, eid.getAddressType()); + } + + @Test public void testGetArrayAsRemoteEidIpv6() { - final RemoteEid eid = getArrayAsRemoteEid(IPV6, IPV6_ADDRESS_BYTES, 12); + final RemoteEid eid = getArrayAsRemoteEid(IPV6, IPV6_ADDRESS_BYTES, DEFAULT_V6_PREFIX, 12); assertEquals(IPV6_STRING, ((Ipv6) eid.getAddress()).getIpv6().getValue()); assertEquals(12, eid.getVirtualNetworkId().getValue().intValue()); assertEquals(Ipv6Afi.class, eid.getAddressType()); } @Test + public void testGetArrayAsRemoteEidIpv6Prefix() { + final RemoteEid eid = getArrayAsRemoteEid(IPV6_PREFIX, IPV6_ADDRESS_BYTES, (byte) 64, 12); + assertEquals(NORMALIZED_V6_PREFIX, ((Ipv6Prefix) eid.getAddress()).getIpv6Prefix().getValue()); + assertEquals(12, eid.getVirtualNetworkId().getValue().intValue()); + assertEquals(Ipv6PrefixAfi.class, eid.getAddressType()); + } + + @Test public void testGetArrayAsRemoteEidMac() { - final RemoteEid eid = getArrayAsRemoteEid(MAC, MAC_ADDRESS_BYTES, 13); + final RemoteEid eid = getArrayAsRemoteEid(MAC, MAC_ADDRESS_BYTES, (byte) 0, 13); assertEquals(MAC_STRING, ((Mac) eid.getAddress()).getMac().getValue()); assertEquals(13, eid.getVirtualNetworkId().getValue().intValue()); assertEquals(MacAfi.class, eid.getAddressType()); @@ -150,17 +220,27 @@ public class EidTranslatorTest implements EidTranslator { @Test public void testGetArrayAsEidStringIpv4() { - assertEquals(IPV4_STRING, getArrayAsEidString(IPV4, IPV_ADDRESS_BYTES)); + assertEquals(IPV4_STRING, getArrayAsEidString(IPV4, IPV_ADDRESS_BYTES, DEFAULT_V4_PREFIX)); + } + + @Test + public void testGetArrayAsEidStringIpv4Prefix() { + assertEquals(NORMALIZED_V4_PREFIX, getArrayAsEidString(IPV4, IPV_ADDRESS_BYTES, (byte) 24)); } @Test public void testGetArrayAsEidStringIpv6() { - assertEquals(IPV6_STRING, getArrayAsEidString(IPV6, IPV6_ADDRESS_BYTES)); + assertEquals(IPV6_STRING, getArrayAsEidString(IPV6, IPV6_ADDRESS_BYTES, DEFAULT_V6_PREFIX)); + } + + @Test + public void testGetArrayAsEidStringIpv6Prefix() { + assertEquals(NORMALIZED_V6_PREFIX, getArrayAsEidString(IPV6, IPV6_ADDRESS_BYTES, (byte) 64)); } @Test public void testGetArrayAsEidStringMac() { - assertEquals(MAC_STRING, getArrayAsEidString(MAC, MAC_ADDRESS_BYTES)); + assertEquals(MAC_STRING, getArrayAsEidString(MAC, MAC_ADDRESS_BYTES, (byte) 0)); } @Test @@ -191,4 +271,48 @@ public class EidTranslatorTest implements EidTranslator { assertFalse(compareAddresses(IPV4_ADDRESS, IPV6_ADDRESS)); assertFalse(compareAddresses(IPV4_ADDRESS, MAC_ADDRES)); } + + @Test + public void testCompareV4AddressFromSameSubnetPositive() { + final Ipv4Prefix firstV4 = new Ipv4PrefixBuilder().setIpv4Prefix(v4Prefix("192.168.2.1/24")).build(); + final Ipv4Prefix secondV4 = new Ipv4PrefixBuilder().setIpv4Prefix(v4Prefix("192.168.2.2/24")).build(); + + assertTrue(compareAddresses(firstV4, secondV4)); + } + + @Test + public void testCompareV4AddressFromSameSubnetNegative() { + final Ipv4Prefix firstV4 = new Ipv4PrefixBuilder().setIpv4Prefix(v4Prefix("192.168.2.1/24")).build(); + final Ipv4Prefix secondV4 = new Ipv4PrefixBuilder().setIpv4Prefix(v4Prefix("192.168.2.1/16")).build(); + + assertFalse(compareAddresses(firstV4, secondV4)); + } + + @Test + public void testCompareV6AddressesFromSameSubnetPositive() { + final Ipv6Prefix firstV6 = new Ipv6PrefixBuilder().setIpv6Prefix(v6Prefix("2001:db8:a0b:12f0::1/64")).build(); + final Ipv6Prefix secondV6 = new Ipv6PrefixBuilder().setIpv6Prefix(v6Prefix("2001:db8:a0b:12f0::4/64")).build(); + + assertTrue(compareAddresses(firstV6, secondV6)); + } + + @Test + public void testCompareV6AddressesFromSameSubnetNegative() { + final Ipv6Prefix firstV6 = new Ipv6PrefixBuilder().setIpv6Prefix(v6Prefix("2001:0db8:85a3:0000:0000:8a2e:0370:7334/64")).build(); + final Ipv6Prefix secondV6 = new Ipv6PrefixBuilder().setIpv6Prefix(v6Prefix("2001:0db8:85a3:0000:0000:8a2e:0370:7334/48")).build(); + + assertFalse(compareAddresses(firstV6, secondV6)); + } + + private static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix v6Prefix( + String v6Prefix) { + return new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix( + v6Prefix); + } + + private static org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix v4Prefix( + String v4Prefix) { + return new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix( + v4Prefix); + } } diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/AdjacencyCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/AdjacencyCustomizerTest.java index bf19ae581..1c487e3ae 100644 --- a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/AdjacencyCustomizerTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/AdjacencyCustomizerTest.java @@ -19,7 +19,9 @@ package io.fd.hc2vpp.lisp.translate.write; 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.REMOTE_EID_ONE; +import static io.fd.hc2vpp.lisp.translate.AdjacencyData.REMOTE_EID_PREFIX_ONE; import static io.fd.hc2vpp.lisp.translate.read.dump.executor.params.MappingsDumpParams.EidType.IPV4; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; @@ -28,6 +30,7 @@ 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.verifyZeroInteractions; import static org.mockito.Mockito.when; import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; @@ -42,10 +45,12 @@ 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.inet.types.rev130715.Ipv4Prefix; 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.Ipv4PrefixBuilder; 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.rev170315.MappingId; @@ -81,9 +86,13 @@ public class AdjacencyCustomizerTest extends WriterCustomizerTest implements Eid private InstanceIdentifier<Adjacency> emptyId; private InstanceIdentifier<Adjacency> validId; - private Adjacency emptyData; + private Adjacency failDataBefore; + private Adjacency failDataAfter; + private Adjacency ignoreDataBefore; + private Adjacency ignoreDataAfter; private Adjacency invalidData; private Adjacency validData; + private Adjacency validDataPrefixBased; @Before public void init() { @@ -100,7 +109,41 @@ public class AdjacencyCustomizerTest extends WriterCustomizerTest implements Eid .child(Adjacencies.class) .child(Adjacency.class, new AdjacencyKey("adj-one")); - emptyData = new AdjacencyBuilder().build(); + failDataBefore = new AdjacencyBuilder().setLocalEid(new LocalEidBuilder() + .setAddress(new Ipv4PrefixBuilder() + .setIpv4Prefix(new Ipv4Prefix("192.168.2.1/24")) + .build()) + .build()).build(); + + failDataAfter = new AdjacencyBuilder().setLocalEid(new LocalEidBuilder() + .setAddress(new Ipv4PrefixBuilder() + .setIpv4Prefix(new Ipv4Prefix("192.168.2.1/16")) + .build()) + .build()).build(); + + ignoreDataBefore = new AdjacencyBuilder().setLocalEid(new LocalEidBuilder() + .setAddress(new Ipv4PrefixBuilder() + .setIpv4Prefix(new Ipv4Prefix("192.168.2.1/24")) + .build()) + .build()) + .setRemoteEid(new RemoteEidBuilder() + .setAddress(new Ipv4PrefixBuilder() + .setIpv4Prefix(new Ipv4Prefix("192.168.3.1/24")) + .build()) + .build()) + .build(); + + ignoreDataAfter = new AdjacencyBuilder().setLocalEid(new LocalEidBuilder() + .setAddress(new Ipv4PrefixBuilder() + .setIpv4Prefix(new Ipv4Prefix("192.168.2.0/24")) + .build()) + .build()) + .setRemoteEid(new RemoteEidBuilder() + .setAddress(new Ipv4PrefixBuilder() + .setIpv4Prefix(new Ipv4Prefix("192.168.3.4/24")) + .build()) + .build()) + .build(); invalidData = new AdjacencyBuilder().setId("ID").setLocalEid( new LocalEidBuilder() @@ -126,13 +169,25 @@ public class AdjacencyCustomizerTest extends WriterCustomizerTest implements Eid .setAddressType(Ipv4Afi.class) .setAddress(new Ipv4Builder().setIpv4(ADDRESS_THREE).build()).build()).build(); + validDataPrefixBased = new AdjacencyBuilder() + .setLocalEid(new LocalEidBuilder() + .setAddressType(LOCAL_EID_PREFIX_ONE.getAddressType()) + .setVirtualNetworkId(LOCAL_EID_PREFIX_ONE.getVirtualNetworkId()) + .setAddress(LOCAL_EID_PREFIX_ONE.getAddress()).build()) + .setRemoteEid(new RemoteEidBuilder() + .setVirtualNetworkId(REMOTE_EID_PREFIX_ONE.getVirtualNetworkId()) + .setAddressType(REMOTE_EID_PREFIX_ONE.getAddressType()) + .setAddress(REMOTE_EID_PREFIX_ONE.getAddress()) + .build()) + .build(); + when(api.oneAddDelAdjacency(any())).thenReturn(future(new OneAddDelAdjacencyReply())); } @Test public void writeCurrentAttributesNoKey() throws Exception { try { - customizer.writeCurrentAttributes(emptyId, emptyData, writeContext); + customizer.writeCurrentAttributes(emptyId, failDataBefore, writeContext); } catch (NullPointerException e) { verify(api, times(0)).oneAddDelAdjacency(any()); return; @@ -161,7 +216,19 @@ public class AdjacencyCustomizerTest extends WriterCustomizerTest implements Eid customizer.writeCurrentAttributes(validId, validData, writeContext); verify(api, times(1)).oneAddDelAdjacency(requestCaptor.capture()); verifyRequest(requestCaptor.getValue(), 1, new byte[]{-64, -88, 2, 1}, 32, new byte[]{-64, -88, 2, 3}, - 32, IPV4.getValue(), 2); + 32, IPV4.getVppTypeBinding(), 2); + verify(adjacenciesMappingContext, times(1)) + .addEidPair("adj-one", "local-eid-one", "remote-eid-one", mappingContext); + } + + @Test + public void writeCurrentAttributesPrefixBased() throws Exception { + defineEidMapping(mappingContext, LOCAL_EID_PREFIX_ONE, new MappingId("local-eid-one"), "local-mapping-context"); + defineEidMapping(mappingContext, REMOTE_EID_PREFIX_ONE, new MappingId("remote-eid-one"), "remote-mapping-context"); + customizer.writeCurrentAttributes(validId, validDataPrefixBased, writeContext); + verify(api, times(1)).oneAddDelAdjacency(requestCaptor.capture()); + verifyRequest(requestCaptor.getValue(), 1, new byte[]{-64, -88, 2, 1}, 24, new byte[]{-64, -88, 2, 3}, + 16, IPV4.getVppTypeBinding(), 2); verify(adjacenciesMappingContext, times(1)) .addEidPair("adj-one", "local-eid-one", "remote-eid-one", mappingContext); } @@ -196,14 +263,21 @@ public class AdjacencyCustomizerTest extends WriterCustomizerTest implements Eid } @Test(expected = UnsupportedOperationException.class) - public void updateCurrentAttributes() throws Exception { - customizer.updateCurrentAttributes(emptyId, emptyData, emptyData, writeContext); + public void updateCurrentAttributesFail() throws Exception { + customizer.updateCurrentAttributes(emptyId, failDataBefore, failDataAfter, writeContext); + } + + @Test + public void updateCurrentAttributesIgnore() throws Exception { + // should not throw in this case + customizer.updateCurrentAttributes(emptyId, ignoreDataBefore, ignoreDataAfter, writeContext); + verifyZeroInteractions(api); } @Test public void deleteCurrentAttributesNoKey() throws Exception { try { - customizer.deleteCurrentAttributes(emptyId, emptyData, writeContext); + customizer.deleteCurrentAttributes(emptyId, failDataBefore, writeContext); } catch (NullPointerException e) { verify(api, times(0)).oneAddDelAdjacency(any()); return; @@ -222,7 +296,7 @@ public class AdjacencyCustomizerTest extends WriterCustomizerTest implements Eid customizer.deleteCurrentAttributes(validId, validData, writeContext); verify(api, times(1)).oneAddDelAdjacency(requestCaptor.capture()); verifyRequest(requestCaptor.getValue(), 0, new byte[]{-64, -88, 2, 1}, 32, new byte[]{-64, -88, 2, 3}, - 32, IPV4.getValue(), 2); + 32, IPV4.getVppTypeBinding(), 2); verify(adjacenciesMappingContext, times(1)).removeForIndex("adj-one", mappingContext); } diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/LocalMappingCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/LocalMappingCustomizerTest.java index f945415a1..c49823f7a 100755 --- a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/LocalMappingCustomizerTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/LocalMappingCustomizerTest.java @@ -24,6 +24,7 @@ import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; @@ -41,8 +42,10 @@ 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.inet.types.rev130715.Ipv4Prefix; 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.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.Lisp; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.MappingId; @@ -70,6 +73,12 @@ public class LocalMappingCustomizerTest extends WriterCustomizerTest implements private InstanceIdentifier<LocalMapping> id; private LocalMapping mapping; private LocalMapping mappingWithHmacKey; + + private LocalMapping failUpdateBefore; + private LocalMapping failUpdateAfter; + private LocalMapping ignoreUpdateBefore; + private LocalMapping ignoreUpdateAfter; + private LocalMappingCustomizer customizer; @Override @@ -95,6 +104,28 @@ public class LocalMappingCustomizerTest extends WriterCustomizerTest implements .build()) .build(); + failUpdateBefore = new LocalMappingBuilder() + .setEid(new EidBuilder().setAddress(new Ipv4PrefixBuilder() + .setIpv4Prefix(new Ipv4Prefix("192.168.2.1/24")) + .build()).build()) + .build(); + failUpdateAfter = new LocalMappingBuilder() + .setEid(new EidBuilder().setAddress(new Ipv4PrefixBuilder() + .setIpv4Prefix(new Ipv4Prefix("192.168.2.1/16")) + .build()).build()) + .build(); + + ignoreUpdateBefore = new LocalMappingBuilder() + .setEid(new EidBuilder().setAddress(new Ipv4PrefixBuilder() + .setIpv4Prefix(new Ipv4Prefix("192.168.2.1/24")) + .build()).build()) + .build(); + ignoreUpdateAfter = new LocalMappingBuilder() + .setEid(new EidBuilder().setAddress(new Ipv4PrefixBuilder() + .setIpv4Prefix(new Ipv4Prefix("192.168.2.4/24")) + .build()).build()) + .build(); + id = InstanceIdentifier.builder(Lisp.class) .child(LispFeatureData.class) .child(EidTable.class) @@ -171,8 +202,14 @@ public class LocalMappingCustomizerTest extends WriterCustomizerTest implements } @Test(expected = UnsupportedOperationException.class) - public void testUpdateCurrentAttributes() throws WriteFailedException { - customizer.updateCurrentAttributes(null, null, null, writeContext); + public void testUpdateCurrentAttributesFail() throws WriteFailedException { + customizer.updateCurrentAttributes(null, failUpdateBefore, failUpdateAfter, writeContext); + } + + @Test + public void testUpdateCurrentAttributesIgnore() throws WriteFailedException { + customizer.updateCurrentAttributes(null, ignoreUpdateBefore, ignoreUpdateAfter, writeContext); + verifyZeroInteractions(api); } @Test @@ -194,7 +231,8 @@ public class LocalMappingCustomizerTest extends WriterCustomizerTest implements } @Test - public void testDeleteCurrentAttributesWithHmacKey() throws WriteFailedException, InterruptedException, ExecutionException { + public void testDeleteCurrentAttributesWithHmacKey() + throws WriteFailedException, InterruptedException, ExecutionException { when(eidMappingContext.containsEid(any(), eq(mappingContext))).thenReturn(true); customizer.deleteCurrentAttributes(id, mappingWithHmacKey, writeContext); diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/RemoteMappingCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/RemoteMappingCustomizerTest.java index 35cc87689..62823df73 100755 --- a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/RemoteMappingCustomizerTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/RemoteMappingCustomizerTest.java @@ -26,6 +26,7 @@ import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; @@ -44,8 +45,10 @@ import org.mockito.Captor; import org.mockito.Mock; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress; 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.inet.types.rev130715.Ipv6Prefix; 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.ietf.params.xml.ns.yang.ietf.lisp.address.types.rev151105.lisp.address.address.Ipv6PrefixBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev170315.Lisp; 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; @@ -77,6 +80,12 @@ public class RemoteMappingCustomizerTest extends WriterCustomizerTest implements private RemoteMapping negativeMapping; private RemoteMapping positiveMappingNoPrioNoWeight; private RemoteMapping positiveMappingPrioWeight; + + private RemoteMapping failUpdateBefore; + private RemoteMapping failUpdateAfter; + private RemoteMapping ignoreUpdateBefore; + private RemoteMapping ignoreUpdateAfter; + private InstanceIdentifier<RemoteMapping> id; @Mock @@ -95,6 +104,28 @@ public class RemoteMappingCustomizerTest extends WriterCustomizerTest implements mappingId = new MappingId("REMOTE"); final RemoteMappingKey key = new RemoteMappingKey(mappingId); + failUpdateBefore = new RemoteMappingBuilder() + .setEid(new EidBuilder().setAddress(new Ipv6PrefixBuilder() + .setIpv6Prefix(new Ipv6Prefix("2001:0db8:85a3:0000:0000:8a2e:0370:7334/64")) + .build()).build()) + .build(); + failUpdateAfter = new RemoteMappingBuilder() + .setEid(new EidBuilder().setAddress(new Ipv6PrefixBuilder() + .setIpv6Prefix(new Ipv6Prefix("2001:0db8:85a3:0000:0000:8a2e:0370:7334/48")) + .build()).build()) + .build(); + + ignoreUpdateBefore = new RemoteMappingBuilder() + .setEid(new EidBuilder().setAddress(new Ipv6PrefixBuilder() + .setIpv6Prefix(new Ipv6Prefix("2001:0db8:85a3:0000:0000:8a2e:0370:7334/64")) + .build()).build()) + .build(); + ignoreUpdateAfter = new RemoteMappingBuilder() + .setEid(new EidBuilder().setAddress(new Ipv6PrefixBuilder() + .setIpv6Prefix(new Ipv6Prefix("2001:0db8:85a3:0000:0000:8a2e:0370:7348/64")) + .build()).build()) + .build(); + negativeMapping = new RemoteMappingBuilder() .setEid(eid) .setLocatorList(new NegativeMappingBuilder() @@ -205,8 +236,14 @@ public class RemoteMappingCustomizerTest extends WriterCustomizerTest implements } @Test(expected = UnsupportedOperationException.class) - public void testUpdateCurrentAttributes() throws WriteFailedException { - customizer.updateCurrentAttributes(null, null, null, writeContext); + public void testUpdateCurrentAttributesFail() throws WriteFailedException { + customizer.updateCurrentAttributes(null, failUpdateBefore, failUpdateAfter, writeContext); + } + + @Test + public void testUpdateCurrentAttributesIgnore() throws WriteFailedException { + customizer.updateCurrentAttributes(null, ignoreUpdateBefore, ignoreUpdateAfter, writeContext); + verifyZeroInteractions(api); } @Test(expected = NullPointerException.class) |