Shashikanth VH | ae8f63d | 2016-02-10 11:46:09 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Shashikanth VH | ae8f63d | 2016-02-10 11:46:09 +0530 | [diff] [blame] | 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 | package org.onosproject.bgpio.protocol.flowspec; |
| 17 | |
| 18 | import java.util.ArrayList; |
| 19 | import java.util.LinkedList; |
| 20 | import java.util.List; |
| 21 | |
| 22 | import org.junit.Test; |
| 23 | import org.onosproject.bgpio.types.BgpFsActionTrafficRate; |
| 24 | import org.onosproject.bgpio.types.BgpFsOperatorValue; |
| 25 | import org.onosproject.bgpio.types.BgpFsPortNum; |
| 26 | import org.onosproject.bgpio.types.BgpValueType; |
| 27 | |
| 28 | import com.google.common.testing.EqualsTester; |
| 29 | |
| 30 | /** |
Shashikanth VH | 26fd38a | 2016-04-26 18:11:37 +0530 | [diff] [blame] | 31 | * Test for BgpFlowSpecNlri flow specification. |
Shashikanth VH | ae8f63d | 2016-02-10 11:46:09 +0530 | [diff] [blame] | 32 | */ |
Shashikanth VH | 26fd38a | 2016-04-26 18:11:37 +0530 | [diff] [blame] | 33 | public class BgpFlowSpecNlriTest { |
Shashikanth VH | ae8f63d | 2016-02-10 11:46:09 +0530 | [diff] [blame] | 34 | |
| 35 | List<BgpValueType> flowSpecComponents1 = new LinkedList<>(); |
| 36 | private List<BgpFsOperatorValue> operatorValue1 = new ArrayList<>(); |
Shashikanth VH | 26fd38a | 2016-04-26 18:11:37 +0530 | [diff] [blame] | 37 | BgpFlowSpecNlri flowSpecDetails1 = new BgpFlowSpecNlri(flowSpecComponents1); |
Shashikanth VH | ae8f63d | 2016-02-10 11:46:09 +0530 | [diff] [blame] | 38 | BgpFsPortNum portNum1 = new BgpFsPortNum(operatorValue1); |
| 39 | |
| 40 | List<BgpValueType> flowSpecComponents = new LinkedList<>(); |
| 41 | private List<BgpFsOperatorValue> operatorValue = new ArrayList<>(); |
Shashikanth VH | 26fd38a | 2016-04-26 18:11:37 +0530 | [diff] [blame] | 42 | BgpFlowSpecNlri flowSpecDetails = new BgpFlowSpecNlri(flowSpecComponents); |
Shashikanth VH | ae8f63d | 2016-02-10 11:46:09 +0530 | [diff] [blame] | 43 | BgpFsPortNum portNum = new BgpFsPortNum(operatorValue); |
| 44 | |
| 45 | List<BgpValueType> flowSpecComponents2 = new LinkedList<>(); |
| 46 | private List<BgpFsOperatorValue> operatorValue2 = new ArrayList<>(); |
Shashikanth VH | 26fd38a | 2016-04-26 18:11:37 +0530 | [diff] [blame] | 47 | BgpFlowSpecNlri flowSpecDetails2 = new BgpFlowSpecNlri(flowSpecComponents2); |
Shashikanth VH | ae8f63d | 2016-02-10 11:46:09 +0530 | [diff] [blame] | 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 VH | e30cfc4 | 2016-02-18 23:31:02 +0530 | [diff] [blame] | 57 | |
| 58 | List<BgpValueType> fsTlvs1 = new LinkedList<>(); |
| 59 | fsTlvs1.add(new BgpFsActionTrafficRate((short) 1, 1)); |
| 60 | flowSpecDetails1.setFsActionTlv(fsTlvs1); |
Shashikanth VH | ae8f63d | 2016-02-10 11:46:09 +0530 | [diff] [blame] | 61 | |
| 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 VH | e30cfc4 | 2016-02-18 23:31:02 +0530 | [diff] [blame] | 67 | |
| 68 | List<BgpValueType> fsTlvs = new LinkedList<>(); |
| 69 | fsTlvs.add(new BgpFsActionTrafficRate((short) 1, 1)); |
Shashikanth VH | ae8f63d | 2016-02-10 11:46:09 +0530 | [diff] [blame] | 70 | |
| 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 VH | e30cfc4 | 2016-02-18 23:31:02 +0530 | [diff] [blame] | 76 | |
| 77 | List<BgpValueType> fsTlvs2 = new LinkedList<>(); |
| 78 | fsTlvs2.add(new BgpFsActionTrafficRate((short) 1, 1)); |
| 79 | flowSpecDetails2.setFsActionTlv(fsTlvs2); |
Shashikanth VH | ae8f63d | 2016-02-10 11:46:09 +0530 | [diff] [blame] | 80 | |
| 81 | new EqualsTester() |
| 82 | .addEqualityGroup(flowSpecDetails1, flowSpecDetails) |
| 83 | .addEqualityGroup(flowSpecDetails2) |
| 84 | .testEquals(); |
| 85 | } |
| 86 | } |