blob: cf832c46a120230a13a83f1d7e89ec3d51226eda [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
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053018import org.junit.After;
19import org.junit.Before;
20import org.junit.Test;
Ray Milkeya7cf8c82018-02-08 15:07:06 -080021import org.onlab.graph.ScalarWeight;
Avantika-Huawei9e848e82016-09-01 12:12:42 +053022import org.onlab.packet.IpAddress;
Ray Milkeyd1c34da2018-06-22 18:10:53 -070023import org.onosproject.incubator.net.resource.label.LabelResourceAdapter;
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053024import org.onosproject.incubator.net.resource.label.LabelResourceAdminService;
Ray Milkeyd1c34da2018-06-22 18:10:53 -070025import org.onosproject.incubator.net.resource.label.LabelResourceId;
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053026import org.onosproject.incubator.net.resource.label.LabelResourceService;
27import org.onosproject.incubator.net.tunnel.LabelStack;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053028import org.onosproject.net.AnnotationKeys;
29import org.onosproject.net.Annotations;
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053030import org.onosproject.net.ConnectPoint;
31import org.onosproject.net.DefaultAnnotations;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053032import org.onosproject.net.DefaultDevice;
Ray Milkeyd1c34da2018-06-22 18:10:53 -070033import org.onosproject.net.DefaultLink;
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053034import org.onosproject.net.DefaultPath;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053035import org.onosproject.net.Device;
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053036import org.onosproject.net.DeviceId;
Ray Milkeyd1c34da2018-06-22 18:10:53 -070037import org.onosproject.net.Link;
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053038import org.onosproject.net.Path;
Ray Milkeyd1c34da2018-06-22 18:10:53 -070039import org.onosproject.net.PortNumber;
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053040import org.onosproject.net.provider.ProviderId;
Avantika-Huawei9e848e82016-09-01 12:12:42 +053041import org.onosproject.pcelabelstore.api.PceLabelStore;
Ray Milkeyd1c34da2018-06-22 18:10:53 -070042import org.onosproject.pcelabelstore.api.PceLabelStoreAdapter;
Avantika-Huawei9e848e82016-09-01 12:12:42 +053043import org.onosproject.pcelabelstore.util.MockDeviceService;
44import org.onosproject.pcelabelstore.util.MockNetConfigRegistryAdapter;
45import org.onosproject.pcelabelstore.util.MockPcepClientController;
Ray Milkeyd1c34da2018-06-22 18:10:53 -070046import org.onosproject.pcep.server.PcepClientAdapter;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053047import org.onosproject.pcep.api.DeviceCapability;
harikrushna-Huaweia2c7c202017-04-10 18:22:00 +053048import org.onosproject.pcep.server.PccId;
49import org.onosproject.pcep.server.impl.PceccSrTeBeHandler;
Avantika-Huawei9e848e82016-09-01 12:12:42 +053050import org.onosproject.pcepio.protocol.PcepVersion;
Ray Milkeyd1c34da2018-06-22 18:10:53 -070051
52import java.util.Iterator;
53import java.util.LinkedList;
54import java.util.List;
55
56import static org.hamcrest.MatcherAssert.assertThat;
57import static org.hamcrest.Matchers.is;
58import static org.hamcrest.Matchers.notNullValue;
59import static org.hamcrest.Matchers.nullValue;
60import static org.onosproject.net.Link.Type.DIRECT;
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053061
62/**
63 * Unit tests for PceccSrTeBeHandler class.
64 */
65public class PceccSrTeBeHandlerTest {
66
67 public static final long GLOBAL_LABEL_SPACE_MIN = 4097;
68 public static final long GLOBAL_LABEL_SPACE_MAX = 5121;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053069 private static final String L3 = "L3";
70 private static final String LSRID = "lsrId";
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053071
72 private PceccSrTeBeHandler srTeHandler;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053073 private LabelResourceAdminService labelRsrcAdminService;
74 private LabelResourceService labelRsrcService;
Avantika-Huawei9e848e82016-09-01 12:12:42 +053075 private PceLabelStore pceStore;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053076 private MockDeviceService deviceService;
Avantika-Huawei9e848e82016-09-01 12:12:42 +053077 private MockNetConfigRegistryAdapter netCfgService = new MockNetConfigRegistryAdapter();
78 private MockPcepClientController clientController = new MockPcepClientController();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053079 private ProviderId providerId;
Avantika-Huawei9e848e82016-09-01 12:12:42 +053080 private DeviceId deviceId1, deviceId2, deviceId3, deviceId4, deviceId5;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053081 private Device deviceD1;
82 private Device deviceD2;
83 private Device deviceD3;
84 private Device deviceD4;
85 private Device deviceD5;
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053086 private PortNumber port1;
87 private PortNumber port2;
88 private PortNumber port3;
89 private PortNumber port4;
90 private PortNumber port5;
91 private Link link1;
92 private Link link2;
93 private Link link3;
94 private Link link4;
95 private Path path1;
96 LabelResourceId labelId;
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053097
98 @Before
99 public void setUp() throws Exception {
100 // Initialization of member variables
101 srTeHandler = PceccSrTeBeHandler.getInstance();
102 labelRsrcService = new LabelResourceAdapter();
103 labelRsrcAdminService = new LabelResourceAdapter();
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530104 pceStore = new PceLabelStoreAdapter();
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530105 deviceService = new MockDeviceService();
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530106
107 srTeHandler.initialize(labelRsrcAdminService,
108 labelRsrcService,
109 clientController,
110 pceStore,
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530111 deviceService);
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530112
113 // Creates path
114 // Creates list of links
115 providerId = new ProviderId("of", "foo");
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530116
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530117 PccId pccId1 = PccId.pccId(IpAddress.valueOf("11.1.1.1"));
118 PccId pccId2 = PccId.pccId(IpAddress.valueOf("12.1.1.1"));
119 PccId pccId3 = PccId.pccId(IpAddress.valueOf("13.1.1.1"));
120 PccId pccId4 = PccId.pccId(IpAddress.valueOf("14.1.1.1"));
121 PccId pccId5 = PccId.pccId(IpAddress.valueOf("15.1.1.1"));
122
123 PcepClientAdapter pc1 = new PcepClientAdapter();
124 pc1.init(pccId1, PcepVersion.PCEP_1);
125
126 PcepClientAdapter pc2 = new PcepClientAdapter();
127 pc2.init(pccId2, PcepVersion.PCEP_1);
128
129 PcepClientAdapter pc3 = new PcepClientAdapter();
130 pc3.init(pccId3, PcepVersion.PCEP_1);
131
132 PcepClientAdapter pc4 = new PcepClientAdapter();
133 pc4.init(pccId4, PcepVersion.PCEP_1);
134
135 PcepClientAdapter pc5 = new PcepClientAdapter();
136 pc5.init(pccId5, PcepVersion.PCEP_1);
137
138 clientController.addClient(pccId1, pc1);
139 clientController.addClient(pccId2, pc2);
140 clientController.addClient(pccId3, pc3);
141 clientController.addClient(pccId4, pc4);
142 clientController.addClient(pccId5, pc5);
143
144 deviceId1 = DeviceId.deviceId("11.1.1.1");
145 deviceId2 = DeviceId.deviceId("12.1.1.1");
146 deviceId3 = DeviceId.deviceId("13.1.1.1");
147 deviceId4 = DeviceId.deviceId("14.1.1.1");
148 deviceId5 = DeviceId.deviceId("15.1.1.1");
149
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530150 // Devices
151 DefaultAnnotations.Builder builderDev1 = DefaultAnnotations.builder();
152 DefaultAnnotations.Builder builderDev2 = DefaultAnnotations.builder();
153 DefaultAnnotations.Builder builderDev3 = DefaultAnnotations.builder();
154 DefaultAnnotations.Builder builderDev4 = DefaultAnnotations.builder();
155 DefaultAnnotations.Builder builderDev5 = DefaultAnnotations.builder();
156
157 builderDev1.set(AnnotationKeys.TYPE, L3);
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530158 builderDev1.set(LSRID, "11.1.1.1");
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530159
160 builderDev2.set(AnnotationKeys.TYPE, L3);
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530161 builderDev2.set(LSRID, "12.1.1.1");
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530162
163 builderDev3.set(AnnotationKeys.TYPE, L3);
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530164 builderDev3.set(LSRID, "13.1.1.1");
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530165
166 builderDev4.set(AnnotationKeys.TYPE, L3);
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530167 builderDev4.set(LSRID, "14.1.1.1");
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530168
169 builderDev5.set(AnnotationKeys.TYPE, L3);
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530170 builderDev5.set(LSRID, "15.1.1.1");
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530171
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530172 deviceD1 = new MockDevice(deviceId1, builderDev1.build());
173 deviceD2 = new MockDevice(deviceId2, builderDev2.build());
174 deviceD3 = new MockDevice(deviceId3, builderDev3.build());
175 deviceD4 = new MockDevice(deviceId4, builderDev4.build());
176 deviceD5 = new MockDevice(deviceId5, builderDev5.build());
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530177
178 deviceService.addDevice(deviceD1);
179 deviceService.addDevice(deviceD2);
180 deviceService.addDevice(deviceD3);
181 deviceService.addDevice(deviceD4);
182 deviceService.addDevice(deviceD5);
183
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530184 DeviceCapability device1Cap = netCfgService.addConfig(deviceId1, DeviceCapability.class);
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530185 device1Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply();
186
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530187 DeviceCapability device2Cap = netCfgService.addConfig(deviceId2, DeviceCapability.class);
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530188 device2Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply();
189
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530190 DeviceCapability device3Cap = netCfgService.addConfig(deviceId3, DeviceCapability.class);
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530191 device3Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply();
192
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530193 DeviceCapability device4Cap = netCfgService.addConfig(deviceId4, DeviceCapability.class);
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530194 device4Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply();
195
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530196 DeviceCapability device5Cap = netCfgService.addConfig(deviceId5, DeviceCapability.class);
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530197 device5Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply();
198
199 // Port Numbers
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530200 port1 = PortNumber.portNumber(1);
201 port2 = PortNumber.portNumber(2);
202 port3 = PortNumber.portNumber(3);
203 port4 = PortNumber.portNumber(4);
204 port5 = PortNumber.portNumber(5);
205 List<Link> linkList = new LinkedList<>();
206
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530207 link1 = DefaultLink.builder().providerId(providerId)
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530208 .annotations(DefaultAnnotations.builder().set("key1", "yahoo").build())
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530209 .src(new ConnectPoint(deviceD1.id(), port1)).dst(new ConnectPoint(deviceD2.id(), port2)).type(DIRECT)
210 .state(Link.State.ACTIVE).build();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530211 linkList.add(link1);
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530212 link2 = DefaultLink.builder().providerId(providerId)
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530213 .annotations(DefaultAnnotations.builder().set("key2", "yahoo").build())
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530214 .src(new ConnectPoint(deviceD2.id(), port2)).dst(new ConnectPoint(deviceD3.id(), port3)).type(DIRECT)
215 .state(Link.State.ACTIVE).build();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530216 linkList.add(link2);
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530217 link3 = DefaultLink.builder().providerId(providerId)
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530218 .annotations(DefaultAnnotations.builder().set("key3", "yahoo").build())
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530219 .src(new ConnectPoint(deviceD3.id(), port3)).dst(new ConnectPoint(deviceD4.id(), port4)).type(DIRECT)
220 .state(Link.State.ACTIVE).build();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530221 linkList.add(link3);
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530222 link4 = DefaultLink.builder().providerId(providerId)
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530223 .annotations(DefaultAnnotations.builder().set("key4", "yahoo").build())
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530224 .src(new ConnectPoint(deviceD4.id(), port4)).dst(new ConnectPoint(deviceD5.id(), port5)).type(DIRECT)
225 .state(Link.State.ACTIVE).build();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530226 linkList.add(link4);
227
228 // Path
Ray Milkeya7cf8c82018-02-08 15:07:06 -0800229 path1 = new DefaultPath(providerId, linkList, ScalarWeight.toWeight(10));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530230 }
231
232 @After
233 public void tearDown() throws Exception {
234 }
235
236 /**
237 * Checks the operation of getInstance() method.
238 */
239 @Test
240 public void testGetInstance() {
241 assertThat(srTeHandler, is(notNullValue()));
242 }
243
244 /**
245 * Checks the operation of reserveGlobalPool() method.
246 */
247 @Test
248 public void testReserveGlobalPool() {
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530249 assertThat(srTeHandler.reserveGlobalPool(GLOBAL_LABEL_SPACE_MIN, GLOBAL_LABEL_SPACE_MAX), is(true));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530250 }
251
252 /**
253 * Checks the operation of allocateNodeLabel() method on node label.
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530254 */
255 @Test
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530256 public void testAllocateNodeLabel() {
257 // Specific device D1.deviceId
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530258
259 //device 1
260 String lsrId1 = "11.1.1.1";
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530261 // Allocate node label for specific device D1deviceId
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530262 assertThat(srTeHandler.allocateNodeLabel(deviceId1, lsrId1), is(true));
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530263 // Retrieve label from store
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530264 LabelResourceId labelId = pceStore.getGlobalNodeLabel(deviceId1);
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530265 // Check whether label is generated for this device D1.deviceId()
266 assertThat(labelId, is(notNullValue()));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530267
268 // device 2
269 String lsrId2 = "12.1.1.1";
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530270 // Allocate node label for specific device D2.deviceId()
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530271 assertThat(srTeHandler.allocateNodeLabel(deviceId2, lsrId2), is(true));
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530272 // Retrieve label from store
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530273 labelId = pceStore.getGlobalNodeLabel(deviceId2);
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530274 // Check whether label is generated for this device D2.deviceId()
275 assertThat(labelId, is(notNullValue()));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530276
277 // device 3
278 String lsrId3 = "13.1.1.1";
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530279 // Allocate node label for specific device D3.deviceId()
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530280 assertThat(srTeHandler.allocateNodeLabel(deviceId3, lsrId3), is(true));
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530281 // Retrieve label from store
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530282 labelId = pceStore.getGlobalNodeLabel(deviceId3);
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530283 // Check whether label is generated for this device D3.deviceId()
284 assertThat(labelId, is(notNullValue()));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530285
286 // device 4
287 String lsrId4 = "14.1.1.1";
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530288 // Allocate node label for specific device D4.deviceId()
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530289 assertThat(srTeHandler.allocateNodeLabel(deviceId4, lsrId4), is(true));
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530290 // Retrieve label from store
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530291 labelId = pceStore.getGlobalNodeLabel(deviceId4);
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530292 // Check whether label is generated for this device D4.deviceId()
293 assertThat(labelId, is(notNullValue()));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530294
295 // device 5
296 String lsrId5 = "15.1.1.1";
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530297 // Allocate node label for specific device D5.deviceId()
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530298 assertThat(srTeHandler.allocateNodeLabel(deviceId5, lsrId5), is(true));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530299 // Retrieve label from store
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530300 labelId = pceStore.getGlobalNodeLabel(deviceId5);
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530301 // Check whether label is generated for this device D5.deviceId()
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530302 assertThat(labelId, is(notNullValue()));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530303 }
304
305 /**
306 * Checks the operation of releaseNodeLabel() method on node label.
307 */
308 @Test
309 public void testReleaseNodeLabelSuccess() {
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530310 testAllocateNodeLabel();
311 // Specific device D1.deviceId()
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530312
313 //device 1
314 String lsrId1 = "11.1.1.1";
315 // Check whether successfully released node label
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530316 assertThat(srTeHandler.releaseNodeLabel(deviceId1, lsrId1), is(true));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530317 // Check whether successfully removed label from store
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530318 LabelResourceId labelId = pceStore.getGlobalNodeLabel(deviceId1);
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530319 assertThat(labelId, is(nullValue()));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530320
321 //device 2
322 String lsrId2 = "12.1.1.1";
323 // Check whether successfully released node label
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530324 assertThat(srTeHandler.releaseNodeLabel(deviceId2, lsrId2), is(true));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530325 // Check whether successfully removed label from store
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530326 labelId = pceStore.getGlobalNodeLabel(deviceId2);
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530327 assertThat(labelId, is(nullValue()));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530328
329 //device 3
330 String lsrId3 = "13.1.1.1";
331 // Check whether successfully released node label
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530332 assertThat(srTeHandler.releaseNodeLabel(deviceId3, lsrId3), is(true));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530333 // Check whether successfully removed label from store
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530334 labelId = pceStore.getGlobalNodeLabel(deviceId3);
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530335 assertThat(labelId, is(nullValue()));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530336
337 //device 4
338 String lsrId4 = "14.1.1.1";
339 // Check whether successfully released node label
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530340 assertThat(srTeHandler.releaseNodeLabel(deviceId4, lsrId4), is(true));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530341 // Check whether successfully removed label from store
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530342 labelId = pceStore.getGlobalNodeLabel(deviceId4);
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530343 assertThat(labelId, is(nullValue()));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530344
345 //device 5
346 String lsrId5 = "15.1.1.1";
347 // Check whether successfully released node label
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530348 assertThat(srTeHandler.releaseNodeLabel(deviceId5, lsrId5), is(true));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530349 // Check whether successfully removed label from store
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530350 labelId = pceStore.getGlobalNodeLabel(deviceId5);
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530351 assertThat(labelId, is(nullValue()));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530352 }
353
354 @Test
355 public void testReleaseNodeLabelFailure() {
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530356 testAllocateNodeLabel();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530357
358 //device 6
359 String lsrId6 = "16.1.1.1";
360 // Check whether successfully released node label
361 DeviceId deviceId6 = DeviceId.deviceId("foo6");
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530362 assertThat(srTeHandler.releaseNodeLabel(deviceId6, lsrId6), is(false));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530363 }
364
365 /**
366 * Checks the operation of allocateAdjacencyLabel() method on adjacency label.
367 */
368 @Test
369 public void testAllocateAdjacencyLabel() {
370 // test link1
371 // Check whether adjacency label is allocated successfully.
372 assertThat(srTeHandler.allocateAdjacencyLabel(link1), is(true));
373 // Retrieve from store and check whether adjacency label is generated successfully for this device.
374 LabelResourceId labelId = pceStore.getAdjLabel(link1);
375 assertThat(labelId, is(notNullValue()));
376
377 // test link2
378 // Check whether adjacency label is allocated successfully.
379 assertThat(srTeHandler.allocateAdjacencyLabel(link2), is(true));
380 // Retrieve from store and check whether adjacency label is generated successfully for this device.
381 labelId = pceStore.getAdjLabel(link2);
382 assertThat(labelId, is(notNullValue()));
383
384 // test link3
385 // Check whether adjacency label is allocated successfully.
386 assertThat(srTeHandler.allocateAdjacencyLabel(link3), is(true));
387 // Retrieve from store and check whether adjacency label is generated successfully for this device.
388 labelId = pceStore.getAdjLabel(link3);
389 assertThat(labelId, is(notNullValue()));
390
391 // test link4
392 // Check whether adjacency label is allocated successfully.
393 assertThat(srTeHandler.allocateAdjacencyLabel(link4), is(true));
394 // Retrieve from store and check whether adjacency label is generated successfully for this device.
395 labelId = pceStore.getAdjLabel(link4);
396 assertThat(labelId, is(notNullValue()));
397 }
398
399 /**
400 * Checks the operation of releaseAdjacencyLabel() method on adjacency label.
401 */
402 @Test
403 public void testReleaseAdjacencyLabel() {
404 // Test link1
405 // Check whether adjacency label is released successfully.
406 assertThat(srTeHandler.allocateAdjacencyLabel(link1), is(true));
407 assertThat(srTeHandler.releaseAdjacencyLabel(link1), is(true));
408 // Retrieve from store and check whether adjacency label is removed successfully for this device.
409 LabelResourceId labelId = pceStore.getAdjLabel(link1);
410 assertThat(labelId, is(nullValue()));
411
412 // Test link2
413 // Check whether adjacency label is released successfully.
414 assertThat(srTeHandler.allocateAdjacencyLabel(link2), is(true));
415 assertThat(srTeHandler.releaseAdjacencyLabel(link2), is(true));
416 // Retrieve from store and check whether adjacency label is removed successfully for this device.
417 labelId = pceStore.getAdjLabel(link2);
418 assertThat(labelId, is(nullValue()));
419 }
420
421 /**
422 * Checks the operation of computeLabelStack() method.
423 */
424 @Test
425 public void testComputeLabelStack() {
426 // Allocate node labels to each devices
427 labelId = LabelResourceId.labelResourceId(4097);
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530428 pceStore.addGlobalNodeLabel(deviceId1, labelId);
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530429 labelId = LabelResourceId.labelResourceId(4098);
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530430 pceStore.addGlobalNodeLabel(deviceId2, labelId);
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530431 labelId = LabelResourceId.labelResourceId(4099);
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530432 pceStore.addGlobalNodeLabel(deviceId3, labelId);
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530433 labelId = LabelResourceId.labelResourceId(4100);
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530434 pceStore.addGlobalNodeLabel(deviceId4, labelId);
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530435 labelId = LabelResourceId.labelResourceId(4101);
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530436 pceStore.addGlobalNodeLabel(deviceId5, labelId);
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530437
438 // Allocate adjacency labels to each devices
439 labelId = LabelResourceId.labelResourceId(5122);
440 pceStore.addAdjLabel(link1, labelId);
441 labelId = LabelResourceId.labelResourceId(5123);
442 pceStore.addAdjLabel(link2, labelId);
443 labelId = LabelResourceId.labelResourceId(5124);
444 pceStore.addAdjLabel(link3, labelId);
445 labelId = LabelResourceId.labelResourceId(5125);
446 pceStore.addAdjLabel(link4, labelId);
447
448 // Compute label stack
449 LabelStack labelStack = srTeHandler.computeLabelStack(path1);
450
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530451 List<LabelResourceId> labelList = labelStack.labelResources();
452 Iterator<LabelResourceId> iterator = labelList.iterator();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530453
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530454 // check adjacency label of D1.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(5122)));
457
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530458 // check node-label of D2.deviceId()
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530459 labelId = iterator.next();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530460 assertThat(labelId, is(LabelResourceId.labelResourceId(4098)));
461
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530462 // check adjacency label of D2.deviceId()
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530463 labelId = iterator.next();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530464 assertThat(labelId, is(LabelResourceId.labelResourceId(5123)));
465
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530466 // check node-label of D3.deviceId()
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530467 labelId = iterator.next();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530468 assertThat(labelId, is(LabelResourceId.labelResourceId(4099)));
469
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530470 // check adjacency label of D3.deviceId()
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530471 labelId = iterator.next();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530472 assertThat(labelId, is(LabelResourceId.labelResourceId(5124)));
473
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530474 // check node-label of D4.deviceId()
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530475 labelId = iterator.next();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530476 assertThat(labelId, is(LabelResourceId.labelResourceId(4100)));
477
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530478 // check adjacency label of D4.deviceId()
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530479 labelId = iterator.next();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530480 assertThat(labelId, is(LabelResourceId.labelResourceId(5125)));
481
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530482 // check node-label of D5.deviceId()
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530483 labelId = iterator.next();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530484 assertThat(labelId, is(LabelResourceId.labelResourceId(4101)));
485 }
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530486
487 private class MockDevice extends DefaultDevice {
488 MockDevice(DeviceId id, Annotations annotations) {
489 super(null, id, null, null, null, null, null, null, annotations);
490 }
491 }
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530492}