blob: f8bc90082105e0b58959a28956e3ea1cc8ad752e [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;
40 private static final DeviceId DEVICE_ID = DeviceId.deviceId("1234");
41 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
58 @Before
59 public void setup() {
60 StatsInfo statsInfo = new DefaultStatsInfo.DefaultBuilder().build();
61 FlowInfo.Builder builder = new DefaultFlowInfo.DefaultBuilder();
62
63 info = builder
64 .withFlowType(FLOW_TYPE)
65 .withDeviceId(DEVICE_ID)
66 .withInputInterfaceId(INPUT_INTERFACE_ID)
67 .withOutputInterfaceId(OUTPUT_INTERFACE_ID)
68 .withVlanId(VLAN_ID)
69 .withSrcIp(SRC_IP_PREFIX)
70 .withDstIp(DST_IP_PREFIX)
71 .withSrcPort(SRC_PORT_NUMBER)
72 .withDstPort(DST_PORT_NUMBER)
73 .withProtocol(PROTOCOL)
74 .withSrcMac(SRC_MAC_ADDRESS)
75 .withDstMac(DST_MAC_ADDRESS)
76 .withStatsInfo(statsInfo)
77 .build();
78 }
79
80 @Test
81 public void testEncodeDecode() {
82 ByteBuffer buffer = codec.encode(info);
83 FlowInfo decoded = codec.decode(ByteBuffer.wrap(buffer.array()));
84 new EqualsTester().addEqualityGroup(info, decoded).testEquals();
85 }
86}