diff options
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) { |