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;
11 import org.opendaylight.transportpce.networkmodel.service.NetworkModelWavelengthService;
12 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev201125.ServiceRpcResultSh;
13 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev201125.TransportpceServicehandlerListener;
14 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.ServiceNotificationTypes;
15 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev200128.RpcStatusEx;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
19 public class ServiceHandlerListener implements TransportpceServicehandlerListener {
20 private static final Logger LOG = LoggerFactory.getLogger(ServiceHandlerListener.class);
21 private final NetworkModelWavelengthService service;
23 public ServiceHandlerListener(NetworkModelWavelengthService service) {
24 LOG.info("Init service handler listener for network");
25 this.service = service;
29 public void onServiceRpcResultSh(ServiceRpcResultSh notification) {
30 if (notification.getStatus() != RpcStatusEx.Successful) {
31 LOG.info("RpcStatusEx of notification not equals successful. Nothing to do for notification {}",
35 ServiceNotificationTypes notificationType = notification.getNotificationType();
36 if (notificationType == null) {
37 LOG.warn("No information about the type of the notification for {}", notification);
40 switch (notificationType) {
41 case ServiceCreateResult:
42 case ServiceReconfigureResult:
43 case ServiceRestorationResult:
44 LOG.info("Service creation or reconfiguration or restoration notification received {}", notification);
45 onServiceCreation(notification);
47 case ServiceDeleteResult:
48 LOG.info("Service delete notification received {}", notification);
49 onServiceDeletion(notification);
52 LOG.warn("This type of notification is not managed at this time {} for notification {}",
53 notificationType, notification);
60 * Allocate wavelength in topology.
61 * @param notification ServiceRpcResultSh
63 private void onServiceCreation(ServiceRpcResultSh notification) {
64 if (notification.getAToZDirection() != null || notification.getZToADirection() != null) {
65 LOG.info("Update topology with used frequency by service {}", notification.getServiceName());
66 service.allocateFrequencies(notification.getAToZDirection(), notification.getZToADirection());
71 * Release wavelength in topology.
72 * @param notification ServiceRpcResultSh
74 private void onServiceDeletion(ServiceRpcResultSh notification) {
75 if (notification.getAToZDirection() != null || notification.getZToADirection() != null) {
76 LOG.info("Update topology with no more used frequency by deleted service {}",
77 notification.getServiceName());
78 service.releaseFrequencies(notification.getAToZDirection(), notification.getZToADirection());