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 --- .../write/ifc/AbstractInterfaceNatCustomizer.java | 57 ++++++++++++++-------- 1 file changed, 38 insertions(+), 19 deletions(-) (limited to 'nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/ifc/AbstractInterfaceNatCustomizer.java') 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 { -- cgit 1.2.3-korg