+ private List<String> getSupIfCapList(Ports port) {
+ Set<Class<? extends SupportedIfCapability>> supIfCapClassList = port.getSupportedInterfaceCapability();
+ return
+ supIfCapClassList == null
+ ? Collections.emptyList()
+ : supIfCapClassList
+ .stream().map(e -> e.getSimpleName())
+ .collect(Collectors.toList());
+ }
+
+ private Ports getPort2(Ports port, String nodeId, String circuitPackName, StringBuilder circuitPackName2,
+ //circuitPackName2 will be updated by reference contrary to circuitPackName
+ List<CircuitPacks> circuitPackList, Map<String, String> lcpMap) {
+ if (!checkPartnerPortNotNull(port)) {
+ LOG.warn(PortMappingUtils.NO_VALID_PARTNERPORT_LOGMSG, nodeId, port.getPortName(), circuitPackName);
+ return null;
+ }
+ if (lcpMap.containsKey(circuitPackName + '+' + port.getPortName())) {
+ return null;
+ }
+ Optional<CircuitPacks> cpOpt = circuitPackList.stream()
+ .filter(cP -> cP.getCircuitPackName().equals(port.getPartnerPort().getCircuitPackName()))
+ .findFirst();
+ if (cpOpt.isEmpty()) {
+ LOG.error(PortMappingUtils.MISSING_CP_LOGMSG, nodeId, port.getPartnerPort().getCircuitPackName());
+ return null;
+ }
+ Optional<Ports> poOpt = cpOpt.get().nonnullPorts().values().stream()
+ .filter(p -> p.getPortName().equals(port.getPartnerPort().getPortName()))
+ .findFirst();
+ if (poOpt.isEmpty()) {
+ LOG.error(PortMappingUtils.NO_PORT_ON_CP_LOGMSG,
+ nodeId, port.getPartnerPort().getPortName(), port.getPartnerPort().getCircuitPackName());
+ return null;
+ }
+ Ports port2 = poOpt.get();
+ circuitPackName2.append(cpOpt.get().getCircuitPackName());
+ if (!checkPartnerPort(circuitPackName, port, port2)) {
+ LOG.error(PortMappingUtils.NOT_CORRECT_PARTNERPORT_LOGMSG,
+ nodeId, port2.getPortName(), circuitPackName2, port.getPortName(), circuitPackName);
+ return null;
+ }
+ return port2;
+ }
+
+ private void putXpdrLcpsInMaps(int line, String nodeId,
+ Integer xponderNb,
+ String circuitPackName, String circuitPackName2, Ports port, Ports port2,
+ Map<String, String> lcpMap, Map<String, Mapping> mappingMap) {
+ String lcp1 =
+ PortMappingUtils.createXpdrLogicalConnectionPort(xponderNb, line, StringConstants.NETWORK_TOKEN);
+ if (lcpMap.containsKey(lcp1)) {
+ LOG.warn(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, "add", lcp1 + " - already exist");
+ return;
+ }
+ String lcp2 =
+ PortMappingUtils.createXpdrLogicalConnectionPort(xponderNb, line + 1, StringConstants.NETWORK_TOKEN);
+ if (lcpMap.containsKey(lcp2)) {
+ LOG.warn(PortMappingUtils.UNABLE_MAPPING_LOGMSG, nodeId, "add", lcp2 + " - already exist");
+ return;
+ }
+ lcpMap.put(circuitPackName + '+' + port.getPortName(), lcp1);
+ lcpMap.put(circuitPackName2 + '+' + port2.getPortName(), lcp2);
+ mappingMap.put(lcp1,
+ createXpdrMappingObject(nodeId, port, circuitPackName, lcp1, lcp2, null, null));
+ mappingMap.put(lcp2,
+ createXpdrMappingObject(nodeId, port2, circuitPackName2, lcp2, lcp1, null, null));
+ return;
+ }
+
+ private int[] fillXpdrLcpsMaps(int line, int client, String nodeId,
+ Integer xponderNb,
+ String circuitPackName, Ports port,
+ List<CircuitPacks> circuitPackList, Map<String, String> lcpMap, Map<String, Mapping> mappingMap) {
+
+ if (port.getPortQual() == null) {
+ LOG.warn(PortMappingUtils.PORTQUAL_LOGMSG, nodeId, port.getPortName(), circuitPackName, "not found");
+ return new int[] {line, client};
+ }
+
+ switch (port.getPortQual()) {
+
+ case XpdrClient:
+ String lcp0 =
+ PortMappingUtils.createXpdrLogicalConnectionPort(xponderNb, client, StringConstants.CLIENT_TOKEN);
+ lcpMap.put(circuitPackName + '+' + port.getPortName(), lcp0);
+ mappingMap.put(lcp0,
+ createXpdrMappingObject(nodeId, port, circuitPackName, lcp0, null, null, null));
+ client++;
+ break;
+
+ case XpdrNetwork:
+ line = fillXpdrNetworkLcpsMaps(line, nodeId,
+ xponderNb,
+ circuitPackName, port,
+ circuitPackList, lcpMap, mappingMap);
+ break;
+
+ default:
+ LOG.error(PortMappingUtils.PORTQUAL_LOGMSG,
+ nodeId, port.getPortName(), circuitPackName, port.getPortQual() + " not supported");
+ }
+ return new int[] {line, client};
+ }
+
+ private int fillXpdrNetworkLcpsMaps(int line, String nodeId,
+ Integer xponderNb,
+ String circuitPackName, Ports port,
+ List<CircuitPacks> circuitPackList, Map<String, String> lcpMap, Map<String, Mapping> mappingMap) {
+
+ switch (port.getPortDirection()) {
+
+ case Bidirectional:
+ String lcp =
+ PortMappingUtils.createXpdrLogicalConnectionPort(xponderNb, line, StringConstants.NETWORK_TOKEN);
+ lcpMap.put(circuitPackName + '+' + port.getPortName(), lcp);
+ mappingMap.put(lcp,
+ createXpdrMappingObject(nodeId, port, circuitPackName, lcp, null, null, null));
+ line++;
+ break;
+
+ case Rx:
+ case Tx:
+ StringBuilder circuitPackName2 = new StringBuilder();
+ Ports port2 = getPort2(port, nodeId, circuitPackName, circuitPackName2,
+ circuitPackList, lcpMap);
+
+ if (port2 == null) {
+ //key already present or an error occured and was logged
+ return line;
+ }
+
+ putXpdrLcpsInMaps(line, nodeId, xponderNb,
+ circuitPackName, circuitPackName2.toString(), port, port2,
+ lcpMap, mappingMap);
+
+ line += 2;
+ break;
+
+ default:
+ LOG.error(PortMappingUtils.UNSUPPORTED_DIR_LOGMSG,
+ nodeId, port.getPortName(), circuitPackName, port.getPortDirection());
+ }
+
+ return line;
+ }
+