Adapt PCE code for OTN services
[transportpce.git] / pce / src / main / java / org / opendaylight / transportpce / pce / PcePathDescription.java
index 6c31082170bb3f9a9f67113976edcc56b04d469d..bb29feb6d4f49f9b474aa18c492af47f74f49943 100644 (file)
@@ -12,36 +12,35 @@ 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.rev170426.path.description.AToZDirectionBuilder;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.path.description.ZToADirectionBuilder;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.path.description.atoz.direction.AToZ;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.path.description.atoz.direction.AToZBuilder;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.path.description.atoz.direction.AToZKey;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.path.description.ztoa.direction.ZToA;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.path.description.ztoa.direction.ZToABuilder;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.path.description.ztoa.direction.ZToAKey;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.Resource;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.ResourceBuilder;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.resource.resource.LinkBuilder;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.resource.resource.NodeBuilder;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.resource.resource.TerminationPoint;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.resource.resource.TerminationPointBuilder;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.resource.resource.link.LinkIdentifierBuilder;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.resource.resource.node.NodeIdentifierBuilder;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.resource.resource.termination.point.TerminationPointIdentifierBuilder;
-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.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.rev180226.LinkId;
 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 PceResult rc;
 
     public PceResult getReturnStructure() {
-        return this.rc;
+        return rc;
     }
 
     private Map<LinkId, PceLink> allPceLinks = null;
@@ -56,38 +55,50 @@ public class PcePathDescription {
     }
 
     public PceResult buildDescriptions() {
-        LOG.info("In buildDescriptions: AtoZ {}", this.pathAtoZ.toString());
+        LOG.info("In buildDescriptions: AtoZ =  {}", pathAtoZ.toString());
         List<AToZ> atozList = new ArrayList<AToZ>();
-        if (this.pathAtoZ == null) {
-            this.rc.setRC(ResponseCodes.RESPONSE_FAILED);
+        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(rc.getRate())
+            .setAToZ(atozList);
+        if ("100GE".equals(rc.getServiceType()) || "OTU4".equals(rc.getServiceType())) {
+            atoZDirectionBldr.setAToZWavelengthNumber(rc.getResultWavelength());
+        } else if ("10GE".equals(rc.getServiceType()) || "1GE".equals(rc.getServiceType())
+            || "ODU4".equals(rc.getServiceType())) {
+            atoZDirectionBldr.setAToZWavelengthNumber(Long.valueOf(0));
+        }
+        rc.setAtoZDirection(atoZDirectionBldr.build());
+        pathZtoA = ImmutableList.copyOf(pathAtoZ).reverse();
+        LOG.info("In buildDescriptions: ZtoA {}", pathZtoA.toString());
 
         List<ZToA> ztoaList = new ArrayList<ZToA>();
-        if (this.pathZtoA == null) {
-            this.rc.setRC(ResponseCodes.RESPONSE_FAILED);
+        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(rc.getRate())
+            .setZToA(ztoaList);
+        if ("100GE".equals(rc.getServiceType()) || "OTU4".equals(rc.getServiceType())) {
+            ztoADirectionBldr.setZToAWavelengthNumber(rc.getResultWavelength());
+        } else if ("10GE".equals(rc.getServiceType()) || "1GE".equals(rc.getServiceType())
+            || "ODU4".equals(rc.getServiceType())) {
+            ztoADirectionBldr.setZToAWavelengthNumber(Long.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;
@@ -96,25 +107,20 @@ public class PcePathDescription {
         String tpName = path.get(0).getClient();
         String xname = path.get(0).getSourceId().getValue();
         TerminationPoint stp = new TerminationPointBuilder()
-                .setTerminationPointIdentifier(new TerminationPointIdentifierBuilder()
-                        .setNodeId(xname).setTpId(tpName).build())
+                .setTpId(tpName).setTpNodeId(xname)
                 .build();
 
         AToZKey clientKey = new AToZKey(index.toString());
         Resource clientResource = new ResourceBuilder().setResource(stp).build();
         AToZ firstResource = new AToZBuilder().setId(tpName).withKey(clientKey).setResource(clientResource).build();
         etoeList.add(firstResource);
-
         index++;
-
         for (PceLink pcelink : path) {
-
             String srcName = pcelink.getSourceId().getValue();
-
             // Nodes
-            org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce
+            org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
                 .resource.resource.resource.Node sourceNode = new NodeBuilder()
-                .setNodeIdentifier(new NodeIdentifierBuilder().setNodeId(srcName).build())
+                .setNodeId(srcName)
                 .build();
 
             // Source Resource
@@ -127,12 +133,11 @@ public class PcePathDescription {
             // source TP
             tpName = pcelink.getSourceTP().toString();
             stp = new TerminationPointBuilder()
-                    .setTerminationPointIdentifier(new TerminationPointIdentifierBuilder()
-                            .setNodeId(srcName).setTpId(tpName).build())
+                    .setTpNodeId(srcName).setTpId(tpName)
                     .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++;
@@ -140,9 +145,9 @@ public class PcePathDescription {
 
             String linkName = pcelink.getLinkId().getValue();
             // Link
-            org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce
+            org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
                 .resource.resource.resource.Link atozLink = new LinkBuilder()
-                .setLinkIdentifier(new LinkIdentifierBuilder().setLinkId(linkName).build())
+                .setLinkId(linkName)
                 .build();
 
             // Link Resource
@@ -156,9 +161,8 @@ public class PcePathDescription {
             // target TP
             tpName = pcelink.getDestTP().toString();
             TerminationPoint dtp = new TerminationPointBuilder()
-                    .setTerminationPointIdentifier(new TerminationPointIdentifierBuilder()
-                            .setNodeId(destName).setTpId(tpName).build())
-                    .build();
+                .setTpNodeId(destName).setTpId(tpName)
+                .build();
 
             // Resource
             AToZKey destTPKey = new AToZKey(index.toString());
@@ -167,9 +171,9 @@ public class PcePathDescription {
             index++;
             etoeList.add(ttpResource);
 
-            org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce
+            org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
                 .resource.resource.resource.Node targetNode = new NodeBuilder()
-                .setNodeIdentifier(new NodeIdentifierBuilder().setNodeId(destName).build())
+                .setNodeId(destName)
                 .build();
 
             // Target Resource
@@ -186,8 +190,7 @@ public class PcePathDescription {
         tpName = lastLink.getClient();
         xname = lastLink.getDestId().getValue();
         stp = new TerminationPointBuilder()
-                .setTerminationPointIdentifier(new TerminationPointIdentifierBuilder()
-                        .setNodeId(xname).setTpId(tpName).build())
+                .setTpNodeId(xname).setTpId(tpName)
                 .build();
 
 
@@ -209,8 +212,7 @@ public class PcePathDescription {
         String tpName = pcelink.getClient();
         String xname = pcelink.getSourceId().getValue();
         TerminationPoint stp = new TerminationPointBuilder()
-                .setTerminationPointIdentifier(new TerminationPointIdentifierBuilder()
-                        .setNodeId(xname).setTpId(tpName).build())
+                .setTpNodeId(xname).setTpId(tpName)
                 .build();
 
         ZToAKey clientKey = new ZToAKey(index.toString());
@@ -228,10 +230,9 @@ public class PcePathDescription {
 
 
             // Nodes
-            org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce
+            org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
                 .resource.resource.resource.Node sourceNode = new NodeBuilder()
-                .setNodeIdentifier(new NodeIdentifierBuilder().setNodeId(srcName).build()).build();
-
+                .setNodeId(srcName).build();
 
 
             // Source Resource
@@ -244,8 +245,7 @@ public class PcePathDescription {
             // source TP
             tpName = pcelink.getSourceTP().toString();
             stp = new TerminationPointBuilder()
-                    .setTerminationPointIdentifier(new TerminationPointIdentifierBuilder()
-                            .setNodeId(srcName).setTpId(tpName).build())
+                    .setTpNodeId(srcName).setTpId(tpName)
                     .build();
 
             // Resource
@@ -257,9 +257,9 @@ public class PcePathDescription {
 
             String linkName = pcelink.getLinkId().getValue();
             // Link
-            org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce
+            org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
                 .resource.resource.resource.Link ztoaLink = new LinkBuilder()
-                .setLinkIdentifier(new LinkIdentifierBuilder().setLinkId(linkName).build()).build();
+                .setLinkId(linkName).build();
 
             // Link Resource
             ZToAKey linkKey = new ZToAKey(index.toString());
@@ -272,9 +272,7 @@ public class PcePathDescription {
             // target TP
             tpName = pcelink.getDestTP().toString();
             TerminationPoint ttp = new TerminationPointBuilder()
-                    .setTerminationPointIdentifier(new TerminationPointIdentifierBuilder()
-                            .setNodeId(destName).setTpId(tpName).build())
-                    .build();
+                    .setTpNodeId(destName).setTpId(tpName).build();
 
             // Resource
             ZToAKey destTPKey = new ZToAKey(index.toString());
@@ -284,9 +282,9 @@ public class PcePathDescription {
             etoelist.add(ttpResource);
 
 
-            org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce
+            org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
                 .resource.resource.resource.Node targetNode = new NodeBuilder()
-                .setNodeIdentifier(new NodeIdentifierBuilder().setNodeId(destName).build()).build();
+                .setNodeId(destName).build();
             // Target Resource
             ZToAKey targetKey = new ZToAKey(index.toString());
             Resource nodeResource3 = new ResourceBuilder().setResource(targetNode).build();
@@ -300,9 +298,7 @@ public class PcePathDescription {
         tpName = lastLink.getClient();
         xname = lastLink.getDestId().getValue();
         stp = new TerminationPointBuilder()
-                .setTerminationPointIdentifier(new TerminationPointIdentifierBuilder()
-                        .setNodeId(xname).setTpId(tpName).build())
-                .build();
+                .setTpNodeId(xname).setTpId(tpName).build();
 
 
         index++;