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,
54 DeviceTransactionManager deviceTransactionManager, OpenRoadmTopology openRoadmTopology,
55 OpenRoadmInterfaces openRoadmInterfaces) {
56 this.dataBroker = dataBroker;
57 this.deviceTransactionManager = deviceTransactionManager;
58 this.openRoadmTopology = openRoadmTopology;
59 this.openRoadmInterfaces = openRoadmInterfaces;
62 public boolean readLLDP(NodeId nodeId) {
63 InstanceIdentifier<Protocols> protocolsIID =
64 InstanceIdentifier.create(OrgOpenroadmDevice.class).child(Protocols.class);
65 Optional<Protocols> protocolObject =
66 this.deviceTransactionManager.getDataFromDevice(nodeId.getValue(), LogicalDatastoreType.OPERATIONAL,
67 protocolsIID, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
68 if (!protocolObject.isPresent() || (protocolObject.get().getAugmentation(Protocols1.class) == null)) {
69 LOG.warn("LLDP subtree is missing : isolated openroadm device");
72 NbrList nbrList = protocolObject.get().getAugmentation(Protocols1.class).getLldp().getNbrList();
73 LOG.info("LLDP subtree is present. Device has {} neighbours", nbrList.getIfName().size());
74 for (IfName ifName : nbrList.getIfName()) {
75 if (ifName.getRemoteSysName() == null) {
76 LOG.error("LLDP subtree is empty in the device for nodeId: {}",
80 Optional<MountPoint> mps = this.deviceTransactionManager.getDeviceMountPoint(ifName.getRemoteSysName());
81 if (!mps.isPresent()) {
82 LOG.warn("Neighbouring nodeId: {} is not mounted yet", ifName.getRemoteSysName());
85 if (!createR2RLink(nodeId, ifName.getIfName(), ifName.getRemoteSysName(),
86 ifName.getRemotePortId())) {
87 LOG.warn("Link Creation failed between {} and {} nodes.", nodeId, ifName.getRemoteSysName());
95 public Direction getDegreeDirection(Integer degreeCounter, NodeId nodeId) {
96 InstanceIdentifier<Degree> deviceIID =
97 InstanceIdentifier.create(OrgOpenroadmDevice.class).child(Degree.class, new DegreeKey(degreeCounter));
98 Optional<Degree> degreeObject =
99 this.deviceTransactionManager.getDataFromDevice(nodeId.getValue(), LogicalDatastoreType.OPERATIONAL,
100 deviceIID, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
101 if (degreeObject.isPresent()) {
102 Integer connectionPortCount = degreeObject.get().getConnectionPorts().size();
103 if (connectionPortCount == 1) {
104 return Direction.Bidirectional;
105 } else if (connectionPortCount > 1) {
108 return Direction.NotApplicable;
111 LOG.error("Couldnt retrieve Degree object for nodeId: {} and DegreeNumbner: {}",
112 nodeId.getValue(),degreeCounter);
113 return Direction.NotApplicable;
117 public boolean createR2RLink(NodeId nodeId, String interfaceName, String remoteSystemName,
118 String remoteInterfaceName) {
119 String srcTpTx = null;
120 String srcTpRx = null;
121 String destTpTx = null;
122 String destTpRx = null;
123 //Find which degree is associated with ethernet interface
124 //portmapping.getDegFromCP(nodeId,interfaceName);
125 Integer srcDegId = getDegFromCP(nodeId, interfaceName);
126 if (srcDegId == null) {
127 LOG.error("Couldnt find degree connected to Ethernet interface for nodeId: {}", nodeId);
130 // Check whether degree is Unidirectional or Bidirectional by counting number of
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 number of
152 // circuit-packs under degree subtree
153 Direction destinationDirection = getDegreeDirection(destDegId, destNodeId);
154 if (Direction.NotApplicable == destinationDirection) {
155 LOG.error("Couldnt find degree direction for nodeId: {} and degree: {}", destNodeId, destDegId);
157 } else if (Direction.Bidirectional == destinationDirection) {
158 destTpTx = "DEG" + destDegId + "-TTP-TXRX";
159 destTpRx = "DEG" + destDegId + "-TTP-TXRX";
161 destTpTx = "DEG" + destDegId + "-TTP-TX";
162 destTpRx = "DEG" + destDegId + "-TTP-RX";
166 "Found a neighbor SrcNodeId: {} , SrcDegId: {} , SrcTPId: {}, DestNodeId:{} , DestDegId: {}, DestTPId: {}",
167 nodeId.getValue(), srcDegId, srcTpTx, destNodeId, destDegId, destTpRx);
168 InitRoadmNodesInputBuilder r2rlinkBuilderAToZ = new InitRoadmNodesInputBuilder();
169 r2rlinkBuilderAToZ.setRdmANode(nodeId.getValue())
170 .setDegANum(srcDegId.shortValue()).setTerminationPointA(srcTpTx)
171 .setRdmZNode(destNodeId.getValue())
172 .setDegZNum(destDegId.shortValue()).setTerminationPointZ(destTpRx);
173 if (!OrdLink.createRdm2RdmLinks(r2rlinkBuilderAToZ.build(),openRoadmTopology,
175 LOG.error("OMS Link creation failed between node: {} and nodeId: {} in A->Z direction",
176 nodeId.getValue(),destNodeId.getValue());
181 "Found a neighbor SrcNodeId: {} , SrcDegId: {}"
182 + ", SrcTPId: {}, DestNodeId:{} , DestDegId: {}, DestTPId: {}",
183 destNodeId, destDegId, destTpTx, nodeId.getValue(), srcDegId, srcTpRx);
185 InitRoadmNodesInputBuilder r2rlinkBuilderZToA = new InitRoadmNodesInputBuilder();
186 r2rlinkBuilderZToA.setRdmANode(destNodeId.getValue())
187 .setDegANum(destDegId.shortValue()).setTerminationPointA(destTpTx)
188 .setRdmZNode(nodeId.getValue())
189 .setDegZNum(srcDegId.shortValue()).setTerminationPointZ(srcTpRx);
190 if (!OrdLink.createRdm2RdmLinks(r2rlinkBuilderZToA.build(),openRoadmTopology,
192 LOG.error("OMS Link creation failed between node: {} and nodeId: {} in Z->A direction",
193 destNodeId.getValue(),nodeId.getValue());
199 public boolean deleteR2RLink(NodeId nodeId, String interfaceName, String remoteSystemName,
200 String remoteInterfaceName) {
201 String srcTpTx = null;
202 String srcTpRx = null;
203 String destTpTx = null;
204 String destTpRx = null;
205 //Find which degree is associated with ethernet interface
206 //portmapping.getDegFromCP(nodeId,interfaceName);
207 Integer srcDegId = getDegFromCP(nodeId, interfaceName);
208 if (srcDegId == null) {
209 LOG.error("Couldnt find degree connected to Ethernet interface for nodeId: {}", nodeId);
212 // Check whether degree is Unidirectional or Bidirectional by counting number of
213 // circuit-packs under degree subtree
214 Direction sourceDirection = getDegreeDirection(srcDegId, nodeId);
215 if (Direction.NotApplicable == sourceDirection) {
216 LOG.error("Couldnt find degree direction for nodeId: {} and degree: {}", nodeId, srcDegId);
218 } else if (Direction.Bidirectional == sourceDirection) {
219 srcTpTx = "DEG" + srcDegId + "-TTP-TXRX";
220 srcTpRx = "DEG" + srcDegId + "-TTP-TXRX";
222 srcTpTx = "DEG" + srcDegId + "-TTP-TX";
223 srcTpRx = "DEG" + srcDegId + "-TTP-RX";
225 // Find degree for which Ethernet interface is created on other end
226 NodeId destNodeId = new NodeId(remoteSystemName);
227 //portmapping.getDegFromCP(nodeId,interfaceName);
228 Integer destDegId = getDegFromCP(destNodeId, remoteInterfaceName);
229 if (destDegId == null) {
230 LOG.error("Couldnt find degree connected to Ethernet interface for nodeId: {}", nodeId);
233 // Check whether degree is Unidirectional or Bidirectional by counting number of
234 // circuit-packs under degree subtree
235 Direction destinationDirection = getDegreeDirection(destDegId, destNodeId);
236 if (Direction.NotApplicable == destinationDirection) {
237 LOG.error("Couldnt find degree direction for nodeId: {} and degree: {}", destNodeId, destDegId);
239 } else if (Direction.Bidirectional == destinationDirection) {
240 destTpTx = "DEG" + destDegId + "-TTP-TXRX";
241 destTpRx = "DEG" + destDegId + "-TTP-TXRX";
243 destTpTx = "DEG" + destDegId + "-TTP-TX";
244 destTpRx = "DEG" + destDegId + "-TTP-RX";
246 return this.openRoadmTopology.deleteLink(nodeId.getValue(), destNodeId.getValue(), srcTpTx, destTpRx)
247 && this.openRoadmTopology.deleteLink(destNodeId.getValue(), nodeId.getValue(), destTpTx, srcTpRx);
250 private CpToDegree getCPtoDegreeMapping(NodeId nodeId, String circuitPackName) {
251 InstanceIdentifier<CpToDegree> cptoDegMappingIID =
252 InstanceIdentifier.builder(Network.class).child(Nodes.class,
253 new NodesKey(nodeId.getValue()))
254 .child(CpToDegree.class, new CpToDegreeKey(circuitPackName)).build();
255 LOG.debug("Input parameters are {},{}", nodeId.getValue(), circuitPackName);
256 try (ReadOnlyTransaction readTx = this.dataBroker.newReadOnlyTransaction()) {
257 Optional<CpToDegree> cptpDegObject =
258 readTx.read(LogicalDatastoreType.CONFIGURATION, cptoDegMappingIID).get().toJavaUtil();
259 if (cptpDegObject.isPresent()) {
260 CpToDegree cpToDeg = cptpDegObject.get();
261 LOG.debug("Found mapping for the Circuit Pack {}. Degree: {}", circuitPackName, cpToDeg);
264 LOG.warn("Could not find mapping for Circuit Pack {} for nodeId {}", circuitPackName,
267 } catch (InterruptedException | ExecutionException ex) {
268 LOG.error("Unable to read mapping for circuit pack : {} for nodeId {}", circuitPackName, nodeId, ex);
273 private Integer getDegFromParentCP(NodeId nodeId, String interfaceName, String supportingCircuitPack) {
274 InstanceIdentifier<CircuitPacks> circuitPackIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
275 .child(CircuitPacks.class, new CircuitPacksKey(supportingCircuitPack));
276 Optional<CircuitPacks> circuitPackObject =
277 this.deviceTransactionManager.getDataFromDevice(nodeId.getValue(), LogicalDatastoreType.OPERATIONAL,
278 circuitPackIID, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
279 if (!circuitPackObject.isPresent()
280 || (circuitPackObject.get().getParentCircuitPack().getCircuitPackName() == null)) {
281 LOG.warn("Parent circuitpack not found for NodeId: {} and Interface: {}", nodeId, interfaceName);
284 String parentCP = circuitPackObject.get().getParentCircuitPack().getCircuitPackName();
285 CpToDegree cpToDegree = getCPtoDegreeMapping(nodeId, parentCP);
286 if (cpToDegree == null) {
287 LOG.error("CP to Degree mapping not found even with parent circuitpack for NodeID: {}" + "and Interface {}",
288 nodeId, interfaceName);
291 LOG.debug("CP to degree is {}", cpToDegree.getDegreeNumber());
292 return cpToDegree.getDegreeNumber().intValue();
296 private Integer getDegFromCP(NodeId nodeId, String interfaceName) {
298 java.util.Optional<Interface> interfaceOpt = this.openRoadmInterfaces.getInterface(nodeId.getValue(),
300 if (!interfaceOpt.isPresent()) {
301 LOG.warn("Interface with {} on node {} was not found!", interfaceName, nodeId.getValue());
304 String supportingCircuitPack = interfaceOpt.get().getSupportingCircuitPackName();
305 LOG.debug("Supporting circuitpack name is :{}",
306 interfaceOpt.get().getSupportingCircuitPackName());
307 CpToDegree cpToDegree = getCPtoDegreeMapping(nodeId, supportingCircuitPack);
308 // Currently devices have different ways to represent connection to Ethernet port and degree port
309 // If Circuit pack is not present under degree tree then read parent CP of given CP(Circuit pack)
310 if (cpToDegree != null) {
311 return cpToDegree.getDegreeNumber().intValue();
313 return getDegFromParentCP(nodeId, interfaceName, supportingCircuitPack);
315 } catch (OpenRoadmInterfaceException ex) {
316 LOG.error("Failed to get source interface {} from node {}!", interfaceName, nodeId, ex);