diff options
author | Marek Gradzki <mgradzki@cisco.com> | 2018-05-10 08:41:03 +0200 |
---|---|---|
committer | Marek Gradzki <mgradzki@cisco.com> | 2018-05-17 05:20:09 +0000 |
commit | 58bb277ee19627abbf5d8c7e77aeacfe8b63995f (patch) | |
tree | 274497583238d25fbcdc3b827d18adecf2597144 /nat/nat2vpp/src/test | |
parent | 03f6001049d60c59c81408c472996cba4e703a75 (diff) |
HC2VPP-321: bump nat model to ietf-nat@2018-02-23.yang
Uses ietf-nat module as defined in
https://tools.ietf.org/html/draft-ietf-opsawg-nat-yang-14
Modifications to original model:
- ip-address is used instead of ip-prefix
(draft is not clear, see HC2VPP-325).
API changes relevant to HC/VPP:
- nat-config and nat-state merged into nat container
- nat-instances and nat-instace renamed
to instances and instance respectively
- external-ip-address-pool has new parent - policy list
- port-type choice was removed, port is now defined using
start-port-number and end-port-number leaves.
Missing end is equivalent to single-port-number case from
the older version.
TODOs:
- HC2VPP-322: single nat64Prefix per NAT instance
- HC2VPP-323: update postman collection
- HC2VPP-324: update CSIT tests.
Out of the scope of NAT model update:
- HC2VPP-326: support for nat-type handling
(vpp-nat model might become obsolete)
- HC2VPP-327: support external-realm container
(requires adding augmentations
that are alredy present in the interface-nat model).
Change-Id: Ie229a55b0a3f6ee3f8c97f4fd13c54a797a62438
Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
Diffstat (limited to 'nat/nat2vpp/src/test')
13 files changed, 160 insertions, 184 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 054bc8cee..01e66e525 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 @@ -32,9 +32,9 @@ public interface NatTestSchemaContext { .getInstance(), org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.$YangModuleInfoImpl .getInstance(), - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.$YangModuleInfoImpl + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.$YangModuleInfoImpl .getInstance(), - org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nat.rev170804.$YangModuleInfoImpl + org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nat.rev180510.$YangModuleInfoImpl .getInstance(), org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev170816.$YangModuleInfoImpl .getInstance())); diff --git a/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/read/ExternalIpPoolCustomizerTest.java b/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/read/ExternalIpPoolCustomizerTest.java index 521320591..f9e27e520 100644 --- a/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/read/ExternalIpPoolCustomizerTest.java +++ b/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/read/ExternalIpPoolCustomizerTest.java @@ -16,14 +16,15 @@ package io.fd.hc2vpp.nat.read; +import static io.fd.hc2vpp.nat.NatIds.NAT_INSTANCES_ID; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.collection.IsEmptyCollection.empty; import static org.hamcrest.core.IsCollectionContaining.hasItems; import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; -import static org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nat.rev170804.NatPoolType.Nat44; -import static org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nat.rev170804.NatPoolType.Nat64; +import static org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nat.rev180510.NatPoolType.Nat44; +import static org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nat.rev180510.NatPoolType.Nat64; import io.fd.hc2vpp.common.test.read.ListReaderCustomizerTest; import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; @@ -37,37 +38,36 @@ import java.util.List; import java.util.stream.LongStream; import org.junit.Test; import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.parameters.ExternalIpAddressPool; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.parameters.ExternalIpAddressPoolBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.parameters.ExternalIpAddressPoolKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.state.NatInstances; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.state.nat.instances.NatInstance; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.state.nat.instances.NatInstanceKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.state.nat.instances.nat.instance.NatCurrentConfig; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.state.nat.instances.nat.instance.NatCurrentConfigBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nat.rev170804.ExternalIpAddressPoolStateAugmentation; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.Instance; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.InstanceKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.instance.Policy; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.instance.PolicyBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.instance.PolicyKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.instance.policy.ExternalIpAddressPool; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.instance.policy.ExternalIpAddressPoolBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.instance.policy.ExternalIpAddressPoolKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nat.rev180510.ExternalIpAddressPoolAugmentation; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public class ExternalIpPoolCustomizerTest extends ListReaderCustomizerTest<ExternalIpAddressPool, ExternalIpAddressPoolKey, ExternalIpAddressPoolBuilder> { - private static final InstanceIdentifier<NatCurrentConfig> NAT_CONFIG_ID = - InstanceIdentifier.create(NatInstances.class) - .child(NatInstance.class, new NatInstanceKey(NatInstanceCustomizer.DEFAULT_VRF_ID)) - .child(NatCurrentConfig.class); + private static final InstanceIdentifier<Policy> POLICY_ID = + NAT_INSTANCES_ID.child(Instance.class, new InstanceKey(NatInstanceCustomizer.DEFAULT_VRF_ID)) + .child(Policy.class, new PolicyKey(0L)); private static final InstanceIdentifier<ExternalIpAddressPool> NAT_DEFAULT_POOL_WILDCARDED_ID = - NAT_CONFIG_ID.child(ExternalIpAddressPool.class); + POLICY_ID.child(ExternalIpAddressPool.class); private static final InstanceIdentifier<ExternalIpAddressPool> NAT_NON_DEFAULT_POOL_WILDCARDED_ID = - InstanceIdentifier.create(NatInstances.class).child(NatInstance.class, new NatInstanceKey(7L)) - .child(NatCurrentConfig.class).child(ExternalIpAddressPool.class); + NAT_INSTANCES_ID.child(Instance.class, new InstanceKey(7L)) + .child(Policy.class).child(ExternalIpAddressPool.class); @Mock private FutureJVppNatFacade jvppNat; public ExternalIpPoolCustomizerTest() { - super(ExternalIpAddressPool.class, NatCurrentConfigBuilder.class); + super(ExternalIpAddressPool.class, PolicyBuilder.class); } @Override @@ -84,7 +84,7 @@ public class ExternalIpPoolCustomizerTest assertEquals("192.168.44.3/32", builder.getExternalIpPool().getValue()); assertEquals(poolId, builder.getPoolId().longValue()); - assertEquals(Nat44, builder.getAugmentation(ExternalIpAddressPoolStateAugmentation.class).getPoolType()); + assertEquals(Nat44, builder.getAugmentation(ExternalIpAddressPoolAugmentation.class).getPoolType()); } @Test @@ -98,7 +98,7 @@ public class ExternalIpPoolCustomizerTest assertEquals("192.168.64.3/32", builder.getExternalIpPool().getValue()); assertEquals(poolId, builder.getPoolId().longValue()); - assertEquals(Nat64, builder.getAugmentation(ExternalIpAddressPoolStateAugmentation.class).getPoolType()); + assertEquals(Nat64, builder.getAugmentation(ExternalIpAddressPoolAugmentation.class).getPoolType()); } @Test @@ -112,7 +112,7 @@ public class ExternalIpPoolCustomizerTest assertEquals("192.168.64.3/32", builder.getExternalIpPool().getValue()); assertEquals(poolId, builder.getPoolId().longValue()); - assertEquals(Nat64, builder.getAugmentation(ExternalIpAddressPoolStateAugmentation.class).getPoolType()); + assertEquals(Nat64, builder.getAugmentation(ExternalIpAddressPoolAugmentation.class).getPoolType()); } @Test @@ -161,7 +161,7 @@ public class ExternalIpPoolCustomizerTest } private static InstanceIdentifier<ExternalIpAddressPool> getId(final long id) { - return NAT_CONFIG_ID.child(ExternalIpAddressPool.class, new ExternalIpAddressPoolKey(id)); + return POLICY_ID.child(ExternalIpAddressPool.class, new ExternalIpAddressPoolKey(id)); } private static Nat44AddressDetailsReplyDump dumpReplyNat44Empty() { diff --git a/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/read/MappingEntryCustomizerTest.java b/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/read/MappingEntryCustomizerTest.java index 576324757..7f38dc9b9 100644 --- a/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/read/MappingEntryCustomizerTest.java +++ b/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/read/MappingEntryCustomizerTest.java @@ -36,15 +36,14 @@ import java.util.List; import java.util.Optional; import org.junit.Test; import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.state.NatInstances; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.state.nat.instances.NatInstance; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.state.nat.instances.NatInstanceKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.state.nat.instances.nat.instance.MappingTable; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.state.nat.instances.nat.instance.MappingTableBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.state.nat.instances.nat.instance.mapping.table.MappingEntry; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.state.nat.instances.nat.instance.mapping.table.MappingEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.state.nat.instances.nat.instance.mapping.table.MappingEntryKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.port.number.port.type.SinglePortNumber; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.Instances; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.Instance; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.InstanceKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.instance.MappingTable; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.instance.MappingTableBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.instance.mapping.table.MappingEntry; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.instance.mapping.table.MappingEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.instance.mapping.table.MappingEntryKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public class MappingEntryCustomizerTest @@ -71,12 +70,12 @@ public class MappingEntryCustomizerTest @Override protected void setUp() throws Exception { - mappingEntryId = InstanceIdentifier.create(NatInstances.class) - .child(NatInstance.class, new NatInstanceKey(NatInstanceCustomizer.DEFAULT_VRF_ID)) + mappingEntryId = InstanceIdentifier.create(Instances.class) + .child(Instance.class, new InstanceKey(NatInstanceCustomizer.DEFAULT_VRF_ID)) .child(MappingTable.class) .child(MappingEntry.class, new MappingEntryKey(NAT_MAPPING_ID)); - mappingEntryWildcarded = InstanceIdentifier.create(NatInstances.class) - .child(NatInstance.class, new NatInstanceKey(NatInstanceCustomizer.DEFAULT_VRF_ID)) + mappingEntryWildcarded = InstanceIdentifier.create(Instances.class) + .child(Instance.class, new InstanceKey(NatInstanceCustomizer.DEFAULT_VRF_ID)) .child(MappingTable.class) .child(MappingEntry.class); nat44DumpManager = new DumpCacheManager.DumpCacheManagerBuilder<Nat44StaticMappingDetailsReplyDump, Void>() @@ -100,13 +99,9 @@ public class MappingEntryCustomizerTest assertEquals(NAT_MAPPING_ID, builder.getIndex().longValue()); assertEquals("192.168.3.8", builder.getExternalSrcAddress().getValue()); - assertEquals(6874, - ((SinglePortNumber) builder.getExternalSrcPort().getPortType()).getSinglePortNumber().getValue() - .intValue()); + assertEquals(6874, builder.getExternalSrcPort().getStartPortNumber().getValue().intValue()); assertArrayEquals("192.168.2.2".toCharArray(), builder.getInternalSrcAddress().getValue()); - assertEquals(1274, - ((SinglePortNumber) builder.getInternalSrcPort().getPortType()).getSinglePortNumber().getValue() - .intValue()); + assertEquals(1274, builder.getInternalSrcPort().getStartPortNumber().getValue().intValue()); } @Test @@ -118,12 +113,8 @@ public class MappingEntryCustomizerTest final MappingEntryBuilder builder = new MappingEntryBuilder(); getCustomizer().readCurrentAttributes(mappingEntryId, builder, ctx); - assertEquals(65535, - ((SinglePortNumber) builder.getExternalSrcPort().getPortType()).getSinglePortNumber().getValue() - .intValue()); - assertEquals(60000, - ((SinglePortNumber) builder.getInternalSrcPort().getPortType()).getSinglePortNumber().getValue() - .intValue()); + assertEquals(65535, builder.getExternalSrcPort().getStartPortNumber().getValue().intValue()); + assertEquals(60000, builder.getInternalSrcPort().getStartPortNumber().getValue().intValue()); } @Test @@ -138,13 +129,9 @@ public class MappingEntryCustomizerTest assertEquals(NAT_MAPPING_ID, builder.getIndex().longValue()); assertEquals("192.168.64.3", builder.getExternalSrcAddress().getValue()); - assertEquals(6874, - ((SinglePortNumber) builder.getExternalSrcPort().getPortType()).getSinglePortNumber().getValue() - .intValue()); + assertEquals(6874, builder.getExternalSrcPort().getStartPortNumber().getValue().intValue()); assertArrayEquals("2001:db8:85a3::8a2e:370:7303".toCharArray(), builder.getInternalSrcAddress().getValue()); - assertEquals(1274, - ((SinglePortNumber) builder.getInternalSrcPort().getPortType()).getSinglePortNumber().getValue() - .intValue()); + assertEquals(1274, builder.getInternalSrcPort().getStartPortNumber().getValue().intValue()); } @Test @@ -157,12 +144,8 @@ public class MappingEntryCustomizerTest final MappingEntryBuilder builder = new MappingEntryBuilder(); getCustomizer().readCurrentAttributes(mappingEntryId, builder, ctx); - assertEquals(65535, - ((SinglePortNumber) builder.getExternalSrcPort().getPortType()).getSinglePortNumber().getValue() - .intValue()); - assertEquals(60000, - ((SinglePortNumber) builder.getInternalSrcPort().getPortType()).getSinglePortNumber().getValue() - .intValue()); + assertEquals(65535, builder.getExternalSrcPort().getStartPortNumber().getValue().intValue()); + assertEquals(60000, builder.getInternalSrcPort().getStartPortNumber().getValue().intValue()); } @Test diff --git a/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/read/Nat64PrefixesCustomizerTest.java b/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/read/Nat64PrefixesCustomizerTest.java index bdb1793ff..2aae28a9e 100644 --- a/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/read/Nat64PrefixesCustomizerTest.java +++ b/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/read/Nat64PrefixesCustomizerTest.java @@ -33,14 +33,15 @@ import java.util.List; import org.junit.Test; import org.mockito.Mock; 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.nat.rev150908.nat.parameters.Nat64Prefixes; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.parameters.Nat64PrefixesBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.parameters.Nat64PrefixesKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.state.NatInstances; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.state.nat.instances.NatInstance; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.state.nat.instances.NatInstanceKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.state.nat.instances.nat.instance.NatCurrentConfig; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.state.nat.instances.nat.instance.NatCurrentConfigBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.Instances; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.Instance; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.InstanceKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.instance.Policy; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.instance.PolicyBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.instance.PolicyKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.instance.policy.Nat64Prefixes; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.instance.policy.Nat64PrefixesBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.instance.policy.Nat64PrefixesKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public class Nat64PrefixesCustomizerTest extends ListReaderCustomizerTest<Nat64Prefixes, Nat64PrefixesKey, Nat64PrefixesBuilder> { @@ -49,7 +50,7 @@ public class Nat64PrefixesCustomizerTest extends ListReaderCustomizerTest<Nat64P private FutureJVppNatFacade jvppNat; public Nat64PrefixesCustomizerTest() { - super(Nat64Prefixes.class, NatCurrentConfigBuilder.class); + super(Nat64Prefixes.class, PolicyBuilder.class); } @Override @@ -70,14 +71,7 @@ public class Nat64PrefixesCustomizerTest extends ListReaderCustomizerTest<Nat64P final long vrfId = 0; final List<Nat64PrefixesKey> allIds = getCustomizer().getAllIds(getWildcardedId(vrfId), ctx); assertEquals(1, allIds.size()); - assertEquals(new Nat64PrefixesKey(0L), allIds.get(0)); - } - - @Test - public void testReadNonZeroId() throws ReadFailedException { - final Nat64PrefixesBuilder builder = mock(Nat64PrefixesBuilder.class); - getCustomizer().readCurrentAttributes(getId(0L, 42L), builder, ctx); - verifyZeroInteractions(builder); + assertEquals(new Nat64PrefixesKey(new Ipv6Prefix("64:ff9b::1/96")), allIds.get(0)); } @Test @@ -85,7 +79,7 @@ public class Nat64PrefixesCustomizerTest extends ListReaderCustomizerTest<Nat64P final long vrfId = 123; when(jvppNat.nat64PrefixDump(any())).thenReturn(future(dump())); final Nat64PrefixesBuilder builder = mock(Nat64PrefixesBuilder.class); - getCustomizer().readCurrentAttributes(getId(vrfId, 0L), builder, ctx); + getCustomizer().readCurrentAttributes(getId(vrfId, "::1/128"), builder, ctx); verifyZeroInteractions(builder); } @@ -94,23 +88,22 @@ public class Nat64PrefixesCustomizerTest extends ListReaderCustomizerTest<Nat64P final long vrfId = 1; when(jvppNat.nat64PrefixDump(any())).thenReturn(future(dump())); final Nat64PrefixesBuilder builder = mock(Nat64PrefixesBuilder.class); - getCustomizer().readCurrentAttributes(getId(vrfId, 0L), builder, ctx); - verify(builder).setNat64PrefixId(0L); + getCustomizer().readCurrentAttributes(getId(vrfId, "::1/128"), builder, ctx); verify(builder).setNat64Prefix(new Ipv6Prefix("::1/128")); } private static InstanceIdentifier<Nat64Prefixes> getWildcardedId(final long vrfId) { - return InstanceIdentifier.create(NatInstances.class) - .child(NatInstance.class, new NatInstanceKey(vrfId)) - .child(NatCurrentConfig.class) + return InstanceIdentifier.create(Instances.class) + .child(Instance.class, new InstanceKey(vrfId)) + .child(Policy.class, new PolicyKey(0L)) .child(Nat64Prefixes.class); } - private static InstanceIdentifier<Nat64Prefixes> getId(final long vrfId, final long prefixId) { - return InstanceIdentifier.create(NatInstances.class) - .child(NatInstance.class, new NatInstanceKey(vrfId)) - .child(NatCurrentConfig.class) - .child(Nat64Prefixes.class, new Nat64PrefixesKey(prefixId)); + private static InstanceIdentifier<Nat64Prefixes> getId(final long vrfId, final String prefix) { + return InstanceIdentifier.create(Instances.class) + .child(Instance.class, new InstanceKey(vrfId)) + .child(Policy.class, new PolicyKey(0L)) + .child(Nat64Prefixes.class, new Nat64PrefixesKey(new Ipv6Prefix(prefix))); } private Nat64PrefixDetailsReplyDump dump() { diff --git a/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/read/NatInstanceCustomizerTest.java b/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/read/NatInstanceCustomizerTest.java index 8978fe5ba..5974f4a45 100644 --- a/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/read/NatInstanceCustomizerTest.java +++ b/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/read/NatInstanceCustomizerTest.java @@ -35,28 +35,28 @@ import java.util.Arrays; import java.util.List; import org.junit.Test; import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.state.NatInstances; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.state.NatInstancesBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.state.nat.instances.NatInstance; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.state.nat.instances.NatInstanceBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.state.nat.instances.NatInstanceKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.Instances; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.InstancesBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.Instance; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.InstanceBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.InstanceKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; public class NatInstanceCustomizerTest - extends InitializingListReaderCustomizerTest<NatInstance, NatInstanceKey, NatInstanceBuilder> { + extends InitializingListReaderCustomizerTest<Instance, InstanceKey, InstanceBuilder> { @Mock private EntityDumpExecutor<Nat44StaticMappingDetailsReplyDump, Void> nat44DumpExecutor; @Mock private EntityDumpExecutor<Nat64BibDetailsReplyDump, Void> nat64DumpExecutor; - private KeyedInstanceIdentifier<NatInstance, NatInstanceKey> natInstanceId; - private InstanceIdentifier<NatInstance> natInstanceWildcarded; + private KeyedInstanceIdentifier<Instance, InstanceKey> natInstanceId; + private InstanceIdentifier<Instance> natInstanceWildcarded; private DumpCacheManager<Nat44StaticMappingDetailsReplyDump, Void> mapEntryNat44DumpMgr; private DumpCacheManager<Nat64BibDetailsReplyDump, Void> mapEntryNat64DumpMgr; public NatInstanceCustomizerTest() { - super(NatInstance.class, NatInstancesBuilder.class); + super(Instance.class, InstancesBuilder.class); } @Override @@ -66,10 +66,10 @@ public class NatInstanceCustomizerTest @Override protected void setUp() throws Exception { - natInstanceId = InstanceIdentifier.create(NatInstances.class) - .child(NatInstance.class, new NatInstanceKey(NatInstanceCustomizer.DEFAULT_VRF_ID)); - natInstanceWildcarded = InstanceIdentifier.create(NatInstances.class) - .child(NatInstance.class); + natInstanceId = InstanceIdentifier.create(Instances.class) + .child(Instance.class, new InstanceKey(NatInstanceCustomizer.DEFAULT_VRF_ID)); + natInstanceWildcarded = InstanceIdentifier.create(Instances.class) + .child(Instance.class); mapEntryNat44DumpMgr = new DumpCacheManager.DumpCacheManagerBuilder<Nat44StaticMappingDetailsReplyDump, Void>() .withExecutor(nat44DumpExecutor) .acceptOnly(Nat44StaticMappingDetailsReplyDump.class) @@ -82,7 +82,7 @@ public class NatInstanceCustomizerTest @Test public void testRead() throws ReadFailedException { - final NatInstanceBuilder builder = mock(NatInstanceBuilder.class); + final InstanceBuilder builder = mock(InstanceBuilder.class); getCustomizer().readCurrentAttributes(natInstanceId, builder, ctx); verify(builder).setId(natInstanceId.getKey().getId()); } @@ -91,11 +91,11 @@ public class NatInstanceCustomizerTest public void testReadAll() throws ReadFailedException { when(nat44DumpExecutor.executeDump(natInstanceWildcarded, null)).thenReturn(nat44NonEmptyDump()); when(nat64DumpExecutor.executeDump(natInstanceWildcarded, null)).thenReturn(nat64NonEmptyDump()); - final List<NatInstanceKey> allIds = getCustomizer().getAllIds(natInstanceWildcarded, ctx); + final List<InstanceKey> allIds = getCustomizer().getAllIds(natInstanceWildcarded, ctx); assertThat(allIds, hasSize(6)); assertThat(allIds, hasItems( - new NatInstanceKey(0L), new NatInstanceKey(1L), new NatInstanceKey(2L), new NatInstanceKey(3L), - new NatInstanceKey(5L), new NatInstanceKey(6L))); + new InstanceKey(0L), new InstanceKey(1L), new InstanceKey(2L), new InstanceKey(3L), + new InstanceKey(5L), new InstanceKey(6L))); } private static Nat44StaticMappingDetailsReplyDump nat44NonEmptyDump() { diff --git a/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/util/MappingEntryContextTest.java b/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/util/MappingEntryContextTest.java index cd173fddc..df5912bce 100644 --- a/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/util/MappingEntryContextTest.java +++ b/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/util/MappingEntryContextTest.java @@ -37,9 +37,9 @@ import org.mockito.Mock; import org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.nat.context.rev161214.mapping.entry.context.attributes.nat.mapping.entry.context.nat.instance.MappingTableBuilder; 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.nat.rev150908.nat.config.nat.instances.nat.instance.mapping.table.MappingEntry; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.nat.instance.mapping.table.MappingEntryBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.nat.instance.mapping.table.MappingEntryKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.instance.mapping.table.MappingEntry; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.instance.mapping.table.MappingEntryBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.instance.mapping.table.MappingEntryKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; @SuppressWarnings("unchecked") @@ -189,7 +189,7 @@ public class MappingEntryContextTest implements Ipv4Translator { private static MappingEntry getEntry(final long id, final String longernalIpv4, final String externalIpv4) { return new MappingEntryBuilder() .setKey(new MappingEntryKey(id)) - .setType(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.MappingEntry.Type.Static) + .setType(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.MappingEntry.Type.Static) .setInternalSrcAddress(new IpAddress(new Ipv4Address(longernalIpv4))) .setExternalSrcAddress(new Ipv4Address(externalIpv4)) .build(); 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 db68ecf6a..294473937 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 @@ -16,6 +16,7 @@ package io.fd.hc2vpp.nat.write; +import static io.fd.hc2vpp.nat.NatIds.NAT_INSTANCES_ID; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -35,12 +36,13 @@ import io.fd.vpp.jvpp.nat.future.FutureJVppNatFacade; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.NatConfig; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.NatInstances; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.NatInstance; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.NatInstanceKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.parameters.ExternalIpAddressPool; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.parameters.ExternalIpAddressPoolKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.Instances; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.Instance; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.InstanceKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.instance.Policy; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.instance.PolicyKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.instance.policy.ExternalIpAddressPool; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.instance.policy.ExternalIpAddressPoolKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; @RunWith(HoneycombTestRunner.class) @@ -49,11 +51,11 @@ public class ExternalIpPoolCustomizerTest extends WriterCustomizerTest implement private static final long NAT_INSTANCE_ID = 0; private static final long POOL_ID = 22; - private static final InstanceIdentifier<ExternalIpAddressPool> IID = InstanceIdentifier.create(NatConfig.class) - .child(NatInstances.class).child(NatInstance.class, new NatInstanceKey(NAT_INSTANCE_ID)) + private static final InstanceIdentifier<ExternalIpAddressPool> IID = NAT_INSTANCES_ID + .child(Instance.class, new InstanceKey(NAT_INSTANCE_ID)).child(Policy.class, new PolicyKey(0L)) .child(ExternalIpAddressPool.class, new ExternalIpAddressPoolKey(POOL_ID)); - private static final String NAT_INSTANCES_PATH = "/ietf-nat:nat-config/ietf-nat:nat-instances"; + private static final String NAT_INSTANCES_PATH = "/ietf-nat:nat/ietf-nat:instances"; @Mock private FutureJVppNatFacade jvppNat; @@ -68,7 +70,7 @@ public class ExternalIpPoolCustomizerTest extends WriterCustomizerTest implement @Test public void testWriteNat44( - @InjectTestData(resourcePath = "/nat44/external-ip-pool.json", id = NAT_INSTANCES_PATH) NatInstances data) + @InjectTestData(resourcePath = "/nat44/external-ip-pool.json", id = NAT_INSTANCES_PATH) Instances data) throws WriteFailedException { customizer.writeCurrentAttributes(IID, extractIpPool(data), writeContext); final Nat44AddDelAddressRange expectedRequest = getExpectedRequestNat44(true); @@ -77,7 +79,7 @@ public class ExternalIpPoolCustomizerTest extends WriterCustomizerTest implement @Test public void testWriteNat64( - @InjectTestData(resourcePath = "/nat64/external-ip-pool.json", id = NAT_INSTANCES_PATH) NatInstances data) + @InjectTestData(resourcePath = "/nat64/external-ip-pool.json", id = NAT_INSTANCES_PATH) Instances data) throws WriteFailedException { customizer.writeCurrentAttributes(IID, extractIpPool(data), writeContext); final Nat64AddDelPoolAddrRange expectedRequest = getExpectedRequestNat64(true); @@ -92,7 +94,7 @@ public class ExternalIpPoolCustomizerTest extends WriterCustomizerTest implement @Test public void testDeleteNat44( - @InjectTestData(resourcePath = "/nat44/external-ip-pool.json", id = NAT_INSTANCES_PATH) NatInstances data) + @InjectTestData(resourcePath = "/nat44/external-ip-pool.json", id = NAT_INSTANCES_PATH) Instances data) throws WriteFailedException { customizer.deleteCurrentAttributes(IID, extractIpPool(data), writeContext); final Nat44AddDelAddressRange expectedRequest = getExpectedRequestNat44(false); @@ -101,16 +103,16 @@ public class ExternalIpPoolCustomizerTest extends WriterCustomizerTest implement @Test public void testDeleteNat64( - @InjectTestData(resourcePath = "/nat64/external-ip-pool.json", id = NAT_INSTANCES_PATH) NatInstances data) + @InjectTestData(resourcePath = "/nat64/external-ip-pool.json", id = NAT_INSTANCES_PATH) Instances data) throws WriteFailedException { customizer.deleteCurrentAttributes(IID, extractIpPool(data), writeContext); final Nat64AddDelPoolAddrRange expectedRequest = getExpectedRequestNat64(false); verify(jvppNat).nat64AddDelPoolAddrRange(expectedRequest); } - private static ExternalIpAddressPool extractIpPool(NatInstances data) { + private static ExternalIpAddressPool extractIpPool(Instances data) { // assumes single nat instance and single ip pool - return data.getNatInstance().get(0).getExternalIpAddressPool().get(0); + return data.getInstance().get(0).getPolicy().get(0).getExternalIpAddressPool().get(0); } private Nat44AddDelAddressRange getExpectedRequestNat44(final boolean isAdd) { diff --git a/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/write/MappingEntryCustomizerTest.java b/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/write/MappingEntryCustomizerTest.java index 29869381a..95bce699a 100644 --- a/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/write/MappingEntryCustomizerTest.java +++ b/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/write/MappingEntryCustomizerTest.java @@ -16,6 +16,7 @@ package io.fd.hc2vpp.nat.write; +import static io.fd.hc2vpp.nat.NatIds.NAT_INSTANCES_ID; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -34,13 +35,11 @@ import io.fd.vpp.jvpp.nat.future.FutureJVppNatFacade; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.NatConfig; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.NatInstances; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.NatInstance; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.NatInstanceKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.nat.instance.MappingTable; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.nat.instance.mapping.table.MappingEntry; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.nat.instance.mapping.table.MappingEntryKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.Instance; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.InstanceKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.instance.MappingTable; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.instance.mapping.table.MappingEntry; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.instance.mapping.table.MappingEntryKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; @RunWith(HoneycombTestRunner.class) @@ -48,12 +47,12 @@ public class MappingEntryCustomizerTest extends WriterCustomizerTest implements private static final long NAT_INSTANCE_ID = 1; private static final long MAPPING_ID = 22; - private static final InstanceIdentifier<MappingEntry> IID = InstanceIdentifier.create(NatConfig.class) - .child(NatInstances.class).child(NatInstance.class, new NatInstanceKey(NAT_INSTANCE_ID)) + private static final InstanceIdentifier<MappingEntry> IID = NAT_INSTANCES_ID + .child(Instance.class, new InstanceKey(NAT_INSTANCE_ID)) .child(MappingTable.class).child(MappingEntry.class, new MappingEntryKey(MAPPING_ID)); - private static final String MAPPING_TABLE_PATH = "/ietf-nat:nat-config/ietf-nat:nat-instances/" - + "ietf-nat:nat-instance[ietf-nat:id='" + NAT_INSTANCE_ID + "']/ietf-nat:mapping-table"; + private static final String MAPPING_TABLE_PATH = "/ietf-nat:nat/ietf-nat:instances/" + + "ietf-nat:instance[ietf-nat:id='" + NAT_INSTANCE_ID + "']/ietf-nat:mapping-table"; @Mock private FutureJVppNatFacade jvppNat; @@ -145,7 +144,9 @@ public class MappingEntryCustomizerTest extends WriterCustomizerTest implements expectedRequest.proto = 58; // icmp v6 expectedRequest.vrfId = (int) NAT_INSTANCE_ID; expectedRequest.iAddr = new byte[] {0x20, 0x01, 0x0d, (byte) 0xb8, (byte) 0x85, (byte) 0xa3, 0, 0, 0, 0, (byte) 0x8a, 0x2e, 0x03, 0x70, 0x73, 0x33}; + expectedRequest.iPort = 123; expectedRequest.oAddr = new byte[] {10, 1, 1, 3}; + expectedRequest.oPort = 456; return expectedRequest; } diff --git a/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/write/Nat64PrefixesCustomizerTest.java b/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/write/Nat64PrefixesCustomizerTest.java index 63a3b4673..2d3290e7c 100644 --- a/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/write/Nat64PrefixesCustomizerTest.java +++ b/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/write/Nat64PrefixesCustomizerTest.java @@ -16,8 +16,8 @@ package io.fd.hc2vpp.nat.write; +import static io.fd.hc2vpp.nat.NatIds.NAT_INSTANCES_ID; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -26,28 +26,27 @@ import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; import io.fd.vpp.jvpp.nat.dto.Nat64AddDelPrefix; import io.fd.vpp.jvpp.nat.dto.Nat64AddDelPrefixReply; import io.fd.vpp.jvpp.nat.future.FutureJVppNatFacade; -import java.util.Collections; import org.junit.Test; import org.mockito.Mock; 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.nat.rev150908.NatConfig; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.NatInstances; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.NatInstance; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.NatInstanceKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.parameters.Nat64Prefixes; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.parameters.Nat64PrefixesBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.parameters.Nat64PrefixesKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.parameters.nat64.prefixes.DestinationIpv4Prefix; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.Instance; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.InstanceKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.instance.Policy; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.instance.PolicyKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.instance.policy.Nat64Prefixes; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.instance.policy.Nat64PrefixesBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.instance.policy.Nat64PrefixesKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public class Nat64PrefixesCustomizerTest extends WriterCustomizerTest implements ByteDataTranslator { private static final long VRF_ID = 123; - private static final InstanceIdentifier<NatInstance> NAT_INSTANCE_ID = - InstanceIdentifier.create(NatConfig.class).child(NatInstances.class).child(NatInstance.class, new NatInstanceKey(VRF_ID)); + private static final InstanceIdentifier<Policy> POLICY_ID = + NAT_INSTANCES_ID.child(Instance.class, new InstanceKey(VRF_ID)).child(Policy.class, new PolicyKey(0L)); - private static final Nat64Prefixes VALID_DATA = new Nat64PrefixesBuilder().setNat64Prefix(new Ipv6Prefix("2001:db8::/32")).build(); + private static final Nat64Prefixes + VALID_DATA = new Nat64PrefixesBuilder().setNat64Prefix(new Ipv6Prefix("2001:db8::/32")).build(); @Mock private FutureJVppNatFacade jvppNat; @@ -60,32 +59,20 @@ public class Nat64PrefixesCustomizerTest extends WriterCustomizerTest implements when(jvppNat.nat64AddDelPrefix(any())).thenReturn(future(new Nat64AddDelPrefixReply())); } - @Test(expected = IllegalArgumentException.class) - public void testWriteNonZeroPrefixIdFails() throws Exception { - customizer.writeCurrentAttributes(getID(1), mock(Nat64Prefixes.class), writeContext); - } - - @Test(expected = IllegalArgumentException.class) - public void testWriteDestinationPrefixFails() throws Exception { - final Nat64Prefixes data = mock(Nat64Prefixes.class); - when(data.getDestinationIpv4Prefix()).thenReturn(Collections.singletonList(mock(DestinationIpv4Prefix.class))); - customizer.writeCurrentAttributes(getID(1), data, writeContext); - } - @Test public void testWrite() throws Exception { - customizer.writeCurrentAttributes(getID(0), VALID_DATA, writeContext); + customizer.writeCurrentAttributes(getID("::1/128"), VALID_DATA, writeContext); verify(jvppNat).nat64AddDelPrefix(expectedRequest(true)); } @Test public void testDelete() throws Exception { - customizer.deleteCurrentAttributes(getID(0), VALID_DATA, writeContext); + customizer.deleteCurrentAttributes(getID("::1/128"), VALID_DATA, writeContext); verify(jvppNat).nat64AddDelPrefix(expectedRequest(false)); } - private static InstanceIdentifier<Nat64Prefixes> getID(final long prefixId) { - return NAT_INSTANCE_ID.child(Nat64Prefixes.class, new Nat64PrefixesKey(prefixId)); + private static InstanceIdentifier<Nat64Prefixes> getID(final String prefix) { + return POLICY_ID.child(Nat64Prefixes.class, new Nat64PrefixesKey(new Ipv6Prefix(prefix))); } private Nat64AddDelPrefix expectedRequest(final boolean isAdd) { diff --git a/nat/nat2vpp/src/test/resources/nat44/external-ip-pool.json b/nat/nat2vpp/src/test/resources/nat44/external-ip-pool.json index 37e8e907f..8e309ef2f 100644 --- a/nat/nat2vpp/src/test/resources/nat44/external-ip-pool.json +++ b/nat/nat2vpp/src/test/resources/nat44/external-ip-pool.json @@ -1,12 +1,14 @@ { - "nat-instances" : { - "nat-instance" : { - "id" : 0, - "external-ip-address-pool": { - "pool-id": 22, - "external-ip-pool": "192.168.1.1/24" + "instances": { + "instance": { + "id": 0, + "policy": { + "id": 0, + "external-ip-address-pool": { + "pool-id": 22, + "external-ip-pool": "192.168.1.1/24" + } } } } } - diff --git a/nat/nat2vpp/src/test/resources/nat64/external-ip-pool.json b/nat/nat2vpp/src/test/resources/nat64/external-ip-pool.json index 3be25d299..724407b29 100644 --- a/nat/nat2vpp/src/test/resources/nat64/external-ip-pool.json +++ b/nat/nat2vpp/src/test/resources/nat64/external-ip-pool.json @@ -1,13 +1,15 @@ { - "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" + "instances": { + "instance": { + "id": 0, + "policy": { + "id": 0, + "external-ip-address-pool": { + "pool-id": 22, + "external-ip-pool": "192.168.1.1/24", + "vpp-nat:pool-type": "nat64" + } } } } } - diff --git a/nat/nat2vpp/src/test/resources/nat64/static-mapping-address-update.json b/nat/nat2vpp/src/test/resources/nat64/static-mapping-address-update.json index 73f2c0e55..2e836ce91 100644 --- a/nat/nat2vpp/src/test/resources/nat64/static-mapping-address-update.json +++ b/nat/nat2vpp/src/test/resources/nat64/static-mapping-address-update.json @@ -7,10 +7,10 @@ "internal-src-address": "2001:db8:85a3::8a2e:370:7334", "external-src-address": "10.1.1.4", "internal-src-port" : { - "single-port-number" : 1234 + "start-port-number" : 1234 }, "external-src-port" : { - "single-port-number" : 5678 + "start-port-number" : 5678 } } } diff --git a/nat/nat2vpp/src/test/resources/nat64/static-mapping.json b/nat/nat2vpp/src/test/resources/nat64/static-mapping.json index d3a1c40c4..9fff452a2 100644 --- a/nat/nat2vpp/src/test/resources/nat64/static-mapping.json +++ b/nat/nat2vpp/src/test/resources/nat64/static-mapping.json @@ -5,7 +5,13 @@ "type": "static", "transport-protocol": 58, "internal-src-address": "2001:db8:85a3::8a2e:370:7333", - "external-src-address": "10.1.1.3" + "internal-src-port": { + "start-port-number": 123 + }, + "external-src-address": "10.1.1.3", + "external-src-port": { + "start-port-number": 456 + } } } } |