blob: 810799c5659208e01618208bc40e86129ec35404 [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
17package org.onlab.packet.lacp;
18
19import com.google.common.collect.Maps;
20import com.google.common.io.Resources;
21import org.junit.Before;
22import org.junit.Test;
23
24import java.util.Map;
25
26import static org.junit.Assert.*;
27
28public class LacpTest {
29 private static final String PACKET_DUMP = "lacp.bin";
30
31 private static final byte LACP_VERSION = 1;
32 private static final Map<Byte, LacpTlv> LACP_TLV = Maps.newHashMap();
33 private static final Lacp LACP = new Lacp();
34
35 static {
36 LACP_TLV.put(Lacp.TYPE_ACTOR, LacpBaseTlvTest.BASE_TLV);
37 LACP_TLV.put(Lacp.TYPE_PARTNER, LacpBaseTlvTest.BASE_TLV);
38 LACP_TLV.put(Lacp.TYPE_COLLECTOR, LacpCollectorTlvTest.COLLECTOR_TLV);
39 LACP_TLV.put(Lacp.TYPE_TERMINATOR, LacpTerminatorTlvTest.TERMINATOR_TLV);
40
41 LACP.setLacpVersion(LACP_VERSION)
42 .setTlv(LACP_TLV);
43 }
44
45 private byte[] data;
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 Lacp lacp = Lacp.deserializer().deserialize(data, 0, data.length);
55 assertEquals(LACP_VERSION, lacp.getLacpVersion());
56 assertEquals(LACP_TLV, lacp.getTlv());
57 }
58
59 @Test
60 public void serialize() {
61 assertArrayEquals(data, LACP.serialize());
62 }
63}