blob: 874d5c14339a724b4898989dbc65fe249554951f [file] [log] [blame]
Charles Chan64c2dfd2018-07-24 11:58:08 -07001/*
2 * Copyright 2018-present Open Networking Foundation
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
18package org.onlab.packet.lacp;
19
20import com.google.common.io.Resources;
21import org.junit.Before;
22import org.junit.Test;
23import org.onlab.packet.MacAddress;
24
25import static org.junit.Assert.*;
26
27public class LacpBaseTlvTest {
28 private static final String PACKET_DUMP = "baseinfo.bin";
29
30 private byte[] data;
31
32 private static final short SYS_PRIORITY = (short) 32768;
33 private static final MacAddress SYS_MAC = MacAddress.valueOf("a4:23:05:00:11:22");
34 private static final short KEY = (short) 13;
35 private static final short PORT_PRIORITY = (short) 32768;
36 private static final short PORT = 22;
37 private static final byte STATE = (byte) 0x85;
38
39 static final LacpBaseTlv BASE_TLV = new LacpBaseTlv()
40 .setSystemPriority(SYS_PRIORITY)
41 .setSystemMac(SYS_MAC)
42 .setKey(KEY)
43 .setPortPriority(PORT_PRIORITY)
44 .setPort(PORT)
45 .setState(STATE);
46
47 @Before
48 public void setUp() throws Exception {
49 data = Resources.toByteArray(LacpBaseTlvTest.class.getResource(PACKET_DUMP));
50 }
51
52 @Test
53 public void deserializer() throws Exception {
54 LacpBaseTlv actorInfo = LacpBaseTlv.deserializer().deserialize(data, 0, data.length);
55 assertEquals(SYS_PRIORITY, actorInfo.getSystemPriority());
56 assertEquals(SYS_MAC, actorInfo.getSystemMac());
57 assertEquals(KEY, actorInfo.getKey());
58 assertEquals(PORT_PRIORITY, actorInfo.getPortPriority());
59 assertEquals(PORT, actorInfo.getPort());
60 assertEquals(STATE, actorInfo.getState().toByte());
61 }
62
63 @Test
64 public void serialize() {
65 assertArrayEquals(data, BASE_TLV.serialize());
66 }
67}