+ private OrgOpenroadmDevice getXpdrDevice(String nodeId) {
+ InstanceIdentifier<OrgOpenroadmDevice> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class);
+ Optional<OrgOpenroadmDevice> deviceObject = deviceTransactionManager.getDataFromDevice(nodeId,
+ LogicalDatastoreType.OPERATIONAL, deviceIID,
+ Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+ if (deviceObject.isEmpty()) {
+ LOG.error(PortMappingUtils.CANNOT_GET_DEV_CONF_LOGMSG, nodeId);
+ return null;
+ }
+ OrgOpenroadmDevice device = deviceObject.get();
+ if (device.getCircuitPacks() == null) {
+ LOG.warn(PortMappingUtils.MISSING_CP_LOGMSG, nodeId, PortMappingUtils.FOUND);
+ return null;
+ }
+ return device;
+ }
+
+ private void getXpdrMaps(OrgOpenroadmDevice device, String nodeId,
+ Map<String, String> lcpMap, Map<String, Mapping> mappingMap) {
+ List<CircuitPacks> circuitPackList = new ArrayList<>(device.nonnullCircuitPacks().values());
+ circuitPackList.sort(Comparator.comparing(CircuitPack::getCircuitPackName));
+ if (device.getXponder() == null) {
+ LOG.warn(PortMappingUtils.XPDR_LIST_IN_CONF_LOGMSG, nodeId, "not found");
+ // Variables to keep track of number of line ports and client ports
+ int line = 1;
+ int client = 1;
+ // TODO the treatment here inside the 2 nested for-loop is very similar to the one
+ // when device.getXponder() != null. Some code mutualization must be considered.
+ for (CircuitPacks cp : circuitPackList) {
+ String circuitPackName = cp.getCircuitPackName();
+ if (cp.getPorts() == null) {
+ LOG.warn(PortMappingUtils.NO_PORT_ON_CP_LOGMSG, nodeId, PortMappingUtils.FOUND, circuitPackName);
+ continue;
+ }
+ List<Ports> portList = new ArrayList<>(cp.nonnullPorts().values());
+ portList.sort(Comparator.comparing(Ports::getPortName));
+ for (Ports port : portList) {
+ int[] counters = fillXpdrLcpsMaps(line, client, nodeId,
+ 1, null, circuitPackName, port,
+ circuitPackList, lcpMap, mappingMap);
+ line = counters[0];
+ client = counters[1];
+ }
+ }
+ } else {
+ LOG.info(PortMappingUtils.XPDR_LIST_IN_CONF_LOGMSG, nodeId, PortMappingUtils.FOUND);
+ for (Xponder xponder : device.nonnullXponder().values()) {
+ // Variables to keep track of number of line ports and client ports
+ int line = 1;
+ int client = 1;
+ Integer xponderNb = xponder.getXpdrNumber().toJava();
+ XpdrNodeTypes xponderType = xponder.getXpdrType();
+ for (XpdrPort xpdrPort : xponder.nonnullXpdrPort().values().stream()
+ .sorted((xp1, xp2) -> xp1.getIndex().compareTo(xp2.getIndex())).collect(Collectors.toList())) {
+ Ports port = getXpdrPorts(device, xpdrPort, nodeId);
+ if (port == null) {
+ continue;
+ }
+ int[] counters = fillXpdrLcpsMaps(line, client, nodeId,
+ xponderNb, xponderType, xpdrPort.getCircuitPackName(), port,
+ circuitPackList, lcpMap, mappingMap);
+ line = counters[0];
+ client = counters[1];
+ }
+ }
+ }
+ }
+
+ private Ports getXpdrPorts(OrgOpenroadmDevice device, XpdrPort xpdrPort, String nodeId) {
+ String circuitPackName = xpdrPort.getCircuitPackName();
+ String portName = xpdrPort.getPortName();
+ // If there xponder-subtree has missing circuit-packs or ports,
+ // This gives a null-pointer expection,
+ Optional<CircuitPacks> cpList = device.nonnullCircuitPacks().values().stream()
+ .filter(cp -> cp.getCircuitPackName().equals(circuitPackName)).findFirst();
+ if (cpList.isEmpty()) {
+ LOG.warn(PortMappingUtils.MISSING_CP_LOGMSG + PortMappingUtils.PORTMAPPING_IGNORE_LOGMSG,
+ nodeId, circuitPackName);
+ return null;
+ }
+ Optional<Ports> portsList = cpList.get().nonnullPorts().values().stream()
+ .filter(p -> p.getPortName().equals(portName)).findFirst();
+ if (portsList.isEmpty()) {
+ LOG.warn(PortMappingUtils.NO_ASSOC_FOUND_LOGMSG + PortMappingUtils.PORTMAPPING_IGNORE_LOGMSG,
+ nodeId, portName, circuitPackName, "in the device");
+ return null;
+ }
+ return portsList.get();
+ }
+