summaryrefslogtreecommitdiffstats
path: root/vpp-common
diff options
context:
space:
mode:
authorMichal Cmarada <mcmarada@cisco.com>2019-02-06 09:41:39 +0100
committerMichal Cmarada <mcmarada@cisco.com>2019-02-06 09:41:39 +0100
commit3751ef96ae1427cc8d5ecb9cbba705e837bb63ca (patch)
tree08c01465ea307e9eebcdf1e12990ebdb66961228 /vpp-common
parentacf5a8a052e2f7f7c2b03c023df3dd489688cb00 (diff)
fix after changes in VPP API
- fixes for mac adress - fixes for ipaddress - fixes refactoring in ipsec Change-Id: Idc3e3557b72a5f1ac5b32b9738d90ca23ed6ed9e Signed-off-by: Michal Cmarada <mcmarada@cisco.com>
Diffstat (limited to 'vpp-common')
-rw-r--r--vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/Ipv4Translator.java33
-rw-r--r--vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/Ipv6Translator.java39
-rw-r--r--vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/MacTranslator.java17
3 files changed, 89 insertions, 0 deletions
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 24f4ae9aa..5f8a283ed 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
@@ -18,9 +18,14 @@ package io.fd.hc2vpp.common.translate.util;
import static com.google.common.base.Preconditions.checkNotNull;
+import io.fd.vpp.jvpp.core.types.Address;
+import io.fd.vpp.jvpp.core.types.AddressFamily;
+import io.fd.vpp.jvpp.core.types.AddressUnion;
+import io.fd.vpp.jvpp.core.types.Ip4Address;
import java.util.Arrays;
import javax.annotation.Nonnull;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IetfInetUtil;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
@@ -83,6 +88,34 @@ public interface Ipv4Translator extends ByteDataTranslator {
return ipv4AddressNoZoneToArray(ipv4Addr.getValue());
}
+ /**
+ * Transform Ipv4 address to a Ip4Address acceptable by VPP.
+ *
+ * @return byte array with address bytes
+ */
+ default Address ipv4AddressNoZoneToAddress(final Ipv4AddressNoZone ipv4Addr) {
+ Address address = new Address();
+ address.af = AddressFamily.ADDRESS_IP4;
+ Ip4Address ip4Address = new Ip4Address();
+ ip4Address.ip4Address = ipv4AddressNoZoneToArray(ipv4Addr);
+ address.un = new AddressUnion(ip4Address);
+ return address;
+ }
+
+ /**
+ * Transform Ipv4 address to a Ip4Address acceptable by VPP.
+ *
+ * @return byte array with address bytes
+ */
+ default Address ipv4AddressToAddress(final Ipv4Address ipv4Addr) {
+ Address address = new Address();
+ address.af = AddressFamily.ADDRESS_IP4;
+ Ip4Address ip4Address = new Ip4Address();
+ ip4Address.ip4Address = ipv4AddressNoZoneToArray(ipv4Addr.getValue());
+ address.un = new AddressUnion(ip4Address);
+ return address;
+ }
+
default byte[] ipv4AddressNoZoneToArray(final String ipv4Addr) {
byte[] retval = new byte[4];
String[] dots = ipv4Addr.split("\\.");
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 b1199d7f7..d5c0ae2e3 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
@@ -21,6 +21,11 @@ import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import com.google.common.net.InetAddresses;
+import io.fd.vpp.jvpp.core.types.Address;
+import io.fd.vpp.jvpp.core.types.AddressFamily;
+import io.fd.vpp.jvpp.core.types.AddressUnion;
+import io.fd.vpp.jvpp.core.types.Ip6Address;
+import io.fd.vpp.jvpp.core.types.Prefix;
import javax.annotation.Nonnull;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IetfInetUtil;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
@@ -46,7 +51,24 @@ public interface Ipv6Translator extends ByteDataTranslator {
}
/**
+ * Transform Ipv6 address to a Address acceptable by VPP.
+ *
+ * @param address {@link Ipv6Address} to be translated
+ * @return Vpp {@link Address} from Ipv6 address
+ */
+ default Address ipv6AddressToAddress(@Nonnull final Ipv6Address address) {
+ Address addr = new Address();
+ addr.af = AddressFamily.ADDRESS_IP6;
+ Ip6Address ip6Address = new Ip6Address();
+ ip6Address.ip6Address = ipv6AddressNoZoneToArray(address);
+ addr.un = new AddressUnion(ip6Address);
+ return addr;
+ }
+
+ /**
* Creates address array from address part of {@link Ipv6Prefix}
+ *
+ * @return Ipv6 address as byte array
*/
default byte[] ipv6AddressPrefixToArray(@Nonnull final Ipv6Prefix ipv6Prefix) {
checkNotNull(ipv6Prefix, "Cannot convert null prefix");
@@ -56,6 +78,23 @@ public interface Ipv6Translator extends ByteDataTranslator {
}
/**
+ * Transforms {@link Prefix} from {@link Ipv6Prefix}
+ * @param ipv6Prefix prefix to be translated
+ * @return Vpp {@link Prefix} from {@link Ipv6Prefix}
+ */
+ default Prefix ipv6AddressPrefixToPrefix(@Nonnull final Ipv6Prefix ipv6Prefix) {
+ checkNotNull(ipv6Prefix, "Cannot convert null prefix");
+ Prefix prefix = new Prefix();
+ prefix.address = new Address();
+ prefix.address.af = AddressFamily.ADDRESS_IP6;
+ Ip6Address ip6Address = new Ip6Address();
+ ip6Address.ip6Address = ipv6AddressPrefixToArray(ipv6Prefix);
+ prefix.address.un = new AddressUnion(ip6Address);
+ prefix.addressLength = extractPrefix(ipv6Prefix);
+ return prefix;
+ }
+
+ /**
* Extracts {@link Ipv6Prefix} prefix
*/
default byte extractPrefix(Ipv6Prefix data) {
diff --git a/vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/MacTranslator.java b/vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/MacTranslator.java
index 71b8a15e6..657029eb3 100644
--- a/vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/MacTranslator.java
+++ b/vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/MacTranslator.java
@@ -20,6 +20,7 @@ import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.Splitter;
+import io.fd.vpp.jvpp.core.types.MacAddress;
import java.util.Arrays;
import java.util.List;
import java.util.function.BiConsumer;
@@ -37,6 +38,9 @@ public interface MacTranslator {
/**
* Parse string represented mac address (using ":" as separator) into a byte array
+ *
+ * @param macAddress string representation of MAC address (using ":" as separator)
+ * @return byte array mac address
*/
@Nonnull
default byte[] parseMac(@Nonnull final String macAddress) {
@@ -45,6 +49,19 @@ public interface MacTranslator {
return parseMacLikeString(parts);
}
+ /**
+ * Parse string represented mac address (using ":" as separator) into a MacAddress in VPP
+ *
+ * @param macAddress string representation of MAC address (using ":" as separator)
+ * @return VPP MacAddress
+ */
+ @Nonnull
+ default MacAddress parseMacAddress(@Nonnull final String macAddress) {
+ MacAddress mac = new MacAddress();
+ mac.macaddress = parseMac(macAddress);
+ return mac;
+ }
+
default byte[] parseMacLikeString(final List<String> strings) {
return strings.stream().limit(6).map(this::parseHexByte).collect(
() -> new byte[strings.size()],