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;
12 import org.opendaylight.transportpce.common.mapping.PortMapping;
13 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.mapping.Mapping;
14 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.ChangeNotification;
15 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.OrgOpenroadmDeviceListener;
16 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.OtdrScanResult;
17 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.change.notification.Edit;
18 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.pack.Ports;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.packs.CircuitPacks;
20 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
21 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
25 public class DeviceListener121 implements OrgOpenroadmDeviceListener {
27 private static final Logger LOG = LoggerFactory.getLogger(DeviceListener121.class);
28 private final String nodeId;
29 private final PortMapping portMapping;
31 public DeviceListener121(String nodeId, PortMapping portMapping) {
34 this.portMapping = portMapping;
38 * Callback for change-notification.
40 * @param notification ChangeNotification object
43 public void onChangeNotification(ChangeNotification notification) {
44 if (notification.getEdit() == null) {
45 LOG.warn("unable to handle {} notificatin received - list of edit is null", ChangeNotification.QNAME);
48 for (Edit edit : notification.getEdit()) {
49 if (edit.getTarget() == null) {
52 // 1. Detect the org-openroadm-device object modified
53 switch (edit.getTarget().getTargetType().getSimpleName()) {
55 LinkedList<PathArgument> path = new LinkedList<>();
56 edit.getTarget().getPathArguments().forEach(p -> path.add(p));
57 InstanceIdentifier<Ports> portIID = InstanceIdentifier.unsafeOf(path);
58 String portName = InstanceIdentifier.keyOf(portIID).getPortName();
60 InstanceIdentifier<CircuitPacks> cpIID = InstanceIdentifier.unsafeOf(path);
61 String cpName = InstanceIdentifier.keyOf(cpIID).getCircuitPackName();
62 LOG.info("port {} of circruit-pack {} modified on device {}", portName, cpName, this.nodeId);
63 Mapping oldMapping = portMapping.getMapping(nodeId, cpName, portName);
64 if (oldMapping == null) {
67 Runnable handleNetconfEvent = new Runnable() {
70 portMapping.updateMapping(nodeId, oldMapping);
71 LOG.info("{} : mapping data for {} updated", nodeId,
72 oldMapping.getLogicalConnectionPoint());
75 Thread thread = new Thread(handleNetconfEvent);
79 LOG.debug("modification of type {} not managed yet", edit.getTarget().getTargetType());
86 * Callback for otdr-scan-result.
88 * @param notification OtdrScanResult object
91 public void onOtdrScanResult(OtdrScanResult notification) {
92 LOG.info("Notification {} received {}", OtdrScanResult.QNAME, notification);