2 * Copyright © 2021 Nokia. 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;
10 import java.util.Collection;
11 import java.util.HashMap;
12 import java.util.List;
14 import java.util.Optional;
15 import java.util.concurrent.ExecutionException;
16 import java.util.stream.Collectors;
17 import java.util.stream.Stream;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.opendaylight.mdsal.binding.api.MountPoint;
20 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
21 import org.opendaylight.transportpce.common.Timeouts;
22 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
23 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
24 import org.opendaylight.transportpce.tapi.utils.TapiLink;
25 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210927.Network;
26 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210927.cp.to.degree.CpToDegree;
27 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210927.mapping.Mapping;
28 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210927.network.Nodes;
29 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210927.network.NodesKey;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev170929.Direction;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.OrgOpenroadmDevice;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.Protocols;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.Protocols1;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.lldp.container.lldp.NbrList;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.lldp.container.lldp.nbr.list.IfName;
36 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
37 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.LayerProtocolName;
38 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.Uuid;
39 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Link;
40 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.LinkKey;
41 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
42 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory;
45 public class R2RTapiLinkDiscovery {
47 private static final Logger LOG = LoggerFactory.getLogger(R2RTapiLinkDiscovery.class);
49 private final NetworkTransactionService networkTransactionService;
50 private final DeviceTransactionManager deviceTransactionManager;
51 private final TapiLink tapiLink;
53 public R2RTapiLinkDiscovery(NetworkTransactionService networkTransactionService,
54 DeviceTransactionManager deviceTransactionManager, TapiLink tapiLink) {
55 this.networkTransactionService = networkTransactionService;
56 this.deviceTransactionManager = deviceTransactionManager;
57 this.tapiLink = tapiLink;
60 public Map<LinkKey, Link> readLLDP(NodeId nodeId, int nodeVersion, Uuid tapiTopoUuid) {
61 LOG.info("Tapi R2R Link Node version = {}", nodeVersion);
62 // TODO -> waiting for device 7.1 in network model to change this to a switch statement and include
63 // support for 7.1 devices
64 switch (nodeVersion) {
67 InstanceIdentifier<Protocols> protocols121IID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
68 .child(Protocols.class);
69 Optional<Protocols> protocol121Object = this.deviceTransactionManager.getDataFromDevice(
70 nodeId.getValue(), LogicalDatastoreType.OPERATIONAL, protocols121IID, Timeouts.DEVICE_READ_TIMEOUT,
71 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
72 if (!protocol121Object.isPresent()
73 || (protocol121Object.get().augmentation(Protocols1.class) == null)) {
74 LOG.warn("LLDP subtree is missing : isolated openroadm device");
75 return new HashMap<>();
78 NbrList nbr121List = protocol121Object.get().augmentation(Protocols1.class).getLldp().getNbrList();
79 LOG.info("LLDP subtree is present. Device has {} neighbours", nbr121List.getIfName().size());
80 // try to create rdm2rdm link
81 return rdm2rdmLinkCreatev121(nodeId, tapiTopoUuid, nbr121List);
84 InstanceIdentifier<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device
85 .container.org.openroadm.device.Protocols> protocols221IID =
86 InstanceIdentifier.create(org.opendaylight.yang.gen.v1.http
87 .org.openroadm.device.rev181019.org.openroadm.device.container.OrgOpenroadmDevice.class)
88 .child(org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019
89 .org.openroadm.device.container.org.openroadm.device.Protocols.class);
90 Optional<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device
91 .container.org.openroadm.device.Protocols> protocol221Object = this.deviceTransactionManager
92 .getDataFromDevice(nodeId.getValue(), LogicalDatastoreType.OPERATIONAL, protocols221IID,
93 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
94 if (!protocol221Object.isPresent() || (protocol221Object.get().augmentation(
95 org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev181019.Protocols1.class) == null)) {
96 LOG.warn("LLDP subtree is missing : isolated openroadm device");
97 return new HashMap<>();
99 org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev181019.lldp.container.lldp.@Nullable NbrList
100 nbr221List = protocol221Object.get().augmentation(org.opendaylight.yang.gen.v1.http
101 .org.openroadm.lldp.rev181019.Protocols1.class).getLldp().getNbrList();
102 LOG.info("LLDP subtree is present. Device has {} neighbours", nbr221List.getIfName().size());
103 return rdm2rdmLinkCreatev221(nodeId, tapiTopoUuid, nbr221List);
106 LOG.info("Not yet supported?");
107 return new HashMap<>();
109 LOG.error("Unable to read LLDP data for unmanaged openroadm device version");
110 return new HashMap<>();
114 private Map<LinkKey, Link> rdm2rdmLinkCreatev221(NodeId nodeId, Uuid tapiTopoUuid,
115 org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev181019.lldp.container.lldp.NbrList nbrList) {
116 Map<LinkKey, Link> linkMap = new HashMap<>();
117 for (org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev181019.lldp.container.lldp.nbr.list.IfName
118 ifName : nbrList.nonnullIfName().values()) {
119 if (ifName.getRemoteSysName() == null) {
120 LOG.warn("Tapi R2R Link LLDP subtree neighbour is empty for nodeId: {}, ifName: {}",
121 nodeId.getValue(),ifName.getIfName());
124 Optional<MountPoint> mps = this.deviceTransactionManager.getDeviceMountPoint(ifName.getRemoteSysName());
125 if (!mps.isPresent()) {
126 LOG.warn("Tapi R2R Link Neighbouring nodeId: {} is not mounted yet", ifName.getRemoteSysName());
127 // The controller raises a warning rather than an error because the first node to
128 // mount cannot see its neighbors yet. The link will be detected when processing
129 // the neighbor node.
132 Link omsLink = createR2RTapiLink(nodeId, ifName.getIfName(), ifName.getRemoteSysName(),
133 ifName.getRemotePortId(), tapiTopoUuid);
134 if (omsLink != null) {
135 linkMap.put(omsLink.key(), omsLink);
137 LOG.error("Link was not created");
143 private Map<LinkKey, Link> rdm2rdmLinkCreatev121(NodeId nodeId, Uuid tapiTopoUuid, NbrList nbrList) {
144 Map<LinkKey, Link> linkMap = new HashMap<>();
145 for (IfName ifName : nbrList.nonnullIfName().values()) {
146 if (ifName.getRemoteSysName() == null) {
147 LOG.warn("Tapi R2R Link LLDP subtree neighbour is empty for nodeId: {}, ifName: {}",
148 nodeId.getValue(),ifName.getIfName());
151 Optional<MountPoint> mps = this.deviceTransactionManager.getDeviceMountPoint(ifName
152 .getRemoteSysName());
153 if (!mps.isPresent()) {
154 LOG.warn("Tapi R2R Link Neighbouring nodeId: {} is not mounted yet", ifName.getRemoteSysName());
155 // The controller raises a warning rather than an error because the first node to
156 // mount cannot see its neighbors yet. The link will be detected when processing
157 // the neighbor node.
160 Link omsLink = createR2RTapiLink(nodeId, ifName.getIfName(), ifName.getRemoteSysName(),
161 ifName.getRemotePortId(), tapiTopoUuid);
162 if (omsLink != null) {
163 linkMap.put(omsLink.key(), omsLink);
165 LOG.error("Link was not created");
171 public Link createR2RTapiLink(NodeId nodeId, String interfaceName, String remoteSystemName,
172 String remoteInterfaceName, Uuid tapiTopoUuid) {
173 String srcTpTx = null;
174 String srcTpRx = null;
175 String destTpTx = null;
176 String destTpRx = null;
177 // Find which degree is associated with ethernet interface
178 Integer srcDegId = getDegFromInterface(nodeId, interfaceName);
179 if (srcDegId == null) {
180 LOG.error("Tapi R2R Link Couldnt find degree connected to Ethernet interface for nodeId: {}", nodeId);
183 // Check whether degree is Unidirectional or Bidirectional by counting
185 // circuit-packs under degree subtree
186 Direction sourceDirection = getDegreeDirection(srcDegId, nodeId);
187 if (Direction.NotApplicable == sourceDirection) {
188 LOG.error("Tapi R2R Link Couldnt find degree direction for nodeId: {} and degree: {}", nodeId, srcDegId);
190 } else if (Direction.Bidirectional == sourceDirection) {
191 srcTpTx = "DEG" + srcDegId + "-TTP-TXRX";
192 srcTpRx = "DEG" + srcDegId + "-TTP-TXRX";
194 srcTpTx = "DEG" + srcDegId + "-TTP-TX";
195 srcTpRx = "DEG" + srcDegId + "-TTP-RX";
197 LOG.debug("Tapi R2R Link SrcTPTx {}, SrcTPRx {}", srcTpTx, srcTpRx);
198 // Find degree for which Ethernet interface is created on other end
199 NodeId destNodeId = new NodeId(remoteSystemName);
200 Integer destDegId = getDegFromInterface(destNodeId, remoteInterfaceName);
201 if (destDegId == null) {
202 LOG.error("Tapi R2R Link Couldnt find degree connected to Ethernet interface for nodeId: {}", nodeId);
205 // Check whether degree is Unidirectional or Bidirectional by counting
207 // circuit-packs under degree subtree
208 Direction destinationDirection = getDegreeDirection(destDegId, destNodeId);
209 if (Direction.NotApplicable == destinationDirection) {
210 LOG.error("Tapi R2R Link Couldnt find degree direction for nodeId: {} and degree: {}",
211 destNodeId, destDegId);
213 } else if (Direction.Bidirectional == destinationDirection) {
214 destTpTx = "DEG" + destDegId + "-TTP-TXRX";
215 destTpRx = "DEG" + destDegId + "-TTP-TXRX";
217 destTpTx = "DEG" + destDegId + "-TTP-TX";
218 destTpRx = "DEG" + destDegId + "-TTP-RX";
220 // Todo -> only handling for the bidirectional case. I assume all tps are of the type bidirectional
221 LOG.debug("Tapi R2R Link DstTPTx {}, DstTPRx {}", destTpTx, srcTpRx);
223 // Create OMS Tapi Link
224 LOG.info("Tapi R2R Link Found a neighbor SrcNodeId: {} , SrcDegId: {} , SrcTPId: {}, DestNodeId:{} , "
225 + "DestDegId: {}, DestTPId: {}", nodeId.getValue(), srcDegId, srcTpTx, destNodeId, destDegId, destTpRx);
226 Link omsLink = this.tapiLink.createTapiLink(nodeId.getValue(), srcTpTx, destNodeId.getValue(), destTpTx,
227 TapiStringConstants.OMS_RDM_RDM_LINK, TapiStringConstants.PHTNC_MEDIA, TapiStringConstants.PHTNC_MEDIA,
228 TapiStringConstants.PHTNC_MEDIA, TapiStringConstants.PHTNC_MEDIA,
229 this.tapiLink.getAdminState(nodeId.getValue(), destNodeId.getValue(), srcTpTx, destTpTx),
230 this.tapiLink.getOperState(nodeId.getValue(), destNodeId.getValue(), srcTpTx, destTpTx),
231 List.of(LayerProtocolName.PHOTONICMEDIA), List.of(LayerProtocolName.PHOTONICMEDIA.getName()), tapiTopoUuid);
232 LOG.info("Tapi R2R Link OMS link created = {}", omsLink);
236 private Integer getDegFromInterface(NodeId nodeId, String interfaceName) {
237 InstanceIdentifier<Nodes> nodesIID = InstanceIdentifier.builder(Network.class)
238 .child(Nodes.class, new NodesKey(nodeId.getValue())).build();
241 Optional<Nodes> nodesObject = this.networkTransactionService.read(LogicalDatastoreType.CONFIGURATION,
243 if (nodesObject.isEmpty() || (nodesObject.get().getCpToDegree() == null)) {
244 LOG.warn("Could not find mapping for Interface {} for nodeId {}", interfaceName,
248 Collection<CpToDegree> cpToDeg = nodesObject.get().nonnullCpToDegree().values();
249 Stream<CpToDegree> cpToDegStream = cpToDeg.stream().filter(cp -> cp.getInterfaceName() != null)
250 .filter(cp -> cp.getInterfaceName().equals(interfaceName));
251 if (cpToDegStream != null) {
252 @SuppressWarnings("unchecked") Optional<CpToDegree> firstCpToDegree = cpToDegStream.findFirst();
253 if (firstCpToDegree.isEmpty() || (firstCpToDegree == null)) {
254 LOG.debug("Not found so returning nothing");
257 LOG.debug("Found and returning {}",firstCpToDegree.get().getDegreeNumber().intValue());
258 return firstCpToDegree.get().getDegreeNumber().intValue();
260 LOG.warn("CircuitPack stream couldnt find anything for nodeId: {} and interfaceName: {}",
261 nodeId.getValue(),interfaceName);
263 } catch (InterruptedException | ExecutionException ex) {
264 LOG.error("Unable to read mapping for Interface : {} for nodeId {}", interfaceName, nodeId, ex);
269 public Direction getDegreeDirection(Integer degreeCounter, NodeId nodeId) {
270 InstanceIdentifier<Nodes> nodesIID = InstanceIdentifier.builder(Network.class)
271 .child(Nodes.class, new NodesKey(nodeId.getValue())).build();
273 Optional<Nodes> nodesObject = this.networkTransactionService.read(LogicalDatastoreType.CONFIGURATION,
275 if (nodesObject.isPresent() && (nodesObject.get().getMapping() != null)) {
276 Collection<Mapping> mappingList = nodesObject.get().nonnullMapping().values();
277 mappingList = mappingList.stream().filter(mp -> mp.getLogicalConnectionPoint().contains("DEG"
278 + degreeCounter)).collect(Collectors.toList());
279 if (mappingList.size() == 1) {
280 return Direction.Bidirectional;
281 } else if (mappingList.size() > 1) {
285 } catch (InterruptedException | ExecutionException e) {
286 LOG.error("Failed getting Mapping data from portMapping",e);
288 return Direction.NotApplicable;