X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=common%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Ftransportpce%2Fcommon%2Fmapping%2FPortMappingVersion710.java;h=3bf2b46f77b41ffe250c140a3dfb1d7c7167a68d;hb=2e33fdc6a6cbef1ed08bc6c1a3f9d30e4d2975b9;hp=b5cdb568acf64816771fa1c665512f93cf965fd4;hpb=d356e7d288af388774773eaea7ea64d66de9bab4;p=transportpce.git diff --git a/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion710.java b/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion710.java index b5cdb568a..3bf2b46f7 100644 --- a/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion710.java +++ b/common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion710.java @@ -99,11 +99,19 @@ import org.slf4j.LoggerFactory; // some mutualization would be helpful public class PortMappingVersion710 { private static final Logger LOG = LoggerFactory.getLogger(PortMappingVersion710.class); + private static final Map SUFFIX; private final DataBroker dataBroker; private final DeviceTransactionManager deviceTransactionManager; private final OpenRoadmInterfaces openRoadmInterfaces; + static { + SUFFIX = Map.of( + Direction.Tx, "TX", + Direction.Rx, "RX", + Direction.Bidirectional, "TXRX"); + } + public PortMappingVersion710(DataBroker dataBroker, DeviceTransactionManager deviceTransactionManager, OpenRoadmInterfaces openRoadmInterfaces) { this.dataBroker = dataBroker; @@ -246,7 +254,7 @@ public class PortMappingVersion710 { switch (port.getPortQual()) { case XpdrClient: - String lcp0 = "XPDR1-" + StringConstants.CLIENT_TOKEN + client; + String lcp0 = createXpdrLogicalConnectionPort(1, client, StringConstants.CLIENT_TOKEN); lcpMap.put(circuitPackName + '+' + port.getPortName(), lcp0); mappingMap.put(lcp0, createXpdrMappingObject(nodeId, port, circuitPackName, lcp0, null, null, null, null)); @@ -256,7 +264,7 @@ public class PortMappingVersion710 { case XpdrNetwork: if (port.getPortDirection().getIntValue() == Direction.Bidirectional.getIntValue()) { - String lcp = "XPDR1-" + StringConstants.NETWORK_TOKEN + line; + String lcp = createXpdrLogicalConnectionPort(1, line, StringConstants.NETWORK_TOKEN); lcpMap.put(circuitPackName + '+' + port.getPortName(), lcp); mappingMap.put(lcp, createXpdrMappingObject(nodeId, port, circuitPackName, lcp, null, null, null, null) @@ -264,12 +272,8 @@ public class PortMappingVersion710 { line++; continue; } - // TODO PortDirection treatment here is similar to the one in createPpPortMapping. - // Some code alignment must be considered. - if (port.getPartnerPort() == null - || port.getPartnerPort().getCircuitPackName() == null - || port.getPartnerPort().getPortName() == null) { + if (!checkPartnerPortNotNull(port)) { LOG.warn("Error in the configuration of port {} of {} for {}", port.getPortName(), circuitPackName, nodeId); continue; @@ -302,11 +306,8 @@ public class PortMappingVersion710 { circuitPackName); continue; } - String lcp1 = "XPDR1-" + StringConstants.NETWORK_TOKEN + line; - String lcp2 = new StringBuilder("XPDR1-") - .append(StringConstants.NETWORK_TOKEN) - .append(line + 1) - .toString(); + String lcp1 = createXpdrLogicalConnectionPort(1, line, StringConstants.NETWORK_TOKEN); + String lcp2 = createXpdrLogicalConnectionPort(1, line + 1, StringConstants.NETWORK_TOKEN); if (lcpMap.containsKey(lcp1) || lcpMap.containsKey(lcp2)) { LOG.warn("mapping already exists for {} or {}", lcp1, lcp2); line += 2; @@ -374,7 +375,8 @@ public class PortMappingVersion710 { case XpdrClient: case SwitchClient: - String lcp0 = "XPDR" + xponderNb + "-" + StringConstants.CLIENT_TOKEN + client; + String lcp0 = + createXpdrLogicalConnectionPort(xponderNb , client, StringConstants.CLIENT_TOKEN); lcpMap.put(circuitPackName + '+' + port.getPortName(), lcp0); mappingMap.put(lcp0, createXpdrMappingObject(nodeId, port, circuitPackName, lcp0, null, null, null, null)); @@ -385,7 +387,8 @@ public class PortMappingVersion710 { case XpdrNetwork: case SwitchNetwork: if (port.getPortDirection().getIntValue() == Direction.Bidirectional.getIntValue()) { - String lcp = "XPDR" + xponderNb + "-" + StringConstants.NETWORK_TOKEN + line; + String lcp = + createXpdrLogicalConnectionPort(xponderNb , line, StringConstants.NETWORK_TOKEN); lcpMap.put(circuitPackName + '+' + port.getPortName(), lcp); mappingMap.put(lcp, createXpdrMappingObject(nodeId, port, circuitPackName, lcp, null, null, null, @@ -393,12 +396,8 @@ public class PortMappingVersion710 { line++; continue; } - // TODO PortDirection treatment here is similar to the one in createPpPortMapping. - // Some code alignment must be considered. - if (port.getPartnerPort() == null - || port.getPartnerPort().getCircuitPackName() == null - || port.getPartnerPort().getPortName() == null) { + if (!checkPartnerPortNotNull(port)) { LOG.warn("Error in the configuration of port {} of {} for {}", port.getPortName(), circuitPackName, nodeId); continue; @@ -433,13 +432,10 @@ public class PortMappingVersion710 { circuitPackName); continue; } - String lcp1 = "XPDR" + xponderNb + "-" + StringConstants.NETWORK_TOKEN + line; - String lcp2 = new StringBuilder("XPDR") - .append(xponderNb) - .append("-") - .append(StringConstants.NETWORK_TOKEN) - .append(line + 1) - .toString(); + String lcp1 = + createXpdrLogicalConnectionPort(xponderNb , line, StringConstants.NETWORK_TOKEN); + String lcp2 = + createXpdrLogicalConnectionPort(xponderNb , line + 1, StringConstants.NETWORK_TOKEN); if (lcpMap.containsKey(lcp1) || lcpMap.containsKey(lcp2)) { LOG.warn("mapping already exists for {} or {}", lcp1, lcp2); line += 2; @@ -531,12 +527,26 @@ public class PortMappingVersion710 { return true; } - private boolean checkPartnerPort(String circuitPackName, Ports port1, Ports port2) { - if (port2.getPartnerPort() == null - || port2.getPartnerPort().getCircuitPackName() == null - || port2.getPartnerPort().getPortName() == null + private boolean checkPartnerPortNotNull(Ports port) { + if (port.getPartnerPort() == null + || port.getPartnerPort().getCircuitPackName() == null + || port.getPartnerPort().getPortName() == null) { + return false; + } + return true; + } + + private boolean checkPartnerPortNoDir(String circuitPackName, Ports port1, Ports port2) { + if (!checkPartnerPortNotNull(port2) || !port2.getPartnerPort().getCircuitPackName().equals(circuitPackName) - || !port2.getPartnerPort().getPortName().equals(port1.getPortName()) + || !port2.getPartnerPort().getPortName().equals(port1.getPortName())) { + return false; + } + return true; + } + + private boolean checkPartnerPort(String circuitPackName, Ports port1, Ports port2) { + if (!checkPartnerPortNoDir(circuitPackName, port1, port2) || ((Direction.Rx.getIntValue() != port1.getPortDirection().getIntValue() || Direction.Tx.getIntValue() != port2.getPortDirection().getIntValue()) && @@ -628,8 +638,8 @@ public class PortMappingVersion710 { case Rx: case Tx: - if (port.getPartnerPort() == null) { - LOG.info("{} : port {} on {} is unidirectional but has no partnerPort" + if (!checkPartnerPortNotNull(port)) { + LOG.info("{} : port {} on {} is unidirectional but has no valid partnerPort" + " - cannot assign logicalConnectionPoint.", nodeId, port.getPortName(), circuitPackName); continue; @@ -685,21 +695,18 @@ public class PortMappingVersion710 { } private String createLogicalConnectionPort(Ports port, int index, int portIndex) { - String lcp = null; - switch (port.getPortDirection()) { - case Tx: - lcp = "SRG" + index + "-PP" + portIndex + "-TX"; - break; - case Rx: - lcp = "SRG" + index + "-PP" + portIndex + "-RX"; - break; - case Bidirectional: - lcp = "SRG" + index + "-PP" + portIndex + "-TXRX"; - break; - default: - LOG.error("Unsupported port direction for port {} : {}", port, port.getPortDirection()); + if (SUFFIX.containsKey(port.getPortDirection())) { + return String.join("-", "SRG" + index, "PP" + portIndex, SUFFIX.get(port.getPortDirection())); } - return lcp; + LOG.error("port {} : Unsupported port direction {}", port, port.getPortDirection()); + return null; + } + + private String createXpdrLogicalConnectionPort(int xponderNb, int lcpNb, String token) { + return new StringBuilder("XPDR").append(xponderNb) + .append("-") + .append(token).append(lcpNb) + .toString(); } private Map getMcCapabilityProfiles(String deviceId, Info ordmInfo) { @@ -719,8 +726,8 @@ public class PortMappingVersion710 { return mcCapabilityProfiles; } - private List getDegrees(String deviceId, Info ordmInfo) { - List degrees = new ArrayList<>(); + private Map getDegreesMap(String deviceId, Info ordmInfo) { + Map degrees = new HashMap<>(); // Get value for max degree from info subtree, required for iteration // if not present assume to be 20 (temporary) @@ -734,13 +741,20 @@ public class PortMappingVersion710 { LogicalDatastoreType.OPERATIONAL, deviceIID, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT); if (ordmDegreeObject.isPresent()) { - degrees.add(ordmDegreeObject.get()); + degrees.put(degreeCounter, ordmDegreeObject.get()); } } LOG.info("Device {} has {} degree", deviceId, degrees.size()); return degrees; } + private Map> getPerDegreePorts(String deviceId, Info ordmInfo) { + Map> conPortMap = new HashMap<>(); + getDegreesMap(deviceId, ordmInfo).forEach( + (index, degree) -> conPortMap.put(index, new ArrayList<>(degree.nonnullConnectionPorts().values()))); + return conPortMap; + } + private List getSrgs(String deviceId, Info ordmInfo) { List srgs = new ArrayList<>(); @@ -761,26 +775,6 @@ public class PortMappingVersion710 { return srgs; } - private Map> getPerDegreePorts(String deviceId, Info ordmInfo) { - Map> conPortMap = new HashMap<>(); - Integer maxDegree = ordmInfo.getMaxDegrees() == null ? 20 : ordmInfo.getMaxDegrees().toJava(); - - for (int degreeCounter = 1; degreeCounter <= maxDegree; degreeCounter++) { - LOG.info("Getting Connection ports for Degree Number {}", degreeCounter); - InstanceIdentifier deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class) - .child(Degree.class, new DegreeKey(Uint16.valueOf(degreeCounter))); - Optional ordmDegreeObject = this.deviceTransactionManager.getDataFromDevice(deviceId, - LogicalDatastoreType.OPERATIONAL, deviceIID, - Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT); - if (ordmDegreeObject.isPresent()) { - conPortMap.put(degreeCounter, new ArrayList<>(ordmDegreeObject.get() - .nonnullConnectionPorts().values())); - } - } - LOG.info("Device {} has {} degree", deviceId, conPortMap.size()); - return conPortMap; - } - private Map getEthInterfaceList(String nodeId) { LOG.info("It is calling get ethernet interface"); InstanceIdentifier protocoliid = InstanceIdentifier.create(OrgOpenroadmDevice.class) @@ -824,23 +818,19 @@ public class PortMappingVersion710 { return cpToInterfaceMap; } - private List getCpToDegreeList(List degrees, String nodeId, - Map interfaceList) { + private List getCpToDegreeList(Map degrees, Map interfaceList) { List cpToDegreeList = new ArrayList<>(); - for (Degree degree : degrees) { - if (degree.getCircuitPacks() == null) { - continue; - } + for (Degree degree : degrees.values()) { LOG.info("Inside CP to degree list"); cpToDegreeList.addAll(degree.nonnullCircuitPacks().values().stream() .map(cp -> createCpToDegreeObject(cp.getCircuitPackName(), - degree.getDegreeNumber().toString(), nodeId, interfaceList)) + degree.getDegreeNumber().toString(), interfaceList)) .collect(Collectors.toList())); } return cpToDegreeList; } - private List getMcCapabilitiesList(List degrees, List srgs, + private List getMcCapabilitiesList(Map degrees, List srgs, Info deviceInfo, String nodeId) { //TODO some divergences with 2.2.1 here LOG.info("Getting the MC capabilities for degrees of node {}", nodeId); @@ -864,20 +854,16 @@ public class PortMappingVersion710 { } if (portMapList != null) { Map mappingMap = new HashMap<>(); + // No element in the list below should be null at this stage for (Mapping mapping: portMapList) { - if (mapping == null) { - continue; - } mappingMap.put(mapping.key(), mapping); } nodesBldr.setMapping(mappingMap); } if (cp2DegreeList != null) { Map cpToDegreeMap = new HashMap<>(); + // No element in the list below should be null at this stage for (CpToDegree cp2Degree: cp2DegreeList) { - if (cp2Degree == null) { - continue; - } cpToDegreeMap.put(cp2Degree.key(), cp2Degree); } nodesBldr.setCpToDegree(cpToDegreeMap); @@ -885,10 +871,8 @@ public class PortMappingVersion710 { if (splList != null) { Map splMap = new HashMap<>(); + // No element in the list below should be null at this stage for (SwitchingPoolLcp spl: splList) { - if (spl == null) { - continue; - } splMap.put(spl.key(), spl); } nodesBldr.setSwitchingPoolLcp(splMap); @@ -915,7 +899,7 @@ public class PortMappingVersion710 { } } - private CpToDegree createCpToDegreeObject(String circuitPackName, String degreeNumber, String nodeId, + private CpToDegree createCpToDegreeObject(String circuitPackName, String degreeNumber, Map interfaceList) { return new CpToDegreeBuilder() .withKey(new CpToDegreeKey(circuitPackName)) @@ -924,11 +908,11 @@ public class PortMappingVersion710 { .setInterfaceName(interfaceList.get(circuitPackName)).build(); } - private List createMcCapDegreeObject(List degrees, + private List createMcCapDegreeObject(Map degrees, Map mcCapabilityProfileMap, String nodeId) { //TODO some divergences here with 2.2.1 List mcCapabilitiesList = new ArrayList<>(); - for (Degree degree : degrees) { + for (Degree degree : degrees.values()) { if ((degree.getMcCapabilityProfileName() == null) || (degree.getMcCapabilityProfileName().isEmpty())) { LOG.warn("No MC profiles are found for node {} on degree {}", nodeId, degree.getDegreeNumber()); @@ -1076,7 +1060,7 @@ public class PortMappingVersion710 { } private boolean createMcCapabilitiesList(String nodeId, Info deviceInfo, List mcCapabilitiesList) { - List degrees = getDegrees(nodeId, deviceInfo); + Map degrees = getDegreesMap(nodeId, deviceInfo); List srgs = getSrgs(nodeId, deviceInfo); mcCapabilitiesList.addAll(getMcCapabilitiesList(degrees, srgs, deviceInfo, nodeId)); return true; @@ -1084,9 +1068,9 @@ public class PortMappingVersion710 { private boolean createTtpPortMapping(String nodeId, Info deviceInfo, List portMapList) { // Creating mapping data for degree TTP's - List degrees = getDegrees(nodeId, deviceInfo); + Map degrees = getDegreesMap(nodeId, deviceInfo); Map interfaceList = getEthInterfaceList(nodeId); - List cpToDegreeList = getCpToDegreeList(degrees, nodeId, interfaceList); + List cpToDegreeList = getCpToDegreeList(degrees, interfaceList); LOG.info("Map looks like this {}", interfaceList); postPortMapping(nodeId, null, null, cpToDegreeList, null, null); @@ -1182,8 +1166,8 @@ public class PortMappingVersion710 { port2.getPortName(), cp2Name, port1.getPortName(), cp1Name); continue; } - // TODO this second checkPartnerPort call has overlap checkings with the first one (Directions) - if (!checkPartnerPort(cp2Name, port2, port1)) { + // Directions checks are the same for cp1 and cp2, no need to check them twice. + if (!checkPartnerPortNoDir(cp2Name, port2, port1)) { LOG.error("port {} on {} is not a correct partner port of {} on {}", port1.getPortName(), cp1Name, port2.getPortName(), cp2Name); continue;