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 LOG.info("Result for temp-service-list with {} is {}", commonId, tempServiceListDelete);
212 if (operationResult.isSuccess()) {
213 sendNbiNotification(nbiNotificationBuilder
214 .setResponseFailed("")
215 .setMessage("Service implemented !")
216 .setOperationalState(State.InService)
218 sendServiceHandlerNotification(notification, ServiceNotificationTypes.ServiceCreateResult);
222 LOG.warn("{}Service status not updated in datastore !", serviceTemp);
223 sendNbiNotification(nbiNotificationBuilder
224 .setResponseFailed(serviceTemp + "Service status not updated in datastore !")
225 .setMessage("ServiceCreate request failed ...")
226 .setOperationalState(State.OutOfService)
231 * Create and send service handler notification.
232 * @param notification RendererRpcResultSp
233 * @param type ServiceNotificationTypes
235 private void sendServiceHandlerNotification(RendererRpcResultSp notification, ServiceNotificationTypes type) {
237 ServiceRpcResultSh serviceHandlerNotification = new ServiceRpcResultShBuilder()
238 .setAToZDirection(notification.getAToZDirection())
239 .setZToADirection(notification.getZToADirection())
240 .setServiceName(notification.getServiceName())
241 .setStatus(notification.getStatus())
242 .setStatusMessage(notification.getStatusMessage())
243 .setNotificationType(type)
245 LOG.debug("Service update in datastore OK, sending notification {}", serviceHandlerNotification);
246 notificationPublishService.putNotification(
247 serviceHandlerNotification);
248 } catch (InterruptedException e) {
249 LOG.warn("Something went wrong while sending notification for service {}",
250 serviceRpcResultSp.getServiceName(), e);
251 Thread.currentThread().interrupt();
255 private void sendServiceRpcResultNotification(RendererRpcResultSp notification, ServiceNotificationTypes type) {
257 ServiceRpcResult serviceRpcResult = new ServiceRpcResultBuilder()
258 .setServiceName(notification.getServiceName())
259 .setNotificationType(type)
260 .setStatusMessage(notification.getStatusMessage())
261 .setCommonId(notification.getCommonId())
262 .setPathComputationResult(new PathComputationResultBuilder()
263 .setAToZ(new AToZBuilder()
264 .setFrequency(notification
266 .getCentralFrequency())
267 .setWidth(notification
270 // TODO: here the optical operational mode should be set
271 // TODO: also set the GNSR, OSNR, power values
272 .setOpticalOperationalMode("test")
274 .setZToA(new ZToABuilder()
275 .setFrequency(notification
277 .getCentralFrequency())
278 .setWidth(notification
281 // TODO: here the optical operational mode should be set
282 // TODO: also set the GNSR, OSNR, power values
283 .setOpticalOperationalMode("test")
287 LOG.info("Sending the notification for service-rpc-result {}", serviceRpcResult);
288 notificationPublishService.putNotification(
290 } catch (InterruptedException e) {
291 LOG.warn("Something went wrong while sending notification for service {}",
292 serviceRpcResultSp.getServiceName(), e);
293 Thread.currentThread().interrupt();
300 * Process failed service implementation for serviceName.
301 * @param serviceName String
303 private void onFailedServiceImplementation(String serviceName) {
304 LOG.error("Renderer implementation failed !");
305 Services service = serviceDataStoreOperations.getService(input.getServiceName()).orElseThrow();
306 sendNbiNotification(new PublishNotificationProcessServiceBuilder()
307 .setServiceName(service.getServiceName())
308 .setServiceAEnd(new ServiceAEndBuilder(service.getServiceAEnd()).build())
309 .setServiceZEnd(new ServiceZEndBuilder(service.getServiceZEnd()).build())
310 .setCommonId(service.getCommonId())
311 .setConnectionType(service.getConnectionType())
312 .setResponseFailed("Renderer implementation failed !")
313 .setMessage("ServiceCreate request failed ...")
314 .setOperationalState(service.getOperationalState())
315 .setPublisherName(PUBLISHER)
317 OperationResult deleteServicePathOperationResult =
318 this.serviceDataStoreOperations.deleteServicePath(serviceName);
319 if (!deleteServicePathOperationResult.isSuccess()) {
320 LOG.warn("Service path was not removed from datastore!");
322 OperationResult deleteServiceOperationResult;
323 String serviceType = "";
325 deleteServiceOperationResult = this.serviceDataStoreOperations.deleteTempService(serviceName);
326 serviceType = "Temp ";
328 deleteServiceOperationResult = this.serviceDataStoreOperations.deleteService(serviceName);
330 if (deleteServiceOperationResult.isSuccess()) {
331 LOG.warn("{}Service was not removed from datastore!", serviceType);
336 value = "ES_COMPARING_STRINGS_WITH_EQ",
337 justification = "false positives, not strings but real object references comparisons")
338 private Boolean compareServiceRpcResultSp(RendererRpcResultSp notification) {
339 if (serviceRpcResultSp == null
340 || serviceRpcResultSp.getNotificationType() != notification.getNotificationType()
341 || serviceRpcResultSp.getServiceName() != notification.getServiceName()
342 || serviceRpcResultSp.getStatus() != notification.getStatus()
343 || serviceRpcResultSp.getStatusMessage() != notification.getStatusMessage()) {
350 public void setServiceInput(ServiceInput serviceInput) {
351 this.input = serviceInput;
355 public void setserviceDataStoreOperations(ServiceDataStoreOperations serviceData) {
356 this.serviceDataStoreOperations = serviceData;
360 public void setTempService(Boolean tempService) {
361 this.tempService = tempService;
365 * Send notification to NBI notification in order to publish message.
366 * @param service PublishNotificationService
368 private void sendNbiNotification(PublishNotificationProcessService service) {
370 notificationPublishService.putNotification(service);
371 } catch (InterruptedException e) {
372 LOG.warn("Cannot send notification to nbi", e);
373 Thread.currentThread().interrupt();
378 private void updateOtnTopology(RendererRpcResultSp notification, boolean isDeletion) {
379 Link link = notification.getLink();
380 if (link == null && notification.getLinkId() == null) {
383 List<String> supportedLinkIds = null;
384 if (notification.getLinkId() != null) {
385 supportedLinkIds = new ArrayList<>(notification.getLinkId());
387 String serviceType = notification.getServiceType();
388 switch (serviceType) {
389 case StringConstants.SERVICE_TYPE_OTU4:
390 case StringConstants.SERVICE_TYPE_OTUC2:
391 case StringConstants.SERVICE_TYPE_OTUC3:
392 case StringConstants.SERVICE_TYPE_OTUC4:
393 case StringConstants.SERVICE_TYPE_ODU4:
394 case StringConstants.SERVICE_TYPE_ODUC2:
395 case StringConstants.SERVICE_TYPE_ODUC3:
396 case StringConstants.SERVICE_TYPE_ODUC4:
397 Map<String, OtnLinkType> otnLinkTypeMap = Map.of(
398 StringConstants.SERVICE_TYPE_OTU4, OtnLinkType.OTU4,
399 // TODO: need to change it when OtnLinkType is updated with enum
400 StringConstants.SERVICE_TYPE_OTUC2, OtnLinkType.OTUC4,
401 StringConstants.SERVICE_TYPE_OTUC3, OtnLinkType.OTUC4,
402 StringConstants.SERVICE_TYPE_OTUC4, OtnLinkType.OTUC4,
403 StringConstants.SERVICE_TYPE_ODU4, OtnLinkType.ODTU4,
404 // TODO: need to change it when OtnLinkType is updated with enum
405 StringConstants.SERVICE_TYPE_ODUC2, OtnLinkType.ODUC4,
406 StringConstants.SERVICE_TYPE_ODUC3, OtnLinkType.ODUC4,
407 StringConstants.SERVICE_TYPE_ODUC4, OtnLinkType.ODUC4);
409 LOG.info("updating otn-topology removing links");
410 this.networkModelService.deleteOtnLinks(link, supportedLinkIds, otnLinkTypeMap.get(serviceType));
412 LOG.info("updating otn-topology adding links");
413 this.networkModelService.createOtnLinks(link, supportedLinkIds, otnLinkTypeMap.get(serviceType));
416 case StringConstants.SERVICE_TYPE_1GE:
417 case StringConstants.SERVICE_TYPE_10GE:
418 case StringConstants.SERVICE_TYPE_100GE_M:
419 Short tribPort = Short.valueOf(notification.getAToZDirection().getMinTribSlot().getValue()
421 Short minTribSlot = Short.valueOf(notification.getAToZDirection().getMinTribSlot().getValue()
423 Short maxTribSlot = Short.valueOf(notification.getAToZDirection().getMaxTribSlot().getValue()
425 LOG.info("updating otn-topology node tps -tps and tpn pools");
426 this.networkModelService.updateOtnLinks(link, supportedLinkIds,
427 notification.getAToZDirection().getRate(), tribPort, minTribSlot, maxTribSlot, isDeletion);
429 case StringConstants.SERVICE_TYPE_100GE_S:
430 this.networkModelService.updateOtnLinks(supportedLinkIds, isDeletion);
433 LOG.warn("service-type {} not managed yet", serviceType);