+ private Collection<SupportedInterfaceCapability> getSupIntfCapaList(Ports port) {
+ return
+ port.augmentation(Ports1.class) == null || port.augmentation(Ports1.class).getPortCapabilities() == null
+ ? null
+ : port.augmentation(Ports1.class).getPortCapabilities().nonnullSupportedInterfaceCapability().values();
+ }
+
+ private ArrayList<OpucnTribSlotDef> getOpucnTribSlots(String deviceId, String mxpProfileName) {
+ ArrayList<OpucnTribSlotDef> minMaxOpucnTribSlots = new ArrayList<>(2);
+
+ LOG.info("{} : Getting Min/Max Trib-slots from {}", deviceId, mxpProfileName);
+ InstanceIdentifier<MuxpProfile> deviceIID = InstanceIdentifier.create(OrgOpenroadmDevice.class)
+ .child(MuxpProfile.class, new MuxpProfileKey(mxpProfileName));
+
+ Optional<MuxpProfile> muxpProfileObject = this.deviceTransactionManager.getDataFromDevice(deviceId,
+ LogicalDatastoreType.OPERATIONAL, deviceIID,
+ Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT);
+
+ List<OpucnTribSlotDef> ntwHoOduOpucnTribSlots = muxpProfileObject.get().getNetworkHoOduOpucnTribSlots();
+ // Sort the tib-slots in ascending order and pick min and max
+ List<OpucnTribSlotDef> sortedNtwHoOduOpucnTribSlots = ntwHoOduOpucnTribSlots.stream().sorted(
+ Comparator.comparingDouble(x -> Double.parseDouble(
+ x.getValue().substring(x.getValue().lastIndexOf('.') + 1))))
+ .collect(Collectors.toList());
+ minMaxOpucnTribSlots.add(sortedNtwHoOduOpucnTribSlots.get(0));
+ minMaxOpucnTribSlots.add(sortedNtwHoOduOpucnTribSlots.get(sortedNtwHoOduOpucnTribSlots.size() - 1));
+ LOG.debug("Min, Max trib slot list {}", minMaxOpucnTribSlots);
+ return minMaxOpucnTribSlots;
+ }
+
+ 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, XpdrNodeTypes xponderType,
+ 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, xponderType));
+ mappingMap.put(lcp2,
+ createXpdrMappingObject(nodeId, port2, circuitPackName2, lcp2, lcp1, null, null, xponderType));
+ return;
+ }
+
+ private int[] fillXpdrLcpsMaps(int line, int client, String nodeId,
+ Integer xponderNb, XpdrNodeTypes xponderType,
+ 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:
+ case SwitchClient:
+ 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, xponderType));
+ client++;
+ break;
+
+ case XpdrNetwork:
+ case SwitchNetwork:
+ line = fillXpdrNetworkLcpsMaps(line, nodeId,
+ xponderNb, xponderType,
+ 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, XpdrNodeTypes xponderType,
+ 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, xponderType));
+ 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, xponderType,
+ 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;
+ }
+
+ private boolean createMcCapabilitiesList(String nodeId, Info deviceInfo,
+ Map<McCapabilitiesKey, McCapabilities> mcCapabilitiesMap) {
+ if (deviceInfo.getNodeType() == NodeTypes.Rdm) {
+ Map<Integer, Degree> degrees = getDegreesMap(nodeId, deviceInfo);
+ List<SharedRiskGroup> srgs = getSrgs(nodeId, deviceInfo);
+ mcCapabilitiesMap.putAll(getMcCapabilities(degrees, srgs, deviceInfo, nodeId));
+ } else if ((deviceInfo.getNodeType() == NodeTypes.Xpdr)) {
+ Map<McCapabilityProfileKey, McCapabilityProfile> mcProfileXpdr = getMcCapabilityProfiles(nodeId,
+ deviceInfo);
+ if (mcProfileXpdr.size() > 1) {
+ LOG.warn("Re-check the mc-capability-profiles for XPDR port-mapping");
+ }
+ // Typically for a XPDR there will be only one mc-capability-profile
+ for (Map.Entry<McCapabilityProfileKey, McCapabilityProfile> mcCapProfile : mcProfileXpdr.entrySet()) {
+ String mcNodeName = "XPDR" + "-" + "mcprofile";
+ McCapabilitiesBuilder mcCapabilitiesBuilder = new McCapabilitiesBuilder()
+ .withKey(new McCapabilitiesKey(mcNodeName))
+ .setMcNodeName(mcNodeName);
+ mcCapabilitiesBuilder
+ .setCenterFreqGranularity(mcCapProfile.getValue().getCenterFreqGranularity())
+ .setSlotWidthGranularity(mcCapProfile.getValue().getSlotWidthGranularity());
+ // Build and add to the Map
+ mcCapabilitiesMap.put(mcCapabilitiesBuilder.key(), mcCapabilitiesBuilder.build());
+ LOG.info("Finished building mc-capability profile for XPDR {}", nodeId);
+ // Since we only have one mc-profile for XPDR, we can break the for-loop
+ break;
+ }
+
+ }