blob: 8f4af77b970274c32bafa3631692021a4878924c [file] [log] [blame]
Jian Li6bd35102018-06-09 00:18:47 +09001/*
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 */
16package org.onosproject.openstacktelemetry.codec;
17
18import com.google.common.testing.EqualsTester;
19import org.junit.Before;
20import org.junit.Test;
21import org.onlab.packet.IpAddress;
22import org.onlab.packet.IpPrefix;
23import org.onlab.packet.MacAddress;
24import org.onlab.packet.TpPort;
25import org.onlab.packet.VlanId;
26import org.onosproject.net.DeviceId;
27import org.onosproject.openstacktelemetry.api.FlowInfo;
28import org.onosproject.openstacktelemetry.api.StatsInfo;
29import org.onosproject.openstacktelemetry.impl.DefaultFlowInfo;
30import org.onosproject.openstacktelemetry.impl.DefaultStatsInfo;
31
32import java.nio.ByteBuffer;
33
34/**
35 * Unit tests for TinaFlowInfoByteBufferCodec.
36 */
Jian Li3db90852018-06-10 22:29:16 +090037public final class TinaFlowInfoByteBufferCodecTest {
Jian Li6bd35102018-06-09 00:18:47 +090038
39 private static final byte FLOW_TYPE = 1;
Jian Li0bbbb1c2018-06-22 22:01:17 +090040 private static final DeviceId DEVICE_ID = DeviceId.deviceId("of:00000000000000a1");
Jian Li6bd35102018-06-09 00:18:47 +090041 private static final int INPUT_INTERFACE_ID = 10;
42 private static final int OUTPUT_INTERFACE_ID = 10;
43 private static final VlanId VLAN_ID = VlanId.vlanId("100");
44 private static final IpAddress SRC_IP_ADDRESS = IpAddress.valueOf("10.10.10.1");
45 private static final IpPrefix SRC_IP_PREFIX = IpPrefix.valueOf(SRC_IP_ADDRESS, 24);
46 private static final IpAddress DST_IP_ADDRESS = IpAddress.valueOf("20.20.20.1");
47 private static final IpPrefix DST_IP_PREFIX = IpPrefix.valueOf(DST_IP_ADDRESS, 24);
48 private static final TpPort SRC_PORT_NUMBER = TpPort.tpPort(1000);
49 private static final TpPort DST_PORT_NUMBER = TpPort.tpPort(2000);
50 private static final byte PROTOCOL = 10;
51 private static final MacAddress SRC_MAC_ADDRESS = MacAddress.valueOf("AA:BB:CC:DD:EE:FF");
52 private static final MacAddress DST_MAC_ADDRESS = MacAddress.valueOf("FF:EE:DD:CC:BB:AA");
53
54 private FlowInfo info;
55 private final TinaFlowInfoByteBufferCodec codec =
56 new TinaFlowInfoByteBufferCodec();
57
Jian Liae3fcff2018-07-30 11:55:44 +090058 /**
59 * Initial setup for this unit test.
60 */
Jian Li6bd35102018-06-09 00:18:47 +090061 @Before
62 public void setup() {
63 StatsInfo statsInfo = new DefaultStatsInfo.DefaultBuilder().build();
64 FlowInfo.Builder builder = new DefaultFlowInfo.DefaultBuilder();
65
66 info = builder
67 .withFlowType(FLOW_TYPE)
68 .withDeviceId(DEVICE_ID)
69 .withInputInterfaceId(INPUT_INTERFACE_ID)
70 .withOutputInterfaceId(OUTPUT_INTERFACE_ID)
71 .withVlanId(VLAN_ID)
72 .withSrcIp(SRC_IP_PREFIX)
73 .withDstIp(DST_IP_PREFIX)
74 .withSrcPort(SRC_PORT_NUMBER)
75 .withDstPort(DST_PORT_NUMBER)
76 .withProtocol(PROTOCOL)
77 .withSrcMac(SRC_MAC_ADDRESS)
78 .withDstMac(DST_MAC_ADDRESS)
79 .withStatsInfo(statsInfo)
80 .build();
81 }
82
83 @Test
84 public void testEncodeDecode() {
85 ByteBuffer buffer = codec.encode(info);
86 FlowInfo decoded = codec.decode(ByteBuffer.wrap(buffer.array()));
87 new EqualsTester().addEqualityGroup(info, decoded).testEquals();
88 }
89}