Update port-mapping data with trib-slots for B100G 68/95968/28
authorBalagangadhar Bathula <bb4341@att.com>
Fri, 30 Apr 2021 21:18:25 +0000 (17:18 -0400)
committerguillaume.lambert <guillaume.lambert@orange.com>
Thu, 24 Jun 2021 08:54:22 +0000 (10:54 +0200)
Muxponder switch-client port-quals require max/min-trib-slots
from muxp-profile to be available in the port-mapping.

JIRA: TRNSPRTPCE-449
Change-Id: Ic360fed70fe07f752078596e1facd7063cc28ac9
Signed-off-by: Balagangadhar Bathula <bb4341@att.com>
common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion710.java

index 50d1383d487b81624e84af7581bbbe0434f078c2..8d85f8e49fcb40f60a975224ae9f68e7ef81d145 100644 (file)
@@ -43,6 +43,7 @@ import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmappi
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.mc.capabilities.McCapabilities;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.mc.capabilities.McCapabilitiesBuilder;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.mc.capabilities.McCapabilitiesKey;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.mpdr.restrictions.grp.MpdrRestrictionsBuilder;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.network.Nodes;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.network.NodesBuilder;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.network.NodesKey;
@@ -71,6 +72,8 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.org.open
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.org.openroadm.device.container.org.openroadm.device.Info;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.org.openroadm.device.container.org.openroadm.device.McCapabilityProfile;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.org.openroadm.device.container.org.openroadm.device.McCapabilityProfileKey;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.org.openroadm.device.container.org.openroadm.device.MuxpProfile;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.org.openroadm.device.container.org.openroadm.device.MuxpProfileKey;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.org.openroadm.device.container.org.openroadm.device.OduSwitchingPools;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.org.openroadm.device.container.org.openroadm.device.Protocols;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev200529.org.openroadm.device.container.org.openroadm.device.SharedRiskGroup;
@@ -89,15 +92,18 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.interfaces.rev191129.OtnO
 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev200529.Protocols1;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev200529.lldp.container.Lldp;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.lldp.rev200529.lldp.container.lldp.PortConfig;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev200327.OpucnTribSlotDef;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.capability.rev200529.Ports1;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.capability.rev200529.port.capability.grp.port.capabilities.SupportedInterfaceCapability;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.port.capability.rev200529.port.capability.grp.port.capabilities.SupportedInterfaceCapabilityKey;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.port.capability.rev200529.port.capability.grp.port.capabilities.supported._interface.capability.otn.capability.MpdrClientRestriction;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.Uint16;
 import org.opendaylight.yangtools.yang.common.Uint32;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+
 // FIXME: many common pieces of code between PortMapping Versions 121 and 221 and 710
 // some mutualization would be helpful
 @SuppressWarnings("CPD-START")
@@ -930,8 +936,26 @@ public class PortMappingVersion710 {
                 .SupportedIfCapability>> supportedIntf = new ArrayList<>();
             Map<SupportedInterfaceCapabilityKey, SupportedInterfaceCapability> supIfCapMap = port
                 .augmentation(Ports1.class).getPortCapabilities().nonnullSupportedInterfaceCapability();
+            SupportedInterfaceCapability sic1 = null;
             for (SupportedInterfaceCapability sic : supIfCapMap.values()) {
                 supportedIntf.add(sic.getIfCapType());
+                sic1 = sic;
+            }
+            if (port.getPortQual() == PortQual.SwitchClient
+                && !sic1.getOtnCapability().getMpdrClientRestriction().isEmpty()) {
+                List<MpdrClientRestriction> mpdrClientRestriction = sic1.getOtnCapability().getMpdrClientRestriction();
+                // Here we assume all the supported-interfaces has the support same rates, and the
+                // trib-slot numbers are assumed to be the same
+                String mxpProfileName = mpdrClientRestriction.get(0).getMuxpProfileName().get(0);
+                // From this muxponder-profile get the min-trib-slot and the max-trib-slot
+                LOG.info("{}: Muxp-profile used for trib information {}", nodeId, mxpProfileName);
+                // This provides the tribSlot information from muxProfile
+                List<OpucnTribSlotDef> minMaxOpucnTribSlots = getOpucnTribSlots(nodeId, mxpProfileName);
+                mpBldr.setMpdrRestrictions(
+                    new MpdrRestrictionsBuilder()
+                        .setMinTribSlot(minMaxOpucnTribSlots.get(0))
+                        .setMaxTribSlot(minMaxOpucnTribSlots.get(1))
+                        .build());
             }
             mpBldr.setSupportedInterfaceCapability(supportedIntf);
         }
@@ -944,6 +968,29 @@ public class PortMappingVersion710 {
         return mpBldr.build();
     }
 
+    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.info("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) {