Shashikanth VH
Committed by Gerrit Code Review

[ONOS-3856] BGP flow specification RIB out test.

Change-Id: Ie4d2ef90c261f8bb5b560cb2b62c5cf7cca29988
1 +/*
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 + */
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 +/**
31 + * Test for BgpFlowSpecDetails flow specification.
32 + */
33 +public 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));
57 + flowSpecDetails1.setFsActionTlv(new BgpFsActionTrafficRate((short) 1, 1));
58 +
59 + flowSpecComponents.add(portNum);
60 + byte[] port = new byte[] {(byte) 0x1 };
61 + operatorValue.add(new BgpFsOperatorValue((byte) 0x81, port));
62 + byte[] port4 = new byte[] {(byte) 0x1 };
63 + operatorValue.add(new BgpFsOperatorValue((byte) 0x82, port4));
64 + flowSpecDetails.setFsActionTlv(new BgpFsActionTrafficRate((short) 1, 1));
65 +
66 + flowSpecComponents2.add(portNum2);
67 + byte[] port2 = new byte[] {(byte) 0x1 };
68 + operatorValue2.add(new BgpFsOperatorValue((byte) 0x82, port2));
69 + byte[] port22 = new byte[] {(byte) 0x1 };
70 + operatorValue2.add(new BgpFsOperatorValue((byte) 0x82, port22));
71 + flowSpecDetails2.setFsActionTlv(new BgpFsActionTrafficRate((short) 1, 1));
72 +
73 + new EqualsTester()
74 + .addEqualityGroup(flowSpecDetails1, flowSpecDetails)
75 + .addEqualityGroup(flowSpecDetails2)
76 + .testEquals();
77 + }
78 +}
1 +/*
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 + */
16 +package org.onosproject.controller.impl;
17 +
18 +import org.junit.Test;
19 +import org.onlab.packet.IpAddress;
20 +import org.onlab.packet.IpPrefix;
21 +import org.onosproject.bgp.controller.impl.BgpFlowSpecRibOut;
22 +import org.onosproject.bgpio.protocol.flowspec.BgpFlowSpecDetails;
23 +import org.onosproject.bgpio.protocol.flowspec.BgpFlowSpecPrefix;
24 +import org.onosproject.bgpio.types.BgpFsOperatorValue;
25 +import org.onosproject.bgpio.types.BgpFsPortNum;
26 +import org.onosproject.bgpio.types.BgpValueType;
27 +import org.onosproject.bgpio.types.RouteDistinguisher;
28 +
29 +import java.util.ArrayList;
30 +import java.util.LinkedList;
31 +import java.util.List;
32 +
33 +import static org.hamcrest.MatcherAssert.assertThat;
34 +import static org.hamcrest.core.Is.is;
35 +
36 +/**
37 + * Test cases for BGP Selection Algorithm.
38 + */
39 +public class BgpFlowSpecRibOutTest {
40 +
41 + /**
42 + * Add flow specification to rib out.
43 + */
44 + @Test
45 + public void bgpFlowSpecRibOutTests1() {
46 + List<BgpValueType> flowSpecComponents = new LinkedList<>();
47 + List<BgpFsOperatorValue> operatorValue = new ArrayList<>();
48 + BgpFlowSpecRibOut ribOut = new BgpFlowSpecRibOut();
49 +
50 + IpPrefix destinationPrefix = IpPrefix.valueOf(IpAddress.valueOf("10.0.1.1"), 32);
51 + IpPrefix sourcePrefix = IpPrefix.valueOf(IpAddress.valueOf("10.0.1.2"), 32);
52 +
53 + BgpFlowSpecPrefix prefix = new BgpFlowSpecPrefix(destinationPrefix, sourcePrefix);
54 +
55 + byte[] port = new byte[] {(byte) 0x1 };
56 + operatorValue.add(new BgpFsOperatorValue((byte) 0x81, port));
57 +
58 + BgpFsPortNum portNum = new BgpFsPortNum(operatorValue);
59 + flowSpecComponents.add(portNum);
60 +
61 + BgpFlowSpecDetails flowSpec = new BgpFlowSpecDetails(flowSpecComponents);
62 +
63 + ribOut.add(prefix, flowSpec);
64 +
65 + boolean isPresent = ribOut.flowSpecTree().containsKey(prefix);
66 + assertThat(isPresent, is(true));
67 + }
68 +
69 + /**
70 + * Add and delete flow specification to rib out.
71 + */
72 + @Test
73 + public void bgpFlowSpecRibOutTest2() {
74 + List<BgpValueType> flowSpecComponents = new LinkedList<>();
75 + List<BgpFsOperatorValue> operatorValue = new ArrayList<>();
76 + BgpFlowSpecRibOut ribOut = new BgpFlowSpecRibOut();
77 +
78 + IpPrefix destinationPrefix = IpPrefix.valueOf(IpAddress.valueOf("10.0.1.1"), 32);
79 + IpPrefix sourcePrefix = IpPrefix.valueOf(IpAddress.valueOf("10.0.1.2"), 32);
80 +
81 + BgpFlowSpecPrefix prefix = new BgpFlowSpecPrefix(destinationPrefix, sourcePrefix);
82 + byte[] port = new byte[] {(byte) 0x1 };
83 + operatorValue.add(new BgpFsOperatorValue((byte) 0x81, port));
84 +
85 + BgpFsPortNum portNum = new BgpFsPortNum(operatorValue);
86 + flowSpecComponents.add(portNum);
87 +
88 + BgpFlowSpecDetails flowSpec = new BgpFlowSpecDetails(flowSpecComponents);
89 +
90 + ribOut.add(prefix, flowSpec);
91 +
92 + boolean isPresent = ribOut.flowSpecTree().containsKey(prefix);
93 + assertThat(isPresent, is(true));
94 +
95 + ribOut.delete(prefix);
96 + isPresent = ribOut.flowSpecTree().containsKey(prefix);
97 + assertThat(isPresent, is(false));
98 +
99 + }
100 +
101 + /**
102 + * Add and delete flow specification with a specific VPN to rib out.
103 + */
104 + @Test
105 + public void bgpFlowSpecRibOutTest3() {
106 + List<BgpValueType> flowSpecComponents = new LinkedList<>();
107 + List<BgpFsOperatorValue> operatorValue = new ArrayList<>();
108 + RouteDistinguisher routeDistinguisher = new RouteDistinguisher(1);
109 + BgpFlowSpecRibOut ribOut = new BgpFlowSpecRibOut();
110 +
111 + IpPrefix destinationPrefix = IpPrefix.valueOf(IpAddress.valueOf("10.0.1.1"), 32);
112 + IpPrefix sourcePrefix = IpPrefix.valueOf(IpAddress.valueOf("10.0.1.2"), 32);
113 +
114 + BgpFlowSpecPrefix prefix = new BgpFlowSpecPrefix(destinationPrefix, sourcePrefix);
115 +
116 + byte[] port = new byte[] {(byte) 0x1 };
117 + operatorValue.add(new BgpFsOperatorValue((byte) 0x81, port));
118 +
119 + BgpFsPortNum portNum = new BgpFsPortNum(operatorValue);
120 + flowSpecComponents.add(portNum);
121 +
122 + BgpFlowSpecDetails flowSpec = new BgpFlowSpecDetails(flowSpecComponents);
123 +
124 + ribOut.add(routeDistinguisher, prefix, flowSpec);
125 +
126 + boolean isPresent = ribOut.vpnFlowSpecTree().containsKey(routeDistinguisher);
127 + assertThat(isPresent, is(true));
128 +
129 + ribOut.delete(routeDistinguisher, prefix);
130 + isPresent = ribOut.vpnFlowSpecTree().containsKey(routeDistinguisher);
131 + assertThat(isPresent, is(false));
132 + }
133 +}