blob: 15dfd4cdca4065da08cbea94e17bc8c0ac315931 [file] [log] [blame]
Shashikanth VHae8f63d2016-02-10 11:46:09 +05301/*
2 * Copyright 2016 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 */
16package org.onosproject.bgpio.protocol.flowspec;
17
18import java.util.ArrayList;
19import java.util.LinkedList;
20import java.util.List;
21
22import org.junit.Test;
23import org.onosproject.bgpio.types.BgpFsActionTrafficRate;
24import org.onosproject.bgpio.types.BgpFsOperatorValue;
25import org.onosproject.bgpio.types.BgpFsPortNum;
26import org.onosproject.bgpio.types.BgpValueType;
27
28import com.google.common.testing.EqualsTester;
29
30/**
31 * Test for BgpFlowSpecDetails flow specification.
32 */
33public class BgpFlowSpecDetailsTest {
34
35 List<BgpValueType> flowSpecComponents1 = new LinkedList<>();
36 private List<BgpFsOperatorValue> operatorValue1 = new ArrayList<>();
37 BgpFlowSpecDetails flowSpecDetails1 = new BgpFlowSpecDetails(flowSpecComponents1);
38 BgpFsPortNum portNum1 = new BgpFsPortNum(operatorValue1);
39
40 List<BgpValueType> flowSpecComponents = new LinkedList<>();
41 private List<BgpFsOperatorValue> operatorValue = new ArrayList<>();
42 BgpFlowSpecDetails flowSpecDetails = new BgpFlowSpecDetails(flowSpecComponents);
43 BgpFsPortNum portNum = new BgpFsPortNum(operatorValue);
44
45 List<BgpValueType> flowSpecComponents2 = new LinkedList<>();
46 private List<BgpFsOperatorValue> operatorValue2 = new ArrayList<>();
47 BgpFlowSpecDetails flowSpecDetails2 = new BgpFlowSpecDetails(flowSpecComponents2);
48 BgpFsPortNum portNum2 = new BgpFsPortNum(operatorValue2);
49
50 @Test
51 public void testEquality() {
52 flowSpecComponents1.add(portNum1);
53 byte[] port1 = new byte[] {(byte) 0x1 };
54 operatorValue1.add(new BgpFsOperatorValue((byte) 0x81, port1));
55 byte[] port11 = new byte[] {(byte) 0x1 };
56 operatorValue1.add(new BgpFsOperatorValue((byte) 0x82, port11));
Shashikanth VHe30cfc42016-02-18 23:31:02 +053057
58 List<BgpValueType> fsTlvs1 = new LinkedList<>();
59 fsTlvs1.add(new BgpFsActionTrafficRate((short) 1, 1));
60 flowSpecDetails1.setFsActionTlv(fsTlvs1);
Shashikanth VHae8f63d2016-02-10 11:46:09 +053061
62 flowSpecComponents.add(portNum);
63 byte[] port = new byte[] {(byte) 0x1 };
64 operatorValue.add(new BgpFsOperatorValue((byte) 0x81, port));
65 byte[] port4 = new byte[] {(byte) 0x1 };
66 operatorValue.add(new BgpFsOperatorValue((byte) 0x82, port4));
Shashikanth VHe30cfc42016-02-18 23:31:02 +053067
68 List<BgpValueType> fsTlvs = new LinkedList<>();
69 fsTlvs.add(new BgpFsActionTrafficRate((short) 1, 1));
Shashikanth VHae8f63d2016-02-10 11:46:09 +053070
71 flowSpecComponents2.add(portNum2);
72 byte[] port2 = new byte[] {(byte) 0x1 };
73 operatorValue2.add(new BgpFsOperatorValue((byte) 0x82, port2));
74 byte[] port22 = new byte[] {(byte) 0x1 };
75 operatorValue2.add(new BgpFsOperatorValue((byte) 0x82, port22));
Shashikanth VHe30cfc42016-02-18 23:31:02 +053076
77 List<BgpValueType> fsTlvs2 = new LinkedList<>();
78 fsTlvs2.add(new BgpFsActionTrafficRate((short) 1, 1));
79 flowSpecDetails2.setFsActionTlv(fsTlvs2);
Shashikanth VHae8f63d2016-02-10 11:46:09 +053080
81 new EqualsTester()
82 .addEqualityGroup(flowSpecDetails1, flowSpecDetails)
83 .addEqualityGroup(flowSpecDetails2)
84 .testEquals();
85 }
86}