blob: 928ee72c501ba65b7c46c940f444d6a24ebdb787 [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001/**
Ray Milkey269ffb92014-04-03 14:43:30 -07002 * Copyright 2011, Big Switch Networks, Inc.
3 * Originally created by David Erickson, Stanford University
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may
6 * not use this file except in compliance with the License. You may obtain
7 * a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations
15 * under the License.
16 **/
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080017
18/**
19 *
20 */
Jonathan Hartdeda0ba2014-04-03 11:14:12 -070021package net.onrc.onos.core.packet;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080022
23import static org.junit.Assert.assertEquals;
24import static org.junit.Assert.assertTrue;
25
26import java.util.Arrays;
27
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080028import org.junit.Test;
29
30/**
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080031 * @author David Erickson (daviderickson@cs.stanford.edu)
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080032 */
33public class LLDPTest {
Ray Milkey269ffb92014-04-03 14:43:30 -070034 protected byte[] pkt = {0x01, 0x23, 0x20, 0x00, 0x00, 0x01, 0x00, 0x12, (byte) 0xe2, 0x78, 0x67, 0x78, (byte) 0x88, (byte) 0xcc, 0x02, 0x07,
35 0x04, 0x00, 0x12, (byte) 0xe2, 0x78, 0x67, 0x64, 0x04, 0x03, 0x02, 0x00, 0x06, 0x06, 0x02, 0x00, 0x78,
36 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
37 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080038
39 protected IPacket getPacket() {
40 return new Ethernet()
Ray Milkey269ffb92014-04-03 14:43:30 -070041 .setPad(true)
42 .setDestinationMACAddress("01:23:20:00:00:01")
43 .setSourceMACAddress("00:12:e2:78:67:78")
44 .setEtherType(Ethernet.TYPE_LLDP)
45 .setPayload(
46 new LLDP()
47 .setChassisId(new LLDPTLV().setType((byte) 1).setLength((short) 7).setValue(new byte[]{0x04, 0x00, 0x12, (byte) 0xe2, 0x78, 0x67, 0x64}))
48 .setPortId(new LLDPTLV().setType((byte) 2).setLength((short) 3).setValue(new byte[]{0x02, 0x00, 0x06}))
49 .setTtl(new LLDPTLV().setType((byte) 3).setLength((short) 2).setValue(new byte[]{0x00, 0x78}))
50
51 );
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080052 }
53
54 @Test
55 public void testSerialize() throws Exception {
56 IPacket ethernet = getPacket();
57 assertTrue(Arrays.equals(pkt, ethernet.serialize()));
58 }
59
60 @Test
61 public void testDeserialize() throws Exception {
62 Ethernet ethernet = (Ethernet) new Ethernet().deserialize(pkt, 0, pkt.length);
63 ethernet.setPad(true);
64 assertTrue(Arrays.equals(pkt, ethernet.serialize()));
65
66 IPacket expected = getPacket();
67 assertEquals(expected, ethernet);
68 }
69}