From 97554c44ffc7f7ce82fe89d6da5ac15c46ee80b4 Mon Sep 17 00:00:00 2001 From: Michal Cmarada Date: Mon, 6 May 2019 13:48:21 +0200 Subject: fix Nat implementation after API changes in VPP Change-Id: Ibe8ead5a19119af9eb6b673f0713890ad5e243cb Signed-off-by: Michal Cmarada --- .../common/translate/util/AddressTranslator.java | 1 - .../common/translate/util/Ipv4Translator.java | 25 +++++++++++++++++++ .../common/translate/util/Ipv6Translator.java | 28 ++++++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) (limited to 'vpp-common/vpp-translate-utils/src/main/java') 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 @@ -55,6 +55,20 @@ public interface Ipv4Translator extends ByteDataTranslator { return retval; } + /** + * 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 */ @@ -88,6 +102,17 @@ public interface Ipv4Translator extends ByteDataTranslator { return ipv4AddressNoZoneToArray(ipv4Addr.getValue()); } + /** + * 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. * 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 @@ -77,6 +77,19 @@ public interface Ipv6Translator extends ByteDataTranslator { new Ipv6Address(ipv6Prefix.getValue().substring(0, ipv6Prefix.getValue().indexOf('/'))))); } + /** + * 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 @@ -94,6 +107,21 @@ public interface Ipv6Translator extends ByteDataTranslator { return prefix; } + /** + * 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 */ -- cgit 1.2.3-korg