From 765a6f91ab92bb47cf6baceeef8a6f2e8de80b59 Mon Sep 17 00:00:00 2001 From: "guillaume.lambert" Date: Wed, 2 Mar 2022 22:20:14 +0100 Subject: [PATCH] Reintroduce netmod dependency Many devices do not advertise netmod capabilities, which caused error for subscription. The previous fix removed netmod dependency. - reintroduce the netmod dependency - handle non-compliant devices by catching empty list of supported streams and so on - ensure OpenROADM streams subscriptions are tested first before testing NetCONF streams JIRA: TRNSPRTPCE-621 Signed-off-by: guillaume.lambert Change-Id: I41e4cd3a673137e109a845e0c3fbac5ecf3968e5 --- .../networkmodel/NetConfTopologyListener.java | 38 +++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/NetConfTopologyListener.java b/networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/NetConfTopologyListener.java index dedc387a0..b48c61ffe 100644 --- a/networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/NetConfTopologyListener.java +++ b/networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/NetConfTopologyListener.java @@ -9,6 +9,7 @@ package org.opendaylight.transportpce.networkmodel; import com.google.common.annotations.VisibleForTesting; import com.google.common.util.concurrent.ListenableFuture; +import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Map; @@ -23,7 +24,9 @@ import org.opendaylight.mdsal.binding.api.DataTreeModification; import org.opendaylight.mdsal.binding.api.MountPoint; import org.opendaylight.mdsal.binding.api.NotificationService; import org.opendaylight.mdsal.binding.api.RpcConsumerRegistry; +import org.opendaylight.mdsal.common.api.LogicalDatastoreType; import org.opendaylight.transportpce.common.StringConstants; +import org.opendaylight.transportpce.common.Timeouts; import org.opendaylight.transportpce.common.device.DeviceTransactionManager; import org.opendaylight.transportpce.common.mapping.PortMapping; import org.opendaylight.transportpce.networkmodel.dto.NodeRegistration; @@ -32,10 +35,14 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification. import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.CreateSubscriptionOutput; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.NotificationsService; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.notification._1._0.rev080714.StreamNameType; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.Netconf; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.Streams; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netmod.notification.rev080714.netconf.streams.Stream; import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode; import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus.ConnectionStatus; import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.available.capabilities.AvailableCapability; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.common.RpcResult; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -147,13 +154,11 @@ public class NetConfTopologyListener implements DataTreeChangeListener { return false; } // Set the default stream as OPENROADM - for (String streamName : List.of("OPENROADM", "NETCONF")) { + for (String streamName : getSupportedStream(nodeId)) { LOG.info("Triggering notification stream {} for node {}", streamName, nodeId); ListenableFuture> subscription = rpcService.createSubscription( new CreateSubscriptionInputBuilder().setStream(new StreamNameType(streamName)).build()); - // If OpenROADM stream is not supported - // Try NETCONF subscription if (checkSupportedStream(streamName, subscription)) { return true; } @@ -189,4 +194,31 @@ public class NetConfTopologyListener implements DataTreeChangeListener { return subscriptionSuccessful; } + private List getSupportedStream(String nodeId) { + InstanceIdentifier streamsIID = InstanceIdentifier.create(Netconf.class).child(Streams.class); + Optional ordmInfoObject = + deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL, streamsIID, + Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT); + if (ordmInfoObject == null || ordmInfoObject.isEmpty() || ordmInfoObject.get().getStream().isEmpty()) { + LOG.error("List of streams supports by device is not present"); + return List.of("OPENROADM","NETCONF"); + } + List streams = new ArrayList<>(); + List netconfStreams = new ArrayList<>(); + for (Stream strm : ordmInfoObject.get().getStream().values()) { + LOG.debug("Streams are {}", strm); + if ("OPENROADM".equalsIgnoreCase(strm.getName().getValue())) { + streams.add(strm.getName().getValue()); + } else if ("NETCONF".equalsIgnoreCase(strm.getName().getValue())) { + netconfStreams.add(strm.getName().getValue()); + } + } + // If OpenROADM streams are not supported, try NETCONF streams subscription + streams.addAll(netconfStreams); + return + streams.isEmpty() + ? List.of("OPENROADM","NETCONF") + : streams; + } + } -- 2.36.6