Constants for service type
[transportpce.git] / pce / src / main / java / org / opendaylight / transportpce / pce / graph / PostAlgoPathValidator.java
index a0dd42d7184cdbea37ae4fa2700fa4b8ef8e7580..047d248a99022ee2d8facd93c388a0ae5f3be9a2 100644 (file)
@@ -8,19 +8,20 @@
 
 package org.opendaylight.transportpce.pce.graph;
 
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-
 import org.jgrapht.GraphPath;
 import org.opendaylight.transportpce.common.ResponseCodes;
+import org.opendaylight.transportpce.common.StringConstants;
 import org.opendaylight.transportpce.pce.constraints.PceConstraints;
 import org.opendaylight.transportpce.pce.constraints.PceConstraints.ResourcePair;
 import org.opendaylight.transportpce.pce.networkanalyzer.PceNode;
 import org.opendaylight.transportpce.pce.networkanalyzer.PceResult;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev181130.OpenroadmLinkType;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmLinkType;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
 import org.opendaylight.yangtools.yang.common.Uint16;
 import org.slf4j.Logger;
@@ -28,9 +29,8 @@ import org.slf4j.LoggerFactory;
 
 public class PostAlgoPathValidator {
     /* Logging. */
-    private static final Logger LOG = LoggerFactory.getLogger(PceGraph.class);
+    private static final Logger LOG = LoggerFactory.getLogger(PostAlgoPathValidator.class);
 
-    // TODO hard-coded 96
     private static final int MAX_WAWELENGTH = 96;
     private static final double MIN_OSNR_W100G = 17;
     private static final double TRX_OSNR = 33;
@@ -38,11 +38,14 @@ public class PostAlgoPathValidator {
     public static final Long CONST_OSNR = 1L;
     public static final double SYS_MARGIN = 0;
 
+    @SuppressFBWarnings(
+        value = "SF_SWITCH_FALLTHROUGH",
+        justification = "intentional fallthrough")
     public PceResult checkPath(GraphPath<String, PceGraphEdge> path, Map<NodeId, PceNode> allPceNodes,
         PceResult pceResult, PceConstraints pceHardConstraints, String serviceType) {
 
         // check if the path is empty
-        if (path.getEdgeList().size() == 0) {
+        if (path.getEdgeList().isEmpty()) {
             pceResult.setRC(ResponseCodes.RESPONSE_FAILED);
             return pceResult;
         }
@@ -51,8 +54,8 @@ public class PostAlgoPathValidator {
         //variable to deal with 1GE (Nb=1) and 10GE (Nb=10) cases
         switch (serviceType) {
 
-            case "100GE":
-            case "OTU4":
+            case StringConstants.SERVICE_TYPE_100GE:
+            case StringConstants.SERVICE_TYPE_OTU4:
                 // choose wavelength available in all nodes of the path
                 Long waveL = chooseWavelength(path, allPceNodes);
                 pceResult.setServiceType(serviceType);
@@ -62,7 +65,7 @@ public class PostAlgoPathValidator {
                     return pceResult;
                 }
                 pceResult.setResultWavelength(waveL);
-                LOG.info("In PostAlgoPathValidator: chooseWavelength WL found {} {}", waveL, path.toString());
+                LOG.info("In PostAlgoPathValidator: chooseWavelength WL found {} {}", waveL, path);
 
                 // Check the OSNR
                 if (!checkOSNR(path)) {
@@ -94,10 +97,10 @@ public class PostAlgoPathValidator {
 
                 break;
 
-            case "10GE":
-                tribSlotNb = 10;
+            case StringConstants.SERVICE_TYPE_10GE:
+                tribSlotNb = 8;
             //fallthrough
-            case "1GE":
+            case StringConstants.SERVICE_TYPE_1GE:
                 pceResult.setRC(ResponseCodes.RESPONSE_FAILED);
                 pceResult.setServiceType(serviceType);
                 Map<String, Uint16> tribPort = chooseTribPort(path, allPceNodes);
@@ -113,15 +116,15 @@ public class PostAlgoPathValidator {
                 }
                 break;
 
-            case "ODU4":
+            case StringConstants.SERVICE_TYPE_ODU4:
                 pceResult.setRC(ResponseCodes.RESPONSE_OK);
-                LOG.info("In PostAlgoPathValidator: ODU4 path found {}", path.toString());
+                LOG.info("In PostAlgoPathValidator: ODU4 path found {}", path);
                 break;
 
             default:
                 pceResult.setRC(ResponseCodes.RESPONSE_FAILED);
                 LOG.warn("In PostAlgoPathValidator checkPath: unsupported serviceType {} found {}",
-                    serviceType, path.toString());
+                    serviceType, path);
                 break;
         }
 
@@ -133,9 +136,9 @@ public class PostAlgoPathValidator {
         Long wavelength = -1L;
         for (long i = 1; i <= MAX_WAWELENGTH; i++) {
             boolean completed = true;
-            LOG.debug("In chooseWavelength: {} {}", path.getLength(), path.toString());
+            LOG.debug("In chooseWavelength: {} {}", path.getLength(), path);
             for (PceGraphEdge edge : path.getEdgeList()) {
-                LOG.debug("In chooseWavelength: source {} ", edge.link().getSourceId().toString());
+                LOG.debug("In chooseWavelength: source {} ", edge.link().getSourceId());
                 PceNode pceNode = allPceNodes.get(edge.link().getSourceId());
                 if (!pceNode.checkWL(i)) {
                     completed = false;
@@ -163,10 +166,7 @@ public class PostAlgoPathValidator {
                     edge.link().getLinkId().getValue());
             }
         }
-        if (latency > maxLatency) {
-            return false;
-        }
-        return true;
+        return (latency < maxLatency);
     }
 
     // Check the inclusion if it is defined in the hard constraints
@@ -179,17 +179,17 @@ public class PostAlgoPathValidator {
         List<PceGraphEdge> pathEdges = path.getEdgeList();
         LOG.debug(" in checkInclude vertex list: [{}]", path.getVertexList());
 
-        List<String> listOfElementsSubNode = new ArrayList<String>();
+        List<String> listOfElementsSubNode = new ArrayList<>();
         listOfElementsSubNode.add(pathEdges.get(0).link().getsourceNetworkSupNodeId());
         listOfElementsSubNode.addAll(listOfElementsBuild(pathEdges, PceConstraints.ResourceType.NODE,
             pceHardConstraintsInput));
 
-        List<String> listOfElementsCLLI = new ArrayList<String>();
+        List<String> listOfElementsCLLI = new ArrayList<>();
         listOfElementsCLLI.add(pathEdges.get(0).link().getsourceCLLI());
         listOfElementsCLLI.addAll(listOfElementsBuild(pathEdges, PceConstraints.ResourceType.CLLI,
             pceHardConstraintsInput));
 
-        List<String> listOfElementsSRLG = new ArrayList<String>();
+        List<String> listOfElementsSRLG = new ArrayList<>();
         // first link is XPONDEROUTPUT, no SRLG for it
         listOfElementsSRLG.add("NONE");
         listOfElementsSRLG.addAll(listOfElementsBuild(pathEdges, PceConstraints.ResourceType.SRLG,
@@ -237,7 +237,7 @@ public class PostAlgoPathValidator {
     private List<String> listOfElementsBuild(List<PceGraphEdge> pathEdges, PceConstraints.ResourceType type,
         PceConstraints pceHardConstraints) {
 
-        List<String> listOfElements = new ArrayList<String>();
+        List<String> listOfElements = new ArrayList<>();
         for (PceGraphEdge link : pathEdges) {
             switch (type) {
                 case NODE:
@@ -262,7 +262,6 @@ public class PostAlgoPathValidator {
                             listOfElements.add(srlgStr);
                             LOG.info("listOfElementsBuild. FOUND SRLG {} in link {}", srlgStr, link.link());
                             found = true;
-                            continue;
                         }
                     }
                     if (!found) {
@@ -279,7 +278,7 @@ public class PostAlgoPathValidator {
 
     private Map<String, Uint16> chooseTribPort(GraphPath<String,
         PceGraphEdge> path, Map<NodeId, PceNode> allPceNodes) {
-        LOG.info("In choosetribPort: edgeList = {} ", path.getEdgeList().toString());
+        LOG.info("In choosetribPort: edgeList = {} ", path.getEdgeList());
         Map<String, Uint16> tribPortMap = new HashMap<>();
 
         for (PceGraphEdge edge : path.getEdgeList()) {
@@ -308,7 +307,7 @@ public class PostAlgoPathValidator {
 
     private Map<String, List<Uint16>> chooseTribSlot(GraphPath<String,
         PceGraphEdge> path, Map<NodeId, PceNode> allPceNodes, int nbSlot) {
-        LOG.info("In choosetribSlot2: edgeList = {} ", path.getEdgeList().toString());
+        LOG.info("In choosetribSlot: edgeList = {} ", path.getEdgeList());
         Map<String, List<Uint16>> tribSlotMap = new HashMap<>();
 
         for (PceGraphEdge edge : path.getEdgeList()) {
@@ -334,7 +333,7 @@ public class PostAlgoPathValidator {
                 discontinue = false;
                 Integer val = commonEdgeTsPool.get(index).toJava();
                 for (int i = 0; i < nbSlot; i++) {
-                    if (commonEdgeTsPool.get(index + i).equals(val + i)) {
+                    if (commonEdgeTsPool.get(index + i).equals(Uint16.valueOf(val + i))) {
                         tribSlotList.add(commonEdgeTsPool.get(index + i));
                     } else {
                         discontinue = true;
@@ -350,63 +349,6 @@ public class PostAlgoPathValidator {
         return tribSlotMap;
     }
 
-    private List<List<Uint16>> chooseTribSlot3(GraphPath<String, PceGraphEdge> path,
-        Map<NodeId, PceNode> allPceNodes) {
-        List<List<Uint16>> tribSlot = new ArrayList<>();
-        boolean statusOK = true;
-        boolean check = false;
-        Object nodeClass = allPceNodes.getClass();
-        if (nodeClass.getClass().isInstance(PceNode.class)) {
-            LOG.debug("In choosetribSlot: AllPceNodes contains PceNode instance, no trib port search");
-            return tribSlot;
-        } else if (nodeClass.getClass().isInstance(PceNode.class)) {
-            LOG.debug("In choosetribPort: {} {}", path.getLength(), path.toString());
-        }
-        for (PceGraphEdge edge : path.getEdgeList()) {
-            LOG.debug("In chooseTribSlot: source {} ", edge.link().getSourceId().toString());
-            PceNode pceNode = allPceNodes.get(edge.link().getSourceId());
-            Object tps = allPceNodes.get(edge.link().getSourceTP());
-            Object tpd = allPceNodes.get(edge.link().getDestTP());
-            if ((pceNode.getAvailableTribSlots().containsKey(tps.toString()))
-                && (pceNode.getAvailableTribSlots().containsKey(tpd.toString()))) {
-                List<Uint16> tribSlotEdgeSourceN = new ArrayList<>();
-                List<Uint16> tribSlotEdgeDestN = new ArrayList<>();
-                tribSlotEdgeSourceN = pceNode.getAvailableTribSlots().get(tps.toString());
-                tribSlotEdgeDestN = pceNode.getAvailableTribSlots().get(tps.toString());
-                check = false;
-                for (int i = 0; i <= 79; i++) {
-                    if (tribSlotEdgeSourceN.get(i) == null) {
-                        break;
-                    }
-                    // TODO This will need to be modified as soon as the trib-slots allocation per
-                    // trib-port
-                    // policy applied by the different manufacturer is known
-                    if (tribSlotEdgeSourceN.get(i) == tribSlotEdgeDestN.get(i)) {
-                        check = true;
-                    } else {
-                        check = false;
-                        LOG.debug("In chooseTribSlot: Misalignement of trib slots between source {} and dest {}",
-                            edge.link().getSourceId().toString(), edge.link().getDestId().toString());
-                        break;
-                    }
-                }
-                if (check) {
-                    tribSlot.add(tribSlotEdgeSourceN);
-                }
-            } else {
-                LOG.debug("In chooseTribSlot: source {} does not have provisonned hosting HO interface ",
-                    edge.link().getSourceId().toString());
-                statusOK = false;
-            }
-        }
-        if (statusOK && check) {
-            return tribSlot;
-        } else {
-            tribSlot.clear();
-            return tribSlot;
-        }
-    }
-
     // Check the path OSNR
     private boolean checkOSNR(GraphPath<String, PceGraphEdge> path) {
         double linkOsnrDb;
@@ -430,10 +372,7 @@ public class PostAlgoPathValidator {
             return false;
         }
         LOG.info("In checkOSNR: OSNR of the path is {} dB", osnrDb);
-        if ((osnrDb + SYS_MARGIN) < MIN_OSNR_W100G) {
-            return false;
-        }
-        return true;
+        return ((osnrDb + SYS_MARGIN) > MIN_OSNR_W100G);
     }
 
     private double getOsnrDb(double osnrLu) {