fix deprecated openroadm interfaces/objects
[transportpce.git] / pce / src / main / java / org / opendaylight / transportpce / pce / networkanalyzer / MapUtils.java
index d3985f00497893d842a02b562e2aad4c0ae45260..de9f0e72431b697637f36e54890d53c1daff6505 100644 (file)
@@ -5,16 +5,20 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-package org.opendaylight.transportpce.pce;
+package org.opendaylight.transportpce.pce.networkanalyzer;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 
+import org.opendaylight.transportpce.pce.constraints.PceConstraints;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.Link1;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.link.rev181130.span.attributes.LinkConcatenation;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.Link1;
+
 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.networks.network.link.oms.attributes.Span;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev181130.OpenroadmLinkType;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.network.Node;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.LinkId;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.Link;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -26,6 +30,49 @@ public final class MapUtils {
     private MapUtils() {
     }
 
+    public static void mapDiversityConstraints(List<Node> allNodes, List<Link> allLinks,
+            PceConstraints pceHardConstraints) {
+        List<String> excClliNodes = pceHardConstraints.getExcludeClliNodes();
+        List<String> excNodes = pceHardConstraints.getExcludeNodes();
+        List<String> excSrlgLinks = pceHardConstraints.getExcludeSrlgLinks();
+
+        LOG.info("mapDiversityConstraints before : ExcludeClliNodes {} \n ExcludeNodes {} \n ExcludeSrlgLinks {}",
+                excClliNodes.toString(), excNodes.toString(), excSrlgLinks.toString());
+
+        for (Node node : allNodes) {
+            if (excClliNodes.contains(node.getNodeId().getValue())) {
+                LOG.debug("mapDiversityConstraints setExcludeCLLI for node {}", node.getNodeId().getValue());
+                pceHardConstraints.setExcludeCLLI(Arrays.asList(getCLLI(node)));
+            }
+
+            if (excNodes.contains(node.getNodeId().getValue())) {
+                LOG.debug("mapDiversityConstraints setExcludeSupNodes for node {}", node.getNodeId().getValue());
+                pceHardConstraints.setExcludeSupNodes(Arrays.asList(getSupNode(node)));
+            }
+        }
+
+        for (Link link : allLinks) {
+            if (excSrlgLinks.contains(link.getLinkId().getValue())) {
+                // zero SRLG means not populated as not OMS link
+                List<Long> srlg = null;
+                if (calcType(link) == OpenroadmLinkType.ROADMTOROADM) {
+                    srlg = getSRLG(link);
+                    if (!srlg.isEmpty()) {
+                        pceHardConstraints.setExcludeSRLG(srlg);
+                        LOG.debug("mapDiversityConstraints setExcludeSRLG {} for link {}",
+                                srlg.toString(), link.getLinkId().getValue());
+                    }
+                }
+            }
+        }
+
+        LOG.info("mapDiversityConstraints after : ExcludeCLLI {} \n ExcludeSupNodes {} \n ExcludeSRLG {}",
+                pceHardConstraints.getExcludeCLLI().toString(),
+                pceHardConstraints.getExcludeSupNodes().toString(),
+                pceHardConstraints.getExcludeSRLG().toString());
+
+    }
+
     public static String getCLLI(Node node) {
         // TODO STUB retrieve CLLI from node. for now it is supporting node ID of the first supp node
         return node.getSupportingNode().get(0).getNodeRef().getValue();
@@ -33,14 +80,13 @@ public final class MapUtils {
 
     public static List<Long> getSRLG(Link link) {
         List<Long> srlgList = new ArrayList<Long>();
-        Span span = getOmsAttributesSpan(link);
-        if (span != null) {
-            List<LinkConcatenation> linkList = span.getLinkConcatenation();
+        try {
+            List<LinkConcatenation> linkList = getOmsAttributesSpan(link).getLinkConcatenation();
             for (LinkConcatenation lc : linkList) {
                 srlgList.add(lc.getSRLGId());
             }
-        } else {
-            LOG.error("MapUtils: No LinkConcatenation for link : {}", link);
+        } catch (NullPointerException e) {
+            LOG.debug("No concatenation for this link");
         }
         return srlgList;
     }
@@ -53,7 +99,7 @@ public final class MapUtils {
     public static OpenroadmLinkType calcType(Link link) {
         Link1 link1 = null;
         OpenroadmLinkType tmplType = null;
-
+        // ID and type
         link1 = link.augmentation(Link1.class);
         if (link1 == null) {
             LOG.error("MapUtils: No Link augmentation available. {}", link.getLinkId().getValue());
@@ -61,6 +107,7 @@ public final class MapUtils {
         }
 
         tmplType = link1.getLinkType();
+
         if (tmplType == null) {
             LOG.error("MapUtils: No Link type available. {}", link.getLinkId().getValue());
             return null;
@@ -69,24 +116,36 @@ public final class MapUtils {
     }
 
     public static Span getOmsAttributesSpan(Link link) {
-        Link1 link1 = null;
+        org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.Link1 link1 = null;
         Span tempSpan = null;
-        link1 = link.augmentation(Link1.class);
+        link1 =
+            link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.Link1.class);
+
         if (link1 == null) {
             LOG.error("MapUtils: No Link augmentation available. {}", link.getLinkId().getValue());
-            return null;
         }
         try {
             tempSpan = link1.getOMSAttributes().getSpan();
-            if (tempSpan == null) {
-                LOG.error("MapUtils: No Link getOMSAttributes available. {}", link.getLinkId().getValue());
-                return null;
-            }
-        } catch (NullPointerException e) {
+        }
+        catch (NullPointerException e) {
             LOG.error("MapUtils: No Link getOMSAttributes available. {}", link.getLinkId().getValue());
-            return null;
         }
+
         return tempSpan;
     }
 
+    public static LinkId extractOppositeLink(Link link) {
+        LinkId tmpoppositeLink = null;
+        org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.Link1 linkOpposite
+            = link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.Link1.class);
+        tmpoppositeLink = linkOpposite.getOppositeLink();
+        LOG.debug("PceLink: reading oppositeLink.  {}", linkOpposite.toString());
+        if (tmpoppositeLink == null) {
+            LOG.error("PceLink: Error reading oppositeLink. Link is ignored {}", link.getLinkId().getValue());
+            return null;
+        }
+        return tmpoppositeLink;
+    }
+
+
 }