2 * Copyright © 2021 Orange 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 java.util.ArrayList;
12 import java.util.HashMap;
13 import java.util.List;
16 import org.opendaylight.mdsal.binding.api.NotificationService.CompositeListener;
17 import org.opendaylight.transportpce.common.mapping.PortMapping;
18 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev240315.mapping.Mapping;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.ChangeNotification;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.CreateTechInfoNotification;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.OtdrScanResult;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.change.notification.Edit;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.circuit.pack.Ports;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.circuit.packs.CircuitPacks;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.org.openroadm.device.container.org.openroadm.device.OduSwitchingPools;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.org.openroadm.device.container.org.openroadm.device.odu.switching.pools.NonBlockingList;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.org.openroadm.device.container.org.openroadm.device.odu.switching.pools.non.blocking.list.PortList;
28 import org.opendaylight.yangtools.binding.DataObject;
29 import org.opendaylight.yangtools.binding.DataObjectStep;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
31 import org.opendaylight.yangtools.yang.common.Uint16;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
35 public class DeviceListener710 {
37 private static final Logger LOG = LoggerFactory.getLogger(DeviceListener710.class);
38 private final String nodeId;
39 private final PortMapping portMapping;
41 public DeviceListener710(String nodeId, PortMapping portMapping) {
44 this.portMapping = portMapping;
47 public CompositeListener getCompositeListener() {
48 return new CompositeListener(Set.of(
49 new CompositeListener.Component<>(ChangeNotification.class, this::onChangeNotification),
50 new CompositeListener.Component<>(CreateTechInfoNotification.class, this::onCreateTechInfoNotification),
51 new CompositeListener.Component<>(OtdrScanResult.class, this::onOtdrScanResult)
56 * Callback for change-notification.
59 * ChangeNotification object
61 void onChangeNotification(ChangeNotification notification) {
62 LOG.debug("device71 notification received = {}", notification);
63 if (notification.getEdit() == null) {
64 LOG.warn("unable to handle {} notificatin received - list of edit is null", ChangeNotification.QNAME);
67 Map<Uint16, List<InstanceIdentifier<PortList>>> nbliidMap = new HashMap<>();
68 InstanceIdentifier<OduSwitchingPools> ospIID = null;
69 for (Edit edit : notification.getEdit()) {
70 if (edit.getTarget() == null) {
73 // 1. Detect the org-openroadm-device object modified
74 InstanceIdentifier<DataObject> path = InstanceIdentifier.unsafeOf(
75 (List<? extends DataObjectStep<?>>) edit.getTarget().steps());
76 LOG.debug("Instance Identifier received = {} from node {}", path.toString(), nodeId);
77 switch (path.lastStep().type().getSimpleName()) {
79 String portName = path.firstKeyOf(Ports.class).getPortName();
80 String cpName = path.firstKeyOf(CircuitPacks.class).getCircuitPackName();
81 LOG.info("port {} of circruit-pack {} modified on device {}", portName, cpName, this.nodeId);
82 Mapping oldMapping = portMapping.getMapping(nodeId, cpName, portName);
83 if (oldMapping == null) {
86 Runnable handleNetconfEvent = new Runnable() {
89 portMapping.updateMapping(nodeId, oldMapping);
90 LOG.info("{} : mapping data for {} updated", nodeId,
91 oldMapping.getLogicalConnectionPoint());
94 Thread thread = new Thread(handleNetconfEvent);
97 case "OduSwitchingPools":
98 LOG.info("odu-switching-pools modified on device {}", nodeId);
99 ospIID = path.firstIdentifierOf(OduSwitchingPools.class);
102 InstanceIdentifier<PortList> plIID = path.firstIdentifierOf(PortList.class);
103 Uint16 nblNb = path.firstKeyOf(NonBlockingList.class).getNblNumber();
104 List<InstanceIdentifier<PortList>> iidList = nbliidMap.containsKey(nblNb)
105 ? nbliidMap.get(nblNb) : new ArrayList<>();
107 nbliidMap.put(nblNb, iidList);
110 LOG.debug("modification of type {} not managed yet", edit.getTarget().getClass());
114 if (!nbliidMap.isEmpty() && ospIID != null) {
115 InstanceIdentifier<OduSwitchingPools> id = ospIID;
116 Runnable handleNetconfEvent = new Runnable() {
119 portMapping.updatePortMappingWithOduSwitchingPools(nodeId, id, nbliidMap);
120 LOG.info("{} : swiching-pool data updated", nodeId);
123 Thread thread = new Thread(handleNetconfEvent);
128 private void onCreateTechInfoNotification(CreateTechInfoNotification notification) {
132 * Callback for otdr-scan-result.
134 * @param notification
135 * OtdrScanResult object
137 private void onOtdrScanResult(OtdrScanResult notification) {
138 LOG.info("Notification {} received {}", OtdrScanResult.QNAME, notification);