+ private Ports getTtpPort(ConnectionPorts cp, String cpName, String nodeId) {
+ InstanceIdentifier<Ports> portID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
+ .child(CircuitPacks.class, new CircuitPacksKey(cpName))
+ .child(Ports.class, new PortsKey(cp.getPortName()));
+ LOG.debug(PortMappingUtils.FETCH_CONNECTIONPORT_LOGMSG, nodeId, cp.getPortName(), cpName);
+ Optional<Ports> portObject = this.deviceTransactionManager.getDataFromDevice(nodeId,
+ LogicalDatastoreType.OPERATIONAL, portID, Timeouts.DEVICE_READ_TIMEOUT,
+ Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+ if (portObject.isEmpty()) {
+ LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, cp.getPortName(), cpName);
+ return null;
+ }
+ return portObject.get();
+ }
+
+ private boolean checkPortQual(Ports port, String cpName, String nodeId) {
+ if (port.getPortQual() == null) {
+ return false;
+ }
+ if (PortQual.RoadmExternal.getIntValue() != port.getPortQual().getIntValue()) {
+ //used to be LOG.error when called from createTtpPortMapping
+ LOG.debug(PortMappingUtils.PORT_NOT_RDMEXT_LOGMSG + PortMappingUtils.CANNOT_AS_LCP_LOGMSG,
+ nodeId, port.getPortName(), cpName);
+ return false;
+ }
+ return true;
+ }
+
+ private boolean checkTtpPort(Ports port, String cpName, String nodeId, boolean bidirectional) {
+ if (!checkPortQual(port, cpName, nodeId)) {
+ return false;
+ }
+ if (Direction.Bidirectional.getIntValue() == port.getPortDirection().getIntValue() ^ bidirectional) {
+ // (a ^ b) makes more sense than (!a && b) here since it can also work for unidirectional links
+ LOG.error(PortMappingUtils.PORTDIR_ERROR_LOGMSG + PortMappingUtils.CANNOT_AS_LCP_LOGMSG,
+ nodeId, port.getPortName(), cpName);
+ return false;
+ }
+ return true;
+ }
+
+ private boolean checkTtpPortsUnidir(Ports port1, Ports port2, String cp1Name, String cp2Name, String nodeId) {
+ if (!checkTtpPort(port1, cp1Name, nodeId, false)) {
+ return false;
+ }
+ if (!checkTtpPort(port2, cp2Name, nodeId, false)) {
+ return false;
+ }
+ if (!checkPartnerPort(cp1Name, port1, port2)) {
+ LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG,
+ nodeId, port2.getPortName(), cp2Name, port1.getPortName(), cp1Name);
+ return false;
+ }
+ // Directions checks are the same for cp1 and cp2, no need to check them twice.
+ if (!checkPartnerPortNoDir(cp2Name, port2, port1)) {
+ LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG,
+ nodeId, port1.getPortName(), cp1Name, port2.getPortName(), cp2Name);
+ return false;
+ }
+ return true;
+ }