2 * Copyright © 2017 Orange, Inc. 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.CheckedFuture;
12 import java.util.ArrayList;
13 import java.util.Comparator;
14 import java.util.HashMap;
15 import java.util.List;
17 import java.util.Optional;
18 import java.util.stream.Collectors;
20 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
21 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
22 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
23 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
24 import org.opendaylight.transportpce.common.StringConstants;
25 import org.opendaylight.transportpce.common.Timeouts;
26 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
27 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaceException;
28 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
29 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev170228.Network;
30 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev170228.NetworkBuilder;
31 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev170228.network.Nodes;
32 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev170228.network.NodesBuilder;
33 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev170228.network.NodesKey;
34 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev170228.network.nodes.CpToDegree;
35 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev170228.network.nodes.CpToDegreeBuilder;
36 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev170228.network.nodes.CpToDegreeKey;
37 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev170228.network.nodes.Mapping;
38 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev170228.network.nodes.MappingBuilder;
39 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev170228.network.nodes.MappingKey;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.NodeTypes;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev181019.Direction;
42 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.Port;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.CircuitPack;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.circuit.pack.Ports;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.circuit.pack.PortsKey;
46 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.circuit.packs.CircuitPacks;
47 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.circuit.packs.CircuitPacksKey;
48 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.degree.ConnectionPorts;
49 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.interfaces.grp.Interface;
50 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.interfaces.grp.InterfaceKey;
51 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container.OrgOpenroadmDevice;
52 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container.org.openroadm.device.ConnectionMap;
53 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container.org.openroadm.device.Degree;
54 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container.org.openroadm.device.DegreeKey;
55 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container.org.openroadm.device.Info;
56 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container.org.openroadm.device.Protocols;
57 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container.org.openroadm.device.SharedRiskGroup;
58 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.org.openroadm.device.container.org.openroadm.device.SharedRiskGroupKey;
59 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.port.Interfaces;
61 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev170626.InterfaceType;
62 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev170626.OpenROADMOpticalMultiplex;
63 import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev170626.OpticalTransport;
64 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev181019.Protocols1;
65 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev181019.lldp.container.Lldp;
66 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev181019.lldp.container.lldp.PortConfig;
67 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
68 import org.slf4j.Logger;
69 import org.slf4j.LoggerFactory;
71 public class PortMappingVersion221 {
72 private static final Logger LOG = LoggerFactory.getLogger(PortMappingImpl.class);
74 private final DataBroker dataBroker;
75 private final DeviceTransactionManager deviceTransactionManager;
76 private final OpenRoadmInterfaces openRoadmInterfaces;
78 public PortMappingVersion221(DataBroker dataBroker, DeviceTransactionManager deviceTransactionManager,
79 OpenRoadmInterfaces openRoadmInterfaces) {
80 this.dataBroker = dataBroker;
81 this.deviceTransactionManager = deviceTransactionManager;
82 this.openRoadmInterfaces = openRoadmInterfaces;
85 public boolean createMappingData(String nodeId) {
87 LOG.info("Create Mapping Data for node 2.2.1 {}", nodeId);
88 List<Mapping> portMapList = new ArrayList<>();
89 InstanceIdentifier<Info> infoIID = InstanceIdentifier.create(OrgOpenroadmDevice.class).child(Info.class);
90 Optional<Info> deviceInfoOptional = this.deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType
91 .OPERATIONAL, infoIID, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
94 if (deviceInfoOptional.isPresent()) {
95 deviceInfo = deviceInfoOptional.get();
97 LOG.warn("Device info subtree is absent for {}", nodeId);
100 if (deviceInfo.getNodeType() == null) {
101 LOG.error("Node type field is missing"); // TODO make mandatory in yang
104 switch (deviceInfo.getNodeType()) {
107 // Get TTP port mapping
108 if (!createTtpPortMapping(nodeId, deviceInfo, portMapList)) {
109 // return false if mapping creation for TTP's failed
110 LOG.warn("Unable to create mapping for TTP's on node {}", nodeId);
114 // Get PP port mapping
115 if (!createPpPortMapping(nodeId, deviceInfo, portMapList)) {
116 // return false if mapping creation for PP's failed
117 LOG.warn("Unable to create mapping for PP's on node {}", nodeId);
122 if (!createXpdrPortMapping(nodeId, portMapList)) {
123 LOG.warn("Unable to create mapping for Xponder on node {}", nodeId);
128 LOG.error("Unable to create mapping for node {} : unknown nodetype ", nodeId);
132 return postPortMapping(deviceInfo, portMapList, deviceInfo.getNodeType().getIntValue(), null);
135 public boolean updateMapping(String nodeId, Mapping oldMapping) {
136 LOG.info("Updating Mapping Data {} for node {}", oldMapping, nodeId);
137 InstanceIdentifier<Ports> portIId = InstanceIdentifier.create(OrgOpenroadmDevice.class)
138 .child(CircuitPacks.class, new CircuitPacksKey(oldMapping.getSupportingCircuitPackName()))
139 .child(Ports.class, new PortsKey(oldMapping.getSupportingPort()));
140 if ((oldMapping != null) && (nodeId != null)) {
142 Optional<Ports> portObject = deviceTransactionManager.getDataFromDevice(nodeId,
143 LogicalDatastoreType.OPERATIONAL, portIId, Timeouts.DEVICE_READ_TIMEOUT,
144 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
145 if (portObject.isPresent()) {
146 Ports port = portObject.get();
147 Mapping newMapping = createMappingObject(nodeId, port, oldMapping.getSupportingCircuitPackName(),
148 oldMapping.getLogicalConnectionPoint());
150 final WriteTransaction writeTransaction = this.dataBroker.newWriteOnlyTransaction();
151 InstanceIdentifier<Mapping> mapIID = InstanceIdentifier.create(Network.class)
152 .child(Nodes.class, new NodesKey(nodeId))
153 .child(Mapping.class, new MappingKey(oldMapping.getLogicalConnectionPoint()));
154 writeTransaction.merge(LogicalDatastoreType.CONFIGURATION, mapIID, newMapping);
155 CheckedFuture<Void, TransactionCommitFailedException> submit = writeTransaction.submit();
160 } catch (TransactionCommitFailedException e) {
161 LOG.error("Transaction Commit Error updating Mapping {} for node {}", oldMapping
162 .getLogicalConnectionPoint(), nodeId, e);
166 LOG.error("Impossible to update mapping");
171 private boolean createXpdrPortMapping(String nodeId, List<Mapping> portMapList) {
172 // Creating for Xponder Line and Client Ports
173 InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
174 Optional<OrgOpenroadmDevice> deviceObject = deviceTransactionManager.getDataFromDevice(nodeId,
175 LogicalDatastoreType.OPERATIONAL, deviceIID,
176 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
178 // Variable to keep track of number of line ports
180 // Variable to keep track of number of client ports
182 if (!deviceObject.isPresent() || deviceObject.get().getCircuitPacks() == null) {
183 LOG.warn("Circuit Packs are not present for {}", nodeId);
184 return false; // TODO return false or continue?
186 Map<String, String> lcpMap = new HashMap<>();
187 Map<String, Mapping> mappingMap = new HashMap<>();
189 List<CircuitPacks> circuitPackList = deviceObject.get().getCircuitPacks();
190 circuitPackList.sort(Comparator.comparing(CircuitPack::getCircuitPackName));
192 for (CircuitPacks cp : circuitPackList) {
193 String circuitPackName = cp.getCircuitPackName();
194 if (cp.getPorts() == null) {
195 LOG.warn("Ports were not found for circuit pack: {}", circuitPackName);
198 List<Ports> portList = cp.getPorts();
199 portList.sort(Comparator.comparing(Ports::getPortName));
200 for (Ports port : portList) {
201 if (port.getPortQual() == null) {
202 LOG.warn("PortQual was not found for port {} on circuit pack: {}", port.getPortName(),
206 if (Port.PortQual.XpdrNetwork.getIntValue() == port.getPortQual().getIntValue()
207 && port.getPortDirection().getIntValue() == Direction.Bidirectional.getIntValue()) {
208 String lcp = "XPDR1-" + StringConstants.NETWORK_TOKEN + line;
209 lcpMap.put(circuitPackName + '+' + port.getPortName(), lcp);
210 mappingMap.put(lcp, createXpdrMappingObject(nodeId, port, circuitPackName, lcp, null, null, null));
212 } else if (Port.PortQual.XpdrNetwork.getIntValue() == port.getPortQual().getIntValue()
213 && port.getPortDirection().getIntValue() != Direction.Bidirectional.getIntValue()
214 && port.getPartnerPort() != null
215 && port.getPartnerPort().getCircuitPackName() != null
216 && port.getPartnerPort().getPortName() != null) {
217 if (lcpMap.containsKey(circuitPackName + '+' + port.getPortName())) {
220 String lcp1 = "XPDR1-" + StringConstants.NETWORK_TOKEN + line;
221 Optional<CircuitPacks> cpOpt = circuitPackList.stream().filter(cP -> cP.getCircuitPackName()
222 .equals(port.getPartnerPort().getCircuitPackName())).findFirst();
223 if (cpOpt.isPresent()) {
224 Optional<Ports> poOpt = cpOpt.get().getPorts().stream().filter(p -> p.getPortName().equals(port
225 .getPartnerPort().getPortName().toString())).findFirst();
226 if (poOpt.isPresent()) {
227 Ports port2 = poOpt.get();
228 if ((Direction.Rx.getIntValue() == port.getPortDirection().getIntValue()
229 && Direction.Tx.getIntValue() == port2.getPortDirection().getIntValue()
230 && port2.getPartnerPort() != null && port2.getPartnerPort().getCircuitPackName() != null
231 && port2.getPartnerPort().getPortName() != null
232 && port2.getPartnerPort().getCircuitPackName().equals(circuitPackName)
233 && port2.getPartnerPort().getPortName().equals(port.getPortName()))
235 (Direction.Tx.getIntValue() == port.getPortDirection().getIntValue()
236 && Direction.Rx.getIntValue() == port2.getPortDirection().getIntValue()
237 && port2.getPartnerPort() != null && port2.getPartnerPort().getCircuitPackName() != null
238 && port2.getPartnerPort().getPortName() != null
239 && port2.getPartnerPort().getCircuitPackName().equals(circuitPackName)
240 && port2.getPartnerPort().getPortName().equals(port.getPortName()))) {
241 String lcp2 = new StringBuilder("XPDR1-").append(StringConstants.NETWORK_TOKEN)
242 .append(line + 1).toString();
243 if (!lcpMap.containsKey(lcp1) && !lcpMap.containsKey(lcp2)) {
244 lcpMap.put(circuitPackName + '+' + port.getPortName(), lcp1);
245 lcpMap.put(cpOpt.get().getCircuitPackName() + '+' + port2.getPortName(), lcp2);
246 mappingMap.put(lcp1, createXpdrMappingObject(nodeId, port, circuitPackName, lcp1,
248 mappingMap.put(lcp2, createXpdrMappingObject(nodeId, port2, cpOpt.get()
249 .getCircuitPackName(), lcp2, lcp1, null, null));
251 LOG.warn("mapping already exists for {} or {}", lcp1, lcp2);
255 LOG.error("port {} on {} is not a correct partner port of {} on {}",
256 port2.getPortName(), cpOpt.get().getCircuitPackName(), port.getPortName(),
260 LOG.error("Error fetching port {} on {} for {}", port.getPartnerPort().getPortName(),
261 port.getPartnerPort().getCircuitPackName(), nodeId);
264 LOG.error("Error fetching circuit-pack {} for {}", port.getPartnerPort().getCircuitPackName(),
267 } else if (Port.PortQual.XpdrClient.getIntValue() == port.getPortQual().getIntValue()) {
268 String lcp = "XPDR1-" + StringConstants.CLIENT_TOKEN + client;
269 lcpMap.put(circuitPackName + '+' + port.getPortName(), lcp);
270 mappingMap.put(lcp, createXpdrMappingObject(nodeId, port, circuitPackName, lcp, null, null, null));
273 LOG.warn("Error in the configuration of port {} of {} for {}", port.getPortName(), circuitPackName,
278 List<ConnectionMap> connectionMap = deviceObject.get().getConnectionMap();
281 for (ConnectionMap cm : connectionMap) {
282 String skey = cm.getSource().getCircuitPackName() + "+" + cm.getSource().getPortName();
283 if (lcpMap.containsKey(skey)) {
284 slcp = lcpMap.get(skey);
286 String dkey = cm.getDestination().get(0).getCircuitPackName() + "+"
287 + cm.getDestination().get(0).getPortName();
288 if (lcpMap.containsKey(dkey)) {
289 dlcp = lcpMap.get(dkey);
292 Mapping mapping = mappingMap.get(slcp);
293 mappingMap.remove(slcp);
294 portMapList.add(createXpdrMappingObject(nodeId, null, null, null, null, mapping, dlcp));
296 LOG.error("Error in connection-map analysis");
299 if (!mappingMap.isEmpty()) {
300 for (Mapping m : mappingMap.values()) {
307 private HashMap<Integer, List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.srg
308 .CircuitPacks>> getSrgCps(String deviceId, Info ordmInfo) {
309 HashMap<Integer, List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.srg
310 .CircuitPacks>> cpPerSrg = new HashMap<>();
312 // Get value for max Srg from info subtree, required for iteration
313 // if not present assume to be 20 (temporary)
314 if (ordmInfo.getMaxSrgs() != null) {
315 maxSrg = ordmInfo.getMaxSrgs();
319 for (int srgCounter = 1; srgCounter <= maxSrg; srgCounter++) {
320 List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.srg.CircuitPacks> srgCps
322 LOG.info("Getting Circuitpacks for Srg Number {}", srgCounter);
323 InstanceIdentifier<SharedRiskGroup> srgIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
324 .child(SharedRiskGroup.class, new SharedRiskGroupKey(srgCounter));
325 Optional<SharedRiskGroup> ordmSrgObject = this.deviceTransactionManager.getDataFromDevice(deviceId,
326 LogicalDatastoreType.OPERATIONAL, srgIID,
327 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
328 if (ordmSrgObject.isPresent()) {
329 srgCps.addAll(ordmSrgObject.get().getCircuitPacks());
330 cpPerSrg.put(ordmSrgObject.get().getSrgNumber(), srgCps);
333 LOG.info("Device {} has {} Srg", deviceId, cpPerSrg.size());
337 private boolean createPpPortMapping(String nodeId, Info deviceInfo, List<Mapping> portMapList) {
338 // Creating mapping data for SRG's PP
339 HashMap<Integer, List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.srg.CircuitPacks>> srgCps
340 = getSrgCps(nodeId, deviceInfo);
342 for (Integer k : srgCps.keySet()) {
343 List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.srg.CircuitPacks> cpList =
345 List<String> keys = new ArrayList<>();
346 for (org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.srg.CircuitPacks cp : cpList) {
347 String circuitPackName = cp.getCircuitPackName();
348 InstanceIdentifier<CircuitPacks> cpIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
349 .child(CircuitPacks.class, new CircuitPacksKey(circuitPackName));
350 Optional<CircuitPacks> circuitPackObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
351 LogicalDatastoreType.OPERATIONAL, cpIID,
352 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
354 if (!circuitPackObject.isPresent() || (circuitPackObject.get().getPorts() == null)) {
355 LOG.warn("{} : Circuit pack {} not found or without ports.", nodeId, circuitPackName);
356 continue; // TODO continue or return false?
358 List<Ports> portList = circuitPackObject.get().getPorts();
359 portList.sort(Comparator.comparing(Ports::getPortName));
361 for (Ports port : portList) {
362 String currentKey = circuitPackName + "-" + port.getPortName();
363 if (port.getPortQual() == null) {
365 } else if (Port.PortQual.RoadmExternal.getIntValue() == port.getPortQual().getIntValue()
366 && Direction.Bidirectional.getIntValue() == port.getPortDirection().getIntValue()
367 && !keys.contains(currentKey)) {
368 String logicalConnectionPoint = createLogicalConnectionPort(port, k, portIndex);
369 LOG.info("{} : Logical Connection Point for {} {} is {}", nodeId, circuitPackName,
370 port.getPortName(), logicalConnectionPoint);
371 portMapList.add(createMappingObject(nodeId, port, circuitPackName, logicalConnectionPoint));
373 keys.add(currentKey);
374 } else if (Port.PortQual.RoadmExternal.getIntValue() == port.getPortQual().getIntValue()
375 && (Direction.Rx.getIntValue() == port.getPortDirection().getIntValue()
376 || Direction.Tx.getIntValue() == port.getPortDirection().getIntValue())
377 && !keys.contains(currentKey)
378 && port.getPartnerPort() != null) {
379 String logicalConnectionPoint1 = createLogicalConnectionPort(port, k, portIndex);
380 LOG.info("{} : Logical Connection Point for {} {} is {}", nodeId, circuitPackName,
381 port.getPortName(), logicalConnectionPoint1);
382 InstanceIdentifier<Ports> port2ID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
383 .child(CircuitPacks.class, new CircuitPacksKey(port.getPartnerPort().getCircuitPackName()))
384 .child(Ports.class, new PortsKey(port.getPartnerPort().getPortName().toString()));
385 Optional<Ports> port2Object = this.deviceTransactionManager.getDataFromDevice(nodeId,
386 LogicalDatastoreType.OPERATIONAL, port2ID,
387 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
388 if (port2Object.isPresent() && port2Object.get().getPortQual().getIntValue() ==
389 Port.PortQual.RoadmExternal.getIntValue()) {
390 Ports port2 = port2Object.get();
391 if ((port.getPortDirection().getIntValue() == Direction.Rx.getIntValue()
392 && port2.getPortDirection().getIntValue() == Direction.Tx.getIntValue()
393 && port2.getPartnerPort() != null
394 && port2.getPartnerPort().getCircuitPackName().equals(circuitPackName)
395 && port2.getPartnerPort().getPortName().toString().equals(port.getPortName()))
397 (port.getPortDirection().getIntValue() == Direction.Tx.getIntValue()
398 && port2.getPortDirection().getIntValue() == Direction.Rx.getIntValue()
399 && port2.getPartnerPort() != null
400 && port2.getPartnerPort().getCircuitPackName().equals(circuitPackName)
401 && port2.getPartnerPort().getPortName().toString().equals(port.getPortName()))) {
402 String logicalConnectionPoint2 = createLogicalConnectionPort(port2, k, portIndex);
403 LOG.info("{} : Logical Connection Point for {} {} is {}", nodeId, circuitPackName,
404 port2.getPortName(), logicalConnectionPoint2);
405 portMapList.add(createMappingObject(nodeId, port, circuitPackName,
406 logicalConnectionPoint1));
407 portMapList.add(createMappingObject(nodeId,port2,
408 port.getPartnerPort().getCircuitPackName(), logicalConnectionPoint2));
410 keys.add(currentKey);
411 keys.add(port.getPartnerPort().getCircuitPackName() + "-" + port2.getPortName());
413 LOG.error("Error with partner port configuration for port {} of {} - {}",
414 port.getPortName(), circuitPackName, nodeId);
418 LOG.error("error getting partner port {} of {} - {}", port.getPartnerPort().getPortName()
419 .toString(), port.getPartnerPort().getCircuitPackName(), nodeId);
423 LOG.info("{} : port {} on {} is not roadm-external or has already been handled."
424 + "No logicalConnectionPoint assignment for this port.",
425 nodeId, port.getPortName(), circuitPackName);
433 private String createLogicalConnectionPort(Ports port, int index, int portIndex) {
435 switch (port.getPortDirection()) {
437 lcp = "SRG" + index + "-PP" + portIndex + "-TX";
440 lcp = "SRG" + index + "-PP" + portIndex + "-RX";
443 lcp = "SRG" + index + "-PP" + portIndex + "-TXRX";
446 LOG.error("Unsupported port direction for port {} : {}", port, port.getPortDirection());
451 private List<Degree> getDegrees(String deviceId, Info ordmInfo) {
452 List<Degree> degrees = new ArrayList<>();
455 // Get value for max degree from info subtree, required for iteration
456 // if not present assume to be 20 (temporary)
457 if (ordmInfo.getMaxDegrees() != null) {
458 maxDegree = ordmInfo.getMaxDegrees();
463 for (int degreeCounter = 1; degreeCounter <= maxDegree; degreeCounter++) {
464 LOG.info("Getting Connection ports for Degree Number {}", degreeCounter);
465 InstanceIdentifier<Degree> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
466 .child(Degree.class, new DegreeKey(degreeCounter));
467 Optional<Degree> ordmDegreeObject = this.deviceTransactionManager.getDataFromDevice(deviceId,
468 LogicalDatastoreType.OPERATIONAL, deviceIID,
469 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
470 if (ordmDegreeObject.isPresent()) {
471 degrees.add(ordmDegreeObject.get());
474 LOG.info("Device {} has {} degree", degrees.size());
478 private Map<Integer, List<ConnectionPorts>> getPerDegreePorts(String deviceId, Info ordmInfo) {
479 Map<Integer, List<ConnectionPorts>> conPortMap = new HashMap<>();
482 if (ordmInfo.getMaxDegrees() != null) {
483 maxDegree = ordmInfo.getMaxDegrees();
487 for (int degreeCounter = 1; degreeCounter <= maxDegree; degreeCounter++) {
488 LOG.info("Getting Connection ports for Degree Number {}", degreeCounter);
489 InstanceIdentifier<Degree> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
490 .child(Degree.class, new DegreeKey(degreeCounter));
491 Optional<Degree> ordmDegreeObject = this.deviceTransactionManager.getDataFromDevice(deviceId,
492 LogicalDatastoreType.OPERATIONAL, deviceIID,
493 Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
494 if (ordmDegreeObject.isPresent()) {
495 conPortMap.put(degreeCounter, ordmDegreeObject.get().getConnectionPorts());
498 LOG.info("Device {} has {} degree", deviceId, conPortMap.size());
502 private Map<String, String> getEthInterfaceList(String nodeId) {
503 LOG.info("It is calling get ethernet interface");
504 Map<String, String> cpToInterfaceMap = new HashMap<>();
505 InstanceIdentifier<Protocols> protocoliid = InstanceIdentifier.create(OrgOpenroadmDevice.class)
506 .child(Protocols.class);
507 Optional<Protocols> protocolObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
508 LogicalDatastoreType.OPERATIONAL, protocoliid, Timeouts.DEVICE_READ_TIMEOUT,
509 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
510 if (protocolObject.isPresent() && protocolObject.get().augmentation(Protocols1.class).getLldp() != null) {
511 Lldp lldp = protocolObject.get().augmentation(Protocols1.class).getLldp();
512 for (PortConfig portConfig : lldp.getPortConfig()) {
513 if (portConfig.getAdminStatus().equals(PortConfig.AdminStatus.Txandrx)) {
514 InstanceIdentifier<Interface> interfaceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
515 .child(Interface.class, new InterfaceKey(portConfig.getIfName()));
516 Optional<Interface> interfaceObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
517 LogicalDatastoreType.OPERATIONAL, interfaceIID, Timeouts.DEVICE_READ_TIMEOUT,
518 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
519 if (interfaceObject.isPresent() && (interfaceObject.get().getSupportingCircuitPackName() != null)) {
520 String supportingCircuitPackName = interfaceObject.get().getSupportingCircuitPackName();
521 cpToInterfaceMap.put(supportingCircuitPackName, portConfig.getIfName());
522 InstanceIdentifier<CircuitPacks> circuitPacksIID = InstanceIdentifier
523 .create(OrgOpenroadmDevice.class)
524 .child(CircuitPacks.class, new CircuitPacksKey(supportingCircuitPackName));
525 Optional<CircuitPacks> circuitPackObject = this.deviceTransactionManager.getDataFromDevice(
526 nodeId, LogicalDatastoreType.OPERATIONAL, circuitPacksIID, Timeouts.DEVICE_READ_TIMEOUT,
527 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
528 if (circuitPackObject.isPresent() && (circuitPackObject.get().getParentCircuitPack() != null)) {
529 cpToInterfaceMap.put(circuitPackObject.get().getParentCircuitPack().getCircuitPackName(),
530 portConfig.getIfName());
536 LOG.warn("Couldnt find port config under LLDP for Node : {}", nodeId);
538 LOG.info("Processiong is done.. now returning..");
539 return cpToInterfaceMap;
542 private List<CpToDegree> getCpToDegreeList(List<Degree> degrees, String nodeId,
543 Map<String, String> interfaceList) {
544 List<CpToDegree> cpToDegreeList = new ArrayList<>();
545 for (Degree degree : degrees) {
546 if (degree.getCircuitPacks() != null) {
547 LOG.info("Inside CP to degree list");
548 cpToDegreeList.addAll(degree.getCircuitPacks().stream()
549 .map(cp -> createCpToDegreeObject(cp.getCircuitPackName(),
550 degree.getDegreeNumber().toString(), nodeId, interfaceList))
551 .collect(Collectors.toList()));
554 return cpToDegreeList;
557 private boolean postPortMapping(Info deviceInfo, List<Mapping> portMapList, Integer nodeType,
558 List<CpToDegree> cp2DegreeList) {
559 NodesBuilder nodesBldr = new NodesBuilder();
560 nodesBldr.withKey(new NodesKey(deviceInfo.getNodeId().getValue())).setNodeId(deviceInfo.getNodeId().getValue());
561 nodesBldr.setNodeType(NodeTypes.forValue(nodeType));
562 nodesBldr.setOpenroadmVersion(Nodes.OpenroadmVersion._221);
563 if (portMapList != null) {
564 nodesBldr.setMapping(portMapList);
566 if (cp2DegreeList != null) {
567 nodesBldr.setCpToDegree(cp2DegreeList);
570 List<Nodes> nodesList = new ArrayList<>();
571 nodesList.add(nodesBldr.build());
573 NetworkBuilder nwBldr = new NetworkBuilder();
574 nwBldr.setNodes(nodesList);
576 final WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
577 InstanceIdentifier<Network> nodesIID = InstanceIdentifier.builder(Network.class).build();
578 Network network = nwBldr.build();
579 writeTransaction.merge(LogicalDatastoreType.CONFIGURATION, nodesIID, network);
580 CheckedFuture<Void, TransactionCommitFailedException> submit = writeTransaction.submit();
585 } catch (TransactionCommitFailedException e) {
586 LOG.warn("Failed to post {}", network, e);
591 private CpToDegree createCpToDegreeObject(String circuitPackName, String degreeNumber, String nodeId,
592 Map<String, String> interfaceList) {
593 String interfaceName = null;
594 if (interfaceList.get(circuitPackName) != null) {
595 interfaceName = interfaceList.get(circuitPackName);
597 return new CpToDegreeBuilder().withKey(new CpToDegreeKey(circuitPackName)).setCircuitPackName(circuitPackName)
598 .setDegreeNumber(new Long(degreeNumber)).setInterfaceName(interfaceName).build();
601 private Mapping createMappingObject(String nodeId, Ports port, String circuitPackName,
602 String logicalConnectionPoint) {
603 MappingBuilder mpBldr = new MappingBuilder();
604 mpBldr.withKey(new MappingKey(logicalConnectionPoint)).setLogicalConnectionPoint(logicalConnectionPoint)
605 .setSupportingCircuitPackName(circuitPackName).setSupportingPort(port.getPortName())
606 .setPortDirection(port.getPortDirection().getName());
608 // Get OMS and OTS interface provisioned on the TTP's
609 if (logicalConnectionPoint.contains(StringConstants.TTP_TOKEN) && (port.getInterfaces() != null)) {
610 for (Interfaces interfaces : port.getInterfaces()) {
612 Optional<Interface> openRoadmInterface = this.openRoadmInterfaces.getInterface(nodeId,
613 interfaces.getInterfaceName());
614 if (openRoadmInterface.isPresent()) {
615 Class<? extends InterfaceType> interfaceType
616 = (Class<? extends InterfaceType>) openRoadmInterface.get().getType();
617 // Check if interface type is OMS or OTS
618 if (interfaceType.equals(OpenROADMOpticalMultiplex.class)) {
619 mpBldr.setSupportingOms(interfaces.getInterfaceName());
621 if (interfaceType.equals(OpticalTransport.class)) {
622 mpBldr.setSupportingOts(interfaces.getInterfaceName());
625 LOG.warn("Interface {} from node {} was null!", interfaces.getInterfaceName(), nodeId);
627 } catch (OpenRoadmInterfaceException ex) {
628 LOG.warn("Error while getting interface {} from node {}!", interfaces.getInterfaceName(), nodeId,
633 return mpBldr.build();
636 private Mapping createXpdrMappingObject(String nodeId, Ports port, String circuitPackName,
637 String logicalConnectionPoint, String partnerLcp, Mapping mapping, String assoLcp) {
638 MappingBuilder mpBldr;
639 if (mapping != null && assoLcp != null) {
640 // update existing mapping
641 mpBldr = new MappingBuilder(mapping);
642 mpBldr.setAssociatedLcp(assoLcp);
644 // create a new mapping
645 mpBldr = new MappingBuilder();
646 mpBldr.withKey(new MappingKey(logicalConnectionPoint))
647 .setLogicalConnectionPoint(logicalConnectionPoint)
648 .setSupportingCircuitPackName(circuitPackName)
649 .setSupportingPort(port.getPortName())
650 .setPortDirection(port.getPortDirection().getName());
651 if (port.getPortQual() != null) {
652 mpBldr.setPortQual(port.getPortQual().getName());
654 if (partnerLcp != null) {
655 mpBldr.setPartnerLcp(partnerLcp);
658 return mpBldr.build();
661 @SuppressWarnings("checkstyle:linelength") //log error message in lines 696 and 766 is too long
662 private boolean createTtpPortMapping(String nodeId, Info deviceInfo, List<Mapping> portMapList) {
663 // Creating mapping data for degree TTP's
664 List<Degree> degrees = getDegrees(nodeId, deviceInfo);
665 Map<String, String> interfaceList = getEthInterfaceList(nodeId);
666 List<CpToDegree> cpToDegreeList = getCpToDegreeList(degrees, nodeId, interfaceList);
667 LOG.info("Map looks like this {}", interfaceList);
669 postPortMapping(deviceInfo, null, deviceInfo.getNodeType().getIntValue(), cpToDegreeList);
671 Map<Integer, List<ConnectionPorts>> connectionPortMap = getPerDegreePorts(nodeId, deviceInfo);
672 for (Integer k : connectionPortMap.keySet()) {
673 switch (connectionPortMap.get(k).size()) {
675 // port is bidirectional
676 InstanceIdentifier<Ports> portID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
677 .child(CircuitPacks.class, new CircuitPacksKey(connectionPortMap.get(k).get(0)
678 .getCircuitPackName()))
679 .child(Ports.class, new PortsKey(connectionPortMap.get(k).get(0)
680 .getPortName().toString()));
681 LOG.info("Fetching connection-port {} at circuit pack {}", connectionPortMap.get(k).get(0)
682 .getPortName().toString(), connectionPortMap.get(k).get(0).getCircuitPackName());
683 Optional<Ports> portObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
684 LogicalDatastoreType.OPERATIONAL, portID, Timeouts.DEVICE_READ_TIMEOUT,
685 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
686 if (portObject.isPresent()) {
687 Ports port = portObject.get();
688 if (port.getPortQual() == null) {
690 } else if (Port.PortQual.RoadmExternal.getIntValue() == port.getPortQual().getIntValue()
691 && Direction.Bidirectional.getIntValue() == port.getPortDirection().getIntValue()) {
692 String logicalConnectionPoint = new StringBuilder("DEG").append(k).append("-TTP-TXRX")
694 LOG.info("{} : Logical Connection Point for {} {} is {}", nodeId,
695 connectionPortMap.get(k).get(0).getCircuitPackName(), port.getPortName(),
696 logicalConnectionPoint);
697 portMapList.add(createMappingObject(nodeId, port,
698 connectionPortMap.get(k).get(0).getCircuitPackName(), logicalConnectionPoint));
701 "Impossible to create logical connection point for port {} of {} on node {} - Error in configuration with port-qual or port-direction",
702 port.getPortName(), connectionPortMap.get(k).get(0).getCircuitPackName(), nodeId);
705 LOG.error("No port {} on circuit pack {} for node {}",
706 connectionPortMap.get(k).get(0).getPortName().toString(),
707 connectionPortMap.get(k).get(0).getCircuitPackName(), nodeId);
712 // ports are unidirectionals
713 String cp1Name = connectionPortMap.get(k).get(0).getCircuitPackName();
714 String cp2Name = connectionPortMap.get(k).get(1).getCircuitPackName();
715 InstanceIdentifier<Ports> port1ID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
716 .child(CircuitPacks.class, new CircuitPacksKey(cp1Name))
717 .child(Ports.class, new PortsKey(connectionPortMap.get(k).get(0).getPortName().toString()));
718 LOG.info("Fetching connection-port {} at circuit pack {}", connectionPortMap.get(k).get(0)
719 .getPortName().toString(), cp1Name);
720 Optional<Ports> port1Object = this.deviceTransactionManager.getDataFromDevice(nodeId,
721 LogicalDatastoreType.OPERATIONAL, port1ID, Timeouts.DEVICE_READ_TIMEOUT,
722 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
723 InstanceIdentifier<Ports> port2ID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
724 .child(CircuitPacks.class, new CircuitPacksKey(cp2Name))
725 .child(Ports.class, new PortsKey(connectionPortMap.get(k).get(1).getPortName().toString()));
726 LOG.info("Fetching connection-port {} at circuit pack {}", connectionPortMap.get(k).get(1)
727 .getPortName().toString(), cp2Name);
728 Optional<Ports> port2Object = this.deviceTransactionManager.getDataFromDevice(nodeId,
729 LogicalDatastoreType.OPERATIONAL, port2ID, Timeouts.DEVICE_READ_TIMEOUT,
730 Timeouts.DEVICE_READ_TIMEOUT_UNIT);
731 if (port1Object.isPresent() && port2Object.isPresent()) {
732 Ports port1 = port1Object.get();
733 Ports port2 = port2Object.get();
734 if (port1.getPortQual() == null || port2.getPortQual() == null) {
736 } else if ((Port.PortQual.RoadmExternal.getIntValue() == port1.getPortQual().getIntValue()
737 && Port.PortQual.RoadmExternal.getIntValue() == port2.getPortQual().getIntValue()
738 && Direction.Rx.getIntValue() == port1.getPortDirection().getIntValue()
739 && Direction.Tx.getIntValue() == port2.getPortDirection().getIntValue()
740 && port1.getPartnerPort() != null && port2.getPartnerPort() != null
741 && port1.getPartnerPort().getCircuitPackName().equals(cp2Name)
742 && port1.getPartnerPort().getPortName().equals(port2.getPortName().toString())
743 && port2.getPartnerPort().getCircuitPackName().equals(cp1Name)
744 && port2.getPartnerPort().getPortName().equals(port1.getPortName()))
746 (Port.PortQual.RoadmExternal.getIntValue() == port1.getPortQual().getIntValue()
747 && Port.PortQual.RoadmExternal.getIntValue() == port2.getPortQual().getIntValue()
748 && Direction.Rx.getIntValue() == port2.getPortDirection().getIntValue()
749 && Direction.Tx.getIntValue() == port1.getPortDirection().getIntValue()
750 && port1.getPartnerPort() != null && port2.getPartnerPort() != null
751 && port1.getPartnerPort().getCircuitPackName().equals(cp2Name)
752 && port1.getPartnerPort().getPortName().equals(port2.getPortName().toString())
753 && port2.getPartnerPort().getCircuitPackName().equals(cp1Name)
754 && port2.getPartnerPort().getPortName().equals(port1.getPortName().toString()))) {
755 String logicalConnectionPoint1 = new StringBuilder("DEG").append(k).append("-TTP-")
756 .append(port1.getPortDirection().getName().toUpperCase()).toString();
757 LOG.info("{} : Logical Connection Point for {} {} is {}", nodeId,
758 connectionPortMap.get(k).get(0).getCircuitPackName(), port1.getPortName(),
759 logicalConnectionPoint1);
760 portMapList.add(createMappingObject(nodeId, port1, connectionPortMap.get(k).get(0)
761 .getCircuitPackName(), logicalConnectionPoint1));
762 String logicalConnectionPoint2 = new StringBuilder("DEG").append(k).append("-TTP-")
763 .append(port2.getPortDirection().getName().toUpperCase()).toString();
764 LOG.info("{} : Logical Connection Point for {} {} is {}", nodeId,
765 connectionPortMap.get(k).get(1).getCircuitPackName(), port2.getPortName(),
766 logicalConnectionPoint2);
767 portMapList.add(createMappingObject(nodeId, port2, connectionPortMap.get(k).get(1)
768 .getCircuitPackName(), logicalConnectionPoint2));
771 "impossible to create logical connection point for port {} or port {} on node {} - Error in configuration with port-qual, port-direction or partner-port configuration",
772 port1.getPortName(), port2.getPortName(), nodeId);
775 LOG.error("No port {} on circuit pack {} for node {}",
776 connectionPortMap.get(k).get(0).getPortName().toString(),
777 connectionPortMap.get(k).get(0).getCircuitPackName(), nodeId);
783 LOG.error("Number of connection port for DEG{} on {} is incorrect", k, nodeId);