summaryrefslogtreecommitdiffstats
path: root/vpp-common/vpp-translate-utils
diff options
context:
space:
mode:
authorMichal Cmarada <mcmarada@cisco.com>2019-05-06 13:48:21 +0200
committerMichal Cmarada <mcmarada@cisco.com>2019-05-06 13:48:21 +0200
commit97554c44ffc7f7ce82fe89d6da5ac15c46ee80b4 (patch)
treed1756819a8e108ab381129e747575c9515e0072e /vpp-common/vpp-translate-utils
parentb248447c7ab16c86b28e9bda5f7224a9d106ac43 (diff)
fix Nat implementation after API changes in VPP
Change-Id: Ibe8ead5a19119af9eb6b673f0713890ad5e243cb Signed-off-by: Michal Cmarada <mcmarada@cisco.com>
Diffstat (limited to 'vpp-common/vpp-translate-utils')
-rw-r--r--vpp-common/vpp-translate-utils/pom.xml5
-rw-r--r--vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/AddressTranslator.java1
-rw-r--r--vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/Ipv4Translator.java25
-rw-r--r--vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/Ipv6Translator.java28
4 files changed, 58 insertions, 1 deletions
diff --git a/vpp-common/vpp-translate-utils/pom.xml b/vpp-common/vpp-translate-utils/pom.xml
index 9519e7970..c5e1fb45a 100644
--- a/vpp-common/vpp-translate-utils/pom.xml
+++ b/vpp-common/vpp-translate-utils/pom.xml
@@ -53,6 +53,11 @@
<artifactId>jvpp-core</artifactId>
</dependency>
<dependency>
+ <groupId>io.fd.jvpp</groupId>
+ <artifactId>jvpp-nat</artifactId>
+ <version>${jvpp.version}</version>
+ </dependency>
+ <dependency>
<groupId>org.opendaylight.mdsal.model</groupId>
<artifactId>ietf-inet-types-2013-07-15</artifactId>
</dependency>
diff --git a/vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/AddressTranslator.java b/vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/AddressTranslator.java
index 3f5a56fb2..e6d71bee8 100644
--- a/vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/AddressTranslator.java
+++ b/vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/AddressTranslator.java
@@ -18,7 +18,6 @@ package io.fd.hc2vpp.common.translate.util;
import static com.google.common.base.Preconditions.checkNotNull;
-import java.util.Arrays;
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.IpAddressNoZone;
diff --git a/vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/Ipv4Translator.java b/vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/Ipv4Translator.java
index 88085db78..f6fc3c78f 100644
--- a/vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/Ipv4Translator.java
+++ b/vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/Ipv4Translator.java
@@ -56,6 +56,20 @@ public interface Ipv4Translator extends ByteDataTranslator {
}
/**
+ * Creates {@link io.fd.jvpp.nat.types.Ip4Address} address from address part of {@link Ipv4Prefix}
+ *
+ * @return {@link io.fd.jvpp.nat.types.Ip4Address}
+ */
+ default io.fd.jvpp.nat.types.Ip4Address ipv4AddressPrefixToNatIp4Address(@Nonnull final Ipv4Prefix ipv4Prefix) {
+ checkNotNull(ipv4Prefix, "Cannot convert null prefix");
+
+ io.fd.jvpp.nat.types.Ip4Address address = new io.fd.jvpp.nat.types.Ip4Address();
+ address.ip4Address = ipv4AddressPrefixToArray(ipv4Prefix);
+
+ return address;
+ }
+
+ /**
* Extracts {@link Ipv4Prefix} prefix
*/
default byte extractPrefix(Ipv4Prefix data) {
@@ -89,6 +103,17 @@ public interface Ipv4Translator extends ByteDataTranslator {
}
/**
+ * Transform Ipv4 address to a {@link io.fd.jvpp.nat.types.Ip4Address} acceptable by VPP.
+ *
+ * @return {@link io.fd.jvpp.nat.types.Ip4Address}
+ */
+ default io.fd.jvpp.nat.types.Ip4Address ipv4AddressNoZoneToNatIp4Address(final Ipv4AddressNoZone ipv4Addr) {
+ io.fd.jvpp.nat.types.Ip4Address ip4Address = new io.fd.jvpp.nat.types.Ip4Address();
+ ip4Address.ip4Address = ipv4AddressNoZoneToArray(ipv4Addr.getValue());
+ return ip4Address;
+ }
+
+ /**
* Transform Ipv4 address to a Ip4Address acceptable by VPP.
*
* @return byte array with address bytes
diff --git a/vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/Ipv6Translator.java b/vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/Ipv6Translator.java
index 153143910..c1ccd2d88 100644
--- a/vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/Ipv6Translator.java
+++ b/vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/Ipv6Translator.java
@@ -78,6 +78,19 @@ public interface Ipv6Translator extends ByteDataTranslator {
}
/**
+ * Creates {@link io.fd.jvpp.nat.types.Ip6Address} from address part of {@link Ipv6Prefix}
+ *
+ * @return {@link io.fd.jvpp.nat.types.Ip6Address}
+ */
+ default io.fd.jvpp.nat.types.Ip6Address ipv6AddressPrefixToNatIp6Address(@Nonnull final Ipv6Prefix ipv6Prefix) {
+ checkNotNull(ipv6Prefix, "Cannot convert null prefix");
+
+ io.fd.jvpp.nat.types.Ip6Address ip6Address = new io.fd.jvpp.nat.types.Ip6Address();
+ ip6Address.ip6Address = ipv6AddressPrefixToArray(ipv6Prefix);
+ return ip6Address;
+ }
+
+ /**
* Transforms {@link Prefix} from {@link Ipv6Prefix}
* @param ipv6Prefix prefix to be translated
* @return Vpp {@link Prefix} from {@link Ipv6Prefix}
@@ -95,6 +108,21 @@ public interface Ipv6Translator extends ByteDataTranslator {
}
/**
+ * Creates {@link io.fd.jvpp.nat.types.Ip6Prefix} from {@link Ipv6Prefix}
+ *
+ * @param ipv6Prefix prefix to be translated
+ * @return Vpp {@link io.fd.jvpp.nat.types.Ip6Prefix} from {@link Ipv6Prefix}
+ */
+ default io.fd.jvpp.nat.types.Ip6Prefix ipv6AddressPrefixToNatIp6Prefix(@Nonnull final Ipv6Prefix ipv6Prefix) {
+ checkNotNull(ipv6Prefix, "Cannot convert null prefix");
+ io.fd.jvpp.nat.types.Ip6Prefix prefix = new io.fd.jvpp.nat.types.Ip6Prefix();
+ prefix.prefix = new io.fd.jvpp.nat.types.Ip6Address();
+ prefix.prefix.ip6Address = ipv6AddressPrefixToArray(ipv6Prefix);
+ prefix.len = extractPrefix(ipv6Prefix);
+ return prefix;
+ }
+
+ /**
* Extracts {@link Ipv6Prefix} prefix
*/
default byte extractPrefix(Ipv6Prefix data) {