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