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