blob: 70f737699581c4606fce673ceb8f88484b2a7434 [file] [log] [blame]
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +05301/*
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 */
16package org.onosproject.pce.pceservice;
17
18import static org.hamcrest.MatcherAssert.assertThat;
19import static org.hamcrest.Matchers.is;
20import static org.hamcrest.Matchers.notNullValue;
21import static org.hamcrest.Matchers.nullValue;
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053022import static org.onosproject.net.Link.Type.DIRECT;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053023import static org.onosproject.pce.pceservice.PathComputationTest.D1;
24import static org.onosproject.pce.pceservice.PathComputationTest.D2;
25import static org.onosproject.pce.pceservice.PathComputationTest.D3;
26import static org.onosproject.pce.pceservice.PathComputationTest.D4;
27import static org.onosproject.pce.pceservice.PathComputationTest.D5;
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053028
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053029import java.util.Iterator;
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053030import java.util.List;
31import java.util.LinkedList;
32
33import org.junit.After;
34import org.junit.Before;
35import org.junit.Test;
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053036import org.onosproject.incubator.net.resource.label.LabelResourceId;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053037import org.onosproject.core.ApplicationId;
38import org.onosproject.core.CoreService;
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053039import org.onosproject.incubator.net.resource.label.LabelResourceAdminService;
40import org.onosproject.incubator.net.resource.label.LabelResourceService;
41import org.onosproject.incubator.net.tunnel.LabelStack;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053042import org.onosproject.net.AnnotationKeys;
43import org.onosproject.net.Annotations;
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053044import org.onosproject.net.ConnectPoint;
45import org.onosproject.net.DefaultAnnotations;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053046import org.onosproject.net.DefaultDevice;
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053047import org.onosproject.net.DefaultPath;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053048import org.onosproject.net.Device;
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053049import org.onosproject.net.DeviceId;
50import org.onosproject.net.PortNumber;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053051import org.onosproject.net.flowobjective.FlowObjectiveService;
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053052import org.onosproject.net.Path;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053053import org.onosproject.pce.pceservice.PathComputationTest.MockNetConfigRegistryAdapter;
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053054import org.onosproject.pce.pcestore.api.PceStore;
55import org.onosproject.net.provider.ProviderId;
56import org.onosproject.pce.util.LabelResourceAdapter;
57import org.onosproject.pce.util.PceStoreAdapter;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053058import org.onosproject.pce.util.MockDeviceService;
59import org.onosproject.pcep.api.DeviceCapability;
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053060import org.onosproject.net.DefaultLink;
61import org.onosproject.net.Link;
62
63/**
64 * Unit tests for PceccSrTeBeHandler class.
65 */
66public 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 Huawei1d17cad2016-06-02 12:53:41 +053070 private static final String L3 = "L3";
71 private static final String LSRID = "lsrId";
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053072
73 private PceccSrTeBeHandler srTeHandler;
Avantika-Huaweidbdf7722016-05-21 14:20:31 +053074 private CoreService coreService;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053075 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-Huaweidbdf7722016-05-21 14:20:31 +053081 private ApplicationId appId;
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053082 private ProviderId providerId;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053083 private Device deviceD1;
84 private Device deviceD2;
85 private Device deviceD3;
86 private Device deviceD4;
87 private Device deviceD5;
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053088 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 Sa4df1aa2016-05-13 08:53:53 +053099
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-Huaweidbdf7722016-05-21 14:20:31 +0530106 flowObjectiveService = new PceManagerTest.MockFlowObjService();
107 coreService = new PceManagerTest.MockCoreService();
108 appId = coreService.registerApplication("org.onosproject.pce");
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530109 pceStore = new PceStoreAdapter();
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530110 deviceService = new MockDeviceService();
111 srTeHandler.initialize(labelRsrcAdminService, labelRsrcService, flowObjectiveService, appId, pceStore,
112 deviceService);
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530113
114 // Creates path
115 // Creates list of links
116 providerId = new ProviderId("of", "foo");
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530117
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 Sa4df1aa2016-05-13 08:53:53 +0530168 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 Huawei1d17cad2016-06-02 12:53:41 +0530175 link1 = DefaultLink.builder().providerId(providerId)
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530176 .annotations(DefaultAnnotations.builder().set("key1", "yahoo").build())
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530177 .src(new ConnectPoint(deviceD1.id(), port1)).dst(new ConnectPoint(deviceD2.id(), port2)).type(DIRECT)
178 .state(Link.State.ACTIVE).build();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530179 linkList.add(link1);
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530180 link2 = DefaultLink.builder().providerId(providerId)
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530181 .annotations(DefaultAnnotations.builder().set("key2", "yahoo").build())
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530182 .src(new ConnectPoint(deviceD2.id(), port2)).dst(new ConnectPoint(deviceD3.id(), port3)).type(DIRECT)
183 .state(Link.State.ACTIVE).build();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530184 linkList.add(link2);
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530185 link3 = DefaultLink.builder().providerId(providerId)
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530186 .annotations(DefaultAnnotations.builder().set("key3", "yahoo").build())
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530187 .src(new ConnectPoint(deviceD3.id(), port3)).dst(new ConnectPoint(deviceD4.id(), port4)).type(DIRECT)
188 .state(Link.State.ACTIVE).build();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530189 linkList.add(link3);
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530190 link4 = DefaultLink.builder().providerId(providerId)
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530191 .annotations(DefaultAnnotations.builder().set("key4", "yahoo").build())
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530192 .src(new ConnectPoint(deviceD4.id(), port4)).dst(new ConnectPoint(deviceD5.id(), port5)).type(DIRECT)
193 .state(Link.State.ACTIVE).build();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530194 linkList.add(link4);
195
196 // Path
197 path1 = new DefaultPath(providerId, linkList, 10);
198 }
199
200 @After
201 public void tearDown() throws Exception {
Priyanka B413fbe82016-05-26 11:44:45 +0530202 PceManagerTest.flowsDownloaded = 0;
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530203 }
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 Huawei1d17cad2016-06-02 12:53:41 +0530218 assertThat(srTeHandler.reserveGlobalPool(GLOBAL_LABEL_SPACE_MIN, GLOBAL_LABEL_SPACE_MAX), is(true));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530219 }
220
221 /**
222 * Checks the operation of allocateNodeLabel() method on node label.
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530223 */
224 @Test
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530225 public void testAllocateNodeLabel() {
226 // Specific device D1.deviceId
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530227
228 //device 1
229 String lsrId1 = "11.1.1.1";
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530230 // 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 Sa4df1aa2016-05-13 08:53:53 +0530236
237 // device 2
238 String lsrId2 = "12.1.1.1";
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530239 // 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 Sa4df1aa2016-05-13 08:53:53 +0530245
246 // device 3
247 String lsrId3 = "13.1.1.1";
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530248 // 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 Sa4df1aa2016-05-13 08:53:53 +0530254
255 // device 4
256 String lsrId4 = "14.1.1.1";
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530257 // 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 Sa4df1aa2016-05-13 08:53:53 +0530263
264 // device 5
265 String lsrId5 = "15.1.1.1";
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530266 // Allocate node label for specific device D5.deviceId()
267 assertThat(srTeHandler.allocateNodeLabel(D5.deviceId(), lsrId5), is(true));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530268 // Retrieve label from store
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530269 labelId = pceStore.getGlobalNodeLabel(D5.deviceId());
270 // Check whether label is generated for this device D5.deviceId()
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530271 assertThat(labelId, is(notNullValue()));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530272 }
273
274 /**
275 * Checks the operation of releaseNodeLabel() method on node label.
276 */
277 @Test
278 public void testReleaseNodeLabelSuccess() {
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530279 testAllocateNodeLabel();
280 // Specific device D1.deviceId()
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530281
282 //device 1
283 String lsrId1 = "11.1.1.1";
284 // Check whether successfully released node label
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530285 assertThat(srTeHandler.releaseNodeLabel(D1.deviceId(), lsrId1), is(true));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530286 // Check whether successfully removed label from store
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530287 LabelResourceId labelId = pceStore.getGlobalNodeLabel(D1.deviceId());
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530288 assertThat(labelId, is(nullValue()));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530289
290 //device 2
291 String lsrId2 = "12.1.1.1";
292 // Check whether successfully released node label
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530293 assertThat(srTeHandler.releaseNodeLabel(D2.deviceId(), lsrId2), is(true));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530294 // Check whether successfully removed label from store
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530295 labelId = pceStore.getGlobalNodeLabel(D2.deviceId());
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530296 assertThat(labelId, is(nullValue()));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530297
298 //device 3
299 String lsrId3 = "13.1.1.1";
300 // Check whether successfully released node label
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530301 assertThat(srTeHandler.releaseNodeLabel(D3.deviceId(), lsrId3), is(true));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530302 // Check whether successfully removed label from store
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530303 labelId = pceStore.getGlobalNodeLabel(D3.deviceId());
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530304 assertThat(labelId, is(nullValue()));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530305
306 //device 4
307 String lsrId4 = "14.1.1.1";
308 // Check whether successfully released node label
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530309 assertThat(srTeHandler.releaseNodeLabel(D4.deviceId(), lsrId4), is(true));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530310 // Check whether successfully removed label from store
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530311 labelId = pceStore.getGlobalNodeLabel(D4.deviceId());
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530312 assertThat(labelId, is(nullValue()));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530313
314 //device 5
315 String lsrId5 = "15.1.1.1";
316 // Check whether successfully released node label
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530317 assertThat(srTeHandler.releaseNodeLabel(D5.deviceId(), lsrId5), is(true));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530318 // Check whether successfully removed label from store
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530319 labelId = pceStore.getGlobalNodeLabel(D5.deviceId());
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530320 assertThat(labelId, is(nullValue()));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530321 }
322
323 @Test
324 public void testReleaseNodeLabelFailure() {
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530325 testAllocateNodeLabel();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530326
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 Huawei1d17cad2016-06-02 12:53:41 +0530331 assertThat(srTeHandler.releaseNodeLabel(deviceId6, lsrId6), is(false));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530332 }
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 Huawei1d17cad2016-06-02 12:53:41 +0530397 pceStore.addGlobalNodeLabel(D1.deviceId(), labelId);
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530398 labelId = LabelResourceId.labelResourceId(4098);
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530399 pceStore.addGlobalNodeLabel(D2.deviceId(), labelId);
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530400 labelId = LabelResourceId.labelResourceId(4099);
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530401 pceStore.addGlobalNodeLabel(D3.deviceId(), labelId);
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530402 labelId = LabelResourceId.labelResourceId(4100);
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530403 pceStore.addGlobalNodeLabel(D4.deviceId(), labelId);
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530404 labelId = LabelResourceId.labelResourceId(4101);
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530405 pceStore.addGlobalNodeLabel(D5.deviceId(), labelId);
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530406
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 Huawei1d17cad2016-06-02 12:53:41 +0530420 // check node-label of D1.deviceId()
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530421 List<LabelResourceId> labelList = labelStack.labelResources();
422 Iterator<LabelResourceId> iterator = labelList.iterator();
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530423 labelId = iterator.next();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530424 assertThat(labelId, is(LabelResourceId.labelResourceId(4097)));
425
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530426 // check adjacency label of D1.deviceId()
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530427 labelId = iterator.next();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530428 assertThat(labelId, is(LabelResourceId.labelResourceId(5122)));
429
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530430 // check node-label of D2.deviceId()
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530431 labelId = iterator.next();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530432 assertThat(labelId, is(LabelResourceId.labelResourceId(4098)));
433
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530434 // check adjacency label of D2.deviceId()
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530435 labelId = iterator.next();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530436 assertThat(labelId, is(LabelResourceId.labelResourceId(5123)));
437
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530438 // check node-label of D3.deviceId()
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530439 labelId = iterator.next();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530440 assertThat(labelId, is(LabelResourceId.labelResourceId(4099)));
441
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530442 // check adjacency label of D3.deviceId()
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530443 labelId = iterator.next();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530444 assertThat(labelId, is(LabelResourceId.labelResourceId(5124)));
445
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530446 // check node-label of D4.deviceId()
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530447 labelId = iterator.next();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530448 assertThat(labelId, is(LabelResourceId.labelResourceId(4100)));
449
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530450 // check adjacency label of D4.deviceId()
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530451 labelId = iterator.next();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530452 assertThat(labelId, is(LabelResourceId.labelResourceId(5125)));
453
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530454 // check node-label of D5.deviceId()
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530455 labelId = iterator.next();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530456 assertThat(labelId, is(LabelResourceId.labelResourceId(4101)));
457 }
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530458
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 Sa4df1aa2016-05-13 08:53:53 +0530464}