do not explicit serialVersionUID anymore
[transportpce.git] / pce / src / main / java / org / opendaylight / transportpce / pce / networkanalyzer / PceLink.java
index 68b6d12db8ae933ab8a379a38e9250353b1f7b62..cf303055bb2d6e0ebec098a88f9f3154787a51be 100644 (file)
@@ -12,10 +12,15 @@ import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.io.Serializable;
+import java.util.Collection;
+import java.util.Iterator;
 import java.util.List;
-
+import java.util.Map;
+import org.eclipse.jdt.annotation.NonNull;
 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.link.rev181130.span.attributes.LinkConcatenation.FiberType;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.link.rev181130.span.attributes.LinkConcatenationKey;
 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.http.transportpce.topology.rev200129.OtnLinkType;
@@ -25,9 +30,11 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.top
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(
+    value = "SE_NO_SERIALVERSIONID",
+    justification = "https://github.com/rzwitserloot/lombok/wiki/WHY-NOT:-serialVersionUID")
 public class PceLink implements Serializable {
 
-    private static final long serialVersionUID = 1L;
     /* Logging. */
     private static final Logger LOG = LoggerFactory.getLogger(PceLink.class);
     ///////////////////////// LINKS ////////////////////
@@ -132,9 +139,12 @@ public class PceLink implements Serializable {
 
         try {
             double tmp = 0;
-            for (int i = 0; i < this.omsAttributesSpan.getLinkConcatenation().size(); i++) {
+            @NonNull
+            Map<LinkConcatenationKey, LinkConcatenation> linkConcatenationMap =
+                this.omsAttributesSpan.nonnullLinkConcatenation();
+            for (Map.Entry<LinkConcatenationKey, LinkConcatenation> entry : linkConcatenationMap.entrySet()) {
                 //Length is expressed in meter and latency is expressed in ms according to OpenROADM MSA
-                tmp += this.omsAttributesSpan.getLinkConcatenation().get(i).getSRLGLength().toJava() / CELERITY;
+                tmp += entry.getValue().getSRLGLength().toJava() / CELERITY;
                 LOG.info("In PceLink: The latency of link {} == {}",link.getLinkId(),tmp);
             }
             tmplatency = (long) Math.ceil(tmp);
@@ -147,23 +157,31 @@ public class PceLink implements Serializable {
 
     //Compute the OSNR of a span
     public double calcSpanOSNR() {
-        try {
-            double pout; //power on the output of the previous ROADM (dBm)
-            pout = retrievePower(this.omsAttributesSpan.getLinkConcatenation().get(0).getFiberType());
-            double spanLoss = this.omsAttributesSpan.getSpanlossCurrent().getValue().doubleValue(); // span loss (dB)
-            double pin = pout - spanLoss; //power on the input of the current ROADM (dBm)
-            double spanOsnrDb;
-            spanOsnrDb = NOISE_MASK_A * pin + NOISE_MASK_B;
-            if (spanOsnrDb > UPPER_BOUND_OSNR) {
-                spanOsnrDb =  UPPER_BOUND_OSNR;
-            } else if (spanOsnrDb < LOWER_BOUND_OSNR) {
-                spanOsnrDb = LOWER_BOUND_OSNR;
-            }
-            return spanOsnrDb;
-        } catch (NullPointerException e) {
+        if (this.omsAttributesSpan == null) {
+            return 0L;
+        }
+        Collection<LinkConcatenation> linkConcatenationList =
+            this.omsAttributesSpan.nonnullLinkConcatenation().values();
+        if (linkConcatenationList == null) {
             LOG.error("in PceLink : Null field in the OmsAttrubtesSpan");
             return 0L;
         }
+        Iterator<LinkConcatenation> linkConcatenationiterator = linkConcatenationList.iterator();
+        if (!linkConcatenationiterator.hasNext()) {
+            return 0L;
+        }
+        // power on the output of the previous ROADM (dBm)
+        double pout = retrievePower(linkConcatenationiterator.next().getFiberType());
+        // span loss (dB)
+        double spanLoss = this.omsAttributesSpan.getSpanlossCurrent().getValue().doubleValue();
+        double pin = pout - spanLoss; // power on the input of the current ROADM (dBm)
+        double spanOsnrDb = NOISE_MASK_A * pin + NOISE_MASK_B;
+        if (spanOsnrDb > UPPER_BOUND_OSNR) {
+            spanOsnrDb = UPPER_BOUND_OSNR;
+        } else if (spanOsnrDb < LOWER_BOUND_OSNR) {
+            spanOsnrDb = LOWER_BOUND_OSNR;
+        }
+        return spanOsnrDb;
     }
 
     private double retrievePower(FiberType fiberType) {