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.LinkedList;
14 import java.util.List;
17 import org.opendaylight.mdsal.binding.api.NotificationService.CompositeListener;
18 import org.opendaylight.transportpce.common.mapping.PortMapping;
19 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev231221.mapping.Mapping;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.ChangeNotification;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.CreateTechInfoNotification;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.OtdrScanResult;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.change.notification.Edit;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.circuit.pack.Ports;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.circuit.packs.CircuitPacks;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.org.openroadm.device.container.org.openroadm.device.OduSwitchingPools;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.org.openroadm.device.container.org.openroadm.device.odu.switching.pools.NonBlockingList;
28 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;
29 import org.opendaylight.yangtools.yang.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 LinkedList<DataObjectStep<?>> path = new LinkedList<>();
75 switch (edit.getTarget().getTargetType().getSimpleName()) {
77 edit.getTarget().getPathArguments().forEach(p -> path.add(p));
78 InstanceIdentifier<Ports> portIID = InstanceIdentifier.unsafeOf(path);
79 String portName = InstanceIdentifier.keyOf(portIID).getPortName();
81 InstanceIdentifier<CircuitPacks> cpIID = InstanceIdentifier.unsafeOf(path);
82 String cpName = InstanceIdentifier.keyOf(cpIID).getCircuitPackName();
83 LOG.info("port {} of circruit-pack {} modified on device {}", portName, cpName, this.nodeId);
84 Mapping oldMapping = portMapping.getMapping(nodeId, cpName, portName);
85 if (oldMapping == null) {
88 Runnable handleNetconfEvent = new Runnable() {
91 portMapping.updateMapping(nodeId, oldMapping);
92 LOG.info("{} : mapping data for {} updated", nodeId,
93 oldMapping.getLogicalConnectionPoint());
96 Thread thread = new Thread(handleNetconfEvent);
99 case "OduSwitchingPools":
100 LOG.info("odu-switching-pools modified on device {}", nodeId);
101 edit.getTarget().getPathArguments().forEach(p -> path.add(p));
102 ospIID = InstanceIdentifier.unsafeOf(path);
105 edit.getTarget().getPathArguments().forEach(p -> path.add(p));
106 InstanceIdentifier<PortList> plIID = InstanceIdentifier.unsafeOf(path);
108 InstanceIdentifier<NonBlockingList> nblIID = InstanceIdentifier.unsafeOf(path);
109 Uint16 nblNb = InstanceIdentifier.keyOf(nblIID).getNblNumber();
110 List<InstanceIdentifier<PortList>> iidList = nbliidMap.containsKey(nblNb)
111 ? nbliidMap.get(nblNb) : new ArrayList<>();
113 nbliidMap.put(nblNb, iidList);
116 LOG.debug("modification of type {} not managed yet", edit.getTarget().getTargetType());
120 if (!nbliidMap.isEmpty() && ospIID != null) {
121 InstanceIdentifier<OduSwitchingPools> id = ospIID;
122 Runnable handleNetconfEvent = new Runnable() {
125 portMapping.updatePortMappingWithOduSwitchingPools(nodeId, id, nbliidMap);
126 LOG.info("{} : swiching-pool data updated", nodeId);
129 Thread thread = new Thread(handleNetconfEvent);
134 private void onCreateTechInfoNotification(CreateTechInfoNotification notification) {
138 * Callback for otdr-scan-result.
140 * @param notification
141 * OtdrScanResult object
143 private void onOtdrScanResult(OtdrScanResult notification) {
144 LOG.info("Notification {} received {}", OtdrScanResult.QNAME, notification);