Fix bug in setting rate of tp in network module 53/97853/11
authorGilles Thouenon <gilles.thouenon@orange.com>
Fri, 8 Oct 2021 08:47:51 +0000 (10:47 +0200)
committerGilles Thouenon <gilles.thouenon@orange.com>
Thu, 9 Dec 2021 08:50:34 +0000 (09:50 +0100)
Depending on the first SupportedInterfaceCapability, it may happen that
the if-10GE if-cap-type is chosen, for which no rate is allocated. Look
at other if-cap-type to determine the rate.

JIRA: TRNSPRTPCE-541
Signed-off-by: Gilles Thouenon <gilles.thouenon@orange.com>
Change-Id: Ie174c9c6b0329d9ffd65971ab140289a13fe3856

networkmodel/src/main/java/org/opendaylight/transportpce/networkmodel/util/OpenRoadmOtnTopology.java
networkmodel/src/test/java/org/opendaylight/transportpce/networkmodel/util/OpenRoadmOtnTopologyTest.java

index 4f65190f7a3e650e9b9955b4b1a5c9df9481d7d8..62aa756ce38b354b56531736b0778ef3a6bae894 100644 (file)
@@ -667,8 +667,11 @@ public final class OpenRoadmOtnTopology {
                     .setSupportedInterfaceCapability(supIfMap)
                     .build();
                 otnTp1Bldr.setTpSupportedInterfaces(tpSupIf);
+                //TODO: It is not logical to assign a priori one of the possible rate to the TP.
+                //Would be worth assigning per default "unallocated" at the tp creation step,
+                //and updating it with correct rate when it supports a specific service.
                 if (withRate) {
-                    xtpcaBldr.setRate(fixRate(mapping.getSupportedInterfaceCapability().get(0)));
+                    xtpcaBldr.setRate(fixRate(mapping.getSupportedInterfaceCapability()));
                     otnTp1Bldr.setXpdrTpPortConnectionAttributes(xtpcaBldr.build());
                 }
             } else {
@@ -713,21 +716,19 @@ public final class OpenRoadmOtnTopology {
         }
     }
 
-    private static Class<? extends OduRateIdentity> fixRate(Class<? extends
-            SupportedIfCapability> ifCapType) {
-        switch (ifCapType.getSimpleName()) {
-            case "If100GEODU4":
-            case "IfOCHOTU4ODU4":
-                return ODU4.class;
-            case "If1GEODU0":
-                return ODU0.class;
-            case "If10GEODU2":
-                return ODU2.class;
-            case "If10GEODU2e":
-                return ODU2e.class;
-            default:
-                return null;
+    private static Class<? extends OduRateIdentity> fixRate(List<Class<? extends SupportedIfCapability>> list) {
+        Map<String, Class<? extends OduRateIdentity>> rateMap = Map.of(
+            "If100GEODU4", ODU4.class,
+            "IfOCHOTU4ODU4", ODU4.class,
+            "If1GEODU0", ODU0.class,
+            "If10GEODU2", ODU2.class,
+            "If10GEODU2e", ODU2e.class);
+        for (Class<? extends SupportedIfCapability> class1 : list) {
+            if (rateMap.containsKey(class1.getSimpleName())) {
+                return rateMap.get(class1.getSimpleName());
+            }
         }
+        return null;
     }
 
     private static Map<SupportingNodeKey,SupportingNode> createSupportingNodes(OtnTopoNode node) {
index 7f0ba490d777b985e0de5161a3bdf36693adb6e5..e6c209a407df109fef7a0e9b871eaff013219785 100644 (file)
@@ -965,7 +965,7 @@ public class OpenRoadmOtnTopologyTest {
                     .or(containsString(String.valueOf(If10GEODU2.class)))
                     .or(containsString(String.valueOf(If10GE.class))));
             }
-            assertThat("the rate should be ODU2 or ODU2e or 10GE",
+            assertThat("the rate should be ODU2 or ODU2e",
                 String.valueOf(tpList.get(2)
                     .augmentation(
                         org.opendaylight.yang.gen.v1.http.org.openroadm.otn.network.topology.rev200529