blob: bb6ec6039345aa39b9ab3bae986576bfd10bbe19 [file] [log] [blame]
Charles M.C. Chan7fee36a2014-12-31 00:19:59 +08001/*
2 * Copyright 2014 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17
18
19package org.onlab.packet;
20
21import org.junit.BeforeClass;
22import org.junit.Test;
23
24import static org.junit.Assert.*;
25
26/**
27 * Tests for class {@link org.onlab.packet.NeighborSolicitation}.
28 */
29public class NeighborSolicitationTest {
30 private static final byte[] TARGET_ADDRESS = {
31 (byte) 0x20, (byte) 0x01, (byte) 0x0f, (byte) 0x18, (byte) 0x01, (byte) 0x13, (byte) 0x02, (byte) 0x15,
32 (byte) 0xca, (byte) 0x2a, (byte) 0x14, (byte) 0xff, (byte) 0xfe, (byte) 0x35, (byte) 0x26, (byte) 0xce
33 };
34 private static final byte[] TARGET_ADDRESS2 = {
35 (byte) 0x20, (byte) 0x01, (byte) 0x0f, (byte) 0x18, (byte) 0x01, (byte) 0x13, (byte) 0x02, (byte) 0x15,
36 (byte) 0xe6, (byte) 0xce, (byte) 0x8f, (byte) 0xff, (byte) 0xfe, (byte) 0x54, (byte) 0x37, (byte) 0xc8
37 };
38 private static Data data;
39 private static byte[] bytePacket;
40
41 @BeforeClass
42 public static void setUpBeforeClass() throws Exception {
43 data = new Data();
44 data.setData("".getBytes());
45
46 byte[] bytePayload = data.serialize();
47 byte[] byteHeader = {
48 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
49 (byte) 0x20, (byte) 0x01, (byte) 0x0f, (byte) 0x18, (byte) 0x01, (byte) 0x13, (byte) 0x02, (byte) 0x15,
50 (byte) 0xca, (byte) 0x2a, (byte) 0x14, (byte) 0xff, (byte) 0xfe, (byte) 0x35, (byte) 0x26, (byte) 0xce
51 };
52 bytePacket = new byte[byteHeader.length + bytePayload.length];
53 System.arraycopy(byteHeader, 0, bytePacket, 0, byteHeader.length);
54 System.arraycopy(bytePayload, 0, bytePacket, byteHeader.length, bytePayload.length);
55 }
56
57 /**
58 * Tests serialize and setters.
59 */
60 @Test
61 public void testSerialize() {
62 NeighborSolicitation ns = new NeighborSolicitation();
63 ns.setTargetAddress(TARGET_ADDRESS);
64
65 assertArrayEquals(ns.serialize(), bytePacket);
66 }
67
68 /**
69 * Tests deserialize and getters.
70 */
71 @Test
72 public void testDeserialize() {
73 NeighborSolicitation ns = new NeighborSolicitation();
74 ns.deserialize(bytePacket, 0, bytePacket.length);
75
76 assertArrayEquals(ns.getTargetAddress(), TARGET_ADDRESS);
77 }
78
79 /**
80 * Tests comparator.
81 */
82 @Test
83 public void testEqual() {
84 NeighborSolicitation ns1 = new NeighborSolicitation();
85 ns1.setTargetAddress(TARGET_ADDRESS);
86
87 NeighborSolicitation ns2 = new NeighborSolicitation();
88 ns2.setTargetAddress(TARGET_ADDRESS2);
89
90 assertTrue(ns1.equals(ns1));
91 assertFalse(ns1.equals(ns2));
92 }
93}