Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +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.pceservice; |
| 17 | |
| 18 | import static org.hamcrest.MatcherAssert.assertThat; |
| 19 | import static org.hamcrest.Matchers.is; |
| 20 | import static org.hamcrest.Matchers.notNullValue; |
| 21 | import static org.hamcrest.Matchers.nullValue; |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 22 | import static org.onosproject.net.Link.Type.DIRECT; |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 23 | import static org.onosproject.pce.pceservice.PathComputationTest.D1; |
| 24 | import static org.onosproject.pce.pceservice.PathComputationTest.D2; |
| 25 | import static org.onosproject.pce.pceservice.PathComputationTest.D3; |
| 26 | import static org.onosproject.pce.pceservice.PathComputationTest.D4; |
| 27 | import static org.onosproject.pce.pceservice.PathComputationTest.D5; |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 28 | |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 29 | import java.util.Iterator; |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 30 | import java.util.List; |
| 31 | import java.util.LinkedList; |
| 32 | |
| 33 | import org.junit.After; |
| 34 | import org.junit.Before; |
| 35 | import org.junit.Test; |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 36 | import org.onosproject.incubator.net.resource.label.LabelResourceId; |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 37 | import org.onosproject.core.ApplicationId; |
| 38 | import org.onosproject.core.CoreService; |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 39 | import org.onosproject.incubator.net.resource.label.LabelResourceAdminService; |
| 40 | import org.onosproject.incubator.net.resource.label.LabelResourceService; |
| 41 | import org.onosproject.incubator.net.tunnel.LabelStack; |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 42 | import org.onosproject.net.AnnotationKeys; |
| 43 | import org.onosproject.net.Annotations; |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 44 | import org.onosproject.net.ConnectPoint; |
| 45 | import org.onosproject.net.DefaultAnnotations; |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 46 | import org.onosproject.net.DefaultDevice; |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 47 | import org.onosproject.net.DefaultPath; |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 48 | import org.onosproject.net.Device; |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 49 | import org.onosproject.net.DeviceId; |
| 50 | import org.onosproject.net.PortNumber; |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 51 | import org.onosproject.net.flowobjective.FlowObjectiveService; |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 52 | import org.onosproject.net.Path; |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 53 | import org.onosproject.pce.pceservice.PathComputationTest.MockNetConfigRegistryAdapter; |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 54 | import org.onosproject.pce.pcestore.api.PceStore; |
| 55 | import org.onosproject.net.provider.ProviderId; |
| 56 | import org.onosproject.pce.util.LabelResourceAdapter; |
| 57 | import org.onosproject.pce.util.PceStoreAdapter; |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 58 | import org.onosproject.pce.util.MockDeviceService; |
| 59 | import org.onosproject.pcep.api.DeviceCapability; |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 60 | import org.onosproject.net.DefaultLink; |
| 61 | import org.onosproject.net.Link; |
| 62 | |
| 63 | /** |
| 64 | * Unit tests for PceccSrTeBeHandler class. |
| 65 | */ |
| 66 | public class PceccSrTeBeHandlerTest { |
| 67 | |
| 68 | public static final long GLOBAL_LABEL_SPACE_MIN = 4097; |
| 69 | public static final long GLOBAL_LABEL_SPACE_MAX = 5121; |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 70 | private static final String L3 = "L3"; |
| 71 | private static final String LSRID = "lsrId"; |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 72 | |
| 73 | private PceccSrTeBeHandler srTeHandler; |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 74 | private CoreService coreService; |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 75 | private LabelResourceAdminService labelRsrcAdminService; |
| 76 | private LabelResourceService labelRsrcService; |
| 77 | private PceStore pceStore; |
| 78 | private MockDeviceService deviceService; |
| 79 | private FlowObjectiveService flowObjectiveService; |
| 80 | private MockNetConfigRegistryAdapter netCfgService = new PathComputationTest.MockNetConfigRegistryAdapter(); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 81 | private ApplicationId appId; |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 82 | private ProviderId providerId; |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 83 | private Device deviceD1; |
| 84 | private Device deviceD2; |
| 85 | private Device deviceD3; |
| 86 | private Device deviceD4; |
| 87 | private Device deviceD5; |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 88 | private PortNumber port1; |
| 89 | private PortNumber port2; |
| 90 | private PortNumber port3; |
| 91 | private PortNumber port4; |
| 92 | private PortNumber port5; |
| 93 | private Link link1; |
| 94 | private Link link2; |
| 95 | private Link link3; |
| 96 | private Link link4; |
| 97 | private Path path1; |
| 98 | LabelResourceId labelId; |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 99 | |
| 100 | @Before |
| 101 | public void setUp() throws Exception { |
| 102 | // Initialization of member variables |
| 103 | srTeHandler = PceccSrTeBeHandler.getInstance(); |
| 104 | labelRsrcService = new LabelResourceAdapter(); |
| 105 | labelRsrcAdminService = new LabelResourceAdapter(); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 106 | flowObjectiveService = new PceManagerTest.MockFlowObjService(); |
| 107 | coreService = new PceManagerTest.MockCoreService(); |
| 108 | appId = coreService.registerApplication("org.onosproject.pce"); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 109 | pceStore = new PceStoreAdapter(); |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 110 | deviceService = new MockDeviceService(); |
| 111 | srTeHandler.initialize(labelRsrcAdminService, labelRsrcService, flowObjectiveService, appId, pceStore, |
| 112 | deviceService); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 113 | |
| 114 | // Creates path |
| 115 | // Creates list of links |
| 116 | providerId = new ProviderId("of", "foo"); |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 117 | |
| 118 | // Devices |
| 119 | DefaultAnnotations.Builder builderDev1 = DefaultAnnotations.builder(); |
| 120 | DefaultAnnotations.Builder builderDev2 = DefaultAnnotations.builder(); |
| 121 | DefaultAnnotations.Builder builderDev3 = DefaultAnnotations.builder(); |
| 122 | DefaultAnnotations.Builder builderDev4 = DefaultAnnotations.builder(); |
| 123 | DefaultAnnotations.Builder builderDev5 = DefaultAnnotations.builder(); |
| 124 | |
| 125 | builderDev1.set(AnnotationKeys.TYPE, L3); |
| 126 | builderDev1.set(LSRID, "1.1.1.1"); |
| 127 | |
| 128 | builderDev2.set(AnnotationKeys.TYPE, L3); |
| 129 | builderDev2.set(LSRID, "2.2.2.2"); |
| 130 | |
| 131 | builderDev3.set(AnnotationKeys.TYPE, L3); |
| 132 | builderDev3.set(LSRID, "3.3.3.3"); |
| 133 | |
| 134 | builderDev4.set(AnnotationKeys.TYPE, L3); |
| 135 | builderDev4.set(LSRID, "4.4.4.4"); |
| 136 | |
| 137 | builderDev5.set(AnnotationKeys.TYPE, L3); |
| 138 | builderDev5.set(LSRID, "5.5.5.5"); |
| 139 | |
| 140 | deviceD1 = new MockDevice(D1.deviceId(), builderDev1.build()); |
| 141 | deviceD2 = new MockDevice(D2.deviceId(), builderDev2.build()); |
| 142 | deviceD3 = new MockDevice(D3.deviceId(), builderDev3.build()); |
| 143 | deviceD4 = new MockDevice(D4.deviceId(), builderDev4.build()); |
| 144 | deviceD5 = new MockDevice(D5.deviceId(), builderDev5.build()); |
| 145 | |
| 146 | deviceService.addDevice(deviceD1); |
| 147 | deviceService.addDevice(deviceD2); |
| 148 | deviceService.addDevice(deviceD3); |
| 149 | deviceService.addDevice(deviceD4); |
| 150 | deviceService.addDevice(deviceD5); |
| 151 | |
| 152 | DeviceCapability device1Cap = netCfgService.addConfig(DeviceId.deviceId("1.1.1.1"), DeviceCapability.class); |
| 153 | device1Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply(); |
| 154 | |
| 155 | DeviceCapability device2Cap = netCfgService.addConfig(DeviceId.deviceId("2.2.2.2"), DeviceCapability.class); |
| 156 | device2Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply(); |
| 157 | |
| 158 | DeviceCapability device3Cap = netCfgService.addConfig(DeviceId.deviceId("3.3.3.3"), DeviceCapability.class); |
| 159 | device3Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply(); |
| 160 | |
| 161 | DeviceCapability device4Cap = netCfgService.addConfig(DeviceId.deviceId("4.4.4.4"), DeviceCapability.class); |
| 162 | device4Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply(); |
| 163 | |
| 164 | DeviceCapability device5Cap = netCfgService.addConfig(DeviceId.deviceId("5.5.5.5"), DeviceCapability.class); |
| 165 | device5Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply(); |
| 166 | |
| 167 | // Port Numbers |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 168 | port1 = PortNumber.portNumber(1); |
| 169 | port2 = PortNumber.portNumber(2); |
| 170 | port3 = PortNumber.portNumber(3); |
| 171 | port4 = PortNumber.portNumber(4); |
| 172 | port5 = PortNumber.portNumber(5); |
| 173 | List<Link> linkList = new LinkedList<>(); |
| 174 | |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 175 | link1 = DefaultLink.builder().providerId(providerId) |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 176 | .annotations(DefaultAnnotations.builder().set("key1", "yahoo").build()) |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 177 | .src(new ConnectPoint(deviceD1.id(), port1)).dst(new ConnectPoint(deviceD2.id(), port2)).type(DIRECT) |
| 178 | .state(Link.State.ACTIVE).build(); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 179 | linkList.add(link1); |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 180 | link2 = DefaultLink.builder().providerId(providerId) |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 181 | .annotations(DefaultAnnotations.builder().set("key2", "yahoo").build()) |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 182 | .src(new ConnectPoint(deviceD2.id(), port2)).dst(new ConnectPoint(deviceD3.id(), port3)).type(DIRECT) |
| 183 | .state(Link.State.ACTIVE).build(); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 184 | linkList.add(link2); |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 185 | link3 = DefaultLink.builder().providerId(providerId) |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 186 | .annotations(DefaultAnnotations.builder().set("key3", "yahoo").build()) |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 187 | .src(new ConnectPoint(deviceD3.id(), port3)).dst(new ConnectPoint(deviceD4.id(), port4)).type(DIRECT) |
| 188 | .state(Link.State.ACTIVE).build(); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 189 | linkList.add(link3); |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 190 | link4 = DefaultLink.builder().providerId(providerId) |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 191 | .annotations(DefaultAnnotations.builder().set("key4", "yahoo").build()) |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 192 | .src(new ConnectPoint(deviceD4.id(), port4)).dst(new ConnectPoint(deviceD5.id(), port5)).type(DIRECT) |
| 193 | .state(Link.State.ACTIVE).build(); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 194 | linkList.add(link4); |
| 195 | |
| 196 | // Path |
| 197 | path1 = new DefaultPath(providerId, linkList, 10); |
| 198 | } |
| 199 | |
| 200 | @After |
| 201 | public void tearDown() throws Exception { |
Priyanka B | 413fbe8 | 2016-05-26 11:44:45 +0530 | [diff] [blame] | 202 | PceManagerTest.flowsDownloaded = 0; |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | /** |
| 206 | * Checks the operation of getInstance() method. |
| 207 | */ |
| 208 | @Test |
| 209 | public void testGetInstance() { |
| 210 | assertThat(srTeHandler, is(notNullValue())); |
| 211 | } |
| 212 | |
| 213 | /** |
| 214 | * Checks the operation of reserveGlobalPool() method. |
| 215 | */ |
| 216 | @Test |
| 217 | public void testReserveGlobalPool() { |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 218 | assertThat(srTeHandler.reserveGlobalPool(GLOBAL_LABEL_SPACE_MIN, GLOBAL_LABEL_SPACE_MAX), is(true)); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | /** |
| 222 | * Checks the operation of allocateNodeLabel() method on node label. |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 223 | */ |
| 224 | @Test |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 225 | public void testAllocateNodeLabel() { |
| 226 | // Specific device D1.deviceId |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 227 | |
| 228 | //device 1 |
| 229 | String lsrId1 = "11.1.1.1"; |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 230 | // Allocate node label for specific device D1deviceId |
| 231 | assertThat(srTeHandler.allocateNodeLabel(D1.deviceId(), lsrId1), is(true)); |
| 232 | // Retrieve label from store |
| 233 | LabelResourceId labelId = pceStore.getGlobalNodeLabel(D1.deviceId()); |
| 234 | // Check whether label is generated for this device D1.deviceId() |
| 235 | assertThat(labelId, is(notNullValue())); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 236 | |
| 237 | // device 2 |
| 238 | String lsrId2 = "12.1.1.1"; |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 239 | // Allocate node label for specific device D2.deviceId() |
| 240 | assertThat(srTeHandler.allocateNodeLabel(D2.deviceId(), lsrId2), is(true)); |
| 241 | // Retrieve label from store |
| 242 | labelId = pceStore.getGlobalNodeLabel(D2.deviceId()); |
| 243 | // Check whether label is generated for this device D2.deviceId() |
| 244 | assertThat(labelId, is(notNullValue())); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 245 | |
| 246 | // device 3 |
| 247 | String lsrId3 = "13.1.1.1"; |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 248 | // Allocate node label for specific device D3.deviceId() |
| 249 | assertThat(srTeHandler.allocateNodeLabel(D3.deviceId(), lsrId3), is(true)); |
| 250 | // Retrieve label from store |
| 251 | labelId = pceStore.getGlobalNodeLabel(D3.deviceId()); |
| 252 | // Check whether label is generated for this device D3.deviceId() |
| 253 | assertThat(labelId, is(notNullValue())); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 254 | |
| 255 | // device 4 |
| 256 | String lsrId4 = "14.1.1.1"; |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 257 | // Allocate node label for specific device D4.deviceId() |
| 258 | assertThat(srTeHandler.allocateNodeLabel(D4.deviceId(), lsrId4), is(true)); |
| 259 | // Retrieve label from store |
| 260 | labelId = pceStore.getGlobalNodeLabel(D4.deviceId()); |
| 261 | // Check whether label is generated for this device D4.deviceId() |
| 262 | assertThat(labelId, is(notNullValue())); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 263 | |
| 264 | // device 5 |
| 265 | String lsrId5 = "15.1.1.1"; |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 266 | // Allocate node label for specific device D5.deviceId() |
| 267 | assertThat(srTeHandler.allocateNodeLabel(D5.deviceId(), lsrId5), is(true)); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 268 | // Retrieve label from store |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 269 | labelId = pceStore.getGlobalNodeLabel(D5.deviceId()); |
| 270 | // Check whether label is generated for this device D5.deviceId() |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 271 | assertThat(labelId, is(notNullValue())); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | /** |
| 275 | * Checks the operation of releaseNodeLabel() method on node label. |
| 276 | */ |
| 277 | @Test |
| 278 | public void testReleaseNodeLabelSuccess() { |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 279 | testAllocateNodeLabel(); |
| 280 | // Specific device D1.deviceId() |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 281 | |
| 282 | //device 1 |
| 283 | String lsrId1 = "11.1.1.1"; |
| 284 | // Check whether successfully released node label |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 285 | assertThat(srTeHandler.releaseNodeLabel(D1.deviceId(), lsrId1), is(true)); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 286 | // Check whether successfully removed label from store |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 287 | LabelResourceId labelId = pceStore.getGlobalNodeLabel(D1.deviceId()); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 288 | assertThat(labelId, is(nullValue())); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 289 | |
| 290 | //device 2 |
| 291 | String lsrId2 = "12.1.1.1"; |
| 292 | // Check whether successfully released node label |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 293 | assertThat(srTeHandler.releaseNodeLabel(D2.deviceId(), lsrId2), is(true)); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 294 | // Check whether successfully removed label from store |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 295 | labelId = pceStore.getGlobalNodeLabel(D2.deviceId()); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 296 | assertThat(labelId, is(nullValue())); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 297 | |
| 298 | //device 3 |
| 299 | String lsrId3 = "13.1.1.1"; |
| 300 | // Check whether successfully released node label |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 301 | assertThat(srTeHandler.releaseNodeLabel(D3.deviceId(), lsrId3), is(true)); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 302 | // Check whether successfully removed label from store |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 303 | labelId = pceStore.getGlobalNodeLabel(D3.deviceId()); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 304 | assertThat(labelId, is(nullValue())); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 305 | |
| 306 | //device 4 |
| 307 | String lsrId4 = "14.1.1.1"; |
| 308 | // Check whether successfully released node label |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 309 | assertThat(srTeHandler.releaseNodeLabel(D4.deviceId(), lsrId4), is(true)); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 310 | // Check whether successfully removed label from store |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 311 | labelId = pceStore.getGlobalNodeLabel(D4.deviceId()); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 312 | assertThat(labelId, is(nullValue())); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 313 | |
| 314 | //device 5 |
| 315 | String lsrId5 = "15.1.1.1"; |
| 316 | // Check whether successfully released node label |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 317 | assertThat(srTeHandler.releaseNodeLabel(D5.deviceId(), lsrId5), is(true)); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 318 | // Check whether successfully removed label from store |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 319 | labelId = pceStore.getGlobalNodeLabel(D5.deviceId()); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 320 | assertThat(labelId, is(nullValue())); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | @Test |
| 324 | public void testReleaseNodeLabelFailure() { |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 325 | testAllocateNodeLabel(); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 326 | |
| 327 | //device 6 |
| 328 | String lsrId6 = "16.1.1.1"; |
| 329 | // Check whether successfully released node label |
| 330 | DeviceId deviceId6 = DeviceId.deviceId("foo6"); |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 331 | assertThat(srTeHandler.releaseNodeLabel(deviceId6, lsrId6), is(false)); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | /** |
| 335 | * Checks the operation of allocateAdjacencyLabel() method on adjacency label. |
| 336 | */ |
| 337 | @Test |
| 338 | public void testAllocateAdjacencyLabel() { |
| 339 | // test link1 |
| 340 | // Check whether adjacency label is allocated successfully. |
| 341 | assertThat(srTeHandler.allocateAdjacencyLabel(link1), is(true)); |
| 342 | // Retrieve from store and check whether adjacency label is generated successfully for this device. |
| 343 | LabelResourceId labelId = pceStore.getAdjLabel(link1); |
| 344 | assertThat(labelId, is(notNullValue())); |
| 345 | |
| 346 | // test link2 |
| 347 | // Check whether adjacency label is allocated successfully. |
| 348 | assertThat(srTeHandler.allocateAdjacencyLabel(link2), is(true)); |
| 349 | // Retrieve from store and check whether adjacency label is generated successfully for this device. |
| 350 | labelId = pceStore.getAdjLabel(link2); |
| 351 | assertThat(labelId, is(notNullValue())); |
| 352 | |
| 353 | // test link3 |
| 354 | // Check whether adjacency label is allocated successfully. |
| 355 | assertThat(srTeHandler.allocateAdjacencyLabel(link3), is(true)); |
| 356 | // Retrieve from store and check whether adjacency label is generated successfully for this device. |
| 357 | labelId = pceStore.getAdjLabel(link3); |
| 358 | assertThat(labelId, is(notNullValue())); |
| 359 | |
| 360 | // test link4 |
| 361 | // Check whether adjacency label is allocated successfully. |
| 362 | assertThat(srTeHandler.allocateAdjacencyLabel(link4), is(true)); |
| 363 | // Retrieve from store and check whether adjacency label is generated successfully for this device. |
| 364 | labelId = pceStore.getAdjLabel(link4); |
| 365 | assertThat(labelId, is(notNullValue())); |
| 366 | } |
| 367 | |
| 368 | /** |
| 369 | * Checks the operation of releaseAdjacencyLabel() method on adjacency label. |
| 370 | */ |
| 371 | @Test |
| 372 | public void testReleaseAdjacencyLabel() { |
| 373 | // Test link1 |
| 374 | // Check whether adjacency label is released successfully. |
| 375 | assertThat(srTeHandler.allocateAdjacencyLabel(link1), is(true)); |
| 376 | assertThat(srTeHandler.releaseAdjacencyLabel(link1), is(true)); |
| 377 | // Retrieve from store and check whether adjacency label is removed successfully for this device. |
| 378 | LabelResourceId labelId = pceStore.getAdjLabel(link1); |
| 379 | assertThat(labelId, is(nullValue())); |
| 380 | |
| 381 | // Test link2 |
| 382 | // Check whether adjacency label is released successfully. |
| 383 | assertThat(srTeHandler.allocateAdjacencyLabel(link2), is(true)); |
| 384 | assertThat(srTeHandler.releaseAdjacencyLabel(link2), is(true)); |
| 385 | // Retrieve from store and check whether adjacency label is removed successfully for this device. |
| 386 | labelId = pceStore.getAdjLabel(link2); |
| 387 | assertThat(labelId, is(nullValue())); |
| 388 | } |
| 389 | |
| 390 | /** |
| 391 | * Checks the operation of computeLabelStack() method. |
| 392 | */ |
| 393 | @Test |
| 394 | public void testComputeLabelStack() { |
| 395 | // Allocate node labels to each devices |
| 396 | labelId = LabelResourceId.labelResourceId(4097); |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 397 | pceStore.addGlobalNodeLabel(D1.deviceId(), labelId); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 398 | labelId = LabelResourceId.labelResourceId(4098); |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 399 | pceStore.addGlobalNodeLabel(D2.deviceId(), labelId); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 400 | labelId = LabelResourceId.labelResourceId(4099); |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 401 | pceStore.addGlobalNodeLabel(D3.deviceId(), labelId); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 402 | labelId = LabelResourceId.labelResourceId(4100); |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 403 | pceStore.addGlobalNodeLabel(D4.deviceId(), labelId); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 404 | labelId = LabelResourceId.labelResourceId(4101); |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 405 | pceStore.addGlobalNodeLabel(D5.deviceId(), labelId); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 406 | |
| 407 | // Allocate adjacency labels to each devices |
| 408 | labelId = LabelResourceId.labelResourceId(5122); |
| 409 | pceStore.addAdjLabel(link1, labelId); |
| 410 | labelId = LabelResourceId.labelResourceId(5123); |
| 411 | pceStore.addAdjLabel(link2, labelId); |
| 412 | labelId = LabelResourceId.labelResourceId(5124); |
| 413 | pceStore.addAdjLabel(link3, labelId); |
| 414 | labelId = LabelResourceId.labelResourceId(5125); |
| 415 | pceStore.addAdjLabel(link4, labelId); |
| 416 | |
| 417 | // Compute label stack |
| 418 | LabelStack labelStack = srTeHandler.computeLabelStack(path1); |
| 419 | |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 420 | // check node-label of D1.deviceId() |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 421 | List<LabelResourceId> labelList = labelStack.labelResources(); |
| 422 | Iterator<LabelResourceId> iterator = labelList.iterator(); |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 423 | labelId = iterator.next(); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 424 | assertThat(labelId, is(LabelResourceId.labelResourceId(4097))); |
| 425 | |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 426 | // check adjacency label of D1.deviceId() |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 427 | labelId = iterator.next(); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 428 | assertThat(labelId, is(LabelResourceId.labelResourceId(5122))); |
| 429 | |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 430 | // check node-label of D2.deviceId() |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 431 | labelId = iterator.next(); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 432 | assertThat(labelId, is(LabelResourceId.labelResourceId(4098))); |
| 433 | |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 434 | // check adjacency label of D2.deviceId() |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 435 | labelId = iterator.next(); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 436 | assertThat(labelId, is(LabelResourceId.labelResourceId(5123))); |
| 437 | |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 438 | // check node-label of D3.deviceId() |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 439 | labelId = iterator.next(); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 440 | assertThat(labelId, is(LabelResourceId.labelResourceId(4099))); |
| 441 | |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 442 | // check adjacency label of D3.deviceId() |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 443 | labelId = iterator.next(); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 444 | assertThat(labelId, is(LabelResourceId.labelResourceId(5124))); |
| 445 | |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 446 | // check node-label of D4.deviceId() |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 447 | labelId = iterator.next(); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 448 | assertThat(labelId, is(LabelResourceId.labelResourceId(4100))); |
| 449 | |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 450 | // check adjacency label of D4.deviceId() |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 451 | labelId = iterator.next(); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 452 | assertThat(labelId, is(LabelResourceId.labelResourceId(5125))); |
| 453 | |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 454 | // check node-label of D5.deviceId() |
Avantika-Huawei | dbdf772 | 2016-05-21 14:20:31 +0530 | [diff] [blame] | 455 | labelId = iterator.next(); |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 456 | assertThat(labelId, is(LabelResourceId.labelResourceId(4101))); |
| 457 | } |
Mahesh Poojary Huawei | 1d17cad | 2016-06-02 12:53:41 +0530 | [diff] [blame^] | 458 | |
| 459 | private class MockDevice extends DefaultDevice { |
| 460 | MockDevice(DeviceId id, Annotations annotations) { |
| 461 | super(null, id, null, null, null, null, null, null, annotations); |
| 462 | } |
| 463 | } |
Mahesh Poojary S | a4df1aa | 2016-05-13 08:53:53 +0530 | [diff] [blame] | 464 | } |