2 * Copyright © 2018 Orange Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.transportpce.renderer.provisiondevice;
10 import java.util.ArrayList;
11 import java.util.List;
12 import java.util.concurrent.ExecutionException;
14 import org.junit.Assert;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.mockito.Mockito;
18 import org.opendaylight.controller.md.sal.binding.api.MountPoint;
19 import org.opendaylight.controller.md.sal.binding.api.MountPointService;
20 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
21 import org.opendaylight.transportpce.common.ResponseCodes;
22 import org.opendaylight.transportpce.common.crossconnect.CrossConnect;
23 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl;
24 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
25 import org.opendaylight.transportpce.common.device.DeviceTransactionManagerImpl;
26 import org.opendaylight.transportpce.common.mapping.PortMapping;
27 import org.opendaylight.transportpce.common.mapping.PortMappingImpl;
28 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaceException;
29 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
30 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl;
31 import org.opendaylight.transportpce.renderer.NetworkModelWavelengthService;
32 import org.opendaylight.transportpce.renderer.NetworkModelWavelengthServiceImpl;
33 import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmInterfaceFactory;
34 import org.opendaylight.transportpce.renderer.stub.MountPointServiceStub;
35 import org.opendaylight.transportpce.renderer.stub.MountPointStub;
36 import org.opendaylight.transportpce.renderer.stub.OlmServiceStub;
37 import org.opendaylight.transportpce.renderer.utils.MountPointUtils;
38 import org.opendaylight.transportpce.renderer.utils.NotificationPublishServiceMock;
39 import org.opendaylight.transportpce.renderer.utils.ServiceDataUtils;
40 import org.opendaylight.transportpce.test.AbstractTest;
41 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.GetPmInput;
42 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.GetPmInputBuilder;
43 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.GetPmOutput;
44 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.GetPmOutputBuilder;
45 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.TransportpceOlmService;
46 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.get.pm.output.Measurements;
47 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.get.pm.output.MeasurementsBuilder;
48 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.device.rev170228.ServicePathOutputBuilder;
49 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceImplementationRequestInput;
50 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceImplementationRequestOutput;
51 import org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev161014.PmGranularity;
52 import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.types.rev161014.ResourceTypeEnum;
53 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev170907.olm.get.pm.input.ResourceIdentifierBuilder;
54 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
56 public class RendererServiceOperationsImplTest extends AbstractTest {
58 private MountPointService mountPointService;
59 private DeviceTransactionManager deviceTransactionManager;
60 private RendererServiceOperationsImpl rendererServiceOperations;
61 private OpenRoadmInterfaces openRoadmInterfaces;
62 private DeviceRendererService deviceRenderer;
63 private PortMapping portMapping;
64 private OpenRoadmInterfaceFactory openRoadmInterfaceFactory;
65 private CrossConnect crossConnect;
66 private TransportpceOlmService olmService;
67 private NetworkModelWavelengthService networkModelWavelengthService;
69 private void setMountPoint(MountPoint mountPoint) {
70 this.mountPointService = new MountPointServiceStub(mountPoint);
71 this.deviceTransactionManager = new DeviceTransactionManagerImpl(this.mountPointService, 3000);
72 this.openRoadmInterfaces = new OpenRoadmInterfacesImpl(this.deviceTransactionManager);
73 this.openRoadmInterfaces = Mockito.spy(this.openRoadmInterfaces);
74 this.portMapping = new PortMappingImpl(this.getDataBroker(), this.deviceTransactionManager,
76 this.openRoadmInterfaceFactory = new OpenRoadmInterfaceFactory(portMapping,
78 this.crossConnect = new CrossConnectImpl(this.deviceTransactionManager);
82 public void setUp() throws OpenRoadmInterfaceException {
83 setMountPoint(new MountPointStub(getDataBroker()));
84 this.olmService = new OlmServiceStub();
85 this.networkModelWavelengthService = new NetworkModelWavelengthServiceImpl(getDataBroker());
86 this.deviceRenderer = new DeviceRendererServiceImpl(this.getDataBroker(),
87 this.deviceTransactionManager, openRoadmInterfaceFactory, openRoadmInterfaces, crossConnect, portMapping);
88 Mockito.doNothing().when(this.openRoadmInterfaces).postEquipmentState(Mockito.anyString(),
89 Mockito.anyString(), Mockito.anyBoolean());
90 NotificationPublishService notificationPublishService = new NotificationPublishServiceMock();
91 this.olmService = Mockito.spy(this.olmService);
92 this.deviceRenderer = Mockito.spy(this.deviceRenderer);
93 this.rendererServiceOperations = new RendererServiceOperationsImpl(this.deviceRenderer, this.olmService,
94 getDataBroker(), this.networkModelWavelengthService, notificationPublishService);
95 ServicePathOutputBuilder mockOutputBuilder = new ServicePathOutputBuilder().setResult("success")
97 Mockito.doReturn(mockOutputBuilder.build()).when(this.deviceRenderer).setupServicePath(Mockito.any(),
102 public void serviceImplementationTerminationPointAsResourceTtp() throws InterruptedException, ExecutionException {
104 ServiceImplementationRequestInput input = ServiceDataUtils
105 .buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.TTP_TOKEN);
106 writePortMapping(input, OpenRoadmInterfacesImpl.TTP_TOKEN);
107 ServicePathOutputBuilder mockOutputBuilder = new ServicePathOutputBuilder().setResult("success")
109 Mockito.doReturn(mockOutputBuilder.build()).when(this.deviceRenderer).setupServicePath(Mockito.any(),
111 ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get();
112 Assert.assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode());
117 public void serviceImplementationTerminationPointAsResourceTtp2() throws InterruptedException, ExecutionException {
119 ServiceImplementationRequestInput input = ServiceDataUtils
120 .buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.TTP_TOKEN);
121 writePortMapping(input, OpenRoadmInterfacesImpl.TTP_TOKEN);
122 ServicePathOutputBuilder mockOutputBuilder = new ServicePathOutputBuilder().setResult("success")
124 Mockito.doReturn(mockOutputBuilder.build()).when(this.deviceRenderer).setupServicePath(Mockito.any(),
126 Mockito.doReturn(RpcResultBuilder.failed().buildFuture()).when(this.olmService)
127 .servicePowerSetup(Mockito.any());
128 ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get();
129 Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, result.getConfigurationResponseCommon().getResponseCode());
134 public void serviceImplementationTerminationPointAsResourcePp() throws InterruptedException, ExecutionException {
136 ServiceImplementationRequestInput input = ServiceDataUtils
137 .buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.PP_TOKEN);
138 writePortMapping(input, OpenRoadmInterfacesImpl.PP_TOKEN);
139 ServicePathOutputBuilder mockOutputBuilder = new ServicePathOutputBuilder().setResult("success")
141 Mockito.doReturn(mockOutputBuilder.build()).when(this.deviceRenderer).setupServicePath(Mockito.any(),
143 ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get();
144 Assert.assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode());
149 public void serviceImplementationTerminationPointAsResourceNetwork()
150 throws InterruptedException, ExecutionException {
152 ServiceImplementationRequestInput input = ServiceDataUtils
153 .buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.NETWORK_TOKEN);
154 writePortMapping(input, OpenRoadmInterfacesImpl.NETWORK_TOKEN);
155 ServicePathOutputBuilder mockOutputBuilder = new ServicePathOutputBuilder().setResult("success")
157 Mockito.doReturn(mockOutputBuilder.build()).when(this.deviceRenderer).setupServicePath(Mockito.any(),
159 ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get();
160 Assert.assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode());
165 public void serviceImplementationTerminationPointAsResourceClient()
166 throws InterruptedException, ExecutionException {
168 ServiceImplementationRequestInput input = ServiceDataUtils
169 .buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.CLIENT_TOKEN);
170 writePortMapping(input, OpenRoadmInterfacesImpl.CLIENT_TOKEN);
171 ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get();
172 Assert.assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode());
176 public void serviceImplementationTerminationPointAsResourceNoMapping()
177 throws InterruptedException, ExecutionException {
179 String[] interfaceTokens = {
180 OpenRoadmInterfacesImpl.NETWORK_TOKEN,
181 OpenRoadmInterfacesImpl.CLIENT_TOKEN,
182 OpenRoadmInterfacesImpl.TTP_TOKEN,
183 OpenRoadmInterfacesImpl.PP_TOKEN
186 ServicePathOutputBuilder mockOutputBuilder = new ServicePathOutputBuilder().setResult("failed")
188 Mockito.doReturn(mockOutputBuilder.build()).when(this.deviceRenderer).setupServicePath(Mockito.any(),
191 for (String tpToken : interfaceTokens) {
192 ServiceImplementationRequestInput input = ServiceDataUtils
193 .buildServiceImplementationRequestInputTerminationPointResource(tpToken);
194 ServiceImplementationRequestOutput result =
195 this.rendererServiceOperations.serviceImplementation(input).get();
196 Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
197 result.getConfigurationResponseCommon().getResponseCode());
201 private void writePortMapping(ServiceImplementationRequestInput input, String tpToken) {
202 MountPointUtils.writeMapping(
203 input.getServiceAEnd().getNodeId(),
204 input.getServiceAEnd().getNodeId() + "-" + tpToken,
205 this.deviceTransactionManager
207 MountPointUtils.writeMapping(
208 input.getServiceZEnd().getNodeId(),
209 input.getServiceZEnd().getNodeId() + "-"
210 + input.getServiceAEnd().getNodeId() + "-" + tpToken,
211 this.deviceTransactionManager
213 MountPointUtils.writeMapping(
214 input.getServiceAEnd().getNodeId(),
215 input.getServiceAEnd().getNodeId() + "-"
216 + input.getServiceZEnd().getNodeId() + "-" + tpToken,
217 this.deviceTransactionManager
219 MountPointUtils.writeMapping(
220 input.getServiceZEnd().getNodeId(),
221 input.getServiceZEnd().getNodeId() + "-" + tpToken,
222 this.deviceTransactionManager
227 public void serviceImplementationRollbackAllNecessary() throws InterruptedException, ExecutionException {
229 ServiceImplementationRequestInput input = ServiceDataUtils
230 .buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.NETWORK_TOKEN);
231 writePortMapping(input, OpenRoadmInterfacesImpl.NETWORK_TOKEN);
232 Mockito.doReturn(RpcResultBuilder.failed().buildFuture()).when(this.olmService)
233 .servicePowerSetup(Mockito.any());
234 ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get();
235 Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, result.getConfigurationResponseCommon().getResponseCode());
239 private GetPmInput createGetPmInput(String nodeId, String tp) {
240 GetPmInputBuilder getPmIpBldr = new GetPmInputBuilder();
241 getPmIpBldr.setNodeId(nodeId);
242 getPmIpBldr.setGranularity(PmGranularity._15min);
243 ResourceIdentifierBuilder rsrcBldr = new ResourceIdentifierBuilder();
244 rsrcBldr.setResourceName(tp + "-OTU");
245 getPmIpBldr.setResourceIdentifier(rsrcBldr.build());
246 getPmIpBldr.setResourceType(ResourceTypeEnum.Interface);
247 return getPmIpBldr.build();
251 public void serviceImplementationServiceInActive() throws InterruptedException, ExecutionException {
253 ServiceImplementationRequestInput input = ServiceDataUtils
254 .buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.NETWORK_TOKEN);
255 writePortMapping(input, OpenRoadmInterfacesImpl.NETWORK_TOKEN);
256 Measurements measurements = new MeasurementsBuilder().setPmparameterName("FECUncorrectableBlocks")
257 .setPmparameterValue("1").build();
258 List<Measurements> measurementsList = new ArrayList<Measurements>();
259 measurementsList.add(measurements);
260 GetPmOutput getPmOutput = new GetPmOutputBuilder()
261 .setNodeId("node1").setMeasurements(measurementsList).build();
262 Mockito.doReturn(RpcResultBuilder.success(getPmOutput).buildFuture()).when(this.olmService)
263 .getPm(Mockito.any());
264 ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get();
265 Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, result.getConfigurationResponseCommon().getResponseCode());
270 public void serviceImplementationServiceInActive2() throws InterruptedException, ExecutionException {
272 ServiceImplementationRequestInput input = ServiceDataUtils
273 .buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.NETWORK_TOKEN);
274 writePortMapping(input, OpenRoadmInterfacesImpl.NETWORK_TOKEN);
275 Measurements measurements = new MeasurementsBuilder().setPmparameterName("FECUncorrectableBlocks")
276 .setPmparameterValue("1").build();
277 List<Measurements> measurementsList = new ArrayList<Measurements>();
278 measurementsList.add(measurements);
279 GetPmOutput getPmOutput = new GetPmOutputBuilder()
280 .setNodeId("node1").setMeasurements(measurementsList).build();
281 GetPmOutput getPmOutput2 = new GetPmOutputBuilder()
282 .setNodeId("node1").setMeasurements(new ArrayList<>()).build();
284 Mockito.when(this.olmService.getPm(Mockito.any()))
285 .thenReturn(RpcResultBuilder.success(getPmOutput).buildFuture());
286 ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get();
287 Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, result.getConfigurationResponseCommon().getResponseCode());
292 public void serviceImplementationServiceInActive3() throws InterruptedException, ExecutionException {
294 ServiceImplementationRequestInput input = ServiceDataUtils
295 .buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.NETWORK_TOKEN);
296 writePortMapping(input, OpenRoadmInterfacesImpl.NETWORK_TOKEN);
297 Measurements measurements = new MeasurementsBuilder().setPmparameterName("FECUncorrectableBlocks")
298 .setPmparameterValue("1").build();
299 List<Measurements> measurementsList = new ArrayList<Measurements>();
300 measurementsList.add(measurements);
301 GetPmOutput getPmOutput = new GetPmOutputBuilder()
302 .setNodeId("node1").setMeasurements(measurementsList).build();
303 GetPmOutput getPmOutput2 = new GetPmOutputBuilder()
304 .setNodeId("node1").setMeasurements(new ArrayList<>()).build();
306 GetPmInput getPmInputZ = createGetPmInput("XPONDER-2-3",
307 OpenRoadmInterfacesImpl.NETWORK_TOKEN);
308 GetPmInput getPmInputA = createGetPmInput("XPONDER-1-2",
309 OpenRoadmInterfacesImpl.NETWORK_TOKEN);
311 Mockito.when(this.olmService.getPm(Mockito.eq(getPmInputZ)))
312 .thenReturn(RpcResultBuilder.success(getPmOutput2).buildFuture());
313 Mockito.when(this.olmService.getPm(Mockito.eq(getPmInputA)))
314 .thenReturn(RpcResultBuilder.success(getPmOutput).buildFuture());
315 ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get();
316 Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, result.getConfigurationResponseCommon().getResponseCode());
321 public void serviceImplementationServiceActive() throws InterruptedException, ExecutionException {
323 ServiceImplementationRequestInput input = ServiceDataUtils
324 .buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.NETWORK_TOKEN);
325 writePortMapping(input, OpenRoadmInterfacesImpl.NETWORK_TOKEN);
326 GetPmOutput getPmOutput = new GetPmOutputBuilder()
327 .setNodeId("node1").setMeasurements(new ArrayList<>()).build();
328 GetPmOutput getPmOutput1 = null;
329 Mockito.when(this.olmService.getPm(Mockito.any())).thenReturn(RpcResultBuilder.success(getPmOutput1)
331 ServicePathOutputBuilder mockOutputBuilder = new ServicePathOutputBuilder().setResult("success")
333 Mockito.doReturn(mockOutputBuilder.build()).when(this.deviceRenderer).setupServicePath(Mockito.any(),
335 ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get();
336 Assert.assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode());
341 public void serviceImplementationServiceActive2() throws InterruptedException, ExecutionException {
343 ServiceImplementationRequestInput input = ServiceDataUtils
344 .buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.NETWORK_TOKEN);
345 writePortMapping(input, OpenRoadmInterfacesImpl.NETWORK_TOKEN);
346 GetPmOutput getPmOutput = new GetPmOutputBuilder().setMeasurements(new ArrayList<>()).build();
347 Mockito.when(this.olmService.getPm(Mockito.any())).thenReturn(RpcResultBuilder.success(getPmOutput)
349 ServicePathOutputBuilder mockOutputBuilder = new ServicePathOutputBuilder().setResult("success")
351 Mockito.doReturn(mockOutputBuilder.build()).when(this.deviceRenderer).setupServicePath(Mockito.any(),
353 ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get();
354 Assert.assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode());
359 public void serviceImplementationServiceInActive4() throws InterruptedException, ExecutionException {
361 ServiceImplementationRequestInput input = ServiceDataUtils
362 .buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.NETWORK_TOKEN);
363 writePortMapping(input, OpenRoadmInterfacesImpl.NETWORK_TOKEN);
364 Measurements measurements = new MeasurementsBuilder().setPmparameterName("preFECCorrectedErrors")
365 .setPmparameterValue("1").build();
366 List<Measurements> measurementsList = new ArrayList<Measurements>();
367 measurementsList.add(measurements);
368 GetPmOutput getPmOutput = new GetPmOutputBuilder()
369 .setNodeId("node1").setMeasurements(measurementsList).build();
371 Mockito.doReturn(RpcResultBuilder.success(getPmOutput).buildFuture()).when(this.olmService)
372 .getPm(Mockito.any());
373 ServicePathOutputBuilder mockOutputBuilder = new ServicePathOutputBuilder().setResult("success")
375 Mockito.doReturn(mockOutputBuilder.build()).when(this.deviceRenderer).setupServicePath(Mockito.any(),
377 ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get();
378 Assert.assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode());
383 public void serviceImplementationServiceInActive5() throws InterruptedException, ExecutionException {
385 ServiceImplementationRequestInput input = ServiceDataUtils
386 .buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.NETWORK_TOKEN);
387 writePortMapping(input, OpenRoadmInterfacesImpl.NETWORK_TOKEN);
388 Measurements measurements = new MeasurementsBuilder().setPmparameterName("preFECCorrectedErrors")
389 .setPmparameterValue("112000000000d").build();
390 List<Measurements> measurementsList = new ArrayList<Measurements>();
391 measurementsList.add(measurements);
392 GetPmOutput getPmOutput = new GetPmOutputBuilder()
393 .setNodeId("node1").setMeasurements(measurementsList).build();
395 Mockito.doReturn(RpcResultBuilder.success(getPmOutput).buildFuture()).when(this.olmService)
396 .getPm(Mockito.any());
397 ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get();
398 Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, result.getConfigurationResponseCommon().getResponseCode());