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.rev211210.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.rev211210.ServiceRpcResult;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceRpcResultBuilder;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.service.list.Services;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.service.rpc.result.PathComputationResultBuilder;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.service.rpc.result.path.computation.result.AToZBuilder;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.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 if (operationResult.isSuccess()) {
202 sendNbiNotification(nbiNotificationBuilder
203 .setResponseFailed("")
204 .setMessage("Service implemented !")
205 .setOperationalState(State.InService)
207 sendServiceHandlerNotification(notification, ServiceNotificationTypes.ServiceCreateResult);
211 LOG.warn("{}Service status not updated in datastore !", serviceTemp);
212 sendNbiNotification(nbiNotificationBuilder
213 .setResponseFailed(serviceTemp + "Service status not updated in datastore !")
214 .setMessage("ServiceCreate request failed ...")
215 .setOperationalState(State.OutOfService)
220 * Create and send service handler notification.
221 * @param notification RendererRpcResultSp
222 * @param type ServiceNotificationTypes
224 private void sendServiceHandlerNotification(RendererRpcResultSp notification, ServiceNotificationTypes type) {
226 ServiceRpcResultSh serviceHandlerNotification = new ServiceRpcResultShBuilder()
227 .setAToZDirection(notification.getAToZDirection())
228 .setZToADirection(notification.getZToADirection())
229 .setServiceName(notification.getServiceName())
230 .setStatus(notification.getStatus())
231 .setStatusMessage(notification.getStatusMessage())
232 .setNotificationType(type)
234 LOG.debug("Service update in datastore OK, sending notification {}", serviceHandlerNotification);
235 notificationPublishService.putNotification(
236 serviceHandlerNotification);
237 } catch (InterruptedException e) {
238 LOG.warn("Something went wrong while sending notification for service {}",
239 serviceRpcResultSp.getServiceName(), e);
240 Thread.currentThread().interrupt();
244 private void sendServiceRpcResultNotification(RendererRpcResultSp notification, ServiceNotificationTypes type) {
246 ServiceRpcResult serviceRpcResult = new ServiceRpcResultBuilder()
247 .setServiceName(notification.getServiceName())
248 .setNotificationType(type)
249 .setStatusMessage(notification.getStatusMessage())
250 .setCommonId(notification.getCommonId())
251 .setPathComputationResult(new PathComputationResultBuilder()
252 .setAToZ(new AToZBuilder()
253 .setFrequency(notification
255 .getCentralFrequency())
256 .setWidth(notification
259 // TODO: here the optical operational mode should be set
260 // TODO: also set the GNSR, OSNR, power values
261 .setOpticalOperationalMode("test")
263 .setZToA(new ZToABuilder()
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")
276 LOG.info("Sending the notification for service-rpc-result {}", serviceRpcResult);
277 notificationPublishService.putNotification(
279 } catch (InterruptedException e) {
280 LOG.warn("Something went wrong while sending notification for service {}",
281 serviceRpcResultSp.getServiceName(), e);
282 Thread.currentThread().interrupt();
289 * Process failed service implementation for serviceName.
290 * @param serviceName String
292 private void onFailedServiceImplementation(String serviceName) {
293 LOG.error("Renderer implementation failed !");
294 Services service = serviceDataStoreOperations.getService(input.getServiceName()).orElseThrow();
295 sendNbiNotification(new PublishNotificationProcessServiceBuilder()
296 .setServiceName(service.getServiceName())
297 .setServiceAEnd(new ServiceAEndBuilder(service.getServiceAEnd()).build())
298 .setServiceZEnd(new ServiceZEndBuilder(service.getServiceZEnd()).build())
299 .setCommonId(service.getCommonId())
300 .setConnectionType(service.getConnectionType())
301 .setResponseFailed("Renderer implementation failed !")
302 .setMessage("ServiceCreate request failed ...")
303 .setOperationalState(service.getOperationalState())
304 .setPublisherName(PUBLISHER)
306 OperationResult deleteServicePathOperationResult =
307 this.serviceDataStoreOperations.deleteServicePath(serviceName);
308 if (!deleteServicePathOperationResult.isSuccess()) {
309 LOG.warn("Service path was not removed from datastore!");
311 OperationResult deleteServiceOperationResult;
312 String serviceType = "";
314 deleteServiceOperationResult = this.serviceDataStoreOperations.deleteTempService(serviceName);
315 serviceType = "Temp ";
317 deleteServiceOperationResult = this.serviceDataStoreOperations.deleteService(serviceName);
319 if (deleteServiceOperationResult.isSuccess()) {
320 LOG.warn("{}Service was not removed from datastore!", serviceType);
325 value = "ES_COMPARING_STRINGS_WITH_EQ",
326 justification = "false positives, not strings but real object references comparisons")
327 private Boolean compareServiceRpcResultSp(RendererRpcResultSp notification) {
328 if (serviceRpcResultSp == null
329 || serviceRpcResultSp.getNotificationType() != notification.getNotificationType()
330 || serviceRpcResultSp.getServiceName() != notification.getServiceName()
331 || serviceRpcResultSp.getStatus() != notification.getStatus()
332 || serviceRpcResultSp.getStatusMessage() != notification.getStatusMessage()) {
339 public void setServiceInput(ServiceInput serviceInput) {
340 this.input = serviceInput;
344 public void setserviceDataStoreOperations(ServiceDataStoreOperations serviceData) {
345 this.serviceDataStoreOperations = serviceData;
349 public void setTempService(Boolean tempService) {
350 this.tempService = tempService;
354 * Send notification to NBI notification in order to publish message.
355 * @param service PublishNotificationService
357 private void sendNbiNotification(PublishNotificationProcessService service) {
359 notificationPublishService.putNotification(service);
360 } catch (InterruptedException e) {
361 LOG.warn("Cannot send notification to nbi", e);
362 Thread.currentThread().interrupt();
367 private void updateOtnTopology(RendererRpcResultSp notification, boolean isDeletion) {
368 Link link = notification.getLink();
369 if (link == null && notification.getLinkId() == null) {
372 List<String> supportedLinkIds = null;
373 if (notification.getLinkId() != null) {
374 supportedLinkIds = new ArrayList<>(notification.getLinkId());
376 String serviceType = notification.getServiceType();
377 switch (serviceType) {
378 case StringConstants.SERVICE_TYPE_OTU4:
379 case StringConstants.SERVICE_TYPE_OTUC2:
380 case StringConstants.SERVICE_TYPE_OTUC3:
381 case StringConstants.SERVICE_TYPE_OTUC4:
382 case StringConstants.SERVICE_TYPE_ODU4:
383 case StringConstants.SERVICE_TYPE_ODUC2:
384 case StringConstants.SERVICE_TYPE_ODUC3:
385 case StringConstants.SERVICE_TYPE_ODUC4:
386 Map<String, OtnLinkType> otnLinkTypeMap = Map.of(
387 StringConstants.SERVICE_TYPE_OTU4, OtnLinkType.OTU4,
388 // TODO: need to change it when OtnLinkType is updated with enum
389 StringConstants.SERVICE_TYPE_OTUC2, OtnLinkType.OTUC4,
390 StringConstants.SERVICE_TYPE_OTUC3, OtnLinkType.OTUC4,
391 StringConstants.SERVICE_TYPE_OTUC4, OtnLinkType.OTUC4,
392 StringConstants.SERVICE_TYPE_ODU4, OtnLinkType.ODTU4,
393 // TODO: need to change it when OtnLinkType is updated with enum
394 StringConstants.SERVICE_TYPE_ODUC2, OtnLinkType.ODUC4,
395 StringConstants.SERVICE_TYPE_ODUC3, OtnLinkType.ODUC4,
396 StringConstants.SERVICE_TYPE_ODUC4, OtnLinkType.ODUC4);
398 LOG.info("updating otn-topology removing links");
399 this.networkModelService.deleteOtnLinks(link, supportedLinkIds, otnLinkTypeMap.get(serviceType));
401 LOG.info("updating otn-topology adding links");
402 this.networkModelService.createOtnLinks(link, supportedLinkIds, otnLinkTypeMap.get(serviceType));
405 case StringConstants.SERVICE_TYPE_1GE:
406 case StringConstants.SERVICE_TYPE_10GE:
407 case StringConstants.SERVICE_TYPE_100GE_M:
408 Short tribPort = Short.valueOf(notification.getAToZDirection().getMinTribSlot().getValue()
410 Short minTribSlot = Short.valueOf(notification.getAToZDirection().getMinTribSlot().getValue()
412 Short maxTribSlot = Short.valueOf(notification.getAToZDirection().getMaxTribSlot().getValue()
414 LOG.info("updating otn-topology node tps -tps and tpn pools");
415 this.networkModelService.updateOtnLinks(link, supportedLinkIds,
416 notification.getAToZDirection().getRate(), tribPort, minTribSlot, maxTribSlot, isDeletion);
418 case StringConstants.SERVICE_TYPE_100GE_S:
419 this.networkModelService.updateOtnLinks(supportedLinkIds, isDeletion);
422 LOG.warn("service-type {} not managed yet", serviceType);