PCE modification in order to prepare flexgrid
[transportpce.git] / pce / src / main / java / org / opendaylight / transportpce / pce / networkanalyzer / PceOpticalNode.java
index 63f2bffe0a518ec7ed49a27174695535396b22e4..4afbf70f69ff3b9abb696427bc89815ac38aea1e 100644 (file)
@@ -14,12 +14,13 @@ import java.util.List;
 import java.util.Map;
 import java.util.Optional;
 import java.util.TreeMap;
+import org.opendaylight.transportpce.common.fixedflex.GridConstant;
 import org.opendaylight.transportpce.pce.SortPortsByName;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev181130.TerminationPoint1;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.Node1;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.networks.network.node.termination.point.pp.attributes.UsedWavelength;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev181130.OpenroadmNodeType;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev181130.OpenroadmTpType;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.common.network.rev200529.TerminationPoint1;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev200529.Node1;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmNodeType;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.OpenroadmTpType;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev200529.available.freq.map.AvailFreqMapsKey;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.format.rev190531.ServiceFormat;
 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.rev180226.networks.network.Node;
@@ -32,11 +33,9 @@ public class PceOpticalNode implements PceNode {
 
     private boolean valid = true;
 
-    private final Node node;
-    private final NodeId nodeId;
-    private final OpenroadmNodeType nodeType;
-    private final ServiceFormat serviceFormat;
-    private final String pceNodeType;
+    private Node node;
+    private NodeId nodeId;
+    private OpenroadmNodeType nodeType;
 
     // wavelength calculation per node type
     private List<Long> availableWLindex = new ArrayList<>();
@@ -45,17 +44,17 @@ public class PceOpticalNode implements PceNode {
     private List<String> usedXpndrNWTps = new ArrayList<>();
     private List<PceLink> outgoingLinks = new ArrayList<>();
     private Map<String, String> clientPerNwTp = new HashMap<>();
+    private final AvailFreqMapsKey freqMapKey = new AvailFreqMapsKey(GridConstant.C_BAND);
+    private String version;
 
-    public PceOpticalNode(Node node, OpenroadmNodeType nodeType, NodeId nodeId, ServiceFormat serviceFormat,
-        String pceNodeType) {
-        this.node = node;
-        this.nodeId = nodeId;
-        this.nodeType = nodeType;
-        this.serviceFormat = serviceFormat;
-        this.pceNodeType = pceNodeType;
-
-        if ((node == null) || (nodeId == null) || (nodeType == null)) {
-            LOG.error("PceNode: one of parameters is not populated : nodeId, node type");
+    public PceOpticalNode(Node node, OpenroadmNodeType nodeType, String version) {
+        if (node != null && node.getNodeId() != null && nodeType != null && version != null) {
+            this.node = node;
+            this.nodeId = node.getNodeId();
+            this.nodeType = nodeType;
+            this.version = version;
+        } else {
+            LOG.error("PceNode: one of parameters is not populated : nodeId, node type, version");
             this.valid = false;
         }
     }
@@ -71,8 +70,8 @@ public class PceOpticalNode implements PceNode {
                 this.node.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
                     .ietf.network.topology.rev180226.Node1.class);
         List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
-            .node.TerminationPoint> allTps = nodeTp.getTerminationPoint();
-        if (allTps == null) {
+            .node.TerminationPoint> allTps = new ArrayList<>(nodeTp.nonnullTerminationPoint().values());
+        if (allTps.isEmpty()) {
             LOG.error("initSrgTpList: ROADM TerminationPoint list is empty for node {}", this);
             this.valid = false;
             return;
@@ -80,9 +79,9 @@ public class PceOpticalNode implements PceNode {
         for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
             .node.TerminationPoint tp : allTps) {
             TerminationPoint1 cntp1 = tp.augmentation(TerminationPoint1.class);
-            org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.TerminationPoint1 nttp1 = tp
-                .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130
-                .TerminationPoint1.class);
+            org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev200529.TerminationPoint1 nttp1 = tp
+                .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev200529
+                        .TerminationPoint1.class);
             OpenroadmTpType type = cntp1.getTpType();
             LOG.info("type = {} for tp {}", type.getName(), tp);
 
@@ -96,18 +95,10 @@ public class PceOpticalNode implements PceNode {
                 case SRGRXPP:
                 case SRGTXPP:
                 case SRGTXRXPP:
-                    boolean used = true;
                     LOG.info("initSrgTpList: SRG-PP tp = {} found", tp.getTpId().getValue());
-                    try {
-                        List<UsedWavelength> usedWavelengths = nttp1.getPpAttributes().getUsedWavelength();
-                        if (usedWavelengths.isEmpty()) {
-                            used = false;
-                        }
-                    } catch (NullPointerException e) {
-                        LOG.warn("initSrgTpList: 'usedWavelengths' for tp={} is null !", tp.getTpId().getValue());
-                        used = false;
-                    }
-                    if (!used) {
+                    if (nttp1 == null || nttp1.getPpAttributes() == null
+                            || nttp1.getPpAttributes().getUsedWavelength() == null
+                            || nttp1.getPpAttributes().getUsedWavelength().values().isEmpty()) {
                         LOG.info("initSrgTpList: adding SRG-PP tp '{}'", tp.getTpId().getValue());
                         this.availableSrgPp.put(tp.getTpId().getValue(), cntp1.getTpType());
                     } else {
@@ -133,39 +124,30 @@ public class PceOpticalNode implements PceNode {
             return;
         }
         Node1 node1 = this.node.augmentation(Node1.class);
+        byte[] freqMap;
+
         switch (this.nodeType) {
             case SRG :
-                List<org.opendaylight.yang.gen.v1.http.org.openroadm.srg.rev181130.srg.node.attributes
-                    .AvailableWavelengths> srgAvailableWL =
-                        node1.getSrgAttributes().getAvailableWavelengths();
-                if (srgAvailableWL == null) {
+                if (!node1.getSrgAttributes().nonnullAvailFreqMaps().containsKey(freqMapKey)) {
+                    LOG.error("initWLlist: SRG no cband available freq maps for node  {}", this);
                     this.valid = false;
-                    LOG.error("initWLlist: SRG AvailableWavelengths is empty for node  {}", this);
                     return;
                 }
-                for (org.opendaylight.yang.gen.v1.http.org.openroadm.srg.rev181130.srg.node.attributes
-                        .AvailableWavelengths awl : srgAvailableWL) {
-                    this.availableWLindex.add(awl.getIndex().toJava());
-                    LOG.debug("initWLlist: SRG next = {} in {}", awl.getIndex(), this);
-                }
+                freqMap = node1.getSrgAttributes().nonnullAvailFreqMaps().get(freqMapKey).getFreqMap();
+                updateAvailableWlIndex(freqMap);
                 break;
             case DEGREE :
-                List<org.opendaylight.yang.gen.v1.http.org.openroadm.degree.rev181130.degree.node.attributes
-                    .AvailableWavelengths> degAvailableWL = node1.getDegreeAttributes().getAvailableWavelengths();
-                if (degAvailableWL == null) {
+                if (!node1.getDegreeAttributes().nonnullAvailFreqMaps().containsKey(freqMapKey)) {
+                    LOG.error("initWLlist: DEG no cband available freq maps for node  {}", this);
                     this.valid = false;
-                    LOG.error("initWLlist: DEG AvailableWavelengths is empty for node  {}", this);
                     return;
                 }
-                for (org.opendaylight.yang.gen.v1.http.org.openroadm.degree.rev181130.degree.node.attributes
-                            .AvailableWavelengths awl : degAvailableWL) {
-                    this.availableWLindex.add(awl.getIndex().toJava());
-                    LOG.debug("initWLlist: DEGREE next = {} in {}", awl.getIndex(), this);
-                }
+                freqMap = node1.getDegreeAttributes().nonnullAvailFreqMaps().get(freqMapKey).getFreqMap();
+                updateAvailableWlIndex(freqMap);
                 break;
             case XPONDER :
                 // HARD CODED 96
-                for (long i = 1; i <= 96; i++) {
+                for (long i = 1; i <= GridConstant.NB_OCTECTS; i++) {
                     this.availableWLindex.add(i);
                 }
                 break;
@@ -180,7 +162,7 @@ public class PceOpticalNode implements PceNode {
         LOG.debug("initWLlist: availableWLindex size = {} in {}", this.availableWLindex.size(), this);
     }
 
-    public void initXndrTps() {
+    public void initXndrTps(ServiceFormat serviceFormat) {
         LOG.info("PceNod: initXndrTps for node : {}", this.nodeId);
         if (!isValid()) {
             return;
@@ -189,8 +171,8 @@ public class PceOpticalNode implements PceNode {
                 this.node.augmentation(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
                     .ietf.network.topology.rev180226.Node1.class);
         List<org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
-            .node.TerminationPoint> allTps = nodeTp.getTerminationPoint();
-        if (allTps == null) {
+            .node.TerminationPoint> allTps = new ArrayList<>(nodeTp.nonnullTerminationPoint().values());
+        if (allTps.isEmpty()) {
             this.valid = false;
             LOG.error("initXndrTps: XPONDER TerminationPoint list is empty for node {}", this);
             return;
@@ -199,8 +181,8 @@ public class PceOpticalNode implements PceNode {
         for (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network
             .node.TerminationPoint tp : allTps) {
             TerminationPoint1 cntp1 = tp.augmentation(TerminationPoint1.class);
-            org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.TerminationPoint1 nttp1 = tp
-                .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130
+            org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev200529.TerminationPoint1 nttp1 = tp
+                .augmentation(org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev200529
                 .TerminationPoint1.class);
             if (cntp1.getTpType() == OpenroadmTpType.XPONDERNETWORK) {
                 if (nttp1 != null && nttp1.getXpdrNetworkAttributes().getWavelength() != null) {
@@ -211,8 +193,8 @@ public class PceOpticalNode implements PceNode {
                 }
                 // find Client of this network TP
                 String client;
-                org.opendaylight.yang.gen.v1.http.transportpce.topology.rev200129.TerminationPoint1 tpceTp1 =
-                    tp.augmentation(org.opendaylight.yang.gen.v1.http.transportpce.topology.rev200129
+                org.opendaylight.yang.gen.v1.http.transportpce.topology.rev201019.TerminationPoint1 tpceTp1 =
+                    tp.augmentation(org.opendaylight.yang.gen.v1.http.transportpce.topology.rev201019
                         .TerminationPoint1.class);
                 if (tpceTp1 != null) {
                     client = tpceTp1.getAssociatedConnectionMapPort();
@@ -223,11 +205,11 @@ public class PceOpticalNode implements PceNode {
                         LOG.error("initXndrTps: XPONDER {} NW TP doesn't have defined Client {}",
                             this, tp.getTpId().getValue());
                     }
-                } else if (ServiceFormat.OTU.equals(this.serviceFormat)) {
+                } else if (ServiceFormat.OTU.equals(serviceFormat)) {
                     LOG.info("Infrastructure OTU4 connection");
                     this.valid = true;
                 } else {
-                    LOG.error("Service Format {} not managed yet", this.serviceFormat.getName());
+                    LOG.error("Service Format {} not managed yet", serviceFormat.getName());
                 }
             }
         }
@@ -283,7 +265,7 @@ public class PceOpticalNode implements PceNode {
     }
 
 
-    public void validateAZxponder(String anodeId, String znodeId) {
+    public void validateAZxponder(String anodeId, String znodeId, ServiceFormat serviceFormat) {
         if (!isValid()) {
             return;
         }
@@ -293,7 +275,7 @@ public class PceOpticalNode implements PceNode {
         // Detect A and Z
         if (this.getSupNetworkNodeId().equals(anodeId) || (this.getSupNetworkNodeId().equals(znodeId))) {
             LOG.info("validateAZxponder: A or Z node detected == {}", nodeId.getValue());
-            initXndrTps();
+            initXndrTps(serviceFormat);
             return;
         }
         LOG.debug("validateAZxponder: XPONDER is ignored == {}", nodeId.getValue());
@@ -336,7 +318,7 @@ public class PceOpticalNode implements PceNode {
 
     @Override
     public String getPceNodeType() {
-        return this.pceNodeType;
+        return "optical";
     }
 
     @Override
@@ -368,4 +350,34 @@ public class PceOpticalNode implements PceNode {
     public Map<String, List<Uint16>> getAvailableTribSlots() {
         return null;
     }
+
+    /**
+     * Get available wave length from frequency map array.
+     * @param freqMap byte[]
+     */
+    private void updateAvailableWlIndex(byte[] freqMap) {
+        if (freqMap == null) {
+            LOG.warn("No frequency map for node {}", node);
+            this.valid = false;
+            return;
+        }
+        long wlIndex = 1;
+        for (int i = 0; i < freqMap.length; i++) {
+            if (freqMap[i] == (byte)GridConstant.AVAILABLE_SLOT_VALUE) {
+                LOG.debug("Adding channel {} to available wave length index",wlIndex);
+                this.availableWLindex.add(wlIndex);
+            }
+            wlIndex++;
+        }
+    }
+
+    /*
+    * (non-Javadoc)
+    *
+    * @see org.opendaylight.transportpce.pce.networkanalyzer.PceNode#getVersion()
+    */
+    @Override
+    public String getVersion() {
+        return this.version;
+    }
 }