diff options
author | Jan Srnicek <jsrnicek@cisco.com> | 2017-01-24 15:44:44 +0100 |
---|---|---|
committer | Marek Gradzki <mgradzki@cisco.com> | 2017-01-25 10:36:15 +0000 |
commit | 2473ec26dc352d62d7351c1a441cc5350e19a42b (patch) | |
tree | ac498b697d63a2fea282628b03b1fca013642920 /lisp/lisp2vpp/src/test | |
parent | 8098a62384726717c5781937b5db253365b298bb (diff) |
Lisp test coverage
Change-Id: If780bbe08c0eee36a00b408b4a71383fa9d1e300
Signed-off-by: Jan Srnicek <jsrnicek@cisco.com>
Diffstat (limited to 'lisp/lisp2vpp/src/test')
3 files changed, 178 insertions, 27 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 e5daace93..6b63f8085 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 @@ -17,9 +17,6 @@ package io.fd.hc2vpp.lisp.context.util; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - import io.fd.hc2vpp.lisp.util.EidMappingContextHelper; import io.fd.honeycomb.translate.MappingContext; import org.junit.Before; @@ -33,6 +30,9 @@ 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.rev161214.dp.subtable.grouping.local.mappings.local.mapping.Eid; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.dp.subtable.grouping.local.mappings.local.mapping.EidBuilder; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + public class EidMappingContextTest implements EidMappingContextHelper { private static final String EID_MAPPING_CONTEXT_NAME = "eidMappingContext"; @@ -88,6 +88,24 @@ public class EidMappingContextTest implements EidMappingContextHelper { assertEquals(mappingId, eidMappingContext.getId(remoteEid, mappingContext)); } + @Test + public void testAddEidLocal() { + eidMappingContext.addEid(mappingId, localEid, 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); + assertEquals(localEid.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); + assertEquals(remoteEid.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/util/EidTranslatorTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/util/EidTranslatorTest.java index c2fc51b5a..8884c7c14 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,45 +16,179 @@ 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.IPV6; -import static io.fd.hc2vpp.lisp.translate.read.dump.executor.params.MappingsDumpParams.EidType.MAC; -import static org.junit.Assert.assertEquals; - 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.lisp.address.address.Ipv4Builder; -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.MacBuilder; +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.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.yang.types.rev130715.MacAddress; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.adjacencies.grouping.adjacencies.adjacency.LocalEid; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.adjacencies.grouping.adjacencies.adjacency.RemoteEid; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.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"; + private static final Mac MAC_ADDRES = new MacBuilder().setMac( + new MacAddress(MAC_STRING)) + .build(); + private static final byte[] MAC_ADDRESS_BYTES = {-65, -65, -65, -65, -65, -65}; + private static final byte[] IPV6_ADDRESS_BYTES = {32, 1, 13, -72, 10, 11, 18, -16, 0, 0, 0, 0, 0, 0, 0, 1}; + private static final String IPV6_STRING = "2001:db8:a0b:12f0::1"; + private static final Ipv6 IPV6_ADDRESS = new Ipv6Builder().setIpv6( + new Ipv6Address(IPV6_STRING)) + .build(); + private static final String IPV4_STRING = "192.168.2.1"; + private static final Ipv4 IPV4_ADDRESS = new Ipv4Builder().setIpv4( + new Ipv4Address(IPV4_STRING)) + .build(); + private static final byte[] IPV_ADDRESS_BYTES = {-64, -88, 2, 1}; + @Test public void testGetEidType() { assertEquals(IPV4, getEidType( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.dp.subtable.grouping.remote.mappings.remote.mapping.EidBuilder() - .setAddress( - new Ipv4Builder().setIpv4( - new Ipv4Address("192.168.2.1")) - .build()) - .build())); + .setAddress(IPV4_ADDRESS).build())); assertEquals(IPV6, getEidType( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.dp.subtable.grouping.remote.mappings.remote.mapping.EidBuilder() - .setAddress( - new Ipv6Builder().setIpv6( - new Ipv6Address("2001:0db8:0a0b:12f0:0000:0000:0000:0001")) - .build()) - .build())); + .setAddress(IPV6_ADDRESS).build())); assertEquals(MAC, getEidType( new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.dp.subtable.grouping.remote.mappings.remote.mapping.EidBuilder() - .setAddress( - new MacBuilder().setMac( - new MacAddress("aa:bb:cc:dd:ee:ff")) - .build()) - .build())); + .setAddress(MAC_ADDRES).build())); + } + + @Test + public void testGetPrefixLength() { + assertEquals(32, getPrefixLength(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.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.rev161214.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.rev161214.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); + assertEquals(IPV4_STRING, ((Ipv4) eid.getAddress()).getIpv4().getValue()); + assertEquals(10, eid.getVirtualNetworkId().getValue().intValue()); + assertEquals(Ipv4Afi.class, eid.getAddressType()); + } + + @Test + public void testGetArrayAsEidRemoteIpv6() { + final Eid eid = getArrayAsEidRemote(IPV6, IPV6_ADDRESS_BYTES, 12); + assertEquals(IPV6_STRING, ((Ipv6) eid.getAddress()).getIpv6().getValue()); + assertEquals(12, eid.getVirtualNetworkId().getValue().intValue()); + assertEquals(Ipv6Afi.class, eid.getAddressType()); + } + + @Test + public void testGetArrayAsEidRemoteMac() { + final Eid eid = getArrayAsEidRemote(MAC, MAC_ADDRESS_BYTES, 13); + assertEquals(MAC_STRING, ((Mac) eid.getAddress()).getMac().getValue()); + assertEquals(13, eid.getVirtualNetworkId().getValue().intValue()); + assertEquals(MacAfi.class, eid.getAddressType()); + } + + @Test + public void testGetArrayAsLocalEidIpv4() { + final LocalEid eid = getArrayAsLocalEid(IPV4, IPV_ADDRESS_BYTES, 10); + assertEquals(IPV4_STRING, ((Ipv4) eid.getAddress()).getIpv4().getValue()); + assertEquals(10, eid.getVirtualNetworkId().getValue().intValue()); + assertEquals(Ipv4Afi.class, eid.getAddressType()); + } + + @Test + public void testGetArrayAsLocalEidIpv6() { + final LocalEid eid = getArrayAsLocalEid(IPV6, IPV6_ADDRESS_BYTES, 12); + assertEquals(IPV6_STRING, ((Ipv6) eid.getAddress()).getIpv6().getValue()); + assertEquals(12, eid.getVirtualNetworkId().getValue().intValue()); + assertEquals(Ipv6Afi.class, eid.getAddressType()); + } + + @Test + public void testGetArrayAsLocalEidMac() { + final LocalEid eid = getArrayAsLocalEid(MAC, MAC_ADDRESS_BYTES, 13); + assertEquals(MAC_STRING, ((Mac) eid.getAddress()).getMac().getValue()); + assertEquals(13, eid.getVirtualNetworkId().getValue().intValue()); + assertEquals(MacAfi.class, eid.getAddressType()); + } + + @Test + public void testGetArrayAsRemoteEidIpv4() { + final RemoteEid eid = getArrayAsRemoteEid(IPV4, IPV_ADDRESS_BYTES, 10); + assertEquals(IPV4_STRING, ((Ipv4) eid.getAddress()).getIpv4().getValue()); + assertEquals(10, eid.getVirtualNetworkId().getValue().intValue()); + assertEquals(Ipv4Afi.class, eid.getAddressType()); + } + + @Test + public void testGetArrayAsRemoteEidIpv6() { + final RemoteEid eid = getArrayAsRemoteEid(IPV6, IPV6_ADDRESS_BYTES, 12); + assertEquals(IPV6_STRING, ((Ipv6) eid.getAddress()).getIpv6().getValue()); + assertEquals(12, eid.getVirtualNetworkId().getValue().intValue()); + assertEquals(Ipv6Afi.class, eid.getAddressType()); + } + + @Test + public void testGetArrayAsRemoteEidMac() { + final RemoteEid eid = getArrayAsRemoteEid(MAC, MAC_ADDRESS_BYTES, 13); + assertEquals(MAC_STRING, ((Mac) eid.getAddress()).getMac().getValue()); + assertEquals(13, eid.getVirtualNetworkId().getValue().intValue()); + assertEquals(MacAfi.class, eid.getAddressType()); + } + + @Test + public void testGetArrayAsEidStringIpv4() { + assertEquals(IPV4_STRING, getArrayAsEidString(IPV4, IPV_ADDRESS_BYTES)); + } + + @Test + public void testGetArrayAsEidStringIpv6() { + assertEquals(IPV6_STRING, getArrayAsEidString(IPV6, IPV6_ADDRESS_BYTES)); + } + + @Test + public void testGetArrayAsEidStringMac() { + assertEquals(MAC_STRING, getArrayAsEidString(MAC, MAC_ADDRESS_BYTES)); + } + + @Test + public void testResolveByteArrayIpv4() { + assertTrue(Arrays.equals(IPV_ADDRESS_BYTES, resolveByteArray(IPV4, IPV4_ADDRESS))); + } + + @Test + public void testResolveByteArrayIpv6() { + assertTrue(Arrays.equals(IPV6_ADDRESS_BYTES, resolveByteArray(IPV6, IPV6_ADDRESS))); + } + + @Test + public void testResolveByteArrayMac() { + assertTrue(Arrays.equals(MAC_ADDRESS_BYTES, resolveByteArray(MAC, MAC_ADDRES))); + } + + @Test + public void testCompareAddressesPositive() { + assertTrue(compareAddresses(MAC_ADDRES, MAC_ADDRES)); + assertTrue(compareAddresses(IPV4_ADDRESS, IPV4_ADDRESS)); + assertTrue(compareAddresses(IPV6_ADDRESS, IPV6_ADDRESS)); + } + + @Test + public void testCompareAddressesNegative() { + assertFalse(compareAddresses(MAC_ADDRES, IPV6_ADDRESS)); + assertFalse(compareAddresses(IPV4_ADDRESS, IPV6_ADDRESS)); + assertFalse(compareAddresses(IPV4_ADDRESS, MAC_ADDRES)); } } diff --git a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/LispCustomizerTest.java b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/LispCustomizerTest.java index 0050d956a..e65aba586 100755 --- a/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/LispCustomizerTest.java +++ b/lisp/lisp2vpp/src/test/java/io/fd/hc2vpp/lisp/translate/write/LispCustomizerTest.java @@ -32,7 +32,6 @@ import org.mockito.ArgumentCaptor; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.Lisp; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.lisp.rev161214.LispBuilder; - public class LispCustomizerTest extends WriterCustomizerTest { private LispCustomizer customizer; |