blob: 6c6e3b31792584760e203c2d2616682262e029e9 [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
Yuta HIGUCHIaa132f52014-06-26 10:18:39 -070030// CHECKSTYLE IGNORE WriteTag FOR NEXT 2 LINES
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080031/**
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080032 * @author David Erickson (daviderickson@cs.stanford.edu)
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080033 */
34public class LLDPTest {
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -070035 protected byte[] pkt = {0x01, 0x23, 0x20, 0x00, 0x00, 0x01,
36 0x00, 0x12, (byte) 0xe2, 0x78, 0x67, 0x78,
37 (byte) 0x88, (byte) 0xcc, 0x02, 0x07,
38 0x04, 0x00, 0x12, (byte) 0xe2, 0x78, 0x67, 0x64,
39 0x04, 0x03,
40 0x02, 0x00, 0x06,
41 0x06, 0x02,
42 0x00, 0x78,
43 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
45 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080046
47 protected IPacket getPacket() {
48 return new Ethernet()
Ray Milkey269ffb92014-04-03 14:43:30 -070049 .setPad(true)
50 .setDestinationMACAddress("01:23:20:00:00:01")
51 .setSourceMACAddress("00:12:e2:78:67:78")
52 .setEtherType(Ethernet.TYPE_LLDP)
53 .setPayload(
54 new LLDP()
Yuta HIGUCHI91a8f502014-06-17 10:15:29 -070055 .setChassisId(new LLDPTLV().setType((byte) 1)
56 .setLength((short) 7)
57 .setValue(new byte[]{0x04, 0x00, 0x12, (byte) 0xe2, 0x78, 0x67, 0x64}))
58 .setPortId(new LLDPTLV().setType((byte) 2)
59 .setLength((short) 3)
60 .setValue(new byte[]{0x02, 0x00, 0x06}))
61 .setTtl(new LLDPTLV().setType((byte) 3)
62 .setLength((short) 2)
63 .setValue(new byte[]{0x00, 0x78}))
Ray Milkey269ffb92014-04-03 14:43:30 -070064
65 );
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080066 }
67
68 @Test
69 public void testSerialize() throws Exception {
70 IPacket ethernet = getPacket();
71 assertTrue(Arrays.equals(pkt, ethernet.serialize()));
72 }
73
74 @Test
75 public void testDeserialize() throws Exception {
76 Ethernet ethernet = (Ethernet) new Ethernet().deserialize(pkt, 0, pkt.length);
77 ethernet.setPad(true);
78 assertTrue(Arrays.equals(pkt, ethernet.serialize()));
79
80 IPacket expected = getPacket();
81 assertEquals(expected, ethernet);
82 }
83}