summaryrefslogtreecommitdiffstats
path: root/vpp-common/vpp-translate-utils/src/main/java/io
diff options
context:
space:
mode:
authorJan Srnicek <jsrnicek@cisco.com>2016-10-04 16:44:47 +0200
committerMaros Marsalek <mmarsale@cisco.com>2016-10-05 11:52:37 +0000
commit6e92b4740d62b5977590f8a247b08eb945b9e5b7 (patch)
tree366c1f8536528637d58ba55088b3a3c90b522283 /vpp-common/vpp-translate-utils/src/main/java/io
parent4cd8aad5217a5225a2a33b448478dd81548e38b1 (diff)
HONEYCOMB-138 - Lisp L2 Support
Change-Id: Idff4776a64a88be2e0a45ab1927978e40876ea92 Signed-off-by: Jan Srnicek <jsrnicek@cisco.com>
Diffstat (limited to 'vpp-common/vpp-translate-utils/src/main/java/io')
-rw-r--r--vpp-common/vpp-translate-utils/src/main/java/io/fd/honeycomb/translate/vpp/util/AddressTranslator.java14
-rw-r--r--vpp-common/vpp-translate-utils/src/main/java/io/fd/honeycomb/translate/vpp/util/MacTranslator.java9
2 files changed, 18 insertions, 5 deletions
diff --git a/vpp-common/vpp-translate-utils/src/main/java/io/fd/honeycomb/translate/vpp/util/AddressTranslator.java b/vpp-common/vpp-translate-utils/src/main/java/io/fd/honeycomb/translate/vpp/util/AddressTranslator.java
index c716dd6f1..bb096d198 100644
--- a/vpp-common/vpp-translate-utils/src/main/java/io/fd/honeycomb/translate/vpp/util/AddressTranslator.java
+++ b/vpp-common/vpp-translate-utils/src/main/java/io/fd/honeycomb/translate/vpp/util/AddressTranslator.java
@@ -39,7 +39,7 @@ public interface AddressTranslator extends Ipv4Translator, Ipv6Translator, MacTr
}
/**
- * Converts array bytes to {@link IpAddress}
+ * Converts array bytes to {@link IpAddress}.
*/
@Nonnull
default IpAddress arrayToIpAddress(boolean isIpv6, byte[] ip) {
@@ -50,6 +50,18 @@ public interface AddressTranslator extends Ipv4Translator, Ipv6Translator, MacTr
}
}
+ /**
+ * Converts array bytes to {@link IpAddress}
+ */
+ @Nonnull
+ default IpAddress arrayToIpAddressReversed(boolean isIpv6, byte[] ip) {
+ if (isIpv6) {
+ return new IpAddress(arrayToIpv6AddressNoZoneReversed(ip));
+ } else {
+ return new IpAddress(arrayToIpv4AddressNoZoneReversed(ip));
+ }
+ }
+
default IpAddress reverseAddress(@Nonnull final IpAddress address) {
//arrayToIpAdddress internaly reverts order
return arrayToIpAddress(isIpv6(address), ipAddressToArray(address));
diff --git a/vpp-common/vpp-translate-utils/src/main/java/io/fd/honeycomb/translate/vpp/util/MacTranslator.java b/vpp-common/vpp-translate-utils/src/main/java/io/fd/honeycomb/translate/vpp/util/MacTranslator.java
index af26b11b2..a947f95c6 100644
--- a/vpp-common/vpp-translate-utils/src/main/java/io/fd/honeycomb/translate/vpp/util/MacTranslator.java
+++ b/vpp-common/vpp-translate-utils/src/main/java/io/fd/honeycomb/translate/vpp/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 java.util.Arrays;
import java.util.List;
import java.util.function.BiConsumer;
import javax.annotation.Nonnull;
@@ -64,17 +65,17 @@ public interface MacTranslator {
* Converts byte array to address string ,not separated with ":"
*/
default String byteArrayToMacUnseparated(byte[] address) {
- checkArgument(address.length == 6, "Illegal array length");
- return Hex.encodeHexString(address);
+ checkArgument(address.length >= 6, "Illegal array length");
+ return Hex.encodeHexString(Arrays.copyOf(address, 6));
}
/**
* Converts byte array to address string ,separated with ":"
*/
default String byteArrayToMacSeparated(byte[] address) {
- checkArgument(address.length == 6, "Illegal array length");
+ checkArgument(address.length >= 6, "Illegal array length");
- String unseparatedAddress = Hex.encodeHexString(address);
+ String unseparatedAddress = Hex.encodeHexString(Arrays.copyOf(address, 6));
String separated = "";
for (int i = 0; i < unseparatedAddress.length(); i = i + 2) {