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.rev210927.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 @SuppressWarnings("unchecked")
54 public void onChangeNotification(ChangeNotification notification) {
55 LOG.debug("device71 notification received = {}", notification);
56 if (notification.getEdit() == null) {
57 LOG.warn("unable to handle {} notificatin received - list of edit is null", ChangeNotification.QNAME);
60 Map<Uint16, List<InstanceIdentifier<PortList>>> nbliidMap = new HashMap<>();
61 InstanceIdentifier<OduSwitchingPools> ospIID = null;
62 for (Edit edit : notification.getEdit()) {
63 if (edit.getTarget() == null) {
66 // 1. Detect the org-openroadm-device object modified
67 LinkedList<PathArgument> path = new LinkedList<>();
68 switch (edit.getTarget().getTargetType().getSimpleName()) {
70 edit.getTarget().getPathArguments().forEach(p -> path.add(p));
71 InstanceIdentifier<Ports> portIID = (InstanceIdentifier<Ports>) InstanceIdentifier
73 String portName = InstanceIdentifier.keyOf(portIID).getPortName();
75 InstanceIdentifier<CircuitPacks> cpIID = (InstanceIdentifier<CircuitPacks>) InstanceIdentifier
77 String cpName = InstanceIdentifier.keyOf(cpIID).getCircuitPackName();
78 LOG.info("port {} of circruit-pack {} modified on device {}", portName, cpName, this.nodeId);
79 Mapping oldMapping = portMapping.getMapping(nodeId, cpName, portName);
80 if (oldMapping == null) {
83 Runnable handleNetconfEvent = new Runnable() {
86 portMapping.updateMapping(nodeId, oldMapping);
87 LOG.info("{} : mapping data for {} updated", nodeId,
88 oldMapping.getLogicalConnectionPoint());
91 Thread thread = new Thread(handleNetconfEvent);
94 case "OduSwitchingPools":
95 LOG.info("odu-switching-pools modified on device {}", nodeId);
96 edit.getTarget().getPathArguments().forEach(p -> path.add(p));
97 ospIID = (InstanceIdentifier<OduSwitchingPools>) InstanceIdentifier.create(path);
100 edit.getTarget().getPathArguments().forEach(p -> path.add(p));
101 InstanceIdentifier<PortList> plIID = (InstanceIdentifier<PortList>) InstanceIdentifier.create(path);
103 InstanceIdentifier<NonBlockingList> nblIID =
104 (InstanceIdentifier<NonBlockingList>) InstanceIdentifier.create(path);
105 Uint16 nblNb = InstanceIdentifier.keyOf(nblIID).getNblNumber();
106 List<InstanceIdentifier<PortList>> iidList = nbliidMap.containsKey(nblNb)
107 ? nbliidMap.get(nblNb) : new ArrayList<>();
109 nbliidMap.put(nblNb, iidList);
112 LOG.debug("modification of type {} not managed yet", edit.getTarget().getTargetType());
116 if (!nbliidMap.isEmpty() && ospIID != null) {
117 InstanceIdentifier<OduSwitchingPools> id = ospIID;
118 Runnable handleNetconfEvent = new Runnable() {
121 portMapping.updatePortMappingWithOduSwitchingPools(nodeId, id, nbliidMap);
122 LOG.info("{} : swiching-pool data updated", nodeId);
125 Thread thread = new Thread(handleNetconfEvent);
131 public void onCreateTechInfoNotification(CreateTechInfoNotification notification) {
135 * Callback for otdr-scan-result.
137 * @param notification
138 * OtdrScanResult object
141 public void onOtdrScanResult(OtdrScanResult notification) {
142 LOG.info("Notification {} received {}", OtdrScanResult.QNAME, notification);