2 * Copyright © 2017 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
9 package org.opendaylight.transportpce.common.mapping;
11 import com.google.common.util.concurrent.FluentFuture;
12 import java.util.ArrayList;
13 import java.util.Collections;
14 import java.util.Comparator;
15 import java.util.HashMap;
16 import java.util.List;
18 import java.util.Optional;
19 import java.util.concurrent.ExecutionException;
20 import java.util.stream.Collectors;
21 import org.eclipse.jdt.annotation.NonNull;
22 import org.eclipse.jdt.annotation.Nullable;
23 import org.opendaylight.mdsal.binding.api.DataBroker;
24 import org.opendaylight.mdsal.binding.api.WriteTransaction;
25 import org.opendaylight.mdsal.common.api.CommitInfo;
26 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
27 import org.opendaylight.transportpce.common.StringConstants;
28 import org.opendaylight.transportpce.common.Timeouts;
29 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
30 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaceException;
31 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
32 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev190702.Network;
33 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev190702.NetworkBuilder;
34 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev190702.network.Nodes;
35 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev190702.network.NodesBuilder;
36 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev190702.network.NodesKey;
37 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev190702.network.nodes.CpToDegree;
38 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev190702.network.nodes.CpToDegreeBuilder;
39 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev190702.network.nodes.CpToDegreeKey;
40 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev190702.network.nodes.Mapping;
41 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev190702.network.nodes.MappingBuilder;
42 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev190702.network.nodes.MappingKey;
43 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev190702.network.nodes.NodeInfo;
44 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev190702.network.nodes.NodeInfo.OpenroadmVersion;
45 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev190702.network.nodes.NodeInfoBuilder;
46 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.Direction;
47 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.NodeTypes;
48 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.CircuitPack;
49 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.Port;
50 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.pack.Ports;
51 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.pack.PortsKey;
52 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.packs.CircuitPacks;
53 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.packs.CircuitPacksKey;
54 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.degree.ConnectionPorts;
55 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.interfaces.grp.Interface;
56 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.interfaces.grp.InterfaceKey;
57 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.OrgOpenroadmDevice;
58 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.ConnectionMap;
59 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.Degree;
60 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.DegreeKey;
61 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.Info;
62 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.Protocols;
63 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.SharedRiskGroup;
64 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.org.openroadm.device.container.org.openroadm.device.SharedRiskGroupKey;
65 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.port.Interfaces;
66 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev161014.InterfaceType;
67 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev161014.OpenROADMOpticalMultiplex;
68 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev161014.OpticalTransport;
69 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.Protocols1;
70 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.lldp.container.Lldp;
71 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev161014.lldp.container.lldp.PortConfig;
72 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
73 import org.slf4j.Logger;
74 import org.slf4j.LoggerFactory;
76 public class PortMappingVersion121 {
78 private static final Logger LOG = LoggerFactory.getLogger(PortMappingImpl.class);
80 private final DataBroker dataBroker;
81 private final DeviceTransactionManager deviceTransactionManager;
82 private final OpenRoadmInterfaces openRoadmInterfaces;
84 public PortMappingVersion121(DataBroker dataBroker, DeviceTransactionManager deviceTransactionManager,
85 OpenRoadmInterfaces openRoadmInterfaces) {
86 this.dataBroker = dataBroker;
87 this.deviceTransactionManager = deviceTransactionManager;
88 this.openRoadmInterfaces = openRoadmInterfaces;
91 public boolean createMappingData(String nodeId) {
92 LOG.info("Create Mapping Data for node 1.2.1 {}", nodeId);
93 List<Mapping> portMapList = new ArrayList<>();
94 InstanceIdentifier<Info> infoIID = InstanceIdentifier.create(OrgOpenroadmDevice.class).child(Info.class);
95 Optional<Info> deviceInfoOptional = this.deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType
96 .OPERATIONAL, infoIID, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
99 if (deviceInfoOptional.isPresent()) {
100 deviceInfo = deviceInfoOptional.get();
101 nodeInfo = createNodeInfo(deviceInfo);
102 if (nodeInfo == null) {
105 postPortMapping(nodeId, nodeInfo, null, null);
108 LOG.warn("Device info subtree is absent for {}", nodeId);
112 switch (deviceInfo.getNodeType()) {
115 // Get TTP port mapping
116 if (!createTtpPortMapping(nodeId, deviceInfo, portMapList)) {
117 // return false if mapping creation for TTP's failed
118 LOG.warn("Unable to create mapping for TTP's on node {}", nodeId);
122 // Get PP port mapping
123 if (!createPpPortMapping(nodeId, deviceInfo, portMapList)) {
124 // return false if mapping creation for PP's failed
125 LOG.warn("Unable to create mapping for PP's on node {}", nodeId);
130 if (!createXpdrPortMapping(nodeId, portMapList)) {
131 LOG.warn("Unable to create mapping for Xponder on node {}", nodeId);
136 LOG.error("Unable to create mapping for node {} : unknown nodetype ", nodeId);
140 return postPortMapping(nodeId, nodeInfo, portMapList, null);
143 public boolean updateMapping(String nodeId, Mapping oldMapping) {
144 LOG.info("Updating Mapping Data {} for node {}", oldMapping, nodeId);
145 InstanceIdentifier<Ports> portIId = InstanceIdentifier.create(OrgOpenroadmDevice.class)
146 .child(CircuitPacks.class, new CircuitPacksKey(oldMapping.getSupportingCircuitPackName()))
147 .child(Ports.class, new PortsKey(oldMapping.getSupportingPort()));
148 if ((oldMapping != null) && (nodeId != null)) {
150 Optional<Ports> portObject = deviceTransactionManager.getDataFromDevice(nodeId,
151 LogicalDatastoreType.OPERATIONAL, portIId, Timeouts.DEVICE_READ_TIMEOUT,
152 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
153 if (portObject.isPresent()) {
154 Ports port = portObject.get();
155 Mapping newMapping = createMappingObject(nodeId, port, oldMapping.getSupportingCircuitPackName(),
156 oldMapping.getLogicalConnectionPoint());
158 final WriteTransaction writeTransaction = this.dataBroker.newWriteOnlyTransaction();
159 InstanceIdentifier<Mapping> mapIID = InstanceIdentifier.create(Network.class)
160 .child(Nodes.class, new NodesKey(nodeId))
161 .child(Mapping.class, new MappingKey(oldMapping.getLogicalConnectionPoint()));
162 writeTransaction.merge(LogicalDatastoreType.CONFIGURATION, mapIID, newMapping);
163 FluentFuture<? extends @NonNull CommitInfo> commit = writeTransaction.commit();
168 } catch (InterruptedException | ExecutionException e) {
169 LOG.error("Error updating Mapping {} for node {}", oldMapping.getLogicalConnectionPoint(), nodeId, e);
173 LOG.error("Impossible to update mapping");
178 private boolean createXpdrPortMapping(String nodeId, List<Mapping> portMapList) {
179 // Creating for Xponder Line and Client Ports
180 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
181 Optional<OrgOpenroadmDevice> deviceObject = deviceTransactionManager.getDataFromDevice(nodeId,
182 LogicalDatastoreType.OPERATIONAL, deviceIID,
183 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
185 // Variable to keep track of number of line ports
187 // Variable to keep track of number of client ports
189 if (!deviceObject.isPresent() || deviceObject.get().getCircuitPacks() == null) {
190 LOG.warn("Circuit Packs are not present for {}", nodeId);
192 // TODO return false or continue?
194 Map<String, String> lcpMap = new HashMap<>();
195 Map<String, Mapping> mappingMap = new HashMap<>();
197 List<CircuitPacks> circuitPackList = deviceObject.get().getCircuitPacks();
198 circuitPackList.sort(Comparator.comparing(CircuitPack::getCircuitPackName));
200 for (CircuitPacks cp : circuitPackList) {
201 String circuitPackName = cp.getCircuitPackName();
202 if (cp.getPorts() == null) {
203 LOG.warn("Ports were not found for circuit pack: {}", circuitPackName);
206 List<Ports> portList = cp.getPorts();
207 portList.sort(Comparator.comparing(Ports::getPortName));
208 for (Ports port : portList) {
209 if (port.getPortQual() == null) {
210 LOG.warn("PortQual was not found for port {} on circuit pack: {}", port.getPortName(),
214 if (Port.PortQual.XpdrNetwork.getIntValue() == port.getPortQual().getIntValue()
215 && port.getPortDirection().getIntValue() == Direction.Bidirectional.getIntValue()) {
216 String lcp = "XPDR1-" + StringConstants.NETWORK_TOKEN + line;
217 lcpMap.put(circuitPackName + '+' + port.getPortName(), lcp);
218 mappingMap.put(lcp, createXpdrMappingObject(nodeId, port, circuitPackName, lcp, null, null, null));
220 } else if (Port.PortQual.XpdrNetwork.getIntValue() == port.getPortQual().getIntValue()
221 && port.getPortDirection().getIntValue() != Direction.Bidirectional.getIntValue()
222 && port.getPartnerPort() != null
223 && port.getPartnerPort().getCircuitPackName() != null
224 && port.getPartnerPort().getPortName() != null) {
225 if (lcpMap.containsKey(circuitPackName + '+' + port.getPortName())) {
228 String lcp1 = "XPDR1-" + StringConstants.NETWORK_TOKEN + line;
229 Optional<CircuitPacks> cpOpt = circuitPackList.stream().filter(cP -> cP.getCircuitPackName()
230 .equals(port.getPartnerPort().getCircuitPackName())).findFirst();
231 if (cpOpt.isPresent()) {
232 Optional<Ports> poOpt = cpOpt.get().getPorts().stream().filter(p -> p.getPortName().equals(port
233 .getPartnerPort().getPortName().toString())).findFirst();
234 if (poOpt.isPresent()) {
235 Ports port2 = poOpt.get();
236 if ((Direction.Rx.getIntValue() == port.getPortDirection().getIntValue()
237 && Direction.Tx.getIntValue() == port2.getPortDirection().getIntValue()
238 && port2.getPartnerPort() != null && port2.getPartnerPort().getCircuitPackName() != null
239 && port2.getPartnerPort().getPortName() != null
240 && port2.getPartnerPort().getCircuitPackName().equals(circuitPackName)
241 && port2.getPartnerPort().getPortName().equals(port.getPortName()))
243 (Direction.Tx.getIntValue() == port.getPortDirection().getIntValue()
244 && Direction.Rx.getIntValue() == port2.getPortDirection().getIntValue()
245 && port2.getPartnerPort() != null && port2.getPartnerPort().getCircuitPackName() != null
246 && port2.getPartnerPort().getPortName() != null
247 && port2.getPartnerPort().getCircuitPackName().equals(circuitPackName)
248 && port2.getPartnerPort().getPortName().equals(port.getPortName()))) {
249 String lcp2 = new StringBuilder("XPDR1-").append(StringConstants.NETWORK_TOKEN)
250 .append(line + 1).toString();
251 if (!lcpMap.containsKey(lcp1) && !lcpMap.containsKey(lcp2)) {
252 lcpMap.put(circuitPackName + '+' + port.getPortName(), lcp1);
253 lcpMap.put(cpOpt.get().getCircuitPackName() + '+' + port2.getPortName(), lcp2);
254 mappingMap.put(lcp1, createXpdrMappingObject(nodeId, port, circuitPackName, lcp1,
256 mappingMap.put(lcp2, createXpdrMappingObject(nodeId, port2,
257 cpOpt.get().getCircuitPackName(), lcp2, lcp1, null, null));
259 LOG.warn("mapping already exists for {} or {}", lcp1, lcp2);
263 LOG.error("port {} on {} is not a correct partner port of {} on {}",
264 port2.getPortName(), cpOpt.get().getCircuitPackName(), port.getPortName(),
268 LOG.error("Error fetching port {} on {} for {}", port.getPartnerPort().getPortName(),
269 port.getPartnerPort().getCircuitPackName(), nodeId);
272 LOG.error("Error fetching circuit-pack {} for {}", port.getPartnerPort().getCircuitPackName(),
275 } else if (Port.PortQual.XpdrClient.getIntValue() == port.getPortQual().getIntValue()) {
276 String lcp = "XPDR1-" + StringConstants.CLIENT_TOKEN + client;
277 lcpMap.put(circuitPackName + '+' + port.getPortName(), lcp);
278 mappingMap.put(lcp, createXpdrMappingObject(nodeId, port, circuitPackName, lcp, null, null, null));
281 LOG.warn("Error in the configuration of port {} of {} for {}", port.getPortName(), circuitPackName,
286 List<ConnectionMap> connectionMap = deviceObject.get().getConnectionMap();
289 for (ConnectionMap cm : connectionMap) {
290 String skey = cm.getSource().getCircuitPackName() + "+" + cm.getSource().getPortName();
291 if (lcpMap.containsKey(skey)) {
292 slcp = lcpMap.get(skey);
294 String dkey = cm.getDestination().get(0).getCircuitPackName() + "+"
295 + cm.getDestination().get(0).getPortName();
296 if (lcpMap.containsKey(dkey)) {
297 dlcp = lcpMap.get(dkey);
300 Mapping mapping = mappingMap.get(slcp);
301 mappingMap.remove(slcp);
302 portMapList.add(createXpdrMappingObject(nodeId, null, null, null, null, mapping, dlcp));
304 LOG.error("Error in connection-map analysis");
307 if (!mappingMap.isEmpty()) {
308 for (Mapping m : mappingMap.values()) {
315 private HashMap<Integer, List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg
316 .CircuitPacks>> getSrgCps(String deviceId, Info ordmInfo) {
317 HashMap<Integer, List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg
318 .CircuitPacks>> cpPerSrg = new HashMap<>();
320 // Get value for max Srg from info subtree, required for iteration
321 // if not present assume to be 20 (temporary)
322 if (ordmInfo.getMaxSrgs() != null) {
323 maxSrg = ordmInfo.getMaxSrgs();
327 for (int srgCounter = 1; srgCounter <= maxSrg; srgCounter++) {
328 List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks> srgCps
330 LOG.info("Getting Circuitpacks for Srg Number {}", srgCounter);
331 InstanceIdentifier<SharedRiskGroup> srgIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
332 .child(SharedRiskGroup.class, new SharedRiskGroupKey(srgCounter));
333 Optional<SharedRiskGroup> ordmSrgObject = this.deviceTransactionManager.getDataFromDevice(deviceId,
334 LogicalDatastoreType.OPERATIONAL, srgIID,
335 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
336 if (ordmSrgObject.isPresent()) {
337 srgCps.addAll(ordmSrgObject.get().getCircuitPacks());
338 cpPerSrg.put(ordmSrgObject.get().getSrgNumber(), srgCps);
341 LOG.info("Device {} has {} Srg", deviceId, cpPerSrg.size());
345 //last LOG info message in this method is too long
346 @SuppressWarnings("checkstyle:linelength")
347 private boolean createPpPortMapping(String nodeId, Info deviceInfo, List<Mapping> portMapList) {
348 // Creating mapping data for SRG's PP
349 HashMap<Integer, List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks>> srgCps
350 = getSrgCps(nodeId, deviceInfo);
352 for (Integer k : srgCps.keySet()) {
353 List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks> cpList =
355 List<String> keys = new ArrayList<>();
356 for (org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg.CircuitPacks cp : cpList) {
357 String circuitPackName = cp.getCircuitPackName();
358 InstanceIdentifier<CircuitPacks> cpIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
359 .child(CircuitPacks.class, new CircuitPacksKey(circuitPackName));
360 Optional<CircuitPacks> circuitPackObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
361 LogicalDatastoreType.OPERATIONAL, cpIID,
362 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
364 if (!circuitPackObject.isPresent() || (circuitPackObject.get().getPorts() == null)) {
365 LOG.warn("{} : Circuit pack {} not found or without ports.", nodeId, circuitPackName);
369 List<Ports> portList = circuitPackObject.get().getPorts();
370 Collections.sort(portList, new SortPort121ByName());
372 for (Ports port : portList) {
373 String currentKey = circuitPackName + "-" + port.getPortName();
374 if (port.getPortQual() == null) {
376 } else if (Port.PortQual.RoadmExternal.getIntValue() == port.getPortQual().getIntValue()
377 && Direction.Bidirectional.getIntValue() == port.getPortDirection().getIntValue()
378 && !keys.contains(currentKey)) {
379 String logicalConnectionPoint = createLogicalConnectionPort(port, k, portIndex);
380 LOG.info("{} : Logical Connection Point for {} {} is {}", nodeId, circuitPackName,
381 port.getPortName(), logicalConnectionPoint);
382 portMapList.add(createMappingObject(nodeId, port, circuitPackName, logicalConnectionPoint));
384 keys.add(currentKey);
385 } else if (Port.PortQual.RoadmExternal.getIntValue() == port.getPortQual().getIntValue()
386 && (Direction.Rx.getIntValue() == port.getPortDirection().getIntValue()
387 || Direction.Tx.getIntValue() == port.getPortDirection().getIntValue())
388 && !keys.contains(currentKey)
389 && port.getPartnerPort() != null) {
390 String logicalConnectionPoint1 = createLogicalConnectionPort(port, k, portIndex);
391 LOG.info("{} : Logical Connection Point for {} {} is {}", nodeId, circuitPackName,
392 port.getPortName(), logicalConnectionPoint1);
393 InstanceIdentifier<Ports> port2ID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
394 .child(CircuitPacks.class, new CircuitPacksKey(port.getPartnerPort().getCircuitPackName()))
395 .child(Ports.class, new PortsKey(port.getPartnerPort().getPortName().toString()));
396 Optional<Ports> port2Object = this.deviceTransactionManager.getDataFromDevice(nodeId,
397 LogicalDatastoreType.OPERATIONAL, port2ID,
398 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
399 if (port2Object.isPresent()
400 && port2Object.get().getPortQual().getIntValue()
401 == Port.PortQual.RoadmExternal.getIntValue()) {
402 Ports port2 = port2Object.get();
403 if ((port.getPortDirection().getIntValue() == Direction.Rx.getIntValue()
404 && port2.getPortDirection().getIntValue() == Direction.Tx.getIntValue()
405 && port2.getPartnerPort() != null
406 && port2.getPartnerPort().getCircuitPackName().equals(circuitPackName)
407 && port2.getPartnerPort().getPortName().toString().equals(port.getPortName()))
409 (port.getPortDirection().getIntValue() == Direction.Tx.getIntValue()
410 && port2.getPortDirection().getIntValue() == Direction.Rx.getIntValue()
411 && port2.getPartnerPort() != null
412 && port2.getPartnerPort().getCircuitPackName().equals(circuitPackName)
413 && port2.getPartnerPort().getPortName().toString().equals(port.getPortName()))) {
414 String logicalConnectionPoint2 = createLogicalConnectionPort(port2, k, portIndex);
415 LOG.info("{} : Logical Connection Point for {} {} is {}", nodeId, circuitPackName,
416 port2.getPortName(), logicalConnectionPoint2);
417 portMapList.add(createMappingObject(nodeId, port, circuitPackName,
418 logicalConnectionPoint1));
419 portMapList.add(createMappingObject(nodeId, port2, port.getPartnerPort()
420 .getCircuitPackName(), logicalConnectionPoint2));
422 keys.add(currentKey);
423 keys.add(port.getPartnerPort().getCircuitPackName() + "-" + port2.getPortName());
425 LOG.error("Error with partner port configuration for port {} of {} - {}",
426 port.getPortName(), circuitPackName, nodeId);
430 LOG.error("error getting partner port {} of {} - {}",
431 port.getPartnerPort().getPortName().toString(),
432 port.getPartnerPort().getCircuitPackName(), nodeId);
436 LOG.info("{} : port {} on {} is not roadm-external or has already been handled. No logicalConnectionPoint assignment for this port.",
437 nodeId, port.getPortName(), circuitPackName);
445 private String createLogicalConnectionPort(Ports port, int index, int portIndex) {
447 switch (port.getPortDirection()) {
449 lcp = "SRG" + index + "-PP" + portIndex + "-TX";
452 lcp = "SRG" + index + "-PP" + portIndex + "-RX";
455 lcp = "SRG" + index + "-PP" + portIndex + "-TXRX";
458 LOG.error("Unsupported port direction for port {} : {}", port, port.getPortDirection());
463 private List<Degree> getDegrees(String deviceId, Info ordmInfo) {
464 List<Degree> degrees = new ArrayList<>();
467 // Get value for max degree from info subtree, required for iteration
468 // if not present assume to be 20 (temporary)
469 if (ordmInfo.getMaxDegrees() != null) {
470 maxDegree = ordmInfo.getMaxDegrees();
475 for (int degreeCounter = 1; degreeCounter <= maxDegree; degreeCounter++) {
476 LOG.info("Getting Connection ports for Degree Number {}", degreeCounter);
477 InstanceIdentifier<Degree> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
478 .child(Degree.class, new DegreeKey(degreeCounter));
479 Optional<Degree> ordmDegreeObject = this.deviceTransactionManager.getDataFromDevice(deviceId,
480 LogicalDatastoreType.OPERATIONAL, deviceIID,
481 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
482 if (ordmDegreeObject.isPresent()) {
483 degrees.add(ordmDegreeObject.get());
486 LOG.info("Device {} has {} degree", degrees.size());
490 private Map<Integer, List<ConnectionPorts>> getPerDegreePorts(String deviceId, Info ordmInfo) {
491 Map<Integer, List<ConnectionPorts>> conPortMap = new HashMap<>();
494 if (ordmInfo.getMaxDegrees() != null) {
495 maxDegree = ordmInfo.getMaxDegrees();
499 for (int degreeCounter = 1; degreeCounter <= maxDegree; degreeCounter++) {
500 LOG.info("Getting Connection ports for Degree Number {}", degreeCounter);
501 InstanceIdentifier<Degree> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
502 .child(Degree.class, new DegreeKey(degreeCounter));
503 Optional<Degree> ordmDegreeObject = this.deviceTransactionManager.getDataFromDevice(deviceId,
504 LogicalDatastoreType.OPERATIONAL, deviceIID,
505 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
506 if (ordmDegreeObject.isPresent()) {
507 conPortMap.put(degreeCounter, ordmDegreeObject.get().getConnectionPorts());
510 LOG.info("Device {} has {} degree", deviceId, conPortMap.size());
514 private Map<String, String> getEthInterfaceList(String nodeId) {
515 LOG.info("It is calling get ethernet interface");
516 Map<String, String> cpToInterfaceMap = new HashMap<>();
517 InstanceIdentifier<Protocols> protocoliid = InstanceIdentifier.create(OrgOpenroadmDevice.class)
518 .child(Protocols.class);
519 Optional<Protocols> protocolObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
520 LogicalDatastoreType.OPERATIONAL, protocoliid, Timeouts.DEVICE_READ_TIMEOUT,
521 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
522 if (protocolObject.isPresent() && protocolObject.get().augmentation(Protocols1.class).getLldp() != null) {
523 Lldp lldp = protocolObject.get().augmentation(Protocols1.class).getLldp();
524 for (PortConfig portConfig : lldp.getPortConfig()) {
525 if (portConfig.getAdminStatus().equals(PortConfig.AdminStatus.Txandrx)) {
526 InstanceIdentifier<Interface> interfaceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
527 .child(Interface.class, new InterfaceKey(portConfig.getIfName()));
528 Optional<Interface> interfaceObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
529 LogicalDatastoreType.OPERATIONAL, interfaceIID, Timeouts.DEVICE_READ_TIMEOUT,
530 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
531 if (interfaceObject.isPresent() && (interfaceObject.get().getSupportingCircuitPackName() != null)) {
532 String supportingCircuitPackName = interfaceObject.get().getSupportingCircuitPackName();
533 cpToInterfaceMap.put(supportingCircuitPackName, portConfig.getIfName());
534 InstanceIdentifier<CircuitPacks> circuitPacksIID = InstanceIdentifier
535 .create(OrgOpenroadmDevice.class)
536 .child(CircuitPacks.class, new CircuitPacksKey(supportingCircuitPackName));
537 Optional<CircuitPacks> circuitPackObject = this.deviceTransactionManager.getDataFromDevice(
538 nodeId, LogicalDatastoreType.OPERATIONAL, circuitPacksIID, Timeouts.DEVICE_READ_TIMEOUT,
539 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
540 if (circuitPackObject.isPresent() && (circuitPackObject.get().getParentCircuitPack() != null)) {
541 cpToInterfaceMap.put(circuitPackObject.get().getParentCircuitPack().getCircuitPackName(),
542 portConfig.getIfName());
548 LOG.warn("Couldnt find port config under LLDP for Node : {}", nodeId);
550 LOG.info("Processiong is done.. now returning..");
551 return cpToInterfaceMap;
554 private List<CpToDegree> getCpToDegreeList(List<Degree> degrees, String nodeId,
555 Map<String, String> interfaceList) {
556 List<CpToDegree> cpToDegreeList = new ArrayList<>();
557 for (Degree degree : degrees) {
558 if (degree.getCircuitPacks() != null) {
559 LOG.info("Inside CP to degree list");
560 cpToDegreeList.addAll(degree.getCircuitPacks().stream()
561 .map(cp -> createCpToDegreeObject(cp.getCircuitPackName(),
562 degree.getDegreeNumber().toString(), nodeId, interfaceList))
563 .collect(Collectors.toList()));
566 return cpToDegreeList;
569 private boolean postPortMapping(String nodeId, NodeInfo nodeInfo, List<Mapping> portMapList,
570 List<CpToDegree> cp2DegreeList) {
571 NodesBuilder nodesBldr = new NodesBuilder();
572 nodesBldr.withKey(new NodesKey(nodeId)).setNodeId(nodeId);
573 if (nodeInfo != null) {
574 nodesBldr.setNodeInfo(nodeInfo);
576 if (portMapList != null) {
577 nodesBldr.setMapping(portMapList);
579 if (cp2DegreeList != null) {
580 nodesBldr.setCpToDegree(cp2DegreeList);
583 List<Nodes> nodesList = new ArrayList<>();
584 nodesList.add(nodesBldr.build());
586 NetworkBuilder nwBldr = new NetworkBuilder();
587 nwBldr.setNodes(nodesList);
589 final WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
590 InstanceIdentifier<Network> nodesIID = InstanceIdentifier.builder(Network.class).build();
591 Network network = nwBldr.build();
592 writeTransaction.merge(LogicalDatastoreType.CONFIGURATION, nodesIID, network);
593 FluentFuture<? extends @NonNull CommitInfo> commit = writeTransaction.commit();
598 } catch (InterruptedException | ExecutionException e) {
599 LOG.warn("Failed to post {}", network, e);
604 private CpToDegree createCpToDegreeObject(String circuitPackName, String degreeNumber, String nodeId,
605 Map<String, String> interfaceList) {
606 String interfaceName = null;
607 if (interfaceList.get(circuitPackName) != null) {
608 interfaceName = interfaceList.get(circuitPackName);
610 return new CpToDegreeBuilder().withKey(new CpToDegreeKey(circuitPackName)).setCircuitPackName(circuitPackName)
611 .setDegreeNumber(new Long(degreeNumber)).setInterfaceName(interfaceName).build();
614 private Mapping createMappingObject(String nodeId, Ports port, String circuitPackName,
615 String logicalConnectionPoint) {
616 MappingBuilder mpBldr = new MappingBuilder();
617 mpBldr.withKey(new MappingKey(logicalConnectionPoint)).setLogicalConnectionPoint(logicalConnectionPoint)
618 .setSupportingCircuitPackName(circuitPackName).setSupportingPort(port.getPortName())
619 .setPortDirection(port.getPortDirection().getName());
621 // Get OMS and OTS interface provisioned on the TTP's
622 if (logicalConnectionPoint.contains(StringConstants.TTP_TOKEN) && (port.getInterfaces() != null)) {
623 for (Interfaces interfaces : port.getInterfaces()) {
625 Optional<Interface> openRoadmInterface = this.openRoadmInterfaces.getInterface(nodeId,
626 interfaces.getInterfaceName());
627 if (openRoadmInterface.isPresent()) {
628 Class<? extends InterfaceType> interfaceType
629 = (Class<? extends InterfaceType>) openRoadmInterface.get().getType();
630 // Check if interface type is OMS or OTS
631 if (interfaceType.equals(OpenROADMOpticalMultiplex.class)) {
632 mpBldr.setSupportingOms(interfaces.getInterfaceName());
634 if (interfaceType.equals(OpticalTransport.class)) {
635 mpBldr.setSupportingOts(interfaces.getInterfaceName());
638 LOG.warn("Interface {} from node {} was null!", interfaces.getInterfaceName(), nodeId);
640 } catch (OpenRoadmInterfaceException ex) {
641 LOG.warn("Error while getting interface {} from node {}!", interfaces.getInterfaceName(), nodeId,
646 return mpBldr.build();
649 private Mapping createXpdrMappingObject(String nodeId, Ports port, String circuitPackName,
650 String logicalConnectionPoint, String partnerLcp, Mapping mapping, String assoLcp) {
651 MappingBuilder mpBldr;
652 if (mapping != null && assoLcp != null) {
653 // update existing mapping
654 mpBldr = new MappingBuilder(mapping);
655 mpBldr.setAssociatedLcp(assoLcp);
657 // create a new mapping
658 mpBldr = new MappingBuilder();
659 mpBldr.withKey(new MappingKey(logicalConnectionPoint))
660 .setLogicalConnectionPoint(logicalConnectionPoint)
661 .setSupportingCircuitPackName(circuitPackName)
662 .setSupportingPort(port.getPortName())
663 .setPortDirection(port.getPortDirection().getName());
664 if (port.getPortQual() != null) {
665 mpBldr.setPortQual(port.getPortQual().getName());
667 if (partnerLcp != null) {
668 mpBldr.setPartnerLcp(partnerLcp);
671 return mpBldr.build();
674 // some LOG messages are too long
675 @SuppressWarnings("checkstyle:linelength")
676 private boolean createTtpPortMapping(String nodeId, Info deviceInfo, List<Mapping> portMapList) {
677 // Creating mapping data for degree TTP's
678 List<Degree> degrees = getDegrees(nodeId, deviceInfo);
679 Map<String, String> interfaceList = getEthInterfaceList(nodeId);
680 List<CpToDegree> cpToDegreeList = getCpToDegreeList(degrees, nodeId, interfaceList);
681 LOG.info("Map looks like this {}", interfaceList);
682 postPortMapping(nodeId, null, null, cpToDegreeList);
684 Map<Integer, List<ConnectionPorts>> connectionPortMap = getPerDegreePorts(nodeId, deviceInfo);
685 for (Integer k : connectionPortMap.keySet()) {
686 switch (connectionPortMap.get(k).size()) {
688 // port is bidirectional
689 InstanceIdentifier<Ports> portID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
690 .child(CircuitPacks.class, new CircuitPacksKey(connectionPortMap.get(k).get(0)
691 .getCircuitPackName()))
692 .child(Ports.class, new PortsKey(connectionPortMap.get(k).get(0)
693 .getPortName().toString()));
694 LOG.info("Fetching connection-port {} at circuit pack {}", connectionPortMap.get(k).get(0)
695 .getPortName().toString(), connectionPortMap.get(k).get(0).getCircuitPackName());
696 Optional<Ports> portObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
697 LogicalDatastoreType.OPERATIONAL, portID, Timeouts.DEVICE_READ_TIMEOUT,
698 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
699 if (portObject.isPresent()) {
700 Ports port = portObject.get();
701 if (port.getPortQual() == null) {
703 } else if (Port.PortQual.RoadmExternal.getIntValue() == port.getPortQual().getIntValue()
704 && Direction.Bidirectional.getIntValue() == port.getPortDirection().getIntValue()) {
705 String logicalConnectionPoint = new StringBuilder("DEG").append(k).append("-TTP-TXRX")
707 LOG.info("{} : Logical Connection Point for {} {} is {}", nodeId,
708 connectionPortMap.get(k).get(0).getCircuitPackName(), port.getPortName(),
709 logicalConnectionPoint);
710 portMapList.add(createMappingObject(nodeId, port,
711 connectionPortMap.get(k).get(0).getCircuitPackName(), logicalConnectionPoint));
714 "Impossible to create logical connection point for port {} of {} on node {} - Error in configuration with port-qual or port-direction",
715 port.getPortName(), connectionPortMap.get(k).get(0).getCircuitPackName(), nodeId);
718 LOG.error("No port {} on circuit pack {} for node {}",
719 connectionPortMap.get(k).get(0).getPortName().toString(),
720 connectionPortMap.get(k).get(0).getCircuitPackName(), nodeId);
725 // ports are unidirectionals
726 String cp1Name = connectionPortMap.get(k).get(0).getCircuitPackName();
727 String cp2Name = connectionPortMap.get(k).get(1).getCircuitPackName();
728 InstanceIdentifier<Ports> port1ID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
729 .child(CircuitPacks.class, new CircuitPacksKey(cp1Name))
730 .child(Ports.class, new PortsKey(connectionPortMap.get(k).get(0).getPortName().toString()));
731 LOG.info("Fetching connection-port {} at circuit pack {}", connectionPortMap.get(k).get(0)
732 .getPortName().toString(), cp1Name);
733 Optional<Ports> port1Object = this.deviceTransactionManager.getDataFromDevice(nodeId,
734 LogicalDatastoreType.OPERATIONAL, port1ID, Timeouts.DEVICE_READ_TIMEOUT,
735 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
736 InstanceIdentifier<Ports> port2ID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
737 .child(CircuitPacks.class, new CircuitPacksKey(cp2Name))
738 .child(Ports.class, new PortsKey(connectionPortMap.get(k).get(1).getPortName().toString()));
739 LOG.info("Fetching connection-port {} at circuit pack {}",
740 connectionPortMap.get(k).get(1).getPortName().toString(), cp2Name);
741 Optional<Ports> port2Object = this.deviceTransactionManager.getDataFromDevice(nodeId,
742 LogicalDatastoreType.OPERATIONAL, port2ID, Timeouts.DEVICE_READ_TIMEOUT,
743 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
744 if (port1Object.isPresent() && port2Object.isPresent()) {
745 Ports port1 = port1Object.get();
746 Ports port2 = port2Object.get();
747 if (port1.getPortQual() == null || port2.getPortQual() == null) {
749 } else if ((Port.PortQual.RoadmExternal.getIntValue() == port1.getPortQual().getIntValue()
750 && Port.PortQual.RoadmExternal.getIntValue() == port2.getPortQual().getIntValue()
751 && Direction.Rx.getIntValue() == port1.getPortDirection().getIntValue()
752 && Direction.Tx.getIntValue() == port2.getPortDirection().getIntValue()
753 && port1.getPartnerPort() != null && port2.getPartnerPort() != null
754 && port1.getPartnerPort().getCircuitPackName().equals(cp2Name)
755 && port1.getPartnerPort().getPortName().equals(port2.getPortName().toString())
756 && port2.getPartnerPort().getCircuitPackName().equals(cp1Name)
757 && port2.getPartnerPort().getPortName().equals(port1.getPortName()))
759 (Port.PortQual.RoadmExternal.getIntValue() == port1.getPortQual().getIntValue()
760 && Port.PortQual.RoadmExternal.getIntValue() == port2.getPortQual().getIntValue()
761 && Direction.Rx.getIntValue() == port2.getPortDirection().getIntValue()
762 && Direction.Tx.getIntValue() == port1.getPortDirection().getIntValue()
763 && port1.getPartnerPort() != null && port2.getPartnerPort() != null
764 && port1.getPartnerPort().getCircuitPackName().equals(cp2Name)
765 && port1.getPartnerPort().getPortName().equals(port2.getPortName().toString())
766 && port2.getPartnerPort().getCircuitPackName().equals(cp1Name)
767 && port2.getPartnerPort().getPortName().equals(port1.getPortName().toString()))) {
768 String logicalConnectionPoint1 = new StringBuilder("DEG").append(k).append("-TTP-")
769 .append(port1.getPortDirection().getName().toUpperCase()).toString();
770 LOG.info("{} : Logical Connection Point for {} {} is {}", nodeId,
771 connectionPortMap.get(k).get(0).getCircuitPackName(), port1.getPortName(),
772 logicalConnectionPoint1);
773 portMapList.add(createMappingObject(nodeId, port1, connectionPortMap.get(k).get(0)
774 .getCircuitPackName(), logicalConnectionPoint1));
775 String logicalConnectionPoint2 = new StringBuilder("DEG").append(k).append("-TTP-")
776 .append(port2.getPortDirection().getName().toUpperCase()).toString();
777 LOG.info("{} : Logical Connection Point for {} {} is {}", nodeId,
778 connectionPortMap.get(k).get(1).getCircuitPackName(), port2.getPortName(),
779 logicalConnectionPoint2);
780 portMapList.add(createMappingObject(nodeId, port2, connectionPortMap.get(k).get(1)
781 .getCircuitPackName(), logicalConnectionPoint2));
784 "Impossible to create logical connection point for port {} or port {} on node {} - Error in configuration with port-qual, port-direction or partner-port configuration",
785 port1.getPortName(), port2.getPortName(), nodeId);
788 LOG.error("No port {} on circuit pack {} for node {}",
789 connectionPortMap.get(k).get(0).getPortName().toString(),
790 connectionPortMap.get(k).get(0).getCircuitPackName(), nodeId);
796 LOG.error("Number of connection port for DEG{} on {} is incorrect", k, nodeId);
803 private NodeInfo createNodeInfo(Info deviceInfo) {
804 NodeInfoBuilder nodeInfoBldr = new NodeInfoBuilder();
805 if (deviceInfo.getNodeType() != null) {
806 nodeInfoBldr = new NodeInfoBuilder()
807 .setOpenroadmVersion(OpenroadmVersion._121);
808 if (deviceInfo.getNodeType().getIntValue() == 1) {
809 nodeInfoBldr.setNodeType(NodeTypes.Rdm);
810 } else if (deviceInfo.getNodeType().getIntValue() == 2) {
811 nodeInfoBldr.setNodeType(NodeTypes.Xpdr);
813 LOG.error("Error with node-type of {}", deviceInfo.getNodeId());
815 if (deviceInfo.getClli() != null && !deviceInfo.getClli().isEmpty()) {
816 nodeInfoBldr.setNodeClli(deviceInfo.getClli());
818 nodeInfoBldr.setNodeClli("defaultCLLI");
820 if (deviceInfo.getModel() != null) {
821 nodeInfoBldr.setNodeModel(deviceInfo.getModel());
823 if (deviceInfo.getVendor() != null) {
824 nodeInfoBldr.setNodeVendor(deviceInfo.getVendor());
826 if (deviceInfo.getIpAddress() != null) {
827 nodeInfoBldr.setNodeIpAddress(deviceInfo.getIpAddress());
830 // TODO make mandatory in yang
831 LOG.error("Node type field is missing");
834 return nodeInfoBldr.build();