diff options
author | 2016-10-04 16:44:47 +0200 | |
---|---|---|
committer | 2016-10-05 11:52:37 +0000 | |
commit | 5d1054b26f144948be321f30204b4b2a7cbbc03e (patch) | |
tree | 2104b21d9a2e728b8275d5d9f2a554c414db8c31 /vpp-common/vpp-translate-utils/src/main/java/io | |
parent | 512143ddd9995d16d9bb055481721fa276ccfa01 (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')
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) { |