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;
15 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
16 import org.opendaylight.mdsal.binding.api.NotificationService.CompositeListener;
17 import org.opendaylight.transportpce.common.OperationResult;
18 import org.opendaylight.transportpce.common.StringConstants;
19 import org.opendaylight.transportpce.networkmodel.service.NetworkModelService;
20 import org.opendaylight.transportpce.pce.service.PathComputationService;
21 import org.opendaylight.transportpce.servicehandler.ServiceInput;
22 import org.opendaylight.transportpce.servicehandler.service.PCEServiceWrapper;
23 import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations;
24 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.networkutils.rev220630.OtnLinkType;
25 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.RendererRpcResultSp;
26 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.renderer.rpc.result.sp.Link;
27 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev201125.ServiceRpcResultSh;
28 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev201125.ServiceRpcResultShBuilder;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.ServiceNotificationTypes;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.equipment.states.types.rev191129.AdminStates;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceRpcResult;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceRpcResultBuilder;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.service.list.Services;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.service.rpc.result.PathComputationResultBuilder;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.service.rpc.result.path.computation.result.AToZBuilder;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.service.rpc.result.path.computation.result.ZToABuilder;
38 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230726.PublishNotificationProcessService;
39 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230726.PublishNotificationProcessServiceBuilder;
40 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230726.notification.process.service.ServiceAEndBuilder;
41 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230726.notification.process.service.ServiceZEndBuilder;
42 import org.osgi.service.component.annotations.Activate;
43 import org.osgi.service.component.annotations.Component;
44 import org.osgi.service.component.annotations.Reference;
45 import org.slf4j.Logger;
46 import org.slf4j.LoggerFactory;
49 * Calls to listen to Renderer notifications.
51 * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange
54 @Component(service = {RendererNotificationHandler.class, RendererListener.class})
55 public class RendererNotificationHandler implements RendererListener {
57 private static final String PUBLISHER = "RendererListener";
58 private static final Logger LOG = LoggerFactory.getLogger(RendererNotificationHandler.class);
59 private RendererRpcResultSp serviceRpcResultSp;
60 private ServiceDataStoreOperations serviceDataStoreOperations;
61 private ServiceInput input;
62 private PCEServiceWrapper pceServiceWrapper;
63 private Boolean tempService;
64 private NotificationPublishService notificationPublishService;
65 private final NetworkModelService networkModelService;
68 public RendererNotificationHandler(@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;
78 public CompositeListener getCompositeListener() {
79 return new CompositeListener(Set.of(
80 new CompositeListener.Component<>(RendererRpcResultSp.class, this::onRendererRpcResultSp)));
83 private void onRendererRpcResultSp(RendererRpcResultSp notification) {
84 if (compareServiceRpcResultSp(notification)) {
85 LOG.warn("ServiceRpcResultSp already wired !");
88 serviceRpcResultSp = notification;
89 int notifType = serviceRpcResultSp.getNotificationType().getIntValue();
90 LOG.info("Renderer '{}' Notification received : {}", serviceRpcResultSp.getNotificationType().getName(),
93 /* service-implementation-request. */
95 onServiceImplementationResult(notification);
99 onServiceDeleteResult(notification);
107 * Process service delete result for serviceName.
108 * @param notification RendererRpcResultSp
110 private void onServiceDeleteResult(RendererRpcResultSp notification) {
111 switch (serviceRpcResultSp.getStatus()) {
113 updateOtnTopology(notification, true);
116 LOG.error("Renderer service delete failed !");
117 Services service = serviceDataStoreOperations.getService(input.getServiceName()).orElseThrow();
118 sendNbiNotification(new PublishNotificationProcessServiceBuilder()
119 .setServiceName(service.getServiceName())
120 .setServiceAEnd(new ServiceAEndBuilder(service.getServiceAEnd()).build())
121 .setServiceZEnd(new ServiceZEndBuilder(service.getServiceZEnd()).build())
122 .setCommonId(service.getCommonId())
123 .setIsTempService(false)
124 .setConnectionType(service.getConnectionType())
125 .setResponseFailed("Renderer service delete failed !")
126 .setMessage("ServiceDelete request failed ...")
127 .setOperationalState(service.getOperationalState())
128 .setPublisherName(PUBLISHER)
132 LOG.warn("Renderer service delete returned a Pending RpcStatusEx code!");
135 LOG.error("Renderer service delete returned an unknown RpcStatusEx code!");
138 LOG.info("Service '{}' deleted !", notification.getServiceName());
139 if (this.input == null) {
140 LOG.error("ServiceInput parameter is null !");
143 LOG.info("sending PCE cancel resource reserve for '{}'", this.input.getServiceName());
144 this.pceServiceWrapper.cancelPCEResource(this.input.getServiceName(),
145 ServiceNotificationTypes.ServiceDeleteResult);
146 sendServiceHandlerNotification(notification, ServiceNotificationTypes.ServiceDeleteResult);
150 * Process service implementation result for serviceName.
151 * @param notification RendererRpcResultSp
153 private void onServiceImplementationResult(RendererRpcResultSp notification) {
154 switch (serviceRpcResultSp.getStatus()) {
156 onSuccededServiceImplementation(notification);
159 onFailedServiceImplementation(notification.getServiceName());
162 LOG.warn("Service Implementation still pending according to RpcStatusEx");
165 LOG.warn("Service Implementation has an unknown RpcStatusEx code");
171 * Process succeeded service implementation for service.
172 * @param notification RendererRpcResultSp
174 private void onSuccededServiceImplementation(RendererRpcResultSp notification) {
175 LOG.info("Service implemented !");
176 if (serviceDataStoreOperations == null) {
177 LOG.debug("serviceDataStoreOperations is null");
180 updateOtnTopology(notification, false);
181 PublishNotificationProcessServiceBuilder nbiNotificationBuilder =
182 new PublishNotificationProcessServiceBuilder()
183 .setServiceAEnd(new ServiceAEndBuilder(input.getServiceAEnd()).build())
184 .setServiceZEnd(new ServiceZEndBuilder(input.getServiceZEnd()).build())
185 .setPublisherName(PUBLISHER);
186 String serviceTemp = "";
188 nbiNotificationBuilder.setCommonId(input.getCommonId()).setConnectionType(input.getConnectionType());
189 nbiNotificationBuilder.setIsTempService(true);
190 if (input.getServiceName() != null) {
191 nbiNotificationBuilder.setServiceName(input.getServiceName());
193 OperationResult operationResult = this.serviceDataStoreOperations.modifyTempService(
194 serviceRpcResultSp.getServiceName(), State.InService, AdminStates.InService);
195 serviceTemp = "Temp ";
196 if (operationResult.isSuccess()) {
197 ServiceRpcResult serviceRpcResult =
198 sendServiceRpcResultNotification(notification, ServiceNotificationTypes.ServiceCreateResult);
199 sendNbiNotification(nbiNotificationBuilder
200 .setResponseFailed("")
201 .setMessage("Temp Service implemented")
203 new org.opendaylight.yang.gen.v1.nbi.notifications.rev230726.notification.process.service
205 .setFrequency(serviceRpcResult.getPathComputationResult().getAToZ().getFrequency())
206 .setWidth(serviceRpcResult.getPathComputationResult().getAToZ().getWidth())
207 .setOpticalOperationalMode(serviceRpcResult.getPathComputationResult()
208 .getAToZ().getOpticalOperationalMode())
209 // TODO: add GNSR, OSNR, min/max output powers
212 new org.opendaylight.yang.gen.v1.nbi.notifications.rev230726.notification.process.service
214 .setFrequency(serviceRpcResult.getPathComputationResult().getZToA().getFrequency())
215 .setWidth(serviceRpcResult.getPathComputationResult().getZToA().getWidth())
216 .setOpticalOperationalMode(serviceRpcResult.getPathComputationResult()
217 .getZToA().getOpticalOperationalMode())
218 // TODO: add GNSR, OSNR, min/max output powers
220 .setOperationalState(State.InService)
222 LOG.debug("For the Temp service, sending notification on service-result-rpc");
226 // Here the service is implemented and the tempService has to be deleted if present
227 nbiNotificationBuilder.setServiceName(input.getServiceName()).setConnectionType(input.getConnectionType());
228 // Make sure temp-service is false
229 nbiNotificationBuilder.setIsTempService(false);
230 String commonId = input.getCommonId();
231 if (commonId != null) {
232 nbiNotificationBuilder.setCommonId(commonId);
233 if (this.serviceDataStoreOperations.getTempService(commonId).isPresent()) {
234 LOG.info("Temp-service exists with the common-Id {}", commonId);
235 // Delete the common-id from this temp-service-list here
236 OperationResult tempServiceListDelete = serviceDataStoreOperations.deleteTempService(commonId);
237 //TODO: Also need to delete the service-path from the transportpce-service-path list
238 this.serviceDataStoreOperations.deleteServicePath(commonId);
239 LOG.info("Result for temp-service-list with {} is {}", commonId, tempServiceListDelete);
242 OperationResult operationResult = this.serviceDataStoreOperations.modifyService(
243 serviceRpcResultSp.getServiceName(), State.InService, AdminStates.InService);
244 if (operationResult.isSuccess()) {
245 sendNbiNotification(nbiNotificationBuilder
246 .setResponseFailed("")
247 .setMessage("Service implemented !")
248 .setOperationalState(State.InService)
250 sendServiceHandlerNotification(notification, ServiceNotificationTypes.ServiceCreateResult);
254 LOG.warn("{}Service status not updated in datastore !", serviceTemp);
255 sendNbiNotification(nbiNotificationBuilder
256 .setResponseFailed(serviceTemp + "Service status not updated in datastore !")
257 .setMessage("ServiceCreate request failed ...")
258 .setOperationalState(State.OutOfService)
263 * Create and send service handler notification.
264 * @param notification RendererRpcResultSp
265 * @param type ServiceNotificationTypes
267 private void sendServiceHandlerNotification(RendererRpcResultSp notification, ServiceNotificationTypes type) {
269 ServiceRpcResultSh serviceHandlerNotification = new ServiceRpcResultShBuilder()
270 .setAToZDirection(notification.getAToZDirection())
271 .setZToADirection(notification.getZToADirection())
272 .setServiceName(notification.getServiceName())
273 .setStatus(notification.getStatus())
274 .setStatusMessage(notification.getStatusMessage())
275 .setNotificationType(type)
277 LOG.debug("Service update in datastore OK, sending notification {}", serviceHandlerNotification);
278 notificationPublishService.putNotification(serviceHandlerNotification);
279 } catch (InterruptedException e) {
280 LOG.warn("Something went wrong while sending notification for service {}",
281 serviceRpcResultSp.getServiceName(), e);
282 Thread.currentThread().interrupt();
286 private ServiceRpcResult sendServiceRpcResultNotification(
287 RendererRpcResultSp notification, ServiceNotificationTypes type) {
289 ServiceRpcResult serviceRpcResult = new ServiceRpcResultBuilder()
290 .setServiceName(notification.getServiceName())
291 .setNotificationType(type)
292 .setStatusMessage(notification.getStatusMessage())
293 .setCommonId(notification.getCommonId())
294 .setPathComputationResult(new PathComputationResultBuilder()
295 .setAToZ(new AToZBuilder()
296 .setFrequency(notification
298 .getCentralFrequency())
299 .setWidth(notification
302 // TODO: here the optical operational mode should be set
303 // A default value is set here
304 .setOpticalOperationalMode("OR-W-400G-oFEC-63.1Gbd")
305 // TODO: also set the GNSR, OSNR, power values
307 .setZToA(new ZToABuilder()
308 .setFrequency(notification
310 .getCentralFrequency())
311 .setWidth(notification
314 // TODO: here the optical operational mode should be set
315 // A default value is set here
316 .setOpticalOperationalMode("OR-W-400G-oFEC-63.1Gbd")
317 // TODO: also set the GNSR, OSNR, power values
321 LOG.info("Sending the notification for service-rpc-result {}", serviceRpcResult);
322 notificationPublishService.putNotification(serviceRpcResult);
323 return serviceRpcResult;
324 } catch (InterruptedException e) {
325 LOG.warn("Something went wrong while sending notification for service {}",
326 serviceRpcResultSp.getServiceName(), e);
327 Thread.currentThread().interrupt();
335 * Process failed service implementation for serviceName.
336 * @param serviceName String
338 private void onFailedServiceImplementation(String serviceName) {
339 LOG.error("Renderer implementation failed !");
340 Services service = serviceDataStoreOperations.getService(input.getServiceName()).orElseThrow();
341 sendNbiNotification(new PublishNotificationProcessServiceBuilder()
342 .setServiceName(service.getServiceName())
343 .setServiceAEnd(new ServiceAEndBuilder(service.getServiceAEnd()).build())
344 .setServiceZEnd(new ServiceZEndBuilder(service.getServiceZEnd()).build())
345 .setCommonId(service.getCommonId())
346 .setConnectionType(service.getConnectionType())
347 .setIsTempService(false)
348 .setResponseFailed("Renderer implementation failed !")
349 .setMessage("ServiceCreate request failed ...")
350 .setOperationalState(service.getOperationalState())
351 .setPublisherName(PUBLISHER)
353 OperationResult deleteServicePathOperationResult =
354 this.serviceDataStoreOperations.deleteServicePath(serviceName);
355 if (!deleteServicePathOperationResult.isSuccess()) {
356 LOG.warn("Service path was not removed from datastore!");
358 OperationResult deleteServiceOperationResult;
359 String serviceType = "";
361 deleteServiceOperationResult = this.serviceDataStoreOperations.deleteTempService(serviceName);
362 serviceType = "Temp ";
364 deleteServiceOperationResult = this.serviceDataStoreOperations.deleteService(serviceName);
366 if (deleteServiceOperationResult.isSuccess()) {
367 LOG.warn("{}Service was not removed from datastore!", serviceType);
372 value = "ES_COMPARING_STRINGS_WITH_EQ",
373 justification = "false positives, not strings but real object references comparisons")
374 private Boolean compareServiceRpcResultSp(RendererRpcResultSp notification) {
375 if (serviceRpcResultSp == null
376 || serviceRpcResultSp.getNotificationType() != notification.getNotificationType()
377 || serviceRpcResultSp.getServiceName() != notification.getServiceName()
378 || serviceRpcResultSp.getStatus() != notification.getStatus()
379 || serviceRpcResultSp.getStatusMessage() != notification.getStatusMessage()) {
386 public void setServiceInput(ServiceInput serviceInput) {
387 this.input = serviceInput;
391 public void setserviceDataStoreOperations(ServiceDataStoreOperations serviceData) {
392 this.serviceDataStoreOperations = serviceData;
396 public void setTempService(Boolean tempService) {
397 this.tempService = tempService;
401 * Send notification to NBI notification in order to publish message.
402 * @param service PublishNotificationService
404 private void sendNbiNotification(PublishNotificationProcessService service) {
406 notificationPublishService.putNotification(service);
407 } catch (InterruptedException e) {
408 LOG.warn("Cannot send notification to nbi", e);
409 Thread.currentThread().interrupt();
414 private void updateOtnTopology(RendererRpcResultSp notification, boolean isDeletion) {
415 Link link = notification.getLink();
416 if (link == null && notification.getLinkId() == null) {
419 List<String> supportedLinkIds = null;
420 if (notification.getLinkId() != null) {
421 supportedLinkIds = new ArrayList<>(notification.getLinkId());
423 String serviceType = notification.getServiceType();
424 switch (serviceType) {
425 case StringConstants.SERVICE_TYPE_OTU4:
426 case StringConstants.SERVICE_TYPE_OTUC2:
427 case StringConstants.SERVICE_TYPE_OTUC3:
428 case StringConstants.SERVICE_TYPE_OTUC4:
429 case StringConstants.SERVICE_TYPE_ODU4:
430 case StringConstants.SERVICE_TYPE_ODUC2:
431 case StringConstants.SERVICE_TYPE_ODUC3:
432 case StringConstants.SERVICE_TYPE_ODUC4:
433 Map<String, OtnLinkType> otnLinkTypeMap = Map.of(
434 StringConstants.SERVICE_TYPE_OTU4, OtnLinkType.OTU4,
435 // TODO: need to change it when OtnLinkType is updated with enum
436 StringConstants.SERVICE_TYPE_OTUC2, OtnLinkType.OTUC4,
437 StringConstants.SERVICE_TYPE_OTUC3, OtnLinkType.OTUC4,
438 StringConstants.SERVICE_TYPE_OTUC4, OtnLinkType.OTUC4,
439 StringConstants.SERVICE_TYPE_ODU4, OtnLinkType.ODTU4,
440 // TODO: need to change it when OtnLinkType is updated with enum
441 StringConstants.SERVICE_TYPE_ODUC2, OtnLinkType.ODUC4,
442 StringConstants.SERVICE_TYPE_ODUC3, OtnLinkType.ODUC4,
443 StringConstants.SERVICE_TYPE_ODUC4, OtnLinkType.ODUC4);
445 LOG.info("updating otn-topology removing links");
446 this.networkModelService.deleteOtnLinks(link, supportedLinkIds, otnLinkTypeMap.get(serviceType));
448 LOG.info("updating otn-topology adding links");
449 this.networkModelService.createOtnLinks(link, supportedLinkIds, otnLinkTypeMap.get(serviceType));
452 case StringConstants.SERVICE_TYPE_1GE:
453 case StringConstants.SERVICE_TYPE_10GE:
454 case StringConstants.SERVICE_TYPE_100GE_M:
455 Short tribPort = Short.valueOf(notification.getAToZDirection().getMinTribSlot().getValue()
457 Short minTribSlot = Short.valueOf(notification.getAToZDirection().getMinTribSlot().getValue()
459 Short maxTribSlot = Short.valueOf(notification.getAToZDirection().getMaxTribSlot().getValue()
461 LOG.info("updating otn-topology node tps -tps and tpn pools");
462 this.networkModelService.updateOtnLinks(link, supportedLinkIds,
463 notification.getAToZDirection().getRate(), tribPort, minTribSlot, maxTribSlot, isDeletion);
465 case StringConstants.SERVICE_TYPE_100GE_S:
466 this.networkModelService.updateOtnLinks(supportedLinkIds, isDeletion);
469 LOG.warn("service-type {} not managed yet", serviceType);