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; |
Carolina Fernandez | ad89343 | 2016-07-18 11:11:34 +0200 | [diff] [blame] | 26 | import org.onosproject.net.flow.TrafficSelector; |
| 27 | import org.onosproject.net.flow.TrafficTreatment; |
| 28 | import org.onosproject.net.intent.AbstractIntentTest; |
| 29 | import org.onosproject.net.intent.Constraint; |
| 30 | import org.onosproject.net.intent.Intent; |
| 31 | import org.onosproject.net.intent.IntentUtils; |
| 32 | import org.onosproject.net.intent.Key; |
| 33 | import org.onosproject.net.intent.PointToPointIntent; |
Carolina Fernandez | ad89343 | 2016-07-18 11:11:34 +0200 | [diff] [blame] | 34 | |
| 35 | import java.util.ArrayList; |
| 36 | import java.util.Arrays; |
| 37 | import java.util.Collections; |
| 38 | import java.util.Iterator; |
Carolina Fernandez | ad89343 | 2016-07-18 11:11:34 +0200 | [diff] [blame] | 39 | import java.util.List; |
| 40 | import java.util.Optional; |
| 41 | |
| 42 | import static java.lang.String.format; |
| 43 | import static org.junit.Assert.assertEquals; |
| 44 | import static org.junit.Assert.assertTrue; |
| 45 | |
| 46 | /** |
| 47 | * Unit tests for SdxL2VlanVCManager. |
| 48 | */ |
| 49 | public class SdxL2VlanVCManagerTest extends AbstractIntentTest { |
| 50 | |
| 51 | private static final String SDXL2_2 = "sdxl2_test2"; |
| 52 | private static final String CP1 = "of:00000000000001/1"; |
| 53 | private static final String CP2 = "of:00000000000002/1"; |
| 54 | private static final String CP5 = "of:00000000000002/4"; |
| 55 | private static final String CP6 = "of:00000000000004/4"; |
| 56 | private static final String CP7 = "of:0000000000000a/4"; |
| 57 | private static final String CP8 = "of:00000000000009/4"; |
| 58 | private static final String CP9 = "of:0000000000000a/4"; |
| 59 | private static final String CP10 = "of:00000000000009/4"; |
| 60 | private static final String VLANS1 = "2,3,4"; |
Carolina Fernandez | ad89343 | 2016-07-18 11:11:34 +0200 | [diff] [blame] | 61 | private static final String VLANS2 = "4,5,6"; |
Carolina Fernandez | ad89343 | 2016-07-18 11:11:34 +0200 | [diff] [blame] | 62 | private static final String VLANS5 = "100"; |
| 63 | private static final String VLANS6 = "1"; |
| 64 | private static final String VLANS7 = "1"; |
| 65 | private static final String VLANS8 = "111"; |
| 66 | private static final String VLANS9 = "1"; |
| 67 | private static final String VLANS10 = "1"; |
| 68 | private static final String NAME_FORMAT = "%s:%s-%s"; |
| 69 | private static final String KEY_FORMAT = "%s,%s"; |
| 70 | private static final ApplicationId APPID = TestApplicationId.create("foo"); |
Carolina Fernandez | ad89343 | 2016-07-18 11:11:34 +0200 | [diff] [blame] | 71 | private SdxL2VlanVCManager manager; |
| 72 | private List<PointToPointIntent> intentList; |
| 73 | |
| 74 | /** |
Carolina Fernandez | b31adee | 2016-08-31 11:29:38 +0200 | [diff] [blame] | 75 | * Prepares environment before starting testing. |
| 76 | * |
| 77 | * @throws Exception when set-up fails |
Carolina Fernandez | ad89343 | 2016-07-18 11:11:34 +0200 | [diff] [blame] | 78 | */ |
Yuta HIGUCHI | c9fae9f | 2017-01-31 15:21:51 -0800 | [diff] [blame] | 79 | @Override |
Carolina Fernandez | ad89343 | 2016-07-18 11:11:34 +0200 | [diff] [blame] | 80 | @Before |
| 81 | public void setUp() throws Exception { |
| 82 | super.setUp(); |
| 83 | SdxL2DistributedStore store = new SdxL2DistributedStore(); |
| 84 | store.initForTest(); |
| 85 | manager = new SdxL2VlanVCManager( |
| 86 | APPID, store, new IntentServiceTest()); |
| 87 | intentList = setIntents(); |
| 88 | } |
| 89 | |
| 90 | /** |
Carolina Fernandez | b31adee | 2016-08-31 11:29:38 +0200 | [diff] [blame] | 91 | * Cleans up environment after finishing testing. |
Carolina Fernandez | ad89343 | 2016-07-18 11:11:34 +0200 | [diff] [blame] | 92 | */ |
Yuta HIGUCHI | c9fae9f | 2017-01-31 15:21:51 -0800 | [diff] [blame] | 93 | @Override |
Carolina Fernandez | ad89343 | 2016-07-18 11:11:34 +0200 | [diff] [blame] | 94 | @After |
| 95 | public void tearDown() { |
| 96 | super.tearDown(); |
| 97 | } |
| 98 | |
Carolina Fernandez | b31adee | 2016-08-31 11:29:38 +0200 | [diff] [blame] | 99 | /** |
| 100 | * Defines the intents to be used when testing the VC. |
| 101 | * |
| 102 | * @return List of point-to-point intents |
| 103 | */ |
| 104 | private List<PointToPointIntent> setIntents() { |
| 105 | List<PointToPointIntent> intents = new ArrayList<>(); |
| 106 | intents.addAll(setupConnectionPoints1To2()); |
| 107 | intents.addAll(setupConnectionPoints5To6()); |
| 108 | intents.addAll(setupConnectionPoints7To8()); |
| 109 | intents.addAll(setupConnectionPoints9To10()); |
Carolina Fernandez | ad89343 | 2016-07-18 11:11:34 +0200 | [diff] [blame] | 110 | return intents; |
| 111 | } |
| 112 | |
Carolina Fernandez | b31adee | 2016-08-31 11:29:38 +0200 | [diff] [blame] | 113 | /** |
| 114 | * Returns the traffic treatment, used in the definition of the intents. |
| 115 | * |
| 116 | * @param setVlan VLAN to set |
| 117 | * @param pushVlan VLAN to push |
| 118 | * @param popVlan boolean to indicate whether a popVlan action is |
| 119 | * performed (true) or not (false) |
| 120 | * @return TrafficTreatment object |
| 121 | */ |
Carolina Fernandez | ad89343 | 2016-07-18 11:11:34 +0200 | [diff] [blame] | 122 | private TrafficTreatment buildTreatment(VlanId setVlan, |
| 123 | VlanId pushVlan, |
| 124 | boolean popVlan) { |
Carolina Fernandez | b31adee | 2016-08-31 11:29:38 +0200 | [diff] [blame] | 125 | return manager.buildTreatment(setVlan, pushVlan, popVlan); |
Carolina Fernandez | ad89343 | 2016-07-18 11:11:34 +0200 | [diff] [blame] | 126 | } |
| 127 | |
Carolina Fernandez | b31adee | 2016-08-31 11:29:38 +0200 | [diff] [blame] | 128 | /** |
| 129 | * Returns the traffic selector, used in the definition of the intents. |
| 130 | * |
| 131 | * @param ethertype name of the Ethernet type used (e.g. of SDX-L2 |
| 132 | * @param ingresstag VLAN id used at the ingress |
| 133 | * @return TrafficSelector object |
| 134 | */ |
Carolina Fernandez | ad89343 | 2016-07-18 11:11:34 +0200 | [diff] [blame] | 135 | private TrafficSelector buildSelector(Short ethertype, |
| 136 | VlanId ingresstag) { |
Carolina Fernandez | b31adee | 2016-08-31 11:29:38 +0200 | [diff] [blame] | 137 | return manager.buildSelector(ethertype, ingresstag); |
Carolina Fernandez | ad89343 | 2016-07-18 11:11:34 +0200 | [diff] [blame] | 138 | } |
| 139 | |
Carolina Fernandez | b31adee | 2016-08-31 11:29:38 +0200 | [diff] [blame] | 140 | /** |
| 141 | * Returns constraints depending on the encapsulation used on the VC. |
| 142 | * |
| 143 | * @return list of constraints to be used in the intents |
| 144 | */ |
| 145 | private List<Constraint> buildConstraints() { |
| 146 | return manager.buildConstraints(); |
Carolina Fernandez | ad89343 | 2016-07-18 11:11:34 +0200 | [diff] [blame] | 147 | } |
| 148 | |
Carolina Fernandez | b31adee | 2016-08-31 11:29:38 +0200 | [diff] [blame] | 149 | /** |
| 150 | * Returns Intent key from SDX-L2 and two SDX-L2 Connection Points. |
| 151 | * |
| 152 | * @param sdxl2 name of SDX-L2 |
| 153 | * @param cpOne sdxl2 connection point one |
| 154 | * @param cpTwo sdxl2 connection point two |
| 155 | * @param index digit used to help identify Intent |
| 156 | * @return canonical intent string key |
| 157 | */ |
| 158 | private Key generateIntentKey(String sdxl2, SdxL2ConnectionPoint cpOne, SdxL2ConnectionPoint cpTwo, String index) { |
| 159 | return manager.generateIntentKey(sdxl2, cpOne, cpTwo, index); |
Carolina Fernandez | ad89343 | 2016-07-18 11:11:34 +0200 | [diff] [blame] | 160 | } |
| 161 | |
Carolina Fernandez | b31adee | 2016-08-31 11:29:38 +0200 | [diff] [blame] | 162 | /** |
| 163 | * Ensures that when adding a VC its related intents are inserted. |
| 164 | */ |
Carolina Fernandez | ad89343 | 2016-07-18 11:11:34 +0200 | [diff] [blame] | 165 | @Test |
| 166 | public void testConnectionSetup() { |
| 167 | Iterator<SdxL2ConnectionPoint> lhs = setupLhsCPs().iterator(); |
| 168 | Iterator<SdxL2ConnectionPoint> rhs = setupRhsCPs().iterator(); |
| 169 | while (lhs.hasNext() && rhs.hasNext()) { |
| 170 | manager.addVC(SDXL2_2, lhs.next(), rhs.next()); |
| 171 | } |
| 172 | |
| 173 | assertEquals(intentList.size(), manager.intentService.getIntentCount()); |
| 174 | |
| 175 | for (Intent emulatedIntent : intentList) { |
| 176 | boolean found = false; |
| 177 | for (Intent realIntent : manager.intentService.getIntents()) { |
| 178 | if (emulatedIntent.key().equals(realIntent.key())) { |
| 179 | found = true; |
| 180 | assertTrue(format("Comparing %s and %s", emulatedIntent, realIntent), |
| 181 | IntentUtils.intentsAreEqual(emulatedIntent, realIntent)); |
| 182 | break; |
| 183 | } |
| 184 | } |
| 185 | assertTrue(found); |
| 186 | } |
| 187 | } |
| 188 | |
Carolina Fernandez | b31adee | 2016-08-31 11:29:38 +0200 | [diff] [blame] | 189 | /** |
| 190 | * Defines the left-hand side endpoints, each with a specific VLAN. |
| 191 | * |
| 192 | * @return list of SdxL2ConnectionPoint objects |
| 193 | */ |
| 194 | private List<SdxL2ConnectionPoint> setupLhsCPs() { |
| 195 | List<SdxL2ConnectionPoint> cps = new ArrayList<>(); |
Carolina Fernandez | ad89343 | 2016-07-18 11:11:34 +0200 | [diff] [blame] | 196 | SdxL2ConnectionPoint cpone = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST1", CP1, VLANS1); |
| 197 | cps.add(cpone); |
| 198 | SdxL2ConnectionPoint cpfive = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST5", CP5, VLANS5); |
| 199 | cps.add(cpfive); |
| 200 | SdxL2ConnectionPoint cpseven = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST7", CP7, VLANS7); |
| 201 | cps.add(cpseven); |
| 202 | SdxL2ConnectionPoint cpnine = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST9", CP9, VLANS9); |
| 203 | cps.add(cpnine); |
| 204 | return cps; |
| 205 | } |
| 206 | |
Carolina Fernandez | b31adee | 2016-08-31 11:29:38 +0200 | [diff] [blame] | 207 | /** |
| 208 | * Defines the right-hand side endpoints, each with a specific VLAN. |
| 209 | * |
| 210 | * @return list of SdxL2ConnectionPoint objects |
| 211 | */ |
| 212 | private List<SdxL2ConnectionPoint> setupRhsCPs() { |
| 213 | List<SdxL2ConnectionPoint> cps = new ArrayList<>(); |
Carolina Fernandez | ad89343 | 2016-07-18 11:11:34 +0200 | [diff] [blame] | 214 | SdxL2ConnectionPoint cptwo = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST2", CP2, VLANS2); |
| 215 | cps.add(cptwo); |
| 216 | SdxL2ConnectionPoint cpsix = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST6", CP6, VLANS6); |
| 217 | cps.add(cpsix); |
| 218 | SdxL2ConnectionPoint cpeight = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST8", CP8, VLANS8); |
| 219 | cps.add(cpeight); |
| 220 | SdxL2ConnectionPoint cpten = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST10", CP10, VLANS10); |
| 221 | cps.add(cpten); |
| 222 | return cps; |
| 223 | } |
| 224 | |
Carolina Fernandez | b31adee | 2016-08-31 11:29:38 +0200 | [diff] [blame] | 225 | /** |
| 226 | * Creates the intents from the information of couple of endpoints. |
| 227 | * |
| 228 | * @param keyIndex identifier of the intent |
| 229 | * @param lhs left-hand side Connection Point |
| 230 | * @param lhsID DPID of the left-hand side CP |
| 231 | * @param lhsVlan VLAN of the left-hand side CP |
| 232 | * @param lhsBuiltTreatment specific treatment for the left-hand side CP |
| 233 | * @param rhs right-hand side Connection Point |
| 234 | * @param rhsID DPID of the right-hand side CP |
| 235 | * @param rhsVlan VLAN of the right-hand side CP |
| 236 | * @param rhsBuiltTreatment specific treatment for the right-hand side CP |
| 237 | * @return List of point-to-point intents |
| 238 | */ |
| 239 | private List<PointToPointIntent> setupConnectionPoints(String keyIndex, |
| 240 | SdxL2ConnectionPoint lhs, String lhsID, |
| 241 | String lhsVlan, |
| 242 | TrafficTreatment lhsBuiltTreatment, |
| 243 | SdxL2ConnectionPoint rhs, String rhsID, |
| 244 | String rhsVlan, |
| 245 | TrafficTreatment rhsBuiltTreatment) { |
| 246 | List<PointToPointIntent> intents = new ArrayList<>(); |
| 247 | VlanId lhsVlanValue = null, rhsVlanValue = null; |
| 248 | if (lhsVlan != null) { |
| 249 | lhsVlanValue = VlanId.vlanId(Short.parseShort(lhsVlan)); |
| 250 | } |
| 251 | if (rhsVlan != null) { |
| 252 | rhsVlanValue = VlanId.vlanId(Short.parseShort(rhsVlan)); |
| 253 | } |
Carolina Fernandez | ad89343 | 2016-07-18 11:11:34 +0200 | [diff] [blame] | 254 | |
Carolina Fernandez | b31adee | 2016-08-31 11:29:38 +0200 | [diff] [blame] | 255 | intents.add(PointToPointIntent.builder() |
| 256 | .appId(APPID) |
| 257 | .key(generateIntentKey(SDXL2_2, lhs, rhs, keyIndex)) |
| 258 | .selector(buildSelector(null, lhsVlanValue)) |
| 259 | .treatment(lhsBuiltTreatment) |
| 260 | .constraints(buildConstraints()) |
| 261 | .ingressPoint(ConnectPoint.deviceConnectPoint(lhsID)) |
| 262 | .egressPoint(ConnectPoint.deviceConnectPoint(rhsID)) |
| 263 | .priority(2000) |
| 264 | .build()); |
| 265 | intents.add(PointToPointIntent.builder() |
| 266 | .appId(APPID) |
| 267 | .key(generateIntentKey(SDXL2_2, rhs, lhs, keyIndex)) |
| 268 | .selector(buildSelector(null, rhsVlanValue)) |
| 269 | .treatment(rhsBuiltTreatment) |
| 270 | .constraints(buildConstraints()) |
| 271 | .ingressPoint(ConnectPoint.deviceConnectPoint(rhsID)) |
| 272 | .egressPoint(ConnectPoint.deviceConnectPoint(lhsID)) |
| 273 | .priority(2000) |
| 274 | .build()); |
| 275 | return intents; |
| 276 | } |
| 277 | |
| 278 | /** |
| 279 | * Defines three pairs of Connection Points, each with a specific VLAN. |
| 280 | * The intents are created aftewards, from this input. |
| 281 | * |
| 282 | * @return list of point-to-point intents |
| 283 | */ |
| 284 | private List<PointToPointIntent> setupConnectionPoints1To2() { |
| 285 | List<PointToPointIntent> intents = new ArrayList<>(); |
| 286 | String lhsID = CP1; |
| 287 | ArrayList<String> lhsVlan = new ArrayList<>(Arrays.asList(VLANS1.split(","))); |
| 288 | String rhsID = CP2; |
| 289 | ArrayList<String> rhsVlan = new ArrayList<>(Arrays.asList(VLANS2.split(","))); |
| 290 | SdxL2ConnectionPoint lhs = SdxL2ConnectionPoint.sdxl2ConnectionPoint( |
| 291 | "TEST1", lhsID, VLANS1); |
| 292 | SdxL2ConnectionPoint rhs = SdxL2ConnectionPoint.sdxl2ConnectionPoint( |
| 293 | "TEST2", rhsID, VLANS2); |
| 294 | TrafficTreatment lhsBuiltTreatment, rhsBuiltTreatment; |
| 295 | |
| 296 | for (int i = 0; i < 3; i++) { |
| 297 | lhsBuiltTreatment = buildTreatment(VlanId.vlanId(rhsVlan.get(i)), null, false); |
| 298 | rhsBuiltTreatment = buildTreatment(VlanId.vlanId(lhsVlan.get(i)), null, false); |
| 299 | intents.addAll(setupConnectionPoints(Integer.toString(i + 1), |
| 300 | lhs, lhsID, lhsVlan.get(i), lhsBuiltTreatment, |
| 301 | rhs, rhsID, rhsVlan.get(i), rhsBuiltTreatment)); |
| 302 | } |
| 303 | return intents; |
| 304 | } |
| 305 | |
| 306 | /** |
| 307 | * Defines a couple of Connection Points, each with a specific VLAN. |
| 308 | * The intents are created aftewards, from this input. |
| 309 | * |
| 310 | * @return list of point-to-point intents |
| 311 | */ |
| 312 | private List<PointToPointIntent> setupConnectionPoints5To6() { |
| 313 | String lhsID = CP5; |
| 314 | String lhsVlan = VLANS5; |
| 315 | SdxL2ConnectionPoint lhs = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST5", lhsID, lhsVlan); |
| 316 | String rhsID = CP6; |
| 317 | String rhsVlan = VLANS6; |
| 318 | SdxL2ConnectionPoint rhs = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST6", rhsID, rhsVlan); |
| 319 | TrafficTreatment lhsBuiltTreatment = buildTreatment(null, null, true); |
| 320 | TrafficTreatment rhsBuiltTreatment = buildTreatment(null, VlanId.vlanId(Short.parseShort(lhsVlan)), false); |
| 321 | return setupConnectionPoints("1", lhs, lhsID, lhsVlan, lhsBuiltTreatment, |
| 322 | rhs, rhsID, null, rhsBuiltTreatment); |
| 323 | } |
| 324 | |
| 325 | /** |
| 326 | * Defines a couple of Connection Points, each with a specific VLAN. |
| 327 | * The intents are created aftewards, from this input. |
| 328 | * |
| 329 | * @return list of point-to-point intents |
| 330 | */ |
| 331 | private List<PointToPointIntent> setupConnectionPoints7To8() { |
| 332 | String lhsID = CP7; |
| 333 | String lhsVlan = VLANS7; |
| 334 | SdxL2ConnectionPoint lhs = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST7", lhsID, lhsVlan); |
| 335 | String rhsID = CP8; |
| 336 | String rhsVlan = VLANS8; |
| 337 | SdxL2ConnectionPoint rhs = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST8", rhsID, rhsVlan); |
| 338 | TrafficTreatment lhsBuiltTreatment = buildTreatment(null, VlanId.vlanId(Short.parseShort(rhsVlan)), false); |
| 339 | TrafficTreatment rhsBuiltTreatment = buildTreatment(null, null, true); |
| 340 | return setupConnectionPoints("1", lhs, lhsID, null, lhsBuiltTreatment, |
| 341 | rhs, rhsID, rhsVlan, rhsBuiltTreatment); |
| 342 | } |
| 343 | |
| 344 | /** |
| 345 | * Defines a couple of Connection Points, each with a specific VLAN. |
| 346 | * The intents are created aftewards, from this input. |
| 347 | * |
| 348 | * @return list of point-to-point intents |
| 349 | */ |
| 350 | private List<PointToPointIntent> setupConnectionPoints9To10() { |
| 351 | String lhsID = CP9; |
| 352 | String lhsVlan = VLANS9; |
| 353 | SdxL2ConnectionPoint lhs = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST9", lhsID, lhsVlan); |
| 354 | String rhsID = CP10; |
| 355 | String rhsVlan = VLANS10; |
| 356 | SdxL2ConnectionPoint rhs = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST10", rhsID, rhsVlan); |
| 357 | TrafficTreatment nullTreatment = buildTreatment(null, null, false); |
| 358 | return setupConnectionPoints("1", lhs, lhsID, null, nullTreatment, |
| 359 | rhs, rhsID, null, nullTreatment); |
| 360 | } |
| 361 | |
| 362 | /** |
| 363 | * Ensures that when removing a VC its related intents are deleted. |
| 364 | */ |
Carolina Fernandez | ad89343 | 2016-07-18 11:11:34 +0200 | [diff] [blame] | 365 | @Test |
Carolina Fernandez | b31adee | 2016-08-31 11:29:38 +0200 | [diff] [blame] | 366 | public void removeVCAndIntents() { |
Carolina Fernandez | ad89343 | 2016-07-18 11:11:34 +0200 | [diff] [blame] | 367 | testConnectionSetup(); |
| 368 | |
Carolina Fernandez | b31adee | 2016-08-31 11:29:38 +0200 | [diff] [blame] | 369 | List<PointToPointIntent> removedIntents = new ArrayList<>(); |
Carolina Fernandez | ad89343 | 2016-07-18 11:11:34 +0200 | [diff] [blame] | 370 | SdxL2ConnectionPoint cpone = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST1", CP1, VLANS1); |
| 371 | SdxL2ConnectionPoint cptwo = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST2", CP2, VLANS2); |
Carolina Fernandez | b31adee | 2016-08-31 11:29:38 +0200 | [diff] [blame] | 372 | removedIntents.addAll(setupConnectionPoints1To2()); |
Carolina Fernandez | ad89343 | 2016-07-18 11:11:34 +0200 | [diff] [blame] | 373 | |
| 374 | SdxL2ConnectionPoint cpfive = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST5", CP5, VLANS5); |
| 375 | SdxL2ConnectionPoint cpsix = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST6", CP6, VLANS6); |
Carolina Fernandez | b31adee | 2016-08-31 11:29:38 +0200 | [diff] [blame] | 376 | removedIntents.addAll(setupConnectionPoints5To6()); |
Carolina Fernandez | ad89343 | 2016-07-18 11:11:34 +0200 | [diff] [blame] | 377 | |
| 378 | SdxL2ConnectionPoint cpseven = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST7", CP7, VLANS7); |
| 379 | SdxL2ConnectionPoint cpeight = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST8", CP8, VLANS8); |
Carolina Fernandez | b31adee | 2016-08-31 11:29:38 +0200 | [diff] [blame] | 380 | removedIntents.addAll(setupConnectionPoints7To8()); |
Carolina Fernandez | ad89343 | 2016-07-18 11:11:34 +0200 | [diff] [blame] | 381 | |
| 382 | manager.removeVC(cpone, cptwo); |
| 383 | manager.removeVC(cpfive, cpsix); |
| 384 | manager.removeVC(cpseven, cpeight); |
| 385 | |
| 386 | assertEquals(2, manager.intentService.getIntentCount()); |
| 387 | |
| 388 | for (Intent removedIntent : removedIntents) { |
| 389 | boolean found = false; |
| 390 | for (Intent existingIntent : manager.intentService.getIntents()) { |
| 391 | if (removedIntent.key().equals(existingIntent.key())) { |
| 392 | found = true; |
| 393 | assertTrue(format("Intent %s equal %s", removedIntent, existingIntent), |
| 394 | !IntentUtils.intentsAreEqual(removedIntent, existingIntent)); |
| 395 | break; |
| 396 | } |
| 397 | } |
| 398 | assertTrue(!found); |
| 399 | } |
Carolina Fernandez | ad89343 | 2016-07-18 11:11:34 +0200 | [diff] [blame] | 400 | } |
| 401 | |
Carolina Fernandez | b31adee | 2016-08-31 11:29:38 +0200 | [diff] [blame] | 402 | /** |
| 403 | * Ensures that when removing a CP its related VCs and intents are also deleted. |
| 404 | */ |
Carolina Fernandez | ad89343 | 2016-07-18 11:11:34 +0200 | [diff] [blame] | 405 | @Test |
| 406 | public void testRemoveVCbyCP() { |
| 407 | testConnectionSetup(); |
| 408 | |
Carolina Fernandez | b31adee | 2016-08-31 11:29:38 +0200 | [diff] [blame] | 409 | List<PointToPointIntent> removedIntents = new ArrayList<>(); |
Carolina Fernandez | ad89343 | 2016-07-18 11:11:34 +0200 | [diff] [blame] | 410 | SdxL2ConnectionPoint cpone = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST1", CP1, VLANS1); |
Carolina Fernandez | b31adee | 2016-08-31 11:29:38 +0200 | [diff] [blame] | 411 | removedIntents.addAll(setupConnectionPoints1To2()); |
Carolina Fernandez | ad89343 | 2016-07-18 11:11:34 +0200 | [diff] [blame] | 412 | SdxL2ConnectionPoint cpsix = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST6", CP6, VLANS6); |
Carolina Fernandez | b31adee | 2016-08-31 11:29:38 +0200 | [diff] [blame] | 413 | removedIntents.addAll(setupConnectionPoints5To6()); |
Carolina Fernandez | ad89343 | 2016-07-18 11:11:34 +0200 | [diff] [blame] | 414 | SdxL2ConnectionPoint cpseven = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST7", CP7, VLANS7); |
Carolina Fernandez | b31adee | 2016-08-31 11:29:38 +0200 | [diff] [blame] | 415 | removedIntents.addAll(setupConnectionPoints7To8()); |
Carolina Fernandez | ad89343 | 2016-07-18 11:11:34 +0200 | [diff] [blame] | 416 | SdxL2ConnectionPoint cpten = SdxL2ConnectionPoint.sdxl2ConnectionPoint("TEST10", CP10, VLANS10); |
Carolina Fernandez | b31adee | 2016-08-31 11:29:38 +0200 | [diff] [blame] | 417 | removedIntents.addAll(setupConnectionPoints9To10()); |
Carolina Fernandez | ad89343 | 2016-07-18 11:11:34 +0200 | [diff] [blame] | 418 | |
| 419 | manager.removeVC(cpone); |
| 420 | manager.removeVC(cpsix); |
| 421 | manager.removeVC(cpseven); |
| 422 | manager.removeVC(cpten); |
| 423 | |
Carolina Fernandez | b31adee | 2016-08-31 11:29:38 +0200 | [diff] [blame] | 424 | assertEquals(Collections.emptySet(), manager.getVCs(Optional.empty())); |
Carolina Fernandez | ad89343 | 2016-07-18 11:11:34 +0200 | [diff] [blame] | 425 | |
| 426 | assertEquals(0, manager.intentService.getIntentCount()); |
| 427 | |
| 428 | for (Intent removedIntent : removedIntents) { |
| 429 | boolean found = false; |
| 430 | for (Intent existingIntent : manager.intentService.getIntents()) { |
| 431 | if (removedIntent.key().equals(existingIntent.key())) { |
| 432 | found = true; |
| 433 | assertTrue(format("Intent %s equal %s", removedIntent, existingIntent), |
| 434 | !IntentUtils.intentsAreEqual(removedIntent, existingIntent)); |
| 435 | break; |
| 436 | } |
| 437 | } |
| 438 | assertTrue(!found); |
| 439 | } |
Carolina Fernandez | ad89343 | 2016-07-18 11:11:34 +0200 | [diff] [blame] | 440 | } |
| 441 | |
Carolina Fernandez | b31adee | 2016-08-31 11:29:38 +0200 | [diff] [blame] | 442 | /** |
| 443 | * Ensures that when removing a SDX its related VCs and intents are also deleted. |
| 444 | */ |
Carolina Fernandez | ad89343 | 2016-07-18 11:11:34 +0200 | [diff] [blame] | 445 | @Test |
| 446 | public void testremoveVCbySdx() { |
| 447 | testConnectionSetup(); |
| 448 | |
Carolina Fernandez | b31adee | 2016-08-31 11:29:38 +0200 | [diff] [blame] | 449 | List<PointToPointIntent> removedIntents = new ArrayList<>(); |
| 450 | removedIntents.addAll(setupConnectionPoints1To2()); |
| 451 | removedIntents.addAll(setupConnectionPoints5To6()); |
| 452 | removedIntents.addAll(setupConnectionPoints7To8()); |
| 453 | removedIntents.addAll(setupConnectionPoints9To10()); |
Carolina Fernandez | ad89343 | 2016-07-18 11:11:34 +0200 | [diff] [blame] | 454 | |
| 455 | manager.removeVCs(SDXL2_2); |
Carolina Fernandez | b31adee | 2016-08-31 11:29:38 +0200 | [diff] [blame] | 456 | assertEquals(Collections.emptySet(), manager.getVCs(Optional.empty())); |
Carolina Fernandez | ad89343 | 2016-07-18 11:11:34 +0200 | [diff] [blame] | 457 | assertEquals(Collections.emptySet(), manager.getVCs(Optional.of(SDXL2_2))); |
| 458 | |
| 459 | for (Intent removedIntent : removedIntents) { |
| 460 | boolean found = false; |
| 461 | for (Intent existingIntent : manager.intentService.getIntents()) { |
| 462 | if (removedIntent.key().equals(existingIntent.key())) { |
| 463 | found = true; |
| 464 | assertTrue(format("Intent %s equal %s", removedIntent, existingIntent), |
| 465 | !IntentUtils.intentsAreEqual(removedIntent, existingIntent)); |
| 466 | break; |
| 467 | } |
| 468 | } |
| 469 | assertTrue(!found); |
| 470 | } |
Carolina Fernandez | ad89343 | 2016-07-18 11:11:34 +0200 | [diff] [blame] | 471 | } |
Yuta HIGUCHI | c9fae9f | 2017-01-31 15:21:51 -0800 | [diff] [blame] | 472 | } |