blob: 6abf6e39dcd939ae4a36a6f04752cdf281f4711e [file] [log] [blame]
Saurav Das261c3002017-06-13 15:35:54 -07001/*
2 * Copyright 2017-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.segmentrouting.grouphandler;
17
18import org.junit.Before;
19import org.junit.Test;
20import org.onosproject.net.DeviceId;
21
22import static org.junit.Assert.assertFalse;
23import static org.junit.Assert.assertTrue;
24
25public class DestinationSetTest {
Saurav Das97241862018-02-14 14:14:54 -080026 DestinationSet ds1, ds2, ds3, ds4, ds5, ds6;
Saurav Das261c3002017-06-13 15:35:54 -070027 DeviceId d201, d202;
28 int el201, el202;
29
30 @Before
31 public void setUp() {
32 d201 = DeviceId.deviceId("of:0000000000000201");
33 d202 = DeviceId.deviceId("of:0000000000000202");
34 el201 = 201;
35 el202 = 202;
Saurav Das97241862018-02-14 14:14:54 -080036 ds1 = new DestinationSet(false, false, d201);
37 ds2 = new DestinationSet(false, false, el201, d201);
38 ds3 = new DestinationSet(false, false, el201, d201, el202, d202);
39 ds4 = new DestinationSet(false, false,
Saurav Das261c3002017-06-13 15:35:54 -070040 DestinationSet.NO_EDGE_LABEL, d201,
41 DestinationSet.NO_EDGE_LABEL, d202);
Saurav Das97241862018-02-14 14:14:54 -080042 ds5 = new DestinationSet(true, false, d201); // not-bos
43 ds6 = new DestinationSet(false, true, el201, d201); // swap group
Saurav Das261c3002017-06-13 15:35:54 -070044 }
45
46 @Test
47 public void testIsValid() {
Saurav Das97241862018-02-14 14:14:54 -080048 assertTrue(!ds1.notBos());
49 assertTrue(!ds1.swap());
Saurav Das261c3002017-06-13 15:35:54 -070050 assertTrue(ds1.getEdgeLabel(d201) == DestinationSet.NO_EDGE_LABEL);
51 assertTrue(ds1.getDestinationSwitches().size() == 1);
52
Saurav Das97241862018-02-14 14:14:54 -080053 assertTrue(!ds2.notBos());
54 assertTrue(!ds2.swap());
Saurav Das261c3002017-06-13 15:35:54 -070055 assertTrue(ds2.getEdgeLabel(d201) == el201);
56 assertTrue(ds2.getDestinationSwitches().size() == 1);
57
Saurav Das97241862018-02-14 14:14:54 -080058 assertTrue(!ds3.notBos());
59 assertTrue(!ds3.swap());
Saurav Das261c3002017-06-13 15:35:54 -070060 assertTrue(ds3.getEdgeLabel(d201) == el201);
61 assertTrue(ds3.getEdgeLabel(d202) == el202);
62 assertTrue(ds3.getDestinationSwitches().size() == 2);
63
Saurav Das97241862018-02-14 14:14:54 -080064 assertTrue(!ds4.notBos());
65 assertTrue(!ds4.swap());
Saurav Das261c3002017-06-13 15:35:54 -070066 assertTrue(ds4.getEdgeLabel(d201) == DestinationSet.NO_EDGE_LABEL);
67 assertTrue(ds4.getEdgeLabel(d202) == DestinationSet.NO_EDGE_LABEL);
68 assertTrue(ds4.getDestinationSwitches().size() == 2);
69
70 assertFalse(ds1.equals(ds2));
71 assertFalse(ds1.equals(ds4));
72 assertFalse(ds3.equals(ds4));
73 assertFalse(ds2.equals(ds3));
Saurav Das97241862018-02-14 14:14:54 -080074 assertFalse(ds1.equals(ds3));
75
76 assertFalse(ds1.equals(ds5));
77 assertFalse(ds2.equals(ds6));
Saurav Das261c3002017-06-13 15:35:54 -070078 }
79
80
81 @Test
82 public void testOneDestinationWithoutLabel() {
Saurav Das97241862018-02-14 14:14:54 -080083 DestinationSet testds = new DestinationSet(false, false, d201);
Saurav Das261c3002017-06-13 15:35:54 -070084 assertTrue(testds.equals(ds1)); // match
85
Saurav Das97241862018-02-14 14:14:54 -080086 testds = new DestinationSet(true, false, d201);
87 assertFalse(testds.equals(ds1)); // wrong notBos
88 assertTrue(testds.equals(ds5)); // correct notBos
Saurav Das261c3002017-06-13 15:35:54 -070089
Saurav Das97241862018-02-14 14:14:54 -080090 testds = new DestinationSet(false, false, d202);
Saurav Das261c3002017-06-13 15:35:54 -070091 assertFalse(testds.equals(ds1)); //wrong device
92
Saurav Das97241862018-02-14 14:14:54 -080093 testds = new DestinationSet(false, false, el201, d201);
Saurav Das261c3002017-06-13 15:35:54 -070094 assertFalse(testds.equals(ds1)); // wrong label
95
Saurav Das97241862018-02-14 14:14:54 -080096 testds = new DestinationSet(false, false, -1, d201, -1, d202);
Saurav Das261c3002017-06-13 15:35:54 -070097 assertFalse(testds.equals(ds1)); // 2-devs should not match
Saurav Das97241862018-02-14 14:14:54 -080098
99 testds = new DestinationSet(false, true, d201);
100 assertFalse(testds.equals(ds1)); // wrong swap
101 assertFalse(testds.equals(ds6)); // wrong label
102
103 testds = new DestinationSet(false, true, el201, d201);
104 assertTrue(testds.equals(ds6)); // correct swap
105
106 testds = new DestinationSet(false, true, DestinationSet.NO_EDGE_LABEL, d201);
107 assertFalse(testds.equals(ds6)); // wrong label
108
109 testds = new DestinationSet(true, true, el201, d201);
110 assertFalse(testds.equals(ds6)); // wrong notbos
Saurav Das261c3002017-06-13 15:35:54 -0700111 }
112
113
114
115 @Test
116 public void testOneDestinationWithLabel() {
Saurav Das97241862018-02-14 14:14:54 -0800117 DestinationSet testds = new DestinationSet(false, false, 203, d202);
Saurav Das261c3002017-06-13 15:35:54 -0700118 assertFalse(testds.equals(ds2)); //wrong label
119
Saurav Das97241862018-02-14 14:14:54 -0800120 testds = new DestinationSet(true, false, 201, d201);
121 assertFalse(testds.equals(ds2)); // wrong notBos
Saurav Das261c3002017-06-13 15:35:54 -0700122
Saurav Das97241862018-02-14 14:14:54 -0800123 testds = new DestinationSet(false, false, 201, d202);
Saurav Das261c3002017-06-13 15:35:54 -0700124 assertFalse(testds.equals(ds2)); //wrong device
125
Saurav Das97241862018-02-14 14:14:54 -0800126 testds = new DestinationSet(false, false, 201,
127 DeviceId.deviceId("of:0000000000000201"));
Saurav Das261c3002017-06-13 15:35:54 -0700128 assertTrue(testds.equals(ds2)); // match
129
Saurav Das97241862018-02-14 14:14:54 -0800130 testds = new DestinationSet(false, false, d201);
Saurav Das261c3002017-06-13 15:35:54 -0700131 assertFalse(testds.equals(ds2)); // wrong label
132
Saurav Das97241862018-02-14 14:14:54 -0800133 testds = new DestinationSet(false, false, el201, d201, el202, d202);
Saurav Das261c3002017-06-13 15:35:54 -0700134 assertFalse(testds.equals(ds1)); // 2-devs should not match
135 }
136
137 @Test
138 public void testDestPairWithLabel() {
Saurav Das97241862018-02-14 14:14:54 -0800139 DestinationSet testds = new DestinationSet(false, false, el201, d201, el202, d202);
Saurav Das261c3002017-06-13 15:35:54 -0700140 assertTrue(testds.equals(ds3)); // match same switches, same order
141 assertTrue(testds.hashCode() == ds3.hashCode());
142
Saurav Das97241862018-02-14 14:14:54 -0800143 testds = new DestinationSet(false, false, el202, d202, el201, d201);
Saurav Das261c3002017-06-13 15:35:54 -0700144 assertTrue(testds.equals(ds3)); // match same switches, order reversed
145 assertTrue(testds.hashCode() == ds3.hashCode());
146
Saurav Das97241862018-02-14 14:14:54 -0800147 testds = new DestinationSet(false, false, el202, d202);
Saurav Das261c3002017-06-13 15:35:54 -0700148 assertFalse(testds.equals(ds3)); // one less switch should not match
149 assertFalse(testds.hashCode() == ds3.hashCode());
150
Saurav Das97241862018-02-14 14:14:54 -0800151 testds = new DestinationSet(false, false, el201, d201);
Saurav Das261c3002017-06-13 15:35:54 -0700152 assertFalse(testds.equals(ds3)); // one less switch should not match
153 assertFalse(testds.hashCode() == ds3.hashCode());
154
Saurav Das97241862018-02-14 14:14:54 -0800155 testds = new DestinationSet(false, false, el201, d201, 0, DeviceId.NONE);
Saurav Das261c3002017-06-13 15:35:54 -0700156 assertFalse(testds.equals(ds3)); // one less switch should not match
157 assertFalse(testds.hashCode() == ds3.hashCode());
158
Saurav Das97241862018-02-14 14:14:54 -0800159 testds = new DestinationSet(false, false, el201, d202, el201, d201);
Saurav Das261c3002017-06-13 15:35:54 -0700160 assertFalse(testds.equals(ds3)); // wrong labels
161 assertFalse(testds.hashCode() == ds3.hashCode());
162
Saurav Das97241862018-02-14 14:14:54 -0800163 testds = new DestinationSet(true, false, el202, d202, el201, d201);
164 assertFalse(testds.equals(ds3)); // wrong not bos
Saurav Das261c3002017-06-13 15:35:54 -0700165 assertFalse(testds.hashCode() == ds3.hashCode());
166
Saurav Das97241862018-02-14 14:14:54 -0800167 testds = new DestinationSet(false, false, el202, d202, el201, d202);
Saurav Das261c3002017-06-13 15:35:54 -0700168 assertFalse(testds.equals(ds3)); // wrong device
169 assertFalse(testds.hashCode() == ds3.hashCode());
170
Saurav Das97241862018-02-14 14:14:54 -0800171 testds = new DestinationSet(false, false,
Saurav Das261c3002017-06-13 15:35:54 -0700172 el202, DeviceId.deviceId("of:0000000000000205"),
173 el201, d201);
174 assertFalse(testds.equals(ds3)); // wrong device
175 assertFalse(testds.hashCode() == ds3.hashCode());
176 }
177
178 @Test
179 public void testDestPairWithoutLabel() {
Saurav Das97241862018-02-14 14:14:54 -0800180 DestinationSet testds = new DestinationSet(false, false, -1, d201, -1, d202);
Saurav Das261c3002017-06-13 15:35:54 -0700181 assertTrue(testds.equals(ds4)); // match same switches, same order
182 assertTrue(testds.hashCode() == ds4.hashCode());
183
Saurav Das97241862018-02-14 14:14:54 -0800184 testds = new DestinationSet(false, false, -1, d202, -1, d201);
Saurav Das261c3002017-06-13 15:35:54 -0700185 assertTrue(testds.equals(ds4)); // match same switches, order reversed
186 assertTrue(testds.hashCode() == ds4.hashCode());
187
Saurav Das97241862018-02-14 14:14:54 -0800188 testds = new DestinationSet(false, false, -1, d202);
Saurav Das261c3002017-06-13 15:35:54 -0700189 assertFalse(testds.equals(ds4)); // one less switch should not match
190 assertFalse(testds.hashCode() == ds4.hashCode());
191
Saurav Das97241862018-02-14 14:14:54 -0800192 testds = new DestinationSet(false, false, -1, d201);
Saurav Das261c3002017-06-13 15:35:54 -0700193 assertFalse(testds.equals(ds4)); // one less switch should not match
194 assertFalse(testds.hashCode() == ds4.hashCode());
195
Saurav Das97241862018-02-14 14:14:54 -0800196 testds = new DestinationSet(false, false, -1, d201, 0, DeviceId.NONE);
Saurav Das261c3002017-06-13 15:35:54 -0700197 assertFalse(testds.equals(ds4)); // one less switch should not match
198 assertFalse(testds.hashCode() == ds4.hashCode());
199
Saurav Das97241862018-02-14 14:14:54 -0800200 testds = new DestinationSet(false, false, el201, d201, -1, d202);
Saurav Das261c3002017-06-13 15:35:54 -0700201 assertFalse(testds.equals(ds4)); // wrong labels
202 assertFalse(testds.hashCode() == ds4.hashCode());
203
Saurav Das97241862018-02-14 14:14:54 -0800204 testds = new DestinationSet(true, false, -1, d202, -1, d201);
Saurav Das261c3002017-06-13 15:35:54 -0700205 assertFalse(testds.equals(ds4)); // wrong mpls set
206 assertFalse(testds.hashCode() == ds4.hashCode());
207
Saurav Das97241862018-02-14 14:14:54 -0800208 testds = new DestinationSet(false, false, -1, d202, -1, d202);
Saurav Das261c3002017-06-13 15:35:54 -0700209 assertFalse(testds.equals(ds4)); // wrong device
210 assertFalse(testds.hashCode() == ds4.hashCode());
211
Saurav Das97241862018-02-14 14:14:54 -0800212 testds = new DestinationSet(false, false,
Saurav Das261c3002017-06-13 15:35:54 -0700213 -1, DeviceId.deviceId("of:0000000000000205"),
214 -1, d201);
215 assertFalse(testds.equals(ds4)); // wrong device
216 assertFalse(testds.hashCode() == ds4.hashCode());
217 }
218
219}