Upgrade Network model from 2.1 to 4.1
[transportpce.git] / pce / src / main / java / org / opendaylight / transportpce / pce / PceLink.java
index 4411cc4f488de848c9b351460bf804fba6bc764a..2fb29265b5c165d54f9e85cd208da24499458b79 100644 (file)
@@ -8,11 +8,15 @@
 
 package org.opendaylight.transportpce.pce;
 
-import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev170929.Link1;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev170929.OpenroadmLinkType;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev150608.NodeId;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev150608.LinkId;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev150608.network.Link;
+import java.util.List;
+
+import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.Link1;
+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.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.LinkId;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.Link;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -43,6 +47,9 @@ public class PceLink {
     private final Object destTP;
     private final LinkId oppositeLink;
     private final Long latency;
+    private final List<Long> srlg;
+    private final double osnr;
+    private final Span omsAttributesSpan;
 
     public PceLink(Link link) {
         LOG.debug("PceLink: : PceLink start ");
@@ -60,15 +67,26 @@ public class PceLink {
         this.oppositeLink = calcOpposite(link);
         this.latency = calcLatency(link);
 
+        if (this.linkType == OpenroadmLinkType.ROADMTOROADM) {
+            this.omsAttributesSpan = MapUtils.getOmsAttributesSpan(link);
+            this.srlg = MapUtils.getSRLG(link);
+            this.osnr = retrieveOSNR();
+        } else {
+            this.omsAttributesSpan = null;
+            this.srlg = null;
+            this.osnr = 0L;
+        }
+
         LOG.debug("PceLink: created PceLink  {}", toString());
     }
 
     private OpenroadmLinkType calcType(Link link) {
-        Link1 link1 = null;
+        org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.@Nullable Link1 link1 = null;
         OpenroadmLinkType tmplType = null;
 
         // ID and type
-        link1 = link.augmentation(Link1.class);
+        link1 = link.augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130
+            .Link1.class);
         if (link1 == null) {
             this.isValid = false;
             LOG.error("PceLink: No Link augmentation available. Link is ignored {}", this.linkId);
@@ -87,9 +105,12 @@ public class PceLink {
     private LinkId calcOpposite(Link link) {
         // opposite link
         LinkId tmpoppositeLink = null;
-        org.opendaylight.yang.gen.v1.http.org.openroadm.opposite.links.rev170929.Link1 linkOpposite = link
-            .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.opposite.links.rev170929.Link1.class);
-        tmpoppositeLink = linkOpposite.getOppositeLink();
+        Link1 linkOpposite = link.augmentation(Link1.class);
+        if (linkOpposite.getOppositeLink() != null) {
+            tmpoppositeLink = linkOpposite.getOppositeLink();
+        } else {
+            LOG.error("link {} has no opposite link", link.getLinkId().getValue());
+        }
         LOG.debug("PceLink: reading oppositeLink.  {}", linkOpposite.toString());
         if (tmpoppositeLink == null) {
             this.isValid = false;
@@ -112,6 +133,78 @@ public class PceLink {
 
     }
 
+    @SuppressWarnings("checkstyle:VariableDeclarationUsageDistance")
+    public double retrieveOSNR() {
+        double sum = 0;        // sum of 1 over the span OSNRs (linear units)
+        double linkOsnrDb;     // link OSNR, in dB
+        double linkOsnrLu;     // link OSNR, in dB
+        double spanOsnrDb;     // span OSNR, in dB
+        double spanOsnrLu;     // span OSNR, in linear units
+        double ampNoise = 5.5; // default amplifier noise value, in dB
+        double loss;           // fiber span measured loss, in dB
+        double power;          // launch power, in dB
+        double constantA = 38.97293;
+        double constantB = 0.72782;
+        double constantC = -0.532331;
+        double constactD = -0.019549;
+        double upperBoundOSNR = 33;
+        double lowerBoundOSNR = 0.1;
+
+        if (omsAttributesSpan ==  null) {
+            return 0L; // indicates no data or N/A
+        }
+        loss = omsAttributesSpan.getSpanlossCurrent().getValue().doubleValue();
+        switch (omsAttributesSpan.getLinkConcatenation().get(0).getFiberType()) {
+            case Smf:
+                power = 2;
+                break;
+
+            case Eleaf:
+                power = 1;
+                break;
+
+            case Oleaf:
+                power = 0;
+                break;
+
+            case Dsf:
+                power = 0;
+                break;
+
+            case Truewave:
+                power = 0;
+                break;
+
+            case Truewavec:
+                power = -1;
+                break;
+
+            case NzDsf:
+                power = 0;
+                break;
+
+            case Ull:
+                power = 0;
+                break;
+
+            default:
+                power = 0;
+                break;
+        }
+        spanOsnrDb = constantA + constantB * power + constantC * loss + constactD * power * loss;
+        if (spanOsnrDb > upperBoundOSNR) {
+            spanOsnrDb =  upperBoundOSNR;
+        } else if (spanOsnrDb < lowerBoundOSNR) {
+            spanOsnrDb = lowerBoundOSNR;
+        }
+        spanOsnrLu = Math.pow(10, (spanOsnrDb / 10.0));
+        sum = PceConstraints.CONST_OSNR / spanOsnrLu;
+        linkOsnrLu = sum;
+        //link_OSNR_dB = 10 * Math.log10(1 / sum);
+        LOG.debug("In retrieveOSNR: link OSNR is {} dB", linkOsnrLu);
+        return linkOsnrLu;
+    }
+
 
     public LinkId getOppositeLink() {
         return this.oppositeLink;