From c5ace756ae5f458a6d56307024ec7f267f67ed76 Mon Sep 17 00:00:00 2001 From: "guillaume.lambert" Date: Thu, 10 Mar 2022 21:30:15 +0100 Subject: [PATCH] Refactor PCE networkanalyzer PceCalculation JIRA: TRNSPRTPCE-643 Signed-off-by: guillaume.lambert Change-Id: I83ec5e58c2690e66e6a65190f8770112a524d1d8 --- .../pce/networkanalyzer/PceCalculation.java | 108 ++++++++++-------- 1 file changed, 58 insertions(+), 50 deletions(-) diff --git a/pce/src/main/java/org/opendaylight/transportpce/pce/networkanalyzer/PceCalculation.java b/pce/src/main/java/org/opendaylight/transportpce/pce/networkanalyzer/PceCalculation.java index 4b6dcc91e..d04664681 100644 --- a/pce/src/main/java/org/opendaylight/transportpce/pce/networkanalyzer/PceCalculation.java +++ b/pce/src/main/java/org/opendaylight/transportpce/pce/networkanalyzer/PceCalculation.java @@ -8,6 +8,7 @@ package org.opendaylight.transportpce.pce.networkanalyzer; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.math.BigDecimal; import java.util.ArrayList; import java.util.HashMap; @@ -137,12 +138,13 @@ public class PceCalculation { serviceFormatA = input.getServiceAEnd().getServiceFormat().getName(); serviceFormatZ = input.getServiceZEnd().getServiceFormat().getName(); serviceRate = input.getServiceAEnd().getServiceRate(); - serviceType = ServiceTypes.getServiceType(serviceFormatA, serviceRate, - (NodeTypes.Xpdr.equals(portMapping.getNode(input.getServiceAEnd().getNodeId()).getNodeInfo().getNodeType()) - && input.getServiceAEnd().getTxDirection() != null - && input.getServiceAEnd().getTxDirection().getPort() != null - && input.getServiceAEnd().getTxDirection().getPort().getPortName() != null) - ? portMapping.getMapping(input.getServiceAEnd().getNodeId(), + serviceType = ServiceTypes.getServiceType( + serviceFormatA, + serviceRate, + NodeTypes.Xpdr.equals(portMapping.getNode(input.getServiceAEnd().getNodeId()).getNodeInfo().getNodeType()) + && checkAendInputTxPortName() + ? portMapping.getMapping( + input.getServiceAEnd().getNodeId(), input.getServiceAEnd().getTxDirection().getPort().getPortName()) : null); @@ -155,23 +157,38 @@ public class PceCalculation { return true; } + private boolean checkAendInputTxPortName() { + return checkAendInputTxPort() + && input.getServiceAEnd().getTxDirection().getPort().getPortName() != null; + } + + private boolean checkAendInputTxPortDeviceName() { + return checkAendInputTxPort() + && input.getServiceAEnd().getTxDirection().getPort().getPortDeviceName() != null; + } + + private boolean checkAendInputTxPort() { + return input.getServiceAEnd() != null + && input.getServiceAEnd().getTxDirection() != null + && input.getServiceAEnd().getTxDirection().getPort() != null; + } + + private boolean checkZendInputTxPortDeviceName() { + return input.getServiceZEnd() != null + && input.getServiceZEnd().getTxDirection() != null + && input.getServiceZEnd().getTxDirection().getPort() != null + && input.getServiceZEnd().getTxDirection().getPort().getPortDeviceName() != null; + } + private void getAZnodeId() { - if (input.getServiceAEnd() != null - && input.getServiceAEnd().getTxDirection() != null - && input.getServiceAEnd().getTxDirection().getPort() != null - && input.getServiceAEnd().getTxDirection().getPort().getPortDeviceName() != null) { - anodeId = input.getServiceAEnd().getTxDirection().getPort().getPortDeviceName(); - } else { - anodeId = input.getServiceAEnd().getNodeId(); - } - if (input.getServiceZEnd() != null - && input.getServiceZEnd().getTxDirection() != null - && input.getServiceZEnd().getTxDirection().getPort() != null - && input.getServiceZEnd().getTxDirection().getPort().getPortDeviceName() != null) { - znodeId = input.getServiceZEnd().getTxDirection().getPort().getPortDeviceName(); - } else { - znodeId = input.getServiceZEnd().getNodeId(); - } + anodeId = + checkAendInputTxPortDeviceName() + ? input.getServiceAEnd().getTxDirection().getPort().getPortDeviceName() + : input.getServiceAEnd().getNodeId(); + znodeId = + checkZendInputTxPortDeviceName() + ? input.getServiceZEnd().getTxDirection().getPort().getPortDeviceName() + : input.getServiceZEnd().getNodeId(); } private boolean readMdSal() { @@ -475,6 +492,10 @@ public class PceCalculation { return; } + @SuppressWarnings("fallthrough") + @SuppressFBWarnings( + value = "SF_SWITCH_FALLTHROUGH", + justification = "intentional fallthrough") private boolean isAZendPceNode(String serviceFormat, PceOpticalNode pceNode, String azNodeId, String azEndPoint) { switch (serviceFormat) { case "Ethernet": @@ -482,33 +503,20 @@ public class PceCalculation { if (pceNode.getSupNetworkNodeId().equals(azNodeId)) { return true; } - if ("A".equals(azEndPoint) - && this.input.getServiceAEnd().getTxDirection() != null - && this.input.getServiceAEnd().getTxDirection().getPort() != null - && this.input.getServiceAEnd().getTxDirection().getPort().getPortDeviceName() != null - && pceNode.getNodeId().getValue() - .equals(this.input.getServiceAEnd().getTxDirection().getPort().getPortDeviceName())) { - return true; - } - if ("Z".equals(azEndPoint) - && this.input.getServiceZEnd().getTxDirection() != null - && this.input.getServiceZEnd().getTxDirection().getPort() != null - && this.input.getServiceZEnd().getTxDirection().getPort().getPortDeviceName() != null - && pceNode.getNodeId().getValue() - .equals(this.input.getServiceZEnd().getTxDirection().getPort().getPortDeviceName())) { - return true; - } - return false; + //fallthrough case "OTU": - if ("A".equals(azEndPoint) && pceNode.getNodeId().getValue() - .equals(this.input.getServiceAEnd().getTxDirection().getPort().getPortDeviceName())) { - return true; - } - if ("Z".equals(azEndPoint) && pceNode.getNodeId().getValue() - .equals(this.input.getServiceZEnd().getTxDirection().getPort().getPortDeviceName())) { - return true; + switch (azEndPoint) { + case "A": + return checkAendInputTxPortDeviceName() + && pceNode.getNodeId().getValue() + .equals(this.input.getServiceAEnd().getTxDirection().getPort().getPortDeviceName()); + case "Z": + return checkZendInputTxPortDeviceName() + && pceNode.getNodeId().getValue() + .equals(this.input.getServiceZEnd().getTxDirection().getPort().getPortDeviceName()); + default: + return false; } - return false; default: LOG.debug("Unsupported service Format {} for node {}", serviceFormat, pceNode.getNodeId().getValue()); return false; @@ -780,7 +788,7 @@ public class PceCalculation { String moduleName = params[params.length - 1]; for (McCapabilities mcCapabitility : mcCapabilities) { if (mcCapabitility.getMcNodeName().contains("XPDR") - && mcCapabitility.getSlotWidthGranularity() != null) { + && mcCapabitility.getSlotWidthGranularity() != null) { return mcCapabitility.getSlotWidthGranularity().getValue(); } if (mcCapabitility.getMcNodeName().contains(moduleName) @@ -806,11 +814,11 @@ public class PceCalculation { String moduleName = params[params.length - 1]; for (McCapabilities mcCapabitility : mcCapabilities) { if (mcCapabitility.getMcNodeName().contains("XPDR") - && mcCapabitility.getCenterFreqGranularity() != null) { + && mcCapabitility.getCenterFreqGranularity() != null) { return mcCapabitility.getCenterFreqGranularity().getValue(); } if (mcCapabitility.getMcNodeName().contains(moduleName) - && mcCapabitility.getCenterFreqGranularity() != null) { + && mcCapabitility.getCenterFreqGranularity() != null) { return mcCapabitility.getCenterFreqGranularity().getValue(); } } -- 2.36.6