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;
16 import org.opendaylight.transportpce.common.mapping.PortMapping;
17 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.mapping.Mapping;
18 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.ChangeNotification;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.CreateTechInfoNotification;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.OrgOpenroadmDeviceListener;
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.yang.binding.InstanceIdentifier;
29 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
30 import org.opendaylight.yangtools.yang.common.Uint16;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
34 public class DeviceListener710 implements OrgOpenroadmDeviceListener {
36 private static final Logger LOG = LoggerFactory.getLogger(DeviceListener710.class);
37 private final String nodeId;
38 private final PortMapping portMapping;
40 public DeviceListener710(String nodeId, PortMapping portMapping) {
43 this.portMapping = portMapping;
47 * Callback for change-notification.
50 * ChangeNotification object
53 public void onChangeNotification(ChangeNotification notification) {
54 LOG.debug("device71 notification received = {}", notification);
55 if (notification.getEdit() == null) {
56 LOG.warn("unable to handle {} notificatin received - list of edit is null", ChangeNotification.QNAME);
59 Map<Uint16, List<InstanceIdentifier<PortList>>> nbliidMap = new HashMap<>();
60 InstanceIdentifier<OduSwitchingPools> ospIID = null;
61 for (Edit edit : notification.getEdit()) {
62 if (edit.getTarget() == null) {
65 // 1. Detect the org-openroadm-device object modified
66 LinkedList<PathArgument> path = new LinkedList<>();
67 switch (edit.getTarget().getTargetType().getSimpleName()) {
69 edit.getTarget().getPathArguments().forEach(p -> path.add(p));
70 InstanceIdentifier<Ports> portIID = InstanceIdentifier.unsafeOf(path);
71 String portName = InstanceIdentifier.keyOf(portIID).getPortName();
73 InstanceIdentifier<CircuitPacks> cpIID = InstanceIdentifier.unsafeOf(path);
74 String cpName = InstanceIdentifier.keyOf(cpIID).getCircuitPackName();
75 LOG.info("port {} of circruit-pack {} modified on device {}", portName, cpName, this.nodeId);
76 Mapping oldMapping = portMapping.getMapping(nodeId, cpName, portName);
77 if (oldMapping == null) {
80 Runnable handleNetconfEvent = new Runnable() {
83 portMapping.updateMapping(nodeId, oldMapping);
84 LOG.info("{} : mapping data for {} updated", nodeId,
85 oldMapping.getLogicalConnectionPoint());
88 Thread thread = new Thread(handleNetconfEvent);
91 case "OduSwitchingPools":
92 LOG.info("odu-switching-pools modified on device {}", nodeId);
93 edit.getTarget().getPathArguments().forEach(p -> path.add(p));
94 ospIID = InstanceIdentifier.unsafeOf(path);
97 edit.getTarget().getPathArguments().forEach(p -> path.add(p));
98 InstanceIdentifier<PortList> plIID = InstanceIdentifier.unsafeOf(path);
100 InstanceIdentifier<NonBlockingList> nblIID = InstanceIdentifier.unsafeOf(path);
101 Uint16 nblNb = InstanceIdentifier.keyOf(nblIID).getNblNumber();
102 List<InstanceIdentifier<PortList>> iidList = nbliidMap.containsKey(nblNb)
103 ? nbliidMap.get(nblNb) : new ArrayList<>();
105 nbliidMap.put(nblNb, iidList);
108 LOG.debug("modification of type {} not managed yet", edit.getTarget().getTargetType());
112 if (!nbliidMap.isEmpty() && ospIID != null) {
113 InstanceIdentifier<OduSwitchingPools> id = ospIID;
114 Runnable handleNetconfEvent = new Runnable() {
117 portMapping.updatePortMappingWithOduSwitchingPools(nodeId, id, nbliidMap);
118 LOG.info("{} : swiching-pool data updated", nodeId);
121 Thread thread = new Thread(handleNetconfEvent);
127 public void onCreateTechInfoNotification(CreateTechInfoNotification notification) {
131 * Callback for otdr-scan-result.
133 * @param notification
134 * OtdrScanResult object
137 public void onOtdrScanResult(OtdrScanResult notification) {
138 LOG.info("Notification {} received {}", OtdrScanResult.QNAME, notification);