From 92545c9dee0fb78c0fdd8a68c4c14cf9306e0d9a Mon Sep 17 00:00:00 2001 From: Jozef Gloncak Date: Thu, 28 May 2015 11:20:40 +0200 Subject: [PATCH] Minor changes in LibLLDP - change modifier of emptyTLV field to final - added cisco header to CustomTLVKey class - formatting CustomTlvKey and LLDPTest classes Change-Id: Ic347f549fb3ba3a97e9b6f02883445c852cd3eb8 Signed-off-by: Jozef Gloncak (cherry picked from commit 1bdead40997cbe805630fced64c93e328a354275) --- .../controller/liblldp/CustomTLVKey.java | 9 +++- .../opendaylight/controller/liblldp/LLDP.java | 2 +- .../controller/liblldp/LLDPTest.java | 49 ++++++++----------- 3 files changed, 29 insertions(+), 31 deletions(-) diff --git a/opendaylight/commons/liblldp/src/main/java/org/opendaylight/controller/liblldp/CustomTLVKey.java b/opendaylight/commons/liblldp/src/main/java/org/opendaylight/controller/liblldp/CustomTLVKey.java index 7bc631e5a6..9953c7e665 100644 --- a/opendaylight/commons/liblldp/src/main/java/org/opendaylight/controller/liblldp/CustomTLVKey.java +++ b/opendaylight/commons/liblldp/src/main/java/org/opendaylight/controller/liblldp/CustomTLVKey.java @@ -1,6 +1,11 @@ -/** +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html */ + package org.opendaylight.controller.liblldp; public class CustomTLVKey { @@ -23,6 +28,7 @@ public class CustomTLVKey { public int getOui() { return oui; } + /** * @return the subtype */ @@ -65,5 +71,4 @@ public class CustomTLVKey { return true; } - } diff --git a/opendaylight/commons/liblldp/src/main/java/org/opendaylight/controller/liblldp/LLDP.java b/opendaylight/commons/liblldp/src/main/java/org/opendaylight/controller/liblldp/LLDP.java index 85b2cbf82e..15dced5f11 100644 --- a/opendaylight/commons/liblldp/src/main/java/org/opendaylight/controller/liblldp/LLDP.java +++ b/opendaylight/commons/liblldp/src/main/java/org/opendaylight/controller/liblldp/LLDP.java @@ -23,7 +23,7 @@ public class LLDP extends Packet { private static final String PORTID = "PortId"; private static final String TTL = "TTL"; private static final int LLDPDefaultTlvs = 3; - private static LLDPTLV emptyTLV = new LLDPTLV().setLength((short) 0).setType((byte) 0); + private static final LLDPTLV emptyTLV = new LLDPTLV().setLength((short) 0).setType((byte) 0); public static final byte[] LLDPMulticastMac = { 1, (byte) 0x80, (byte) 0xc2, 0, 0, (byte) 0xe }; private Map mandatoryTLVs; diff --git a/opendaylight/commons/liblldp/src/test/java/org/opendaylight/controller/liblldp/LLDPTest.java b/opendaylight/commons/liblldp/src/test/java/org/opendaylight/controller/liblldp/LLDPTest.java index 8bd700875a..7d27d80d52 100644 --- a/opendaylight/commons/liblldp/src/test/java/org/opendaylight/controller/liblldp/LLDPTest.java +++ b/opendaylight/commons/liblldp/src/test/java/org/opendaylight/controller/liblldp/LLDPTest.java @@ -101,16 +101,13 @@ public class LLDPTest { offset = checkTLV(serialized, offset, (byte) 0b00000010, "ChassisID", CHASSIS_ID_LENGTH, CHASSIS_ID_VALUE); offset = checkTLV(serialized, offset, (byte) 0b00000110, "TTL", TTL_LENGTH, TTL_VALUE); offset = checkTLV(serialized, offset, (byte) 0b00000100, "PortID", PORT_LENGTH, PORT_VALUE); - offset = checkTLV(serialized, offset, (byte) 0b00001010, "SystemName", SYSTEM_NAME_LENGTH, - SYSTEM_NAME_VALUE); - offset = checkTLV(serialized, offset, (byte) 0b00010000, "System capabilities", - SYSTEM_CAPABILITIES_LENGTH, SYSTEM_CAPABILITIES_VALUE); - offset = checkTLV(serialized, offset, (byte) 0b11111110, "Custom subtype A", - CUSTOM_SUBTYPE_A_LENGTH, CUSTOM_SUBTYPE_A_VALUE, OUI[0], OUI[1], OUI[2], - OUI_SUBTYPE_A[0]); - offset = checkTLV(serialized, offset, (byte) 0b11111110, "Custom subtype B", - CUSTOM_SUBTYPE_B_LENGTH, CUSTOM_SUBTYPE_B_VALUE, OUI[0], OUI[1], OUI[2], - OUI_SUBTYPE_B[0]); + offset = checkTLV(serialized, offset, (byte) 0b00001010, "SystemName", SYSTEM_NAME_LENGTH, SYSTEM_NAME_VALUE); + offset = checkTLV(serialized, offset, (byte) 0b00010000, "System capabilities", SYSTEM_CAPABILITIES_LENGTH, + SYSTEM_CAPABILITIES_VALUE); + offset = checkTLV(serialized, offset, (byte) 0b11111110, "Custom subtype A", CUSTOM_SUBTYPE_A_LENGTH, + CUSTOM_SUBTYPE_A_VALUE, OUI[0], OUI[1], OUI[2], OUI_SUBTYPE_A[0]); + offset = checkTLV(serialized, offset, (byte) 0b11111110, "Custom subtype B", CUSTOM_SUBTYPE_B_LENGTH, + CUSTOM_SUBTYPE_B_VALUE, OUI[0], OUI[1], OUI[2], OUI_SUBTYPE_B[0]); } @@ -123,17 +120,16 @@ public class LLDPTest { @Test public void testDeserialize() throws Exception { - byte[] rawLldpTlv = Bytes.concat( - awaitedBytes((byte) 0b00000010, CHASSIS_ID_LENGTH, CHASSIS_ID_VALUE, null), - awaitedBytes((byte) 0b00000110, TTL_LENGTH, TTL_VALUE, null), - awaitedBytes((byte) 0b00000100, PORT_LENGTH, PORT_VALUE, null), - awaitedBytes((byte) 0b00001010, SYSTEM_NAME_LENGTH, SYSTEM_NAME_VALUE, null), - awaitedBytes((byte) 0b00010010, SYSTEM_CAPABILITIES_LENGTH, - SYSTEM_CAPABILITIES_VALUE, null), - awaitedBytes((byte) 0b11111110, CUSTOM_SUBTYPE_A_LENGTH, CUSTOM_SUBTYPE_A_VALUE, - BYTES_BEFORE_CUSTOM_A), - awaitedBytes((byte) 0b11111110, CUSTOM_SUBTYPE_B_LENGTH, CUSTOM_SUBTYPE_B_VALUE, - BYTES_BEFORE_CUSTOM_B)); + byte[] rawLldpTlv = Bytes + .concat(awaitedBytes((byte) 0b00000010, CHASSIS_ID_LENGTH, CHASSIS_ID_VALUE, null), + awaitedBytes((byte) 0b00000110, TTL_LENGTH, TTL_VALUE, null), + awaitedBytes((byte) 0b00000100, PORT_LENGTH, PORT_VALUE, null), + awaitedBytes((byte) 0b00001010, SYSTEM_NAME_LENGTH, SYSTEM_NAME_VALUE, null), + awaitedBytes((byte) 0b00010010, SYSTEM_CAPABILITIES_LENGTH, SYSTEM_CAPABILITIES_VALUE, null), + awaitedBytes((byte) 0b11111110, CUSTOM_SUBTYPE_A_LENGTH, CUSTOM_SUBTYPE_A_VALUE, + BYTES_BEFORE_CUSTOM_A), + awaitedBytes((byte) 0b11111110, CUSTOM_SUBTYPE_B_LENGTH, CUSTOM_SUBTYPE_B_VALUE, + BYTES_BEFORE_CUSTOM_B)); lldpBuilder.deserialize(rawLldpTlv, 0, rawLldpTlv.length * NetUtils.NumBitsInAByte); Assert.assertEquals("chassis", new String(lldpBuilder.getChassisId().getValue())); @@ -168,6 +164,7 @@ public class LLDPTest { /** * Test of {@link LLDP#addCustomTLV(LLDPTLV)} + * * @throws PacketException */ @Test @@ -218,15 +215,11 @@ public class LLDPTest { Assert.assertEquals(127, customItem.getType()); LOG.debug("custom TLV1.length: {}", customItem.getLength()); Assert.assertEquals(expectedValue, - new String( - LLDPTLV.getCustomString( - customItem.getValue(), - customItem.getLength())) - ); + new String(LLDPTLV.getCustomString(customItem.getValue(), customItem.getLength()))); } - private static int checkTLV(byte[] serializedData, int offset, byte typeTLVBits, String typeTLVName, short lengthTLV, - byte[] valueTLV, byte... bytesBeforeValue) throws ArrayComparisonFailure { + private static int checkTLV(byte[] serializedData, int offset, byte typeTLVBits, String typeTLVName, + short lengthTLV, byte[] valueTLV, byte... bytesBeforeValue) throws ArrayComparisonFailure { byte[] concreteTlvAwaited = awaitedBytes(typeTLVBits, lengthTLV, valueTLV, bytesBeforeValue); int concreteTlvAwaitLength = concreteTlvAwaited.length; assertArrayEquals("Serialization problem " + typeTLVName, concreteTlvAwaited, -- 2.36.6