blob: a9bc3bc5a883fa2294cc5366fa71ddc7c5c32aae [file] [log] [blame]
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +05303 *
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 */
Avantika-Huawei9e848e82016-09-01 12:12:42 +053016package org.onosproject.pcelabelstore.label;
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053017
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 Sa4df1aa2016-05-13 08:53:53 +053023import java.util.Iterator;
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053024import java.util.List;
25import java.util.LinkedList;
26
27import org.junit.After;
28import org.junit.Before;
29import org.junit.Test;
Ray Milkeya7cf8c82018-02-08 15:07:06 -080030import org.onlab.graph.ScalarWeight;
Avantika-Huawei9e848e82016-09-01 12:12:42 +053031import org.onlab.packet.IpAddress;
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053032import org.onosproject.incubator.net.resource.label.LabelResourceId;
33import org.onosproject.incubator.net.resource.label.LabelResourceAdminService;
34import org.onosproject.incubator.net.resource.label.LabelResourceService;
35import org.onosproject.incubator.net.tunnel.LabelStack;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053036import org.onosproject.net.AnnotationKeys;
37import org.onosproject.net.Annotations;
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053038import org.onosproject.net.ConnectPoint;
39import org.onosproject.net.DefaultAnnotations;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053040import org.onosproject.net.DefaultDevice;
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053041import org.onosproject.net.DefaultPath;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053042import org.onosproject.net.Device;
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053043import org.onosproject.net.DeviceId;
44import org.onosproject.net.PortNumber;
45import org.onosproject.net.Path;
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053046import org.onosproject.net.provider.ProviderId;
Avantika-Huawei9e848e82016-09-01 12:12:42 +053047import org.onosproject.pcelabelstore.api.PceLabelStore;
48import org.onosproject.pcelabelstore.util.LabelResourceAdapter;
49import org.onosproject.pcelabelstore.util.MockDeviceService;
50import org.onosproject.pcelabelstore.util.MockNetConfigRegistryAdapter;
51import org.onosproject.pcelabelstore.util.MockPcepClientController;
52import org.onosproject.pcelabelstore.util.PceLabelStoreAdapter;
53import org.onosproject.pcelabelstore.util.PcepClientAdapter;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053054import org.onosproject.pcep.api.DeviceCapability;
harikrushna-Huaweia2c7c202017-04-10 18:22:00 +053055import org.onosproject.pcep.server.PccId;
56import org.onosproject.pcep.server.impl.PceccSrTeBeHandler;
Avantika-Huawei9e848e82016-09-01 12:12:42 +053057import org.onosproject.pcepio.protocol.PcepVersion;
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053058import org.onosproject.net.DefaultLink;
59import org.onosproject.net.Link;
60
61/**
62 * Unit tests for PceccSrTeBeHandler class.
63 */
64public class PceccSrTeBeHandlerTest {
65
66 public static final long GLOBAL_LABEL_SPACE_MIN = 4097;
67 public static final long GLOBAL_LABEL_SPACE_MAX = 5121;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053068 private static final String L3 = "L3";
69 private static final String LSRID = "lsrId";
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053070
71 private PceccSrTeBeHandler srTeHandler;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053072 private LabelResourceAdminService labelRsrcAdminService;
73 private LabelResourceService labelRsrcService;
Avantika-Huawei9e848e82016-09-01 12:12:42 +053074 private PceLabelStore pceStore;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053075 private MockDeviceService deviceService;
Avantika-Huawei9e848e82016-09-01 12:12:42 +053076 private MockNetConfigRegistryAdapter netCfgService = new MockNetConfigRegistryAdapter();
77 private MockPcepClientController clientController = new MockPcepClientController();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053078 private ProviderId providerId;
Avantika-Huawei9e848e82016-09-01 12:12:42 +053079 private DeviceId deviceId1, deviceId2, deviceId3, deviceId4, deviceId5;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053080 private Device deviceD1;
81 private Device deviceD2;
82 private Device deviceD3;
83 private Device deviceD4;
84 private Device deviceD5;
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053085 private PortNumber port1;
86 private PortNumber port2;
87 private PortNumber port3;
88 private PortNumber port4;
89 private PortNumber port5;
90 private Link link1;
91 private Link link2;
92 private Link link3;
93 private Link link4;
94 private Path path1;
95 LabelResourceId labelId;
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053096
97 @Before
98 public void setUp() throws Exception {
99 // Initialization of member variables
100 srTeHandler = PceccSrTeBeHandler.getInstance();
101 labelRsrcService = new LabelResourceAdapter();
102 labelRsrcAdminService = new LabelResourceAdapter();
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530103 pceStore = new PceLabelStoreAdapter();
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530104 deviceService = new MockDeviceService();
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530105
106 srTeHandler.initialize(labelRsrcAdminService,
107 labelRsrcService,
108 clientController,
109 pceStore,
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530110 deviceService);
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530111
112 // Creates path
113 // Creates list of links
114 providerId = new ProviderId("of", "foo");
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530115
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530116 PccId pccId1 = PccId.pccId(IpAddress.valueOf("11.1.1.1"));
117 PccId pccId2 = PccId.pccId(IpAddress.valueOf("12.1.1.1"));
118 PccId pccId3 = PccId.pccId(IpAddress.valueOf("13.1.1.1"));
119 PccId pccId4 = PccId.pccId(IpAddress.valueOf("14.1.1.1"));
120 PccId pccId5 = PccId.pccId(IpAddress.valueOf("15.1.1.1"));
121
122 PcepClientAdapter pc1 = new PcepClientAdapter();
123 pc1.init(pccId1, PcepVersion.PCEP_1);
124
125 PcepClientAdapter pc2 = new PcepClientAdapter();
126 pc2.init(pccId2, PcepVersion.PCEP_1);
127
128 PcepClientAdapter pc3 = new PcepClientAdapter();
129 pc3.init(pccId3, PcepVersion.PCEP_1);
130
131 PcepClientAdapter pc4 = new PcepClientAdapter();
132 pc4.init(pccId4, PcepVersion.PCEP_1);
133
134 PcepClientAdapter pc5 = new PcepClientAdapter();
135 pc5.init(pccId5, PcepVersion.PCEP_1);
136
137 clientController.addClient(pccId1, pc1);
138 clientController.addClient(pccId2, pc2);
139 clientController.addClient(pccId3, pc3);
140 clientController.addClient(pccId4, pc4);
141 clientController.addClient(pccId5, pc5);
142
143 deviceId1 = DeviceId.deviceId("11.1.1.1");
144 deviceId2 = DeviceId.deviceId("12.1.1.1");
145 deviceId3 = DeviceId.deviceId("13.1.1.1");
146 deviceId4 = DeviceId.deviceId("14.1.1.1");
147 deviceId5 = DeviceId.deviceId("15.1.1.1");
148
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530149 // Devices
150 DefaultAnnotations.Builder builderDev1 = DefaultAnnotations.builder();
151 DefaultAnnotations.Builder builderDev2 = DefaultAnnotations.builder();
152 DefaultAnnotations.Builder builderDev3 = DefaultAnnotations.builder();
153 DefaultAnnotations.Builder builderDev4 = DefaultAnnotations.builder();
154 DefaultAnnotations.Builder builderDev5 = DefaultAnnotations.builder();
155
156 builderDev1.set(AnnotationKeys.TYPE, L3);
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530157 builderDev1.set(LSRID, "11.1.1.1");
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530158
159 builderDev2.set(AnnotationKeys.TYPE, L3);
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530160 builderDev2.set(LSRID, "12.1.1.1");
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530161
162 builderDev3.set(AnnotationKeys.TYPE, L3);
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530163 builderDev3.set(LSRID, "13.1.1.1");
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530164
165 builderDev4.set(AnnotationKeys.TYPE, L3);
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530166 builderDev4.set(LSRID, "14.1.1.1");
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530167
168 builderDev5.set(AnnotationKeys.TYPE, L3);
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530169 builderDev5.set(LSRID, "15.1.1.1");
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530170
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530171 deviceD1 = new MockDevice(deviceId1, builderDev1.build());
172 deviceD2 = new MockDevice(deviceId2, builderDev2.build());
173 deviceD3 = new MockDevice(deviceId3, builderDev3.build());
174 deviceD4 = new MockDevice(deviceId4, builderDev4.build());
175 deviceD5 = new MockDevice(deviceId5, builderDev5.build());
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530176
177 deviceService.addDevice(deviceD1);
178 deviceService.addDevice(deviceD2);
179 deviceService.addDevice(deviceD3);
180 deviceService.addDevice(deviceD4);
181 deviceService.addDevice(deviceD5);
182
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530183 DeviceCapability device1Cap = netCfgService.addConfig(deviceId1, DeviceCapability.class);
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530184 device1Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply();
185
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530186 DeviceCapability device2Cap = netCfgService.addConfig(deviceId2, DeviceCapability.class);
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530187 device2Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply();
188
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530189 DeviceCapability device3Cap = netCfgService.addConfig(deviceId3, DeviceCapability.class);
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530190 device3Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply();
191
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530192 DeviceCapability device4Cap = netCfgService.addConfig(deviceId4, DeviceCapability.class);
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530193 device4Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply();
194
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530195 DeviceCapability device5Cap = netCfgService.addConfig(deviceId5, DeviceCapability.class);
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530196 device5Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply();
197
198 // Port Numbers
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530199 port1 = PortNumber.portNumber(1);
200 port2 = PortNumber.portNumber(2);
201 port3 = PortNumber.portNumber(3);
202 port4 = PortNumber.portNumber(4);
203 port5 = PortNumber.portNumber(5);
204 List<Link> linkList = new LinkedList<>();
205
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530206 link1 = DefaultLink.builder().providerId(providerId)
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530207 .annotations(DefaultAnnotations.builder().set("key1", "yahoo").build())
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530208 .src(new ConnectPoint(deviceD1.id(), port1)).dst(new ConnectPoint(deviceD2.id(), port2)).type(DIRECT)
209 .state(Link.State.ACTIVE).build();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530210 linkList.add(link1);
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530211 link2 = DefaultLink.builder().providerId(providerId)
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530212 .annotations(DefaultAnnotations.builder().set("key2", "yahoo").build())
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530213 .src(new ConnectPoint(deviceD2.id(), port2)).dst(new ConnectPoint(deviceD3.id(), port3)).type(DIRECT)
214 .state(Link.State.ACTIVE).build();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530215 linkList.add(link2);
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530216 link3 = DefaultLink.builder().providerId(providerId)
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530217 .annotations(DefaultAnnotations.builder().set("key3", "yahoo").build())
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530218 .src(new ConnectPoint(deviceD3.id(), port3)).dst(new ConnectPoint(deviceD4.id(), port4)).type(DIRECT)
219 .state(Link.State.ACTIVE).build();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530220 linkList.add(link3);
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530221 link4 = DefaultLink.builder().providerId(providerId)
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530222 .annotations(DefaultAnnotations.builder().set("key4", "yahoo").build())
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530223 .src(new ConnectPoint(deviceD4.id(), port4)).dst(new ConnectPoint(deviceD5.id(), port5)).type(DIRECT)
224 .state(Link.State.ACTIVE).build();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530225 linkList.add(link4);
226
227 // Path
Ray Milkeya7cf8c82018-02-08 15:07:06 -0800228 path1 = new DefaultPath(providerId, linkList, ScalarWeight.toWeight(10));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530229 }
230
231 @After
232 public void tearDown() throws Exception {
233 }
234
235 /**
236 * Checks the operation of getInstance() method.
237 */
238 @Test
239 public void testGetInstance() {
240 assertThat(srTeHandler, is(notNullValue()));
241 }
242
243 /**
244 * Checks the operation of reserveGlobalPool() method.
245 */
246 @Test
247 public void testReserveGlobalPool() {
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530248 assertThat(srTeHandler.reserveGlobalPool(GLOBAL_LABEL_SPACE_MIN, GLOBAL_LABEL_SPACE_MAX), is(true));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530249 }
250
251 /**
252 * Checks the operation of allocateNodeLabel() method on node label.
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530253 */
254 @Test
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530255 public void testAllocateNodeLabel() {
256 // Specific device D1.deviceId
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530257
258 //device 1
259 String lsrId1 = "11.1.1.1";
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530260 // Allocate node label for specific device D1deviceId
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530261 assertThat(srTeHandler.allocateNodeLabel(deviceId1, lsrId1), is(true));
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530262 // Retrieve label from store
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530263 LabelResourceId labelId = pceStore.getGlobalNodeLabel(deviceId1);
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530264 // Check whether label is generated for this device D1.deviceId()
265 assertThat(labelId, is(notNullValue()));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530266
267 // device 2
268 String lsrId2 = "12.1.1.1";
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530269 // Allocate node label for specific device D2.deviceId()
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530270 assertThat(srTeHandler.allocateNodeLabel(deviceId2, lsrId2), is(true));
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530271 // Retrieve label from store
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530272 labelId = pceStore.getGlobalNodeLabel(deviceId2);
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530273 // Check whether label is generated for this device D2.deviceId()
274 assertThat(labelId, is(notNullValue()));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530275
276 // device 3
277 String lsrId3 = "13.1.1.1";
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530278 // Allocate node label for specific device D3.deviceId()
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530279 assertThat(srTeHandler.allocateNodeLabel(deviceId3, lsrId3), is(true));
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530280 // Retrieve label from store
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530281 labelId = pceStore.getGlobalNodeLabel(deviceId3);
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530282 // Check whether label is generated for this device D3.deviceId()
283 assertThat(labelId, is(notNullValue()));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530284
285 // device 4
286 String lsrId4 = "14.1.1.1";
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530287 // Allocate node label for specific device D4.deviceId()
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530288 assertThat(srTeHandler.allocateNodeLabel(deviceId4, lsrId4), is(true));
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530289 // Retrieve label from store
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530290 labelId = pceStore.getGlobalNodeLabel(deviceId4);
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530291 // Check whether label is generated for this device D4.deviceId()
292 assertThat(labelId, is(notNullValue()));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530293
294 // device 5
295 String lsrId5 = "15.1.1.1";
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530296 // Allocate node label for specific device D5.deviceId()
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530297 assertThat(srTeHandler.allocateNodeLabel(deviceId5, lsrId5), is(true));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530298 // Retrieve label from store
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530299 labelId = pceStore.getGlobalNodeLabel(deviceId5);
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530300 // Check whether label is generated for this device D5.deviceId()
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530301 assertThat(labelId, is(notNullValue()));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530302 }
303
304 /**
305 * Checks the operation of releaseNodeLabel() method on node label.
306 */
307 @Test
308 public void testReleaseNodeLabelSuccess() {
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530309 testAllocateNodeLabel();
310 // Specific device D1.deviceId()
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530311
312 //device 1
313 String lsrId1 = "11.1.1.1";
314 // Check whether successfully released node label
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530315 assertThat(srTeHandler.releaseNodeLabel(deviceId1, lsrId1), is(true));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530316 // Check whether successfully removed label from store
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530317 LabelResourceId labelId = pceStore.getGlobalNodeLabel(deviceId1);
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530318 assertThat(labelId, is(nullValue()));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530319
320 //device 2
321 String lsrId2 = "12.1.1.1";
322 // Check whether successfully released node label
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530323 assertThat(srTeHandler.releaseNodeLabel(deviceId2, lsrId2), is(true));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530324 // Check whether successfully removed label from store
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530325 labelId = pceStore.getGlobalNodeLabel(deviceId2);
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530326 assertThat(labelId, is(nullValue()));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530327
328 //device 3
329 String lsrId3 = "13.1.1.1";
330 // Check whether successfully released node label
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530331 assertThat(srTeHandler.releaseNodeLabel(deviceId3, lsrId3), is(true));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530332 // Check whether successfully removed label from store
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530333 labelId = pceStore.getGlobalNodeLabel(deviceId3);
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530334 assertThat(labelId, is(nullValue()));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530335
336 //device 4
337 String lsrId4 = "14.1.1.1";
338 // Check whether successfully released node label
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530339 assertThat(srTeHandler.releaseNodeLabel(deviceId4, lsrId4), is(true));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530340 // Check whether successfully removed label from store
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530341 labelId = pceStore.getGlobalNodeLabel(deviceId4);
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530342 assertThat(labelId, is(nullValue()));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530343
344 //device 5
345 String lsrId5 = "15.1.1.1";
346 // Check whether successfully released node label
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530347 assertThat(srTeHandler.releaseNodeLabel(deviceId5, lsrId5), is(true));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530348 // Check whether successfully removed label from store
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530349 labelId = pceStore.getGlobalNodeLabel(deviceId5);
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530350 assertThat(labelId, is(nullValue()));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530351 }
352
353 @Test
354 public void testReleaseNodeLabelFailure() {
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530355 testAllocateNodeLabel();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530356
357 //device 6
358 String lsrId6 = "16.1.1.1";
359 // Check whether successfully released node label
360 DeviceId deviceId6 = DeviceId.deviceId("foo6");
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530361 assertThat(srTeHandler.releaseNodeLabel(deviceId6, lsrId6), is(false));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530362 }
363
364 /**
365 * Checks the operation of allocateAdjacencyLabel() method on adjacency label.
366 */
367 @Test
368 public void testAllocateAdjacencyLabel() {
369 // test link1
370 // Check whether adjacency label is allocated successfully.
371 assertThat(srTeHandler.allocateAdjacencyLabel(link1), is(true));
372 // Retrieve from store and check whether adjacency label is generated successfully for this device.
373 LabelResourceId labelId = pceStore.getAdjLabel(link1);
374 assertThat(labelId, is(notNullValue()));
375
376 // test link2
377 // Check whether adjacency label is allocated successfully.
378 assertThat(srTeHandler.allocateAdjacencyLabel(link2), is(true));
379 // Retrieve from store and check whether adjacency label is generated successfully for this device.
380 labelId = pceStore.getAdjLabel(link2);
381 assertThat(labelId, is(notNullValue()));
382
383 // test link3
384 // Check whether adjacency label is allocated successfully.
385 assertThat(srTeHandler.allocateAdjacencyLabel(link3), is(true));
386 // Retrieve from store and check whether adjacency label is generated successfully for this device.
387 labelId = pceStore.getAdjLabel(link3);
388 assertThat(labelId, is(notNullValue()));
389
390 // test link4
391 // Check whether adjacency label is allocated successfully.
392 assertThat(srTeHandler.allocateAdjacencyLabel(link4), is(true));
393 // Retrieve from store and check whether adjacency label is generated successfully for this device.
394 labelId = pceStore.getAdjLabel(link4);
395 assertThat(labelId, is(notNullValue()));
396 }
397
398 /**
399 * Checks the operation of releaseAdjacencyLabel() method on adjacency label.
400 */
401 @Test
402 public void testReleaseAdjacencyLabel() {
403 // Test link1
404 // Check whether adjacency label is released successfully.
405 assertThat(srTeHandler.allocateAdjacencyLabel(link1), is(true));
406 assertThat(srTeHandler.releaseAdjacencyLabel(link1), is(true));
407 // Retrieve from store and check whether adjacency label is removed successfully for this device.
408 LabelResourceId labelId = pceStore.getAdjLabel(link1);
409 assertThat(labelId, is(nullValue()));
410
411 // Test link2
412 // Check whether adjacency label is released successfully.
413 assertThat(srTeHandler.allocateAdjacencyLabel(link2), is(true));
414 assertThat(srTeHandler.releaseAdjacencyLabel(link2), is(true));
415 // Retrieve from store and check whether adjacency label is removed successfully for this device.
416 labelId = pceStore.getAdjLabel(link2);
417 assertThat(labelId, is(nullValue()));
418 }
419
420 /**
421 * Checks the operation of computeLabelStack() method.
422 */
423 @Test
424 public void testComputeLabelStack() {
425 // Allocate node labels to each devices
426 labelId = LabelResourceId.labelResourceId(4097);
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530427 pceStore.addGlobalNodeLabel(deviceId1, labelId);
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530428 labelId = LabelResourceId.labelResourceId(4098);
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530429 pceStore.addGlobalNodeLabel(deviceId2, labelId);
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530430 labelId = LabelResourceId.labelResourceId(4099);
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530431 pceStore.addGlobalNodeLabel(deviceId3, labelId);
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530432 labelId = LabelResourceId.labelResourceId(4100);
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530433 pceStore.addGlobalNodeLabel(deviceId4, labelId);
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530434 labelId = LabelResourceId.labelResourceId(4101);
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530435 pceStore.addGlobalNodeLabel(deviceId5, labelId);
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530436
437 // Allocate adjacency labels to each devices
438 labelId = LabelResourceId.labelResourceId(5122);
439 pceStore.addAdjLabel(link1, labelId);
440 labelId = LabelResourceId.labelResourceId(5123);
441 pceStore.addAdjLabel(link2, labelId);
442 labelId = LabelResourceId.labelResourceId(5124);
443 pceStore.addAdjLabel(link3, labelId);
444 labelId = LabelResourceId.labelResourceId(5125);
445 pceStore.addAdjLabel(link4, labelId);
446
447 // Compute label stack
448 LabelStack labelStack = srTeHandler.computeLabelStack(path1);
449
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530450 List<LabelResourceId> labelList = labelStack.labelResources();
451 Iterator<LabelResourceId> iterator = labelList.iterator();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530452
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530453 // check adjacency label of D1.deviceId()
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530454 labelId = iterator.next();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530455 assertThat(labelId, is(LabelResourceId.labelResourceId(5122)));
456
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530457 // check node-label of D2.deviceId()
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530458 labelId = iterator.next();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530459 assertThat(labelId, is(LabelResourceId.labelResourceId(4098)));
460
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530461 // check adjacency label of D2.deviceId()
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530462 labelId = iterator.next();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530463 assertThat(labelId, is(LabelResourceId.labelResourceId(5123)));
464
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530465 // check node-label of D3.deviceId()
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530466 labelId = iterator.next();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530467 assertThat(labelId, is(LabelResourceId.labelResourceId(4099)));
468
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530469 // check adjacency label of D3.deviceId()
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530470 labelId = iterator.next();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530471 assertThat(labelId, is(LabelResourceId.labelResourceId(5124)));
472
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530473 // check node-label of D4.deviceId()
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530474 labelId = iterator.next();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530475 assertThat(labelId, is(LabelResourceId.labelResourceId(4100)));
476
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530477 // check adjacency label of D4.deviceId()
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530478 labelId = iterator.next();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530479 assertThat(labelId, is(LabelResourceId.labelResourceId(5125)));
480
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530481 // check node-label of D5.deviceId()
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530482 labelId = iterator.next();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530483 assertThat(labelId, is(LabelResourceId.labelResourceId(4101)));
484 }
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530485
486 private class MockDevice extends DefaultDevice {
487 MockDevice(DeviceId id, Annotations annotations) {
488 super(null, id, null, null, null, null, null, null, annotations);
489 }
490 }
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530491}