2 * Copyright © 2021 Nokia, Inc. 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
8 package org.opendaylight.transportpce.tapi.topology;
10 import java.util.Collection;
11 import java.util.Optional;
12 import javax.annotation.Nonnull;
13 import org.opendaylight.mdsal.binding.api.DataObjectModification;
14 import org.opendaylight.mdsal.binding.api.DataTreeChangeListener;
15 import org.opendaylight.mdsal.binding.api.DataTreeModification;
16 import org.opendaylight.transportpce.common.StringConstants;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus.ConnectionStatus;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.available.capabilities.AvailableCapability;
20 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
24 public class TapiNetconfTopologyListener implements DataTreeChangeListener<Node> {
26 private static final Logger LOG = LoggerFactory.getLogger(TapiNetconfTopologyListener.class);
27 private final TapiNetworkModelService tapiNetworkModelService;
29 public TapiNetconfTopologyListener(final TapiNetworkModelService tapiNetworkModelService) {
30 this.tapiNetworkModelService = tapiNetworkModelService;
33 public void onDataTreeChanged(@Nonnull Collection<DataTreeModification<Node>> changes) {
34 LOG.info("onDataTreeChanged - {}", this.getClass().getSimpleName());
35 for (DataTreeModification<Node> change : changes) {
36 DataObjectModification<Node> rootNode = change.getRootNode();
37 if (rootNode.getDataBefore() == null) {
40 String nodeId = rootNode.getDataBefore().key().getNodeId().getValue();
41 NetconfNode netconfNodeBefore = rootNode.getDataBefore().augmentation(NetconfNode.class);
42 switch (rootNode.getModificationType()) {
44 this.tapiNetworkModelService.deleteTapinode(nodeId);
45 // TODO -> unregistration to NETCONF stream not yet supported
46 // onDeviceDisConnected(nodeId);
47 LOG.info("Device {} correctly disconnected from controller", nodeId);
50 NetconfNode netconfNodeAfter = rootNode.getDataAfter().augmentation(NetconfNode.class);
51 if (ConnectionStatus.Connecting.equals(netconfNodeBefore.getConnectionStatus())
52 && ConnectionStatus.Connected.equals(netconfNodeAfter.getConnectionStatus())) {
53 LOG.info("Connecting Node: {}", nodeId);
54 Optional<AvailableCapability> deviceCapabilityOpt = netconfNodeAfter
55 .getAvailableCapabilities().getAvailableCapability().stream()
56 .filter(cp -> cp.getCapability().contains(StringConstants.OPENROADM_DEVICE_MODEL_NAME))
57 .sorted((c1, c2) -> c2.getCapability().compareTo(c1.getCapability()))
59 if (deviceCapabilityOpt.isEmpty()) {
60 LOG.error("Unable to get openroadm-device-capability");
63 // TODO -> subscription to NETCONF stream not yet supported... no listeners implementation
64 // onDeviceConnected(nodeId,deviceCapabilityOpt.get().getCapability());
65 LOG.info("Device {} waiting for portmapping to be populated", nodeId);
67 if (ConnectionStatus.Connected.equals(netconfNodeBefore.getConnectionStatus())
68 && ConnectionStatus.Connecting.equals(netconfNodeAfter.getConnectionStatus())) {
69 LOG.warn("Node: {} is being disconnected", nodeId);
73 LOG.debug("Unknown modification type {}", rootNode.getModificationType().name());