summaryrefslogtreecommitdiffstats
path: root/nat/nat2vpp/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'nat/nat2vpp/src/main')
-rw-r--r--nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/ExternalIpPoolCustomizer.java51
-rw-r--r--nat/nat2vpp/src/main/java/io/fd/hc2vpp/nat/write/NatWriterFactory.java6
2 files changed, 45 insertions, 12 deletions
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 61fedbd48..62331620d 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
@@ -17,13 +17,16 @@
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 io.fd.honeycomb.translate.spi.write.ListWriterCustomizer;
+import io.fd.hc2vpp.common.translate.util.ByteDataTranslator;
import io.fd.hc2vpp.common.translate.util.Ipv4AddressRange;
import io.fd.hc2vpp.common.translate.util.Ipv4Translator;
import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer;
+import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer;
import io.fd.honeycomb.translate.write.WriteContext;
import io.fd.honeycomb.translate.write.WriteFailedException;
+import io.fd.vpp.jvpp.snat.dto.Nat64AddDelPoolAddrRange;
import io.fd.vpp.jvpp.snat.dto.SnatAddAddressRange;
import io.fd.vpp.jvpp.snat.future.FutureJVppSnatFacade;
import javax.annotation.Nonnull;
@@ -31,12 +34,13 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
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.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
final class ExternalIpPoolCustomizer implements ListWriterCustomizer<ExternalIpAddressPool, ExternalIpAddressPoolKey>,
- JvppReplyConsumer, Ipv4Translator {
+ JvppReplyConsumer, Ipv4Translator, ByteDataTranslator {
private static final Logger LOG = LoggerFactory.getLogger(ExternalIpPoolCustomizer.class);
@@ -54,8 +58,7 @@ final class ExternalIpPoolCustomizer implements ListWriterCustomizer<ExternalIpA
"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
- getReplyForCreate(jvppSnat.snatAddAddressRange(
- getRequest(dataAfter.getExternalIpPool(), true)).toCompletableFuture(), id, dataAfter);
+ configureAddressPool(id, dataAfter, true);
LOG.debug("Address range: {} added successfully", id);
}
@@ -64,20 +67,46 @@ final class ExternalIpPoolCustomizer implements ListWriterCustomizer<ExternalIpA
@Nonnull final ExternalIpAddressPool dataBefore,
@Nonnull final WriteContext writeContext) throws WriteFailedException {
LOG.trace("Deleting address range:{}, as: {}", id, dataBefore);
- getReplyForDelete(jvppSnat.snatAddAddressRange(
- getRequest(dataBefore.getExternalIpPool(), false)).toCompletableFuture(), id);
+ configureAddressPool(id, dataBefore, false);
LOG.debug("Deleting range: {} added successfully", id);
}
- private SnatAddAddressRange getRequest(final Ipv4Prefix externalIpPool, boolean isAdd) {
- SnatAddAddressRange request = new SnatAddAddressRange();
- // SNAT supports only IPv4 now, so does the model
+ private void configureAddressPool(@Nonnull final InstanceIdentifier<ExternalIpAddressPool> id,
+ @Nonnull final ExternalIpAddressPool addressPool,
+ final boolean isAdd) throws WriteFailedException {
+ boolean isNat64 = false;
+ final ExternalIpAddressPoolConfigAugmentation augmentation =
+ addressPool.getAugmentation(ExternalIpAddressPoolConfigAugmentation.class);
+ if (augmentation != null) {
+ isNat64 = Nat64.equals(augmentation.getPoolType());
+ }
+ if (isNat64) {
+ final Nat64AddDelPoolAddrRange request = getNat64Request(addressPool.getExternalIpPool(), isAdd);
+ getReplyForWrite(jvppSnat.nat64AddDelPoolAddrRange(request).toCompletableFuture(), id);
+ } else {
+ final SnatAddAddressRange request = getNat44Request(addressPool.getExternalIpPool(), isAdd);
+ getReplyForWrite(jvppSnat.snatAddAddressRange(request).toCompletableFuture(), id);
+ }
+ }
+
+ private SnatAddAddressRange getNat44Request(final Ipv4Prefix externalIpPool, boolean isAdd) {
+ final SnatAddAddressRange request = new SnatAddAddressRange();
final Ipv4AddressRange range = Ipv4AddressRange.fromPrefix(externalIpPool);
- LOG.trace("Handling address range: {}", range);
+ LOG.trace("Handling NAT44 address range: {}", range);
request.isIp4 = 1;
- request.isAdd = (byte) (isAdd ? 1 : 0);
+ request.isAdd = booleanToByte(isAdd);
request.firstIpAddress = ipv4AddressNoZoneToArray(range.getStart());
request.lastIpAddress = ipv4AddressNoZoneToArray(range.getEnd());
return request;
}
+
+ private Nat64AddDelPoolAddrRange getNat64Request(final Ipv4Prefix externalIpPool, boolean isAdd) {
+ final Nat64AddDelPoolAddrRange request = new Nat64AddDelPoolAddrRange();
+ final Ipv4AddressRange range = Ipv4AddressRange.fromPrefix(externalIpPool);
+ LOG.trace("Handling NAT64 address range: {}", range);
+ request.isAdd = booleanToByte(isAdd);
+ request.startAddr = ipv4AddressNoZoneToArray(range.getStart());
+ request.endAddr = ipv4AddressNoZoneToArray(range.getEnd());
+ return request;
+ }
}
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 e239721d4..ef2a2afdd 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
@@ -32,6 +32,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.nat.rev1509
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.opendaylight.params.xml.ns.yang.vpp.nat.rev170804.ExternalIpAddressPoolConfigAugmentation;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
/**
@@ -66,7 +67,10 @@ public final class NatWriterFactory implements WriterFactory {
// 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
- registry.addBefore(new GenericListWriter<>(NAT_INSTANCE_ID.child(ExternalIpAddressPool.class),
+ registry.subtreeAddBefore(
+ Sets.newHashSet(InstanceIdentifier.create(ExternalIpAddressPool.class)
+ .augmentation(ExternalIpAddressPoolConfigAugmentation.class)),
+ new GenericListWriter<>(NAT_INSTANCE_ID.child(ExternalIpAddressPool.class),
new ExternalIpPoolCustomizer(jvppSnat)),
MAP_ENTRY_ID);
}