Adapt PCE output to include trib-port & trib-slot
[transportpce.git] / pce / src / main / java / org / opendaylight / transportpce / pce / PcePathDescription.java
index a65a0773d346ec7ea655acfffdb0b572f59f5316..bc15bf50e68b4a0a30f3744cd6c1653fbc42d30e 100644 (file)
@@ -12,39 +12,37 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import org.opendaylight.transportpce.common.ResponseCodes;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.AToZDirectionBuilder;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.ZToADirectionBuilder;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.atoz.direction.AToZ;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.atoz.direction.AToZBuilder;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.atoz.direction.AToZKey;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.ztoa.direction.ZToA;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.ztoa.direction.ZToABuilder;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.ztoa.direction.ZToAKey;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce.resource.Resource;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce.resource.ResourceBuilder;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce.resource.resource.resource.LinkBuilder;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce.resource.resource.resource.NodeBuilder;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce.resource.resource.resource.TerminationPoint;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce.resource.resource.resource.TerminationPointBuilder;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev150608.LinkId;
+import org.opendaylight.transportpce.pce.networkanalyzer.PceLink;
+import org.opendaylight.transportpce.pce.networkanalyzer.PceResult;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.path.description.AToZDirectionBuilder;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.path.description.ZToADirectionBuilder;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.path.description.atoz.direction.AToZ;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.path.description.atoz.direction.AToZBuilder;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.path.description.atoz.direction.AToZKey;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.path.description.ztoa.direction.ZToA;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.path.description.ztoa.direction.ZToABuilder;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.path.description.ztoa.direction.ZToAKey;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.pce.resource.Resource;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.pce.resource.ResourceBuilder;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.pce.resource.resource.resource.LinkBuilder;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.pce.resource.resource.resource.NodeBuilder;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.pce.resource.resource.resource.TerminationPoint;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.pce.resource.resource.resource.TerminationPointBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.LinkId;
+import org.opendaylight.yangtools.yang.common.Uint16;
+import org.opendaylight.yangtools.yang.common.Uint32;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public class PcePathDescription {
     /* Logging. */
-    private static final Logger LOG = LoggerFactory.getLogger(PceCalculation.class);
+    private static final Logger LOG = LoggerFactory.getLogger(PcePathDescription.class);
 
     private List<PceLink> pathAtoZ = null;
+    private List<PceLink> pathZtoA = null;
     private PceResult rc;
-
-    public PceResult getReturnStructure() {
-        return this.rc;
-    }
-
     private Map<LinkId, PceLink> allPceLinks = null;
 
-    private List<PceLink> pathZtoA = null;
-
     public PcePathDescription(List<PceLink> pathAtoZ, Map<LinkId, PceLink> allPceLinks, PceResult rc) {
         super();
         this.allPceLinks = allPceLinks;
@@ -53,38 +51,66 @@ public class PcePathDescription {
     }
 
     public PceResult buildDescriptions() {
-        LOG.info("In buildDescriptions: AtoZ {}", this.pathAtoZ.toString());
-        List<AToZ> atozList = new ArrayList<AToZ>();
-        if (this.pathAtoZ == null) {
-            this.rc.setRC(ResponseCodes.RESPONSE_FAILED);
+        LOG.info("In buildDescriptions: AtoZ =  {}", pathAtoZ);
+        List<AToZ> atozList = new ArrayList<>();
+        if (pathAtoZ == null) {
+            rc.setRC(ResponseCodes.RESPONSE_FAILED);
             LOG.error("In buildDescriptions: there is empty AtoZ path");
-            return this.rc;
+            return rc;
         }
 
-        buildAtoZ(atozList, this.pathAtoZ);
-
-        this.rc.setAtoZDirection(new AToZDirectionBuilder().setRate(this.rc.getRate())
-                .setAToZWavelengthNumber(this.rc.getResultWavelength()).setAToZ(atozList).build());
-
-        this.pathZtoA = ImmutableList.copyOf(this.pathAtoZ).reverse();
-        LOG.info("In buildDescriptions: ZtoA {}", this.pathZtoA.toString());
+        buildAtoZ(atozList, pathAtoZ);
+        AToZDirectionBuilder atoZDirectionBldr = new AToZDirectionBuilder()
+            .setRate(Uint32.valueOf(rc.getRate()))
+            .setAToZ(atozList);
+        if ("100GE".equals(rc.getServiceType()) || "OTU4".equals(rc.getServiceType())) {
+            atoZDirectionBldr.setAToZWavelengthNumber(Uint32.valueOf(rc.getResultWavelength()));
+        } else if ("10GE".equals(rc.getServiceType()) || "1GE".equals(rc.getServiceType())
+            || "ODU4".equals(rc.getServiceType())) {
+            if (rc.getResultTribSlot() != null && rc.getResultTribPort() != null) {
+                List<Uint16> tribSlotList = (List<Uint16>) rc.getResultTribSlot().values().toArray()[0];
+                atoZDirectionBldr.setAToZWavelengthNumber(Uint32.valueOf(0))
+                    .setTribPortNumber(Uint16.valueOf(rc.getResultTribPort().values().toArray()[0].toString()))
+                    .setTribSlotNumber(tribSlotList.get(0));
+            } else {
+                LOG.error("Trib port and trib slot number should be present");
+                atoZDirectionBldr.setTribSlotNumber(Uint16.valueOf(0)).setTribPortNumber(Uint16.valueOf(0));
+            }
+        }
+        rc.setAtoZDirection(atoZDirectionBldr.build());
+        pathZtoA = ImmutableList.copyOf(pathAtoZ).reverse();
+        LOG.info("In buildDescriptions: ZtoA {}", pathZtoA);
 
-        List<ZToA> ztoaList = new ArrayList<ZToA>();
-        if (this.pathZtoA == null) {
-            this.rc.setRC(ResponseCodes.RESPONSE_FAILED);
+        List<ZToA> ztoaList = new ArrayList<>();
+        if (pathZtoA == null) {
+            rc.setRC(ResponseCodes.RESPONSE_FAILED);
             LOG.error("In buildDescriptions: there is empty ZtoA path");
-            return this.rc;
+            return rc;
         }
-        buildZtoA(ztoaList, this.pathZtoA);
-
-        this.rc.setZtoADirection(new ZToADirectionBuilder().setRate(this.rc.getRate())
-                .setZToAWavelengthNumber(this.rc.getResultWavelength()).setZToA(ztoaList).build());
+        buildZtoA(ztoaList, pathZtoA);
+        ZToADirectionBuilder ztoADirectionBldr = new ZToADirectionBuilder()
+            .setRate(Uint32.valueOf(rc.getRate()))
+            .setZToA(ztoaList);
+        if ("100GE".equals(rc.getServiceType()) || "OTU4".equals(rc.getServiceType())) {
+            ztoADirectionBldr.setZToAWavelengthNumber(Uint32.valueOf(rc.getResultWavelength()));
+        } else if ("10GE".equals(rc.getServiceType()) || "1GE".equals(rc.getServiceType())
+            || "ODU4".equals(rc.getServiceType())) {
+            if (rc.getResultTribSlot() != null && rc.getResultTribPort() != null) {
+                List<Uint16> tribSlotList = (List<Uint16>) rc.getResultTribSlot().values().toArray()[0];
+                ztoADirectionBldr.setZToAWavelengthNumber(Uint32.valueOf(0))
+                    .setTribPortNumber(Uint16.valueOf(rc.getResultTribPort().values().toArray()[0].toString()))
+                    .setTribSlotNumber(tribSlotList.get(0));
+            } else {
+                LOG.error("Trib port and trib slot number should be present");
+                ztoADirectionBldr.setTribSlotNumber(Uint16.valueOf(0)).setTribPortNumber(Uint16.valueOf(0));
+            }
+        }
+        rc.setZtoADirection(ztoADirectionBldr.build());
 
-        return this.rc;
+        return rc;
     }
 
     private void buildAtoZ(List<AToZ> etoeList, List<PceLink> path) {
-
         Integer index = 0;
         PceLink lastLink = null;
         AToZ lastResource = null;
@@ -100,15 +126,11 @@ public class PcePathDescription {
         Resource clientResource = new ResourceBuilder().setResource(stp).build();
         AToZ firstResource = new AToZBuilder().setId(tpName).withKey(clientKey).setResource(clientResource).build();
         etoeList.add(firstResource);
-
-        index++;
-
+        index += 1;
         for (PceLink pcelink : path) {
-
             String srcName = pcelink.getSourceId().getValue();
-
             // Nodes
-            org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
+            org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.pce
                 .resource.resource.resource.Node sourceNode = new NodeBuilder()
                 .setNodeId(srcName)
                 .build();
@@ -117,7 +139,7 @@ public class PcePathDescription {
             AToZKey sourceKey = new AToZKey(index.toString());
             Resource nodeResource1 = new ResourceBuilder().setResource(sourceNode).build();
             AToZ srcResource = new AToZBuilder().setId(srcName).withKey(sourceKey).setResource(nodeResource1).build();
-            index++;
+            index += 1;
             etoeList.add(srcResource);
 
             // source TP
@@ -127,15 +149,15 @@ public class PcePathDescription {
                     .build();
 
             // Resource
-            AToZKey srcTPKey = new AToZKey(index.toString());// tpName);
+            AToZKey srcTPKey = new AToZKey(index.toString());
             Resource tpResource1 = new ResourceBuilder().setResource(stp).build();
             AToZ stpResource = new AToZBuilder().setId(tpName).withKey(srcTPKey).setResource(tpResource1).build();
-            index++;
+            index += 1;
             etoeList.add(stpResource);
 
             String linkName = pcelink.getLinkId().getValue();
             // Link
-            org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
+            org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.pce
                 .resource.resource.resource.Link atozLink = new LinkBuilder()
                 .setLinkId(linkName)
                 .build();
@@ -144,24 +166,24 @@ public class PcePathDescription {
             AToZKey linkKey = new AToZKey(index.toString());
             Resource nodeResource2 = new ResourceBuilder().setResource(atozLink).build();
             AToZ linkResource = new AToZBuilder().setId(linkName).withKey(linkKey).setResource(nodeResource2).build();
-            index++;
+            index += 1;
             etoeList.add(linkResource);
 
             String destName = pcelink.getDestId().getValue();
             // target TP
             tpName = pcelink.getDestTP().toString();
             TerminationPoint dtp = new TerminationPointBuilder()
-                    .setTpNodeId(destName).setTpId(tpName)
-                    .build();
+                .setTpNodeId(destName).setTpId(tpName)
+                .build();
 
             // Resource
             AToZKey destTPKey = new AToZKey(index.toString());
             Resource tpResource2 = new ResourceBuilder().setResource(dtp).build();
             AToZ ttpResource = new AToZBuilder().setId(tpName).withKey(destTPKey).setResource(tpResource2).build();
-            index++;
+            index += 1;
             etoeList.add(ttpResource);
 
-            org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
+            org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.pce
                 .resource.resource.resource.Node targetNode = new NodeBuilder()
                 .setNodeId(destName)
                 .build();
@@ -183,8 +205,7 @@ public class PcePathDescription {
                 .setTpNodeId(xname).setTpId(tpName)
                 .build();
 
-
-        index++;
+        index += 1;
         clientKey = new AToZKey(index.toString());
         clientResource = new ResourceBuilder().setResource(stp).build();
         lastResource = new AToZBuilder().setId(tpName).withKey(clientKey).setResource(clientResource).build();
@@ -209,18 +230,18 @@ public class PcePathDescription {
         Resource clientResource = new ResourceBuilder().setResource(stp).build();
         ZToA firstResource = new ZToABuilder().setId(tpName).withKey(clientKey).setResource(clientResource).build();
         etoelist.add(firstResource);
-        index++;
+        index += 1;
 
         for (PceLink pcelinkAtoZ : path) {
 
             pcelink = this.allPceLinks.get(pcelinkAtoZ.getOppositeLink());
-            LOG.debug("link to oppsite: {} to {}", pcelinkAtoZ.toString(), pcelink.toString());
+            LOG.debug("link to oppsite: {} to {}", pcelinkAtoZ, pcelink);
 
             String srcName = pcelink.getSourceId().getValue();
 
 
             // Nodes
-            org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
+            org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.pce
                 .resource.resource.resource.Node sourceNode = new NodeBuilder()
                 .setNodeId(srcName).build();
 
@@ -229,7 +250,7 @@ public class PcePathDescription {
             ZToAKey sourceKey = new ZToAKey(index.toString());
             Resource nodeResource1 = new ResourceBuilder().setResource(sourceNode).build();
             ZToA srcResource = new ZToABuilder().setId(srcName).withKey(sourceKey).setResource(nodeResource1).build();
-            index++;
+            index += 1;
             etoelist.add(srcResource);
 
             // source TP
@@ -242,12 +263,12 @@ public class PcePathDescription {
             ZToAKey srcTPKey = new ZToAKey(index.toString());
             Resource tpResource1 = new ResourceBuilder().setResource(stp).build();
             ZToA stpResource = new ZToABuilder().setId(tpName).withKey(srcTPKey).setResource(tpResource1).build();
-            index++;
+            index += 1;
             etoelist.add(stpResource);
 
             String linkName = pcelink.getLinkId().getValue();
             // Link
-            org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
+            org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.pce
                 .resource.resource.resource.Link ztoaLink = new LinkBuilder()
                 .setLinkId(linkName).build();
 
@@ -255,7 +276,7 @@ public class PcePathDescription {
             ZToAKey linkKey = new ZToAKey(index.toString());
             Resource nodeResource2 = new ResourceBuilder().setResource(ztoaLink).build();
             ZToA linkResource = new ZToABuilder().setId(linkName).withKey(linkKey).setResource(nodeResource2).build();
-            index++;
+            index += 1;
             etoelist.add(linkResource);
 
             String destName = pcelink.getDestId().getValue();
@@ -268,11 +289,11 @@ public class PcePathDescription {
             ZToAKey destTPKey = new ZToAKey(index.toString());
             Resource tpResource2 = new ResourceBuilder().setResource(ttp).build();
             ZToA ttpResource = new ZToABuilder().setId(tpName).withKey(destTPKey).setResource(tpResource2).build();
-            index++;
+            index += 1;
             etoelist.add(ttpResource);
 
 
-            org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
+            org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.pce
                 .resource.resource.resource.Node targetNode = new NodeBuilder()
                 .setNodeId(destName).build();
             // Target Resource
@@ -290,13 +311,14 @@ public class PcePathDescription {
         stp = new TerminationPointBuilder()
                 .setTpNodeId(xname).setTpId(tpName).build();
 
-
-        index++;
+        index += 1;
         clientKey = new ZToAKey(index.toString());
         clientResource = new ResourceBuilder().setResource(stp).build();
         lastResource = new ZToABuilder().setId(tpName).withKey(clientKey).setResource(clientResource).build();
         etoelist.add(lastResource);
-
     }
 
+    public PceResult getReturnStructure() {
+        return rc;
+    }
 }