2 * Copyright © 2020 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
9 package org.opendaylight.transportpce.networkmodel.listeners;
12 import org.opendaylight.mdsal.binding.api.NotificationService.CompositeListener;
13 import org.opendaylight.transportpce.networkmodel.service.FrequenciesService;
14 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev201125.ServiceRpcResultSh;
15 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.ServiceNotificationTypes;
16 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.RpcStatusEx;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
20 public class ServiceHandlerListener {
21 private static final Logger LOG = LoggerFactory.getLogger(ServiceHandlerListener.class);
22 private final FrequenciesService service;
25 public ServiceHandlerListener(FrequenciesService service) {
26 LOG.info("Init service handler listener for network");
27 this.service = service;
30 public CompositeListener getCompositeListener() {
31 return new CompositeListener(Set.of(
32 new CompositeListener.Component<>(ServiceRpcResultSh.class, this::onServiceRpcResultSh)));
35 public void onServiceRpcResultSh(ServiceRpcResultSh notification) {
36 if (notification.getStatus() != RpcStatusEx.Successful) {
37 LOG.info("RpcStatusEx of notification not equals successful. Nothing to do for notification {}",
41 ServiceNotificationTypes notificationType = notification.getNotificationType();
42 if (notificationType == null) {
43 LOG.warn("No information about the type of the notification for {}", notification);
46 switch (notificationType) {
47 case ServiceCreateResult:
48 case ServiceReconfigureResult:
49 case ServiceRestorationResult:
50 LOG.info("Service creation or reconfiguration or restoration notification received {}", notification);
51 onServiceCreation(notification);
53 case ServiceDeleteResult:
54 LOG.info("Service delete notification received {}", notification);
55 onServiceDeletion(notification);
58 LOG.warn("This type of notification is not managed at this time {} for notification {}",
59 notificationType, notification);
66 * Allocate frequencies in topology.
67 * @param notification ServiceRpcResultSh
69 private void onServiceCreation(ServiceRpcResultSh notification) {
70 if (notification.getAToZDirection() != null || notification.getZToADirection() != null) {
71 LOG.info("Update topology with used frequency by service {}", notification.getServiceName());
72 service.allocateFrequencies(notification.getAToZDirection(), notification.getZToADirection());
77 * Release frequencies in topology.
78 * @param notification ServiceRpcResultSh
80 private void onServiceDeletion(ServiceRpcResultSh notification) {
81 if (notification.getAToZDirection() != null || notification.getZToADirection() != null) {
82 LOG.info("Update topology with no more used frequency by deleted service {}",
83 notification.getServiceName());
84 service.releaseFrequencies(notification.getAToZDirection(), notification.getZToADirection());