summaryrefslogtreecommitdiffstats
path: root/v3po/v3po2vpp/src/main/java/io
diff options
context:
space:
mode:
authorMarek Gradzki <mgradzki@cisco.com>2016-05-05 15:00:50 +0200
committerMarek Gradzki <mgradzki@cisco.com>2016-05-06 07:19:10 +0200
commitac5c0256f9b96deda69da1d250d55c5d00b83046 (patch)
tree2afaff7f678c0372454165dc29827bc52eaff694 /v3po/v3po2vpp/src/main/java/io
parentca361fd5bfe881014d0791fd9c3b13b66a2d13b2 (diff)
Fix physical address parsing
Change-Id: Ib5fedab56d9bef556fc13f28a266004d2e5d73a6 Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
Diffstat (limited to 'v3po/v3po2vpp/src/main/java/io')
-rw-r--r--v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/InterfaceUtils.java24
1 files changed, 17 insertions, 7 deletions
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/InterfaceUtils.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/InterfaceUtils.java
index 979c9d6bd..691b95f98 100644
--- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/InterfaceUtils.java
+++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/InterfaceUtils.java
@@ -19,6 +19,7 @@ package io.fd.honeycomb.v3po.translate.v3po.interfacesstate;
import com.google.common.base.Preconditions;
import com.google.common.collect.Iterables;
import java.math.BigInteger;
+import java.util.Objects;
import java.util.concurrent.ExecutionException;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@@ -31,7 +32,7 @@ import org.openvpp.jvpp.future.FutureJVpp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class InterfaceUtils {
+public final class InterfaceUtils {
private static final Logger LOG = LoggerFactory.getLogger(InterfaceUtils.class);
private static final Gauge64 vppLinkSpeed0 = new Gauge64(BigInteger.ZERO);
@@ -44,6 +45,12 @@ public class InterfaceUtils {
private static final char[] HEX_CHARS = "0123456789abcdef".toCharArray();
+ private static final int PHYSICAL_ADDRESS_LENGTH = 6;
+
+ private InterfaceUtils() {
+ throw new UnsupportedOperationException("This utility class cannot be instantiated");
+ }
+
/**
* Convert VPP's link speed bitmask to Yang type. 1 = 10M, 2 = 100M, 4 = 1G, 8 = 10G, 16 = 40G, 32 = 100G
*
@@ -76,21 +83,24 @@ public class InterfaceUtils {
}
/**
- * Convert VPP's physical address stored byte array format to string as Yang dictates <p> Replace later with
+ * Reads first 6 bytes of supplied byte array and converts to string as Yang dictates
+ * <p> Replace later with
* https://git.opendaylight.org/gerrit/#/c/34869/10/model/ietf/ietf-type- util/src/main/
* java/org/opendaylight/mdsal/model/ietf/util/AbstractIetfYangUtil.java
*
- * @param vppPhysAddress byte array of bytes constructing the network IF physical address.
+ * @param vppPhysAddress byte array of bytes in big endian order, constructing the network IF physical address.
* @return String like "aa:bb:cc:dd:ee:ff"
+ * @throws NullPointerException if vppPhysAddress is null
+ * @throws IllegalArgumentException if vppPhysAddress.length < 6
*/
public static String vppPhysAddrToYang(@Nonnull final byte[] vppPhysAddress) {
- Preconditions.checkNotNull(vppPhysAddress, "Empty physicall address bytes");
- Preconditions.checkArgument(vppPhysAddress.length == 6, "Invalid physical address size %s, expected 6",
- vppPhysAddress.length);
+ Objects.requireNonNull(vppPhysAddress, "Empty physical address bytes");
+ Preconditions.checkArgument(PHYSICAL_ADDRESS_LENGTH <= vppPhysAddress.length,
+ "Invalid physical address size %s, expected >= 6", vppPhysAddress.length);
StringBuilder physAddr = new StringBuilder();
appendHexByte(physAddr, vppPhysAddress[0]);
- for (int i = 1; i < vppPhysAddress.length; i++) {
+ for (int i=1; i < PHYSICAL_ADDRESS_LENGTH; i++) {
physAddr.append(":");
appendHexByte(physAddr, vppPhysAddress[i]);
}