+ if (device.getXponder() == null) {
+ LOG.warn("{} configuration does not contain a list of xponders", nodeId);
+ for (CircuitPacks cp : circuitPackList) {
+ String circuitPackName = cp.getCircuitPackName();
+ if (cp.getPorts() == null) {
+ LOG.warn("Ports were not found for circuit pack: {}", circuitPackName);
+ continue;
+ }
+ List<Ports> portList = new ArrayList<>(cp.getPorts());
+ portList.sort(Comparator.comparing(Ports::getPortName));
+ for (Ports port : portList) {
+ if (port.getPortQual() == null) {
+ LOG.warn("PortQual was not found for port {} on circuit pack: {}", port.getPortName(),
+ circuitPackName);
+ continue;
+ }
+ if (PortQual.XpdrNetwork.getIntValue() == port.getPortQual().getIntValue()
+ && port.getPortDirection().getIntValue() == Direction.Bidirectional.getIntValue()) {
+ String lcp = "XPDR1-" + StringConstants.NETWORK_TOKEN + line;
+ lcpMap.put(circuitPackName + '+' + port.getPortName(), lcp);
+ mappingMap.put(lcp, createXpdrMappingObject(nodeId, port, circuitPackName, lcp, null, null,
+ null, null));
+ line++;
+ } else if (PortQual.XpdrNetwork.getIntValue() == port.getPortQual().getIntValue()
+ && port.getPortDirection().getIntValue() != Direction.Bidirectional.getIntValue()
+ && port.getPartnerPort() != null
+ && port.getPartnerPort().getCircuitPackName() != null
+ && port.getPartnerPort().getPortName() != null) {
+ if (lcpMap.containsKey(circuitPackName + '+' + port.getPortName())) {
+ continue;
+ }
+ String lcp1 = "XPDR1-" + StringConstants.NETWORK_TOKEN + line;
+ Optional<CircuitPacks> cpOpt = circuitPackList.stream()
+ .filter(cP -> cP.getCircuitPackName().equals(port.getPartnerPort().getCircuitPackName()))
+ .findFirst();
+ if (cpOpt.isPresent()) {
+ Optional<Ports> poOpt = cpOpt.get().getPorts().stream()
+ .filter(p -> p.getPortName().equals(port.getPartnerPort().getPortName().toString()))
+ .findFirst();
+ if (poOpt.isPresent()) {
+ Ports port2 = poOpt.get();
+ if (checkPartnerPort(circuitPackName, port, port2)) {
+ String lcp2 = new StringBuilder("XPDR1-").append(StringConstants.NETWORK_TOKEN)
+ .append(line + 1).toString();
+ if (!lcpMap.containsKey(lcp1) && !lcpMap.containsKey(lcp2)) {
+ lcpMap.put(circuitPackName + '+' + port.getPortName(), lcp1);
+ lcpMap.put(cpOpt.get().getCircuitPackName() + '+' + port2.getPortName(), lcp2);
+ mappingMap.put(lcp1, createXpdrMappingObject(nodeId, port, circuitPackName,
+ lcp1, lcp2, null, null, null));
+ mappingMap.put(lcp2, createXpdrMappingObject(nodeId, port2, cpOpt.get()
+ .getCircuitPackName(), lcp2, lcp1, null, null, null));
+ } else {
+ LOG.warn("mapping already exists for {} or {}", lcp1, lcp2);
+ }
+ line += 2;
+ } else {
+ LOG.error("port {} on {} is not a correct partner port of {} on {}",
+ port2.getPortName(), cpOpt.get().getCircuitPackName(), port.getPortName(),
+ circuitPackName);
+ }
+ } else {
+ LOG.error("Error fetching port {} on {} for {}", port.getPartnerPort().getPortName(),
+ port.getPartnerPort().getCircuitPackName(), nodeId);
+ }
+ } else {
+ LOG.error("Error fetching circuit-pack {} for {}", port.getPartnerPort()
+ .getCircuitPackName(), nodeId);
+ }
+ } else if (PortQual.XpdrClient.getIntValue() == port.getPortQual().getIntValue()) {
+ String lcp = "XPDR1-" + StringConstants.CLIENT_TOKEN + client;
+ lcpMap.put(circuitPackName + '+' + port.getPortName(), lcp);
+ mappingMap.put(lcp, createXpdrMappingObject(nodeId, port, circuitPackName, lcp, null, null,
+ null, null));
+ client++;
+ } else {
+ LOG.warn("Error in the configuration of port {} of {} for {}", port.getPortName(),
+ circuitPackName,
+ nodeId);
+ }
+ }
+ }
+ } else {
+ LOG.info("{} configuration contains a list of xponders", nodeId);
+ for (Xponder xponder:deviceObject.get().getXponder()) {
+ line = 1;
+ client = 1;
+ Integer xponderNb = xponder.getXpdrNumber().toJava();
+ XpdrNodeTypes xponderType = xponder.getXpdrType();
+ for (XpdrPort xpdrPort : xponder.getXpdrPort()) {
+ String circuitPackName = xpdrPort.getCircuitPackName();
+ String portName = xpdrPort.getPortName().toString();
+ // If there xponder-subtree has missing circuit-packs or ports,
+ // This gives a null-pointer expection,
+ if (device.getCircuitPacks().stream()
+ .filter(cp -> cp.getCircuitPackName().equals(circuitPackName))
+ .findFirst().isEmpty()) {
+ LOG.warn("Circuit-pack {} is missing in the device", circuitPackName);
+ LOG.warn("Port-mapping will continue ignoring this circuit-pack {}", circuitPackName);
+ continue;
+ }
+ if (device.getCircuitPacks().stream()
+ .filter(cp -> cp.getCircuitPackName().equals(circuitPackName))
+ .findFirst().get().getPorts().stream()
+ .filter(p -> p.getPortName().equals(portName))
+ .findFirst().isEmpty()) {
+ LOG.warn("Port {} associated with CP {} is missing in the device", portName, circuitPackName);
+ LOG.warn("Port-mapping will continue ignoring this port {}", portName);
+ continue;
+ }
+ Ports port = device.getCircuitPacks().stream()
+ .filter(cp -> cp.getCircuitPackName().equals(circuitPackName))
+ .findFirst().get().getPorts().stream()
+ .filter(p -> p.getPortName().equals(portName))
+ .findFirst().get();
+ if (port.getPortQual() == null) {
+ LOG.warn("PortQual was not found for port {} on circuit pack: {}", port.getPortName(),
+ circuitPackName);
+ continue;
+ }
+ if ((PortQual.XpdrNetwork.getIntValue() == port.getPortQual().getIntValue()
+ || PortQual.SwitchNetwork.getIntValue() == port.getPortQual().getIntValue())
+ && port.getPortDirection().getIntValue() == Direction.Bidirectional.getIntValue()) {
+ String lcp = "XPDR" + xponderNb + "-" + StringConstants.NETWORK_TOKEN + line;
+ lcpMap.put(circuitPackName + '+' + port.getPortName(), lcp);
+ mappingMap.put(lcp, createXpdrMappingObject(nodeId, port, circuitPackName, lcp,
+ null, null, null, xponderType));
+ line++;
+ } else if ((PortQual.XpdrNetwork.getIntValue() == port.getPortQual().getIntValue()
+ || PortQual.SwitchNetwork.getIntValue() == port.getPortQual().getIntValue())
+ && port.getPortDirection().getIntValue() != Direction.Bidirectional.getIntValue()
+ && port.getPartnerPort() != null
+ && port.getPartnerPort().getCircuitPackName() != null
+ && port.getPartnerPort().getPortName() != null) {
+ if (lcpMap.containsKey(circuitPackName + '+' + port.getPortName())) {
+ continue;
+ }
+ String lcp1 = "XPDR" + xponderNb + "-" + StringConstants.NETWORK_TOKEN + line;
+
+ Optional<CircuitPacks> cpOpt = circuitPackList.stream()
+ .filter(cP -> cP.getCircuitPackName().equals(port.getPartnerPort().getCircuitPackName()))
+ .findFirst();
+ if (cpOpt.isPresent()) {
+ Optional<Ports> poOpt = cpOpt.get().getPorts().stream()
+ .filter(p -> p.getPortName().equals(port.getPartnerPort().getPortName().toString()))
+ .findFirst();
+ if (poOpt.isPresent()) {
+ Ports port2 = poOpt.get();
+ if (checkPartnerPort(circuitPackName, port, port2)) {
+ String lcp2 = new StringBuilder("XPDR").append(xponderNb).append("-").append(
+ StringConstants.NETWORK_TOKEN).append(line + 1).toString();
+ if (!lcpMap.containsKey(lcp1) && !lcpMap.containsKey(lcp2)) {
+ lcpMap.put(circuitPackName + '+' + port.getPortName(), lcp1);
+ lcpMap.put(cpOpt.get().getCircuitPackName() + '+' + port2.getPortName(),
+ lcp2);
+ mappingMap.put(lcp1, createXpdrMappingObject(nodeId, port, circuitPackName,
+ lcp1, lcp2, null, null, xponderType));
+ mappingMap.put(lcp2, createXpdrMappingObject(nodeId, port2, cpOpt.get()
+ .getCircuitPackName(), lcp2, lcp1, null, null,
+ xponderType));
+ } else {
+ LOG.warn("mapping already exists for {} or {}", lcp1, lcp2);
+ }
+ line += 2;
+ } else {
+ LOG.error("port {} on {} is not a correct partner port of {} on {}", port2
+ .getPortName(), cpOpt.get().getCircuitPackName(), port.getPortName(),
+ circuitPackName);
+ }
+ } else {
+ LOG.error("Error fetching port {} on {} for {}",
+ port.getPartnerPort().getPortName(),
+ port.getPartnerPort().getCircuitPackName(), nodeId);
+ }
+ } else {
+ LOG.error("Error fetching circuit-pack {} for {}", port.getPartnerPort()
+ .getCircuitPackName(), nodeId);
+ }
+ } else if (PortQual.XpdrClient.getIntValue() == port.getPortQual().getIntValue()
+ || PortQual.SwitchClient.getIntValue() == port.getPortQual().getIntValue()) {
+ String lcp = "XPDR" + xponderNb + "-" + StringConstants.CLIENT_TOKEN + client;
+ lcpMap.put(circuitPackName + '+' + port.getPortName(), lcp);
+ mappingMap.put(lcp, createXpdrMappingObject(nodeId, port, circuitPackName, lcp,
+ null, null, null, null));
+ client++;
+ } else {
+ LOG.warn("Error in the configuration of port {} of {} for {}", port.getPortName(),
+ circuitPackName, nodeId);
+ }
+ }