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();
92 this.olmService = Mockito.spy(this.olmService);
93 this.deviceRenderer = Mockito.spy(this.deviceRenderer);
94 this.rendererServiceOperations = new RendererServiceOperationsImpl(this.deviceRenderer, this.olmService,
95 getDataBroker(), this.networkModelWavelengthService, notificationPublishService);
97 ServicePathOutputBuilder mockOutputBuilder = new ServicePathOutputBuilder().setResult("success")
99 Mockito.doReturn(mockOutputBuilder.build()).when(this.deviceRenderer).setupServicePath(Mockito.any(),
104 public void serviceImplementationTerminationPointAsResourceTtp() throws InterruptedException, ExecutionException {
106 ServiceImplementationRequestInput input = ServiceDataUtils
107 .buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.TTP_TOKEN);
108 writePortMapping(input, OpenRoadmInterfacesImpl.TTP_TOKEN);
109 ServicePathOutputBuilder mockOutputBuilder = new ServicePathOutputBuilder().setResult("success")
111 Mockito.doReturn(mockOutputBuilder.build()).when(this.deviceRenderer).setupServicePath(Mockito.any(),
113 ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get();
114 Assert.assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode());
119 public void serviceImplementationTerminationPointAsResourceTtp2() throws InterruptedException, ExecutionException {
121 ServiceImplementationRequestInput input = ServiceDataUtils
122 .buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.TTP_TOKEN);
123 writePortMapping(input, OpenRoadmInterfacesImpl.TTP_TOKEN);
124 ServicePathOutputBuilder mockOutputBuilder = new ServicePathOutputBuilder().setResult("success")
126 Mockito.doReturn(mockOutputBuilder.build()).when(this.deviceRenderer).setupServicePath(Mockito.any(),
128 Mockito.doReturn(RpcResultBuilder.failed().buildFuture()).when(this.olmService)
129 .servicePowerSetup(Mockito.any());
130 ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get();
131 Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, result.getConfigurationResponseCommon().getResponseCode());
136 public void serviceImplementationTerminationPointAsResourcePp() throws InterruptedException, ExecutionException {
138 ServiceImplementationRequestInput input = ServiceDataUtils
139 .buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.PP_TOKEN);
140 writePortMapping(input, OpenRoadmInterfacesImpl.PP_TOKEN);
141 ServicePathOutputBuilder mockOutputBuilder = new ServicePathOutputBuilder().setResult("success")
143 Mockito.doReturn(mockOutputBuilder.build()).when(this.deviceRenderer).setupServicePath(Mockito.any(),
145 ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get();
146 Assert.assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode());
151 public void serviceImplementationTerminationPointAsResourceNetwork()
152 throws InterruptedException, ExecutionException {
154 ServiceImplementationRequestInput input = ServiceDataUtils
155 .buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.NETWORK_TOKEN);
156 writePortMapping(input, OpenRoadmInterfacesImpl.NETWORK_TOKEN);
157 ServicePathOutputBuilder mockOutputBuilder = new ServicePathOutputBuilder().setResult("success")
159 Mockito.doReturn(mockOutputBuilder.build()).when(this.deviceRenderer).setupServicePath(Mockito.any(),
161 ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get();
162 Assert.assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode());
167 public void serviceImplementationTerminationPointAsResourceClient()
168 throws InterruptedException, ExecutionException {
170 ServiceImplementationRequestInput input = ServiceDataUtils
171 .buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.CLIENT_TOKEN);
172 writePortMapping(input, OpenRoadmInterfacesImpl.CLIENT_TOKEN);
173 ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get();
174 Assert.assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode());
178 public void serviceImplementationTerminationPointAsResourceNoMapping()
179 throws InterruptedException, ExecutionException {
181 String[] interfaceTokens = {
182 OpenRoadmInterfacesImpl.NETWORK_TOKEN,
183 OpenRoadmInterfacesImpl.CLIENT_TOKEN,
184 OpenRoadmInterfacesImpl.TTP_TOKEN,
185 OpenRoadmInterfacesImpl.PP_TOKEN
188 ServicePathOutputBuilder mockOutputBuilder = new ServicePathOutputBuilder().setResult("failed")
190 Mockito.doReturn(mockOutputBuilder.build()).when(this.deviceRenderer).setupServicePath(Mockito.any(),
193 for (String tpToken : interfaceTokens) {
194 ServiceImplementationRequestInput input = ServiceDataUtils
195 .buildServiceImplementationRequestInputTerminationPointResource(tpToken);
196 ServiceImplementationRequestOutput result =
197 this.rendererServiceOperations.serviceImplementation(input).get();
198 Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
199 result.getConfigurationResponseCommon().getResponseCode());
203 private void writePortMapping(ServiceImplementationRequestInput input, String tpToken) {
204 MountPointUtils.writeMapping(
205 input.getServiceAEnd().getNodeId(),
206 input.getServiceAEnd().getNodeId() + "-" + tpToken,
207 this.deviceTransactionManager
209 MountPointUtils.writeMapping(
210 input.getServiceZEnd().getNodeId(),
211 input.getServiceZEnd().getNodeId() + "-"
212 + input.getServiceAEnd().getNodeId() + "-" + tpToken,
213 this.deviceTransactionManager
215 MountPointUtils.writeMapping(
216 input.getServiceAEnd().getNodeId(),
217 input.getServiceAEnd().getNodeId() + "-"
218 + input.getServiceZEnd().getNodeId() + "-" + tpToken,
219 this.deviceTransactionManager
221 MountPointUtils.writeMapping(
222 input.getServiceZEnd().getNodeId(),
223 input.getServiceZEnd().getNodeId() + "-" + tpToken,
224 this.deviceTransactionManager
229 public void serviceImplementationRollbackAllNecessary() throws InterruptedException, ExecutionException {
231 ServiceImplementationRequestInput input = ServiceDataUtils
232 .buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.NETWORK_TOKEN);
233 writePortMapping(input, OpenRoadmInterfacesImpl.NETWORK_TOKEN);
234 Mockito.doReturn(RpcResultBuilder.failed().buildFuture()).when(this.olmService)
235 .servicePowerSetup(Mockito.any());
236 ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get();
237 Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, result.getConfigurationResponseCommon().getResponseCode());
241 private GetPmInput createGetPmInput(String nodeId, String tp) {
242 GetPmInputBuilder getPmIpBldr = new GetPmInputBuilder();
243 getPmIpBldr.setNodeId(nodeId);
244 getPmIpBldr.setGranularity(PmGranularity._15min);
245 ResourceIdentifierBuilder rsrcBldr = new ResourceIdentifierBuilder();
246 rsrcBldr.setResourceName(tp + "-OTU");
247 getPmIpBldr.setResourceIdentifier(rsrcBldr.build());
248 getPmIpBldr.setResourceType(ResourceTypeEnum.Interface);
249 return getPmIpBldr.build();
253 public void serviceImplementationServiceInActive() throws InterruptedException, ExecutionException {
255 ServiceImplementationRequestInput input = ServiceDataUtils
256 .buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.NETWORK_TOKEN);
257 writePortMapping(input, OpenRoadmInterfacesImpl.NETWORK_TOKEN);
258 Measurements measurements = new MeasurementsBuilder().setPmparameterName("FECUncorrectableBlocks")
259 .setPmparameterValue("1").build();
260 List<Measurements> measurementsList = new ArrayList<Measurements>();
261 measurementsList.add(measurements);
262 GetPmOutput getPmOutput = new GetPmOutputBuilder()
263 .setNodeId("node1").setMeasurements(measurementsList).build();
264 Mockito.doReturn(RpcResultBuilder.success(getPmOutput).buildFuture()).when(this.olmService)
265 .getPm(Mockito.any());
266 ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get();
267 Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, result.getConfigurationResponseCommon().getResponseCode());
272 public void serviceImplementationServiceInActive2() throws InterruptedException, ExecutionException {
274 ServiceImplementationRequestInput input = ServiceDataUtils
275 .buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.NETWORK_TOKEN);
276 writePortMapping(input, OpenRoadmInterfacesImpl.NETWORK_TOKEN);
277 Measurements measurements = new MeasurementsBuilder().setPmparameterName("FECUncorrectableBlocks")
278 .setPmparameterValue("1").build();
279 List<Measurements> measurementsList = new ArrayList<Measurements>();
280 measurementsList.add(measurements);
281 GetPmOutput getPmOutput = new GetPmOutputBuilder()
282 .setNodeId("node1").setMeasurements(measurementsList).build();
283 GetPmOutput getPmOutput2 = new GetPmOutputBuilder()
284 .setNodeId("node1").setMeasurements(new ArrayList<>()).build();
286 Mockito.when(this.olmService.getPm(Mockito.any()))
287 .thenReturn(RpcResultBuilder.success(getPmOutput).buildFuture());
288 ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get();
289 Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, result.getConfigurationResponseCommon().getResponseCode());
294 public void serviceImplementationServiceInActive3() throws InterruptedException, ExecutionException {
296 ServiceImplementationRequestInput input = ServiceDataUtils
297 .buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.NETWORK_TOKEN);
298 writePortMapping(input, OpenRoadmInterfacesImpl.NETWORK_TOKEN);
299 Measurements measurements = new MeasurementsBuilder().setPmparameterName("FECUncorrectableBlocks")
300 .setPmparameterValue("1").build();
301 List<Measurements> measurementsList = new ArrayList<Measurements>();
302 measurementsList.add(measurements);
303 GetPmOutput getPmOutput = new GetPmOutputBuilder()
304 .setNodeId("node1").setMeasurements(measurementsList).build();
305 GetPmOutput getPmOutput2 = new GetPmOutputBuilder()
306 .setNodeId("node1").setMeasurements(new ArrayList<>()).build();
308 GetPmInput getPmInputZ = createGetPmInput("XPONDER-2-3",
309 OpenRoadmInterfacesImpl.NETWORK_TOKEN);
310 GetPmInput getPmInputA = createGetPmInput("XPONDER-1-2",
311 OpenRoadmInterfacesImpl.NETWORK_TOKEN);
313 Mockito.when(this.olmService.getPm(Mockito.eq(getPmInputZ)))
314 .thenReturn(RpcResultBuilder.success(getPmOutput2).buildFuture());
315 Mockito.when(this.olmService.getPm(Mockito.eq(getPmInputA)))
316 .thenReturn(RpcResultBuilder.success(getPmOutput).buildFuture());
317 ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get();
318 Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, result.getConfigurationResponseCommon().getResponseCode());
323 public void serviceImplementationServiceActive() throws InterruptedException, ExecutionException {
325 ServiceImplementationRequestInput input = ServiceDataUtils
326 .buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.NETWORK_TOKEN);
327 writePortMapping(input, OpenRoadmInterfacesImpl.NETWORK_TOKEN);
328 GetPmOutput getPmOutput = new GetPmOutputBuilder()
329 .setNodeId("node1").setMeasurements(new ArrayList<>()).build();
330 GetPmOutput getPmOutput1 = null;
331 Mockito.when(this.olmService.getPm(Mockito.any())).thenReturn(RpcResultBuilder.success(getPmOutput1)
333 ServicePathOutputBuilder mockOutputBuilder = new ServicePathOutputBuilder().setResult("success")
335 Mockito.doReturn(mockOutputBuilder.build()).when(this.deviceRenderer).setupServicePath(Mockito.any(),
337 ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get();
338 Assert.assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode());
343 public void serviceImplementationServiceActive2() throws InterruptedException, ExecutionException {
345 ServiceImplementationRequestInput input = ServiceDataUtils
346 .buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.NETWORK_TOKEN);
347 writePortMapping(input, OpenRoadmInterfacesImpl.NETWORK_TOKEN);
348 GetPmOutput getPmOutput = new GetPmOutputBuilder().setMeasurements(new ArrayList<>()).build();
349 Mockito.when(this.olmService.getPm(Mockito.any())).thenReturn(RpcResultBuilder.success(getPmOutput)
351 ServicePathOutputBuilder mockOutputBuilder = new ServicePathOutputBuilder().setResult("success")
353 Mockito.doReturn(mockOutputBuilder.build()).when(this.deviceRenderer).setupServicePath(Mockito.any(),
355 ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get();
356 Assert.assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode());
361 public void serviceImplementationServiceInActive4() throws InterruptedException, ExecutionException {
363 ServiceImplementationRequestInput input = ServiceDataUtils
364 .buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.NETWORK_TOKEN);
365 writePortMapping(input, OpenRoadmInterfacesImpl.NETWORK_TOKEN);
366 Measurements measurements = new MeasurementsBuilder().setPmparameterName("preFECCorrectedErrors")
367 .setPmparameterValue("1").build();
368 List<Measurements> measurementsList = new ArrayList<Measurements>();
369 measurementsList.add(measurements);
370 GetPmOutput getPmOutput = new GetPmOutputBuilder()
371 .setNodeId("node1").setMeasurements(measurementsList).build();
373 Mockito.doReturn(RpcResultBuilder.success(getPmOutput).buildFuture()).when(this.olmService)
374 .getPm(Mockito.any());
375 ServicePathOutputBuilder mockOutputBuilder = new ServicePathOutputBuilder().setResult("success")
377 Mockito.doReturn(mockOutputBuilder.build()).when(this.deviceRenderer).setupServicePath(Mockito.any(),
379 ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get();
380 Assert.assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode());
385 public void serviceImplementationServiceInActive5() throws InterruptedException, ExecutionException {
387 ServiceImplementationRequestInput input = ServiceDataUtils
388 .buildServiceImplementationRequestInputTerminationPointResource(OpenRoadmInterfacesImpl.NETWORK_TOKEN);
389 writePortMapping(input, OpenRoadmInterfacesImpl.NETWORK_TOKEN);
390 Measurements measurements = new MeasurementsBuilder().setPmparameterName("preFECCorrectedErrors")
391 .setPmparameterValue("112000000000d").build();
392 List<Measurements> measurementsList = new ArrayList<Measurements>();
393 measurementsList.add(measurements);
394 GetPmOutput getPmOutput = new GetPmOutputBuilder()
395 .setNodeId("node1").setMeasurements(measurementsList).build();
397 Mockito.doReturn(RpcResultBuilder.success(getPmOutput).buildFuture()).when(this.olmService)
398 .getPm(Mockito.any());
399 ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input).get();
400 Assert.assertEquals(ResponseCodes.RESPONSE_FAILED, result.getConfigurationResponseCommon().getResponseCode());