Hc2vpp supports 48-bit addresses.
VPP returns 64-bits, so ignore extended part.
This patch updates MAC address handling broken by
https://gerrit.fd.io/r/#/c/9090/
Change-Id: I7cc8d75e19f1f56e1f1adc23848a4a9baef87206
Signed-off-by: Marek Gradzki <[email protected]>
final int endIndex = PHYSICAL_ADDRESS_LENGTH;
checkArgument(endIndex <= vppPhysAddress.length,
"Invalid physical address size (%s), expected >= %s", vppPhysAddress.length, endIndex);
- return printHexBinary(vppPhysAddress);
+ // Extended (64-bit) MAC addresses are currently not supported , so use first 48-bits.
+ // Adding support for extended MAC addresses might require yang model change.
+ // Also VPP is not consistent (e.g. for TAP it allows to configure MAC of 6 bytes, but sw_interface_details
+ // contains 8 bytes.
+ return printHexBinary(vppPhysAddress, 0, PHYSICAL_ADDRESS_LENGTH);
}
/**
@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}));
+ // Extended (64-bit) MAC addresses are currently not supported (it might require yang model update),
+ // so test if extended part is ignored
+ assertEquals("0a:0b:0c:0d:0e:0f", vppPhysAddrToYang(new byte[]{0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0, 0}));
}
@Test(expected = NullPointerException.class)
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[0]);
- for (int i = 1; i < bytes.length; i++) {
+ Impl.appendHexByte(str, bytes[startIndex]);
+ for (int i = startIndex + 1; i < endIndex; i++) {
str.append(":");
Impl.appendHexByte(str, bytes[i]);
}