diff options
author | Marek Gradzki <mgradzki@cisco.com> | 2017-08-15 14:04:51 +0200 |
---|---|---|
committer | Marek Gradzki <mgradzki@cisco.com> | 2017-08-16 12:20:16 +0200 |
commit | 8b051e21ed6e4e4c24415c40fd0b6c6b684c071d (patch) | |
tree | d80c878f616180060682da6f8e09304bb6c9ebb8 /nat/nat2vpp/src/test | |
parent | b8cf23cd61c2d3f57f9450570236534bce69232e (diff) |
HC2VPP-105: add support for nat64 pool configuration
Change-Id: I5e57b7855e081056ad0d675084209fc9cd4add23
Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
Diffstat (limited to 'nat/nat2vpp/src/test')
3 files changed, 60 insertions, 14 deletions
diff --git a/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/NatTestSchemaContext.java b/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/NatTestSchemaContext.java index 8a30df277..041096f88 100644 --- a/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/NatTestSchemaContext.java +++ b/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/NatTestSchemaContext.java @@ -34,7 +34,9 @@ public interface NatTestSchemaContext { .getInstance(), org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.$YangModuleInfoImpl .getInstance(), - org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev170801.$YangModuleInfoImpl + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nat.rev170804.$YangModuleInfoImpl + .getInstance(), + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev170801.$YangModuleInfoImpl .getInstance())); return context; } diff --git a/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/write/ExternalIpPoolCustomizerTest.java b/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/write/ExternalIpPoolCustomizerTest.java index e2db427a5..8f25bfa12 100644 --- a/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/write/ExternalIpPoolCustomizerTest.java +++ b/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/write/ExternalIpPoolCustomizerTest.java @@ -22,10 +22,13 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; +import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; import io.fd.hc2vpp.nat.NatTestSchemaContext; import io.fd.honeycomb.test.tools.HoneycombTestRunner; import io.fd.honeycomb.test.tools.annotations.InjectTestData; import io.fd.honeycomb.translate.write.WriteFailedException; +import io.fd.vpp.jvpp.snat.dto.Nat64AddDelPoolAddrRange; +import io.fd.vpp.jvpp.snat.dto.Nat64AddDelPoolAddrRangeReply; import io.fd.vpp.jvpp.snat.dto.SnatAddAddressRange; import io.fd.vpp.jvpp.snat.dto.SnatAddAddressRangeReply; import io.fd.vpp.jvpp.snat.future.FutureJVppSnatFacade; @@ -41,7 +44,8 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev1509 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; @RunWith(HoneycombTestRunner.class) -public class ExternalIpPoolCustomizerTest extends WriterCustomizerTest implements NatTestSchemaContext { +public class ExternalIpPoolCustomizerTest extends WriterCustomizerTest implements NatTestSchemaContext, + ByteDataTranslator { private static final long NAT_INSTANCE_ID = 0; private static final long POOL_ID = 22; @@ -59,43 +63,70 @@ public class ExternalIpPoolCustomizerTest extends WriterCustomizerTest implement public void setUpTest() { customizer = new ExternalIpPoolCustomizer(jvppSnat); when(jvppSnat.snatAddAddressRange(any())).thenReturn(future(new SnatAddAddressRangeReply())); + when(jvppSnat.nat64AddDelPoolAddrRange(any())).thenReturn(future(new Nat64AddDelPoolAddrRangeReply())); } @Test - public void testWrite( - @InjectTestData(resourcePath = "/nat44/external-ip-pool.json", id = NAT_INSTANCES_PATH) NatInstances data) - throws WriteFailedException { + public void testWriteNat44( + @InjectTestData(resourcePath = "/nat44/external-ip-pool.json", id = NAT_INSTANCES_PATH) NatInstances data) + throws WriteFailedException { customizer.writeCurrentAttributes(IID, extractIpPool(data), writeContext); - final SnatAddAddressRange expectedRequest = getExpectedRequest(); - expectedRequest.isAdd = 1; + final SnatAddAddressRange expectedRequest = getExpectedRequestNat44(true); verify(jvppSnat).snatAddAddressRange(expectedRequest); } - @Test(expected = UnsupportedOperationException.class) - public void testUpdate() throws WriteFailedException { + @Test + public void testWriteNat64( + @InjectTestData(resourcePath = "/nat64/external-ip-pool.json", id = NAT_INSTANCES_PATH) NatInstances data) + throws WriteFailedException { + customizer.writeCurrentAttributes(IID, extractIpPool(data), writeContext); + final Nat64AddDelPoolAddrRange expectedRequest = getExpectedRequestNat64(true); + verify(jvppSnat).nat64AddDelPoolAddrRange(expectedRequest); + } + + @Test(expected = UnsupportedOperationException.class) + public void testUpdateNat44() throws WriteFailedException { final ExternalIpAddressPool data = mock(ExternalIpAddressPool.class); customizer.updateCurrentAttributes(IID, data, data, writeContext); } @Test - public void testDelete( - @InjectTestData(resourcePath = "/nat44/external-ip-pool.json", id = NAT_INSTANCES_PATH) NatInstances data) - throws WriteFailedException { + public void testDeleteNat44( + @InjectTestData(resourcePath = "/nat44/external-ip-pool.json", id = NAT_INSTANCES_PATH) NatInstances data) + throws WriteFailedException { customizer.deleteCurrentAttributes(IID, extractIpPool(data), writeContext); - final SnatAddAddressRange expectedRequest = getExpectedRequest(); + final SnatAddAddressRange expectedRequest = getExpectedRequestNat44(false); verify(jvppSnat).snatAddAddressRange(expectedRequest); } + @Test + public void testDeleteNat64( + @InjectTestData(resourcePath = "/nat64/external-ip-pool.json", id = NAT_INSTANCES_PATH) NatInstances data) + throws WriteFailedException { + customizer.deleteCurrentAttributes(IID, extractIpPool(data), writeContext); + final Nat64AddDelPoolAddrRange expectedRequest = getExpectedRequestNat64(false); + verify(jvppSnat).nat64AddDelPoolAddrRange(expectedRequest); + } + private static ExternalIpAddressPool extractIpPool(NatInstances data) { // assumes single nat instance and single ip pool return data.getNatInstance().get(0).getExternalIpAddressPool().get(0); } - private static SnatAddAddressRange getExpectedRequest() { + private SnatAddAddressRange getExpectedRequestNat44(final boolean isAdd) { final SnatAddAddressRange expectedRequest = new SnatAddAddressRange(); + expectedRequest.isAdd = booleanToByte(isAdd); expectedRequest.isIp4 = 1; expectedRequest.firstIpAddress = new byte[] {(byte) 192, (byte) 168, 1, 0}; expectedRequest.lastIpAddress = new byte[] {(byte) 192, (byte) 168, 1, (byte) 255}; return expectedRequest; } + + private Nat64AddDelPoolAddrRange getExpectedRequestNat64(final boolean isAdd) { + final Nat64AddDelPoolAddrRange expectedRequest = new Nat64AddDelPoolAddrRange(); + expectedRequest.isAdd = booleanToByte(isAdd); + expectedRequest.startAddr = new byte[] {(byte) 192, (byte) 168, 1, 0}; + expectedRequest.endAddr = new byte[] {(byte) 192, (byte) 168, 1, (byte) 255}; + return expectedRequest; + } }
\ No newline at end of file diff --git a/nat/nat2vpp/src/test/resources/nat64/external-ip-pool.json b/nat/nat2vpp/src/test/resources/nat64/external-ip-pool.json new file mode 100644 index 000000000..3be25d299 --- /dev/null +++ b/nat/nat2vpp/src/test/resources/nat64/external-ip-pool.json @@ -0,0 +1,13 @@ +{ + "nat-instances" : { + "nat-instance" : { + "id" : 0, + "external-ip-address-pool": { + "pool-id": 22, + "external-ip-pool": "192.168.1.1/24", + "vpp-nat:pool-type": "nat64" + } + } + } +} + |