Improve networkmodel util OpenRoadmOtnTopology 1/2 67/99667/1
authorguillaume.lambert <guillaume.lambert@orange.com>
Fri, 4 Feb 2022 10:28:03 +0000 (11:28 +0100)
committerGilles Thouenon <gilles.thouenon@orange.com>
Wed, 9 Feb 2022 08:37:48 +0000 (09:37 +0100)
- use class Map for OTU4 and OTUC4 support in some methods
- generalize ODUC3 and ODUC2 support in some methods

JIRA: TRNSPRTPCE-597 TRNSPRTPCE-526
Signed-off-by: guillaume.lambert <guillaume.lambert@orange.com>
Change-Id: I1140eec757df681ebb3a312be913aead061c29e5

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

index 1fe13910eeec53d13f1bed82240308f470a13587..8eebe23e393356b216ca9965017276b1f0725013 100644 (file)
@@ -101,6 +101,9 @@ public final class OpenRoadmOtnTopology {
         OtnLinkType.ODUC4, 400000L,
         OtnLinkType.ODUC3, 300000L,
         OtnLinkType.ODUC2, 200000L);
+    private static Map<OtnLinkType, Long> otnOtuLinkTypeBwMap = Map.of(
+        OtnLinkType.OTU4, 100000L,
+        OtnLinkType.OTUC4, 400000L);
     private static Map<Uint32, Long> serviceRateBwIncrMap = Map.of(
         Uint32.valueOf(1), 1000L,
         Uint32.valueOf(10), 10000L,
@@ -137,7 +140,7 @@ public final class OpenRoadmOtnTopology {
 
         return new TopologyShard(
             null,
-            OtnLinkType.OTU4.equals(linkType) || OtnLinkType.OTUC4.equals(linkType)
+            otnOtuLinkTypeBwMap.containsKey(linkType)
                 ? initialiseOtnLinks(nodeA, tpA, nodeZ, tpZ, linkType)
                 : null);
     }
@@ -161,28 +164,24 @@ public final class OpenRoadmOtnTopology {
                 .Link notifLink,
             List<Link> supportedOtu4links, List<TerminationPoint> supportedTPs, OtnLinkType linkType) {
 
-        List<Link> links;
-        switch (linkType) {
-            case OTU4:
-            case OTUC4:
-                links = initialiseOtnLinks(
-                        notifLink.getATermination().getNodeId(), notifLink.getATermination().getTpId(),
-                        notifLink.getZTermination().getNodeId(), notifLink.getZTermination().getTpId(), linkType);
-                return new TopologyShard(null, links);
-            case ODTU4:
-            case ODUC4:
-                links = initialiseOtnLinks(
+        if (otnOtuLinkTypeBwMap.containsKey(linkType)) {
+            return new TopologyShard(
+                null,
+                initialiseOtnLinks(
                     notifLink.getATermination().getNodeId(), notifLink.getATermination().getTpId(),
-                    notifLink.getZTermination().getNodeId(), notifLink.getZTermination().getTpId(), linkType);
-                links.addAll(updateOtnLinkBwParameters(supportedOtu4links, linkType));
-                List<TerminationPoint> updatedTPs = new ArrayList<>();
-                for (TerminationPoint tp : supportedTPs) {
-                    updatedTPs.add(updateTp(tp, true, linkType));
-                }
-                return new TopologyShard(null, links, updatedTPs);
-                //TODO shouldn't other linkt type listed in otnLinkTypeBwMap be handled too ?
-            default:
-                return null;
+                    notifLink.getZTermination().getNodeId(), notifLink.getZTermination().getTpId(), linkType));
+        } else if (otnLinkTypeBwMap.containsKey(linkType)) {
+            List<Link> links = initialiseOtnLinks(
+                notifLink.getATermination().getNodeId(), notifLink.getATermination().getTpId(),
+                notifLink.getZTermination().getNodeId(), notifLink.getZTermination().getTpId(), linkType);
+            links.addAll(updateOtnLinkBwParameters(supportedOtu4links, linkType));
+            List<TerminationPoint> updatedTPs = new ArrayList<>();
+            for (TerminationPoint tp : supportedTPs) {
+                updatedTPs.add(updateTp(tp, true, linkType));
+            }
+            return new TopologyShard(null, links, updatedTPs);
+        } else {
+            return null;
         }
     }
 
@@ -257,11 +256,11 @@ public final class OpenRoadmOtnTopology {
                 tps.add(updateNodeTpTsPool(tp, serviceRate, tribPortNb, minTribSlotNb, maxTribSlotNb, isDeletion));
             }
         }
-        if (!links.isEmpty() && !tps.isEmpty()) {
-            return new TopologyShard(null, links, tps);
-        } else {
+        if (links.isEmpty() || tps.isEmpty()) {
             LOG.error("unable to update otn links");
             return new TopologyShard(null, null, null);
+        } else {
+            return new TopologyShard(null, links, tps);
         }
     }
 
@@ -293,7 +292,6 @@ public final class OpenRoadmOtnTopology {
             OtnLinkType linkType) {
 
         List<Link> links = new ArrayList<>();
-        OtnLinkType otnLinkType = null;
         for (Link link : suppOtuLinks) {
             if (link.augmentation(Link1.class) == null
                     || link.augmentation(
@@ -301,16 +299,14 @@ public final class OpenRoadmOtnTopology {
                 LOG.error(OTN_PARAMS_ERROR, link.getLinkId().getValue());
                 return new TopologyShard(null, null, null);
             }
-            otnLinkType = link.augmentation(
+            OtnLinkType otnLinkType = link.augmentation(
                     org.opendaylight.yang.gen.v1.http.transportpce.topology.rev220123.Link1.class).getOtnLinkType();
-            if (OtnLinkType.OTU4.equals(otnLinkType)) {
-                links.add(updateOtnLinkBwParameters(link, 100000L, 0L));
-            } else if (OtnLinkType.OTUC4.equals(otnLinkType)) {
-                links.add(updateOtnLinkBwParameters(link, 400000L, 0L));
-            } else {
+            if (!otnOtuLinkTypeBwMap.containsKey(otnLinkType)) {
+            //TODO shouldn't other link type listed in otnLinkTypeBwMap be handled too ?
                 LOG.warn("Unexpected otn-link-type {} for link {}", otnLinkType, link.getLinkId());
+                continue;
             }
-            //TODO shouldn't other linkt type listed in otnLinkTypeBwMap be handled too ?
+            links.add(updateOtnLinkBwParameters(link, otnOtuLinkTypeBwMap.get(otnLinkType) , 0L));
         }
         List<TerminationPoint> tps = new ArrayList<>();
         for (TerminationPoint tp : oldTps) {
@@ -333,19 +329,12 @@ public final class OpenRoadmOtnTopology {
                 .setOtnLinkType(linkType).build();
         Link1Builder otnLink1Bldr = new Link1Builder()
             .setUsedBandwidth(Uint32.valueOf(0));
-        switch (linkType) {
-            case OTU4:
-            case ODTU4:
-                otnLink1Bldr.setAvailableBandwidth(Uint32.valueOf(100000));
-                break;
-            case OTUC4:
-            case ODUC4:
-                otnLink1Bldr.setAvailableBandwidth(Uint32.valueOf(400000));
-                break;
-            default:
-                LOG.error("unable to set available bandwidth to unknown link type");
-                break;
-            //TODO shouldn't other linkt type listed in otnLinkTypeBwMap be handled too ?
+        if (otnOtuLinkTypeBwMap.containsKey(linkType)) {
+            otnLink1Bldr.setAvailableBandwidth(Uint32.valueOf(otnOtuLinkTypeBwMap.get(linkType)));
+        } else if (otnLinkTypeBwMap.containsKey(linkType)) {
+            otnLink1Bldr.setAvailableBandwidth(Uint32.valueOf(otnLinkTypeBwMap.get(linkType)));
+        } else {
+            LOG.error("unable to set available bandwidth to unknown link type");
         }
         // create link A-Z
         LinkBuilder ietfLinkAZBldr = TopologyUtils.createLink(nodeATopo, nodeZTopo, tpA, tpZ, linkType.getName());
@@ -381,36 +370,27 @@ public final class OpenRoadmOtnTopology {
     private static Link updateOtnLinkBwParameters(Link link, Long availBw, Long usedBw) {
 
         LOG.debug("in updateOtnLinkBwParameters with availBw = {}, usedBw = {}", availBw, usedBw);
-        LinkBuilder updatedLinkBldr = new LinkBuilder(link);
-        Link1Builder updatedLink1Bldr = new Link1Builder(link.augmentation(Link1.class))
-            .setAvailableBandwidth(Uint32.valueOf(availBw))
-            .setUsedBandwidth(Uint32.valueOf(usedBw));
-        updatedLinkBldr.addAugmentation(updatedLink1Bldr.build());
-        return updatedLinkBldr.build();
+        return new LinkBuilder(link)
+            .addAugmentation(
+                new Link1Builder(link.augmentation(Link1.class))
+                    .setAvailableBandwidth(Uint32.valueOf(availBw))
+                    .setUsedBandwidth(Uint32.valueOf(usedBw))
+                    .build())
+            .build();
     }
 
     private static List<Link> updateOtnLinkBwParameters(List<Link> supportedLinks, OtnLinkType linkType) {
 
         LOG.debug("in updateOtnLinkBwParameters with supportedLinks = {}, linkType = {}", supportedLinks, linkType);
-        Uint32 usedBw;
-        switch (linkType) {
-            case ODTU4:
-                usedBw = Uint32.valueOf(100000);
-                break;
-            case ODUC4:
-                usedBw = Uint32.valueOf(400000);
-                break;
-            default:
-                usedBw = Uint32.valueOf(0);
-                break;
-        }
-        //TODO shouldn't other linkt type listed in otnLinkTypeBwMap be handled too ?
         List<Link> updatedlinks = new ArrayList<>();
         for (Link link : supportedLinks) {
             LinkBuilder updatedLinkBldr = new LinkBuilder(link);
             updatedLinkBldr.addAugmentation(new Link1Builder(link.augmentation(Link1.class))
                 .setAvailableBandwidth(Uint32.valueOf(0))
-                .setUsedBandwidth(usedBw)
+                .setUsedBandwidth(
+                    otnLinkTypeBwMap.containsKey(linkType)
+                        ? Uint32.valueOf(otnLinkTypeBwMap.get(linkType))
+                        : Uint32.valueOf(0))
                 .build());
             updatedlinks.add(updatedLinkBldr.build());
         }