Manage ODU4 services over multiple OTU4
[transportpce.git] / networkmodel / src / main / java / org / opendaylight / transportpce / networkmodel / util / OpenRoadmOtnTopology.java
index dd5325563b63418553daa1dddc46c4217a871d8a..fa02061f1d0de0215bc455d6b7ebabb2ac3a343d 100644 (file)
@@ -18,8 +18,8 @@ import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.transportpce.common.NetworkUtils;
 import org.opendaylight.transportpce.networkmodel.dto.OtnTopoNode;
 import org.opendaylight.transportpce.networkmodel.dto.TopologyShard;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210426.mapping.Mapping;
-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.rev210927.mapping.Mapping;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210927.network.Nodes;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.types.rev191129.XpdrNodeTypes;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.equipment.states.types.rev191129.AdminStates;
@@ -130,6 +130,47 @@ public final class OpenRoadmOtnTopology {
         return new TopologyShard(null, links);
     }
 
+    public static TopologyShard createOtnLinks(
+            org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.renderer.rpc.result.sp
+                .Link notifLink,
+            OtnLinkType linkType) {
+
+        return new TopologyShard(null, initialiseOtnLinks(notifLink.getATermination().getNodeId(),
+            notifLink.getATermination().getTpId(), notifLink.getZTermination().getNodeId(),
+            notifLink.getZTermination().getTpId(), linkType));
+    }
+
+    public static TopologyShard createOtnLinks(
+            org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.renderer.rpc.result.sp
+                .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(
+                    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);
+            default:
+                return null;
+        }
+    }
+
     public static TopologyShard createOtnLinks(List<Link> suppOtuLinks, List<TerminationPoint> oldTps,
             OtnLinkType linkType) {
         List<Link> links = new ArrayList<>();
@@ -213,6 +254,29 @@ public final class OpenRoadmOtnTopology {
         }
     }
 
+    public static TopologyShard updateOtnLinks(List<Link> suppOtuLinks, boolean isDeletion) {
+        List<Link> links = new ArrayList<>();
+        for (Link link : suppOtuLinks) {
+            if (link.augmentation(Link1.class) == null
+                || link.augmentation(Link1.class).getAvailableBandwidth() == null
+                || link.augmentation(Link1.class).getUsedBandwidth() == null) {
+                LOG.error("Error with otn parameters of supported link {}", link.getLinkId().getValue());
+            } else {
+                if (isDeletion) {
+                    links.add(updateOtnLinkBwParameters(link, Long.valueOf(100000), Long.valueOf(0)));
+                } else {
+                    links.add(updateOtnLinkBwParameters(link, Long.valueOf(0), Long.valueOf(100000)));
+                }
+            }
+        }
+        if (links.isEmpty()) {
+            LOG.error("unable to update otn links");
+            return new TopologyShard(null, null, null);
+        } else {
+            return new TopologyShard(null, links, null);
+        }
+    }
+
     public static TopologyShard deleteOtnLinks(List<Link> suppOtuLinks, List<TerminationPoint> oldTps,
             OtnLinkType linkType) {
         List<Link> links = new ArrayList<>();
@@ -238,7 +302,7 @@ public final class OpenRoadmOtnTopology {
         for (TerminationPoint tp : oldTps) {
             tps.add(updateTp(tp, false, linkType));
         }
-        if (links.size() == 2 && tps.size() == 2) {
+        if (!links.isEmpty() && !tps.isEmpty()) {
             return new TopologyShard(null, links, tps);
         } else {
             return new TopologyShard(null, null, null);
@@ -309,6 +373,32 @@ public final class OpenRoadmOtnTopology {
         return updatedLinkBldr.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;
+        }
+        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)
+                .build());
+            updatedlinks.add(updatedLinkBldr.build());
+        }
+        return updatedlinks;
+    }
+
     private static TerminationPoint updateTp(TerminationPoint originalTp, boolean addingTsTpnPoolTermination,
             OtnLinkType linkType) {
         LOG.debug("in updateTp");
@@ -644,8 +734,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 {
@@ -690,21 +783,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) {