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 static org.junit.jupiter.api.Assertions.assertEquals;
11 import static org.mockito.ArgumentMatchers.any;
12 import static org.mockito.ArgumentMatchers.eq;
13 import static org.mockito.Mockito.doReturn;
14 import static org.mockito.Mockito.when;
16 import java.util.ArrayList;
17 import java.util.List;
18 import java.util.concurrent.ExecutionException;
19 import org.junit.jupiter.api.BeforeEach;
20 import org.junit.jupiter.api.Disabled;
21 import org.junit.jupiter.api.Test;
22 import org.junit.jupiter.api.extension.ExtendWith;
23 import org.mockito.Mock;
24 import org.mockito.junit.jupiter.MockitoExtension;
25 import org.opendaylight.mdsal.binding.api.DataBroker;
26 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
27 import org.opendaylight.mdsal.binding.api.RpcService;
28 import org.opendaylight.transportpce.common.ResponseCodes;
29 import org.opendaylight.transportpce.common.StringConstants;
30 import org.opendaylight.transportpce.common.mapping.PortMapping;
31 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaceException;
32 import org.opendaylight.transportpce.renderer.provisiondevice.notification.NotificationSender;
33 import org.opendaylight.transportpce.renderer.utils.NotificationPublishServiceMock;
34 import org.opendaylight.transportpce.renderer.utils.ServiceDataUtils;
35 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.RendererRollbackInputBuilder;
36 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.RendererRollbackOutputBuilder;
37 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.ServicePathOutputBuilder;
38 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.GetPm;
39 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.GetPmInput;
40 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.GetPmInputBuilder;
41 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.GetPmOutput;
42 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.GetPmOutputBuilder;
43 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetup;
44 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupOutputBuilder;
45 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndown;
46 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndownOutputBuilder;
47 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.get.pm.output.Measurements;
48 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.get.pm.output.MeasurementsBuilder;
49 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceImplementationRequestInput;
50 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceImplementationRequestOutput;
51 import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.types.rev161014.ResourceTypeEnum;
52 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev220926.PmGranularity;
53 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev220926.olm.get.pm.input.ResourceIdentifierBuilder;
54 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
56 @ExtendWith(MockitoExtension.class)
57 public class RendererServiceOperationsImplTest {
60 private DeviceRendererService deviceRenderer;
62 private OtnDeviceRendererService otnDeviceRendererService;
64 private DataBroker dataBroker;
66 private PortMapping portMapping;
68 private RpcService rpcService;
70 private ServicePowerSetup servicePowerSetup;
72 private ServicePowerTurndown servicePowerTurndown;
75 private RendererServiceOperationsImpl rendererServiceOperations;
79 void setUp() throws OpenRoadmInterfaceException {
80 NotificationPublishService notificationPublishService = new NotificationPublishServiceMock();
81 this.rendererServiceOperations = new RendererServiceOperationsImpl(deviceRenderer, otnDeviceRendererService,
82 dataBroker, new NotificationSender(notificationPublishService), portMapping, rpcService);
86 void serviceImplementationTerminationPointAsResourceTtp() throws InterruptedException, ExecutionException {
87 ServiceImplementationRequestInput input = ServiceDataUtils
88 .buildServiceImplementationRequestInputTerminationPointResource(StringConstants.TTP_TOKEN);
89 when(deviceRenderer.setupServicePath(any(), any(), any()))
90 .thenReturn(new ServicePathOutputBuilder().setResult("success").setSuccess(true).build());
92 when(rpcService.getRpc(ServicePowerSetup.class)).thenReturn(servicePowerSetup);
93 when(rpcService.getRpc(ServicePowerTurndown.class)).thenReturn(servicePowerTurndown);
94 when(rpcService.getRpc(GetPm.class)).thenReturn(getPm);
95 doReturn(RpcResultBuilder
96 .success(new ServicePowerSetupOutputBuilder().setResult(ResponseCodes.SUCCESS_RESULT).build())
97 .buildFuture()).when(servicePowerSetup).invoke(any());
98 doReturn(RpcResultBuilder.success(new GetPmOutputBuilder().setNodeId("node id").build()).buildFuture())
99 .when(getPm).invoke(any());
100 ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input, false)
102 assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode());
106 void serviceImplementationTerminationPointAsResourceTtp2() throws InterruptedException, ExecutionException {
107 ServiceImplementationRequestInput input = ServiceDataUtils
108 .buildServiceImplementationRequestInputTerminationPointResource(StringConstants.TTP_TOKEN);
109 ServicePathOutputBuilder mockOutputBuilder = new ServicePathOutputBuilder().setResult("success")
111 doReturn(mockOutputBuilder.build()).when(this.deviceRenderer).setupServicePath(any(), any(), any());
112 when(rpcService.getRpc(ServicePowerSetup.class)).thenReturn(servicePowerSetup);
113 doReturn(RpcResultBuilder.failed().buildFuture()).when(servicePowerSetup).invoke(any());
114 ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input, false)
116 assertEquals(ResponseCodes.RESPONSE_FAILED, result.getConfigurationResponseCommon().getResponseCode());
120 void serviceImplementationTerminationPointAsResourceNoMapping() throws InterruptedException, ExecutionException {
121 // when no mapping available, 100GE between transponders must be implemented
123 when(deviceRenderer.setupServicePath(any(), any(), any()))
124 .thenReturn(new ServicePathOutputBuilder().setResult("success").setSuccess(true).build());
126 when(rpcService.getRpc(ServicePowerSetup.class)).thenReturn(servicePowerSetup);
127 when(rpcService.getRpc(ServicePowerTurndown.class)).thenReturn(servicePowerTurndown);
128 when(rpcService.getRpc(GetPm.class)).thenReturn(getPm);
129 doReturn(RpcResultBuilder
130 .success(new ServicePowerSetupOutputBuilder().setResult(ResponseCodes.SUCCESS_RESULT).build())
131 .buildFuture()).when(servicePowerSetup).invoke(any());
132 doReturn(RpcResultBuilder.success(new GetPmOutputBuilder().setNodeId("node id").build()).buildFuture())
133 .when(getPm).invoke(any());
135 String[] interfaceTokens = { StringConstants.NETWORK_TOKEN, StringConstants.CLIENT_TOKEN,
136 StringConstants.TTP_TOKEN, StringConstants.PP_TOKEN };
137 for (String tpToken : interfaceTokens) {
138 ServiceImplementationRequestInput input = ServiceDataUtils
139 .buildServiceImplementationRequestInputTerminationPointResource(tpToken);
140 ServiceImplementationRequestOutput result = this.rendererServiceOperations
141 .serviceImplementation(input, false).get();
142 assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode());
147 void serviceImplementationRollbackAllNecessary() throws InterruptedException, ExecutionException {
148 ServiceImplementationRequestInput input = ServiceDataUtils
149 .buildServiceImplementationRequestInputTerminationPointResource(StringConstants.NETWORK_TOKEN);
150 when(deviceRenderer.setupServicePath(any(), any()))
151 .thenReturn(new ServicePathOutputBuilder().setResult("success").setSuccess(true).build());
152 when(rpcService.getRpc(ServicePowerSetup.class)).thenReturn(servicePowerSetup);
153 when(rpcService.getRpc(ServicePowerTurndown.class)).thenReturn(servicePowerTurndown);
154 doReturn(RpcResultBuilder
155 .success(new ServicePowerSetupOutputBuilder().setResult(ResponseCodes.RESPONSE_FAILED).build())
156 .buildFuture()).when(servicePowerSetup).invoke(any());
157 doReturn(RpcResultBuilder
158 .success(new ServicePowerTurndownOutputBuilder().setResult(ResponseCodes.SUCCESS_RESULT).build())
159 .buildFuture()).when(servicePowerTurndown).invoke(any());
160 when(deviceRenderer.rendererRollback(new RendererRollbackInputBuilder().build()))
161 .thenReturn(new RendererRollbackOutputBuilder().setSuccess(true).build());
162 ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input, false)
164 assertEquals(ResponseCodes.RESPONSE_FAILED, result.getConfigurationResponseCommon().getResponseCode());
167 @Disabled("Disabled until we understand the author objective...")
169 void serviceImplementationServiceInActive() throws InterruptedException, ExecutionException {
170 ServiceImplementationRequestInput input = ServiceDataUtils
171 .buildServiceImplementationRequestInputTerminationPointResource(StringConstants.NETWORK_TOKEN);
172 List<Measurements> measurementsList = new ArrayList<Measurements>();
173 measurementsList.add(new MeasurementsBuilder().setPmparameterName("FECUncorrectableBlocks")
174 .setPmparameterValue("1").build());
175 GetPmOutput getPmOutput = new GetPmOutputBuilder().setNodeId("node1").setMeasurements(measurementsList).build();
176 doReturn(RpcResultBuilder.success(getPmOutput).buildFuture()).when(getPm).invoke(any());
177 ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input, false)
179 assertEquals(ResponseCodes.RESPONSE_FAILED, result.getConfigurationResponseCommon().getResponseCode());
182 @Disabled("Disabled until we understand the author objective...")
184 void serviceImplementationServiceInActive3() throws InterruptedException, ExecutionException {
185 when(rpcService.getRpc(ServicePowerSetup.class)).thenReturn(servicePowerSetup);
186 List<Measurements> measurementsList = new ArrayList<Measurements>();
187 measurementsList.add(new MeasurementsBuilder().setPmparameterName("FECUncorrectableBlocks")
188 .setPmparameterValue("1").build());
189 GetPmOutput getPmOutput = new GetPmOutputBuilder().setNodeId("node1").setMeasurements(measurementsList).build();
190 GetPmOutput getPmOutput2 = new GetPmOutputBuilder().setNodeId("node1").setMeasurements(new ArrayList<>())
193 GetPmInput getPmInputZ = createGetPmInput("XPONDER-2-3", StringConstants.NETWORK_TOKEN);
194 GetPmInput getPmInputA = createGetPmInput("XPONDER-1-2", StringConstants.NETWORK_TOKEN);
196 when(getPm.invoke(eq(getPmInputZ))).thenReturn(RpcResultBuilder.success(getPmOutput2).buildFuture());
197 when(getPm.invoke(eq(getPmInputA))).thenReturn(RpcResultBuilder.success(getPmOutput).buildFuture());
198 ServicePathOutputBuilder mockOutputBuilder = new ServicePathOutputBuilder().setResult("success")
200 doReturn(mockOutputBuilder.build()).when(this.deviceRenderer).setupServicePath(any(), any(), any());
201 ServiceImplementationRequestInput input = ServiceDataUtils
202 .buildServiceImplementationRequestInputTerminationPointResource(StringConstants.NETWORK_TOKEN);
203 ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input, false)
205 assertEquals(ResponseCodes.RESPONSE_FAILED, result.getConfigurationResponseCommon().getResponseCode());
209 void serviceImplementationServiceActive() throws InterruptedException, ExecutionException {
210 ServiceImplementationRequestInput input = ServiceDataUtils
211 .buildServiceImplementationRequestInputTerminationPointResource(StringConstants.NETWORK_TOKEN);
212 when(deviceRenderer.setupServicePath(any(), any(), any()))
213 .thenReturn(new ServicePathOutputBuilder().setResult("success").setSuccess(true).build());
215 when(rpcService.getRpc(ServicePowerSetup.class)).thenReturn(servicePowerSetup);
216 when(rpcService.getRpc(ServicePowerTurndown.class)).thenReturn(servicePowerTurndown);
217 when(rpcService.getRpc(GetPm.class)).thenReturn(getPm);
218 doReturn(RpcResultBuilder
219 .success(new ServicePowerSetupOutputBuilder().setResult(ResponseCodes.SUCCESS_RESULT).build())
220 .buildFuture()).when(servicePowerSetup).invoke(any());
221 GetPmOutput getPmOutput1 = null;
222 when(getPm.invoke(any())).thenReturn(RpcResultBuilder.success(getPmOutput1).buildFuture());
223 ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input, false)
225 assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode());
229 void serviceImplementationServiceInActive4() throws InterruptedException, ExecutionException {
230 when(deviceRenderer.setupServicePath(any(), any(), any()))
231 .thenReturn(new ServicePathOutputBuilder().setResult("success").setSuccess(true).build());
233 when(rpcService.getRpc(ServicePowerSetup.class)).thenReturn(servicePowerSetup);
234 when(rpcService.getRpc(ServicePowerTurndown.class)).thenReturn(servicePowerTurndown);
235 when(rpcService.getRpc(GetPm.class)).thenReturn(getPm);
236 doReturn(RpcResultBuilder
237 .success(new ServicePowerSetupOutputBuilder().setResult(ResponseCodes.SUCCESS_RESULT).build())
238 .buildFuture()).when(servicePowerSetup).invoke(any());
240 List<Measurements> measurementsList = new ArrayList<Measurements>();
241 measurementsList.add(
242 new MeasurementsBuilder().setPmparameterName("preFECCorrectedErrors").setPmparameterValue("1").build());
243 GetPmOutput getPmOutput = new GetPmOutputBuilder().setNodeId("node1").setMeasurements(measurementsList).build();
244 when(getPm.invoke(any())).thenReturn(RpcResultBuilder.success(getPmOutput).buildFuture());
246 ServiceImplementationRequestInput input = ServiceDataUtils
247 .buildServiceImplementationRequestInputTerminationPointResource(StringConstants.NETWORK_TOKEN);
248 ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input, false)
250 assertEquals(ResponseCodes.RESPONSE_OK, result.getConfigurationResponseCommon().getResponseCode());
254 void serviceImplementationServiceInActive5() throws InterruptedException, ExecutionException {
255 when(deviceRenderer.setupServicePath(any(), any(), any()))
256 .thenReturn(new ServicePathOutputBuilder().setResult("success").setSuccess(true).build());
257 when(rpcService.getRpc(ServicePowerSetup.class)).thenReturn(servicePowerSetup);
258 when(rpcService.getRpc(ServicePowerTurndown.class)).thenReturn(servicePowerTurndown);
259 when(rpcService.getRpc(GetPm.class)).thenReturn(getPm);
260 doReturn(RpcResultBuilder
261 .success(new ServicePowerSetupOutputBuilder().setResult(ResponseCodes.SUCCESS_RESULT).build())
262 .buildFuture()).when(servicePowerSetup).invoke(any());
264 List<Measurements> measurementsList = new ArrayList<Measurements>();
265 measurementsList.add(new MeasurementsBuilder().setPmparameterName("preFECCorrectedErrors")
266 .setPmparameterValue("112000000000d").build());
267 GetPmOutput getPmOutput = new GetPmOutputBuilder().setNodeId("node1").setMeasurements(measurementsList).build();
268 when(getPm.invoke(any())).thenReturn(RpcResultBuilder.success(getPmOutput).buildFuture());
270 ServiceImplementationRequestInput input = ServiceDataUtils
271 .buildServiceImplementationRequestInputTerminationPointResource(StringConstants.NETWORK_TOKEN);
272 ServiceImplementationRequestOutput result = this.rendererServiceOperations.serviceImplementation(input, false)
274 assertEquals(ResponseCodes.RESPONSE_FAILED, result.getConfigurationResponseCommon().getResponseCode());
277 private GetPmInput createGetPmInput(String nodeId, String tp) {
278 return new GetPmInputBuilder().setNodeId(nodeId).setGranularity(PmGranularity._15min)
279 .setResourceIdentifier(new ResourceIdentifierBuilder().setResourceName(tp + "-OTU").build())
280 .setResourceType(ResourceTypeEnum.Interface).build();