blob: c093efb07cd538d692f084ae4f44e537148d8735 [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001/**
2* 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**/
17
18/**
19 *
20 */
Jonathan Hart96892d12014-03-26 20:21:29 -070021package net.onrc.onos.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
Jonathan Hart96892d12014-03-26 20:21:29 -070028import net.onrc.onos.packet.Ethernet;
29import net.onrc.onos.packet.IPacket;
30import net.onrc.onos.packet.LLDP;
31import net.onrc.onos.packet.LLDPTLV;
32
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080033import org.junit.Test;
34
35/**
36 *
37 * @author David Erickson (daviderickson@cs.stanford.edu)
38 *
39 */
40public class LLDPTest {
41 protected byte[] pkt = {0x01,0x23,0x20,0x00,0x00,0x01,0x00,0x12,(byte) 0xe2,0x78,0x67,0x78,(byte) 0x88,(byte) 0xcc,0x02,0x07,
42 0x04,0x00,0x12,(byte) 0xe2,0x78,0x67,0x64,0x04,0x03,0x02,0x00,0x06,0x06,0x02,0x00,0x78,
43 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
44 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
45
46 protected IPacket getPacket() {
47 return new Ethernet()
48 .setPad(true)
49 .setDestinationMACAddress("01:23:20:00:00:01")
50 .setSourceMACAddress("00:12:e2:78:67:78")
51 .setEtherType(Ethernet.TYPE_LLDP)
52 .setPayload(
53 new LLDP()
54 .setChassisId(new LLDPTLV().setType((byte) 1).setLength((short) 7).setValue(new byte[] {0x04, 0x00, 0x12, (byte) 0xe2, 0x78, 0x67, 0x64}))
55 .setPortId(new LLDPTLV().setType((byte) 2).setLength((short) 3).setValue(new byte[] {0x02, 0x00, 0x06}))
56 .setTtl(new LLDPTLV().setType((byte) 3).setLength((short) 2).setValue(new byte[] {0x00, 0x78}))
57
58 );
59 }
60
61 @Test
62 public void testSerialize() throws Exception {
63 IPacket ethernet = getPacket();
64 assertTrue(Arrays.equals(pkt, ethernet.serialize()));
65 }
66
67 @Test
68 public void testDeserialize() throws Exception {
69 Ethernet ethernet = (Ethernet) new Ethernet().deserialize(pkt, 0, pkt.length);
70 ethernet.setPad(true);
71 assertTrue(Arrays.equals(pkt, ethernet.serialize()));
72
73 IPacket expected = getPacket();
74 assertEquals(expected, ethernet);
75 }
76}