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.nio.charset.Charset;
11 import java.util.ArrayList;
12 import java.util.Collection;
13 import java.util.HashMap;
14 import java.util.List;
16 import java.util.Optional;
17 import java.util.UUID;
18 import java.util.concurrent.ExecutionException;
19 import java.util.stream.Collectors;
20 import java.util.stream.Stream;
21 import org.eclipse.jdt.annotation.Nullable;
22 import org.opendaylight.mdsal.binding.api.DataBroker;
23 import org.opendaylight.mdsal.binding.api.MountPoint;
24 import org.opendaylight.mdsal.binding.api.ReadTransaction;
25 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
26 import org.opendaylight.transportpce.common.Timeouts;
27 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
28 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.Network;
29 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.cp.to.degree.CpToDegree;
30 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.mapping.Mapping;
31 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.network.Nodes;
32 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.network.NodesKey;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev170929.Direction;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.OrgOpenroadmDevice;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.Protocols;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.Protocols1;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.lldp.container.lldp.NbrList;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.lldp.container.lldp.nbr.list.IfName;
39 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
40 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.AdministrativeState;
41 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.CapacityUnit;
42 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.Context;
43 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.ForwardingDirection;
44 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.LayerProtocolName;
45 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.LifecycleState;
46 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.OperationalState;
47 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.Uuid;
48 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.capacity.TotalSizeBuilder;
49 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.capacity.pac.AvailableCapacityBuilder;
50 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.capacity.pac.TotalPotentialCapacityBuilder;
51 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.global._class.Name;
52 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev181210.global._class.NameBuilder;
53 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.Context1;
54 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.ProtectionType;
55 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.RestorationPolicy;
56 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.context.TopologyContext;
57 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.link.NodeEdgePoint;
58 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.link.NodeEdgePointBuilder;
59 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.link.NodeEdgePointKey;
60 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.link.ResilienceTypeBuilder;
61 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.OwnedNodeEdgePoint;
62 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.node.OwnedNodeEdgePointKey;
63 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.risk.parameter.pac.RiskCharacteristic;
64 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.risk.parameter.pac.RiskCharacteristicBuilder;
65 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Link;
66 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.LinkBuilder;
67 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.LinkKey;
68 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.Node;
69 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.NodeKey;
70 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.context.Topology;
71 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.topology.context.TopologyKey;
72 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.transfer.cost.pac.CostCharacteristic;
73 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.transfer.cost.pac.CostCharacteristicBuilder;
74 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.transfer.timing.pac.LatencyCharacteristic;
75 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.transfer.timing.pac.LatencyCharacteristicBuilder;
76 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.validation.pac.ValidationMechanism;
77 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.validation.pac.ValidationMechanismBuilder;
78 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
79 import org.opendaylight.yangtools.yang.common.Uint64;
80 import org.slf4j.Logger;
81 import org.slf4j.LoggerFactory;
83 public class R2RTapiLinkDiscovery {
85 private static final Logger LOG = LoggerFactory.getLogger(R2RTapiLinkDiscovery.class);
87 private final DataBroker dataBroker;
88 private final DeviceTransactionManager deviceTransactionManager;
89 private static final String PHTNC_MEDIA = "PHOTONIC_MEDIA";
91 public R2RTapiLinkDiscovery(final DataBroker dataBroker, DeviceTransactionManager deviceTransactionManager) {
92 this.dataBroker = dataBroker;
93 this.deviceTransactionManager = deviceTransactionManager;
96 public Map<LinkKey, Link> readLLDP(NodeId nodeId, int nodeVersion, Uuid tapiTopoUuid) {
97 LOG.info("Tapi R2R Link Node version = {}", nodeVersion);
98 // TODO -> waiting for device 7.1 in network model to change this to a switch statement and include
99 // support for 7.1 devices
100 switch (nodeVersion) {
103 InstanceIdentifier<Protocols> protocols121IID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
104 .child(Protocols.class);
105 Optional<Protocols> protocol121Object = this.deviceTransactionManager.getDataFromDevice(
106 nodeId.getValue(), LogicalDatastoreType.OPERATIONAL, protocols121IID, Timeouts.DEVICE_READ_TIMEOUT,
107 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
108 if (!protocol121Object.isPresent()
109 || (protocol121Object.get().augmentation(Protocols1.class) == null)) {
110 LOG.warn("LLDP subtree is missing : isolated openroadm device");
111 return new HashMap<>();
114 NbrList nbr121List = protocol121Object.get().augmentation(Protocols1.class).getLldp().getNbrList();
115 LOG.info("LLDP subtree is present. Device has {} neighbours", nbr121List.getIfName().size());
116 // try to create rdm2rdm link
117 return rdm2rdmLinkCreatev121(nodeId, tapiTopoUuid, nbr121List);
120 InstanceIdentifier<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device
121 .container.org.openroadm.device.Protocols> protocols221IID =
122 InstanceIdentifier.create(org.opendaylight.yang.gen.v1.http
123 .org.openroadm.device.rev181019.org.openroadm.device.container.OrgOpenroadmDevice.class)
124 .child(org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019
125 .org.openroadm.device.container.org.openroadm.device.Protocols.class);
126 Optional<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device
127 .container.org.openroadm.device.Protocols> protocol221Object = this.deviceTransactionManager
128 .getDataFromDevice(nodeId.getValue(), LogicalDatastoreType.OPERATIONAL, protocols221IID,
129 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
130 if (!protocol221Object.isPresent() || (protocol221Object.get().augmentation(
131 org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev181019.Protocols1.class) == null)) {
132 LOG.warn("LLDP subtree is missing : isolated openroadm device");
133 return new HashMap<>();
135 org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev181019.lldp.container.lldp.@Nullable NbrList
136 nbr221List = protocol221Object.get().augmentation(org.opendaylight.yang.gen.v1.http
137 .org.openroadm.lldp.rev181019.Protocols1.class).getLldp().getNbrList();
138 LOG.info("LLDP subtree is present. Device has {} neighbours", nbr221List.getIfName().size());
139 return rdm2rdmLinkCreatev221(nodeId, tapiTopoUuid, nbr221List);
142 LOG.info("Not yet supported?");
143 return new HashMap<>();
145 LOG.error("Unable to read LLDP data for unmanaged openroadm device version");
146 return new HashMap<>();
150 private Map<LinkKey, Link> rdm2rdmLinkCreatev221(NodeId nodeId, Uuid tapiTopoUuid,
151 org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev181019.lldp.container.lldp.NbrList nbrList) {
152 Map<LinkKey, Link> linkMap = new HashMap<>();
153 for (org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev181019.lldp.container.lldp.nbr.list.IfName
154 ifName : nbrList.nonnullIfName().values()) {
155 if (ifName.getRemoteSysName() == null) {
156 LOG.warn("Tapi R2R Link LLDP subtree neighbour is empty for nodeId: {}, ifName: {}",
157 nodeId.getValue(),ifName.getIfName());
160 Optional<MountPoint> mps = this.deviceTransactionManager.getDeviceMountPoint(ifName.getRemoteSysName());
161 if (!mps.isPresent()) {
162 LOG.warn("Tapi R2R Link Neighbouring nodeId: {} is not mounted yet", ifName.getRemoteSysName());
163 // The controller raises a warning rather than an error because the first node to
164 // mount cannot see its neighbors yet. The link will be detected when processing
165 // the neighbor node.
168 Link omsLink = createR2RTapiLink(nodeId, ifName.getIfName(), ifName.getRemoteSysName(),
169 ifName.getRemotePortId(), tapiTopoUuid);
170 if (omsLink != null) {
171 linkMap.put(omsLink.key(), omsLink);
173 LOG.error("Link was not created");
179 private Map<LinkKey, Link> rdm2rdmLinkCreatev121(NodeId nodeId, Uuid tapiTopoUuid, NbrList nbrList) {
180 Map<LinkKey, Link> linkMap = new HashMap<>();
181 for (IfName ifName : nbrList.nonnullIfName().values()) {
182 if (ifName.getRemoteSysName() == null) {
183 LOG.warn("Tapi R2R Link LLDP subtree neighbour is empty for nodeId: {}, ifName: {}",
184 nodeId.getValue(),ifName.getIfName());
187 Optional<MountPoint> mps = this.deviceTransactionManager.getDeviceMountPoint(ifName
188 .getRemoteSysName());
189 if (!mps.isPresent()) {
190 LOG.warn("Tapi R2R Link Neighbouring nodeId: {} is not mounted yet", ifName.getRemoteSysName());
191 // The controller raises a warning rather than an error because the first node to
192 // mount cannot see its neighbors yet. The link will be detected when processing
193 // the neighbor node.
196 Link omsLink = createR2RTapiLink(nodeId, ifName.getIfName(), ifName.getRemoteSysName(),
197 ifName.getRemotePortId(), tapiTopoUuid);
198 if (omsLink != null) {
199 linkMap.put(omsLink.key(), omsLink);
201 LOG.error("Link was not created");
207 public Link createR2RTapiLink(NodeId nodeId, String interfaceName, String remoteSystemName,
208 String remoteInterfaceName, Uuid tapiTopoUuid) {
209 String srcTpTx = null;
210 String srcTpRx = null;
211 String destTpTx = null;
212 String destTpRx = null;
213 // Find which degree is associated with ethernet interface
214 Integer srcDegId = getDegFromInterface(nodeId, interfaceName);
215 if (srcDegId == null) {
216 LOG.error("Tapi R2R Link Couldnt find degree connected to Ethernet interface for nodeId: {}", nodeId);
219 // Check whether degree is Unidirectional or Bidirectional by counting
221 // circuit-packs under degree subtree
222 Direction sourceDirection = getDegreeDirection(srcDegId, nodeId);
223 if (Direction.NotApplicable == sourceDirection) {
224 LOG.error("Tapi R2R Link Couldnt find degree direction for nodeId: {} and degree: {}", nodeId, srcDegId);
226 } else if (Direction.Bidirectional == sourceDirection) {
227 srcTpTx = "DEG" + srcDegId + "-TTP-TXRX";
228 srcTpRx = "DEG" + srcDegId + "-TTP-TXRX";
230 srcTpTx = "DEG" + srcDegId + "-TTP-TX";
231 srcTpRx = "DEG" + srcDegId + "-TTP-RX";
233 LOG.debug("Tapi R2R Link SrcTPTx {}, SrcTPRx {}", srcTpTx, srcTpRx);
234 // Find degree for which Ethernet interface is created on other end
235 NodeId destNodeId = new NodeId(remoteSystemName);
236 Integer destDegId = getDegFromInterface(destNodeId, remoteInterfaceName);
237 if (destDegId == null) {
238 LOG.error("Tapi R2R Link Couldnt find degree connected to Ethernet interface for nodeId: {}", nodeId);
241 // Check whether degree is Unidirectional or Bidirectional by counting
243 // circuit-packs under degree subtree
244 Direction destinationDirection = getDegreeDirection(destDegId, destNodeId);
245 if (Direction.NotApplicable == destinationDirection) {
246 LOG.error("Tapi R2R Link Couldnt find degree direction for nodeId: {} and degree: {}",
247 destNodeId, destDegId);
249 } else if (Direction.Bidirectional == destinationDirection) {
250 destTpTx = "DEG" + destDegId + "-TTP-TXRX";
251 destTpRx = "DEG" + destDegId + "-TTP-TXRX";
253 destTpTx = "DEG" + destDegId + "-TTP-TX";
254 destTpRx = "DEG" + destDegId + "-TTP-RX";
256 // Todo -> only handling for the bidirectional case. I assume all tps are of the type bidirectional
257 LOG.debug("Tapi R2R Link DstTPTx {}, DstTPRx {}", destTpTx, srcTpRx);
259 // Create OMS Tapi Link
260 LOG.info("Tapi R2R Link Found a neighbor SrcNodeId: {} , SrcDegId: {} , SrcTPId: {}, DestNodeId:{} , "
261 + "DestDegId: {}, DestTPId: {}", nodeId.getValue(), srcDegId, srcTpTx, destNodeId, destDegId, destTpRx);
262 Link omsLink = createTapiLink(nodeId.getValue(), srcTpTx, destNodeId.getValue(), destTpRx, tapiTopoUuid);
263 LOG.info("Tapi R2R Link OMS link created = {}", omsLink);
267 private Link createTapiLink(String sourceNode, String sourceTp, String destNode, String destTp, Uuid tapiTopoUuid) {
268 Map<NodeEdgePointKey, NodeEdgePoint> nepList = new HashMap<>();
269 Uuid sourceUuidNode = new Uuid(UUID.nameUUIDFromBytes((String.join("+", sourceNode,
270 PHTNC_MEDIA)).getBytes(Charset.forName("UTF-8"))).toString());
271 Uuid sourceUuidTp = new Uuid(UUID.nameUUIDFromBytes((String.join("+", sourceNode, PHTNC_MEDIA, sourceTp))
272 .getBytes(Charset.forName("UTF-8"))).toString());
273 Uuid destUuidNode = new Uuid(UUID.nameUUIDFromBytes((String.join("+", destNode,
274 PHTNC_MEDIA)).getBytes(Charset.forName("UTF-8"))).toString());
275 Uuid destUuidTp = new Uuid(UUID.nameUUIDFromBytes((String.join("+", destNode, PHTNC_MEDIA, destTp))
276 .getBytes(Charset.forName("UTF-8"))).toString());
277 NodeEdgePoint sourceNep = new NodeEdgePointBuilder()
278 .setTopologyUuid(tapiTopoUuid)
279 .setNodeUuid(sourceUuidNode)
280 .setNodeEdgePointUuid(sourceUuidTp)
282 nepList.put(sourceNep.key(), sourceNep);
283 NodeEdgePoint destNep = new NodeEdgePointBuilder()
284 .setTopologyUuid(tapiTopoUuid)
285 .setNodeUuid(destUuidNode)
286 .setNodeEdgePointUuid(destUuidTp)
288 nepList.put(destNep.key(), destNep);
289 OperationalState sourceOperState = getOperState(tapiTopoUuid, sourceUuidTp, sourceUuidNode);
290 OperationalState destOperState = getOperState(tapiTopoUuid, destUuidTp, destUuidNode);
291 if (sourceOperState == null || destOperState == null) {
292 LOG.error("No link can be created, as the operational state was not found in the TAPI topology");
295 AdministrativeState sourceAdminState = getAdminState(tapiTopoUuid, sourceUuidTp, sourceUuidNode);
296 AdministrativeState destAdminState = getAdminState(tapiTopoUuid, destUuidTp, destUuidNode);
297 if (sourceAdminState == null || destAdminState == null) {
298 LOG.error("No link can be created, as the administrative state was not found in the TAPI topology");
301 OperationalState operState = (OperationalState.ENABLED.equals(sourceOperState)
302 && OperationalState.ENABLED.equals(destOperState))
303 ? OperationalState.ENABLED : OperationalState.DISABLED;
304 AdministrativeState adminState = (AdministrativeState.UNLOCKED.equals(sourceAdminState)
305 && AdministrativeState.UNLOCKED.equals(destAdminState))
306 ? AdministrativeState.UNLOCKED : AdministrativeState.LOCKED;
307 String linkNameValue = String.join("-", sourceNode, sourceTp.split("-")[0], sourceTp)
308 + "to" + String.join("-", destNode, destTp.split("-")[0], destTp);
309 Name linkName = new NameBuilder().setValueName("OMS link name")
310 .setValue(linkNameValue)
312 CostCharacteristic costCharacteristic = new CostCharacteristicBuilder()
313 .setCostAlgorithm("Restricted Shortest Path - RSP")
314 .setCostName("HOP_COUNT")
315 .setCostValue("12345678")
317 LatencyCharacteristic latencyCharacteristic = new LatencyCharacteristicBuilder()
318 .setFixedLatencyCharacteristic("12345678")
319 .setQueingLatencyCharacteristic("12345678")
320 .setJitterCharacteristic("12345678")
321 .setWanderCharacteristic("12345678")
322 .setTrafficPropertyName("FIXED_LATENCY")
324 RiskCharacteristic riskCharacteristic = new RiskCharacteristicBuilder()
325 .setRiskCharacteristicName("risk characteristic")
326 .setRiskIdentifierList(List.of("risk identifier1", "risk identifier2"))
328 ValidationMechanism validationMechanism = new ValidationMechanismBuilder()
329 .setValidationMechanism("validation mechanism")
330 .setValidationRobustness("validation robustness")
331 .setLayerProtocolAdjacencyValidated("layer protocol adjacency")
333 return new LinkBuilder()
335 UUID.nameUUIDFromBytes(linkNameValue.getBytes(Charset.forName("UTF-8")))
337 .setName(Map.of(linkName.key(), linkName))
338 .setLayerProtocolName(List.of(LayerProtocolName.PHOTONICMEDIA))
339 .setTransitionedLayerProtocolName(new ArrayList<>())
340 .setNodeEdgePoint(nepList)
341 .setDirection(ForwardingDirection.BIDIRECTIONAL)
342 .setResilienceType(new ResilienceTypeBuilder().setProtectionType(ProtectionType.NOPROTECTON)
343 .setRestorationPolicy(RestorationPolicy.NA)
345 .setAdministrativeState(adminState)
346 .setOperationalState(operState)
347 .setLifecycleState(LifecycleState.INSTALLED)
348 .setTotalPotentialCapacity(new TotalPotentialCapacityBuilder().setTotalSize(
349 new TotalSizeBuilder().setUnit(CapacityUnit.GBPS)
350 .setValue(Uint64.valueOf(100)).build()).build())
351 .setAvailableCapacity(new AvailableCapacityBuilder().setTotalSize(
352 new TotalSizeBuilder().setUnit(CapacityUnit.MBPS)
353 .setValue(Uint64.valueOf(100)).build())
355 .setCostCharacteristic(Map.of(costCharacteristic.key(), costCharacteristic))
356 .setLatencyCharacteristic(Map.of(latencyCharacteristic.key(), latencyCharacteristic))
357 .setRiskCharacteristic(Map.of(riskCharacteristic.key(), riskCharacteristic))
358 .setErrorCharacteristic("error")
359 .setLossCharacteristic("loss")
360 .setRepeatDeliveryCharacteristic("repeat delivery")
361 .setDeliveryOrderCharacteristic("delivery order")
362 .setUnavailableTimeCharacteristic("unavailable time")
363 .setServerIntegrityProcessCharacteristic("server integrity process")
364 .setValidationMechanism(Map.of(validationMechanism.key(), validationMechanism))
368 private Integer getDegFromInterface(NodeId nodeId, String interfaceName) {
369 InstanceIdentifier<Nodes> nodesIID = InstanceIdentifier.builder(Network.class)
370 .child(Nodes.class, new NodesKey(nodeId.getValue())).build();
371 try (ReadTransaction readTx = this.dataBroker.newReadOnlyTransaction()) {
372 Optional<Nodes> nodesObject = readTx.read(LogicalDatastoreType.CONFIGURATION, nodesIID).get();
373 if (nodesObject.isEmpty() || (nodesObject.get().getCpToDegree() == null)) {
374 LOG.warn("Could not find mapping for Interface {} for nodeId {}", interfaceName,
378 Collection<CpToDegree> cpToDeg = nodesObject.get().nonnullCpToDegree().values();
379 Stream<CpToDegree> cpToDegStream = cpToDeg.stream().filter(cp -> cp.getInterfaceName() != null)
380 .filter(cp -> cp.getInterfaceName().equals(interfaceName));
381 if (cpToDegStream != null) {
382 @SuppressWarnings("unchecked") Optional<CpToDegree> firstCpToDegree = cpToDegStream.findFirst();
383 if (firstCpToDegree.isEmpty() || (firstCpToDegree == null)) {
384 LOG.debug("Not found so returning nothing");
387 LOG.debug("Found and returning {}",firstCpToDegree.get().getDegreeNumber().intValue());
388 return firstCpToDegree.get().getDegreeNumber().intValue();
390 LOG.warn("CircuitPack stream couldnt find anything for nodeId: {} and interfaceName: {}",
391 nodeId.getValue(),interfaceName);
393 } catch (InterruptedException | ExecutionException ex) {
394 LOG.error("Unable to read mapping for Interface : {} for nodeId {}", interfaceName, nodeId, ex);
399 public Direction getDegreeDirection(Integer degreeCounter, NodeId nodeId) {
400 InstanceIdentifier<Nodes> nodesIID = InstanceIdentifier.builder(Network.class)
401 .child(Nodes.class, new NodesKey(nodeId.getValue())).build();
402 try (ReadTransaction readTx = this.dataBroker.newReadOnlyTransaction()) {
403 Optional<Nodes> nodesObject = readTx.read(LogicalDatastoreType.CONFIGURATION, nodesIID).get();
404 if (nodesObject.isPresent() && (nodesObject.get().getMapping() != null)) {
405 Collection<Mapping> mappingList = nodesObject.get().nonnullMapping().values();
406 mappingList = mappingList.stream().filter(mp -> mp.getLogicalConnectionPoint().contains("DEG"
407 + degreeCounter)).collect(Collectors.toList());
408 if (mappingList.size() == 1) {
409 return Direction.Bidirectional;
410 } else if (mappingList.size() > 1) {
414 } catch (InterruptedException | ExecutionException e) {
415 LOG.error("Failed getting Mapping data from portMapping",e);
417 return Direction.NotApplicable;
420 private OperationalState getOperState(Uuid tapiTopoUuid, Uuid nepUuid, Uuid nodeUuid) {
421 InstanceIdentifier<OwnedNodeEdgePoint> onepIID = InstanceIdentifier.builder(Context.class)
422 .augmentation(Context1.class).child(TopologyContext.class)
423 .child(Topology.class, new TopologyKey(tapiTopoUuid)).child(Node.class, new NodeKey(nodeUuid))
424 .child(OwnedNodeEdgePoint.class, new OwnedNodeEdgePointKey(nepUuid))
426 try (ReadTransaction readTx = this.dataBroker.newReadOnlyTransaction()) {
427 Optional<OwnedNodeEdgePoint> optionalOnep = readTx.read(LogicalDatastoreType.OPERATIONAL, onepIID).get();
428 if (optionalOnep.isPresent()) {
429 return optionalOnep.get().getOperationalState();
432 } catch (InterruptedException | ExecutionException e) {
433 LOG.error("Failed getting Mapping data from portMapping",e);
438 private AdministrativeState getAdminState(Uuid tapiTopoUuid, Uuid nepUuid, Uuid nodeUuid) {
439 InstanceIdentifier<OwnedNodeEdgePoint> onepIID = InstanceIdentifier.builder(Context.class)
440 .augmentation(Context1.class).child(TopologyContext.class)
441 .child(Topology.class, new TopologyKey(tapiTopoUuid)).child(Node.class, new NodeKey(nodeUuid))
442 .child(OwnedNodeEdgePoint.class, new OwnedNodeEdgePointKey(nepUuid))
444 try (ReadTransaction readTx = this.dataBroker.newReadOnlyTransaction()) {
445 Optional<OwnedNodeEdgePoint> optionalOnep = readTx.read(LogicalDatastoreType.OPERATIONAL, onepIID).get();
446 if (optionalOnep.isPresent()) {
447 return optionalOnep.get().getAdministrativeState();
450 } catch (InterruptedException | ExecutionException e) {
451 LOG.error("Failed getting Mapping data from portMapping",e);