blob: 38ea63a9099b1e3905dbe5acc5942e75108fafb8 [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;
Avantika-Huawei9e848e82016-09-01 12:12:42 +053030import org.onlab.packet.IpAddress;
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053031import org.onosproject.incubator.net.resource.label.LabelResourceId;
32import org.onosproject.incubator.net.resource.label.LabelResourceAdminService;
33import org.onosproject.incubator.net.resource.label.LabelResourceService;
34import org.onosproject.incubator.net.tunnel.LabelStack;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053035import org.onosproject.net.AnnotationKeys;
36import org.onosproject.net.Annotations;
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053037import org.onosproject.net.ConnectPoint;
38import org.onosproject.net.DefaultAnnotations;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053039import org.onosproject.net.DefaultDevice;
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053040import org.onosproject.net.DefaultPath;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053041import org.onosproject.net.Device;
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053042import org.onosproject.net.DeviceId;
43import org.onosproject.net.PortNumber;
44import org.onosproject.net.Path;
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053045import org.onosproject.net.provider.ProviderId;
Avantika-Huawei9e848e82016-09-01 12:12:42 +053046import org.onosproject.pcelabelstore.api.PceLabelStore;
47import org.onosproject.pcelabelstore.util.LabelResourceAdapter;
48import org.onosproject.pcelabelstore.util.MockDeviceService;
49import org.onosproject.pcelabelstore.util.MockNetConfigRegistryAdapter;
50import org.onosproject.pcelabelstore.util.MockPcepClientController;
51import org.onosproject.pcelabelstore.util.PceLabelStoreAdapter;
52import org.onosproject.pcelabelstore.util.PcepClientAdapter;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053053import org.onosproject.pcep.api.DeviceCapability;
harikrushna-Huaweia2c7c202017-04-10 18:22:00 +053054import org.onosproject.pcep.server.PccId;
55import org.onosproject.pcep.server.impl.PceccSrTeBeHandler;
Avantika-Huawei9e848e82016-09-01 12:12:42 +053056import org.onosproject.pcepio.protocol.PcepVersion;
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053057import org.onosproject.net.DefaultLink;
58import org.onosproject.net.Link;
59
60/**
61 * Unit tests for PceccSrTeBeHandler class.
62 */
63public class PceccSrTeBeHandlerTest {
64
65 public static final long GLOBAL_LABEL_SPACE_MIN = 4097;
66 public static final long GLOBAL_LABEL_SPACE_MAX = 5121;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053067 private static final String L3 = "L3";
68 private static final String LSRID = "lsrId";
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053069
70 private PceccSrTeBeHandler srTeHandler;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053071 private LabelResourceAdminService labelRsrcAdminService;
72 private LabelResourceService labelRsrcService;
Avantika-Huawei9e848e82016-09-01 12:12:42 +053073 private PceLabelStore pceStore;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053074 private MockDeviceService deviceService;
Avantika-Huawei9e848e82016-09-01 12:12:42 +053075 private MockNetConfigRegistryAdapter netCfgService = new MockNetConfigRegistryAdapter();
76 private MockPcepClientController clientController = new MockPcepClientController();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053077 private ProviderId providerId;
Avantika-Huawei9e848e82016-09-01 12:12:42 +053078 private DeviceId deviceId1, deviceId2, deviceId3, deviceId4, deviceId5;
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +053079 private Device deviceD1;
80 private Device deviceD2;
81 private Device deviceD3;
82 private Device deviceD4;
83 private Device deviceD5;
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053084 private PortNumber port1;
85 private PortNumber port2;
86 private PortNumber port3;
87 private PortNumber port4;
88 private PortNumber port5;
89 private Link link1;
90 private Link link2;
91 private Link link3;
92 private Link link4;
93 private Path path1;
94 LabelResourceId labelId;
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +053095
96 @Before
97 public void setUp() throws Exception {
98 // Initialization of member variables
99 srTeHandler = PceccSrTeBeHandler.getInstance();
100 labelRsrcService = new LabelResourceAdapter();
101 labelRsrcAdminService = new LabelResourceAdapter();
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530102 pceStore = new PceLabelStoreAdapter();
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530103 deviceService = new MockDeviceService();
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530104
105 srTeHandler.initialize(labelRsrcAdminService,
106 labelRsrcService,
107 clientController,
108 pceStore,
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530109 deviceService);
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530110
111 // Creates path
112 // Creates list of links
113 providerId = new ProviderId("of", "foo");
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530114
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530115 PccId pccId1 = PccId.pccId(IpAddress.valueOf("11.1.1.1"));
116 PccId pccId2 = PccId.pccId(IpAddress.valueOf("12.1.1.1"));
117 PccId pccId3 = PccId.pccId(IpAddress.valueOf("13.1.1.1"));
118 PccId pccId4 = PccId.pccId(IpAddress.valueOf("14.1.1.1"));
119 PccId pccId5 = PccId.pccId(IpAddress.valueOf("15.1.1.1"));
120
121 PcepClientAdapter pc1 = new PcepClientAdapter();
122 pc1.init(pccId1, PcepVersion.PCEP_1);
123
124 PcepClientAdapter pc2 = new PcepClientAdapter();
125 pc2.init(pccId2, PcepVersion.PCEP_1);
126
127 PcepClientAdapter pc3 = new PcepClientAdapter();
128 pc3.init(pccId3, PcepVersion.PCEP_1);
129
130 PcepClientAdapter pc4 = new PcepClientAdapter();
131 pc4.init(pccId4, PcepVersion.PCEP_1);
132
133 PcepClientAdapter pc5 = new PcepClientAdapter();
134 pc5.init(pccId5, PcepVersion.PCEP_1);
135
136 clientController.addClient(pccId1, pc1);
137 clientController.addClient(pccId2, pc2);
138 clientController.addClient(pccId3, pc3);
139 clientController.addClient(pccId4, pc4);
140 clientController.addClient(pccId5, pc5);
141
142 deviceId1 = DeviceId.deviceId("11.1.1.1");
143 deviceId2 = DeviceId.deviceId("12.1.1.1");
144 deviceId3 = DeviceId.deviceId("13.1.1.1");
145 deviceId4 = DeviceId.deviceId("14.1.1.1");
146 deviceId5 = DeviceId.deviceId("15.1.1.1");
147
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530148 // Devices
149 DefaultAnnotations.Builder builderDev1 = DefaultAnnotations.builder();
150 DefaultAnnotations.Builder builderDev2 = DefaultAnnotations.builder();
151 DefaultAnnotations.Builder builderDev3 = DefaultAnnotations.builder();
152 DefaultAnnotations.Builder builderDev4 = DefaultAnnotations.builder();
153 DefaultAnnotations.Builder builderDev5 = DefaultAnnotations.builder();
154
155 builderDev1.set(AnnotationKeys.TYPE, L3);
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530156 builderDev1.set(LSRID, "11.1.1.1");
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530157
158 builderDev2.set(AnnotationKeys.TYPE, L3);
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530159 builderDev2.set(LSRID, "12.1.1.1");
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530160
161 builderDev3.set(AnnotationKeys.TYPE, L3);
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530162 builderDev3.set(LSRID, "13.1.1.1");
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530163
164 builderDev4.set(AnnotationKeys.TYPE, L3);
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530165 builderDev4.set(LSRID, "14.1.1.1");
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530166
167 builderDev5.set(AnnotationKeys.TYPE, L3);
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530168 builderDev5.set(LSRID, "15.1.1.1");
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530169
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530170 deviceD1 = new MockDevice(deviceId1, builderDev1.build());
171 deviceD2 = new MockDevice(deviceId2, builderDev2.build());
172 deviceD3 = new MockDevice(deviceId3, builderDev3.build());
173 deviceD4 = new MockDevice(deviceId4, builderDev4.build());
174 deviceD5 = new MockDevice(deviceId5, builderDev5.build());
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530175
176 deviceService.addDevice(deviceD1);
177 deviceService.addDevice(deviceD2);
178 deviceService.addDevice(deviceD3);
179 deviceService.addDevice(deviceD4);
180 deviceService.addDevice(deviceD5);
181
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530182 DeviceCapability device1Cap = netCfgService.addConfig(deviceId1, DeviceCapability.class);
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530183 device1Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply();
184
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530185 DeviceCapability device2Cap = netCfgService.addConfig(deviceId2, DeviceCapability.class);
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530186 device2Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply();
187
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530188 DeviceCapability device3Cap = netCfgService.addConfig(deviceId3, DeviceCapability.class);
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530189 device3Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply();
190
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530191 DeviceCapability device4Cap = netCfgService.addConfig(deviceId4, DeviceCapability.class);
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530192 device4Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply();
193
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530194 DeviceCapability device5Cap = netCfgService.addConfig(deviceId5, DeviceCapability.class);
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530195 device5Cap.setLabelStackCap(true).setLocalLabelCap(false).setSrCap(true).apply();
196
197 // Port Numbers
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530198 port1 = PortNumber.portNumber(1);
199 port2 = PortNumber.portNumber(2);
200 port3 = PortNumber.portNumber(3);
201 port4 = PortNumber.portNumber(4);
202 port5 = PortNumber.portNumber(5);
203 List<Link> linkList = new LinkedList<>();
204
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530205 link1 = DefaultLink.builder().providerId(providerId)
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530206 .annotations(DefaultAnnotations.builder().set("key1", "yahoo").build())
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530207 .src(new ConnectPoint(deviceD1.id(), port1)).dst(new ConnectPoint(deviceD2.id(), port2)).type(DIRECT)
208 .state(Link.State.ACTIVE).build();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530209 linkList.add(link1);
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530210 link2 = DefaultLink.builder().providerId(providerId)
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530211 .annotations(DefaultAnnotations.builder().set("key2", "yahoo").build())
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530212 .src(new ConnectPoint(deviceD2.id(), port2)).dst(new ConnectPoint(deviceD3.id(), port3)).type(DIRECT)
213 .state(Link.State.ACTIVE).build();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530214 linkList.add(link2);
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530215 link3 = DefaultLink.builder().providerId(providerId)
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530216 .annotations(DefaultAnnotations.builder().set("key3", "yahoo").build())
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530217 .src(new ConnectPoint(deviceD3.id(), port3)).dst(new ConnectPoint(deviceD4.id(), port4)).type(DIRECT)
218 .state(Link.State.ACTIVE).build();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530219 linkList.add(link3);
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530220 link4 = DefaultLink.builder().providerId(providerId)
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530221 .annotations(DefaultAnnotations.builder().set("key4", "yahoo").build())
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530222 .src(new ConnectPoint(deviceD4.id(), port4)).dst(new ConnectPoint(deviceD5.id(), port5)).type(DIRECT)
223 .state(Link.State.ACTIVE).build();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530224 linkList.add(link4);
225
226 // Path
227 path1 = new DefaultPath(providerId, linkList, 10);
228 }
229
230 @After
231 public void tearDown() throws Exception {
232 }
233
234 /**
235 * Checks the operation of getInstance() method.
236 */
237 @Test
238 public void testGetInstance() {
239 assertThat(srTeHandler, is(notNullValue()));
240 }
241
242 /**
243 * Checks the operation of reserveGlobalPool() method.
244 */
245 @Test
246 public void testReserveGlobalPool() {
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530247 assertThat(srTeHandler.reserveGlobalPool(GLOBAL_LABEL_SPACE_MIN, GLOBAL_LABEL_SPACE_MAX), is(true));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530248 }
249
250 /**
251 * Checks the operation of allocateNodeLabel() method on node label.
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530252 */
253 @Test
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530254 public void testAllocateNodeLabel() {
255 // Specific device D1.deviceId
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530256
257 //device 1
258 String lsrId1 = "11.1.1.1";
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530259 // Allocate node label for specific device D1deviceId
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530260 assertThat(srTeHandler.allocateNodeLabel(deviceId1, lsrId1), is(true));
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530261 // Retrieve label from store
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530262 LabelResourceId labelId = pceStore.getGlobalNodeLabel(deviceId1);
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530263 // Check whether label is generated for this device D1.deviceId()
264 assertThat(labelId, is(notNullValue()));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530265
266 // device 2
267 String lsrId2 = "12.1.1.1";
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530268 // Allocate node label for specific device D2.deviceId()
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530269 assertThat(srTeHandler.allocateNodeLabel(deviceId2, lsrId2), is(true));
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530270 // Retrieve label from store
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530271 labelId = pceStore.getGlobalNodeLabel(deviceId2);
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530272 // Check whether label is generated for this device D2.deviceId()
273 assertThat(labelId, is(notNullValue()));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530274
275 // device 3
276 String lsrId3 = "13.1.1.1";
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530277 // Allocate node label for specific device D3.deviceId()
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530278 assertThat(srTeHandler.allocateNodeLabel(deviceId3, lsrId3), is(true));
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530279 // Retrieve label from store
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530280 labelId = pceStore.getGlobalNodeLabel(deviceId3);
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530281 // Check whether label is generated for this device D3.deviceId()
282 assertThat(labelId, is(notNullValue()));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530283
284 // device 4
285 String lsrId4 = "14.1.1.1";
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530286 // Allocate node label for specific device D4.deviceId()
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530287 assertThat(srTeHandler.allocateNodeLabel(deviceId4, lsrId4), is(true));
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530288 // Retrieve label from store
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530289 labelId = pceStore.getGlobalNodeLabel(deviceId4);
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530290 // Check whether label is generated for this device D4.deviceId()
291 assertThat(labelId, is(notNullValue()));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530292
293 // device 5
294 String lsrId5 = "15.1.1.1";
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530295 // Allocate node label for specific device D5.deviceId()
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530296 assertThat(srTeHandler.allocateNodeLabel(deviceId5, lsrId5), is(true));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530297 // Retrieve label from store
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530298 labelId = pceStore.getGlobalNodeLabel(deviceId5);
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530299 // Check whether label is generated for this device D5.deviceId()
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530300 assertThat(labelId, is(notNullValue()));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530301 }
302
303 /**
304 * Checks the operation of releaseNodeLabel() method on node label.
305 */
306 @Test
307 public void testReleaseNodeLabelSuccess() {
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530308 testAllocateNodeLabel();
309 // Specific device D1.deviceId()
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530310
311 //device 1
312 String lsrId1 = "11.1.1.1";
313 // Check whether successfully released node label
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530314 assertThat(srTeHandler.releaseNodeLabel(deviceId1, lsrId1), is(true));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530315 // Check whether successfully removed label from store
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530316 LabelResourceId labelId = pceStore.getGlobalNodeLabel(deviceId1);
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530317 assertThat(labelId, is(nullValue()));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530318
319 //device 2
320 String lsrId2 = "12.1.1.1";
321 // Check whether successfully released node label
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530322 assertThat(srTeHandler.releaseNodeLabel(deviceId2, lsrId2), is(true));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530323 // Check whether successfully removed label from store
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530324 labelId = pceStore.getGlobalNodeLabel(deviceId2);
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530325 assertThat(labelId, is(nullValue()));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530326
327 //device 3
328 String lsrId3 = "13.1.1.1";
329 // Check whether successfully released node label
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530330 assertThat(srTeHandler.releaseNodeLabel(deviceId3, lsrId3), is(true));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530331 // Check whether successfully removed label from store
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530332 labelId = pceStore.getGlobalNodeLabel(deviceId3);
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530333 assertThat(labelId, is(nullValue()));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530334
335 //device 4
336 String lsrId4 = "14.1.1.1";
337 // Check whether successfully released node label
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530338 assertThat(srTeHandler.releaseNodeLabel(deviceId4, lsrId4), is(true));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530339 // Check whether successfully removed label from store
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530340 labelId = pceStore.getGlobalNodeLabel(deviceId4);
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530341 assertThat(labelId, is(nullValue()));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530342
343 //device 5
344 String lsrId5 = "15.1.1.1";
345 // Check whether successfully released node label
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530346 assertThat(srTeHandler.releaseNodeLabel(deviceId5, lsrId5), is(true));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530347 // Check whether successfully removed label from store
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530348 labelId = pceStore.getGlobalNodeLabel(deviceId5);
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530349 assertThat(labelId, is(nullValue()));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530350 }
351
352 @Test
353 public void testReleaseNodeLabelFailure() {
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530354 testAllocateNodeLabel();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530355
356 //device 6
357 String lsrId6 = "16.1.1.1";
358 // Check whether successfully released node label
359 DeviceId deviceId6 = DeviceId.deviceId("foo6");
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530360 assertThat(srTeHandler.releaseNodeLabel(deviceId6, lsrId6), is(false));
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530361 }
362
363 /**
364 * Checks the operation of allocateAdjacencyLabel() method on adjacency label.
365 */
366 @Test
367 public void testAllocateAdjacencyLabel() {
368 // test link1
369 // Check whether adjacency label is allocated successfully.
370 assertThat(srTeHandler.allocateAdjacencyLabel(link1), is(true));
371 // Retrieve from store and check whether adjacency label is generated successfully for this device.
372 LabelResourceId labelId = pceStore.getAdjLabel(link1);
373 assertThat(labelId, is(notNullValue()));
374
375 // test link2
376 // Check whether adjacency label is allocated successfully.
377 assertThat(srTeHandler.allocateAdjacencyLabel(link2), is(true));
378 // Retrieve from store and check whether adjacency label is generated successfully for this device.
379 labelId = pceStore.getAdjLabel(link2);
380 assertThat(labelId, is(notNullValue()));
381
382 // test link3
383 // Check whether adjacency label is allocated successfully.
384 assertThat(srTeHandler.allocateAdjacencyLabel(link3), is(true));
385 // Retrieve from store and check whether adjacency label is generated successfully for this device.
386 labelId = pceStore.getAdjLabel(link3);
387 assertThat(labelId, is(notNullValue()));
388
389 // test link4
390 // Check whether adjacency label is allocated successfully.
391 assertThat(srTeHandler.allocateAdjacencyLabel(link4), is(true));
392 // Retrieve from store and check whether adjacency label is generated successfully for this device.
393 labelId = pceStore.getAdjLabel(link4);
394 assertThat(labelId, is(notNullValue()));
395 }
396
397 /**
398 * Checks the operation of releaseAdjacencyLabel() method on adjacency label.
399 */
400 @Test
401 public void testReleaseAdjacencyLabel() {
402 // Test link1
403 // Check whether adjacency label is released successfully.
404 assertThat(srTeHandler.allocateAdjacencyLabel(link1), is(true));
405 assertThat(srTeHandler.releaseAdjacencyLabel(link1), is(true));
406 // Retrieve from store and check whether adjacency label is removed successfully for this device.
407 LabelResourceId labelId = pceStore.getAdjLabel(link1);
408 assertThat(labelId, is(nullValue()));
409
410 // Test link2
411 // Check whether adjacency label is released successfully.
412 assertThat(srTeHandler.allocateAdjacencyLabel(link2), is(true));
413 assertThat(srTeHandler.releaseAdjacencyLabel(link2), is(true));
414 // Retrieve from store and check whether adjacency label is removed successfully for this device.
415 labelId = pceStore.getAdjLabel(link2);
416 assertThat(labelId, is(nullValue()));
417 }
418
419 /**
420 * Checks the operation of computeLabelStack() method.
421 */
422 @Test
423 public void testComputeLabelStack() {
424 // Allocate node labels to each devices
425 labelId = LabelResourceId.labelResourceId(4097);
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530426 pceStore.addGlobalNodeLabel(deviceId1, labelId);
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530427 labelId = LabelResourceId.labelResourceId(4098);
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530428 pceStore.addGlobalNodeLabel(deviceId2, labelId);
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530429 labelId = LabelResourceId.labelResourceId(4099);
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530430 pceStore.addGlobalNodeLabel(deviceId3, labelId);
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530431 labelId = LabelResourceId.labelResourceId(4100);
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530432 pceStore.addGlobalNodeLabel(deviceId4, labelId);
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530433 labelId = LabelResourceId.labelResourceId(4101);
Avantika-Huawei9e848e82016-09-01 12:12:42 +0530434 pceStore.addGlobalNodeLabel(deviceId5, labelId);
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530435
436 // Allocate adjacency labels to each devices
437 labelId = LabelResourceId.labelResourceId(5122);
438 pceStore.addAdjLabel(link1, labelId);
439 labelId = LabelResourceId.labelResourceId(5123);
440 pceStore.addAdjLabel(link2, labelId);
441 labelId = LabelResourceId.labelResourceId(5124);
442 pceStore.addAdjLabel(link3, labelId);
443 labelId = LabelResourceId.labelResourceId(5125);
444 pceStore.addAdjLabel(link4, labelId);
445
446 // Compute label stack
447 LabelStack labelStack = srTeHandler.computeLabelStack(path1);
448
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530449 List<LabelResourceId> labelList = labelStack.labelResources();
450 Iterator<LabelResourceId> iterator = labelList.iterator();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530451
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530452 // check adjacency label of D1.deviceId()
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530453 labelId = iterator.next();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530454 assertThat(labelId, is(LabelResourceId.labelResourceId(5122)));
455
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530456 // check node-label of D2.deviceId()
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530457 labelId = iterator.next();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530458 assertThat(labelId, is(LabelResourceId.labelResourceId(4098)));
459
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530460 // check adjacency label of D2.deviceId()
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530461 labelId = iterator.next();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530462 assertThat(labelId, is(LabelResourceId.labelResourceId(5123)));
463
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530464 // check node-label of D3.deviceId()
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530465 labelId = iterator.next();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530466 assertThat(labelId, is(LabelResourceId.labelResourceId(4099)));
467
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530468 // check adjacency label of D3.deviceId()
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530469 labelId = iterator.next();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530470 assertThat(labelId, is(LabelResourceId.labelResourceId(5124)));
471
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530472 // check node-label of D4.deviceId()
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530473 labelId = iterator.next();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530474 assertThat(labelId, is(LabelResourceId.labelResourceId(4100)));
475
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530476 // check adjacency label of D4.deviceId()
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530477 labelId = iterator.next();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530478 assertThat(labelId, is(LabelResourceId.labelResourceId(5125)));
479
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530480 // check node-label of D5.deviceId()
Avantika-Huaweidbdf7722016-05-21 14:20:31 +0530481 labelId = iterator.next();
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530482 assertThat(labelId, is(LabelResourceId.labelResourceId(4101)));
483 }
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +0530484
485 private class MockDevice extends DefaultDevice {
486 MockDevice(DeviceId id, Annotations annotations) {
487 super(null, id, null, null, null, null, null, null, annotations);
488 }
489 }
Mahesh Poojary Sa4df1aa2016-05-13 08:53:53 +0530490}