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
9 package org.opendaylight.transportpce.renderer.provisiondevice;
11 import com.google.common.util.concurrent.ListenableFuture;
12 import com.google.common.util.concurrent.ListeningExecutorService;
13 import com.google.common.util.concurrent.MoreExecutors;
14 import java.util.Collections;
15 import java.util.concurrent.ExecutionException;
16 import java.util.concurrent.Executors;
17 import org.junit.Assert;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.mockito.Mockito;
21 import org.opendaylight.mdsal.binding.api.MountPoint;
22 import org.opendaylight.mdsal.binding.api.MountPointService;
23 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
24 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
25 import org.opendaylight.transportpce.common.ResponseCodes;
26 import org.opendaylight.transportpce.common.StringConstants;
27 import org.opendaylight.transportpce.common.crossconnect.CrossConnect;
28 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl;
29 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl121;
30 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl221;
31 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
32 import org.opendaylight.transportpce.common.device.DeviceTransactionManagerImpl;
33 import org.opendaylight.transportpce.common.fixedflex.FixedFlexImpl;
34 import org.opendaylight.transportpce.common.fixedflex.FixedFlexInterface;
35 import org.opendaylight.transportpce.common.fixedflex.FlexGridImpl;
36 import org.opendaylight.transportpce.common.mapping.MappingUtils;
37 import org.opendaylight.transportpce.common.mapping.MappingUtilsImpl;
38 import org.opendaylight.transportpce.common.mapping.PortMapping;
39 import org.opendaylight.transportpce.common.mapping.PortMappingImpl;
40 import org.opendaylight.transportpce.common.mapping.PortMappingVersion121;
41 import org.opendaylight.transportpce.common.mapping.PortMappingVersion221;
42 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
43 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl;
44 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl121;
45 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl221;
46 import org.opendaylight.transportpce.renderer.NetworkModelWavelengthService;
47 import org.opendaylight.transportpce.renderer.NetworkModelWavelengthServiceImpl;
48 import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmInterface121;
49 import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmInterface221;
50 import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmInterfaceFactory;
51 import org.opendaylight.transportpce.renderer.openroadminterface.OpenRoadmOtnInterface221;
52 import org.opendaylight.transportpce.renderer.stub.MountPointServiceStub;
53 import org.opendaylight.transportpce.renderer.stub.MountPointStub;
54 import org.opendaylight.transportpce.renderer.stub.OlmServiceStub;
55 import org.opendaylight.transportpce.renderer.utils.NotificationPublishServiceMock;
56 import org.opendaylight.transportpce.renderer.utils.ServiceDeleteDataUtils;
57 import org.opendaylight.transportpce.renderer.utils.TransactionUtils;
58 import org.opendaylight.transportpce.test.AbstractTest;
59 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.ServicePowerTurndownOutputBuilder;
60 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.TransportpceOlmService;
61 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev200520.ServiceDeleteInputBuilder;
62 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev200520.ServiceDeleteOutput;
63 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.ConnectionType;
64 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.ServiceAEnd;
65 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.service.ServiceAEndBuilder;
66 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.format.rev190531.ServiceFormat;
67 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.list.Services;
68 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.list.ServicesBuilder;
69 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev200128.service.handler.header.ServiceHandlerHeaderBuilder;
70 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.ServicePathList;
71 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePaths;
72 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePathsBuilder;
73 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePathsKey;
74 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
75 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
76 import org.opendaylight.yangtools.yang.common.Uint32;
78 public class RendererServiceOperationsImplDeleteTest extends AbstractTest {
80 private static final int NUMBER_OF_THREADS = 4;
81 private DeviceTransactionManager deviceTransactionManager;
82 private RendererServiceOperationsImpl rendererServiceOperations;
83 private OpenRoadmInterfaces openRoadmInterfaces;
84 private DeviceRendererService deviceRenderer;
85 private PortMapping portMapping;
86 private CrossConnect crossConnect;
87 private NetworkModelWavelengthService networkModelWavelengthService;
88 private TransportpceOlmService olmService;
89 private MappingUtils mappingUtils;
90 private OpenRoadmInterfacesImpl121 openRoadmInterfacesImpl121;
91 private OpenRoadmInterfacesImpl221 openRoadmInterfacesImpl221;
92 private PortMappingVersion221 portMappingVersion22;
93 private PortMappingVersion121 portMappingVersion121;
94 private CrossConnectImpl121 crossConnectImpl121;
95 private CrossConnectImpl221 crossConnectImpl221;
96 private OtnDeviceRendererService otnDeviceRendererService;
98 private void setMountPoint(MountPoint mountPoint) {
99 MountPointService mountPointService = new MountPointServiceStub(mountPoint);
100 this.deviceTransactionManager = new DeviceTransactionManagerImpl(mountPointService, 3000);
101 this.openRoadmInterfacesImpl121 = new OpenRoadmInterfacesImpl121(deviceTransactionManager);
102 this.openRoadmInterfacesImpl221 = new OpenRoadmInterfacesImpl221(deviceTransactionManager);
103 this.mappingUtils = new MappingUtilsImpl(getDataBroker());
104 this.openRoadmInterfaces = new OpenRoadmInterfacesImpl(deviceTransactionManager, mappingUtils,
105 openRoadmInterfacesImpl121, openRoadmInterfacesImpl221);
106 this.openRoadmInterfaces = Mockito.spy(this.openRoadmInterfaces);
107 this.portMappingVersion22 =
108 new PortMappingVersion221(getDataBroker(), deviceTransactionManager, this.openRoadmInterfaces);
109 this.portMappingVersion121 =
110 new PortMappingVersion121(getDataBroker(), deviceTransactionManager, this.openRoadmInterfaces);
111 this.portMapping = new PortMappingImpl(getDataBroker(), this.portMappingVersion22,
112 this.portMappingVersion121);
113 this.crossConnectImpl121 = new CrossConnectImpl121(deviceTransactionManager);
114 this.crossConnectImpl221 = new CrossConnectImpl221(deviceTransactionManager);
115 this.crossConnect = new CrossConnectImpl(deviceTransactionManager, this.mappingUtils, this.crossConnectImpl121,
116 this.crossConnectImpl221);
117 this.crossConnect = Mockito.spy(crossConnect);
118 FixedFlexInterface fixedFlexInterface = new FixedFlexImpl();
119 FlexGridImpl flexGrid = new FlexGridImpl();
120 OpenRoadmInterface121 openRoadmInterface121 = new OpenRoadmInterface121(portMapping,openRoadmInterfaces);
121 OpenRoadmInterface221 openRoadmInterface221 = new OpenRoadmInterface221(portMapping,openRoadmInterfaces,
122 fixedFlexInterface, flexGrid);
123 OpenRoadmOtnInterface221 openRoadmOTNInterface = new OpenRoadmOtnInterface221(portMapping, openRoadmInterfaces);
124 OpenRoadmInterfaceFactory openRoadmInterfaceFactory = new OpenRoadmInterfaceFactory(this.mappingUtils,
125 openRoadmInterface121, openRoadmInterface221, openRoadmOTNInterface);
127 this.deviceRenderer = new DeviceRendererServiceImpl(this.getDataBroker(),
128 this.deviceTransactionManager, openRoadmInterfaceFactory, openRoadmInterfaces, crossConnect,
129 this.portMapping, null);
131 this.otnDeviceRendererService = new OtnDeviceRendererServiceImpl(openRoadmInterfaceFactory, crossConnect,
132 openRoadmInterfaces, this.deviceTransactionManager, null);
137 public void setUp() {
138 setMountPoint(new MountPointStub(getDataBroker()));
139 this.olmService = new OlmServiceStub();
140 this.olmService = Mockito.spy(this.olmService);
141 ListeningExecutorService executor =
142 MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(NUMBER_OF_THREADS));
143 this.networkModelWavelengthService = new NetworkModelWavelengthServiceImpl(getDataBroker());
144 NotificationPublishService notificationPublishService = new NotificationPublishServiceMock();
145 this.rendererServiceOperations = new RendererServiceOperationsImpl(this.deviceRenderer,
146 this.otnDeviceRendererService, olmService, getDataBroker(), this.networkModelWavelengthService,
147 notificationPublishService);
153 public void serviceDeleteOperationPp() throws ExecutionException, InterruptedException {
154 writePathDescription();
155 ServiceDeleteInputBuilder serviceDeleteInputBuilder = new ServiceDeleteInputBuilder();
156 serviceDeleteInputBuilder.setServiceName("service 1");
157 serviceDeleteInputBuilder.setServiceHandlerHeader((new ServiceHandlerHeaderBuilder())
158 .setRequestId("request1").build());
159 Mockito.doReturn(Collections.emptyList()).when(this.crossConnect).deleteCrossConnect(Mockito.anyString(),
160 Mockito.anyString(), Mockito.eq(false));
161 ServiceAEnd serviceAEnd = new ServiceAEndBuilder()
162 .setServiceFormat(ServiceFormat.Ethernet)
163 .setServiceRate(Uint32.valueOf("100"))
165 Services service = new ServicesBuilder()
166 .setConnectionType(ConnectionType.Service)
167 .setServiceAEnd(serviceAEnd)
169 ServiceDeleteOutput serviceDeleteOutput
170 = this.rendererServiceOperations.serviceDelete(serviceDeleteInputBuilder.build(), service).get();
171 Assert.assertEquals(ResponseCodes.RESPONSE_OK,
172 serviceDeleteOutput.getConfigurationResponseCommon().getResponseCode());
173 Mockito.verify(this.crossConnect, Mockito.times(2))
174 .deleteCrossConnect(Mockito.any(), Mockito.any(), Mockito.eq(false));
178 public void serviceDeleteOperationNoDescription() throws InterruptedException, ExecutionException {
179 ServiceDeleteInputBuilder serviceDeleteInputBuilder = new ServiceDeleteInputBuilder();
180 serviceDeleteInputBuilder.setServiceName("service 1");
181 ServiceDeleteOutput serviceDeleteOutput
182 = this.rendererServiceOperations.serviceDelete(serviceDeleteInputBuilder.build(), null).get();
183 Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
184 serviceDeleteOutput.getConfigurationResponseCommon().getResponseCode());
185 Mockito.verify(this.crossConnect, Mockito.times(0))
186 .deleteCrossConnect(Mockito.any(), Mockito.any(), Mockito.eq(false));
190 public void serviceDeleteOperationTearDownFailedAtoZ() throws ExecutionException, InterruptedException {
191 Mockito.doReturn(Collections.emptyList()).when(this.crossConnect).deleteCrossConnect(Mockito.anyString(),
192 Mockito.anyString(), Mockito.eq(false));
193 Mockito.doReturn(RpcResultBuilder.success((new ServicePowerTurndownOutputBuilder())
194 .setResult("Failed").build()).buildFuture()).when(this.olmService).servicePowerTurndown(Mockito.any());
196 writePathDescription();
197 ServiceDeleteInputBuilder serviceDeleteInputBuilder = new ServiceDeleteInputBuilder();
198 serviceDeleteInputBuilder.setServiceName("service 1");
199 serviceDeleteInputBuilder.setServiceHandlerHeader((new ServiceHandlerHeaderBuilder())
200 .setRequestId("request1").build());
201 ServiceAEnd serviceAEnd = new ServiceAEndBuilder()
202 .setServiceFormat(ServiceFormat.Ethernet)
203 .setServiceRate(Uint32.valueOf("100"))
205 Services service = new ServicesBuilder()
206 .setConnectionType(ConnectionType.Service)
207 .setServiceAEnd(serviceAEnd)
209 ListenableFuture<ServiceDeleteOutput> serviceDeleteOutput
210 = this.rendererServiceOperations.serviceDelete(serviceDeleteInputBuilder.build(), service);
211 ServiceDeleteOutput output = serviceDeleteOutput.get();
212 Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
213 output.getConfigurationResponseCommon().getResponseCode());
214 Mockito.verify(this.crossConnect, Mockito.times(0)).deleteCrossConnect(Mockito.eq("node1"), Mockito.any(),
216 Mockito.verify(this.crossConnect, Mockito.times(0)).deleteCrossConnect(Mockito.eq("node2"), Mockito.any(),
221 public void serviceDeleteOperationTearDownFailedZtoA() throws ExecutionException, InterruptedException {
222 Mockito.doReturn(Collections.emptyList()).when(this.crossConnect).deleteCrossConnect(Mockito.anyString(),
223 Mockito.anyString(), Mockito.eq(false));
224 Mockito.when(this.olmService.servicePowerTurndown(Mockito.any()))
225 .thenReturn(RpcResultBuilder.success((new ServicePowerTurndownOutputBuilder())
226 .setResult("Success").build()).buildFuture())
227 .thenReturn(RpcResultBuilder.success((new ServicePowerTurndownOutputBuilder())
228 .setResult("Failed").build()).buildFuture());
230 writePathDescription();
231 ServiceDeleteInputBuilder serviceDeleteInputBuilder = new ServiceDeleteInputBuilder();
232 serviceDeleteInputBuilder.setServiceName("service 1");
233 serviceDeleteInputBuilder.setServiceHandlerHeader((new ServiceHandlerHeaderBuilder())
234 .setRequestId("request1").build());
235 ServiceAEnd serviceAEnd = new ServiceAEndBuilder()
236 .setServiceFormat(ServiceFormat.Ethernet)
237 .setServiceRate(Uint32.valueOf("100"))
239 Services service = new ServicesBuilder()
240 .setConnectionType(ConnectionType.Service)
241 .setServiceAEnd(serviceAEnd)
243 ServiceDeleteOutput serviceDeleteOutput =
244 this.rendererServiceOperations.serviceDelete(serviceDeleteInputBuilder.build(), service).get();
245 Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
246 serviceDeleteOutput.getConfigurationResponseCommon().getResponseCode());
247 Mockito.verify(this.olmService, Mockito.times(2)).servicePowerTurndown(Mockito.any());
248 Mockito.verify(this.crossConnect, Mockito.times(0)).deleteCrossConnect(Mockito.eq("node1"), Mockito.any(),
250 Mockito.verify(this.crossConnect, Mockito.times(0)).deleteCrossConnect(Mockito.eq("node2"), Mockito.any(),
254 private void writePathDescription() throws ExecutionException, InterruptedException {
255 ServicePathsBuilder servicePathsBuilder = new ServicePathsBuilder();
256 servicePathsBuilder.setPathDescription(ServiceDeleteDataUtils
257 .createTransactionPathDescription(StringConstants.PP_TOKEN));
258 servicePathsBuilder.setServiceAEnd(ServiceDeleteDataUtils.getServiceAEndBuild().build())
259 .setServiceZEnd(ServiceDeleteDataUtils.getServiceZEndBuild().build());
260 servicePathsBuilder.withKey(new ServicePathsKey("service 1"));
261 servicePathsBuilder.setServiceHandlerHeader(new ServiceHandlerHeaderBuilder().setRequestId("Request 1")
263 InstanceIdentifier<ServicePaths> servicePathsInstanceIdentifier = InstanceIdentifier.create(
264 ServicePathList.class).child(ServicePaths.class, new ServicePathsKey("service 1"));
265 TransactionUtils.writeTransaction(
266 this.deviceTransactionManager,
267 "node1" + StringConstants.PP_TOKEN,
268 LogicalDatastoreType.OPERATIONAL,
269 servicePathsInstanceIdentifier,
270 servicePathsBuilder.build());