Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [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 | package org.onosproject.pce.pcestore; |
| 17 | |
| 18 | import static org.hamcrest.MatcherAssert.assertThat; |
| 19 | import static org.hamcrest.Matchers.is; |
| 20 | import static org.hamcrest.Matchers.notNullValue; |
| 21 | |
| 22 | import java.util.LinkedList; |
| 23 | import java.util.List; |
| 24 | import java.util.Map; |
| 25 | |
| 26 | import org.junit.After; |
| 27 | import org.junit.AfterClass; |
| 28 | import org.junit.Before; |
| 29 | import org.junit.BeforeClass; |
| 30 | import org.junit.Test; |
| 31 | |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 32 | import org.onlab.util.DataRateUnit; |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 33 | import org.onosproject.incubator.net.resource.label.DefaultLabelResource; |
| 34 | import org.onosproject.incubator.net.resource.label.LabelResource; |
| 35 | import org.onosproject.incubator.net.resource.label.LabelResourceId; |
| 36 | import org.onosproject.incubator.net.tunnel.TunnelId; |
| 37 | import org.onosproject.net.ConnectPoint; |
| 38 | import org.onosproject.net.DefaultAnnotations; |
| 39 | import org.onosproject.net.DefaultLink; |
| 40 | import org.onosproject.net.DeviceId; |
| 41 | import org.onosproject.net.ElementId; |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 42 | import org.onosproject.net.intent.Constraint; |
| 43 | import org.onosproject.net.intent.constraint.BandwidthConstraint; |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 44 | import org.onosproject.net.Link; |
| 45 | import org.onosproject.net.PortNumber; |
| 46 | import org.onosproject.net.resource.ResourceConsumer; |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 47 | import org.onosproject.pce.pceservice.LspType; |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 48 | import org.onosproject.pce.pceservice.TunnelConsumerId; |
| 49 | import org.onosproject.pce.pcestore.api.LspLocalLabelInfo; |
| 50 | import org.onosproject.net.provider.ProviderId; |
| 51 | import org.onosproject.store.service.TestStorageService; |
| 52 | |
| 53 | /** |
| 54 | * Unit tests for DistributedPceStore class. |
| 55 | */ |
| 56 | public class DistributedPceStoreTest { |
| 57 | |
| 58 | private DistributedPceStore distrPceStore; |
| 59 | private DeviceId deviceId1 = DeviceId.deviceId("foo"); |
| 60 | private DeviceId deviceId2 = DeviceId.deviceId("goo"); |
| 61 | private DeviceId deviceId3 = DeviceId.deviceId("yaa"); |
| 62 | private DeviceId deviceId4 = DeviceId.deviceId("zoo"); |
| 63 | private LabelResourceId labelId1 = LabelResourceId.labelResourceId(1); |
| 64 | private LabelResourceId labelId2 = LabelResourceId.labelResourceId(2); |
| 65 | private LabelResourceId labelId3 = LabelResourceId.labelResourceId(3); |
| 66 | private LabelResourceId labelId4 = LabelResourceId.labelResourceId(4); |
| 67 | private PortNumber portNumber1 = PortNumber.portNumber(1); |
| 68 | private PortNumber portNumber2 = PortNumber.portNumber(2); |
| 69 | private PortNumber portNumber3 = PortNumber.portNumber(3); |
| 70 | private PortNumber portNumber4 = PortNumber.portNumber(4); |
| 71 | private ConnectPoint srcConnectionPoint1 = new ConnectPoint((ElementId) deviceId1, portNumber1); |
| 72 | private ConnectPoint dstConnectionPoint2 = new ConnectPoint((ElementId) deviceId2, portNumber2); |
| 73 | private ConnectPoint srcConnectionPoint3 = new ConnectPoint((ElementId) deviceId3, portNumber3); |
| 74 | private ConnectPoint dstConnectionPoint4 = new ConnectPoint((ElementId) deviceId4, portNumber4); |
| 75 | private LabelResource labelResource1 = new DefaultLabelResource(deviceId1, labelId1); |
| 76 | private LabelResource labelResource2 = new DefaultLabelResource(deviceId2, labelId2); |
| 77 | private LabelResource labelResource3 = new DefaultLabelResource(deviceId3, labelId3); |
| 78 | private LabelResource labelResource4 = new DefaultLabelResource(deviceId4, labelId4); |
| 79 | private Link link1; |
| 80 | private Link link2; |
| 81 | private List<LabelResource> labelList1 = new LinkedList<>(); |
| 82 | private List<LabelResource> labelList2 = new LinkedList<>(); |
| 83 | private TunnelId tunnelId1 = TunnelId.valueOf("1"); |
| 84 | private TunnelId tunnelId2 = TunnelId.valueOf("2"); |
| 85 | private TunnelId tunnelId3 = TunnelId.valueOf("3"); |
| 86 | private TunnelId tunnelId4 = TunnelId.valueOf("4"); |
| 87 | private PceccTunnelInfo pceccTunnelInfo1; |
| 88 | private PceccTunnelInfo pceccTunnelInfo2; |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 89 | private PcePathInfo failedPathInfo1; |
| 90 | private PcePathInfo failedPathInfo2; |
| 91 | private PcePathInfo failedPathInfo3; |
| 92 | private PcePathInfo failedPathInfo4; |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 93 | |
| 94 | @BeforeClass |
| 95 | public static void setUpBeforeClass() throws Exception { |
| 96 | } |
| 97 | |
| 98 | @AfterClass |
| 99 | public static void tearDownAfterClass() throws Exception { |
| 100 | } |
| 101 | |
| 102 | @Before |
| 103 | public void setUp() throws Exception { |
| 104 | distrPceStore = new DistributedPceStore(); |
| 105 | |
| 106 | // Initialization of member variables |
| 107 | link1 = DefaultLink.builder() |
| 108 | .providerId(new ProviderId("eth", "1")) |
| 109 | .annotations(DefaultAnnotations.builder().set("key1", "yahoo").build()) |
| 110 | .src(srcConnectionPoint1) |
| 111 | .dst(dstConnectionPoint2) |
| 112 | .type(Link.Type.DIRECT) |
| 113 | .state(Link.State.ACTIVE) |
| 114 | .build(); |
| 115 | link2 = DefaultLink.builder() |
| 116 | .providerId(new ProviderId("mac", "2")) |
| 117 | .annotations(DefaultAnnotations.builder().set("key2", "google").build()) |
| 118 | .src(srcConnectionPoint3) |
| 119 | .dst(dstConnectionPoint4) |
| 120 | .type(Link.Type.DIRECT) |
| 121 | .state(Link.State.ACTIVE) |
| 122 | .build(); |
| 123 | labelList1.add(labelResource1); |
| 124 | labelList1.add(labelResource2); |
| 125 | labelList2.add(labelResource3); |
| 126 | labelList2.add(labelResource4); |
| 127 | |
| 128 | // Create pceccTunnelInfo1 |
| 129 | List<LspLocalLabelInfo> lspLocalLabelInfoList1 = new LinkedList<>(); |
| 130 | ResourceConsumer tunnelConsumerId1 = TunnelConsumerId.valueOf(10); |
| 131 | |
| 132 | DeviceId deviceId1 = DeviceId.deviceId("foo"); |
| 133 | LabelResourceId inLabelId1 = LabelResourceId.labelResourceId(1); |
| 134 | LabelResourceId outLabelId1 = LabelResourceId.labelResourceId(2); |
| 135 | |
| 136 | LspLocalLabelInfo lspLocalLabel1 = DefaultLspLocalLabelInfo.builder() |
| 137 | .deviceId(deviceId1) |
| 138 | .inLabelId(inLabelId1) |
| 139 | .outLabelId(outLabelId1) |
| 140 | .build(); |
| 141 | lspLocalLabelInfoList1.add(lspLocalLabel1); |
| 142 | |
| 143 | pceccTunnelInfo1 = new PceccTunnelInfo(lspLocalLabelInfoList1, tunnelConsumerId1); |
| 144 | |
| 145 | // Create pceccTunnelInfo2 |
| 146 | List<LspLocalLabelInfo> lspLocalLabelInfoList2 = new LinkedList<>(); |
| 147 | ResourceConsumer tunnelConsumerId2 = TunnelConsumerId.valueOf(20); |
| 148 | |
| 149 | DeviceId deviceId2 = DeviceId.deviceId("foo"); |
| 150 | LabelResourceId inLabelId2 = LabelResourceId.labelResourceId(3); |
| 151 | LabelResourceId outLabelId2 = LabelResourceId.labelResourceId(4); |
| 152 | |
| 153 | LspLocalLabelInfo lspLocalLabel2 = DefaultLspLocalLabelInfo.builder() |
| 154 | .deviceId(deviceId2) |
| 155 | .inLabelId(inLabelId2) |
| 156 | .outLabelId(outLabelId2) |
| 157 | .build(); |
| 158 | lspLocalLabelInfoList2.add(lspLocalLabel2); |
| 159 | |
| 160 | pceccTunnelInfo2 = new PceccTunnelInfo(lspLocalLabelInfoList2, tunnelConsumerId2); |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 161 | |
| 162 | // Creates failedPathInfo1 |
| 163 | DeviceId src1 = DeviceId.deviceId("foo1"); |
| 164 | DeviceId dst1 = DeviceId.deviceId("goo1"); |
| 165 | String name1 = "pcc1"; |
| 166 | LspType lspType1 = LspType.SR_WITHOUT_SIGNALLING; |
| 167 | List<Constraint> constraints1 = new LinkedList<>(); |
| 168 | Constraint bandwidth1 = BandwidthConstraint.of(200, DataRateUnit.BPS); |
| 169 | constraints1.add(bandwidth1); |
| 170 | |
| 171 | failedPathInfo1 = new PcePathInfo(src1, dst1, name1, constraints1, lspType1); |
| 172 | |
| 173 | // Creates failedPathInfo2 |
| 174 | DeviceId src2 = DeviceId.deviceId("foo2"); |
| 175 | DeviceId dst2 = DeviceId.deviceId("goo2"); |
| 176 | String name2 = "pcc2"; |
| 177 | LspType lspType2 = LspType.SR_WITHOUT_SIGNALLING; |
| 178 | List<Constraint> constraints2 = new LinkedList<>(); |
| 179 | Constraint bandwidth2 = BandwidthConstraint.of(400, DataRateUnit.BPS); |
| 180 | constraints2.add(bandwidth2); |
| 181 | |
| 182 | failedPathInfo2 = new PcePathInfo(src2, dst2, name2, constraints2, lspType2); |
| 183 | |
| 184 | // Creates failedPathInfo3 |
| 185 | DeviceId src3 = DeviceId.deviceId("foo3"); |
| 186 | DeviceId dst3 = DeviceId.deviceId("goo3"); |
| 187 | String name3 = "pcc3"; |
| 188 | LspType lspType3 = LspType.SR_WITHOUT_SIGNALLING; |
| 189 | List<Constraint> constraints3 = new LinkedList<>(); |
| 190 | Constraint bandwidth3 = BandwidthConstraint.of(500, DataRateUnit.BPS); |
| 191 | constraints3.add(bandwidth3); |
| 192 | |
| 193 | failedPathInfo3 = new PcePathInfo(src3, dst3, name3, constraints3, lspType3); |
| 194 | |
| 195 | // Creates failedPathInfo4 |
| 196 | DeviceId src4 = DeviceId.deviceId("foo4"); |
| 197 | DeviceId dst4 = DeviceId.deviceId("goo4"); |
| 198 | String name4 = "pcc4"; |
| 199 | LspType lspType4 = LspType.SR_WITHOUT_SIGNALLING; |
| 200 | List<Constraint> constraints4 = new LinkedList<>(); |
| 201 | Constraint bandwidth4 = BandwidthConstraint.of(600, DataRateUnit.BPS); |
| 202 | constraints4.add(bandwidth4); |
| 203 | |
| 204 | failedPathInfo4 = new PcePathInfo(src4, dst4, name4, constraints4, lspType4); |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | @After |
| 208 | public void tearDown() throws Exception { |
| 209 | } |
| 210 | |
| 211 | /** |
| 212 | * Checks the operation of addGlobalNodeLabel() method. |
| 213 | */ |
| 214 | @Test |
| 215 | public void testAddGlobalNodeLabel() { |
| 216 | // initialization |
| 217 | distrPceStore.storageService = new TestStorageService(); |
| 218 | distrPceStore.activate(); |
| 219 | |
| 220 | // add device with label |
| 221 | distrPceStore.addGlobalNodeLabel(deviceId1, labelId1); |
| 222 | assertThat(distrPceStore.existsGlobalNodeLabel(deviceId1), is(true)); |
| 223 | assertThat(distrPceStore.getGlobalNodeLabel(deviceId1), is(labelId1)); |
| 224 | distrPceStore.addGlobalNodeLabel(deviceId2, labelId2); |
| 225 | assertThat(distrPceStore.existsGlobalNodeLabel(deviceId2), is(true)); |
| 226 | assertThat(distrPceStore.getGlobalNodeLabel(deviceId2), is(labelId2)); |
| 227 | } |
| 228 | |
| 229 | /** |
| 230 | * Checks the operation of addAdjLabel() method. |
| 231 | */ |
| 232 | @Test |
| 233 | public void testAddAdjLabel() { |
| 234 | // initialization |
| 235 | distrPceStore.storageService = new TestStorageService(); |
| 236 | distrPceStore.activate(); |
| 237 | |
| 238 | // link with list of labels |
| 239 | distrPceStore.addAdjLabel(link1, labelId1); |
| 240 | assertThat(distrPceStore.existsAdjLabel(link1), is(true)); |
| 241 | assertThat(distrPceStore.getAdjLabel(link1), is(labelId1)); |
| 242 | distrPceStore.addAdjLabel(link2, labelId2); |
| 243 | assertThat(distrPceStore.existsAdjLabel(link2), is(true)); |
| 244 | assertThat(distrPceStore.getAdjLabel(link2), is(labelId2)); |
| 245 | } |
| 246 | |
| 247 | /** |
| 248 | * Checks the operation of addTunnelInfo() method. |
| 249 | */ |
| 250 | @Test |
| 251 | public void testAddTunnelInfo() { |
| 252 | // initialization |
| 253 | distrPceStore.storageService = new TestStorageService(); |
| 254 | distrPceStore.activate(); |
| 255 | |
| 256 | // TunnelId with device label store information |
| 257 | distrPceStore.addTunnelInfo(tunnelId1, pceccTunnelInfo1); |
| 258 | assertThat(distrPceStore.existsTunnelInfo(tunnelId1), is(true)); |
| 259 | assertThat(distrPceStore.getTunnelInfo(tunnelId1), is(pceccTunnelInfo1)); |
| 260 | distrPceStore.addTunnelInfo(tunnelId2, pceccTunnelInfo2); |
| 261 | assertThat(distrPceStore.existsTunnelInfo(tunnelId2), is(true)); |
| 262 | assertThat(distrPceStore.getTunnelInfo(tunnelId2), is(pceccTunnelInfo2)); |
| 263 | } |
| 264 | |
| 265 | /** |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 266 | * Checks the operation of addFailedPathInfo() method. |
| 267 | */ |
| 268 | @Test |
| 269 | public void testAddFailedPathInfo() { |
| 270 | // initialization |
| 271 | distrPceStore.storageService = new TestStorageService(); |
| 272 | distrPceStore.activate(); |
| 273 | |
| 274 | // PcePathInfo with pce path input information |
| 275 | distrPceStore.addFailedPathInfo(failedPathInfo1); |
| 276 | assertThat(distrPceStore.existsFailedPathInfo(failedPathInfo1), is(true)); |
| 277 | distrPceStore.addFailedPathInfo(failedPathInfo2); |
| 278 | assertThat(distrPceStore.existsFailedPathInfo(failedPathInfo2), is(true)); |
| 279 | } |
| 280 | |
| 281 | /** |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 282 | * Checks the operation of existsGlobalNodeLabel() method. |
| 283 | */ |
| 284 | @Test |
| 285 | public void testExistsGlobalNodeLabel() { |
| 286 | testAddGlobalNodeLabel(); |
| 287 | |
| 288 | assertThat(distrPceStore.existsGlobalNodeLabel(deviceId1), is(true)); |
| 289 | assertThat(distrPceStore.existsGlobalNodeLabel(deviceId2), is(true)); |
| 290 | assertThat(distrPceStore.existsGlobalNodeLabel(deviceId3), is(false)); |
| 291 | assertThat(distrPceStore.existsGlobalNodeLabel(deviceId4), is(false)); |
| 292 | } |
| 293 | |
| 294 | /** |
| 295 | * Checks the operation of existsAdjLabel() method. |
| 296 | */ |
| 297 | @Test |
| 298 | public void testExistsAdjLabel() { |
| 299 | testAddAdjLabel(); |
| 300 | |
| 301 | assertThat(distrPceStore.existsAdjLabel(link1), is(true)); |
| 302 | assertThat(distrPceStore.existsAdjLabel(link2), is(true)); |
| 303 | } |
| 304 | |
| 305 | /** |
| 306 | * Checks the operation of existsTunnelInfo() method. |
| 307 | */ |
| 308 | @Test |
| 309 | public void testExistsTunnelInfo() { |
| 310 | testAddTunnelInfo(); |
| 311 | |
| 312 | assertThat(distrPceStore.existsTunnelInfo(tunnelId1), is(true)); |
| 313 | assertThat(distrPceStore.existsTunnelInfo(tunnelId2), is(true)); |
| 314 | assertThat(distrPceStore.existsTunnelInfo(tunnelId3), is(false)); |
| 315 | assertThat(distrPceStore.existsTunnelInfo(tunnelId4), is(false)); |
| 316 | } |
| 317 | |
| 318 | /** |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 319 | * Checks the operation of existsFailedPathInfo() method. |
| 320 | */ |
| 321 | @Test |
| 322 | public void testExistsFailedPathInfo() { |
| 323 | testAddFailedPathInfo(); |
| 324 | |
| 325 | assertThat(distrPceStore.existsFailedPathInfo(failedPathInfo1), is(true)); |
| 326 | assertThat(distrPceStore.existsFailedPathInfo(failedPathInfo2), is(true)); |
| 327 | assertThat(distrPceStore.existsFailedPathInfo(failedPathInfo3), is(false)); |
| 328 | assertThat(distrPceStore.existsFailedPathInfo(failedPathInfo4), is(false)); |
| 329 | } |
| 330 | |
| 331 | /** |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 332 | * Checks the operation of getGlobalNodeLabelCount() method. |
| 333 | */ |
| 334 | @Test |
| 335 | public void testGetGlobalNodeLabelCount() { |
| 336 | testAddGlobalNodeLabel(); |
| 337 | |
| 338 | assertThat(distrPceStore.getGlobalNodeLabelCount(), is(2)); |
| 339 | } |
| 340 | |
| 341 | /** |
| 342 | * Checks the operation of getAdjLabelCount() method. |
| 343 | */ |
| 344 | @Test |
| 345 | public void testGetAdjLabelCount() { |
| 346 | testAddAdjLabel(); |
| 347 | |
| 348 | assertThat(distrPceStore.getAdjLabelCount(), is(2)); |
| 349 | } |
| 350 | |
| 351 | /** |
| 352 | * Checks the operation of getTunnelInfoCount() method. |
| 353 | */ |
| 354 | @Test |
| 355 | public void testGetTunnelInfoCount() { |
| 356 | testAddTunnelInfo(); |
| 357 | |
| 358 | assertThat(distrPceStore.getTunnelInfoCount(), is(2)); |
| 359 | } |
| 360 | |
| 361 | /** |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 362 | * Checks the operation of getFailedPathInfoCount() method. |
| 363 | */ |
| 364 | @Test |
| 365 | public void testGetFailedPathInfoCount() { |
| 366 | testAddFailedPathInfo(); |
| 367 | |
| 368 | assertThat(distrPceStore.getFailedPathInfoCount(), is(2)); |
| 369 | } |
| 370 | |
| 371 | /** |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 372 | * Checks the operation of getGlobalNodeLabels() method. |
| 373 | */ |
| 374 | @Test |
| 375 | public void testGetGlobalNodeLabels() { |
| 376 | testAddGlobalNodeLabel(); |
| 377 | |
| 378 | Map<DeviceId, LabelResourceId> nodeLabelMap = distrPceStore.getGlobalNodeLabels(); |
| 379 | assertThat(nodeLabelMap, is(notNullValue())); |
| 380 | assertThat(nodeLabelMap.isEmpty(), is(false)); |
| 381 | assertThat(nodeLabelMap.size(), is(2)); |
| 382 | } |
| 383 | |
| 384 | /** |
| 385 | * Checks the operation of getAdjLabels() method. |
| 386 | */ |
| 387 | @Test |
| 388 | public void testGetAdjLabels() { |
| 389 | testAddAdjLabel(); |
| 390 | |
| 391 | Map<Link, LabelResourceId> adjLabelMap = distrPceStore.getAdjLabels(); |
| 392 | assertThat(adjLabelMap, is(notNullValue())); |
| 393 | assertThat(adjLabelMap.isEmpty(), is(false)); |
| 394 | assertThat(adjLabelMap.size(), is(2)); |
| 395 | } |
| 396 | |
| 397 | /** |
| 398 | * Checks the operation of getTunnelInfos() method. |
| 399 | */ |
| 400 | @Test |
| 401 | public void testGetTunnelInfos() { |
| 402 | testAddTunnelInfo(); |
| 403 | |
| 404 | Map<TunnelId, PceccTunnelInfo> tunnelInfoMap = distrPceStore.getTunnelInfos(); |
| 405 | assertThat(tunnelInfoMap, is(notNullValue())); |
| 406 | assertThat(tunnelInfoMap.isEmpty(), is(false)); |
| 407 | assertThat(tunnelInfoMap.size(), is(2)); |
| 408 | } |
| 409 | |
| 410 | /** |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 411 | * Checks the operation of getFailedPathInfos() method. |
| 412 | */ |
| 413 | @Test |
| 414 | public void testGetFailedPathInfos() { |
| 415 | testAddFailedPathInfo(); |
| 416 | |
| 417 | Iterable<PcePathInfo> failedPathInfoSet = distrPceStore.getFailedPathInfos(); |
| 418 | assertThat(failedPathInfoSet, is(notNullValue())); |
| 419 | assertThat(failedPathInfoSet.iterator().hasNext(), is(true)); |
| 420 | } |
| 421 | |
| 422 | /** |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 423 | * Checks the operation of getGlobalNodeLabel() method. |
| 424 | */ |
| 425 | @Test |
| 426 | public void testGetGlobalNodeLabel() { |
| 427 | testAddGlobalNodeLabel(); |
| 428 | |
| 429 | // deviceId1 with labelId1 |
| 430 | assertThat(deviceId1, is(notNullValue())); |
| 431 | assertThat(distrPceStore.getGlobalNodeLabel(deviceId1), is(labelId1)); |
| 432 | |
| 433 | // deviceId2 with labelId2 |
| 434 | assertThat(deviceId2, is(notNullValue())); |
| 435 | assertThat(distrPceStore.getGlobalNodeLabel(deviceId2), is(labelId2)); |
| 436 | } |
| 437 | |
| 438 | /** |
| 439 | * Checks the operation of getAdjLabel() method. |
| 440 | */ |
| 441 | @Test |
| 442 | public void testGetAdjLabel() { |
| 443 | testAddAdjLabel(); |
| 444 | |
| 445 | // link1 with labels |
| 446 | assertThat(link1, is(notNullValue())); |
| 447 | assertThat(distrPceStore.getAdjLabel(link1), is(labelId1)); |
| 448 | |
| 449 | // link2 with labels |
| 450 | assertThat(link2, is(notNullValue())); |
| 451 | assertThat(distrPceStore.getAdjLabel(link2), is(labelId2)); |
| 452 | } |
| 453 | |
| 454 | /** |
| 455 | * Checks the operation of getTunnelInfo() method. |
| 456 | */ |
| 457 | @Test |
| 458 | public void testGetTunnelInfo() { |
| 459 | testAddTunnelInfo(); |
| 460 | |
| 461 | // tunnelId1 with device label store info |
| 462 | assertThat(tunnelId1, is(notNullValue())); |
| 463 | assertThat(distrPceStore.getTunnelInfo(tunnelId1), is(pceccTunnelInfo1)); |
| 464 | |
| 465 | // tunnelId2 with device label store info |
| 466 | assertThat(tunnelId2, is(notNullValue())); |
| 467 | assertThat(distrPceStore.getTunnelInfo(tunnelId2), is(pceccTunnelInfo2)); |
| 468 | } |
| 469 | |
| 470 | /** |
| 471 | * Checks the operation of updateTunnelInfo() method. |
| 472 | */ |
| 473 | @Test |
| 474 | public void testUpdateTunnelInfo() { |
| 475 | // add tunnel info |
| 476 | testAddTunnelInfo(); |
| 477 | |
| 478 | // new updates |
| 479 | // Create pceccTunnelInfo3 |
| 480 | List<LspLocalLabelInfo> lspLocalLabelInfoList3 = new LinkedList<>(); |
| 481 | ResourceConsumer tunnelConsumerId3 = TunnelConsumerId.valueOf(30); |
| 482 | |
| 483 | DeviceId deviceId3 = DeviceId.deviceId("goo"); |
| 484 | LabelResourceId inLabelId3 = LabelResourceId.labelResourceId(3); |
| 485 | LabelResourceId outLabelId3 = LabelResourceId.labelResourceId(4); |
| 486 | |
| 487 | LspLocalLabelInfo lspLocalLabel3 = DefaultLspLocalLabelInfo.builder() |
| 488 | .deviceId(deviceId3) |
| 489 | .inLabelId(inLabelId3) |
| 490 | .outLabelId(outLabelId3) |
| 491 | .build(); |
| 492 | lspLocalLabelInfoList3.add(lspLocalLabel3); |
| 493 | |
| 494 | PceccTunnelInfo pceccTunnelInfo3 = new PceccTunnelInfo(lspLocalLabelInfoList3, tunnelConsumerId3); |
| 495 | |
| 496 | // Create pceccTunnelInfo4 |
| 497 | List<LspLocalLabelInfo> lspLocalLabelInfoList4 = new LinkedList<>(); |
| 498 | ResourceConsumer tunnelConsumerId4 = TunnelConsumerId.valueOf(40); |
| 499 | |
| 500 | DeviceId deviceId4 = DeviceId.deviceId("goo"); |
| 501 | LabelResourceId inLabelId4 = LabelResourceId.labelResourceId(4); |
| 502 | LabelResourceId outLabelId4 = LabelResourceId.labelResourceId(5); |
| 503 | |
| 504 | LspLocalLabelInfo lspLocalLabel4 = DefaultLspLocalLabelInfo.builder() |
| 505 | .deviceId(deviceId4) |
| 506 | .inLabelId(inLabelId4) |
| 507 | .outLabelId(outLabelId4) |
| 508 | .build(); |
| 509 | lspLocalLabelInfoList4.add(lspLocalLabel4); |
| 510 | |
| 511 | PceccTunnelInfo pceccTunnelInfo4 = new PceccTunnelInfo(lspLocalLabelInfoList4, tunnelConsumerId4); |
| 512 | |
| 513 | // update only lspLocalLabelInfoList |
| 514 | assertThat(distrPceStore.updateTunnelInfo(tunnelId1, lspLocalLabelInfoList3), is(true)); |
| 515 | assertThat(distrPceStore.updateTunnelInfo(tunnelId2, lspLocalLabelInfoList4), is(true)); |
| 516 | |
| 517 | // update only tunnelConsumerId |
| 518 | assertThat(distrPceStore.updateTunnelInfo(tunnelId1, tunnelConsumerId3), is(true)); |
| 519 | assertThat(distrPceStore.updateTunnelInfo(tunnelId2, tunnelConsumerId4), is(true)); |
| 520 | |
| 521 | assertThat(distrPceStore.getTunnelInfo(tunnelId1), is(pceccTunnelInfo3)); |
| 522 | assertThat(distrPceStore.getTunnelInfo(tunnelId2), is(pceccTunnelInfo4)); |
| 523 | } |
| 524 | |
| 525 | /** |
| 526 | * Checks the operation of removeGlobalNodeLabel() method. |
| 527 | */ |
| 528 | @Test |
| 529 | public void testRemoveGlobalNodeLabel() { |
| 530 | testAddGlobalNodeLabel(); |
| 531 | |
| 532 | assertThat(distrPceStore.removeGlobalNodeLabel(deviceId1), is(true)); |
| 533 | assertThat(distrPceStore.removeGlobalNodeLabel(deviceId2), is(true)); |
| 534 | } |
| 535 | |
| 536 | /** |
| 537 | * Checks the operation of removeAdjLabel() method. |
| 538 | */ |
| 539 | @Test |
| 540 | public void testRemoveAdjLabel() { |
| 541 | testAddAdjLabel(); |
| 542 | |
| 543 | assertThat(distrPceStore.removeAdjLabel(link1), is(true)); |
| 544 | assertThat(distrPceStore.removeAdjLabel(link2), is(true)); |
| 545 | } |
| 546 | |
| 547 | /** |
| 548 | * Checks the operation of removeTunnelInfo() method. |
| 549 | */ |
| 550 | @Test |
| 551 | public void testRemoveTunnelInfo() { |
| 552 | testAddTunnelInfo(); |
| 553 | |
| 554 | assertThat(distrPceStore.removeTunnelInfo(tunnelId1), is(true)); |
| 555 | assertThat(distrPceStore.removeTunnelInfo(tunnelId2), is(true)); |
| 556 | } |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 557 | |
| 558 | /** |
| 559 | * Checks the operation of removeFailedPathInfo() method. |
| 560 | */ |
| 561 | @Test |
| 562 | public void testRemoveFailedPathInfo() { |
| 563 | testAddFailedPathInfo(); |
| 564 | |
| 565 | assertThat(distrPceStore.removeFailedPathInfo(failedPathInfo1), is(true)); |
| 566 | assertThat(distrPceStore.removeFailedPathInfo(failedPathInfo2), is(true)); |
| 567 | assertThat(distrPceStore.removeFailedPathInfo(failedPathInfo3), is(false)); |
| 568 | assertThat(distrPceStore.removeFailedPathInfo(failedPathInfo4), is(false)); |
| 569 | } |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 570 | } |