diff options
Diffstat (limited to 'nat/nat2vpp')
26 files changed, 439 insertions, 442 deletions
diff --git a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/NatIds.java b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/NatIds.java new file mode 100644 index 000000000..c0aa538d5 --- /dev/null +++ b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/NatIds.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.nat; + +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.Nat; +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.instance.MappingTable; +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.mapping.table.MappingEntry; +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.Nat64Prefixes; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public interface NatIds { + InstanceIdentifier<Nat> NAT_ID = InstanceIdentifier.create(Nat.class); + InstanceIdentifier<Instances> NAT_INSTANCES_ID = NAT_ID.child(Instances.class); + InstanceIdentifier<Instance> NAT_INSTANCE_ID = NAT_INSTANCES_ID.child(Instance.class); + InstanceIdentifier<MappingTable> MAPPING_TABLE_ID = NAT_INSTANCE_ID.child(MappingTable.class); + InstanceIdentifier<MappingEntry> MAPPING_ENTRY_ID = MAPPING_TABLE_ID.child(MappingEntry.class); + InstanceIdentifier<Policy> POLICY_ID = NAT_INSTANCE_ID.child(Policy.class); + InstanceIdentifier<ExternalIpAddressPool> ADDRESS_POOL_ID = POLICY_ID.child(ExternalIpAddressPool.class); + InstanceIdentifier<Nat64Prefixes> NAT64_PREFIXES_ID = POLICY_ID.child(Nat64Prefixes.class); +} diff --git a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ExternalIpPoolCustomizer.java b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ExternalIpPoolCustomizer.java index 77b5b2cf6..cfc9be4ce 100644 --- a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ExternalIpPoolCustomizer.java +++ b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ExternalIpPoolCustomizer.java @@ -24,7 +24,6 @@ import io.fd.honeycomb.translate.read.ReadContext; import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.Initialized; import io.fd.honeycomb.translate.spi.read.InitializingListReaderCustomizer; -import io.fd.honeycomb.translate.util.RWUtils; import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; import io.fd.vpp.jvpp.nat.dto.Nat44AddressDetails; import io.fd.vpp.jvpp.nat.dto.Nat44AddressDetailsReplyDump; @@ -39,15 +38,15 @@ import java.util.stream.Collectors; import java.util.stream.LongStream; import javax.annotation.Nonnull; 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.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.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.NatCurrentConfigBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nat.rev170804.ExternalIpAddressPoolStateAugmentation; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nat.rev170804.ExternalIpAddressPoolStateAugmentationBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nat.rev170804.NatPoolType; +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.PolicyBuilder; +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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nat.rev180510.ExternalIpAddressPoolAugmentationBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nat.rev180510.NatPoolType; import org.opendaylight.yangtools.concepts.Builder; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; @@ -76,13 +75,8 @@ final class ExternalIpPoolCustomizer implements } private static void setPoolType(@Nonnull final ExternalIpAddressPoolBuilder builder, final NatPoolType poolType) { - builder.addAugmentation(ExternalIpAddressPoolStateAugmentation.class, - new ExternalIpAddressPoolStateAugmentationBuilder().setPoolType(poolType).build()); - } - - static InstanceIdentifier<ExternalIpAddressPool> getCfgId(final @Nonnull InstanceIdentifier<ExternalIpAddressPool> id) { - return NatInstanceCustomizer.getCfgId(RWUtils.cutId(id, NatInstance.class)) - .child(ExternalIpAddressPool.class, id.firstKeyOf(ExternalIpAddressPool.class)); + builder.addAugmentation(ExternalIpAddressPoolAugmentation.class, + new ExternalIpAddressPoolAugmentationBuilder().setPoolType(poolType).build()); } @Nonnull @@ -138,7 +132,7 @@ final class ExternalIpPoolCustomizer implements @Override public List<ExternalIpAddressPoolKey> getAllIds(@Nonnull final InstanceIdentifier<ExternalIpAddressPool> id, @Nonnull final ReadContext ctx) throws ReadFailedException { - final NatInstanceKey natKey = id.firstKeyOf(NatInstance.class); + final InstanceKey natKey = id.firstKeyOf(Instance.class); if (!natKey.equals(NatInstanceCustomizer.DEFAULT_VRF_ID)) { // IP Pools are not vrf aware ... so they are only visible under default vrf (nat-instance) return Collections.emptyList(); @@ -174,7 +168,7 @@ final class ExternalIpPoolCustomizer implements @Override public void merge(@Nonnull final Builder<? extends DataObject> builder, @Nonnull final List<ExternalIpAddressPool> readData) { - ((NatCurrentConfigBuilder) builder).setExternalIpAddressPool(readData); + ((PolicyBuilder) builder).setExternalIpAddressPool(readData); } @Override @@ -182,6 +176,6 @@ final class ExternalIpPoolCustomizer implements @Nonnull final InstanceIdentifier<ExternalIpAddressPool> id, @Nonnull final ExternalIpAddressPool readValue, @Nonnull final ReadContext ctx) { - return Initialized.create(getCfgId(id), readValue); + return Initialized.create(id, readValue); } } diff --git a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/MappingEntryCustomizer.java b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/MappingEntryCustomizer.java index 9075f4d0c..43dba092a 100644 --- a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/MappingEntryCustomizer.java +++ b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/MappingEntryCustomizer.java @@ -24,7 +24,6 @@ import io.fd.honeycomb.translate.read.ReadContext; import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.Initialized; import io.fd.honeycomb.translate.spi.read.InitializingListReaderCustomizer; -import io.fd.honeycomb.translate.util.RWUtils; import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; import io.fd.honeycomb.translate.util.read.cache.EntityDumpExecutor; import io.fd.vpp.jvpp.nat.dto.Nat44StaticMappingDetails; @@ -40,15 +39,13 @@ import java.util.stream.Collectors; import javax.annotation.Nonnull; 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.PortNumber; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.mapping.entry.ExternalSrcPortBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.mapping.entry.InternalSrcPortBuilder; -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.state.nat.instances.NatInstance; -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.SinglePortNumberBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.mapping.entry.ExternalSrcPortBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.mapping.entry.InternalSrcPortBuilder; +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.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.concepts.Builder; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; @@ -56,7 +53,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; final class MappingEntryCustomizer implements Ipv4Translator, Ipv6Translator, - InitializingListReaderCustomizer<MappingEntry, MappingEntryKey, MappingEntryBuilder> { + InitializingListReaderCustomizer<MappingEntry, MappingEntryKey, MappingEntryBuilder> { private static final Logger LOG = LoggerFactory.getLogger(MappingEntryCustomizer.class); @@ -86,7 +83,7 @@ final class MappingEntryCustomizer implements Ipv4Translator, Ipv6Translator, LOG.trace("Reading current attributes for mapping-entry: {}", id); final int idx = id.firstKeyOf(MappingEntry.class).getIndex().intValue(); - final int natInstanceId = id.firstKeyOf(NatInstance.class).getId().intValue(); + final int natInstanceId = id.firstKeyOf(Instance.class).getId().intValue(); final List<Nat44StaticMappingDetails> nat44Details = nat44DumpManager.getDump(id, ctx.getModificationCache()) .or(new Nat44StaticMappingDetailsReplyDump()).nat44StaticMappingDetails; @@ -116,22 +113,16 @@ final class MappingEntryCustomizer implements Ipv4Translator, Ipv6Translator, final int index, final Nat44StaticMappingDetails detail) { builder.setIndex((long) index); builder.setType( - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.MappingEntry.Type.Static); + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.MappingEntry.Type.Static); builder.setExternalSrcAddress(arrayToIpv4AddressNoZone(detail.externalIpAddress)); builder.setInternalSrcAddress( new IpAddress(arrayToIpv4AddressNoZone(detail.localIpAddress))); if (detail.addrOnly == 0) { builder.setExternalSrcPort(new ExternalSrcPortBuilder() - .setPortType(new SinglePortNumberBuilder().setSinglePortNumber(new PortNumber( - Short.toUnsignedInt(detail.externalPort))) - .build()) - .build()); + .setStartPortNumber(new PortNumber(Short.toUnsignedInt(detail.externalPort))).build()); builder.setInternalSrcPort(new InternalSrcPortBuilder() - .setPortType(new SinglePortNumberBuilder().setSinglePortNumber(new PortNumber( - Short.toUnsignedInt(detail.localPort))) - .build()) - .build()); + .setStartPortNumber(new PortNumber(Short.toUnsignedInt(detail.localPort))).build()); } } @@ -140,32 +131,26 @@ final class MappingEntryCustomizer implements Ipv4Translator, Ipv6Translator, builder.setIndex((long) index); if (detail.isStatic == 1) { builder.setType( - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.MappingEntry.Type.Static); + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.MappingEntry.Type.Static); } else { builder.setType( - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.MappingEntry.Type.Dynamic); + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.MappingEntry.Type.DynamicImplicit); } builder.setExternalSrcAddress(arrayToIpv4AddressNoZone(detail.oAddr)); builder.setInternalSrcAddress( new IpAddress(arrayToIpv6AddressNoZone(detail.iAddr))); builder.setExternalSrcPort(new ExternalSrcPortBuilder() - .setPortType(new SinglePortNumberBuilder().setSinglePortNumber(new PortNumber( - Short.toUnsignedInt(detail.oPort))) - .build()) - .build()); + .setStartPortNumber(new PortNumber(Short.toUnsignedInt(detail.oPort))).build()); builder.setInternalSrcPort(new InternalSrcPortBuilder() - .setPortType(new SinglePortNumberBuilder().setSinglePortNumber(new PortNumber( - Short.toUnsignedInt(detail.iPort))) - .build()) - .build()); + .setStartPortNumber(new PortNumber(Short.toUnsignedInt(detail.iPort))).build()); } @Nonnull @Override public List<MappingEntryKey> getAllIds(@Nonnull final InstanceIdentifier<MappingEntry> id, @Nonnull final ReadContext context) throws ReadFailedException { - final Long natInstanceId = id.firstKeyOf(NatInstance.class).getId(); + final Long natInstanceId = id.firstKeyOf(Instance.class).getId(); LOG.trace("Listing IDs for all mapping-entries within nat-instance(vrf):{}", natInstanceId); final List<MappingEntryKey> entryKeys = @@ -199,23 +184,11 @@ final class MappingEntryCustomizer implements Ipv4Translator, Ipv6Translator, } @Override - public Initialized<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.nat.instance.mapping.table.MappingEntry> init( + public Initialized<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.instance.mapping.table.MappingEntry> init( @Nonnull final InstanceIdentifier<MappingEntry> id, @Nonnull final MappingEntry readValue, @Nonnull final ReadContext ctx) { - return Initialized.create(getCfgId(id), - new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.nat.instance.mapping.table.MappingEntryBuilder( - readValue) - .build()); - } - - static InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.nat.instance.mapping.table.MappingEntry> getCfgId( - final @Nonnull InstanceIdentifier<MappingEntry> id) { - return NatInstanceCustomizer.getCfgId(RWUtils.cutId(id, NatInstance.class)) - .child(MappingTable.class) - .child(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.nat.instance.mapping.table.MappingEntry.class, - new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.nat.instance.mapping.table.MappingEntryKey( - id.firstKeyOf(MappingEntry.class).getIndex())); + return Initialized.create(id, readValue); } static final class MappingEntryNat44DumpExecutor diff --git a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/Nat64PrefixesCustomizer.java b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/Nat64PrefixesCustomizer.java index 5026a0127..c32bbd5a7 100644 --- a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/Nat64PrefixesCustomizer.java +++ b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/Nat64PrefixesCustomizer.java @@ -37,12 +37,13 @@ import java.util.Collections; import java.util.List; import java.util.Map; import javax.annotation.Nonnull; -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.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.NatCurrentConfigBuilder; +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.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.PolicyBuilder; +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.concepts.Builder; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; @@ -70,16 +71,15 @@ final class Nat64PrefixesCustomizer public List<Nat64PrefixesKey> getAllIds(@Nonnull final InstanceIdentifier<Nat64Prefixes> id, @Nonnull final ReadContext context) throws ReadFailedException { - final NatInstanceKey natKey = id.firstKeyOf(NatInstance.class); + final InstanceKey natKey = id.firstKeyOf(Instance.class); LOG.trace("Listing IDs for all nat64 prefixes within nat-instance(vrf): {}", natKey); + // VPP supports only single nat64-prefix per VRF/nat-instance (we map nat-instances to VRFs) final Map<Long, Nat64PrefixDetails> prefixesByVrfId = dumpManager.getDump(id, context.getModificationCache()).get(); - final Nat64PrefixDetails nat64PrefixDetails = prefixesByVrfId.get(natKey.getId()); - if (nat64PrefixDetails != null) { - // VPP supports only single nat64-prefix per VRF/nat-instance (we map nat-instances to VRFs) - // To ensure that (and for simplicity), we set nat64-prefix-id to 0. - return Collections.singletonList(new Nat64PrefixesKey(0L)); + final Nat64PrefixDetails details = prefixesByVrfId.get(natKey.getId()); + if (details != null) { + return Collections.singletonList(new Nat64PrefixesKey(readPrefix(details))); } else { return Collections.emptyList(); } @@ -88,7 +88,7 @@ final class Nat64PrefixesCustomizer @Override public void merge(@Nonnull final Builder<? extends DataObject> builder, @Nonnull final List<Nat64Prefixes> readData) { - ((NatCurrentConfigBuilder) builder).setNat64Prefixes(readData); + ((PolicyBuilder) builder).setNat64Prefixes(readData); } @Nonnull @@ -102,21 +102,18 @@ final class Nat64PrefixesCustomizer @Nonnull final Nat64PrefixesBuilder builder, @Nonnull final ReadContext context) throws ReadFailedException { LOG.trace("Reading nat64-prefixes: {}", id); - final long prefixId = id.firstKeyOf(Nat64Prefixes.class).getNat64PrefixId().longValue(); - if (prefixId != 0L) { - // Ignore non zero IDs (VPP supports single nat64 prefix per VRF) - return; - } final Map<Long, Nat64PrefixDetails> prefixesByVrfId = dumpManager.getDump(id, context.getModificationCache()).get(); - final Nat64PrefixDetails prefixDetails = prefixesByVrfId.get(id.firstKeyOf(NatInstance.class).getId()); - if (prefixDetails != null) { - builder.setNat64PrefixId(prefixId); - builder.setNat64Prefix( - toIpv6Prefix(prefixDetails.prefix, UnsignedBytes.toInt(prefixDetails.prefixLen))); + final Nat64PrefixDetails details = prefixesByVrfId.get(id.firstKeyOf(Instance.class).getId()); + if (details != null) { + builder.setNat64Prefix(readPrefix(details)); } } + private Ipv6Prefix readPrefix(final Nat64PrefixDetails details) { + return toIpv6Prefix(details.prefix, UnsignedBytes.toInt(details.prefixLen)); + } + private final class Nat64PrefixesExecutor implements EntityDumpExecutor<Map<Long, Nat64PrefixDetails>, Void> { private final FutureJVppNatFacade jvppNat; diff --git a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/NatInstanceCustomizer.java b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/NatInstanceCustomizer.java index 926c6e95f..1bbd5f19e 100644 --- a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/NatInstanceCustomizer.java +++ b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/NatInstanceCustomizer.java @@ -27,11 +27,10 @@ import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; import javax.annotation.Nonnull; -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.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.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.concepts.Builder; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; @@ -42,10 +41,10 @@ import org.slf4j.LoggerFactory; * Nat instance ID is mapped to VRF-ID in VPP. */ final class NatInstanceCustomizer - implements InitializingListReaderCustomizer<NatInstance, NatInstanceKey, NatInstanceBuilder> { + implements InitializingListReaderCustomizer<Instance, InstanceKey, InstanceBuilder> { private static final Logger LOG = LoggerFactory.getLogger(NatInstanceCustomizer.class); - static final NatInstanceKey DEFAULT_VRF_ID = new NatInstanceKey(0L); + static final InstanceKey DEFAULT_VRF_ID = new InstanceKey(0L); private final DumpCacheManager<Nat44StaticMappingDetailsReplyDump, Void> nat44DumpManager; private final DumpCacheManager<Nat64BibDetailsReplyDump, Void> nat64DumpManager; @@ -59,26 +58,26 @@ final class NatInstanceCustomizer @Nonnull @Override - public NatInstanceBuilder getBuilder(@Nonnull final InstanceIdentifier<NatInstance> id) { - return new NatInstanceBuilder(); + public InstanceBuilder getBuilder(@Nonnull final InstanceIdentifier<Instance> id) { + return new InstanceBuilder(); } @Override - public void readCurrentAttributes(@Nonnull final InstanceIdentifier<NatInstance> id, - @Nonnull final NatInstanceBuilder builder, @Nonnull final ReadContext ctx) + public void readCurrentAttributes(@Nonnull final InstanceIdentifier<Instance> id, + @Nonnull final InstanceBuilder builder, @Nonnull final ReadContext ctx) throws ReadFailedException { LOG.trace("Reading current attributes for nat-instance: {}", id); - builder.setId(id.firstKeyOf(NatInstance.class).getId()); + builder.setId(id.firstKeyOf(Instance.class).getId()); } @Nonnull @Override - public List<NatInstanceKey> getAllIds(@Nonnull final InstanceIdentifier<NatInstance> id, + public List<InstanceKey> getAllIds(@Nonnull final InstanceIdentifier<Instance> id, @Nonnull final ReadContext context) throws ReadFailedException { LOG.trace("Listing IDs for all nat-instances"); // Find the nat instance IDs (vrf-ids) by listing all static mappings and their VRF assignment - final List<NatInstanceKey> vrfIds = Stream.concat( + final List<InstanceKey> vrfIds = Stream.concat( nat44DumpManager.getDump(id, context.getModificationCache()) .or(new Nat44StaticMappingDetailsReplyDump()).nat44StaticMappingDetails.stream() .map(detail -> detail.vrfId), @@ -88,7 +87,7 @@ final class NatInstanceCustomizer // V4 (nat44) and V6 (nat64) VRFs in VPP can have the same id. We store them under single nat instance, // because the ietf-nat model does not require separate instances for nat44 and nat64 features. .distinct() - .map(vrfId -> new NatInstanceKey((long) vrfId)) + .map(vrfId -> new InstanceKey((long) vrfId)) .collect(Collectors.toList()); // Add default vrf id if not present @@ -101,27 +100,15 @@ final class NatInstanceCustomizer } @Override - public void merge(@Nonnull final Builder<? extends DataObject> builder, @Nonnull final List<NatInstance> readData) { - ((NatInstancesBuilder) builder).setNatInstance(readData); + public void merge(@Nonnull final Builder<? extends DataObject> builder, @Nonnull final List<Instance> readData) { + ((InstancesBuilder) builder).setInstance(readData); } @Override - public Initialized<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.NatInstance> init( - @Nonnull final InstanceIdentifier<NatInstance> id, - @Nonnull final NatInstance readValue, + public Initialized<Instance> init( + @Nonnull final InstanceIdentifier<Instance> id, + @Nonnull final Instance readValue, @Nonnull final ReadContext ctx) { - return Initialized.create(getCfgId(id), - new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.NatInstanceBuilder() - .setId(readValue.getId()) - .build()); - } - - static InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.NatInstance> getCfgId( - @Nonnull final InstanceIdentifier<NatInstance> id) { - return InstanceIdentifier.create(NatConfig.class) - .child(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.NatInstances.class) - .child(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.NatInstance.class, - new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.NatInstanceKey( - id.firstKeyOf(NatInstance.class).getId())); + return Initialized.create(id, readValue); } } diff --git a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/NatReaderFactory.java b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/NatReaderFactory.java index a97d47a1a..c89b3030f 100644 --- a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/NatReaderFactory.java +++ b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/NatReaderFactory.java @@ -16,6 +16,15 @@ package io.fd.hc2vpp.nat.read; +import static io.fd.hc2vpp.nat.NatIds.ADDRESS_POOL_ID; +import static io.fd.hc2vpp.nat.NatIds.MAPPING_ENTRY_ID; +import static io.fd.hc2vpp.nat.NatIds.MAPPING_TABLE_ID; +import static io.fd.hc2vpp.nat.NatIds.NAT64_PREFIXES_ID; +import static io.fd.hc2vpp.nat.NatIds.NAT_ID; +import static io.fd.hc2vpp.nat.NatIds.NAT_INSTANCES_ID; +import static io.fd.hc2vpp.nat.NatIds.NAT_INSTANCE_ID; +import static io.fd.hc2vpp.nat.NatIds.POLICY_ID; + import com.google.common.collect.Sets; import com.google.inject.Inject; import io.fd.hc2vpp.nat.util.MappingEntryContext; @@ -27,40 +36,27 @@ import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; import io.fd.vpp.jvpp.nat.dto.Nat44StaticMappingDetailsReplyDump; import io.fd.vpp.jvpp.nat.dto.Nat64BibDetailsReplyDump; import io.fd.vpp.jvpp.nat.future.FutureJVppNatFacade; +import java.util.Collections; import javax.annotation.Nonnull; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.NatState; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.NatStateBuilder; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.mapping.entry.ExternalSrcPort; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.mapping.entry.InternalSrcPort; -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.Nat64Prefixes; -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.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.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.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.rev150908.nat.state.nat.instances.nat.instance.mapping.table.MappingEntry; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.NatBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.mapping.entry.ExternalSrcPort; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.mapping.entry.InternalSrcPort; +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.MappingTableBuilder; +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.mapping.table.MappingEntry; +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.nat64.prefixes.DestinationIpv4Prefix; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; public class NatReaderFactory implements ReaderFactory { - private static final InstanceIdentifier<NatState> NAT_OPER_ID = InstanceIdentifier.create(NatState.class); - private static final InstanceIdentifier<NatInstances> NAT_INSTANCES_ID = NAT_OPER_ID.child(NatInstances.class); - private static final InstanceIdentifier<NatInstance> NAT_INSTANCE_ID = NAT_INSTANCES_ID.child(NatInstance.class); - private static final InstanceIdentifier<NatCurrentConfig> CURRENT_CONFIG = - NAT_INSTANCE_ID.child(NatCurrentConfig.class); - private static final InstanceIdentifier<MappingTable> MAP_TABLE_ID = NAT_INSTANCE_ID.child(MappingTable.class); - private static final InstanceIdentifier<MappingEntry> MAP_ENTRY_ID = MAP_TABLE_ID.child(MappingEntry.class); - private final FutureJVppNatFacade jvppNat; private final MappingEntryContext mappingEntryContext; private final DumpCacheManager<Nat44StaticMappingDetailsReplyDump, Void> mapEntryNat44DumpMgr; private final DumpCacheManager<Nat64BibDetailsReplyDump, Void> mapEntryNat64DumpMgr; - @Inject public NatReaderFactory(final FutureJVppNatFacade jvppNat, final MappingEntryContext mappingEntryContext) { @@ -80,24 +76,23 @@ public class NatReaderFactory implements ReaderFactory { @Override public void init(@Nonnull final ModifiableReaderRegistryBuilder registry) { - registry.addStructuralReader(NAT_OPER_ID, NatStateBuilder.class); - registry.addStructuralReader(NAT_INSTANCES_ID, NatInstancesBuilder.class); + registry.addStructuralReader(NAT_ID, NatBuilder.class); + registry.addStructuralReader(NAT_INSTANCES_ID, InstancesBuilder.class); registry.add(new GenericInitListReader<>(NAT_INSTANCE_ID, new NatInstanceCustomizer(mapEntryNat44DumpMgr, mapEntryNat64DumpMgr))); - registry.addStructuralReader(MAP_TABLE_ID, MappingTableBuilder.class); + registry.addStructuralReader(MAPPING_TABLE_ID, MappingTableBuilder.class); registry.subtreeAdd(Sets.newHashSet(InstanceIdentifier.create(MappingEntry.class).child(ExternalSrcPort.class), InstanceIdentifier.create(MappingEntry.class).child(InternalSrcPort.class)), - new GenericInitListReader<>(MAP_ENTRY_ID, + new GenericInitListReader<>(MAPPING_ENTRY_ID, new MappingEntryCustomizer(mapEntryNat44DumpMgr, mapEntryNat64DumpMgr, mappingEntryContext))); - registry.addStructuralReader(CURRENT_CONFIG, NatCurrentConfigBuilder.class); - registry.add(new GenericInitListReader<>(CURRENT_CONFIG.child(ExternalIpAddressPool.class), - new ExternalIpPoolCustomizer(jvppNat))); + // Ony single policy is supported + registry.addStructuralListReader(POLICY_ID, PolicyBuilder.class, Collections.singletonList(new PolicyKey(0L))); + registry.add(new GenericInitListReader<>(ADDRESS_POOL_ID, new ExternalIpPoolCustomizer(jvppNat))); // nat64-prefixes registry.subtreeAdd( Sets.newHashSet(InstanceIdentifier.create(Nat64Prefixes.class).child(DestinationIpv4Prefix.class)), - new GenericListReader<>(CURRENT_CONFIG.child(Nat64Prefixes.class), - new Nat64PrefixesCustomizer(jvppNat))); + new GenericListReader<>(NAT64_PREFIXES_ID, new Nat64PrefixesCustomizer(jvppNat))); } } diff --git a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/util/MappingEntryContext.java b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/util/MappingEntryContext.java index 0f3924ec6..0f7220988 100644 --- a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/util/MappingEntryContext.java +++ b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/util/MappingEntryContext.java @@ -59,7 +59,7 @@ public class MappingEntryContext implements Ipv4Translator, Ipv6Translator { */ public synchronized void addEntry(final long natInstanceId, final long entryId, - @Nonnull final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.nat.instance.mapping.table.MappingEntry entry, + @Nonnull final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.instance.mapping.table.MappingEntry entry, @Nonnull final MappingContext mappingContext) { final InstanceIdentifier<MappingEntry> id = getId(natInstanceId, entryToKey(entry)); checkArgument(!containsEntry(natInstanceId, entry, mappingContext), "Mapping for %s already present", id); @@ -70,7 +70,7 @@ public class MappingEntryContext implements Ipv4Translator, Ipv6Translator { * Check whether mapping entry to index mapping already exists in context. */ public synchronized boolean containsEntry(final long natInstanceId, - @Nonnull final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.nat.instance.mapping.table.MappingEntry entry, + @Nonnull final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.instance.mapping.table.MappingEntry entry, @Nonnull final MappingContext mappingContext) { final InstanceIdentifier<MappingEntry> id = getId(natInstanceId, entryToKey(entry)); return mappingContext.read(id).isPresent(); @@ -92,7 +92,7 @@ public class MappingEntryContext implements Ipv4Translator, Ipv6Translator { @VisibleForTesting static MappingEntryKey entryToKey( - final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.nat.instance.mapping.table.MappingEntry entry) { + final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.instance.mapping.table.MappingEntry entry) { // Only IPv4 return new MappingEntryKey(new IpAddress(entry.getExternalSrcAddress()), entry.getInternalSrcAddress()); } @@ -144,7 +144,7 @@ public class MappingEntryContext implements Ipv4Translator, Ipv6Translator { @VisibleForTesting static MappingEntry toCtxMapEntry( - @Nonnull final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.nat.instance.mapping.table.MappingEntry entry, + @Nonnull final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.instance.mapping.table.MappingEntry entry, final long entryId) { return new MappingEntryBuilder() .setKey(entryToKey(entry)) @@ -170,7 +170,7 @@ public class MappingEntryContext implements Ipv4Translator, Ipv6Translator { * Delete mapping of mapping entry to index from context. */ public synchronized void removeEntry(final long natInstanceId, - @Nonnull final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.nat.instance.mapping.table.MappingEntry entry, + @Nonnull final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.instance.mapping.table.MappingEntry entry, @Nonnull final MappingContext mappingContext) { mappingContext.delete(getId(natInstanceId, entryToKey(entry))); } @@ -245,7 +245,7 @@ public class MappingEntryContext implements Ipv4Translator, Ipv6Translator { * Get index for a stored mapping entry. */ public synchronized Optional<Long> getStoredIndex(final long natInstanceId, - @Nonnull final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.nat.config.nat.instances.nat.instance.mapping.table.MappingEntry entry, + @Nonnull final org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.instance.mapping.table.MappingEntry entry, @Nonnull final MappingContext mappingContext) { return mappingContext.read(getId(natInstanceId, entryToKey(entry))) .transform(MappingEntry::getIndex); diff --git a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/ExternalIpPoolCustomizer.java b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/ExternalIpPoolCustomizer.java index 775c9a6dd..36440b013 100644 --- a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/ExternalIpPoolCustomizer.java +++ b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/ExternalIpPoolCustomizer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Cisco and/or its affiliates. + * Copyright (c) 2018 Cisco and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,7 @@ package io.fd.hc2vpp.nat.write; import static com.google.common.base.Preconditions.checkArgument; -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.Nat64; import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; import io.fd.hc2vpp.common.translate.util.Ipv4AddressRange; @@ -31,10 +31,10 @@ import io.fd.vpp.jvpp.nat.dto.Nat64AddDelPoolAddrRange; import io.fd.vpp.jvpp.nat.future.FutureJVppNatFacade; import javax.annotation.Nonnull; 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.nat.rev150908.nat.config.nat.instances.NatInstance; -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.opendaylight.params.xml.ns.yang.vpp.nat.rev170804.ExternalIpAddressPoolConfigAugmentation; +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.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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nat.rev180510.ExternalIpAddressPoolAugmentation; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -54,7 +54,7 @@ final class ExternalIpPoolCustomizer implements ListWriterCustomizer<ExternalIpA public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<ExternalIpAddressPool> id, @Nonnull final ExternalIpAddressPool dataAfter, @Nonnull final WriteContext writeContext) throws WriteFailedException { - checkArgument(id.firstKeyOf(NatInstance.class).getId() == 0, + checkArgument(id.firstKeyOf(Instance.class).getId() == 0, "External IP pools are only assignable for nat instance(vrf-id) with ID 0"); LOG.trace("Adding address range:{}, as: {}", id, dataAfter); // TODO check overlaps ? VPP-478 maybe no necessary, depending on how VPP handles them @@ -75,8 +75,8 @@ final class ExternalIpPoolCustomizer implements ListWriterCustomizer<ExternalIpA @Nonnull final ExternalIpAddressPool addressPool, final boolean isAdd) throws WriteFailedException { boolean isNat64 = false; - final ExternalIpAddressPoolConfigAugmentation augmentation = - addressPool.getAugmentation(ExternalIpAddressPoolConfigAugmentation.class); + final ExternalIpAddressPoolAugmentation augmentation = + addressPool.getAugmentation(ExternalIpAddressPoolAugmentation.class); if (augmentation != null) { isNat64 = Nat64.equals(augmentation.getPoolType()); } diff --git a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/MappingEntryCustomizer.java b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/MappingEntryCustomizer.java index 97a41c0ca..6aca1af9e 100644 --- a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/MappingEntryCustomizer.java +++ b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/MappingEntryCustomizer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Cisco and/or its affiliates. + * Copyright (c) 2018 Cisco and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,12 +35,10 @@ import javax.annotation.Nonnull; 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.Ipv6Address; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.PortNumber; -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.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.rev150908.port.number.PortType; -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.PortNumber; +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.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; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -65,9 +63,9 @@ final class MappingEntryCustomizer implements ListWriterCustomizer<MappingEntry, throws WriteFailedException { // Only static mapping supported by SNAT for now checkArgument(dataAfter.getType() == - org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.MappingEntry.Type.Static, + org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.MappingEntry.Type.Static, "Only static NAT entries are supported currently. Trying to write: %s entry", dataAfter.getType()); - final Long natInstanceId = id.firstKeyOf(NatInstance.class).getId(); + final Long natInstanceId = id.firstKeyOf(Instance.class).getId(); final Long mappingEntryId = id.firstKeyOf(MappingEntry.class).getIndex(); LOG.debug("Writing mapping entry: {} for nat-instance(vrf): {}", natInstanceId, mappingEntryId); @@ -130,7 +128,7 @@ final class MappingEntryCustomizer implements ListWriterCustomizer<MappingEntry, public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<MappingEntry> id, @Nonnull final MappingEntry dataBefore, @Nonnull final WriteContext writeContext) throws WriteFailedException { - final long natInstanceId = id.firstKeyOf(NatInstance.class).getId(); + final long natInstanceId = id.firstKeyOf(Instance.class).getId(); final MappingEntryKey mappingEntryKey = id.firstKeyOf(MappingEntry.class); LOG.debug("Deleting mapping entry: {} for nat-instance(vrf): {}", natInstanceId, mappingEntryKey); @@ -167,14 +165,12 @@ final class MappingEntryCustomizer implements ListWriterCustomizer<MappingEntry, request.protocol = protocol.byteValue(); } - Optional<Short> internalPortNumber = getPortNumber(id, mappingEntry, - (entry) -> Optional.fromNullable(entry.getInternalSrcPort()).transform(PortNumber::getPortType)); - Optional<Short> externalPortNumber = getPortNumber(id, mappingEntry, - (entry) -> Optional.fromNullable(entry.getExternalSrcPort()).transform(PortNumber::getPortType)); - if (internalPortNumber.isPresent() && externalPortNumber.isPresent()) { + final Short internalPortNumber = getPortNumber(id, mappingEntry.getInternalSrcPort()); + final Short externalPortNumber = getPortNumber(id, mappingEntry.getExternalSrcPort()); + if (internalPortNumber != null && externalPortNumber != null) { request.addrOnly = 0; - request.localPort = internalPortNumber.get(); - request.externalPort = externalPortNumber.get(); + request.localPort = internalPortNumber; + request.externalPort = externalPortNumber; } return request; } @@ -205,32 +201,24 @@ final class MappingEntryCustomizer implements ListWriterCustomizer<MappingEntry, request.proto = protocol.byteValue(); } - Optional<Short> internalPortNumber = getPortNumber(id, mappingEntry, - (entry) -> Optional.fromNullable(entry.getInternalSrcPort()).transform(PortNumber::getPortType)); - Optional<Short> externalPortNumber = getPortNumber(id, mappingEntry, - (entry) -> Optional.fromNullable(entry.getExternalSrcPort()).transform(PortNumber::getPortType)); - if (internalPortNumber.isPresent() && externalPortNumber.isPresent()) { - request.iPort = internalPortNumber.get(); - request.oPort = externalPortNumber.get(); + final Short internalPortNumber = getPortNumber(id, mappingEntry.getInternalSrcPort()); + final Short externalPortNumber = getPortNumber(id, mappingEntry.getExternalSrcPort()); + if (internalPortNumber != null && externalPortNumber != null) { + request.iPort = internalPortNumber; + request.oPort = externalPortNumber; } return request; } - - private Optional<Short> getPortNumber(final InstanceIdentifier<MappingEntry> id, final MappingEntry dataAfter, - final PortGetter portGetter) { - return portGetter.getPortType(dataAfter).transform(port -> { - if (port instanceof SinglePortNumber) { - return ((SinglePortNumber) port).getSinglePortNumber().getValue().shortValue(); + private Short getPortNumber(final InstanceIdentifier<MappingEntry> id, final PortNumber portNumber) { + if (portNumber != null) { + if (portNumber.getStartPortNumber() != null && portNumber.getEndPortNumber() == null) { + return portNumber.getStartPortNumber().getValue().shortValue(); } else { throw new IllegalArgumentException( - String.format("Only single port number supported. Submitted: %s for entry: %s", - dataAfter.getInternalSrcPort(), id)); + String.format("Only single port number supported. Submitted: %s for entry: %s", portNumber, id)); } - }); - } - - interface PortGetter { - Optional<PortType> getPortType(MappingEntry entry); + } + return null; } } diff --git a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/Nat64PrefixesCustomizer.java b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/Nat64PrefixesCustomizer.java index b62733e75..33dad0d1b 100644 --- a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/Nat64PrefixesCustomizer.java +++ b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/Nat64PrefixesCustomizer.java @@ -30,10 +30,10 @@ import io.fd.vpp.jvpp.nat.future.FutureJVppNatFacade; import java.util.List; import javax.annotation.Nonnull; 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.config.nat.instances.NatInstance; -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.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.instance.policy.Nat64Prefixes; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.instance.policy.Nat64PrefixesKey; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.instance.policy.nat64.prefixes.DestinationIpv4Prefix; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -54,14 +54,10 @@ final class Nat64PrefixesCustomizer public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<Nat64Prefixes> id, @Nonnull final Nat64Prefixes dataAfter, @Nonnull final WriteContext writeContext) throws WriteFailedException { - final int natInstanceId = id.firstKeyOf(NatInstance.class).getId().intValue(); + final int natInstanceId = id.firstKeyOf(Instance.class).getId().intValue(); LOG.debug("Configuring nat64 prefix: {} for nat-instance(vrf): {}", dataAfter, natInstanceId); - // VPP supports only single nat64-prefix per VRF/nat-instance (we map nat-instances to VRFs) - // To ensure that (and for simplicity), we require nat64-prefix-id = 0. - final Long nat64PrefixId = id.firstKeyOf(Nat64Prefixes.class).getNat64PrefixId(); - checkArgument(nat64PrefixId == 0, "Only single nat64 prefix is supported (expected id=0, but %s given)", - nat64PrefixId); + // TODO(HC2VPP-320): ensure at most one prefix is configured per NAT instance // VPP does not support configuring different nat64-prefixes depending on ipv4 destination prefix: final List<DestinationIpv4Prefix> destinationIpv4PrefixList = dataAfter.getDestinationIpv4Prefix(); @@ -77,7 +73,7 @@ final class Nat64PrefixesCustomizer @Nonnull final Nat64Prefixes dataBefore, @Nonnull final WriteContext writeContext) throws WriteFailedException { - final int natInstanceId = id.firstKeyOf(NatInstance.class).getId().intValue(); + final int natInstanceId = id.firstKeyOf(Instance.class).getId().intValue(); LOG.debug("Removing nat64 prefix configuration: {} for nat-instance(vrf): {}", dataBefore, natInstanceId); // No need for validation here (it was done on write) addDelPrefix(id, dataBefore, natInstanceId, false); diff --git a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/NatInstaceCustomizer.java b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/NatInstaceCustomizer.java index 8e5673003..22641437f 100644 --- a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/NatInstaceCustomizer.java +++ b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/NatInstaceCustomizer.java @@ -20,31 +20,31 @@ import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer; import io.fd.honeycomb.translate.write.WriteContext; import io.fd.honeycomb.translate.write.WriteFailedException; import javax.annotation.Nonnull; -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.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.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -final class NatInstaceCustomizer implements ListWriterCustomizer<NatInstance, NatInstanceKey> { +final class NatInstaceCustomizer implements ListWriterCustomizer<Instance, InstanceKey> { private static final Logger LOG = LoggerFactory.getLogger(NatInstaceCustomizer.class); @Override - public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<NatInstance> id, - @Nonnull final NatInstance dataAfter, @Nonnull final WriteContext writeContext) + public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<Instance> id, + @Nonnull final Instance dataAfter, @Nonnull final WriteContext writeContext) throws WriteFailedException { - LOG.trace("Writing nat-instance: {}", id); + LOG.trace("Writing NAT instance: {}", id); } @Override - public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<NatInstance> id, - @Nonnull final NatInstance dataBefore, @Nonnull final WriteContext writeContext) + public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<Instance> id, + @Nonnull final Instance dataBefore, @Nonnull final WriteContext writeContext) throws WriteFailedException { - LOG.trace("Deleting nat-instance: {}", id); + LOG.trace("Deleting NAT instance: {}", id); // For consistency with reader, forbid removing default NAT instance: - final Long vrfId = id.firstKeyOf(NatInstance.class).getId(); + final Long vrfId = id.firstKeyOf(Instance.class).getId(); if (vrfId == 0) { throw new WriteFailedException.DeleteFailedException(id, new UnsupportedOperationException("Removing default NAT instance (vrf=0) is not supported.")); diff --git a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/NatWriterFactory.java b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/NatWriterFactory.java index 802d6875b..ae9e0efca 100644 --- a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/NatWriterFactory.java +++ b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/NatWriterFactory.java @@ -16,6 +16,12 @@ package io.fd.hc2vpp.nat.write; +import static io.fd.hc2vpp.nat.NatIds.ADDRESS_POOL_ID; +import static io.fd.hc2vpp.nat.NatIds.MAPPING_ENTRY_ID; +import static io.fd.hc2vpp.nat.NatIds.NAT64_PREFIXES_ID; +import static io.fd.hc2vpp.nat.NatIds.NAT_INSTANCE_ID; +import static io.fd.hc2vpp.nat.NatIds.POLICY_ID; + import com.google.common.collect.Sets; import com.google.inject.Inject; import io.fd.hc2vpp.nat.util.MappingEntryContext; @@ -24,17 +30,13 @@ import io.fd.honeycomb.translate.write.WriterFactory; import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder; import io.fd.vpp.jvpp.nat.future.FutureJVppNatFacade; import javax.annotation.Nonnull; -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.mapping.entry.ExternalSrcPort; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev150908.mapping.entry.InternalSrcPort; -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.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.parameters.ExternalIpAddressPool; -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.nat64.prefixes.DestinationIpv4Prefix; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nat.rev170804.ExternalIpAddressPoolConfigAugmentation; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.mapping.entry.ExternalSrcPort; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.mapping.entry.InternalSrcPort; +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.policy.ExternalIpAddressPool; +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.nat64.prefixes.DestinationIpv4Prefix; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.nat.rev180510.ExternalIpAddressPoolAugmentation; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; /** @@ -42,12 +44,6 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; */ public final class NatWriterFactory implements WriterFactory { - private static final InstanceIdentifier<NatConfig> NAT_CFG_ID = InstanceIdentifier.create(NatConfig.class); - private static final InstanceIdentifier<NatInstance> NAT_INSTANCE_ID = - NAT_CFG_ID.child(NatInstances.class).child(NatInstance.class); - private static final InstanceIdentifier<MappingEntry> MAP_ENTRY_ID = - NAT_INSTANCE_ID.child(MappingTable.class).child(MappingEntry.class); - private final FutureJVppNatFacade jvppNat; private final MappingEntryContext mappingEntryContext; @@ -60,26 +56,28 @@ public final class NatWriterFactory implements WriterFactory { @Override public void init(@Nonnull final ModifiableWriterRegistryBuilder registry) { - // Nat-instance + // +-- nat + // +-- instances/instance registry.add(new GenericListWriter<>(NAT_INSTANCE_ID, new NatInstaceCustomizer())); - // Mapping-entry + // +-- mapping-table/mapping-entry registry.subtreeAdd(Sets.newHashSet(InstanceIdentifier.create(MappingEntry.class).child(ExternalSrcPort.class), InstanceIdentifier.create(MappingEntry.class).child(InternalSrcPort.class)), - new GenericListWriter<>(MAP_ENTRY_ID, new MappingEntryCustomizer(jvppNat, mappingEntryContext))); + new GenericListWriter<>(MAPPING_ENTRY_ID, new MappingEntryCustomizer(jvppNat, mappingEntryContext))); + + // +-- policy + registry.add(new GenericListWriter<>(POLICY_ID, new PolicyCustomizer())); - // External address pool has to be executed before mapping entry. Because adding mapping entries requires to - // already have an IP range predefined ... in some cases + // +-- external-ip-address-pool registry.subtreeAddBefore( - Sets.newHashSet(InstanceIdentifier.create(ExternalIpAddressPool.class) - .augmentation(ExternalIpAddressPoolConfigAugmentation.class)), - new GenericListWriter<>(NAT_INSTANCE_ID.child(ExternalIpAddressPool.class), - new ExternalIpPoolCustomizer(jvppNat)), - MAP_ENTRY_ID); + // External address pool has to be executed before mapping entry. Because adding mapping entries + // requires to already have an IP range predefined ... in some cases + Sets.newHashSet(InstanceIdentifier.create(ExternalIpAddressPool.class) + .augmentation(ExternalIpAddressPoolAugmentation.class)), + new GenericListWriter<>(ADDRESS_POOL_ID, new ExternalIpPoolCustomizer(jvppNat)), MAPPING_ENTRY_ID); - // nat64-prefixes + // +-- nat64-prefixes registry.subtreeAdd( Sets.newHashSet(InstanceIdentifier.create(Nat64Prefixes.class).child(DestinationIpv4Prefix.class)), - new GenericListWriter<>(NAT_INSTANCE_ID.child(Nat64Prefixes.class), - new Nat64PrefixesCustomizer(jvppNat))); + new GenericListWriter<>(NAT64_PREFIXES_ID, new Nat64PrefixesCustomizer(jvppNat))); } } diff --git a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/PolicyCustomizer.java b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/PolicyCustomizer.java new file mode 100644 index 000000000..ecc340f38 --- /dev/null +++ b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/PolicyCustomizer.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2018 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.hc2vpp.nat.write; + +import static com.google.common.base.Preconditions.checkArgument; + +import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer; +import io.fd.honeycomb.translate.write.WriteContext; +import io.fd.honeycomb.translate.write.WriteFailedException; +import javax.annotation.Nonnull; +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.instance.Policy; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev180223.nat.instances.instance.PolicyKey; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +final class PolicyCustomizer implements ListWriterCustomizer<Policy, PolicyKey> { + + private static final Logger LOG = LoggerFactory.getLogger(PolicyCustomizer.class); + + @Override + public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<Policy> id, + @Nonnull final Policy dataAfter, @Nonnull final WriteContext writeContext) + throws WriteFailedException { + LOG.trace("Writing NAT policy: {}", id); + + // HC supports only single NAT policy per NAT instance (VRF) + // To ensure that (and for simplicity), we require policy id = 0. + final Long policyId = id.firstKeyOf(Policy.class).getId(); + checkArgument(policyId == 0, + "Only single policy per NAT instance (VRF) is supported (expected id=0, but %s given)", policyId); + } + + @Override + public void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<Policy> id, + @Nonnull final Policy dataBefore, @Nonnull final WriteContext writeContext) + throws WriteFailedException { + LOG.trace("Deleting NAT policy: {}", id); + } +} 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 + } } } } |