2 * Copyright (c) 2016 Pantheon Technologies s.r.o. 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
9 package org.opendaylight.openflowplugin.applications.topology.lldp.utils;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNull;
14 import org.junit.Test;
15 import org.junit.runner.RunWith;
16 import org.mockito.runners.MockitoJUnitRunner;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
26 * Test for {@link LLDPDiscoveryUtils}.
28 @RunWith(MockitoJUnitRunner.class)
29 public class LLDPDiscoveryUtilsTest {
31 private static final Logger LOG = LoggerFactory.getLogger(LLDPDiscoveryUtilsTest.class);
34 public void testLldpToNodeConnectorRefLLDP() throws Exception {
36 0x01, 0x23, 0x00, 0x00, 0x00, 0x01, (byte) 0x8a, (byte) 0x8e,
37 (byte) 0xcc, (byte) 0x85, (byte) 0xeb, 0x27,
38 /* ethernet type LLDP 0x88cc */(byte) 0x88, (byte) 0xcc,
39 0x02, 0x07, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x04,
40 0x02, 0x07, 0x32, 0x06, 0x02, 0x13, 0x37, 0x0a, 0x0a,
41 /* openflow:2 */0x6f, 0x70, 0x65, 0x6e, 0x66, 0x6c, 0x6f, 0x77, 0x3a, 0x32,
42 (byte) 0xfe, 0x10, 0x00, 0x26, (byte) 0xe1, 0x00,
43 /* openflow:2:2 */0x6f, 0x70, 0x65, 0x6e, 0x66, 0x6c, 0x6f, 0x77, 0x3a, 0x32, 0x3a, 0x32,
44 (byte) 0xfe, 0x14, 0x00, 0x26, (byte) 0xe1, 0x01, 0x62, (byte) 0xc8, 0x2b, 0x67, (byte) 0xce,
45 (byte) 0xbe, 0x7c, 0x2b, 0x47, (byte) 0xbe, 0x2b, (byte) 0xe7, (byte) 0xbc,
46 (byte) 0xe9, 0x75, 0x3d, 0x00, 0x00
49 NodeConnectorRef nodeConnectorRef = LLDPDiscoveryUtils.lldpToNodeConnectorRef(packetLLDP, false);
51 NodeKey nodeKey = nodeConnectorRef.getValue().firstKeyOf(Node.class);
52 NodeConnectorKey nodeConnectorKey = nodeConnectorRef.getValue().firstKeyOf(NodeConnector.class);
54 assertEquals(nodeKey.getId().getValue(), "openflow:2");
55 assertEquals(nodeConnectorKey.getId().getValue(), "openflow:2:2");
59 public void testLldpToNodeConnectorRefNotLLDP() throws Exception {
60 byte[] packetNotLLDP = {
61 0x01, 0x23, 0x00, 0x00, 0x00, 0x01, (byte) 0x8a, (byte) 0x8e,
62 (byte) 0xcc, (byte) 0x85, (byte) 0xeb, 0x27,
63 /* ethernet type IPv4 0x0800 */(byte) 0x08, (byte) 0x00,
64 0x02, 0x07, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x04,
65 0x02, 0x07, 0x32, 0x06, 0x02, 0x13, 0x37, 0x0a,
66 0x0a, 0x6f, 0x70, 0x65, 0x6e, 0x66, 0x6c, 0x6f,
67 0x77, 0x3a, 0x32, (byte) 0xfe, 0x10, 0x00, 0x26, (byte) 0xe1,
68 0x00, 0x6f, 0x70, 0x65, 0x6e, 0x66, 0x6c, 0x6f,
69 0x77, 0x3a, 0x32, 0x3a, 0x32, (byte) 0xfe, 0x14, 0x00,
70 0x26, (byte) 0xe1, 0x01, 0x62, (byte) 0xc8, 0x2b, 0x67, (byte) 0xce,
71 (byte) 0xbe, 0x7c, 0x2b, 0x47, (byte) 0xbe, 0x2b, (byte) 0xe7, (byte) 0xbc,
72 (byte) 0xe9, 0x75, 0x3d, 0x00, 0x00
75 NodeConnectorRef nodeConnectorRef = LLDPDiscoveryUtils.lldpToNodeConnectorRef(packetNotLLDP, false);
77 assertNull(nodeConnectorRef);