Improve portmapping LCP names creation process 90/94990/1
authorguillaume.lambert <guillaume.lambert@orange.com>
Wed, 3 Feb 2021 12:15:52 +0000 (13:15 +0100)
committerGuillaume Lambert <guillaume.lambert@orange.com>
Mon, 8 Feb 2021 16:54:42 +0000 (16:54 +0000)
JIRA: TRNSPRTPCE-353
Signed-off-by: guillaume.lambert <guillaume.lambert@orange.com>
Change-Id: Ic7ebdea90142831bfdab5ca45432f26defdde79b
(cherry picked from commit 8583b48ee1a38129b851ee5b4d94121a390a394d)

common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion121.java
common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion221.java
common/src/main/java/org/opendaylight/transportpce/common/mapping/PortMappingVersion710.java

index 1aa58c60ca06022fc365338d599f492fba9f8406..f883080a5599797ceaecc77e50df3f8e4bad80ba 100644 (file)
@@ -84,11 +84,19 @@ import org.slf4j.LoggerFactory;
 public class PortMappingVersion121 {
 
     private static final Logger LOG = LoggerFactory.getLogger(PortMappingVersion121.class);
+    private static final Map<Direction, String> SUFFIX;
 
     private final DataBroker dataBroker;
     private final DeviceTransactionManager deviceTransactionManager;
     private final OpenRoadmInterfaces openRoadmInterfaces;
 
+    static {
+        SUFFIX =  Map.of(
+            Direction.Tx, "TX",
+            Direction.Rx, "RX",
+            Direction.Bidirectional, "TXRX");
+    }
+
     public PortMappingVersion121(DataBroker dataBroker, DeviceTransactionManager deviceTransactionManager,
         OpenRoadmInterfaces openRoadmInterfaces) {
         this.dataBroker = dataBroker;
@@ -498,21 +506,11 @@ public class PortMappingVersion121 {
     }
 
     private String createLogicalConnectionPort(Ports port, int index, int portIndex) {
-        String lcp = null;
-        switch (port.getPortDirection()) {
-            case Tx:
-                lcp = "SRG" + index + "-PP" + portIndex + "-TX";
-                break;
-            case Rx:
-                lcp = "SRG" + index + "-PP" + portIndex + "-RX";
-                break;
-            case Bidirectional:
-                lcp = "SRG" + index + "-PP" + portIndex + "-TXRX";
-                break;
-            default:
-                LOG.error("Unsupported port direction for port {} : {}", port, port.getPortDirection());
+        if (SUFFIX.containsKey(port.getPortDirection())) {
+            return String.join("-", "SRG" + index, "PP" + portIndex, SUFFIX.get(port.getPortDirection()));
         }
-        return lcp;
+        LOG.error("port {} : Unsupported port direction {}", port, port.getPortDirection());
+        return null;
     }
 
     private Map<Integer, Degree> getDegreesMap(String deviceId, Info ordmInfo) {
index a31ddc82743e2c6c24f082c0808975b48d0cfb53..3af8fc344725e875e855c9ae47de6d2e55594851 100644 (file)
@@ -100,11 +100,19 @@ import org.slf4j.LoggerFactory;
 // some mutualization would be helpful
 public class PortMappingVersion221 {
     private static final Logger LOG = LoggerFactory.getLogger(PortMappingVersion221.class);
+    private static final Map<Direction, String> SUFFIX;
 
     private final DataBroker dataBroker;
     private final DeviceTransactionManager deviceTransactionManager;
     private final OpenRoadmInterfaces openRoadmInterfaces;
 
+    static {
+        SUFFIX =  Map.of(
+            Direction.Tx, "TX",
+            Direction.Rx, "RX",
+            Direction.Bidirectional, "TXRX");
+    }
+
     public PortMappingVersion221(DataBroker dataBroker, DeviceTransactionManager deviceTransactionManager,
         OpenRoadmInterfaces openRoadmInterfaces) {
         this.dataBroker = dataBroker;
@@ -695,21 +703,11 @@ public class PortMappingVersion221 {
     }
 
     private String createLogicalConnectionPort(Ports port, int index, int portIndex) {
-        String lcp = null;
-        switch (port.getPortDirection()) {
-            case Tx:
-                lcp = "SRG" + index + "-PP" + portIndex + "-TX";
-                break;
-            case Rx:
-                lcp = "SRG" + index + "-PP" + portIndex + "-RX";
-                break;
-            case Bidirectional:
-                lcp = "SRG" + index + "-PP" + portIndex + "-TXRX";
-                break;
-            default:
-                LOG.error("Unsupported port direction for port {} : {}", port, port.getPortDirection());
+        if (SUFFIX.containsKey(port.getPortDirection())) {
+            return String.join("-", "SRG" + index, "PP" + portIndex, SUFFIX.get(port.getPortDirection()));
         }
-        return lcp;
+        LOG.error("port {} : Unsupported port direction {}", port, port.getPortDirection());
+        return null;
     }
 
     private Map<Integer, Degree> getDegreesMap(String deviceId, Info ordmInfo) {
index 98d5fdafa70d75a8dc96a5394cb61629b45abc5c..6f3be2916685ac5ebe5b9666676d3da07197e310 100644 (file)
@@ -99,11 +99,19 @@ import org.slf4j.LoggerFactory;
 // some mutualization would be helpful
 public class PortMappingVersion710 {
     private static final Logger LOG = LoggerFactory.getLogger(PortMappingVersion710.class);
+    private static final Map<Direction, String> SUFFIX;
 
     private final DataBroker dataBroker;
     private final DeviceTransactionManager deviceTransactionManager;
     private final OpenRoadmInterfaces openRoadmInterfaces;
 
+    static {
+        SUFFIX =  Map.of(
+            Direction.Tx, "TX",
+            Direction.Rx, "RX",
+            Direction.Bidirectional, "TXRX");
+    }
+
     public PortMappingVersion710(DataBroker dataBroker, DeviceTransactionManager deviceTransactionManager,
         OpenRoadmInterfaces openRoadmInterfaces) {
         this.dataBroker = dataBroker;
@@ -695,21 +703,11 @@ public class PortMappingVersion710 {
     }
 
     private String createLogicalConnectionPort(Ports port, int index, int portIndex) {
-        String lcp = null;
-        switch (port.getPortDirection()) {
-            case Tx:
-                lcp = "SRG" + index + "-PP" + portIndex + "-TX";
-                break;
-            case Rx:
-                lcp = "SRG" + index + "-PP" + portIndex + "-RX";
-                break;
-            case Bidirectional:
-                lcp = "SRG" + index + "-PP" + portIndex + "-TXRX";
-                break;
-            default:
-                LOG.error("Unsupported port direction for port {} : {}", port, port.getPortDirection());
+        if (SUFFIX.containsKey(port.getPortDirection())) {
+            return String.join("-", "SRG" + index, "PP" + portIndex, SUFFIX.get(port.getPortDirection()));
         }
-        return lcp;
+        LOG.error("port {} : Unsupported port direction {}", port, port.getPortDirection());
+        return null;
     }
 
     private Map<McCapabilityProfileKey, McCapabilityProfile> getMcCapabilityProfiles(String deviceId, Info ordmInfo) {