2 * Copyright © 2017 AT&T 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.LinkedList;
13 import org.opendaylight.mdsal.binding.api.NotificationService.CompositeListener;
14 import org.opendaylight.transportpce.common.mapping.PortMapping;
15 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev231221.mapping.Mapping;
16 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.ChangeNotification;
17 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.CreateTechInfoNotification;
18 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.OtdrScanResult;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.change.notification.Edit;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.circuit.pack.Ports;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.circuit.packs.CircuitPacks;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.interfaces.grp.Interface;
23 import org.opendaylight.yangtools.yang.binding.DataObjectStep;
24 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
28 public class DeviceListener221 {
30 private static final Logger LOG = LoggerFactory.getLogger(DeviceListener221.class);
31 private final String nodeId;
32 private final PortMapping portMapping;
34 public DeviceListener221(String nodeId, PortMapping portMapping) {
37 this.portMapping = portMapping;
40 public CompositeListener getCompositeListener() {
41 return new CompositeListener(Set.of(
42 new CompositeListener.Component<>(ChangeNotification.class, this::onChangeNotification),
43 new CompositeListener.Component<>(CreateTechInfoNotification.class, this::onCreateTechInfoNotification),
44 new CompositeListener.Component<>(OtdrScanResult.class, this::onOtdrScanResult)
49 * Callback for change-notification.
52 * ChangeNotification object
54 void onChangeNotification(ChangeNotification notification) {
55 LOG.info("notification received from device {}: {}", this.nodeId, notification.toString());
56 if (notification.getEdit() == null) {
57 LOG.warn("unable to handle {} notificatin received - list of edit is null", ChangeNotification.QNAME);
60 for (Edit edit : notification.getEdit()) {
61 if (edit.getTarget() == null) {
64 // 1. Detect the org-openroadm-device object modified
65 switch (edit.getTarget().getTargetType().getSimpleName()) {
67 LinkedList<DataObjectStep<?>> path = new LinkedList<>();
68 edit.getTarget().getPathArguments().forEach(p -> path.add(p));
69 InstanceIdentifier<Ports> portIID = InstanceIdentifier.unsafeOf(path);
70 String portName = InstanceIdentifier.keyOf(portIID).getPortName();
72 InstanceIdentifier<CircuitPacks> cpIID = InstanceIdentifier.unsafeOf(path);
73 String cpName = InstanceIdentifier.keyOf(cpIID).getCircuitPackName();
74 LOG.info("port {} of circruit-pack {} modified on device {}", portName, cpName, this.nodeId);
75 Mapping oldMapping = portMapping.getMapping(nodeId, cpName, portName);
76 if (oldMapping == null) {
79 Runnable handleNetconfEvent = new Runnable() {
82 portMapping.updateMapping(nodeId, oldMapping);
83 LOG.info("{} : mapping data for {} updated", nodeId,
84 oldMapping.getLogicalConnectionPoint());
87 Thread thread = new Thread(handleNetconfEvent);
91 LinkedList<DataObjectStep<?>> pathInter = new LinkedList<>();
92 edit.getTarget().getPathArguments().forEach(p -> pathInter.add(p));
93 InstanceIdentifier<Interface> interfIID = InstanceIdentifier.unsafeOf(pathInter);
94 String interfName = InstanceIdentifier.keyOf(interfIID).getName();
95 LOG.info("interface {} modified on device {}", interfName, this.nodeId);
96 Mapping oldMapping2 = portMapping.getMappingFromOtsInterface(nodeId, interfName);
97 if (oldMapping2 == null) {
100 Runnable handleNetconfEvent2 = new Runnable() {
103 portMapping.updateMapping(nodeId, oldMapping2);
104 LOG.info("{} : mapping data for {} updated", nodeId,
105 oldMapping2.getLogicalConnectionPoint());
108 Thread thread2 = new Thread(handleNetconfEvent2);
112 LOG.debug("modification of type {} not managed yet", edit.getTarget().getTargetType());
118 private void onCreateTechInfoNotification(CreateTechInfoNotification notification) {
122 * Callback for otdr-scan-result.
124 * @param notification
125 * OtdrScanResult object
127 private void onOtdrScanResult(OtdrScanResult notification) {
128 LOG.info("Notification {} received {}", OtdrScanResult.QNAME, notification);