From 9f7328169d65529de3fb1ed75872a081e4dc2184 Mon Sep 17 00:00:00 2001 From: Jan Srnicek Date: Wed, 21 Sep 2016 15:02:12 +0200 Subject: Fixed reading of operational state of lisp Rejecting of empty locator-sets Added revert of searched key to match vpp address order Ignoring helper data returned by dumps Change-Id: I5ec74f48dc373099b5fe516553d769c20e4a98f8 Signed-off-by: Jan Srnicek --- .../translate/v3po/util/TranslateUtils.java | 63 ++++++++++++---------- 1 file changed, 34 insertions(+), 29 deletions(-) (limited to 'vpp-common/vpp-translate-utils/src/main/java/io/fd/honeycomb') diff --git a/vpp-common/vpp-translate-utils/src/main/java/io/fd/honeycomb/translate/v3po/util/TranslateUtils.java b/vpp-common/vpp-translate-utils/src/main/java/io/fd/honeycomb/translate/v3po/util/TranslateUtils.java index 95b07743f..c1f17ea6c 100644 --- a/vpp-common/vpp-translate-utils/src/main/java/io/fd/honeycomb/translate/v3po/util/TranslateUtils.java +++ b/vpp-common/vpp-translate-utils/src/main/java/io/fd/honeycomb/translate/v3po/util/TranslateUtils.java @@ -59,14 +59,14 @@ public final class TranslateUtils { public static > REP getReplyForWrite(@Nonnull Future future, @Nonnull final InstanceIdentifier replyType) - throws VppBaseCallException, WriteTimeoutException { + throws VppBaseCallException, WriteTimeoutException { return getReplyForWrite(future, replyType, DEFAULT_TIMEOUT_IN_SECONDS); } public static > REP getReplyForWrite(@Nonnull Future future, @Nonnull final InstanceIdentifier replyType, @Nonnegative final int timeoutInSeconds) - throws VppBaseCallException, WriteTimeoutException { + throws VppBaseCallException, WriteTimeoutException { try { return getReply(future, timeoutInSeconds); } catch (TimeoutException e) { @@ -76,14 +76,14 @@ public final class TranslateUtils { public static > REP getReplyForRead(@Nonnull Future future, @Nonnull final InstanceIdentifier replyType) - throws VppBaseCallException, ReadTimeoutException { + throws VppBaseCallException, ReadTimeoutException { return getReplyForRead(future, replyType, DEFAULT_TIMEOUT_IN_SECONDS); } public static > REP getReplyForRead(@Nonnull Future future, @Nonnull final InstanceIdentifier replyType, @Nonnegative final int timeoutInSeconds) - throws VppBaseCallException, ReadTimeoutException { + throws VppBaseCallException, ReadTimeoutException { try { return getReply(future, timeoutInSeconds); } catch (TimeoutException e) { @@ -92,13 +92,13 @@ public final class TranslateUtils { } public static > REP getReply(@Nonnull Future future) - throws TimeoutException, VppBaseCallException { + throws TimeoutException, VppBaseCallException { return getReply(future, DEFAULT_TIMEOUT_IN_SECONDS); } public static > REP getReply(@Nonnull Future future, @Nonnegative final int timeoutInSeconds) - throws TimeoutException, VppBaseCallException { + throws TimeoutException, VppBaseCallException { try { checkArgument(timeoutInSeconds > 0, "Timeout cannot be < 0"); return future.get(timeoutInSeconds, TimeUnit.SECONDS); @@ -195,19 +195,19 @@ public final class TranslateUtils { //splits address and add ommited zeros for easier parsing List segments = Arrays.asList(ipv6Addr.getValue().split(":")) .stream() - .map(segment -> StringUtils.repeat('0',4-segment.length())+segment) + .map(segment -> StringUtils.repeat('0', 4 - segment.length()) + segment) .collect(Collectors.toList()); byte index = 0; for (String segment : segments) { - String firstPart =segment.substring(0, 2); + String firstPart = segment.substring(0, 2); String secondPart = segment.substring(2); //first part should be ommited - if("00".equals(firstPart)){ + if ("00".equals(firstPart)) { index++; - }else{ + } else { retval[index++] = ((byte) Short.parseShort(firstPart, 16)); } @@ -312,16 +312,16 @@ public final class TranslateUtils { /** * Converts MAC string to byte array - * */ - public static byte[] macToByteArray(String mac){ - checkNotNull(mac,"MAC cannot be null"); + */ + public static byte[] macToByteArray(String mac) { + checkNotNull(mac, "MAC cannot be null"); - mac = mac.replace(":",""); + mac = mac.replace(":", ""); try { return Hex.decodeHex(mac.toCharArray()); } catch (DecoderException e) { - throw new IllegalArgumentException("Unable to convert mac",e); + throw new IllegalArgumentException("Unable to convert mac", e); } } @@ -331,7 +331,7 @@ public final class TranslateUtils { public static boolean isIpv6(IpAddress address) { checkNotNull(address, "Address cannot be null"); - checkState(!(address.getIpv4Address() == null && address.getIpv6Address() == null), "Invalid address"); + checkState(!(address.getIpv4Address() == null && address.getIpv6Address() == null), "Invalid address"); return address.getIpv6Address() != null; } @@ -431,19 +431,19 @@ public final class TranslateUtils { private static byte[] parseMacLikeString(final List strings) { return strings.stream().limit(6).map(TranslateUtils::parseHexByte).collect( - () -> new byte[strings.size()], - new BiConsumer() { + () -> new byte[strings.size()], + new BiConsumer() { - private int i = -1; + private int i = -1; - @Override - public void accept(final byte[] bytes, final Byte aByte) { - bytes[++i] = aByte; - } - }, - (bytes, bytes2) -> { - throw new UnsupportedOperationException("Parallel collect not supported"); - }); + @Override + public void accept(final byte[] bytes, final Byte aByte) { + bytes[++i] = aByte; + } + }, + (bytes, bytes2) -> { + throw new UnsupportedOperationException("Parallel collect not supported"); + }); } public static byte parseHexByte(final String aByte) { @@ -458,8 +458,8 @@ public final class TranslateUtils { */ public static byte booleanToByte(@Nullable final Boolean value) { return value != null && value - ? (byte) 1 - : (byte) 0; + ? (byte) 1 + : (byte) 0; } /** @@ -494,4 +494,9 @@ public final class TranslateUtils { return reversed; } + + public static IpAddress reverseAddress(@Nonnull final IpAddress address) { + //arrayToIpAdddress internaly reverts order + return arrayToIpAddress(isIpv6(address), ipAddressToArray(address)); + } } -- cgit 1.2.3-korg