Fix few code issues
[transportpce.git] / pce / src / main / java / org / opendaylight / transportpce / pce / graph / PostAlgoPathValidator.java
index 0ec32575c447c0c404bd688a9c8706728d967b84..61e7f145aa52e840d302b93e5cd0cae3b06e977a 100644 (file)
@@ -25,9 +25,9 @@ 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.opendaylight.transportpce.pce.rev210701.SpectrumAssignment;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev210701.SpectrumAssignmentBuilder;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmLinkType;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220118.SpectrumAssignment;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220118.SpectrumAssignmentBuilder;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev211210.OpenroadmLinkType;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.otn.common.types.rev181130.OpucnTribSlotDef;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
 import org.opendaylight.yangtools.yang.common.Uint16;
@@ -44,6 +44,7 @@ public class PostAlgoPathValidator {
     public static final Long CONST_OSNR = 1L;
     public static final double SYS_MARGIN = 0;
 
+    @SuppressWarnings("fallthrough")
     @SuppressFBWarnings(
         value = "SF_SWITCH_FALLTHROUGH",
         justification = "intentional fallthrough")
@@ -60,6 +61,8 @@ public class PostAlgoPathValidator {
         SpectrumAssignment spectrumAssignment = null;
         //variable to deal with 1GE (Nb=1) and 10GE (Nb=10) cases
         switch (serviceType) {
+            case StringConstants.SERVICE_TYPE_OTUC2:
+            case StringConstants.SERVICE_TYPE_OTUC3:
             case StringConstants.SERVICE_TYPE_OTUC4:
             case StringConstants.SERVICE_TYPE_400GE:
                 spectralWidthSlotNumber = GridConstant.SPECTRAL_WIDTH_SLOT_NUMBER_MAP
@@ -138,9 +141,13 @@ public class PostAlgoPathValidator {
                 }
                 break;
             case StringConstants.SERVICE_TYPE_ODU4:
+            case StringConstants.SERVICE_TYPE_ODUC2:
+            case StringConstants.SERVICE_TYPE_ODUC3:
             case StringConstants.SERVICE_TYPE_ODUC4:
+            case StringConstants.SERVICE_TYPE_100GE_S:
                 pceResult.setRC(ResponseCodes.RESPONSE_OK);
-                LOG.info("In PostAlgoPathValidator: ODU4/ODUC4 path found {}", path);
+                pceResult.setServiceType(serviceType);
+                LOG.info("In PostAlgoPathValidator: ODU4/ODUCn path found {}", path);
                 break;
             default:
                 pceResult.setRC(ResponseCodes.RESPONSE_FAILED);
@@ -156,13 +163,13 @@ public class PostAlgoPathValidator {
         double latency = 0;
 
         for (PceGraphEdge edge : path.getEdgeList()) {
-            try {
-                latency += edge.link().getLatency();
-                LOG.debug("- In checkLatency: latency of {} = {} units", edge.link().getLinkId().getValue(), latency);
-            } catch (NullPointerException e) {
+            if (edge.link() == null || edge.link().getLatency() == null) {
                 LOG.warn("- In checkLatency: the link {} does not contain latency field",
                     edge.link().getLinkId().getValue());
+                return false;
             }
+            latency += edge.link().getLatency();
+            LOG.debug("- In checkLatency: latency of {} = {} units", edge.link().getLinkId().getValue(), latency);
         }
         return (latency < maxLatency);
     }
@@ -281,9 +288,9 @@ public class PostAlgoPathValidator {
 
         for (PceGraphEdge edge : path.getEdgeList()) {
             NodeId linkSrcNode = edge.link().getSourceId();
-            String linkSrcTp = edge.link().getSourceTP().toString();
+            String linkSrcTp = edge.link().getSourceTP().getValue();
             NodeId linkDestNode = edge.link().getDestId();
-            String linkDestTp = edge.link().getDestTP().toString();
+            String linkDestTp = edge.link().getDestTP().getValue();
             PceNode pceOtnNodeSrc = allPceNodes.get(linkSrcNode);
             PceNode pceOtnNodeDest = allPceNodes.get(linkDestNode);
             List<Uint16> srcTpnPool = pceOtnNodeSrc.getAvailableTribPorts().get(linkSrcTp);
@@ -316,9 +323,9 @@ public class PostAlgoPathValidator {
 
         for (PceGraphEdge edge : path.getEdgeList()) {
             NodeId linkSrcNode = edge.link().getSourceId();
-            String linkSrcTp = edge.link().getSourceTP().toString();
+            String linkSrcTp = edge.link().getSourceTP().getValue();
             NodeId linkDestNode = edge.link().getDestId();
-            String linkDestTp = edge.link().getDestTP().toString();
+            String linkDestTp = edge.link().getDestTP().getValue();
             PceNode pceOtnNodeSrc = allPceNodes.get(linkSrcNode);
             PceNode pceOtnNodeDest = allPceNodes.get(linkDestNode);
             List<Uint16> srcTsPool = pceOtnNodeSrc.getAvailableTribSlots().get(linkSrcTp);