Adapt network module to update OTU links only
[transportpce.git] / networkmodel / src / main / java / org / opendaylight / transportpce / networkmodel / util / OpenRoadmOtnTopology.java
index 649852dba6af94fadf8c7596bf9601a2827b923e..4f65190f7a3e650e9b9955b4b1a5c9df9481d7d8 100644 (file)
@@ -146,9 +146,9 @@ public final class OpenRoadmOtnTopology {
         }
         if (links.size() == 2) {
             links.addAll(initialiseOtnLinks(suppOtuLinks.get(0).getSource().getSourceNode().getValue(),
-                suppOtuLinks.get(0).getSource().getSourceTp().toString(),
+                suppOtuLinks.get(0).getSource().getSourceTp().getValue(),
                 suppOtuLinks.get(0).getDestination().getDestNode().getValue(),
-                suppOtuLinks.get(0).getDestination().getDestTp().toString(),
+                suppOtuLinks.get(0).getDestination().getDestTp().getValue(),
                 linkType));
         }
         List<TerminationPoint> tps = new ArrayList<>();
@@ -213,6 +213,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<>();
@@ -671,7 +694,7 @@ public final class OpenRoadmOtnTopology {
                 SupportingTerminationPoint stp = new SupportingTerminationPointBuilder()
                     .setNetworkRef(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID))
                     .setNodeRef(new NodeId(node.getNodeId() + XPDR + node.getXpdrNb()))
-                    .setTpRef(tpId.getValue())
+                    .setTpRef(tpId)
                     .build();
                 TerminationPoint ietfTpNw = buildIetfTp(tpceTp1Bldr, otnTp1, tpType, tpId, Map.of(stp.key(), stp),
                     mapping);
@@ -752,20 +775,16 @@ public final class OpenRoadmOtnTopology {
                     .setOperationalState(TopologyUtils.setNetworkOperState(mapping.getPortOperState()))
                     .build();
 
-        ietfTpBldr.setTpId(tpId)
-            .withKey(new TerminationPointKey(tpId))
-            .addAugmentation(otnTp1)
-            .addAugmentation(ocnTp);
-        return ietfTpBldr.build();
+        return ietfTpBldr.setTpId(tpId)
+                .withKey(new TerminationPointKey(tpId))
+                .addAugmentation(otnTp1)
+                .addAugmentation(ocnTp)
+                .build();
     }
 
     private static String formatNodeName(String nodeName, String tpName) {
-        String newNodeName = null;
-        if (nodeName.contains(XPDR)) {
-            newNodeName = nodeName;
-        } else {
-            newNodeName = new StringBuilder(nodeName).append("-").append(tpName.split("-")[0]).toString();
-        }
-        return newNodeName;
+        return nodeName.contains(XPDR)
+                ? nodeName
+                : new StringBuilder(nodeName).append("-").append(tpName.split("-")[0]).toString();
     }
 }