summaryrefslogtreecommitdiffstats
path: root/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write
diff options
context:
space:
mode:
Diffstat (limited to 'nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write')
-rw-r--r--nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/ifc/AbstractInterfaceNatCustomizer.java73
-rw-r--r--nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/ifc/AbstractSubInterfaceNatCustomizer.java8
-rw-r--r--nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/ifc/IfcNatWriterFactory.java4
-rw-r--r--nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/ifc/SubIfcNatWriterFactory.java10
4 files changed, 61 insertions, 34 deletions
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 455b4615f..82af93481 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,22 +16,28 @@
package io.fd.hc2vpp.nat.write.ifc;
-import io.fd.honeycomb.translate.spi.write.WriterCustomizer;
+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.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.rev170801.InterfaceNatVppFeatureAttributes;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
-abstract class AbstractInterfaceNatCustomizer<D extends DataObject> implements JvppReplyConsumer, WriterCustomizer<D> {
+abstract class AbstractInterfaceNatCustomizer<D extends InterfaceNatVppFeatureAttributes & DataObject>
+ implements ByteDataTranslator, JvppReplyConsumer, WriterCustomizer<D> {
private final FutureJVppSnatFacade jvppSnat;
private final NamingContext ifcContext;
@@ -47,14 +53,16 @@ abstract class AbstractInterfaceNatCustomizer<D extends DataObject> implements J
@Nonnull final WriteContext writeContext) throws WriteFailedException {
final String ifcName = getName(id);
getLog().debug("Enabling " + getType() + " NAT on interface: {}", ifcName);
- getLog().debug("Enabling " + getType() + " NAT: {}", id);
+ getLog().debug("Enabling {} NAT: {}", dataAfter, id);
final int ifcIndex = ifcContext.getIndex(ifcName, writeContext.getMappingContext());
- final SnatInterfaceAddDelFeature request = getRequest(ifcIndex, (byte)1);
- final CompletionStage<SnatInterfaceAddDelFeatureReply> future = jvppSnat.snatInterfaceAddDelFeature(request);
-
- final SnatInterfaceAddDelFeatureReply reply = getReplyForWrite(future.toCompletableFuture(), id);
- getLog().debug("NAT " + getType() + " enabled successfully on: {}, reply: {}", ifcName, reply);
+ final JVppReply reply;
+ if (dataAfter.isPostRouting()) {
+ reply = postRoutingNat(id, ifcIndex, true);
+ } else {
+ reply = preRoutingNat(id, ifcIndex, true);
+ }
+ getLog().debug("NAT {} enabled successfully on: {}, reply: {}", dataAfter, ifcName, reply);
}
@Override
@@ -71,22 +79,47 @@ abstract class AbstractInterfaceNatCustomizer<D extends DataObject> implements J
throws WriteFailedException {
final String ifcName = getName(id);
getLog().debug("Disabling " + getType() + " NAT on interface: {}", ifcName);
- getLog().debug("Disabling " + getType() + " NAT: {}", id);
+ getLog().debug("Disabling {} NAT: {}", dataBefore, id);
final int ifcIndex = ifcContext.getIndex(ifcName, writeContext.getMappingContext());
- final SnatInterfaceAddDelFeature request = getRequest(ifcIndex, (byte)0);
- final CompletionStage<SnatInterfaceAddDelFeatureReply> future = jvppSnat.snatInterfaceAddDelFeature(request);
-
- final SnatInterfaceAddDelFeatureReply reply = getReplyForWrite(future.toCompletableFuture(), id);
- getLog().debug("NAT " + getType() + " disabled successfully on: {}, reply: {}", ifcName, reply);
+ final JVppReply reply;
+ if (dataBefore.isPostRouting()) {
+ reply = postRoutingNat(id, ifcIndex, false);
+ } else {
+ reply = preRoutingNat(id, ifcIndex, false);
+ }
+ getLog().debug("NAT {} disabled successfully on: {}, reply: {}", dataBefore, ifcName, reply);
}
protected String getName(final InstanceIdentifier<D> id) {
return id.firstKeyOf(Interface.class).getName();
}
+ private JVppReply postRoutingNat(@Nonnull final InstanceIdentifier<D> id, final int ifcIndex, final boolean enable)
+ throws WriteFailedException {
+ final SnatInterfaceAddDelOutputFeature request = new SnatInterfaceAddDelOutputFeature();
+ request.isAdd = booleanToByte(enable);
+ request.isInside = getType().isInside;
+ request.swIfIndex = ifcIndex;
+
+ final CompletionStage<SnatInterfaceAddDelOutputFeatureReply> future =
+ jvppSnat.snatInterfaceAddDelOutputFeature(request);
+ return getReplyForWrite(future.toCompletableFuture(), id);
+ }
+
+ private JVppReply preRoutingNat(@Nonnull final InstanceIdentifier<D> 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;
+
+ final CompletionStage<SnatInterfaceAddDelFeatureReply> future = jvppSnat.snatInterfaceAddDelFeature(request);
+ return getReplyForWrite(future.toCompletableFuture(), id);
+ }
+
enum NatType {
- INBOUND((byte)1), OUTBOUND((byte)0);
+ INBOUND((byte) 1), OUTBOUND((byte) 0);
private final byte isInside;
@@ -96,14 +129,6 @@ abstract class AbstractInterfaceNatCustomizer<D extends DataObject> implements J
}
abstract NatType getType();
- abstract Logger getLog();
-
- private SnatInterfaceAddDelFeature getRequest(final int ifcIdx, final byte isAdd) {
- final SnatInterfaceAddDelFeature request = new SnatInterfaceAddDelFeature();
- request.isAdd = isAdd;
- request.isInside = getType().isInside;
- request.swIfIndex = ifcIdx;
- return request;
- }
+ abstract Logger getLog();
}
diff --git a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/ifc/AbstractSubInterfaceNatCustomizer.java b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/ifc/AbstractSubInterfaceNatCustomizer.java
index 4e693ecde..ca40f8a98 100644
--- a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/ifc/AbstractSubInterfaceNatCustomizer.java
+++ b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/ifc/AbstractSubInterfaceNatCustomizer.java
@@ -37,13 +37,15 @@ import io.fd.hc2vpp.common.translate.util.NamingContext;
import io.fd.vpp.jvpp.snat.future.FutureJVppSnatFacade;
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.rev170801.InterfaceNatVppFeatureAttributes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.vpp.vlan.rev170607.interfaces._interface.sub.interfaces.SubInterface;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-abstract class AbstractSubInterfaceNatCustomizer<D extends DataObject> extends AbstractInterfaceNatCustomizer<D> {
+abstract class AbstractSubInterfaceNatCustomizer<D extends InterfaceNatVppFeatureAttributes & DataObject>
+ extends AbstractInterfaceNatCustomizer<D> {
AbstractSubInterfaceNatCustomizer(@Nonnull final FutureJVppSnatFacade jvppSnat,
- @Nonnull final NamingContext ifcContext) {
+ @Nonnull final NamingContext ifcContext) {
super(jvppSnat, ifcContext);
}
@@ -51,7 +53,7 @@ abstract class AbstractSubInterfaceNatCustomizer<D extends DataObject> extends A
protected String getName(final InstanceIdentifier<D> id) {
// TODO(HC2VPP-99): use SubInterfaceUtils after it is moved from v3po2vpp
final String parentInterfaceName =
- checkNotNull(id.firstKeyOf(Interface.class), "Interface configuration identifier expected").getName();
+ checkNotNull(id.firstKeyOf(Interface.class), "Interface configuration identifier expected").getName();
final Long subIfId = id.firstKeyOf(SubInterface.class).getIdentifier();
return String.format("%s.%d", parentInterfaceName, subIfId.intValue());
}
diff --git a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/ifc/IfcNatWriterFactory.java b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/ifc/IfcNatWriterFactory.java
index 12a12b329..499c9a999 100644
--- a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/ifc/IfcNatWriterFactory.java
+++ b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/ifc/IfcNatWriterFactory.java
@@ -18,8 +18,8 @@ package io.fd.hc2vpp.nat.write.ifc;
import com.google.inject.Inject;
import com.google.inject.name.Named;
-import io.fd.honeycomb.translate.impl.write.GenericWriter;
import io.fd.hc2vpp.common.translate.util.NamingContext;
+import io.fd.honeycomb.translate.impl.write.GenericWriter;
import io.fd.honeycomb.translate.write.WriterFactory;
import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder;
import io.fd.vpp.jvpp.snat.future.FutureJVppSnatFacade;
@@ -40,7 +40,7 @@ public final class IfcNatWriterFactory implements WriterFactory {
private static final InstanceIdentifier<Interface>
IFC_ID = InstanceIdentifier.create(Interfaces.class).child(Interface.class);
private static final InstanceIdentifier<Nat> NAT_AUG_ID =
- IFC_ID .augmentation(NatInterfaceAugmentation.class).child(Nat.class);
+ IFC_ID.augmentation(NatInterfaceAugmentation.class).child(Nat.class);
private final FutureJVppSnatFacade jvppSnat;
private final NamingContext ifcContext;
diff --git a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/ifc/SubIfcNatWriterFactory.java b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/ifc/SubIfcNatWriterFactory.java
index 86209f627..231d73f72 100644
--- a/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/ifc/SubIfcNatWriterFactory.java
+++ b/nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/ifc/SubIfcNatWriterFactory.java
@@ -41,10 +41,10 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
public final class SubIfcNatWriterFactory implements WriterFactory {
private static final InstanceIdentifier<SubInterface>
- SUB_IFC_ID = InstanceIdentifier.create(Interfaces.class).child(Interface.class).augmentation(
- SubinterfaceAugmentation.class).child(SubInterfaces.class).child(SubInterface.class);
+ SUB_IFC_ID = InstanceIdentifier.create(Interfaces.class).child(Interface.class).augmentation(
+ SubinterfaceAugmentation.class).child(SubInterfaces.class).child(SubInterface.class);
private static final InstanceIdentifier<Nat> NAT_AUG_ID =
- SUB_IFC_ID.augmentation(NatSubinterfaceAugmentation.class).child(Nat.class);
+ SUB_IFC_ID.augmentation(NatSubinterfaceAugmentation.class).child(Nat.class);
private final FutureJVppSnatFacade jvppSnat;
private final NamingContext ifcContext;
@@ -59,8 +59,8 @@ public final class SubIfcNatWriterFactory implements WriterFactory {
@Override
public void init(@Nonnull final ModifiableWriterRegistryBuilder registry) {
registry.addAfter(new GenericWriter<>(NAT_AUG_ID.child(Inbound.class),
- new SubInterfaceInboundNatCustomizer(jvppSnat, ifcContext)), SUB_IFC_ID);
+ new SubInterfaceInboundNatCustomizer(jvppSnat, ifcContext)), SUB_IFC_ID);
registry.addAfter(new GenericWriter<>(NAT_AUG_ID.child(Outbound.class),
- new SubInterfaceOutboundNatCustomizer(jvppSnat, ifcContext)), SUB_IFC_ID);
+ new SubInterfaceOutboundNatCustomizer(jvppSnat, ifcContext)), SUB_IFC_ID);
}
}