+ public boolean updatePortMappingWithOduSwitchingPools(String nodeId, InstanceIdentifier<OduSwitchingPools> ospIID,
+ Map<Uint16, List<InstanceIdentifier<PortList>>> nbliidMap) {
+
+ KeyedInstanceIdentifier<Nodes, NodesKey> portMappingNodeIID =
+ InstanceIdentifier.create(Network.class).child(Nodes.class, new NodesKey(nodeId));
+ Nodes portmappingNode = null;
+ try (ReadTransaction readTx = this.dataBroker.newReadOnlyTransaction()) {
+ portmappingNode = readTx.read(LogicalDatastoreType.CONFIGURATION, portMappingNodeIID).get().orElseThrow();
+ } catch (InterruptedException | ExecutionException ex) {
+ LOG.error("Unable to read the port-mapping for nodeId {}", nodeId, ex);
+ }
+ if (portmappingNode == null) {
+ return false;
+ }
+
+ OduSwitchingPools osp = deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL,
+ ospIID, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT).orElseThrow();
+ Uint16 ospNumber = osp.getSwitchingPoolNumber();
+ Map<SwitchingPoolLcpKey, SwitchingPoolLcp> splMap =
+ new HashMap<SwitchingPoolLcpKey, SwitchingPoolLcp>(portmappingNode.nonnullSwitchingPoolLcp());
+ SwitchingPoolLcpBuilder splBldr = splMap.containsKey(new SwitchingPoolLcpKey(ospNumber))
+ ? new SwitchingPoolLcpBuilder(splMap.get(new SwitchingPoolLcpKey(ospNumber)))
+ : new SwitchingPoolLcpBuilder().setSwitchingPoolNumber(ospNumber)
+ .setSwitchingPoolType(osp.getSwitchingPoolType());
+ Map<NonBlockingListKey, NonBlockingList> nblMap = new HashMap<>();
+ for (Entry<Uint16, List<InstanceIdentifier<PortList>>> entry : nbliidMap.entrySet()) {
+ NonBlockingList nbl = createNonBlockingList(
+ splBldr,
+ osp.getNonBlockingList()
+ .get(new org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529
+ .org.openroadm.device.container.org.openroadm.device.odu.switching.pools
+ .NonBlockingListKey(entry.getKey()))
+ .getInterconnectBandwidth(),
+ entry,
+ portmappingNode.nonnullMapping(),
+ nodeId);
+ if (nbl == null) {
+ return false;
+ }
+ nblMap.put(nbl.key(), nbl);
+ }
+ SwitchingPoolLcp switchingPoolLcp = splBldr.setNonBlockingList(nblMap).build();
+ splMap.put(switchingPoolLcp.key(), switchingPoolLcp);
+ postPortMapping(nodeId, null, null, null, new ArrayList<SwitchingPoolLcp>(splMap.values()), null);
+ return true;
+ }
+
+ private NonBlockingList createNonBlockingList(SwitchingPoolLcpBuilder splBldr, Uint32 interconnectBw,
+ Entry<Uint16, List<InstanceIdentifier<PortList>>> entry, Map<MappingKey, Mapping> mappings, String nodeId) {
+ NonBlockingListBuilder nblBldr = splBldr.getNonBlockingList() == null
+ || !splBldr.getNonBlockingList().containsKey(new NonBlockingListKey(entry.getKey()))
+ ? new NonBlockingListBuilder().setNblNumber(entry.getKey()).setInterconnectBandwidth(interconnectBw)
+ : new NonBlockingListBuilder(splBldr.getNonBlockingList().get(new NonBlockingListKey(entry.getKey())));
+ Set<String> lcpList = nblBldr.getLcpList() != null ? nblBldr.getLcpList() : new HashSet<>();
+ for (InstanceIdentifier<PortList> id : entry.getValue()) {
+ PortList portList = deviceTransactionManager.getDataFromDevice(nodeId, LogicalDatastoreType.OPERATIONAL,
+ id, Timeouts.DEVICE_READ_TIMEOUT, Timeouts.DEVICE_READ_TIMEOUT_UNIT).orElseThrow();
+ String lcp = getLcpFromCpAndPort(mappings, portList.getCircuitPackName(), portList.getPortName());
+ if (lcp == null || lcpList.contains(lcp)) {
+ return null;
+ }
+ lcpList.add(lcp);
+ }
+ return nblBldr.setLcpList(lcpList).build();
+ }
+