2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.openflowplugin.libraries.liblldp;
10 import com.google.common.io.BaseEncoding;
11 import com.google.common.primitives.Bytes;
12 import org.junit.Assert;
13 import org.junit.Test;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
17 @SuppressWarnings("checkstyle:AbbreviationAsWordInName")
18 public class LLDPTLVTest {
20 /** dummy custom tlv value. */
21 private static final String CUSTOM_TLV_ULTIMATE = "What do you get when you multiply 6 by 9?";
22 /** dummy custom tlv value in binary form. */
23 private static final byte[] CUSTOM_TLV_ULTIMATE_BIN = new byte[] {
24 0x57, 0x68, 0x61, 0x74, 0x20, 0x64, 0x6f, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x67, 0x65, 0x74,
25 0x20, 0x77, 0x68, 0x65, 0x6e, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x6d, 0x75, 0x6c, 0x74, 0x69,
26 0x70, 0x6c, 0x79, 0x20, 0x36, 0x20, 0x62, 0x79, 0x20, 0x39, 0x3f
29 private static final Logger LOG = LoggerFactory.getLogger(LLDPTLVTest.class);
33 * {@link org.opendaylight.openflowplugin.libraries.liblldp.LLDPTLV#createCustomTLVValue(java.lang.String)}
37 public void testCreateCustomTLVValue() {
38 byte[] tlv = LLDPTLV.createCustomTLVValue(CUSTOM_TLV_ULTIMATE);
40 byte[] expectedCustomTlv = Bytes.concat(new byte[] {
41 // custom type (7b) + length (9b) = 16b = 2B (skipped)
44 0x00, 0x26, (byte) 0xe1,
48 CUSTOM_TLV_ULTIMATE_BIN);
50 BaseEncoding be = BaseEncoding.base16().withSeparator(" ", 2).lowerCase();
51 LOG.debug("expected: {}", be.encode(expectedCustomTlv));
52 LOG.debug("actual : {}", be.encode(tlv));
53 Assert.assertArrayEquals(expectedCustomTlv, tlv);
58 * {@link org.opendaylight.openflowplugin.libraries.liblldp.LLDPTLV#getCustomString(byte[], int)}.
61 public void testGetCustomString() {
62 byte[] inputCustomTlv = Bytes.concat(new byte[] {
63 // custom type (7b) + length (9b) = 16b = 2B (skipped)
66 0x00, 0x26, (byte) 0xe1,
70 CUSTOM_TLV_ULTIMATE_BIN);
72 String actual = LLDPTLV.getCustomString(inputCustomTlv, inputCustomTlv.length);
73 LOG.debug("actual custom TLV value as string: {}", actual);
74 Assert.assertEquals(CUSTOM_TLV_ULTIMATE, actual);