/* * Copyright © 2017 AT&T and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.transportpce.networkmodel.listeners; import java.util.LinkedList; import java.util.Set; import org.opendaylight.mdsal.binding.api.NotificationService.CompositeListener; import org.opendaylight.transportpce.common.mapping.PortMapping; import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev231221.mapping.Mapping; import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.ChangeNotification; import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.CreateTechInfoNotification; import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.OtdrScanResult; import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.change.notification.Edit; import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.circuit.pack.Ports; import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.circuit.packs.CircuitPacks; import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.interfaces.grp.Interface; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class DeviceListener221 { private static final Logger LOG = LoggerFactory.getLogger(DeviceListener221.class); private final String nodeId; private final PortMapping portMapping; public DeviceListener221(String nodeId, PortMapping portMapping) { super(); this.nodeId = nodeId; this.portMapping = portMapping; } public CompositeListener getCompositeListener() { return new CompositeListener(Set.of( new CompositeListener.Component<>(ChangeNotification.class, this::onChangeNotification), new CompositeListener.Component<>(CreateTechInfoNotification.class, this::onCreateTechInfoNotification), new CompositeListener.Component<>(OtdrScanResult.class, this::onOtdrScanResult) )); } /** * Callback for change-notification. * * @param notification * ChangeNotification object */ void onChangeNotification(ChangeNotification notification) { LOG.info("notification received from device {}: {}", this.nodeId, notification.toString()); if (notification.getEdit() == null) { LOG.warn("unable to handle {} notificatin received - list of edit is null", ChangeNotification.QNAME); return; } for (Edit edit : notification.getEdit()) { if (edit.getTarget() == null) { continue; } // 1. Detect the org-openroadm-device object modified switch (edit.getTarget().getTargetType().getSimpleName()) { case "Ports": LinkedList path = new LinkedList<>(); edit.getTarget().getPathArguments().forEach(p -> path.add(p)); InstanceIdentifier portIID = InstanceIdentifier.unsafeOf(path); String portName = InstanceIdentifier.keyOf(portIID).getPortName(); path.removeLast(); InstanceIdentifier cpIID = InstanceIdentifier.unsafeOf(path); String cpName = InstanceIdentifier.keyOf(cpIID).getCircuitPackName(); LOG.info("port {} of circruit-pack {} modified on device {}", portName, cpName, this.nodeId); Mapping oldMapping = portMapping.getMapping(nodeId, cpName, portName); if (oldMapping == null) { return; } Runnable handleNetconfEvent = new Runnable() { @Override public void run() { portMapping.updateMapping(nodeId, oldMapping); LOG.info("{} : mapping data for {} updated", nodeId, oldMapping.getLogicalConnectionPoint()); } }; Thread thread = new Thread(handleNetconfEvent); thread.start(); break; case "Interface": LinkedList pathInter = new LinkedList<>(); edit.getTarget().getPathArguments().forEach(p -> pathInter.add(p)); InstanceIdentifier interfIID = InstanceIdentifier.unsafeOf(pathInter); String interfName = InstanceIdentifier.keyOf(interfIID).getName(); LOG.info("interface {} modified on device {}", interfName, this.nodeId); Mapping oldMapping2 = portMapping.getMappingFromOtsInterface(nodeId, interfName); if (oldMapping2 == null) { return; } Runnable handleNetconfEvent2 = new Runnable() { @Override public void run() { portMapping.updateMapping(nodeId, oldMapping2); LOG.info("{} : mapping data for {} updated", nodeId, oldMapping2.getLogicalConnectionPoint()); } }; Thread thread2 = new Thread(handleNetconfEvent2); thread2.start(); break; default: LOG.debug("modification of type {} not managed yet", edit.getTarget().getTargetType()); break; } } } private void onCreateTechInfoNotification(CreateTechInfoNotification notification) { } /** * Callback for otdr-scan-result. * * @param notification * OtdrScanResult object */ private void onOtdrScanResult(OtdrScanResult notification) { LOG.info("Notification {} received {}", OtdrScanResult.QNAME, notification); } }