2 * Copyright © 2017 Orange, 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.servicehandler.listeners;
10 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
11 import java.util.ArrayList;
12 import java.util.List;
14 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
15 import org.opendaylight.transportpce.common.OperationResult;
16 import org.opendaylight.transportpce.common.StringConstants;
17 import org.opendaylight.transportpce.networkmodel.service.NetworkModelService;
18 import org.opendaylight.transportpce.pce.service.PathComputationService;
19 import org.opendaylight.transportpce.servicehandler.ServiceInput;
20 import org.opendaylight.transportpce.servicehandler.service.PCEServiceWrapper;
21 import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations;
22 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.networkutils.rev220630.OtnLinkType;
23 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.RendererRpcResultSp;
24 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.TransportpceRendererListener;
25 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.renderer.rpc.result.sp.Link;
26 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev201125.ServiceRpcResultSh;
27 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev201125.ServiceRpcResultShBuilder;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.ServiceNotificationTypes;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.equipment.states.types.rev191129.AdminStates;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceRpcResult;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceRpcResultBuilder;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.service.list.Services;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.service.rpc.result.PathComputationResultBuilder;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.service.rpc.result.path.computation.result.AToZBuilder;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.service.rpc.result.path.computation.result.ZToABuilder;
37 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.PublishNotificationProcessService;
38 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.PublishNotificationProcessServiceBuilder;
39 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.notification.process.service.ServiceAEndBuilder;
40 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.notification.process.service.ServiceZEndBuilder;
41 import org.osgi.service.component.annotations.Activate;
42 import org.osgi.service.component.annotations.Component;
43 import org.osgi.service.component.annotations.Reference;
44 import org.slf4j.Logger;
45 import org.slf4j.LoggerFactory;
48 * Calls to listen to Renderer notifications.
50 * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange
54 public class RendererListenerImpl implements TransportpceRendererListener, RendererListener {
56 private static final String PUBLISHER = "RendererListener";
57 private static final Logger LOG = LoggerFactory.getLogger(RendererListenerImpl.class);
58 private RendererRpcResultSp serviceRpcResultSp;
59 private ServiceDataStoreOperations serviceDataStoreOperations;
60 private ServiceInput input;
61 private PCEServiceWrapper pceServiceWrapper;
62 private Boolean tempService;
63 private NotificationPublishService notificationPublishService;
64 private final NetworkModelService networkModelService;
68 public RendererListenerImpl(@Reference PathComputationService pathComputationService,
69 @Reference NotificationPublishService notificationPublishService,
70 @Reference NetworkModelService networkModelService) {
71 this.pceServiceWrapper = new PCEServiceWrapper(pathComputationService, notificationPublishService);
72 setServiceInput(null);
73 setTempService(false);
74 this.notificationPublishService = notificationPublishService;
75 this.networkModelService = networkModelService;
79 public void onRendererRpcResultSp(RendererRpcResultSp notification) {
80 if (compareServiceRpcResultSp(notification)) {
81 LOG.warn("ServiceRpcResultSp already wired !");
84 serviceRpcResultSp = notification;
85 int notifType = serviceRpcResultSp.getNotificationType().getIntValue();
86 LOG.info("Renderer '{}' Notification received : {}", serviceRpcResultSp.getNotificationType().getName(),
89 /* service-implementation-request. */
91 onServiceImplementationResult(notification);
95 onServiceDeleteResult(notification);
103 * Process service delete result for serviceName.
104 * @param notification RendererRpcResultSp
106 private void onServiceDeleteResult(RendererRpcResultSp notification) {
107 switch (serviceRpcResultSp.getStatus()) {
109 updateOtnTopology(notification, true);
112 LOG.error("Renderer service delete failed !");
113 Services service = serviceDataStoreOperations.getService(input.getServiceName()).orElseThrow();
114 sendNbiNotification(new PublishNotificationProcessServiceBuilder()
115 .setServiceName(service.getServiceName())
116 .setServiceAEnd(new ServiceAEndBuilder(service.getServiceAEnd()).build())
117 .setServiceZEnd(new ServiceZEndBuilder(service.getServiceZEnd()).build())
118 .setCommonId(service.getCommonId())
119 .setConnectionType(service.getConnectionType())
120 .setResponseFailed("Renderer service delete failed !")
121 .setMessage("ServiceDelete request failed ...")
122 .setOperationalState(service.getOperationalState())
123 .setPublisherName(PUBLISHER)
127 LOG.warn("Renderer service delete returned a Pending RpcStatusEx code!");
130 LOG.error("Renderer service delete returned an unknown RpcStatusEx code!");
133 LOG.info("Service '{}' deleted !", notification.getServiceName());
134 if (this.input == null) {
135 LOG.error("ServiceInput parameter is null !");
138 LOG.info("sending PCE cancel resource reserve for '{}'", this.input.getServiceName());
139 this.pceServiceWrapper.cancelPCEResource(this.input.getServiceName(),
140 ServiceNotificationTypes.ServiceDeleteResult);
141 sendServiceHandlerNotification(notification, ServiceNotificationTypes.ServiceDeleteResult);
145 * Process service implementation result for serviceName.
146 * @param notification RendererRpcResultSp
148 private void onServiceImplementationResult(RendererRpcResultSp notification) {
149 switch (serviceRpcResultSp.getStatus()) {
151 onSuccededServiceImplementation(notification);
154 onFailedServiceImplementation(notification.getServiceName());
157 LOG.warn("Service Implementation still pending according to RpcStatusEx");
160 LOG.warn("Service Implementation has an unknown RpcStatusEx code");
166 * Process succeeded service implementation for service.
167 * @param notification RendererRpcResultSp
169 private void onSuccededServiceImplementation(RendererRpcResultSp notification) {
170 LOG.info("Service implemented !");
171 if (serviceDataStoreOperations == null) {
172 LOG.debug("serviceDataStoreOperations is null");
175 updateOtnTopology(notification, false);
176 PublishNotificationProcessServiceBuilder nbiNotificationBuilder =
177 new PublishNotificationProcessServiceBuilder()
178 .setServiceName(input.getServiceName())
179 .setServiceAEnd(new ServiceAEndBuilder(input.getServiceAEnd()).build())
180 .setServiceZEnd(new ServiceZEndBuilder(input.getServiceZEnd()).build())
181 .setCommonId(input.getCommonId()).setConnectionType(input.getConnectionType())
182 .setPublisherName(PUBLISHER);
183 String serviceTemp = "";
185 OperationResult operationResult = this.serviceDataStoreOperations.modifyTempService(
186 serviceRpcResultSp.getServiceName(), State.InService, AdminStates.InService);
187 serviceTemp = "Temp ";
188 if (operationResult.isSuccess()) {
189 sendNbiNotification(nbiNotificationBuilder
190 .setResponseFailed("")
191 .setMessage("Temp Service implemented !")
192 .setOperationalState(State.InService)
194 LOG.debug("For the Temp service, sending notification on service-result-rpc");
195 sendServiceRpcResultNotification(notification, ServiceNotificationTypes.ServiceCreateResult);
199 OperationResult operationResult = this.serviceDataStoreOperations.modifyService(
200 serviceRpcResultSp.getServiceName(), State.InService, AdminStates.InService);
201 // Here the service is implemented and the tempService has to be deleted if present
202 String commonId = input.getCommonId();
203 if (commonId != null) {
204 if (this.serviceDataStoreOperations.getTempService(commonId).isPresent()) {
205 LOG.info("Temp-service exists with the common-Id {}", commonId);
206 // Delete the common-id from this temp-service-list here
207 OperationResult tempServiceListDelete = serviceDataStoreOperations.deleteTempService(commonId);
208 //TODO: Also need to delete the service-path from the transportpce-service-path list
209 this.serviceDataStoreOperations.deleteServicePath(commonId);
210 LOG.info("Result for temp-service-list with {} is {}", commonId, tempServiceListDelete);
214 if (operationResult.isSuccess()) {
215 sendNbiNotification(nbiNotificationBuilder
216 .setResponseFailed("")
217 .setMessage("Service implemented !")
218 .setOperationalState(State.InService)
220 sendServiceHandlerNotification(notification, ServiceNotificationTypes.ServiceCreateResult);
224 LOG.warn("{}Service status not updated in datastore !", serviceTemp);
225 sendNbiNotification(nbiNotificationBuilder
226 .setResponseFailed(serviceTemp + "Service status not updated in datastore !")
227 .setMessage("ServiceCreate request failed ...")
228 .setOperationalState(State.OutOfService)
233 * Create and send service handler notification.
234 * @param notification RendererRpcResultSp
235 * @param type ServiceNotificationTypes
237 private void sendServiceHandlerNotification(RendererRpcResultSp notification, ServiceNotificationTypes type) {
239 ServiceRpcResultSh serviceHandlerNotification = new ServiceRpcResultShBuilder()
240 .setAToZDirection(notification.getAToZDirection())
241 .setZToADirection(notification.getZToADirection())
242 .setServiceName(notification.getServiceName())
243 .setStatus(notification.getStatus())
244 .setStatusMessage(notification.getStatusMessage())
245 .setNotificationType(type)
247 LOG.debug("Service update in datastore OK, sending notification {}", serviceHandlerNotification);
248 notificationPublishService.putNotification(
249 serviceHandlerNotification);
250 } catch (InterruptedException e) {
251 LOG.warn("Something went wrong while sending notification for service {}",
252 serviceRpcResultSp.getServiceName(), e);
253 Thread.currentThread().interrupt();
257 private void sendServiceRpcResultNotification(RendererRpcResultSp notification, ServiceNotificationTypes type) {
259 ServiceRpcResult serviceRpcResult = new ServiceRpcResultBuilder()
260 .setServiceName(notification.getServiceName())
261 .setNotificationType(type)
262 .setStatusMessage(notification.getStatusMessage())
263 .setCommonId(notification.getCommonId())
264 .setPathComputationResult(new PathComputationResultBuilder()
265 .setAToZ(new AToZBuilder()
266 .setFrequency(notification
268 .getCentralFrequency())
269 .setWidth(notification
272 // TODO: here the optical operational mode should be set
273 // TODO: also set the GNSR, OSNR, power values
274 .setOpticalOperationalMode("test")
276 .setZToA(new ZToABuilder()
277 .setFrequency(notification
279 .getCentralFrequency())
280 .setWidth(notification
283 // TODO: here the optical operational mode should be set
284 // TODO: also set the GNSR, OSNR, power values
285 .setOpticalOperationalMode("test")
289 LOG.info("Sending the notification for service-rpc-result {}", serviceRpcResult);
290 notificationPublishService.putNotification(
292 } catch (InterruptedException e) {
293 LOG.warn("Something went wrong while sending notification for service {}",
294 serviceRpcResultSp.getServiceName(), e);
295 Thread.currentThread().interrupt();
302 * Process failed service implementation for serviceName.
303 * @param serviceName String
305 private void onFailedServiceImplementation(String serviceName) {
306 LOG.error("Renderer implementation failed !");
307 Services service = serviceDataStoreOperations.getService(input.getServiceName()).orElseThrow();
308 sendNbiNotification(new PublishNotificationProcessServiceBuilder()
309 .setServiceName(service.getServiceName())
310 .setServiceAEnd(new ServiceAEndBuilder(service.getServiceAEnd()).build())
311 .setServiceZEnd(new ServiceZEndBuilder(service.getServiceZEnd()).build())
312 .setCommonId(service.getCommonId())
313 .setConnectionType(service.getConnectionType())
314 .setResponseFailed("Renderer implementation failed !")
315 .setMessage("ServiceCreate request failed ...")
316 .setOperationalState(service.getOperationalState())
317 .setPublisherName(PUBLISHER)
319 OperationResult deleteServicePathOperationResult =
320 this.serviceDataStoreOperations.deleteServicePath(serviceName);
321 if (!deleteServicePathOperationResult.isSuccess()) {
322 LOG.warn("Service path was not removed from datastore!");
324 OperationResult deleteServiceOperationResult;
325 String serviceType = "";
327 deleteServiceOperationResult = this.serviceDataStoreOperations.deleteTempService(serviceName);
328 serviceType = "Temp ";
330 deleteServiceOperationResult = this.serviceDataStoreOperations.deleteService(serviceName);
332 if (deleteServiceOperationResult.isSuccess()) {
333 LOG.warn("{}Service was not removed from datastore!", serviceType);
338 value = "ES_COMPARING_STRINGS_WITH_EQ",
339 justification = "false positives, not strings but real object references comparisons")
340 private Boolean compareServiceRpcResultSp(RendererRpcResultSp notification) {
341 if (serviceRpcResultSp == null
342 || serviceRpcResultSp.getNotificationType() != notification.getNotificationType()
343 || serviceRpcResultSp.getServiceName() != notification.getServiceName()
344 || serviceRpcResultSp.getStatus() != notification.getStatus()
345 || serviceRpcResultSp.getStatusMessage() != notification.getStatusMessage()) {
352 public void setServiceInput(ServiceInput serviceInput) {
353 this.input = serviceInput;
357 public void setserviceDataStoreOperations(ServiceDataStoreOperations serviceData) {
358 this.serviceDataStoreOperations = serviceData;
362 public void setTempService(Boolean tempService) {
363 this.tempService = tempService;
367 * Send notification to NBI notification in order to publish message.
368 * @param service PublishNotificationService
370 private void sendNbiNotification(PublishNotificationProcessService service) {
372 notificationPublishService.putNotification(service);
373 } catch (InterruptedException e) {
374 LOG.warn("Cannot send notification to nbi", e);
375 Thread.currentThread().interrupt();
380 private void updateOtnTopology(RendererRpcResultSp notification, boolean isDeletion) {
381 Link link = notification.getLink();
382 if (link == null && notification.getLinkId() == null) {
385 List<String> supportedLinkIds = null;
386 if (notification.getLinkId() != null) {
387 supportedLinkIds = new ArrayList<>(notification.getLinkId());
389 String serviceType = notification.getServiceType();
390 switch (serviceType) {
391 case StringConstants.SERVICE_TYPE_OTU4:
392 case StringConstants.SERVICE_TYPE_OTUC2:
393 case StringConstants.SERVICE_TYPE_OTUC3:
394 case StringConstants.SERVICE_TYPE_OTUC4:
395 case StringConstants.SERVICE_TYPE_ODU4:
396 case StringConstants.SERVICE_TYPE_ODUC2:
397 case StringConstants.SERVICE_TYPE_ODUC3:
398 case StringConstants.SERVICE_TYPE_ODUC4:
399 Map<String, OtnLinkType> otnLinkTypeMap = Map.of(
400 StringConstants.SERVICE_TYPE_OTU4, OtnLinkType.OTU4,
401 // TODO: need to change it when OtnLinkType is updated with enum
402 StringConstants.SERVICE_TYPE_OTUC2, OtnLinkType.OTUC4,
403 StringConstants.SERVICE_TYPE_OTUC3, OtnLinkType.OTUC4,
404 StringConstants.SERVICE_TYPE_OTUC4, OtnLinkType.OTUC4,
405 StringConstants.SERVICE_TYPE_ODU4, OtnLinkType.ODTU4,
406 // TODO: need to change it when OtnLinkType is updated with enum
407 StringConstants.SERVICE_TYPE_ODUC2, OtnLinkType.ODUC4,
408 StringConstants.SERVICE_TYPE_ODUC3, OtnLinkType.ODUC4,
409 StringConstants.SERVICE_TYPE_ODUC4, OtnLinkType.ODUC4);
411 LOG.info("updating otn-topology removing links");
412 this.networkModelService.deleteOtnLinks(link, supportedLinkIds, otnLinkTypeMap.get(serviceType));
414 LOG.info("updating otn-topology adding links");
415 this.networkModelService.createOtnLinks(link, supportedLinkIds, otnLinkTypeMap.get(serviceType));
418 case StringConstants.SERVICE_TYPE_1GE:
419 case StringConstants.SERVICE_TYPE_10GE:
420 case StringConstants.SERVICE_TYPE_100GE_M:
421 Short tribPort = Short.valueOf(notification.getAToZDirection().getMinTribSlot().getValue()
423 Short minTribSlot = Short.valueOf(notification.getAToZDirection().getMinTribSlot().getValue()
425 Short maxTribSlot = Short.valueOf(notification.getAToZDirection().getMaxTribSlot().getValue()
427 LOG.info("updating otn-topology node tps -tps and tpn pools");
428 this.networkModelService.updateOtnLinks(link, supportedLinkIds,
429 notification.getAToZDirection().getRate(), tribPort, minTribSlot, maxTribSlot, isDeletion);
431 case StringConstants.SERVICE_TYPE_100GE_S:
432 this.networkModelService.updateOtnLinks(supportedLinkIds, isDeletion);
435 LOG.warn("service-type {} not managed yet", serviceType);