summaryrefslogtreecommitdiffstats
path: root/vpp-common
diff options
context:
space:
mode:
authorJan Srnicek <jsrnicek@cisco.com>2016-09-21 15:02:12 +0200
committerMaros Marsalek <mmarsale@cisco.com>2016-09-21 13:38:13 +0000
commit9f7328169d65529de3fb1ed75872a081e4dc2184 (patch)
treebf556f170aadedba740dc1eee58441e21725bbe5 /vpp-common
parent5cfbc703cbf0183b76fb9d8157ffb860f429ec26 (diff)
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 <jsrnicek@cisco.com>
Diffstat (limited to 'vpp-common')
-rw-r--r--vpp-common/vpp-translate-utils/src/main/java/io/fd/honeycomb/translate/v3po/util/TranslateUtils.java63
-rw-r--r--vpp-common/vpp-translate-utils/src/test/java/io/fd/honeycomb/translate/v3po/util/TranslateUtilsTest.java33
2 files changed, 57 insertions, 39 deletions
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 extends JVppReply<?>> REP getReplyForWrite(@Nonnull Future<REP> future,
@Nonnull final InstanceIdentifier<?> replyType)
- throws VppBaseCallException, WriteTimeoutException {
+ throws VppBaseCallException, WriteTimeoutException {
return getReplyForWrite(future, replyType, DEFAULT_TIMEOUT_IN_SECONDS);
}
public static <REP extends JVppReply<?>> REP getReplyForWrite(@Nonnull Future<REP> 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 extends JVppReply<?>> REP getReplyForRead(@Nonnull Future<REP> future,
@Nonnull final InstanceIdentifier<?> replyType)
- throws VppBaseCallException, ReadTimeoutException {
+ throws VppBaseCallException, ReadTimeoutException {
return getReplyForRead(future, replyType, DEFAULT_TIMEOUT_IN_SECONDS);
}
public static <REP extends JVppReply<?>> REP getReplyForRead(@Nonnull Future<REP> 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 extends JVppReply<?>> REP getReply(@Nonnull Future<REP> future)
- throws TimeoutException, VppBaseCallException {
+ throws TimeoutException, VppBaseCallException {
return getReply(future, DEFAULT_TIMEOUT_IN_SECONDS);
}
public static <REP extends JVppReply<?>> REP getReply(@Nonnull Future<REP> 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<String> 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<String> strings) {
return strings.stream().limit(6).map(TranslateUtils::parseHexByte).collect(
- () -> new byte[strings.size()],
- new BiConsumer<byte[], Byte>() {
+ () -> new byte[strings.size()],
+ new BiConsumer<byte[], Byte>() {
- 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));
+ }
}
diff --git a/vpp-common/vpp-translate-utils/src/test/java/io/fd/honeycomb/translate/v3po/util/TranslateUtilsTest.java b/vpp-common/vpp-translate-utils/src/test/java/io/fd/honeycomb/translate/v3po/util/TranslateUtilsTest.java
index a55c3053a..3b7efbfc5 100644
--- a/vpp-common/vpp-translate-utils/src/test/java/io/fd/honeycomb/translate/v3po/util/TranslateUtilsTest.java
+++ b/vpp-common/vpp-translate-utils/src/test/java/io/fd/honeycomb/translate/v3po/util/TranslateUtilsTest.java
@@ -1,5 +1,6 @@
package io.fd.honeycomb.translate.v3po.util;
+import static io.fd.honeycomb.translate.v3po.util.TranslateUtils.reverseAddress;
import static io.fd.honeycomb.translate.v3po.util.TranslateUtils.reverseBytes;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
@@ -14,8 +15,11 @@ import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
+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;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6AddressNoZone;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
import org.opendaylight.yangtools.yang.binding.DataContainer;
@@ -66,7 +70,7 @@ public class TranslateUtilsTest {
public void testIpv4NoZone() throws Exception {
final Ipv4AddressNoZone ipv4Addr = new Ipv4AddressNoZone("192.168.1.1");
byte[] bytes = TranslateUtils.ipv4AddressNoZoneToArray(ipv4Addr);
- assertEquals((byte)192, bytes[0]);
+ assertEquals((byte) 192, bytes[0]);
// Simulating the magic of VPP
bytes = reverseBytes(bytes);
final Ipv4AddressNoZone ipv4AddressNoZone = TranslateUtils.arrayToIpv4AddressNoZone(bytes);
@@ -138,37 +142,37 @@ public class TranslateUtilsTest {
}
@Test
- public void testIpv6NoZone(){
+ public void testIpv6NoZone() {
final Ipv6AddressNoZone ipv6Addr = new Ipv6AddressNoZone("3ffe:1900:4545:3:200:f8ff:fe21:67cf");
byte[] bytes = TranslateUtils.ipv6AddressNoZoneToArray(ipv6Addr);
- assertEquals((byte)63,bytes[0]);
+ assertEquals((byte) 63, bytes[0]);
bytes = reverseBytes(bytes);
final Ipv6AddressNoZone ivp6AddressNoZone = TranslateUtils.arrayToIpv6AddressNoZone(bytes);
- assertEquals(ipv6Addr,ivp6AddressNoZone);
+ assertEquals(ipv6Addr, ivp6AddressNoZone);
}
@Test
- public void testByteArrayToMacUnseparated(){
+ public void testByteArrayToMacUnseparated() {
byte[] address = TranslateUtils.parseMac("aa:bb:cc:dd:ee:ff");
String converted = TranslateUtils.byteArrayToMacUnseparated(address);
- assertEquals("aabbccddeeff",converted);
+ assertEquals("aabbccddeeff", converted);
}
@Test
- public void testByteArrayToMacSeparated(){
+ public void testByteArrayToMacSeparated() {
byte[] address = TranslateUtils.parseMac("aa:bb:cc:dd:ee:ff");
String converted = TranslateUtils.byteArrayToMacSeparated(address);
- assertEquals("aa:bb:cc:dd:ee:ff",converted);
+ assertEquals("aa:bb:cc:dd:ee:ff", converted);
}
@Test(expected = IllegalArgumentException.class)
- public void testByteArrayToMacUnseparatedIllegal(){
- TranslateUtils.byteArrayToMacUnseparated(new byte[]{54,26,87,32,14});
+ public void testByteArrayToMacUnseparatedIllegal() {
+ TranslateUtils.byteArrayToMacUnseparated(new byte[]{54, 26, 87, 32, 14});
}
@Test(expected = IllegalArgumentException.class)
@@ -195,4 +199,13 @@ public class TranslateUtilsTest {
assertEquals(24, TranslateUtils.extractPrefix(new Ipv4Prefix("192.168.2.1/24")));
assertEquals(48, TranslateUtils.extractPrefix(new Ipv6Prefix("3ffe:1900:4545:3:200:f8ff:fe21:67cf/48")));
}
+
+ @Test
+ public void testRevertAddress() {
+ assertEquals("1.2.168.192",
+ reverseAddress(new IpAddress(new Ipv4Address("192.168.2.1"))).getIpv4Address().getValue());
+ assertEquals("3473:7003:2e8a::a385:b80d:120",
+ reverseAddress(new IpAddress(new Ipv6Address("2001:db8:85a3:0:0:8a2e:370:7334"))).getIpv6Address()
+ .getValue());
+ }
} \ No newline at end of file