blob: b41fe07ecc21aef6520f29e8557f9b12c64af0d1 [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;
Andreas Pantelopoulosb281ae22018-05-01 14:56:05 -070036 ds1 = DestinationSet.createTypePushNone(d201);
37 ds2 = DestinationSet.createTypePushBos(el201, d201);
38 ds3 = DestinationSet.createTypePushBos(el201, d201, el202, d202);
39 ds4 = DestinationSet.createTypePushBos(DestinationSet.NO_EDGE_LABEL, d201,
40 DestinationSet.NO_EDGE_LABEL, d202);
41 ds5 = DestinationSet.createTypePopNotBos(d201);
42 ds6 = DestinationSet.createTypeSwapBos(el201, d201);
Saurav Das261c3002017-06-13 15:35:54 -070043 }
44
45 @Test
46 public void testIsValid() {
Saurav Das97241862018-02-14 14:14:54 -080047 assertTrue(!ds1.notBos());
48 assertTrue(!ds1.swap());
Saurav Das261c3002017-06-13 15:35:54 -070049 assertTrue(ds1.getEdgeLabel(d201) == DestinationSet.NO_EDGE_LABEL);
50 assertTrue(ds1.getDestinationSwitches().size() == 1);
51
Saurav Das97241862018-02-14 14:14:54 -080052 assertTrue(!ds2.notBos());
53 assertTrue(!ds2.swap());
Saurav Das261c3002017-06-13 15:35:54 -070054 assertTrue(ds2.getEdgeLabel(d201) == el201);
55 assertTrue(ds2.getDestinationSwitches().size() == 1);
56
Saurav Das97241862018-02-14 14:14:54 -080057 assertTrue(!ds3.notBos());
58 assertTrue(!ds3.swap());
Saurav Das261c3002017-06-13 15:35:54 -070059 assertTrue(ds3.getEdgeLabel(d201) == el201);
60 assertTrue(ds3.getEdgeLabel(d202) == el202);
61 assertTrue(ds3.getDestinationSwitches().size() == 2);
62
Saurav Das97241862018-02-14 14:14:54 -080063 assertTrue(!ds4.notBos());
64 assertTrue(!ds4.swap());
Saurav Das261c3002017-06-13 15:35:54 -070065 assertTrue(ds4.getEdgeLabel(d201) == DestinationSet.NO_EDGE_LABEL);
66 assertTrue(ds4.getEdgeLabel(d202) == DestinationSet.NO_EDGE_LABEL);
67 assertTrue(ds4.getDestinationSwitches().size() == 2);
68
69 assertFalse(ds1.equals(ds2));
70 assertFalse(ds1.equals(ds4));
71 assertFalse(ds3.equals(ds4));
72 assertFalse(ds2.equals(ds3));
Saurav Das97241862018-02-14 14:14:54 -080073 assertFalse(ds1.equals(ds3));
74
75 assertFalse(ds1.equals(ds5));
76 assertFalse(ds2.equals(ds6));
Saurav Das261c3002017-06-13 15:35:54 -070077 }
78
79
80 @Test
81 public void testOneDestinationWithoutLabel() {
Andreas Pantelopoulosb281ae22018-05-01 14:56:05 -070082 DestinationSet testds = DestinationSet.createTypePushNone(d201);
Saurav Das261c3002017-06-13 15:35:54 -070083 assertTrue(testds.equals(ds1)); // match
84
Andreas Pantelopoulosb281ae22018-05-01 14:56:05 -070085 testds = DestinationSet.createTypePopNotBos(d201);
Saurav Das97241862018-02-14 14:14:54 -080086 assertFalse(testds.equals(ds1)); // wrong notBos
87 assertTrue(testds.equals(ds5)); // correct notBos
Saurav Das261c3002017-06-13 15:35:54 -070088
Andreas Pantelopoulosb281ae22018-05-01 14:56:05 -070089 testds = DestinationSet.createTypePushNone(d202);
Saurav Das261c3002017-06-13 15:35:54 -070090 assertFalse(testds.equals(ds1)); //wrong device
91
Andreas Pantelopoulosb281ae22018-05-01 14:56:05 -070092 testds = DestinationSet.createTypePushBos(el201, d201);
Saurav Das261c3002017-06-13 15:35:54 -070093 assertFalse(testds.equals(ds1)); // wrong label
94
Andreas Pantelopoulosb281ae22018-05-01 14:56:05 -070095 testds = DestinationSet.createTypePushBos(-1, d201, -1, d202);
Saurav Das261c3002017-06-13 15:35:54 -070096 assertFalse(testds.equals(ds1)); // 2-devs should not match
Saurav Das97241862018-02-14 14:14:54 -080097
Andreas Pantelopoulosb281ae22018-05-01 14:56:05 -070098 testds = DestinationSet.createTypeSwapBos(el201, d201);
99 assertFalse(testds.equals(ds1)); // wrong type and label
Saurav Das97241862018-02-14 14:14:54 -0800100 assertTrue(testds.equals(ds6)); // correct swap
101
Andreas Pantelopoulosb281ae22018-05-01 14:56:05 -0700102 testds = DestinationSet.createTypeSwapNotBos(el201, d201);
Saurav Das97241862018-02-14 14:14:54 -0800103 assertFalse(testds.equals(ds6)); // wrong notbos
Saurav Das261c3002017-06-13 15:35:54 -0700104 }
105
106
107
108 @Test
109 public void testOneDestinationWithLabel() {
Andreas Pantelopoulosb281ae22018-05-01 14:56:05 -0700110 DestinationSet testds = DestinationSet.createTypePushBos(203, d202);
Saurav Das261c3002017-06-13 15:35:54 -0700111 assertFalse(testds.equals(ds2)); //wrong label
112
Andreas Pantelopoulosb281ae22018-05-01 14:56:05 -0700113 testds = DestinationSet.createTypePushBos(201, d202);
Saurav Das261c3002017-06-13 15:35:54 -0700114 assertFalse(testds.equals(ds2)); //wrong device
115
Andreas Pantelopoulosb281ae22018-05-01 14:56:05 -0700116 testds = DestinationSet.createTypePushBos(201, DeviceId.deviceId("of:0000000000000201"));
Saurav Das261c3002017-06-13 15:35:54 -0700117 assertTrue(testds.equals(ds2)); // match
118
Andreas Pantelopoulosb281ae22018-05-01 14:56:05 -0700119 testds = DestinationSet.createTypePushNone(d201);
Saurav Das261c3002017-06-13 15:35:54 -0700120 assertFalse(testds.equals(ds2)); // wrong label
121
Andreas Pantelopoulosb281ae22018-05-01 14:56:05 -0700122 testds = DestinationSet.createTypePushBos(el201, d201, el202, d202);
Saurav Das261c3002017-06-13 15:35:54 -0700123 assertFalse(testds.equals(ds1)); // 2-devs should not match
124 }
125
126 @Test
127 public void testDestPairWithLabel() {
Andreas Pantelopoulosb281ae22018-05-01 14:56:05 -0700128 DestinationSet testds = DestinationSet.createTypePushBos(el201, d201, el202, d202);
Saurav Das261c3002017-06-13 15:35:54 -0700129 assertTrue(testds.equals(ds3)); // match same switches, same order
130 assertTrue(testds.hashCode() == ds3.hashCode());
131
Andreas Pantelopoulosb281ae22018-05-01 14:56:05 -0700132 testds = DestinationSet.createTypePushBos(el202, d202, el201, d201);
Saurav Das261c3002017-06-13 15:35:54 -0700133 assertTrue(testds.equals(ds3)); // match same switches, order reversed
134 assertTrue(testds.hashCode() == ds3.hashCode());
135
Andreas Pantelopoulosb281ae22018-05-01 14:56:05 -0700136 testds = DestinationSet.createTypePushBos(el202, d202);
Saurav Das261c3002017-06-13 15:35:54 -0700137 assertFalse(testds.equals(ds3)); // one less switch should not match
138 assertFalse(testds.hashCode() == ds3.hashCode());
139
Andreas Pantelopoulosb281ae22018-05-01 14:56:05 -0700140 testds = DestinationSet.createTypePushBos(el201, d201);
Saurav Das261c3002017-06-13 15:35:54 -0700141 assertFalse(testds.equals(ds3)); // one less switch should not match
142 assertFalse(testds.hashCode() == ds3.hashCode());
143
Andreas Pantelopoulosb281ae22018-05-01 14:56:05 -0700144 testds = DestinationSet.createTypePushBos(el201, d201, 0, DeviceId.NONE);
Saurav Das261c3002017-06-13 15:35:54 -0700145 assertFalse(testds.equals(ds3)); // one less switch should not match
146 assertFalse(testds.hashCode() == ds3.hashCode());
147
Andreas Pantelopoulosb281ae22018-05-01 14:56:05 -0700148 testds = DestinationSet.createTypePushBos(el201, d202, el201, d201);
Saurav Das261c3002017-06-13 15:35:54 -0700149 assertFalse(testds.equals(ds3)); // wrong labels
150 assertFalse(testds.hashCode() == ds3.hashCode());
151
Andreas Pantelopoulosb281ae22018-05-01 14:56:05 -0700152 testds = DestinationSet.createTypePushBos(el202, d202, el201, d202);
Saurav Das261c3002017-06-13 15:35:54 -0700153 assertFalse(testds.equals(ds3)); // wrong device
154 assertFalse(testds.hashCode() == ds3.hashCode());
155
Andreas Pantelopoulosb281ae22018-05-01 14:56:05 -0700156 testds = DestinationSet.createTypePushBos(
Saurav Das261c3002017-06-13 15:35:54 -0700157 el202, DeviceId.deviceId("of:0000000000000205"),
158 el201, d201);
159 assertFalse(testds.equals(ds3)); // wrong device
160 assertFalse(testds.hashCode() == ds3.hashCode());
161 }
162
163 @Test
164 public void testDestPairWithoutLabel() {
Andreas Pantelopoulosb281ae22018-05-01 14:56:05 -0700165 DestinationSet testds = DestinationSet.createTypePushBos(-1, d201, -1, d202);
Saurav Das261c3002017-06-13 15:35:54 -0700166 assertTrue(testds.equals(ds4)); // match same switches, same order
167 assertTrue(testds.hashCode() == ds4.hashCode());
168
Andreas Pantelopoulosb281ae22018-05-01 14:56:05 -0700169 testds = DestinationSet.createTypePushBos(-1, d202, -1, d201);
Saurav Das261c3002017-06-13 15:35:54 -0700170 assertTrue(testds.equals(ds4)); // match same switches, order reversed
171 assertTrue(testds.hashCode() == ds4.hashCode());
172
Andreas Pantelopoulosb281ae22018-05-01 14:56:05 -0700173 testds = DestinationSet.createTypePushBos(-1, d202);
Saurav Das261c3002017-06-13 15:35:54 -0700174 assertFalse(testds.equals(ds4)); // one less switch should not match
175 assertFalse(testds.hashCode() == ds4.hashCode());
176
Andreas Pantelopoulosb281ae22018-05-01 14:56:05 -0700177 testds = DestinationSet.createTypePushBos(-1, d201);
Saurav Das261c3002017-06-13 15:35:54 -0700178 assertFalse(testds.equals(ds4)); // one less switch should not match
179 assertFalse(testds.hashCode() == ds4.hashCode());
180
Andreas Pantelopoulosb281ae22018-05-01 14:56:05 -0700181 testds = DestinationSet.createTypePushBos(-1, d201, 0, DeviceId.NONE);
Saurav Das261c3002017-06-13 15:35:54 -0700182 assertFalse(testds.equals(ds4)); // one less switch should not match
183 assertFalse(testds.hashCode() == ds4.hashCode());
184
Andreas Pantelopoulosb281ae22018-05-01 14:56:05 -0700185 testds = DestinationSet.createTypePushBos(el201, d201, -1, d202);
Saurav Das261c3002017-06-13 15:35:54 -0700186 assertFalse(testds.equals(ds4)); // wrong labels
187 assertFalse(testds.hashCode() == ds4.hashCode());
188
Andreas Pantelopoulosb281ae22018-05-01 14:56:05 -0700189 testds = DestinationSet.createTypePushBos(-1, d202, -1, d202);
Saurav Das261c3002017-06-13 15:35:54 -0700190 assertFalse(testds.equals(ds4)); // wrong device
191 assertFalse(testds.hashCode() == ds4.hashCode());
192
Andreas Pantelopoulosb281ae22018-05-01 14:56:05 -0700193 testds = DestinationSet.createTypePushBos(
Saurav Das261c3002017-06-13 15:35:54 -0700194 -1, DeviceId.deviceId("of:0000000000000205"),
195 -1, d201);
196 assertFalse(testds.equals(ds4)); // wrong device
197 assertFalse(testds.hashCode() == ds4.hashCode());
198 }
199
200}