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.rev181019.ChangeNotification;
15 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.CreateTechInfoNotification;
16 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.OrgOpenroadmDeviceListener;
17 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.OtdrScanResult;
18 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.change.notification.Edit;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.circuit.pack.Ports;
20 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.circuit.packs.CircuitPacks;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.interfaces.grp.Interface;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
23 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
27 public class DeviceListener221 implements OrgOpenroadmDeviceListener {
29 private static final Logger LOG = LoggerFactory.getLogger(DeviceListener221.class);
30 private final String nodeId;
31 private final PortMapping portMapping;
33 public DeviceListener221(String nodeId, PortMapping portMapping) {
36 this.portMapping = portMapping;
40 * Callback for change-notification.
43 * ChangeNotification object
46 public void onChangeNotification(ChangeNotification notification) {
47 LOG.info("notification received from device {}: {}", this.nodeId, notification.toString());
48 if (notification.getEdit() == null) {
49 LOG.warn("unable to handle {} notificatin received - list of edit is null", ChangeNotification.QNAME);
52 for (Edit edit : notification.getEdit()) {
53 if (edit.getTarget() == null) {
56 // 1. Detect the org-openroadm-device object modified
57 switch (edit.getTarget().getTargetType().getSimpleName()) {
59 LinkedList<PathArgument> path = new LinkedList<>();
60 edit.getTarget().getPathArguments().forEach(p -> path.add(p));
61 InstanceIdentifier<Ports> portIID = InstanceIdentifier.unsafeOf(path);
62 String portName = InstanceIdentifier.keyOf(portIID).getPortName();
64 InstanceIdentifier<CircuitPacks> cpIID = InstanceIdentifier.unsafeOf(path);
65 String cpName = InstanceIdentifier.keyOf(cpIID).getCircuitPackName();
66 LOG.info("port {} of circruit-pack {} modified on device {}", portName, cpName, this.nodeId);
67 Mapping oldMapping = portMapping.getMapping(nodeId, cpName, portName);
68 if (oldMapping == null) {
71 Runnable handleNetconfEvent = new Runnable() {
74 portMapping.updateMapping(nodeId, oldMapping);
75 LOG.info("{} : mapping data for {} updated", nodeId,
76 oldMapping.getLogicalConnectionPoint());
79 Thread thread = new Thread(handleNetconfEvent);
83 LinkedList<PathArgument> pathInter = new LinkedList<>();
84 edit.getTarget().getPathArguments().forEach(p -> pathInter.add(p));
85 InstanceIdentifier<Interface> interfIID = InstanceIdentifier.unsafeOf(pathInter);
86 String interfName = InstanceIdentifier.keyOf(interfIID).getName();
87 LOG.info("interface {} modified on device {}", interfName, this.nodeId);
88 Mapping oldMapping2 = portMapping.getMappingFromOtsInterface(nodeId, interfName);
89 if (oldMapping2 == null) {
92 Runnable handleNetconfEvent2 = new Runnable() {
95 portMapping.updateMapping(nodeId, oldMapping2);
96 LOG.info("{} : mapping data for {} updated", nodeId,
97 oldMapping2.getLogicalConnectionPoint());
100 Thread thread2 = new Thread(handleNetconfEvent2);
104 LOG.debug("modification of type {} not managed yet", edit.getTarget().getTargetType());
111 public void onCreateTechInfoNotification(CreateTechInfoNotification notification) {
115 * Callback for otdr-scan-result.
117 * @param notification
118 * OtdrScanResult object
121 public void onOtdrScanResult(OtdrScanResult notification) {
122 LOG.info("Notification {} received {}", OtdrScanResult.QNAME, notification);