Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 1 | /** |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 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 | **/ |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 17 | |
| 18 | /** |
| 19 | * |
| 20 | */ |
Jonathan Hart | deda0ba | 2014-04-03 11:14:12 -0700 | [diff] [blame] | 21 | package net.onrc.onos.core.packet; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 22 | |
| 23 | import static org.junit.Assert.assertEquals; |
| 24 | import static org.junit.Assert.assertTrue; |
| 25 | |
| 26 | import java.util.Arrays; |
| 27 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 28 | import org.junit.Test; |
| 29 | |
Yuta HIGUCHI | aa132f5 | 2014-06-26 10:18:39 -0700 | [diff] [blame^] | 30 | // CHECKSTYLE IGNORE WriteTag FOR NEXT 2 LINES |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 31 | /** |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 32 | * @author David Erickson (daviderickson@cs.stanford.edu) |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 33 | */ |
| 34 | public class LLDPTest { |
Yuta HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 35 | 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 Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 46 | |
| 47 | protected IPacket getPacket() { |
| 48 | return new Ethernet() |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 49 | .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 HIGUCHI | 91a8f50 | 2014-06-17 10:15:29 -0700 | [diff] [blame] | 55 | .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 Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 64 | |
| 65 | ); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 66 | } |
| 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 | } |