"{} : port {} on {} - associated Logical Connection Point is {}";
public static final String CANNOT_AS_LCP_LOGMSG =
" - cannot assign Logical Connection Point";
- public static final String CANNOT_CREATE_LCP_LOGMSG =
- "{} : port {} on {} - Impossible to create logical connection point";
public static final String CANNOT_GET_DEV_CONF_LOGMSG =
"{} : impossible to get device configuration";
public static final String CANNOT_GET_LLDP_CONF_LOGMSG =
public static final String PORT_NOT_RDMEXT_LOGMSG =
"{} : port {} on {} is not roadm-external";
public static final String PORTDIR_ERROR_LOGMSG =
- " - error in configuration with port-direction";
+ "{} : port {} on {} - error in configuration with port-direction";
public static final String PORTMAPPING_IGNORE_LOGMSG =
" - ignoring it in port-mapping";
public static final String PORTMAPPING_POST_FAIL_LOGMSG =
"{} : port-mapping post-treatment failure for {}";
- public static final String PORTQUAL_ERROR_LOGMSG =
- " - error in configuration with port-qual";
public static final String PORTQUAL_LOGMSG =
"{} : port {} on {} - PortQual {}";
public static final String PROCESSING_DONE_LOGMSG =
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
+import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
import org.eclipse.jdt.annotation.NonNull;
private static final Logger LOG = LoggerFactory.getLogger(PortMappingVersion121.class);
private static final Map<Direction, String> SUFFIX;
+ private static final Set<Integer> TXRX_SET = Set.of(Direction.Tx.getIntValue(), Direction.Rx.getIntValue());
private final DataBroker dataBroker;
private final DeviceTransactionManager deviceTransactionManager;
}
private boolean checkPartnerPort(String circuitPackName, Ports port1, Ports port2) {
- return (checkPartnerPortNoDir(circuitPackName, port1, port2)
- && ((Direction.Rx.getIntValue() == port1.getPortDirection().getIntValue()
- && Direction.Tx.getIntValue() == port2.getPortDirection().getIntValue())
- ||
- (Direction.Tx.getIntValue() == port1.getPortDirection().getIntValue()
- && Direction.Rx.getIntValue() == port2.getPortDirection().getIntValue())));
+ return checkPartnerPortNoDir(circuitPackName, port1, port2)
+ && Set.of(port1.getPortDirection().getIntValue(), port2.getPortDirection().getIntValue())
+ .equals(TXRX_SET);
}
private HashMap<Integer, List<org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.srg
Collections.sort(portList, new SortPort121ByName());
int portIndex = 1;
for (Ports port : portList) {
- String currentKey = circuitPackName + "-" + port.getPortName();
- if (port.getPortQual() == null) {
- continue;
- }
-
- if (Port.PortQual.RoadmExternal.getIntValue() != port.getPortQual().getIntValue()) {
- LOG.debug(PortMappingUtils.PORT_NOT_RDMEXT_LOGMSG + PortMappingUtils.CANNOT_AS_LCP_LOGMSG,
- nodeId, port.getPortName(), circuitPackName);
+ if (!checkPortQual(port, circuitPackName, nodeId)) {
continue;
}
+ String currentKey = circuitPackName + "-" + port.getPortName();
if (keys.contains(currentKey)) {
LOG.debug(PortMappingUtils.PORT_ALREADY_HANDLED_LOGMSG + PortMappingUtils.CANNOT_AS_LCP_LOGMSG,
nodeId, port.getPortName(), circuitPackName);
return false;
}
Ports port = portObject.get();
- if (port.getPortQual() == null) {
- continue;
- }
- if (Port.PortQual.RoadmExternal.getIntValue() != port.getPortQual().getIntValue()) {
- LOG.error(PortMappingUtils.CANNOT_CREATE_LCP_LOGMSG + PortMappingUtils.PORTQUAL_ERROR_LOGMSG,
- nodeId, port.getPortName(), cp1Name);
- continue;
- }
- if (Direction.Bidirectional.getIntValue() != port.getPortDirection().getIntValue()) {
- LOG.error(PortMappingUtils.CANNOT_CREATE_LCP_LOGMSG + PortMappingUtils.PORTDIR_ERROR_LOGMSG,
- nodeId, port.getPortName(), cp1Name);
+ if (!checkTtpPort(port, cp1Name, nodeId, true)) {
continue;
}
InstanceIdentifier<Ports> port2ID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
.child(CircuitPacks.class, new CircuitPacksKey(cp2Name))
.child(Ports.class, new PortsKey(cp2.getPortName()));
- LOG.debug(PortMappingUtils.FETCH_CONNECTIONPORT_LOGMSG,
- nodeId, cp2.getPortName(), cp2Name);
+ LOG.debug(PortMappingUtils.FETCH_CONNECTIONPORT_LOGMSG, nodeId, cp2.getPortName(), cp2Name);
Optional<Ports> port2Object = this.deviceTransactionManager.getDataFromDevice(nodeId,
LogicalDatastoreType.OPERATIONAL, port2ID, Timeouts.DEVICE_READ_TIMEOUT,
Timeouts.DEVICE_READ_TIMEOUT_UNIT);
}
Ports port1 = port1Object.get();
- Ports port2 = port2Object.get();
- if (port1.getPortQual() == null || port2.getPortQual() == null) {
+ if (!checkTtpPort(port1, cp1Name, nodeId, false)) {
continue;
}
- if (Port.PortQual.RoadmExternal.getIntValue() != port1.getPortQual().getIntValue()) {
- LOG.error(PortMappingUtils.CANNOT_CREATE_LCP_LOGMSG + PortMappingUtils.PORTQUAL_ERROR_LOGMSG,
- nodeId, port1.getPortName(), cp1Name);
- continue;
- }
- if (Port.PortQual.RoadmExternal.getIntValue() != port2.getPortQual().getIntValue()) {
- LOG.error(PortMappingUtils.CANNOT_CREATE_LCP_LOGMSG + PortMappingUtils.PORTQUAL_ERROR_LOGMSG,
- nodeId, port2.getPortName(), cp2Name);
+ Ports port2 = port2Object.get();
+ if (!checkTtpPort(port2, cp2Name, nodeId, false)) {
continue;
}
return true;
}
+ private boolean checkPortQual(Ports port, String cpName, String nodeId) {
+ if (port.getPortQual() == null) {
+ return false;
+ }
+ if (Port.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 NodeInfo createNodeInfo(Info deviceInfo) {
if (deviceInfo.getNodeType() == null) {
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
+import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
import org.eclipse.jdt.annotation.NonNull;
private static final Logger LOG = LoggerFactory.getLogger(PortMappingVersion221.class);
private static final Map<Direction, String> SUFFIX;
+ private static final Set<Integer> TXRX_SET = Set.of(Direction.Tx.getIntValue(), Direction.Rx.getIntValue());
private final DataBroker dataBroker;
private final DeviceTransactionManager deviceTransactionManager;
}
private boolean checkPartnerPort(String circuitPackName, Ports port1, Ports port2) {
- return (checkPartnerPortNoDir(circuitPackName, port1, port2)
- && ((Direction.Rx.getIntValue() == port1.getPortDirection().getIntValue()
- && Direction.Tx.getIntValue() == port2.getPortDirection().getIntValue())
- ||
- (Direction.Tx.getIntValue() == port1.getPortDirection().getIntValue()
- && Direction.Rx.getIntValue() == port2.getPortDirection().getIntValue())));
+ return checkPartnerPortNoDir(circuitPackName, port1, port2)
+ && Set.of(port1.getPortDirection().getIntValue(), port2.getPortDirection().getIntValue())
+ .equals(TXRX_SET);
}
Collections.sort(portList, new SortPort221ByName());
int portIndex = 1;
for (Ports port : portList) {
- String currentKey = circuitPackName + "-" + port.getPortName();
- if (port.getPortQual() == null) {
- continue;
- }
-
- if (PortQual.RoadmExternal.getIntValue() != port.getPortQual().getIntValue()) {
- LOG.debug(PortMappingUtils.PORT_NOT_RDMEXT_LOGMSG + PortMappingUtils.CANNOT_AS_LCP_LOGMSG,
- nodeId, port.getPortName(), circuitPackName);
+ if (!checkPortQual(port, circuitPackName, nodeId)) {
continue;
}
+ String currentKey = circuitPackName + "-" + port.getPortName();
if (keys.contains(currentKey)) {
LOG.debug(PortMappingUtils.PORT_ALREADY_HANDLED_LOGMSG + PortMappingUtils.CANNOT_AS_LCP_LOGMSG,
nodeId, port.getPortName(), circuitPackName);
return false;
}
Ports port = portObject.get();
- if (port.getPortQual() == null) {
- continue;
- }
- if (PortQual.RoadmExternal.getIntValue() != port.getPortQual().getIntValue()) {
- LOG.error(PortMappingUtils.CANNOT_CREATE_LCP_LOGMSG + PortMappingUtils.PORTQUAL_ERROR_LOGMSG,
- nodeId, port.getPortName(), cp1Name);
- continue;
- }
- if (Direction.Bidirectional.getIntValue() != port.getPortDirection().getIntValue()) {
- LOG.error(PortMappingUtils.CANNOT_CREATE_LCP_LOGMSG + PortMappingUtils.PORTDIR_ERROR_LOGMSG,
- nodeId, port.getPortName(), cp1Name);
+ if (!checkTtpPort(port, cp1Name, nodeId, true)) {
continue;
}
}
Ports port1 = port1Object.get();
- Ports port2 = port2Object.get();
- if (port1.getPortQual() == null || port2.getPortQual() == null) {
+ if (!checkTtpPort(port1, cp1Name, nodeId, false)) {
continue;
}
- if (PortQual.RoadmExternal.getIntValue() != port1.getPortQual().getIntValue()) {
- LOG.error(PortMappingUtils.CANNOT_CREATE_LCP_LOGMSG + PortMappingUtils.PORTQUAL_ERROR_LOGMSG,
- nodeId, port1.getPortName(), cp1Name);
- continue;
- }
- if (PortQual.RoadmExternal.getIntValue() != port2.getPortQual().getIntValue()) {
- LOG.error(PortMappingUtils.CANNOT_CREATE_LCP_LOGMSG + PortMappingUtils.PORTQUAL_ERROR_LOGMSG,
- nodeId, port2.getPortName(), cp2Name);
+ Ports port2 = port2Object.get();
+ if (!checkTtpPort(port2, cp2Name, nodeId, false)) {
continue;
}
return true;
}
+ 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 NodeInfo createNodeInfo(Info deviceInfo) {
if (deviceInfo.getNodeType() == null) {
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
+import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
import org.eclipse.jdt.annotation.NonNull;
private static final Logger LOG = LoggerFactory.getLogger(PortMappingVersion710.class);
private static final Map<Direction, String> SUFFIX;
+ private static final Set<Integer> TXRX_SET = Set.of(Direction.Tx.getIntValue(), Direction.Rx.getIntValue());
private final DataBroker dataBroker;
private final DeviceTransactionManager deviceTransactionManager;
}
private boolean checkPartnerPort(String circuitPackName, Ports port1, Ports port2) {
- return (checkPartnerPortNoDir(circuitPackName, port1, port2)
- && ((Direction.Rx.getIntValue() == port1.getPortDirection().getIntValue()
- && Direction.Tx.getIntValue() == port2.getPortDirection().getIntValue())
- ||
- (Direction.Tx.getIntValue() == port1.getPortDirection().getIntValue()
- && Direction.Rx.getIntValue() == port2.getPortDirection().getIntValue())));
+ return checkPartnerPortNoDir(circuitPackName, port1, port2)
+ && Set.of(port1.getPortDirection().getIntValue(), port2.getPortDirection().getIntValue())
+ .equals(TXRX_SET);
}
Collections.sort(portList, new SortPort710ByName());
int portIndex = 1;
for (Ports port : portList) {
- String currentKey = circuitPackName + "-" + port.getPortName();
- if (port.getPortQual() == null) {
- continue;
- }
-
- if (PortQual.RoadmExternal.getIntValue() != port.getPortQual().getIntValue()) {
- LOG.debug(PortMappingUtils.PORT_NOT_RDMEXT_LOGMSG + PortMappingUtils.CANNOT_AS_LCP_LOGMSG,
- nodeId, port.getPortName(), circuitPackName);
+ if (!checkPortQual(port, circuitPackName, nodeId)) {
continue;
}
+ String currentKey = circuitPackName + "-" + port.getPortName();
if (keys.contains(currentKey)) {
LOG.debug(PortMappingUtils.PORT_ALREADY_HANDLED_LOGMSG + PortMappingUtils.CANNOT_AS_LCP_LOGMSG,
nodeId, port.getPortName(), circuitPackName);
return false;
}
Ports port = portObject.get();
- if (port.getPortQual() == null) {
- continue;
- }
- if (PortQual.RoadmExternal.getIntValue() != port.getPortQual().getIntValue()) {
- LOG.error(PortMappingUtils.CANNOT_CREATE_LCP_LOGMSG + PortMappingUtils.PORTQUAL_ERROR_LOGMSG,
- nodeId, port.getPortName(), cp1Name);
- continue;
- }
- if (Direction.Bidirectional.getIntValue() != port.getPortDirection().getIntValue()) {
- LOG.error(PortMappingUtils.CANNOT_CREATE_LCP_LOGMSG + PortMappingUtils.PORTDIR_ERROR_LOGMSG,
- nodeId, port.getPortName(), cp1Name);
+ if (!checkTtpPort(port, cp1Name, nodeId, true)) {
continue;
}
}
Ports port1 = port1Object.get();
- Ports port2 = port2Object.get();
- if (port1.getPortQual() == null || port2.getPortQual() == null) {
+ if (!checkTtpPort(port1, cp1Name, nodeId, false)) {
continue;
}
- if (PortQual.RoadmExternal.getIntValue() != port1.getPortQual().getIntValue()) {
- LOG.error(PortMappingUtils.CANNOT_CREATE_LCP_LOGMSG + PortMappingUtils.PORTQUAL_ERROR_LOGMSG,
- nodeId, port1.getPortName(), cp1Name);
- continue;
- }
- if (PortQual.RoadmExternal.getIntValue() != port2.getPortQual().getIntValue()) {
- LOG.error(PortMappingUtils.CANNOT_CREATE_LCP_LOGMSG + PortMappingUtils.PORTQUAL_ERROR_LOGMSG,
- nodeId, port2.getPortName(), cp2Name);
+ Ports port2 = port2Object.get();
+ if (!checkTtpPort(port2, cp2Name, nodeId, false)) {
continue;
}
return true;
}
+ 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 NodeInfo createNodeInfo(Info deviceInfo) {
if (deviceInfo.getNodeType() == null) {