blob: e6dd92190f97d46355f25cda4b26da85b6d71a4f [file] [log] [blame]
Carolina Fernandezad893432016-07-18 11:11:34 +02001/*
2 * Copyright 2016-present 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
17package org.onosproject.sdxl2;
18
19import org.junit.After;
20import org.junit.Before;
21import org.junit.Test;
22import org.onlab.packet.VlanId;
23import org.onosproject.TestApplicationId;
24import org.onosproject.core.ApplicationId;
25import org.onosproject.net.ConnectPoint;
26import org.onosproject.net.EncapsulationType;
27import org.onosproject.net.flow.DefaultTrafficSelector;
28import org.onosproject.net.flow.DefaultTrafficTreatment;
29import org.onosproject.net.flow.TrafficSelector;
30import org.onosproject.net.flow.TrafficTreatment;
31import org.onosproject.net.intent.AbstractIntentTest;
32import org.onosproject.net.intent.Constraint;
33import org.onosproject.net.intent.Intent;
34import org.onosproject.net.intent.IntentUtils;
35import org.onosproject.net.intent.Key;
36import org.onosproject.net.intent.PointToPointIntent;
37import org.onosproject.net.intent.constraint.EncapsulationConstraint;
38
39import java.util.ArrayList;
40import java.util.Arrays;
41import java.util.Collections;
42import java.util.Iterator;
43import java.util.LinkedList;
44import java.util.List;
45import java.util.Optional;
46
47import static java.lang.String.format;
48import static org.junit.Assert.assertEquals;
49import static org.junit.Assert.assertTrue;
50
51/**
52 * Unit tests for SdxL2VlanVCManager.
53 */
54public class SdxL2VlanVCManagerTest extends AbstractIntentTest {
55
56 private static final String SDXL2_2 = "sdxl2_test2";
57 private static final String CP1 = "of:00000000000001/1";
58 private static final String CP2 = "of:00000000000002/1";
59 private static final String CP5 = "of:00000000000002/4";
60 private static final String CP6 = "of:00000000000004/4";
61 private static final String CP7 = "of:0000000000000a/4";
62 private static final String CP8 = "of:00000000000009/4";
63 private static final String CP9 = "of:0000000000000a/4";
64 private static final String CP10 = "of:00000000000009/4";
65 private static final String VLANS1 = "2,3,4";
66 private static final ArrayList<String> VLANS1_ARRAY =
67 new ArrayList<String>(Arrays.asList(VLANS1.split(",")));;
68 private static final String VLANS2 = "4,5,6";
69 private static final ArrayList<String> VLANS2_ARRAY =
70 new ArrayList<String>(Arrays.asList(VLANS2.split(",")));;
71 private static final String VLANS5 = "100";
72 private static final String VLANS6 = "1";
73 private static final String VLANS7 = "1";
74 private static final String VLANS8 = "111";
75 private static final String VLANS9 = "1";
76 private static final String VLANS10 = "1";
77 private static final String NAME_FORMAT = "%s:%s-%s";
78 private static final String KEY_FORMAT = "%s,%s";
79 private static final ApplicationId APPID = TestApplicationId.create("foo");
80 private static final int POINT_TO_POINT_INDEXES = 3;
81 private SdxL2VlanVCManager manager;
82 private List<PointToPointIntent> intentList;
83
84 /**
85 * Prepare environment before starting testing VLAN-based VCs.
86 */
87 @Before
88 public void setUp() throws Exception {
89 super.setUp();
90 SdxL2DistributedStore store = new SdxL2DistributedStore();
91 store.initForTest();
92 manager = new SdxL2VlanVCManager(
93 APPID, store, new IntentServiceTest());
94 intentList = setIntents();
95 }
96
97 /**
98 * Clean up environment after finishing testing VLAN-based VCs.
99 */
100 @After
101 public void tearDown() {
102 super.tearDown();
103 }
104
105 public List<PointToPointIntent> setIntents() {
106 List<PointToPointIntent> intents = new ArrayList<PointToPointIntent>();
107 List<Constraint> encapsulation = buildConstraints();
108
109 SdxL2ConnectionPoint cpone = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST1", CP1, VLANS1);
110 SdxL2ConnectionPoint cptwo = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST2", CP2, VLANS2);
111 for (int i = 0; i < POINT_TO_POINT_INDEXES; i++) {
112 intents.add(PointToPointIntent.builder()
113 .appId(APPID)
114 .key(generateIntentKey(SDXL2_2, cpone, cptwo, Integer.toString(i + 1))) // 1
115 .selector(buildSelector(null, VlanId.vlanId(Short.parseShort(VLANS1_ARRAY.get(i)))))
116 .treatment(buildTreatment(
117 VlanId.vlanId(Short.parseShort(VLANS2_ARRAY.get(i))), null, false))
118 .constraints(encapsulation)
119 .ingressPoint(ConnectPoint.deviceConnectPoint(CP1))
120 .egressPoint(ConnectPoint.deviceConnectPoint(CP2))
121 .priority(2000)
122 .build());
123 intents.add(PointToPointIntent.builder()
124 .appId(APPID)
125 .key(generateIntentKey(SDXL2_2, cptwo, cpone, Integer.toString(i + 1)))
126 .selector(buildSelector(null, VlanId.vlanId(Short.parseShort(VLANS2_ARRAY.get(i)))))
127 .treatment(buildTreatment(
128 VlanId.vlanId(Short.parseShort(VLANS1_ARRAY.get(i))), null, false))
129 .constraints(encapsulation)
130 .ingressPoint(ConnectPoint.deviceConnectPoint(CP2))
131 .egressPoint(ConnectPoint.deviceConnectPoint(CP1))
132 .priority(2000)
133 .build());
134 }
135
136 SdxL2ConnectionPoint cpfive = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST5", CP5, VLANS5);
137 SdxL2ConnectionPoint cpsix = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST6", CP6, VLANS6);
138 intents.add(PointToPointIntent.builder()
139 .appId(APPID)
140 .key(generateIntentKey(SDXL2_2, cpfive, cpsix, "1"))
141 .selector(buildSelector(null, VlanId.vlanId(Short.parseShort("100"))))
142 .treatment(buildTreatment(null, null, true))
143 .constraints(encapsulation)
144 .ingressPoint(ConnectPoint.deviceConnectPoint(CP5))
145 .egressPoint(ConnectPoint.deviceConnectPoint(CP6))
146 .priority(2000)
147 .build());
148 intents.add(PointToPointIntent.builder()
149 .appId(APPID)
150 .key(generateIntentKey(SDXL2_2, cpsix, cpfive, "1"))
151 .selector(buildSelector(null, null))
152 .constraints(encapsulation)
153 .treatment(buildTreatment(null, VlanId.vlanId(Short.parseShort("100")), false))
154 .ingressPoint(ConnectPoint.deviceConnectPoint(CP6))
155 .egressPoint(ConnectPoint.deviceConnectPoint(CP5))
156 .priority(2000)
157 .build());
158
159 SdxL2ConnectionPoint cpseven = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST7", CP7, VLANS7);
160 SdxL2ConnectionPoint cpeight = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST8", CP8, VLANS8);
161 intents.add(PointToPointIntent.builder()
162 .appId(APPID)
163 .key(generateIntentKey(SDXL2_2, cpseven, cpeight, "1"))
164 .selector(buildSelector(null, null))
165 .treatment(buildTreatment(null, VlanId.vlanId(Short.parseShort("111")), false))
166 .constraints(encapsulation)
167 .ingressPoint(ConnectPoint.deviceConnectPoint(CP7))
168 .egressPoint(ConnectPoint.deviceConnectPoint(CP8))
169 .priority(2000)
170 .build());
171 intents.add(PointToPointIntent.builder()
172 .appId(APPID)
173 .key(generateIntentKey(SDXL2_2, cpeight, cpseven, "1"))
174 .selector(buildSelector(null, VlanId.vlanId(Short.parseShort("111"))))
175 .constraints(encapsulation)
176 .treatment(buildTreatment(null, null, true))
177 .ingressPoint(ConnectPoint.deviceConnectPoint(CP8))
178 .egressPoint(ConnectPoint.deviceConnectPoint(CP7))
179 .priority(2000)
180 .build());
181
182 SdxL2ConnectionPoint cpnine = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST9", CP9, VLANS9);
183 SdxL2ConnectionPoint cpten = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST10", CP10, VLANS10);
184 intents.add(PointToPointIntent.builder()
185 .appId(APPID)
186 .key(generateIntentKey(SDXL2_2, cpnine, cpten, "1"))
187 .selector(buildSelector(null, null))
188 .constraints(encapsulation)
189 .treatment(buildTreatment(null, null, false))
190 .ingressPoint(ConnectPoint.deviceConnectPoint(CP9))
191 .egressPoint(ConnectPoint.deviceConnectPoint(CP10))
192 .priority(2000)
193 .build());
194 intents.add(PointToPointIntent.builder()
195 .appId(APPID)
196 .key(generateIntentKey(SDXL2_2, cpten, cpnine, "1"))
197 .selector(buildSelector(null, null))
198 .constraints(encapsulation)
199 .treatment(buildTreatment(null, null, false))
200 .ingressPoint(ConnectPoint.deviceConnectPoint(CP10))
201 .egressPoint(ConnectPoint.deviceConnectPoint(CP9))
202 .priority(2000)
203 .build());
204
205 return intents;
206 }
207
208 private TrafficTreatment buildTreatment(VlanId setVlan,
209 VlanId pushVlan,
210 boolean popVlan) {
211
212 TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
213 if (setVlan != null) {
214 treatmentBuilder.setVlanId(setVlan);
215 }
216 if (pushVlan != null) {
217 treatmentBuilder.pushVlan();
218 treatmentBuilder.setVlanId(pushVlan);
219 }
220 if (popVlan) {
221 treatmentBuilder.popVlan();
222 }
223 return treatmentBuilder.build();
224 }
225
226 private TrafficSelector buildSelector(Short ethertype,
227 VlanId ingresstag) {
228
229 TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
230 if (ethertype != null) {
231 selectorBuilder.matchEthType(ethertype);
232 }
233 if (ingresstag != null) {
234 selectorBuilder.matchVlanId(ingresstag);
235 }
236 return selectorBuilder.build();
237 }
238
239 protected List<Constraint> buildConstraints() {
240 final List<Constraint> constraints = new LinkedList<>();
241 constraints.add(new EncapsulationConstraint(EncapsulationType.VLAN));
242 return constraints;
243 }
244
245 private Key generateIntentKey(String sdxl2, SdxL2ConnectionPoint cpone, SdxL2ConnectionPoint cptwo, String index) {
246 String cps = format(NAME_FORMAT, sdxl2, cpone.name(), cptwo.name());
247 String key = format(KEY_FORMAT, cps, index);
248 return Key.of(key, APPID);
249 }
250
251 @Test
252 public void testConnectionSetup() {
253 Iterator<SdxL2ConnectionPoint> lhs = setupLhsCPs().iterator();
254 Iterator<SdxL2ConnectionPoint> rhs = setupRhsCPs().iterator();
255 while (lhs.hasNext() && rhs.hasNext()) {
256 manager.addVC(SDXL2_2, lhs.next(), rhs.next());
257 }
258
259 assertEquals(intentList.size(), manager.intentService.getIntentCount());
260
261 for (Intent emulatedIntent : intentList) {
262 boolean found = false;
263 for (Intent realIntent : manager.intentService.getIntents()) {
264 if (emulatedIntent.key().equals(realIntent.key())) {
265 found = true;
266 assertTrue(format("Comparing %s and %s", emulatedIntent, realIntent),
267 IntentUtils.intentsAreEqual(emulatedIntent, realIntent));
268 break;
269 }
270 }
271 assertTrue(found);
272 }
273 }
274
275 public List<SdxL2ConnectionPoint> setupLhsCPs() {
276 List<SdxL2ConnectionPoint> cps = new ArrayList<SdxL2ConnectionPoint>();
277 SdxL2ConnectionPoint cpone = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST1", CP1, VLANS1);
278 cps.add(cpone);
279 SdxL2ConnectionPoint cpfive = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST5", CP5, VLANS5);
280 cps.add(cpfive);
281 SdxL2ConnectionPoint cpseven = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST7", CP7, VLANS7);
282 cps.add(cpseven);
283 SdxL2ConnectionPoint cpnine = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST9", CP9, VLANS9);
284 cps.add(cpnine);
285 return cps;
286 }
287
288 public List<SdxL2ConnectionPoint> setupRhsCPs() {
289 List<SdxL2ConnectionPoint> cps = new ArrayList<SdxL2ConnectionPoint>();
290 SdxL2ConnectionPoint cptwo = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST2", CP2, VLANS2);
291 cps.add(cptwo);
292 SdxL2ConnectionPoint cpsix = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST6", CP6, VLANS6);
293 cps.add(cpsix);
294 SdxL2ConnectionPoint cpeight = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST8", CP8, VLANS8);
295 cps.add(cpeight);
296 SdxL2ConnectionPoint cpten = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST10", CP10, VLANS10);
297 cps.add(cpten);
298 return cps;
299 }
300
301
302 @Test
303 public void removeConnection() {
304 testConnectionSetup();
305
306 List<PointToPointIntent> removedIntents = new ArrayList<PointToPointIntent>();
307 SdxL2ConnectionPoint cpone = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST1", CP1, VLANS1);
308 SdxL2ConnectionPoint cptwo = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST2", CP2, VLANS2);
309
310 removedIntents.add(PointToPointIntent.builder()
311 .appId(APPID)
312 .key(generateIntentKey(SDXL2_2, cpone, cptwo, "1"))
313 .selector(buildSelector(null, VlanId.vlanId(Short.parseShort("2"))))
314 .treatment(buildTreatment(VlanId.vlanId(Short.parseShort("4")), null, false))
315 .ingressPoint(ConnectPoint.deviceConnectPoint(CP1))
316 .egressPoint(ConnectPoint.deviceConnectPoint(CP2))
317 .priority(2000)
318 .build());
319 removedIntents.add(PointToPointIntent.builder()
320 .appId(APPID)
321 .key(generateIntentKey(SDXL2_2, cptwo, cpone, "1"))
322 .selector(buildSelector(null, VlanId.vlanId(Short.parseShort("4"))))
323 .treatment(buildTreatment(VlanId.vlanId(Short.parseShort("2")), null, false))
324 .ingressPoint(ConnectPoint.deviceConnectPoint(CP2))
325 .egressPoint(ConnectPoint.deviceConnectPoint(CP1))
326 .priority(2000)
327 .build());
328 removedIntents.add(PointToPointIntent.builder()
329 .appId(APPID)
330 .key(generateIntentKey(SDXL2_2, cpone, cptwo, "2"))
331 .selector(buildSelector(null, VlanId.vlanId(Short.parseShort("3"))))
332 .treatment(buildTreatment(VlanId.vlanId(Short.parseShort("5")), null, false))
333 .ingressPoint(ConnectPoint.deviceConnectPoint(CP1))
334 .egressPoint(ConnectPoint.deviceConnectPoint(CP2))
335 .priority(2000)
336 .build());
337 removedIntents.add(PointToPointIntent.builder()
338 .appId(APPID)
339 .key(generateIntentKey(SDXL2_2, cptwo, cpone, "2"))
340 .selector(buildSelector(null, VlanId.vlanId(Short.parseShort("5"))))
341 .treatment(buildTreatment(VlanId.vlanId(Short.parseShort("3")), null, false))
342 .ingressPoint(ConnectPoint.deviceConnectPoint(CP2))
343 .egressPoint(ConnectPoint.deviceConnectPoint(CP1))
344 .priority(2000)
345 .build());
346 removedIntents.add(PointToPointIntent.builder()
347 .appId(APPID)
348 .key(generateIntentKey(SDXL2_2, cpone, cptwo, "3"))
349 .selector(buildSelector(null, VlanId.vlanId(Short.parseShort("4"))))
350 .treatment(buildTreatment(VlanId.vlanId(Short.parseShort("6")), null, false))
351 .ingressPoint(ConnectPoint.deviceConnectPoint(CP1))
352 .egressPoint(ConnectPoint.deviceConnectPoint(CP2))
353 .priority(2000)
354 .build());
355 removedIntents.add(PointToPointIntent.builder()
356 .appId(APPID)
357 .key(generateIntentKey(SDXL2_2, cptwo, cpone, "3"))
358 .selector(buildSelector(null, VlanId.vlanId(Short.parseShort("6"))))
359 .treatment(buildTreatment(VlanId.vlanId(Short.parseShort("4")), null, false))
360 .ingressPoint(ConnectPoint.deviceConnectPoint(CP2))
361 .egressPoint(ConnectPoint.deviceConnectPoint(CP1))
362 .priority(2000)
363 .build());
364
365 SdxL2ConnectionPoint cpfive = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST5", CP5, VLANS5);
366 SdxL2ConnectionPoint cpsix = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST6", CP6, VLANS6);
367 removedIntents.add(PointToPointIntent.builder()
368 .appId(APPID)
369 .key(generateIntentKey(SDXL2_2, cpfive, cpsix, "1"))
370 .selector(buildSelector(null, VlanId.vlanId(Short.parseShort("100"))))
371 .treatment(buildTreatment(null, null, true))
372 .ingressPoint(ConnectPoint.deviceConnectPoint(CP5))
373 .egressPoint(ConnectPoint.deviceConnectPoint(CP6))
374 .priority(2000)
375 .build());
376 removedIntents.add(PointToPointIntent.builder()
377 .appId(APPID)
378 .key(generateIntentKey(SDXL2_2, cpsix, cpfive, "1"))
379 .selector(buildSelector(null, null))
380 .treatment(buildTreatment(null, VlanId.vlanId(Short.parseShort("100")), false))
381 .ingressPoint(ConnectPoint.deviceConnectPoint(CP6))
382 .egressPoint(ConnectPoint.deviceConnectPoint(CP5))
383 .priority(2000)
384 .build());
385
386 SdxL2ConnectionPoint cpseven = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST7", CP7, VLANS7);
387 SdxL2ConnectionPoint cpeight = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST8", CP8, VLANS8);
388 removedIntents.add(PointToPointIntent.builder()
389 .appId(APPID)
390 .key(generateIntentKey(SDXL2_2, cpseven, cpeight, "1"))
391 .selector(buildSelector(null, null))
392 .treatment(buildTreatment(null, VlanId.vlanId(Short.parseShort("111")), false))
393 .ingressPoint(ConnectPoint.deviceConnectPoint(CP7))
394 .egressPoint(ConnectPoint.deviceConnectPoint(CP8))
395 .priority(2000)
396 .build());
397 removedIntents.add(PointToPointIntent.builder()
398 .appId(APPID)
399 .key(generateIntentKey(SDXL2_2, cpeight, cpseven, "1"))
400 .selector(buildSelector(null, VlanId.vlanId(Short.parseShort("111"))))
401 .treatment(buildTreatment(null, null, true))
402 .ingressPoint(ConnectPoint.deviceConnectPoint(CP8))
403 .egressPoint(ConnectPoint.deviceConnectPoint(CP7))
404 .priority(2000)
405 .build());
406
407 manager.removeVC(cpone, cptwo);
408 manager.removeVC(cpfive, cpsix);
409 manager.removeVC(cpseven, cpeight);
410
411 assertEquals(2, manager.intentService.getIntentCount());
412
413 for (Intent removedIntent : removedIntents) {
414 boolean found = false;
415 for (Intent existingIntent : manager.intentService.getIntents()) {
416 if (removedIntent.key().equals(existingIntent.key())) {
417 found = true;
418 assertTrue(format("Intent %s equal %s", removedIntent, existingIntent),
419 !IntentUtils.intentsAreEqual(removedIntent, existingIntent));
420 break;
421 }
422 }
423 assertTrue(!found);
424 }
425
426 }
427
428
429 @Test
430 public void testRemoveVCbyCP() {
431 testConnectionSetup();
432
433 List<PointToPointIntent> removedIntents = new ArrayList<PointToPointIntent>();
434 SdxL2ConnectionPoint cpone = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST1", CP1, VLANS1);
435 SdxL2ConnectionPoint cptwo = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST2", CP2, VLANS2);
436
437 removedIntents.add(PointToPointIntent.builder()
438 .appId(APPID)
439 .key(generateIntentKey(SDXL2_2, cpone, cptwo, "1"))
440 .selector(buildSelector(null, VlanId.vlanId(Short.parseShort("2"))))
441 .treatment(buildTreatment(VlanId.vlanId(Short.parseShort("4")), null, false))
442 .ingressPoint(ConnectPoint.deviceConnectPoint(CP1))
443 .egressPoint(ConnectPoint.deviceConnectPoint(CP2))
444 .priority(2000)
445 .build());
446 removedIntents.add(PointToPointIntent.builder()
447 .appId(APPID)
448 .key(generateIntentKey(SDXL2_2, cptwo, cpone, "1"))
449 .selector(buildSelector(null, VlanId.vlanId(Short.parseShort("4"))))
450 .treatment(buildTreatment(VlanId.vlanId(Short.parseShort("2")), null, false))
451 .ingressPoint(ConnectPoint.deviceConnectPoint(CP2))
452 .egressPoint(ConnectPoint.deviceConnectPoint(CP1))
453 .priority(2000)
454 .build());
455 removedIntents.add(PointToPointIntent.builder()
456 .appId(APPID)
457 .key(generateIntentKey(SDXL2_2, cpone, cptwo, "2"))
458 .selector(buildSelector(null, VlanId.vlanId(Short.parseShort("3"))))
459 .treatment(buildTreatment(VlanId.vlanId(Short.parseShort("5")), null, false))
460 .ingressPoint(ConnectPoint.deviceConnectPoint(CP1))
461 .egressPoint(ConnectPoint.deviceConnectPoint(CP2))
462 .priority(2000)
463 .build());
464 removedIntents.add(PointToPointIntent.builder()
465 .appId(APPID)
466 .key(generateIntentKey(SDXL2_2, cptwo, cpone, "2"))
467 .selector(buildSelector(null, VlanId.vlanId(Short.parseShort("5"))))
468 .treatment(buildTreatment(VlanId.vlanId(Short.parseShort("3")), null, false))
469 .ingressPoint(ConnectPoint.deviceConnectPoint(CP2))
470 .egressPoint(ConnectPoint.deviceConnectPoint(CP1))
471 .priority(2000)
472 .build());
473 removedIntents.add(PointToPointIntent.builder()
474 .appId(APPID)
475 .key(generateIntentKey(SDXL2_2, cpone, cptwo, "3"))
476 .selector(buildSelector(null, VlanId.vlanId(Short.parseShort("4"))))
477 .treatment(buildTreatment(VlanId.vlanId(Short.parseShort("6")), null, false))
478 .ingressPoint(ConnectPoint.deviceConnectPoint(CP1))
479 .egressPoint(ConnectPoint.deviceConnectPoint(CP2))
480 .priority(2000)
481 .build());
482 removedIntents.add(PointToPointIntent.builder()
483 .appId(APPID)
484 .key(generateIntentKey(SDXL2_2, cptwo, cpone, "3"))
485 .selector(buildSelector(null, VlanId.vlanId(Short.parseShort("6"))))
486 .treatment(buildTreatment(VlanId.vlanId(Short.parseShort("4")), null, false))
487 .ingressPoint(ConnectPoint.deviceConnectPoint(CP2))
488 .egressPoint(ConnectPoint.deviceConnectPoint(CP1))
489 .priority(2000)
490 .build());
491
492 SdxL2ConnectionPoint cpfive = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST5", CP5, VLANS5);
493 SdxL2ConnectionPoint cpsix = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST6", CP6, VLANS6);
494 removedIntents.add(PointToPointIntent.builder()
495 .appId(APPID)
496 .key(generateIntentKey(SDXL2_2, cpfive, cpsix, "1"))
497 .selector(buildSelector(null, VlanId.vlanId(Short.parseShort("100"))))
498 .treatment(buildTreatment(null, null, true))
499 .ingressPoint(ConnectPoint.deviceConnectPoint(CP5))
500 .egressPoint(ConnectPoint.deviceConnectPoint(CP6))
501 .priority(2000)
502 .build());
503 removedIntents.add(PointToPointIntent.builder()
504 .appId(APPID)
505 .key(generateIntentKey(SDXL2_2, cpsix, cpfive, "1"))
506 .selector(buildSelector(null, null))
507 .treatment(buildTreatment(null, VlanId.vlanId(Short.parseShort("100")), false))
508 .ingressPoint(ConnectPoint.deviceConnectPoint(CP6))
509 .egressPoint(ConnectPoint.deviceConnectPoint(CP5))
510 .priority(2000)
511 .build());
512
513 SdxL2ConnectionPoint cpseven = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST7", CP7, VLANS7);
514 SdxL2ConnectionPoint cpeight = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST8", CP8, VLANS8);
515 removedIntents.add(PointToPointIntent.builder()
516 .appId(APPID)
517 .key(generateIntentKey(SDXL2_2, cpseven, cpeight, "1"))
518 .selector(buildSelector(null, null))
519 .treatment(buildTreatment(null, VlanId.vlanId(Short.parseShort("111")), false))
520 .ingressPoint(ConnectPoint.deviceConnectPoint(CP7))
521 .egressPoint(ConnectPoint.deviceConnectPoint(CP8))
522 .priority(2000)
523 .build());
524 removedIntents.add(PointToPointIntent.builder()
525 .appId(APPID)
526 .key(generateIntentKey(SDXL2_2, cpeight, cpseven, "1"))
527 .selector(buildSelector(null, VlanId.vlanId(Short.parseShort("111"))))
528 .treatment(buildTreatment(null, null, true))
529 .ingressPoint(ConnectPoint.deviceConnectPoint(CP8))
530 .egressPoint(ConnectPoint.deviceConnectPoint(CP7))
531 .priority(2000)
532 .build());
533
534 SdxL2ConnectionPoint cpnine = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST9", CP9, VLANS9);
535 SdxL2ConnectionPoint cpten = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST10", CP10, VLANS10);
536 removedIntents.add(PointToPointIntent.builder()
537 .appId(APPID)
538 .key(generateIntentKey(SDXL2_2, cpnine, cpten, "1"))
539 .selector(buildSelector(null, null))
540 .treatment(buildTreatment(null, null, false))
541 .ingressPoint(ConnectPoint.deviceConnectPoint(CP9))
542 .egressPoint(ConnectPoint.deviceConnectPoint(CP10))
543 .priority(2000)
544 .build());
545 removedIntents.add(PointToPointIntent.builder()
546 .appId(APPID)
547 .key(generateIntentKey(SDXL2_2, cpten, cpnine, "1"))
548 .selector(buildSelector(null, null))
549 .treatment(buildTreatment(null, null, false))
550 .ingressPoint(ConnectPoint.deviceConnectPoint(CP10))
551 .egressPoint(ConnectPoint.deviceConnectPoint(CP9))
552 .priority(2000)
553 .build());
554
555 manager.removeVC(cpone);
556 manager.removeVC(cpsix);
557 manager.removeVC(cpseven);
558 manager.removeVC(cpten);
559
560 assertEquals(Collections.emptySet(), manager.getVCs(Optional.ofNullable(null)));
561
562 assertEquals(0, manager.intentService.getIntentCount());
563
564 for (Intent removedIntent : removedIntents) {
565 boolean found = false;
566 for (Intent existingIntent : manager.intentService.getIntents()) {
567 if (removedIntent.key().equals(existingIntent.key())) {
568 found = true;
569 assertTrue(format("Intent %s equal %s", removedIntent, existingIntent),
570 !IntentUtils.intentsAreEqual(removedIntent, existingIntent));
571 break;
572 }
573 }
574 assertTrue(!found);
575 }
576
577 }
578
579 @Test
580 public void testremoveVCbySdx() {
581 testConnectionSetup();
582
583 List<PointToPointIntent> removedIntents = new ArrayList<PointToPointIntent>();
584 SdxL2ConnectionPoint cpone = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST1", CP1, VLANS1);
585 SdxL2ConnectionPoint cptwo = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST2", CP2, VLANS2);
586
587 removedIntents.add(PointToPointIntent.builder()
588 .appId(APPID)
589 .key(generateIntentKey(SDXL2_2, cpone, cptwo, "1"))
590 .selector(buildSelector(null, VlanId.vlanId(Short.parseShort("2"))))
591 .treatment(buildTreatment(VlanId.vlanId(Short.parseShort("4")), null, false))
592 .ingressPoint(ConnectPoint.deviceConnectPoint(CP1))
593 .egressPoint(ConnectPoint.deviceConnectPoint(CP2))
594 .priority(2000)
595 .build());
596 removedIntents.add(PointToPointIntent.builder()
597 .appId(APPID)
598 .key(generateIntentKey(SDXL2_2, cptwo, cpone, "1"))
599 .selector(buildSelector(null, VlanId.vlanId(Short.parseShort("4"))))
600 .treatment(buildTreatment(VlanId.vlanId(Short.parseShort("2")), null, false))
601 .ingressPoint(ConnectPoint.deviceConnectPoint(CP2))
602 .egressPoint(ConnectPoint.deviceConnectPoint(CP1))
603 .priority(2000)
604 .build());
605 removedIntents.add(PointToPointIntent.builder()
606 .appId(APPID)
607 .key(generateIntentKey(SDXL2_2, cpone, cptwo, "2"))
608 .selector(buildSelector(null, VlanId.vlanId(Short.parseShort("3"))))
609 .treatment(buildTreatment(VlanId.vlanId(Short.parseShort("5")), null, false))
610 .ingressPoint(ConnectPoint.deviceConnectPoint(CP1))
611 .egressPoint(ConnectPoint.deviceConnectPoint(CP2))
612 .priority(2000)
613 .build());
614 removedIntents.add(PointToPointIntent.builder()
615 .appId(APPID)
616 .key(generateIntentKey(SDXL2_2, cptwo, cpone, "2"))
617 .selector(buildSelector(null, VlanId.vlanId(Short.parseShort("5"))))
618 .treatment(buildTreatment(VlanId.vlanId(Short.parseShort("3")), null, false))
619 .ingressPoint(ConnectPoint.deviceConnectPoint(CP2))
620 .egressPoint(ConnectPoint.deviceConnectPoint(CP1))
621 .priority(2000)
622 .build());
623 removedIntents.add(PointToPointIntent.builder()
624 .appId(APPID)
625 .key(generateIntentKey(SDXL2_2, cpone, cptwo, "3"))
626 .selector(buildSelector(null, VlanId.vlanId(Short.parseShort("4"))))
627 .treatment(buildTreatment(VlanId.vlanId(Short.parseShort("6")), null, false))
628 .ingressPoint(ConnectPoint.deviceConnectPoint(CP1))
629 .egressPoint(ConnectPoint.deviceConnectPoint(CP2))
630 .priority(2000)
631 .build());
632 removedIntents.add(PointToPointIntent.builder()
633 .appId(APPID)
634 .key(generateIntentKey(SDXL2_2, cptwo, cpone, "3"))
635 .selector(buildSelector(null, VlanId.vlanId(Short.parseShort("6"))))
636 .treatment(buildTreatment(VlanId.vlanId(Short.parseShort("4")), null, false))
637 .ingressPoint(ConnectPoint.deviceConnectPoint(CP2))
638 .egressPoint(ConnectPoint.deviceConnectPoint(CP1))
639 .priority(2000)
640 .build());
641
642 SdxL2ConnectionPoint cpfive = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST5", CP5, VLANS5);
643 SdxL2ConnectionPoint cpsix = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST6", CP6, VLANS6);
644 removedIntents.add(PointToPointIntent.builder()
645 .appId(APPID)
646 .key(generateIntentKey(SDXL2_2, cpfive, cpsix, "1"))
647 .selector(buildSelector(null, VlanId.vlanId(Short.parseShort("100"))))
648 .treatment(buildTreatment(null, null, true))
649 .ingressPoint(ConnectPoint.deviceConnectPoint(CP5))
650 .egressPoint(ConnectPoint.deviceConnectPoint(CP6))
651 .priority(2000)
652 .build());
653 removedIntents.add(PointToPointIntent.builder()
654 .appId(APPID)
655 .key(generateIntentKey(SDXL2_2, cpsix, cpfive, "1"))
656 .selector(buildSelector(null, null))
657 .treatment(buildTreatment(null, VlanId.vlanId(Short.parseShort("100")), false))
658 .ingressPoint(ConnectPoint.deviceConnectPoint(CP6))
659 .egressPoint(ConnectPoint.deviceConnectPoint(CP5))
660 .priority(2000)
661 .build());
662
663 SdxL2ConnectionPoint cpseven = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST7", CP7, VLANS7);
664 SdxL2ConnectionPoint cpeight = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST8", CP8, VLANS8);
665 removedIntents.add(PointToPointIntent.builder()
666 .appId(APPID)
667 .key(generateIntentKey(SDXL2_2, cpseven, cpeight, "1"))
668 .selector(buildSelector(null, null))
669 .treatment(buildTreatment(null, VlanId.vlanId(Short.parseShort("111")), false))
670 .ingressPoint(ConnectPoint.deviceConnectPoint(CP7))
671 .egressPoint(ConnectPoint.deviceConnectPoint(CP8))
672 .priority(2000)
673 .build());
674 removedIntents.add(PointToPointIntent.builder()
675 .appId(APPID)
676 .key(generateIntentKey(SDXL2_2, cpeight, cpseven, "1"))
677 .selector(buildSelector(null, VlanId.vlanId(Short.parseShort("111"))))
678 .treatment(buildTreatment(null, null, true))
679 .ingressPoint(ConnectPoint.deviceConnectPoint(CP8))
680 .egressPoint(ConnectPoint.deviceConnectPoint(CP7))
681 .priority(2000)
682 .build());
683
684 SdxL2ConnectionPoint cpnine = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST9", CP9, VLANS9);
685 SdxL2ConnectionPoint cpten = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST10", CP10, VLANS10);
686 removedIntents.add(PointToPointIntent.builder()
687 .appId(APPID)
688 .key(generateIntentKey(SDXL2_2, cpnine, cpten, "1"))
689 .selector(buildSelector(null, null))
690 .treatment(buildTreatment(null, null, false))
691 .ingressPoint(ConnectPoint.deviceConnectPoint(CP9))
692 .egressPoint(ConnectPoint.deviceConnectPoint(CP10))
693 .priority(2000)
694 .build());
695 removedIntents.add(PointToPointIntent.builder()
696 .appId(APPID)
697 .key(generateIntentKey(SDXL2_2, cpten, cpnine, "1"))
698 .selector(buildSelector(null, null))
699 .treatment(buildTreatment(null, null, false))
700 .ingressPoint(ConnectPoint.deviceConnectPoint(CP10))
701 .egressPoint(ConnectPoint.deviceConnectPoint(CP9))
702 .priority(2000)
703 .build());
704
705 manager.removeVCs(SDXL2_2);
706 assertEquals(Collections.emptySet(), manager.getVCs(Optional.ofNullable(null)));
707 assertEquals(Collections.emptySet(), manager.getVCs(Optional.of(SDXL2_2)));
708
709 for (Intent removedIntent : removedIntents) {
710 boolean found = false;
711 for (Intent existingIntent : manager.intentService.getIntents()) {
712 if (removedIntent.key().equals(existingIntent.key())) {
713 found = true;
714 assertTrue(format("Intent %s equal %s", removedIntent, existingIntent),
715 !IntentUtils.intentsAreEqual(removedIntent, existingIntent));
716 break;
717 }
718 }
719 assertTrue(!found);
720 }
721
722 }
723}