Adapt to mac address representation change in l2.api 31/9131/3
authorMarek Gradzki <[email protected]>
Tue, 31 Oct 2017 07:50:10 +0000 (08:50 +0100)
committerMarek Gradzki <[email protected]>
Tue, 31 Oct 2017 16:58:35 +0000 (16:58 +0000)
https://gerrit.fd.io/r/#/c/9090/ changes mac representation
from u64 to u8[]

Change-Id: Ia82d5652926f8bd10c1c8fc3ad0e147b35dbee4c
Signed-off-by: Marek Gradzki <[email protected]>
v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceDataTranslator.java
v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/l2/L2FibEntryCustomizer.java
v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/l2state/L2FibEntryCustomizer.java
v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfacesstate/InterfaceDataTranslatorTest.java
v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2/L2FibEntryCustomizerTest.java
v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/l2state/L2FibEntryCustomizerTest.java
vpp-common/vpp-translate-utils/src/main/java/io/fd/hc2vpp/common/translate/util/ByteDataTranslator.java

index ec47ee2..01adefe 100644 (file)
@@ -95,16 +95,11 @@ public interface InterfaceDataTranslator extends ByteDataTranslator, JvppReplyCo
      * @throws IllegalArgumentException if vppPhysAddress.length < 6
      */
     default String vppPhysAddrToYang(@Nonnull final byte[] vppPhysAddress) {
-        return vppPhysAddrToYang(vppPhysAddress, 0);
-    }
-
-    default String vppPhysAddrToYang(@Nonnull final byte[] vppPhysAddress, final int startIndex) {
         Objects.requireNonNull(vppPhysAddress, "Empty physical address bytes");
-        final int endIndex = startIndex + PHYSICAL_ADDRESS_LENGTH;
+        final int endIndex = PHYSICAL_ADDRESS_LENGTH;
         checkArgument(endIndex <= vppPhysAddress.length,
-                "Invalid physical address size (%s) for given startIndex (%s), expected >= %s", vppPhysAddress.length,
-                startIndex, endIndex);
-        return printHexBinary(vppPhysAddress, startIndex, endIndex);
+                "Invalid physical address size (%s), expected >= %s", vppPhysAddress.length, endIndex);
+        return printHexBinary(vppPhysAddress);
     }
 
     /**
index 1b5248f..8f29aed 100644 (file)
@@ -19,7 +19,6 @@ package io.fd.hc2vpp.v3po.l2;
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkNotNull;
 
-import com.google.common.primitives.Longs;
 import io.fd.hc2vpp.common.translate.util.ByteDataTranslator;
 import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer;
 import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer;
@@ -114,7 +113,7 @@ public class L2FibEntryCustomizer extends FutureJVppCustomizer
 
     private L2FibAddDel createL2FibRequest(final L2FibEntry entry, final int bdId, final int swIfIndex, boolean isAdd) {
         final L2FibAddDel request = new L2FibAddDel();
-        request.mac = macToLong(entry.getPhysAddress().getValue());
+        request.mac = parseMac(entry.getPhysAddress().getValue());
         request.bdId = bdId;
         request.swIfIndex = swIfIndex;
         request.isAdd = booleanToByte(isAdd);
@@ -124,12 +123,4 @@ public class L2FibEntryCustomizer extends FutureJVppCustomizer
         }
         return request;
     }
-
-    // mac address is string of the form: 11:22:33:44:55:66
-    // but VPP expects long value in the format 11:22:33:44:55:66:XX:XX
-    private long macToLong(final String macAddress) {
-        final byte[] mac = parseMac(macAddress);
-        return Longs.fromBytes(mac[0], mac[1], mac[2], mac[3],
-                mac[4], mac[5], (byte) 0, (byte) 0);
-    }
 }
index 61780f5..e552ce8 100644 (file)
@@ -17,7 +17,6 @@
 package io.fd.hc2vpp.v3po.l2state;
 
 import com.google.common.base.Preconditions;
-import com.google.common.primitives.Longs;
 import io.fd.hc2vpp.common.translate.util.ByteDataTranslator;
 import io.fd.hc2vpp.common.translate.util.FutureJVppCustomizer;
 import io.fd.hc2vpp.common.translate.util.NamingContext;
@@ -85,7 +84,7 @@ public final class L2FibEntryCustomizer extends FutureJVppCustomizer
         try {
             // TODO HONEYCOMB-186 use cached l2FibTable
             final L2FibTableDetails entry = dumpL2Fibs(id, bdId).stream().filter(e -> key.getPhysAddress()
-                    .equals(new PhysAddress(vppPhysAddrToYang(Longs.toByteArray(e.mac), 2))))
+                    .equals(new PhysAddress(vppPhysAddrToYang((e.mac)))))
                     .collect(SINGLE_ITEM_COLLECTOR);
 
             builder.setAction(byteToBoolean(entry.filterMac)
@@ -131,8 +130,7 @@ public final class L2FibEntryCustomizer extends FutureJVppCustomizer
 
         LOG.debug("Reading L2 FIB for bridge domain {} (bdId={})", bridgeDomainKey, bdId);
         return dumpL2Fibs(id, bdId).stream()
-                .map(entry -> new L2FibEntryKey(
-                        new PhysAddress(vppPhysAddrToYang(Longs.toByteArray(entry.mac), 2))))
+                .map(entry -> new L2FibEntryKey(new PhysAddress(vppPhysAddrToYang(entry.mac))))
                 .collect(Collectors.toList());
     }
 
index 40bb6b9..c584097 100644 (file)
@@ -30,7 +30,7 @@ public class InterfaceDataTranslatorTest implements InterfaceDataTranslator {
     @Test
     public void testVppPhysAddrToYang() throws Exception {
         assertEquals("01:02:03:04:05:06", vppPhysAddrToYang(new byte[]{1, 2, 3, 4, 5, 6}));
-        assertEquals("0a:0b:0c:0d:0e:0f", vppPhysAddrToYang(new byte[]{0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0, 0}));
+        assertEquals("0a:0b:0c:0d:0e:0f", vppPhysAddrToYang(new byte[]{0xa, 0xb, 0xc, 0xd, 0xe, 0xf}));
     }
 
     @Test(expected = NullPointerException.class)
index 2b09650..54faa9a 100644 (file)
@@ -16,6 +16,7 @@
 
 package io.fd.hc2vpp.v3po.l2;
 
+import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
@@ -81,7 +82,7 @@ public class L2FibEntryCustomizerTest extends WriterCustomizerTest {
         doReturn(failedFuture()).when(api).l2FibAddDel(any(L2FibAddDel.class));
     }
 
-    private L2FibAddDel generateL2FibAddDelFilterRequest(final long mac, final byte isAdd, final int ifaceIndex) {
+    private L2FibAddDel generateL2FibAddDelFilterRequest(final byte[] mac, final byte isAdd, final int ifaceIndex) {
         final L2FibAddDel request = new L2FibAddDel();
         request.mac = mac;
         request.bdId = BD_ID;
@@ -94,7 +95,7 @@ public class L2FibEntryCustomizerTest extends WriterCustomizerTest {
         return request;
     }
 
-    private L2FibAddDel generateL2FibAddDelForwardRequest(final long mac, final byte isAdd, final int ifaceIndex) {
+    private L2FibAddDel generateL2FibAddDelForwardRequest(final byte[] mac, final byte isAdd, final int ifaceIndex) {
         final L2FibAddDel request = new L2FibAddDel();
         request.mac = mac;
         request.bdId = BD_ID;
@@ -134,7 +135,7 @@ public class L2FibEntryCustomizerTest extends WriterCustomizerTest {
         ArgumentCaptor<L2FibAddDel> argumentCaptor = ArgumentCaptor.forClass(L2FibAddDel.class);
         verify(api).l2FibAddDel(argumentCaptor.capture());
         final L2FibAddDel actual = argumentCaptor.getValue();
-        assertEquals(expected.mac, actual.mac);
+        assertArrayEquals(expected.mac, actual.mac);
         assertEquals(expected.bdId, actual.bdId);
         assertEquals(expected.swIfIndex, actual.swIfIndex);
         assertEquals(expected.isAdd, actual.isAdd);
@@ -144,7 +145,7 @@ public class L2FibEntryCustomizerTest extends WriterCustomizerTest {
 
     @Test
     public void testCreateFilter() throws Exception {
-        final long address_vpp = 0x0102030405060000L;
+        final byte[] address_vpp = new byte[]{1, 2, 3, 4, 5, 6};
         final PhysAddress address = new PhysAddress("01:02:03:04:05:06");
         final L2FibEntry entry = generateL2FibFilterEntry(address);
         final InstanceIdentifier<L2FibEntry> id = getL2FibEntryId(address);
@@ -158,7 +159,7 @@ public class L2FibEntryCustomizerTest extends WriterCustomizerTest {
 
     @Test
     public void testCreateForward() throws Exception {
-        final long address_vpp = 0x0102030405060000L;
+        final byte[] address_vpp = new byte[]{1, 2, 3, 4, 5, 6};
         final PhysAddress address = new PhysAddress("01:02:03:04:05:06");
         final L2FibEntry entry = generateL2FibForwardEntry(address);
         final InstanceIdentifier<L2FibEntry> id = getL2FibEntryId(address);
@@ -172,7 +173,7 @@ public class L2FibEntryCustomizerTest extends WriterCustomizerTest {
 
     @Test
     public void testCreateFilterFailed() throws Exception {
-        final long address_vpp = 0x1122334455660000L;
+        final byte[] address_vpp = new byte[]{0x11, 0x22 ,0x33, 0x44 ,0x55, 0x66};
         final PhysAddress address = new PhysAddress("11:22:33:44:55:66");
         final L2FibEntry entry = generateL2FibFilterEntry(address);
         final InstanceIdentifier<L2FibEntry> id = getL2FibEntryId(address);
@@ -191,7 +192,7 @@ public class L2FibEntryCustomizerTest extends WriterCustomizerTest {
 
     @Test
     public void testCreateForwardFailed() throws Exception {
-        final long address_vpp = 0x1122334455660000L;
+        final byte[] address_vpp = new byte[]{0x11, 0x22 ,0x33, 0x44 ,0x55, 0x66};
         final PhysAddress address = new PhysAddress("11:22:33:44:55:66");
         final L2FibEntry entry = generateL2FibForwardEntry(address);
         final InstanceIdentifier<L2FibEntry> id = getL2FibEntryId(address);
@@ -216,7 +217,7 @@ public class L2FibEntryCustomizerTest extends WriterCustomizerTest {
 
     @Test
     public void testDeleteFilter() throws Exception {
-        final long address_vpp = 0x1122334455660000L;
+        final byte[] address_vpp = new byte[]{0x11, 0x22 ,0x33, 0x44 ,0x55, 0x66};
         final PhysAddress address = new PhysAddress("11:22:33:44:55:66");
         final L2FibEntry entry = generateL2FibFilterEntry(address);
         final InstanceIdentifier<L2FibEntry> id = getL2FibEntryId(address);
@@ -230,7 +231,7 @@ public class L2FibEntryCustomizerTest extends WriterCustomizerTest {
 
     @Test
     public void testDeleteForward() throws Exception {
-        final long address_vpp = 0x1122334455660000L;
+        final byte[] address_vpp = new byte[]{0x11, 0x22 ,0x33, 0x44 ,0x55, 0x66};
         final PhysAddress address = new PhysAddress("11:22:33:44:55:66");
         final L2FibEntry entry = generateL2FibForwardEntry(address);
         final InstanceIdentifier<L2FibEntry> id = getL2FibEntryId(address);
@@ -245,7 +246,7 @@ public class L2FibEntryCustomizerTest extends WriterCustomizerTest {
 
     @Test
     public void testDeleteFilterFailed() throws Exception {
-        final long address_vpp = 0x0102030405060000L;
+        final byte[] address_vpp = new byte[]{1, 2, 3, 4, 5, 6};
         final PhysAddress address = new PhysAddress("01:02:03:04:05:06");
         final L2FibEntry entry = generateL2FibFilterEntry(address);
         final InstanceIdentifier<L2FibEntry> id = getL2FibEntryId(address);
@@ -264,7 +265,7 @@ public class L2FibEntryCustomizerTest extends WriterCustomizerTest {
 
     @Test
     public void testDeleteForwardFailed() throws Exception {
-        final long address_vpp = 0x0102030405060000L;
+        final byte[] address_vpp = new byte[]{1, 2, 3, 4, 5, 6};
         final PhysAddress address = new PhysAddress("01:02:03:04:05:06");
         final L2FibEntry entry = generateL2FibForwardEntry(address);
         final InstanceIdentifier<L2FibEntry> id = getL2FibEntryId(address);
index a8e200e..40dbe79 100644 (file)
@@ -86,7 +86,7 @@ public class L2FibEntryCustomizerTest extends ListReaderCustomizerTest<L2FibEntr
 
     @Test
     public void testRead() throws Exception {
-        final long address_vpp = 0x0000010203040506L;
+        final byte[] address_vpp = new byte[]{1, 2, 3, 4, 5, 6};
         final PhysAddress address = new PhysAddress("01:02:03:04:05:06");
         defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
 
@@ -103,7 +103,7 @@ public class L2FibEntryCustomizerTest extends ListReaderCustomizerTest<L2FibEntr
         verify(builder).setKey(new L2FibEntryKey(address));
     }
 
-    private L2FibTableDetails generateL2FibEntry(final long mac) {
+    private L2FibTableDetails generateL2FibEntry(final byte[] mac) {
         final L2FibTableDetails entry = new L2FibTableDetails();
         entry.mac = mac;
         entry.swIfIndex = IFACE_ID;
@@ -112,7 +112,7 @@ public class L2FibEntryCustomizerTest extends ListReaderCustomizerTest<L2FibEntr
 
     @Test
     public void testGetAllIds() throws Exception {
-        final long address_vpp = 0x0000112233445566L;
+        final byte[] address_vpp = new byte[]{0x11, 0x22, 0x33, 0x44, 0x55, 0x66};
         final PhysAddress address = new PhysAddress("11:22:33:44:55:66");
 
         whenL2FibTableDumpThenReturn(Collections.singletonList(generateL2FibEntry(address_vpp)));
index c7583fb..25b8d50 100644 (file)
@@ -100,14 +100,10 @@ public interface ByteDataTranslator {
 
     default String printHexBinary(@Nonnull final byte[] bytes) {
         Objects.requireNonNull(bytes, "bytes array should not be null");
-        return printHexBinary(bytes, 0, bytes.length);
-    }
-
-    default String printHexBinary(@Nonnull final byte[] bytes, final int startIndex, final int endIndex) {
         StringBuilder str = new StringBuilder();
 
-        Impl.appendHexByte(str, bytes[startIndex]);
-        for (int i = startIndex + 1; i < endIndex; i++) {
+        Impl.appendHexByte(str, bytes[0]);
+        for (int i = 1; i < bytes.length; i++) {
             str.append(":");
             Impl.appendHexByte(str, bytes[i]);
         }