2 * Copyright © 2016 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
8 package org.opendaylight.transportpce.networkmodel;
10 import java.util.Optional;
11 import java.util.concurrent.ExecutionException;
13 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
14 import org.opendaylight.controller.md.sal.binding.api.MountPoint;
15 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
16 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
17 import org.opendaylight.transportpce.common.Timeouts;
18 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
19 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaceException;
20 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
21 import org.opendaylight.transportpce.networkmodel.util.OpenRoadmTopology;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev170929.Direction;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.packs.CircuitPacks;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.packs.CircuitPacksKey;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.interfaces.grp.Interface;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.OrgOpenroadmDevice;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.Degree;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.DegreeKey;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.Protocols;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.Protocols1;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.lldp.container.lldp.NbrList;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.lldp.container.lldp.nbr.list.IfName;
33 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev150608.NodeId;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.networkutils.rev170818.InitRoadmNodesInputBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.portmapping.rev170228.Network;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.portmapping.rev170228.network.Nodes;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.portmapping.rev170228.network.NodesKey;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.portmapping.rev170228.network.nodes.CpToDegree;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.portmapping.rev170228.network.nodes.CpToDegreeKey;
40 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
41 import org.slf4j.Logger;
42 import org.slf4j.LoggerFactory;
44 public class R2RLinkDiscovery {
46 private static final Logger LOG = LoggerFactory.getLogger(R2RLinkDiscovery.class);
48 private final DataBroker dataBroker;
49 private final DeviceTransactionManager deviceTransactionManager;
50 private final OpenRoadmTopology openRoadmTopology;
51 private final OpenRoadmInterfaces openRoadmInterfaces;
53 public R2RLinkDiscovery(final DataBroker dataBroker, DeviceTransactionManager deviceTransactionManager,
54 OpenRoadmTopology openRoadmTopology, OpenRoadmInterfaces openRoadmInterfaces) {
55 this.dataBroker = dataBroker;
56 this.deviceTransactionManager = deviceTransactionManager;
57 this.openRoadmTopology = openRoadmTopology;
58 this.openRoadmInterfaces = openRoadmInterfaces;
61 public boolean readLLDP(NodeId nodeId) {
62 InstanceIdentifier<Protocols> protocolsIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
63 .child(Protocols.class);
64 Optional<Protocols> protocolObject = this.deviceTransactionManager.getDataFromDevice(nodeId.getValue(),
65 LogicalDatastoreType.OPERATIONAL, protocolsIID, Timeouts.DEVICE_READ_TIMEOUT,
66 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
67 if (!protocolObject.isPresent() || (protocolObject.get().getAugmentation(Protocols1.class) == null)) {
68 LOG.warn("LLDP subtree is missing : isolated openroadm device");
71 NbrList nbrList = protocolObject.get().getAugmentation(Protocols1.class).getLldp().getNbrList();
72 LOG.info("LLDP subtree is present. Device has {} neighbours", nbrList.getIfName().size());
73 for (IfName ifName : nbrList.getIfName()) {
74 if (ifName.getRemoteSysName() == null) {
75 LOG.error("LLDP subtree is empty in the device for nodeId: {}", nodeId.getValue());
78 Optional<MountPoint> mps = this.deviceTransactionManager.getDeviceMountPoint(ifName.getRemoteSysName());
79 if (!mps.isPresent()) {
80 LOG.warn("Neighbouring nodeId: {} is not mounted yet", ifName.getRemoteSysName());
81 // The controller raises a warning rather than an error because the first node to
82 // mount cannot see its neighbors yet. The link will be detected when processing
85 if (!createR2RLink(nodeId, ifName.getIfName(), ifName.getRemoteSysName(), ifName.getRemotePortId())) {
86 LOG.error("Link Creation failed between {} and {} nodes.", nodeId, ifName.getRemoteSysName());
94 public Direction getDegreeDirection(Integer degreeCounter, NodeId nodeId) {
95 InstanceIdentifier<Degree> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class).child(Degree.class,
96 new DegreeKey(degreeCounter));
97 Optional<Degree> degreeObject = this.deviceTransactionManager.getDataFromDevice(nodeId.getValue(),
98 LogicalDatastoreType.OPERATIONAL, deviceIID, Timeouts.DEVICE_READ_TIMEOUT,
99 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
100 if (degreeObject.isPresent()) {
101 Integer connectionPortCount = degreeObject.get().getConnectionPorts().size();
102 if (connectionPortCount == 1) {
103 return Direction.Bidirectional;
104 } else if (connectionPortCount > 1) {
107 return Direction.NotApplicable;
110 LOG.error("Couldnt retrieve Degree object for nodeId: {} and DegreeNumbner: {}", nodeId.getValue(),
112 return Direction.NotApplicable;
116 public boolean createR2RLink(NodeId nodeId, String interfaceName, String remoteSystemName,
117 String remoteInterfaceName) {
118 String srcTpTx = null;
119 String srcTpRx = null;
120 String destTpTx = null;
121 String destTpRx = null;
122 // Find which degree is associated with ethernet interface
123 // portmapping.getDegFromCP(nodeId,interfaceName);
124 Integer srcDegId = getDegFromCP(nodeId, interfaceName);
125 if (srcDegId == null) {
126 LOG.error("Couldnt find degree connected to Ethernet interface for nodeId: {}", nodeId);
129 // Check whether degree is Unidirectional or Bidirectional by counting
131 // circuit-packs under degree subtree
132 Direction sourceDirection = getDegreeDirection(srcDegId, nodeId);
133 if (Direction.NotApplicable == sourceDirection) {
134 LOG.error("Couldnt find degree direction for nodeId: {} and degree: {}", nodeId, srcDegId);
136 } else if (Direction.Bidirectional == sourceDirection) {
137 srcTpTx = "DEG" + srcDegId + "-TTP-TXRX";
138 srcTpRx = "DEG" + srcDegId + "-TTP-TXRX";
140 srcTpTx = "DEG" + srcDegId + "-TTP-TX";
141 srcTpRx = "DEG" + srcDegId + "-TTP-RX";
143 // Find degree for which Ethernet interface is created on other end
144 NodeId destNodeId = new NodeId(remoteSystemName);
145 Integer destDegId = getDegFromCP(destNodeId, remoteInterfaceName);
146 // portmapping.getDegFromCP(nodeId,interfaceName);
147 if (destDegId == null) {
148 LOG.error("Couldnt find degree connected to Ethernet interface for nodeId: {}", nodeId);
151 // Check whether degree is Unidirectional or Bidirectional by counting
153 // circuit-packs under degree subtree
154 Direction destinationDirection = getDegreeDirection(destDegId, destNodeId);
155 if (Direction.NotApplicable == destinationDirection) {
156 LOG.error("Couldnt find degree direction for nodeId: {} and degree: {}", destNodeId, destDegId);
158 } else if (Direction.Bidirectional == destinationDirection) {
159 destTpTx = "DEG" + destDegId + "-TTP-TXRX";
160 destTpRx = "DEG" + destDegId + "-TTP-TXRX";
162 destTpTx = "DEG" + destDegId + "-TTP-TX";
163 destTpRx = "DEG" + destDegId + "-TTP-RX";
167 "Found a neighbor SrcNodeId: {} , SrcDegId: {} , SrcTPId: {}, DestNodeId:{} , DestDegId: {}, DestTPId: {}",
168 nodeId.getValue(), srcDegId, srcTpTx, destNodeId, destDegId, destTpRx);
169 InitRoadmNodesInputBuilder r2rlinkBuilderAToZ = new InitRoadmNodesInputBuilder();
170 r2rlinkBuilderAToZ.setRdmANode(nodeId.getValue()).setDegANum(srcDegId.shortValue())
171 .setTerminationPointA(srcTpTx).setRdmZNode(destNodeId.getValue()).setDegZNum(destDegId.shortValue())
172 .setTerminationPointZ(destTpRx);
173 if (!OrdLink.createRdm2RdmLinks(r2rlinkBuilderAToZ.build(), openRoadmTopology, dataBroker)) {
174 LOG.error("OMS Link creation failed between node: {} and nodeId: {} in A->Z direction", nodeId.getValue(),
175 destNodeId.getValue());
180 "Found a neighbor SrcNodeId: {} , SrcDegId: {}"
181 + ", SrcTPId: {}, DestNodeId:{} , DestDegId: {}, DestTPId: {}",
182 destNodeId, destDegId, destTpTx, nodeId.getValue(), srcDegId, srcTpRx);
184 InitRoadmNodesInputBuilder r2rlinkBuilderZToA = new InitRoadmNodesInputBuilder();
185 r2rlinkBuilderZToA.setRdmANode(destNodeId.getValue()).setDegANum(destDegId.shortValue())
186 .setTerminationPointA(destTpTx).setRdmZNode(nodeId.getValue()).setDegZNum(srcDegId.shortValue())
187 .setTerminationPointZ(srcTpRx);
188 if (!OrdLink.createRdm2RdmLinks(r2rlinkBuilderZToA.build(), openRoadmTopology, dataBroker)) {
189 LOG.error("OMS Link creation failed between node: {} and nodeId: {} in Z->A direction",
190 destNodeId.getValue(), nodeId.getValue());
196 public boolean deleteR2RLink(NodeId nodeId, String interfaceName, String remoteSystemName,
197 String remoteInterfaceName) {
198 String srcTpTx = null;
199 String srcTpRx = null;
200 String destTpTx = null;
201 String destTpRx = null;
202 // Find which degree is associated with ethernet interface
203 // portmapping.getDegFromCP(nodeId,interfaceName);
204 Integer srcDegId = getDegFromCP(nodeId, interfaceName);
205 if (srcDegId == null) {
206 LOG.error("Couldnt find degree connected to Ethernet interface for nodeId: {}", nodeId);
209 // Check whether degree is Unidirectional or Bidirectional by counting number of
210 // circuit-packs under degree subtree
211 Direction sourceDirection = getDegreeDirection(srcDegId, nodeId);
212 if (Direction.NotApplicable == sourceDirection) {
213 LOG.error("Couldnt find degree direction for nodeId: {} and degree: {}", nodeId, srcDegId);
215 } else if (Direction.Bidirectional == sourceDirection) {
216 srcTpTx = "DEG" + srcDegId + "-TTP-TXRX";
217 srcTpRx = "DEG" + srcDegId + "-TTP-TXRX";
219 srcTpTx = "DEG" + srcDegId + "-TTP-TX";
220 srcTpRx = "DEG" + srcDegId + "-TTP-RX";
222 // Find degree for which Ethernet interface is created on other end
223 NodeId destNodeId = new NodeId(remoteSystemName);
224 // portmapping.getDegFromCP(nodeId,interfaceName);
225 Integer destDegId = getDegFromCP(destNodeId, remoteInterfaceName);
226 if (destDegId == null) {
227 LOG.error("Couldnt find degree connected to Ethernet interface for nodeId: {}", nodeId);
230 // Check whether degree is Unidirectional or Bidirectional by counting number of
231 // circuit-packs under degree subtree
232 Direction destinationDirection = getDegreeDirection(destDegId, destNodeId);
233 if (Direction.NotApplicable == destinationDirection) {
234 LOG.error("Couldnt find degree direction for nodeId: {} and degree: {}", destNodeId, destDegId);
236 } else if (Direction.Bidirectional == destinationDirection) {
237 destTpTx = "DEG" + destDegId + "-TTP-TXRX";
238 destTpRx = "DEG" + destDegId + "-TTP-TXRX";
240 destTpTx = "DEG" + destDegId + "-TTP-TX";
241 destTpRx = "DEG" + destDegId + "-TTP-RX";
243 return this.openRoadmTopology.deleteLink(nodeId.getValue(), destNodeId.getValue(), srcTpTx, destTpRx)
244 && this.openRoadmTopology.deleteLink(destNodeId.getValue(), nodeId.getValue(), destTpTx, srcTpRx);
247 private CpToDegree getCPtoDegreeMapping(NodeId nodeId, String circuitPackName) {
248 InstanceIdentifier<CpToDegree> cptoDegMappingIID = InstanceIdentifier.builder(Network.class)
249 .child(Nodes.class, new NodesKey(nodeId.getValue()))
250 .child(CpToDegree.class, new CpToDegreeKey(circuitPackName)).build();
251 LOG.debug("Input parameters are {},{}", nodeId.getValue(), circuitPackName);
252 try (ReadOnlyTransaction readTx = this.dataBroker.newReadOnlyTransaction()) {
253 Optional<CpToDegree> cptpDegObject = readTx.read(LogicalDatastoreType.CONFIGURATION, cptoDegMappingIID)
255 if (cptpDegObject.isPresent()) {
256 CpToDegree cpToDeg = cptpDegObject.get();
257 LOG.debug("Found mapping for the Circuit Pack {}. Degree: {}", circuitPackName, cpToDeg);
260 LOG.warn("Could not find mapping for Circuit Pack {} for nodeId {}", circuitPackName,
263 } catch (InterruptedException | ExecutionException ex) {
264 LOG.error("Unable to read mapping for circuit pack : {} for nodeId {}", circuitPackName, nodeId, ex);
269 private Integer getDegFromParentCP(NodeId nodeId, String interfaceName, String supportingCircuitPack) {
270 InstanceIdentifier<CircuitPacks> circuitPackIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
271 .child(CircuitPacks.class, new CircuitPacksKey(supportingCircuitPack));
272 Optional<CircuitPacks> circuitPackObject = this.deviceTransactionManager.getDataFromDevice(nodeId.getValue(),
273 LogicalDatastoreType.OPERATIONAL, circuitPackIID, Timeouts.DEVICE_READ_TIMEOUT,
274 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
275 if (!circuitPackObject.isPresent()
276 || (circuitPackObject.get().getParentCircuitPack().getCircuitPackName() == null)) {
277 LOG.warn("Parent circuitpack not found for NodeId: {} and Interface: {}", nodeId, interfaceName);
280 String parentCP = circuitPackObject.get().getParentCircuitPack().getCircuitPackName();
281 CpToDegree cpToDegree = getCPtoDegreeMapping(nodeId, parentCP);
282 if (cpToDegree == null) {
283 LOG.error("CP to Degree mapping not found even with parent circuitpack for NodeID: {}" + "and Interface {}",
284 nodeId, interfaceName);
287 LOG.debug("CP to degree is {}", cpToDegree.getDegreeNumber());
288 return cpToDegree.getDegreeNumber().intValue();
292 private Integer getDegFromCP(NodeId nodeId, String interfaceName) {
294 java.util.Optional<Interface> interfaceOpt = this.openRoadmInterfaces.getInterface(nodeId.getValue(),
296 if (!interfaceOpt.isPresent()) {
297 LOG.warn("Interface with {} on node {} was not found!", interfaceName, nodeId.getValue());
300 String supportingCircuitPack = interfaceOpt.get().getSupportingCircuitPackName();
301 LOG.debug("Supporting circuitpack name is :{}", interfaceOpt.get().getSupportingCircuitPackName());
302 CpToDegree cpToDegree = getCPtoDegreeMapping(nodeId, supportingCircuitPack);
303 // Currently devices have different ways to represent connection to Ethernet port
305 // If Circuit pack is not present under degree tree then read parent CP of given
306 // CP (Circuit pack).
307 if (cpToDegree != null) {
308 return cpToDegree.getDegreeNumber().intValue();
310 return getDegFromParentCP(nodeId, interfaceName, supportingCircuitPack);
312 } catch (OpenRoadmInterfaceException ex) {
313 LOG.error("Failed to get source interface {} from node {}!", interfaceName, nodeId, ex);