From 70d981d7b08ba57d7789d8f33629fc33b2b0d9ff Mon Sep 17 00:00:00 2001 From: Marek Gradzki Date: Wed, 16 Aug 2017 17:09:37 +0200 Subject: HC2VPP-105: add support for nat64 configuration on interface Change-Id: I071f8981b680845ea031a9e61dfca7e34ea539e5 Signed-off-by: Marek Gradzki --- .../read/ifc/AbstractInterfaceNatCustomizer.java | 98 +++++++++++++--------- .../ifc/AbstractSubInterfaceNatCustomizer.java | 5 +- .../hc2vpp/nat/read/ifc/IfcNatReaderFactory.java | 1 - .../nat/read/ifc/InboundAttributesBuilder.java | 36 ++++++++ .../read/ifc/InterfaceInboundNatCustomizer.java | 7 +- .../read/ifc/InterfaceOutboundNatCustomizer.java | 7 +- .../nat/read/ifc/OutboundAttributesReader.java | 36 ++++++++ .../read/ifc/SubInterfaceInboundNatCustomizer.java | 7 +- .../ifc/SubInterfaceOutboundNatCustomizer.java | 7 +- .../hc2vpp/nat/read/ifc/VppAttributesBuilder.java | 28 +++++++ .../write/ifc/AbstractInterfaceNatCustomizer.java | 57 ++++++++----- .../ifc/InterfaceInboundNatCustomizerTest.java | 9 +- .../ifc/InterfaceOutboundNatCustomizerTest.java | 9 +- .../nat/write/ifc/AbstractNatCustomizerTest.java | 42 ++++++++-- .../ifc/InterfaceInboundNatCustomizerTest.java | 4 +- .../ifc/InterfaceOutboundNatCustomizerTest.java | 4 +- 16 files changed, 248 insertions(+), 109 deletions(-) create mode 100644 nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/InboundAttributesBuilder.java create mode 100644 nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/OutboundAttributesReader.java create mode 100644 nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/VppAttributesBuilder.java diff --git a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/AbstractInterfaceNatCustomizer.java b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/AbstractInterfaceNatCustomizer.java index c3c81ffb8..5079f1630 100644 --- a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/AbstractInterfaceNatCustomizer.java +++ b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/AbstractInterfaceNatCustomizer.java @@ -25,6 +25,8 @@ import io.fd.honeycomb.translate.read.ReadContext; import io.fd.honeycomb.translate.read.ReadFailedException; import io.fd.honeycomb.translate.spi.read.InitializingReaderCustomizer; import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager; +import io.fd.vpp.jvpp.snat.dto.Nat64InterfaceDetailsReplyDump; +import io.fd.vpp.jvpp.snat.dto.Nat64InterfaceDump; import io.fd.vpp.jvpp.snat.dto.SnatInterfaceDetailsReplyDump; import io.fd.vpp.jvpp.snat.dto.SnatInterfaceDump; import io.fd.vpp.jvpp.snat.dto.SnatInterfaceOutputFeatureDetailsReplyDump; @@ -40,21 +42,31 @@ import org.slf4j.Logger; abstract class AbstractInterfaceNatCustomizer> implements InitializingReaderCustomizer, JvppReplyConsumer { - private final FutureJVppSnatFacade jvppSnat; - private final DumpCacheManager preRoutingDumpMgr; - private final DumpCacheManager postRoutingDumpMgr; + private final DumpCacheManager preRoutingNat44DumpMgr; + private final DumpCacheManager preRoutingNat64DumpMgr; + private final DumpCacheManager postRoutingNat44DumpMgr; private final NamingContext ifcContext; + private final VppAttributesBuilder vppAttributesBuilder; AbstractInterfaceNatCustomizer(@Nonnull final FutureJVppSnatFacade jvppSnat, - @Nonnull final NamingContext ifcContext) { - this.jvppSnat = requireNonNull(jvppSnat, "jvppSnat should not be null"); + @Nonnull final NamingContext ifcContext, + @Nonnull final VppAttributesBuilder vppAttributesBuilder) { + requireNonNull(jvppSnat, "jvppSnat should not be null"); this.ifcContext = requireNonNull(ifcContext, "ifcContext should not be null"); - this.preRoutingDumpMgr = new DumpCacheManager.DumpCacheManagerBuilder() - .withExecutor((id, params) -> getReplyForRead( - jvppSnat.snatInterfaceDump(new SnatInterfaceDump()).toCompletableFuture(), id)) - .acceptOnly(SnatInterfaceDetailsReplyDump.class) - .build(); - this.postRoutingDumpMgr = + this.vppAttributesBuilder = requireNonNull(vppAttributesBuilder, "ifcContext should not be null"); + this.preRoutingNat44DumpMgr = + new DumpCacheManager.DumpCacheManagerBuilder() + .withExecutor((id, params) -> getReplyForRead( + jvppSnat.snatInterfaceDump(new SnatInterfaceDump()).toCompletableFuture(), id)) + .acceptOnly(SnatInterfaceDetailsReplyDump.class) + .build(); + this.preRoutingNat64DumpMgr = + new DumpCacheManager.DumpCacheManagerBuilder() + .withExecutor((id, params) -> getReplyForRead( + jvppSnat.nat64InterfaceDump(new Nat64InterfaceDump()).toCompletableFuture(), id)) + .acceptOnly(Nat64InterfaceDetailsReplyDump.class) + .build(); + this.postRoutingNat44DumpMgr = new DumpCacheManager.DumpCacheManagerBuilder() .withExecutor((id, params) -> getReplyForRead( jvppSnat.snatInterfaceOutputFeatureDump(new SnatInterfaceOutputFeatureDump()) @@ -71,39 +83,51 @@ abstract class AbstractInterfaceNatCustomizer postRoutingDump = - postRoutingDumpMgr.getDump(id, ctx.getModificationCache(), null); + // Each of the following cases uses different VPP API, but we store them under single node. + // Not all combinations are possible, but we don't validate on read and rely on VPP. + readPreRoutingNat44(id, index, builder, ctx); + readPreRoutingNat64(id, index, builder, ctx); + readPostRoutingNat44(id, index, builder, ctx); + } + + private void readPreRoutingNat44(final InstanceIdentifier id, final int index, final B builder, + final ReadContext ctx) throws ReadFailedException { + final Optional dump = + preRoutingNat44DumpMgr.getDump(id, ctx.getModificationCache(), null); - postRoutingDump.or(new SnatInterfaceOutputFeatureDetailsReplyDump()).snatInterfaceOutputFeatureDetails.stream() + dump.or(new SnatInterfaceDetailsReplyDump()).snatInterfaceDetails.stream() .filter(snatIfcDetail -> snatIfcDetail.swIfIndex == index) .filter(snatIfcDetail -> isExpectedNatType(snatIfcDetail.isInside)) - .findFirst() - .ifPresent(snatIfcDetail -> setPostRouting(builder)); + .findAny() + .ifPresent(snatIfcDetail -> vppAttributesBuilder.enableNat44(builder)); + // do not modify builder is feature is absent (inbound/outbound are presence containers) } - @Override - public boolean isPresent(final InstanceIdentifier id, final C built, final ReadContext ctx) - throws ReadFailedException { - // In the post routing case, we can reuse default implementation: - if (InitializingReaderCustomizer.super.isPresent(id, built, ctx)) { - // post routing was set - return true; - } - // In the pre routing case, we need to inspect pre routing dump: - final String ifcName = getName(id); - getLog().debug("Checking NAT presence for interface: {}", ifcName); - final int index = ifcContext.getIndex(ifcName, ctx.getMappingContext()); + private void readPreRoutingNat64(final InstanceIdentifier id, final int index, final B builder, + final ReadContext ctx) throws ReadFailedException { + final Optional dump = + preRoutingNat64DumpMgr.getDump(id, ctx.getModificationCache(), null); - // Cache dump for each interface under the same key since this is all ifc dump: - final Optional preRoutingDump = - preRoutingDumpMgr.getDump(id, ctx.getModificationCache(), null); + dump.or(new Nat64InterfaceDetailsReplyDump()).nat64InterfaceDetails.stream() + .filter(snatIfcDetail -> snatIfcDetail.swIfIndex == index) + .filter(snatIfcDetail -> isExpectedNatType(snatIfcDetail.isInside)) + .findAny() + .ifPresent(snatIfcDetail -> vppAttributesBuilder.enableNat64(builder)); + // do not modify builder is feature is absent (inbound/outbound are presence containers) + } - // Find entries for current ifc and if is marked as inside set the builder to return presence container: - return preRoutingDump.or(new SnatInterfaceDetailsReplyDump()).snatInterfaceDetails.stream() + private void readPostRoutingNat44(final InstanceIdentifier id, final int index, final B builder, + final ReadContext ctx) throws ReadFailedException { + final Optional dump = + postRoutingNat44DumpMgr.getDump(id, ctx.getModificationCache(), null); + + dump.or(new SnatInterfaceOutputFeatureDetailsReplyDump()).snatInterfaceOutputFeatureDetails + .stream() .filter(snatIfcDetail -> snatIfcDetail.swIfIndex == index) - .anyMatch(snatIfcDetail -> isExpectedNatType(snatIfcDetail.isInside)); - // Not setting data, just marking the builder to propagate empty container to indicate presence. + .filter(snatIfcDetail -> isExpectedNatType(snatIfcDetail.isInside)) + .findAny() + .ifPresent(snatIfcDetail -> vppAttributesBuilder.enablePostRouting(builder)); + // do not modify builder is feature is absent (inbound/outbound are presence containers) } protected String getName(final InstanceIdentifier id) { @@ -113,6 +137,4 @@ abstract class AbstractInterfaceNatCustomizer> extends AbstractInterfaceNatCustomizer { AbstractSubInterfaceNatCustomizer(@Nonnull final FutureJVppSnatFacade jvppSnat, - @Nonnull final NamingContext ifcContext) { - super(jvppSnat, ifcContext); + @Nonnull final NamingContext ifcContext, + @Nonnull final VppAttributesBuilder vppAttributesBuilder) { + super(jvppSnat, ifcContext, vppAttributesBuilder); } @Override diff --git a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/IfcNatReaderFactory.java b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/IfcNatReaderFactory.java index 51150dc1d..86dc605ce 100644 --- a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/IfcNatReaderFactory.java +++ b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/IfcNatReaderFactory.java @@ -16,7 +16,6 @@ package io.fd.hc2vpp.nat.read.ifc; - import com.google.inject.Inject; import com.google.inject.name.Named; import io.fd.hc2vpp.common.translate.util.NamingContext; diff --git a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/InboundAttributesBuilder.java b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/InboundAttributesBuilder.java new file mode 100644 index 000000000..b8b9db8c7 --- /dev/null +++ b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/InboundAttributesBuilder.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2017 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.read.ifc; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev170816._interface.nat.attributes.nat.InboundBuilder; + +final class InboundAttributesBuilder implements VppAttributesBuilder { + @Override + public void enableNat44(final InboundBuilder builder) { + builder.setNat44Support(true); + } + + @Override + public void enableNat64(final InboundBuilder builder) { + builder.setNat64Support(true); + } + + @Override + public void enablePostRouting(final InboundBuilder builder) { + builder.setPostRouting(true); + } +} diff --git a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/InterfaceInboundNatCustomizer.java b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/InterfaceInboundNatCustomizer.java index 006190610..cabdd0f8b 100644 --- a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/InterfaceInboundNatCustomizer.java +++ b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/InterfaceInboundNatCustomizer.java @@ -41,7 +41,7 @@ final class InterfaceInboundNatCustomizer extends AbstractInterfaceNatCustomizer InterfaceInboundNatCustomizer(@Nonnull final FutureJVppSnatFacade jvppSnat, @Nonnull final NamingContext ifcContext) { - super(jvppSnat, ifcContext); + super(jvppSnat, ifcContext, new InboundAttributesBuilder()); } @Override @@ -54,11 +54,6 @@ final class InterfaceInboundNatCustomizer extends AbstractInterfaceNatCustomizer return isInside == 1; } - @Override - void setPostRouting(final InboundBuilder builder) { - builder.setPostRouting(true); - } - @Nonnull @Override public InboundBuilder getBuilder(@Nonnull final InstanceIdentifier id) { diff --git a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/InterfaceOutboundNatCustomizer.java b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/InterfaceOutboundNatCustomizer.java index 2fb2a9282..438e43862 100644 --- a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/InterfaceOutboundNatCustomizer.java +++ b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/InterfaceOutboundNatCustomizer.java @@ -41,7 +41,7 @@ final class InterfaceOutboundNatCustomizer extends AbstractInterfaceNatCustomize InterfaceOutboundNatCustomizer(@Nonnull final FutureJVppSnatFacade jvppSnat, @Nonnull final NamingContext ifcContext) { - super(jvppSnat, ifcContext); + super(jvppSnat, ifcContext, new OutboundAttributesReader()); } @Override @@ -54,11 +54,6 @@ final class InterfaceOutboundNatCustomizer extends AbstractInterfaceNatCustomize return isInside == 0; } - @Override - void setPostRouting(final OutboundBuilder builder) { - builder.setPostRouting(true); - } - @Nonnull @Override public OutboundBuilder getBuilder(@Nonnull final InstanceIdentifier id) { diff --git a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/OutboundAttributesReader.java b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/OutboundAttributesReader.java new file mode 100644 index 000000000..16ab317a2 --- /dev/null +++ b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/OutboundAttributesReader.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2017 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.read.ifc; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev170816._interface.nat.attributes.nat.OutboundBuilder; + +final class OutboundAttributesReader implements VppAttributesBuilder { + @Override + public void enableNat44(final OutboundBuilder builder) { + builder.setNat44Support(true); + } + + @Override + public void enableNat64(final OutboundBuilder builder) { + builder.setNat64Support(true); + } + + @Override + public void enablePostRouting(final OutboundBuilder builder) { + builder.setPostRouting(true); + } +} diff --git a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/SubInterfaceInboundNatCustomizer.java b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/SubInterfaceInboundNatCustomizer.java index f9550e1e2..39ee7c9f3 100644 --- a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/SubInterfaceInboundNatCustomizer.java +++ b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/SubInterfaceInboundNatCustomizer.java @@ -45,7 +45,7 @@ final class SubInterfaceInboundNatCustomizer extends AbstractSubInterfaceNatCust SubInterfaceInboundNatCustomizer(@Nonnull final FutureJVppSnatFacade jvppSnat, @Nonnull final NamingContext ifcContext) { - super(jvppSnat, ifcContext); + super(jvppSnat, ifcContext, new InboundAttributesBuilder()); } @Override @@ -58,11 +58,6 @@ final class SubInterfaceInboundNatCustomizer extends AbstractSubInterfaceNatCust return isInside == 1; } - @Override - void setPostRouting(final InboundBuilder builder) { - builder.setPostRouting(true); - } - @Nonnull @Override public InboundBuilder getBuilder(@Nonnull final InstanceIdentifier id) { diff --git a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/SubInterfaceOutboundNatCustomizer.java b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/SubInterfaceOutboundNatCustomizer.java index 9b6dce766..330e4c4b3 100644 --- a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/SubInterfaceOutboundNatCustomizer.java +++ b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/SubInterfaceOutboundNatCustomizer.java @@ -45,7 +45,7 @@ final class SubInterfaceOutboundNatCustomizer extends AbstractSubInterfaceNatCus SubInterfaceOutboundNatCustomizer(@Nonnull final FutureJVppSnatFacade jvppSnat, @Nonnull final NamingContext ifcContext) { - super(jvppSnat, ifcContext); + super(jvppSnat, ifcContext, new OutboundAttributesReader()); } @Override @@ -58,11 +58,6 @@ final class SubInterfaceOutboundNatCustomizer extends AbstractSubInterfaceNatCus return isInside == 0; } - @Override - void setPostRouting(final OutboundBuilder builder) { - builder.setPostRouting(true); - } - @Nonnull @Override public OutboundBuilder getBuilder(@Nonnull final InstanceIdentifier id) { diff --git a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/VppAttributesBuilder.java b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/VppAttributesBuilder.java new file mode 100644 index 000000000..57c24fa4b --- /dev/null +++ b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/read/ifc/VppAttributesBuilder.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2017 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.read.ifc; + +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev170816.InterfaceNatVppFeatureAttributes; +import org.opendaylight.yangtools.concepts.Builder; + +interface VppAttributesBuilder> { + void enableNat44(final B builder); + + void enableNat64(final B builder); + + void enablePostRouting(final B builder); +} diff --git a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/ifc/AbstractInterfaceNatCustomizer.java b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/ifc/AbstractInterfaceNatCustomizer.java index dbfbb17e4..4a44fe9a6 100644 --- a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/ifc/AbstractInterfaceNatCustomizer.java +++ b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/ifc/AbstractInterfaceNatCustomizer.java @@ -16,19 +16,18 @@ package io.fd.hc2vpp.nat.write.ifc; +import static com.google.common.base.Preconditions.checkArgument; + import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer; import io.fd.hc2vpp.common.translate.util.NamingContext; import io.fd.honeycomb.translate.spi.write.WriterCustomizer; import io.fd.honeycomb.translate.write.WriteContext; import io.fd.honeycomb.translate.write.WriteFailedException; -import io.fd.vpp.jvpp.dto.JVppReply; +import io.fd.vpp.jvpp.snat.dto.Nat64AddDelInterface; import io.fd.vpp.jvpp.snat.dto.SnatInterfaceAddDelFeature; -import io.fd.vpp.jvpp.snat.dto.SnatInterfaceAddDelFeatureReply; import io.fd.vpp.jvpp.snat.dto.SnatInterfaceAddDelOutputFeature; -import io.fd.vpp.jvpp.snat.dto.SnatInterfaceAddDelOutputFeatureReply; import io.fd.vpp.jvpp.snat.future.FutureJVppSnatFacade; -import java.util.concurrent.CompletionStage; import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang._interface.nat.rev170816.InterfaceNatVppFeatureAttributes; @@ -56,13 +55,12 @@ abstract class AbstractInterfaceNatCustomizer id) { return id.firstKeyOf(Interface.class).getName(); } - private JVppReply postRoutingNat(@Nonnull final InstanceIdentifier id, final int ifcIndex, final boolean enable) + private void postRoutingNat(@Nonnull final InstanceIdentifier id, final D natAttributes, final int ifcIndex, + final boolean enable) throws WriteFailedException { + checkArgument(!isNat64Supported(natAttributes), "Post routing Nat64 is not supported by VPP"); final SnatInterfaceAddDelOutputFeature request = new SnatInterfaceAddDelOutputFeature(); request.isAdd = booleanToByte(enable); request.isInside = getType().isInside; request.swIfIndex = ifcIndex; + getReplyForWrite(jvppSnat.snatInterfaceAddDelOutputFeature(request).toCompletableFuture(), id); + } + + private void preRoutingNat(@Nonnull final InstanceIdentifier id, final D natAttributes, final int ifcIndex, + final boolean enable) + throws WriteFailedException { + if (natAttributes.isNat44Support()) { + // default value is defined for nat44-support, so no need for null check + preRoutingNat44(id, ifcIndex, enable); + } + if (isNat64Supported(natAttributes)) { + preRoutingNat64(id, ifcIndex, enable); + } + } - final CompletionStage future = - jvppSnat.snatInterfaceAddDelOutputFeature(request); - return getReplyForWrite(future.toCompletableFuture(), id); + private boolean isNat64Supported(final D natAttributes) { + return natAttributes.isNat64Support() != null && natAttributes.isNat64Support(); } - private JVppReply preRoutingNat(@Nonnull final InstanceIdentifier id, final int ifcIndex, final boolean enable) + private void preRoutingNat44(@Nonnull final InstanceIdentifier id, final int ifcIndex, final boolean enable) throws WriteFailedException { final SnatInterfaceAddDelFeature request = new SnatInterfaceAddDelFeature(); request.isAdd = booleanToByte(enable); request.isInside = getType().isInside; request.swIfIndex = ifcIndex; + getReplyForWrite(jvppSnat.snatInterfaceAddDelFeature(request).toCompletableFuture(), id); + } - final CompletionStage future = jvppSnat.snatInterfaceAddDelFeature(request); - return getReplyForWrite(future.toCompletableFuture(), id); + private void preRoutingNat64(@Nonnull final InstanceIdentifier id, final int ifcIndex, final boolean enable) + throws WriteFailedException { + final Nat64AddDelInterface request = new Nat64AddDelInterface(); + request.isAdd = booleanToByte(enable); + request.isInside = getType().isInside; + request.swIfIndex = ifcIndex; + getReplyForWrite(jvppSnat.nat64AddDelInterface(request).toCompletableFuture(), id); } enum NatType { diff --git a/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/read/ifc/InterfaceInboundNatCustomizerTest.java b/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/read/ifc/InterfaceInboundNatCustomizerTest.java index 2d31e3b6a..a2d92b4d0 100644 --- a/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/read/ifc/InterfaceInboundNatCustomizerTest.java +++ b/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/read/ifc/InterfaceInboundNatCustomizerTest.java @@ -16,7 +16,6 @@ package io.fd.hc2vpp.nat.read.ifc; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; @@ -29,6 +28,7 @@ import io.fd.hc2vpp.common.translate.util.NamingContext; import io.fd.honeycomb.translate.impl.read.GenericReader; import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; import io.fd.honeycomb.translate.util.RWUtils; +import io.fd.vpp.jvpp.snat.dto.Nat64InterfaceDetailsReplyDump; import io.fd.vpp.jvpp.snat.dto.SnatInterfaceDetails; import io.fd.vpp.jvpp.snat.dto.SnatInterfaceDetailsReplyDump; import io.fd.vpp.jvpp.snat.dto.SnatInterfaceOutputFeatureDetails; @@ -79,17 +79,14 @@ public class InterfaceInboundNatCustomizerTest when(jvppSnat.snatInterfaceDump(any())).thenReturn(future(new SnatInterfaceDetailsReplyDump())); when(jvppSnat.snatInterfaceOutputFeatureDump(any())) .thenReturn(future(new SnatInterfaceOutputFeatureDetailsReplyDump())); + when(jvppSnat.nat64InterfaceDump(any())) + .thenReturn(future(new Nat64InterfaceDetailsReplyDump())); } private GenericReader getReader() { return new GenericReader<>(RWUtils.makeIidWildcarded(id), customizer); } - @Test - public void testNoPresence() throws Exception { - assertFalse(getReader().read(id, ctx).isPresent()); - } - private void mockPostRoutingDump() { final SnatInterfaceOutputFeatureDetailsReplyDump details = new SnatInterfaceOutputFeatureDetailsReplyDump(); final SnatInterfaceOutputFeatureDetails detail = new SnatInterfaceOutputFeatureDetails(); diff --git a/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/read/ifc/InterfaceOutboundNatCustomizerTest.java b/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/read/ifc/InterfaceOutboundNatCustomizerTest.java index 92dfff161..4640944a5 100644 --- a/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/read/ifc/InterfaceOutboundNatCustomizerTest.java +++ b/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/read/ifc/InterfaceOutboundNatCustomizerTest.java @@ -17,7 +17,6 @@ package io.fd.hc2vpp.nat.read.ifc; import static io.fd.hc2vpp.nat.read.ifc.InterfaceInboundNatCustomizerTest.getId; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; @@ -30,6 +29,7 @@ import io.fd.hc2vpp.common.translate.util.NamingContext; import io.fd.honeycomb.translate.impl.read.GenericReader; import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; import io.fd.honeycomb.translate.util.RWUtils; +import io.fd.vpp.jvpp.snat.dto.Nat64InterfaceDetailsReplyDump; import io.fd.vpp.jvpp.snat.dto.SnatInterfaceDetails; import io.fd.vpp.jvpp.snat.dto.SnatInterfaceDetailsReplyDump; import io.fd.vpp.jvpp.snat.dto.SnatInterfaceOutputFeatureDetails; @@ -65,17 +65,14 @@ public class InterfaceOutboundNatCustomizerTest when(jvppSnat.snatInterfaceDump(any())).thenReturn(future(new SnatInterfaceDetailsReplyDump())); when(jvppSnat.snatInterfaceOutputFeatureDump(any())) .thenReturn(future(new SnatInterfaceOutputFeatureDetailsReplyDump())); + when(jvppSnat.nat64InterfaceDump(any())) + .thenReturn(future(new Nat64InterfaceDetailsReplyDump())); } private GenericReader getReader() { return new GenericReader<>(RWUtils.makeIidWildcarded(id), customizer); } - @Test - public void testNoPresence() throws Exception { - assertFalse(getReader().read(id, ctx).isPresent()); - } - private void mockPostRoutingDump() { final SnatInterfaceOutputFeatureDetailsReplyDump details = new SnatInterfaceOutputFeatureDetailsReplyDump(); final SnatInterfaceOutputFeatureDetails detail = new SnatInterfaceOutputFeatureDetails(); diff --git a/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/write/ifc/AbstractNatCustomizerTest.java b/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/write/ifc/AbstractNatCustomizerTest.java index 5e37d165d..c70999907 100644 --- a/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/write/ifc/AbstractNatCustomizerTest.java +++ b/nat/nat2vpp/src/test/java/io/fd/hc2vpp/nat/write/ifc/AbstractNatCustomizerTest.java @@ -17,12 +17,15 @@ package io.fd.hc2vpp.nat.write.ifc; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import io.fd.hc2vpp.common.test.write.WriterCustomizerTest; import io.fd.hc2vpp.common.translate.util.ByteDataTranslator; import io.fd.hc2vpp.common.translate.util.NamingContext; +import io.fd.vpp.jvpp.snat.dto.Nat64AddDelInterface; +import io.fd.vpp.jvpp.snat.dto.Nat64AddDelInterfaceReply; import io.fd.vpp.jvpp.snat.dto.SnatInterfaceAddDelFeature; import io.fd.vpp.jvpp.snat.dto.SnatInterfaceAddDelFeatureReply; import io.fd.vpp.jvpp.snat.dto.SnatInterfaceAddDelOutputFeature; @@ -54,13 +57,14 @@ abstract class AbstractNatCustomizerTest