GNPy migration to Aluminium
[transportpce.git] / pce / src / main / java / org / opendaylight / transportpce / pce / networkanalyzer / PceLink.java
index dde21e1a79a0f01e2d09578a94fa998d02ce7af2..720ffcd013e844c19e84cd5574263e59175080d6 100644 (file)
@@ -12,6 +12,8 @@ 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;
@@ -153,24 +155,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.nonnullLinkConcatenation()
-                    .values().iterator().next().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) {