Improve portmapping LCP names creation process
[transportpce.git] / common / src / main / java / org / opendaylight / transportpce / common / mapping / PortMappingVersion121.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) {