Supporting new paths computed by GNPy 10/85210/18
authoratriki <ahmed.triki.tn@gmail.com>
Fri, 23 Aug 2019 14:20:21 +0000 (16:20 +0200)
committerguillaume.lambert <guillaume.lambert@orange.com>
Fri, 6 Dec 2019 16:42:09 +0000 (17:42 +0100)
- In the case where the path is not feasible, PCE asks gnpy to
compute a new path
- The service handler constraints concerning the nodes inclusion
are also transmitted to gnpy
- The PCE verifies the new path and computes the equivalent
openroadm-topology

JIRA: TRNSPRTPCE-49
Change-Id: Icb05209a6e3261dbb2da605f3787a0b48c0aee0a
Signed-off-by: atriki <ahmed.triki.tn@gmail.com>
api/src/main/yang/gnpy-api@2019-01-03.yang
pce/src/main/java/org/opendaylight/transportpce/pce/PceSendingPceRPCs.java
pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/ConnectToGnpyServer.java
pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/GnpyResult.java
pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/GnpyServiceImpl.java [new file with mode: 0644]
pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/GnpyTopoImpl.java [moved from pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/ExtractTopoDataStoreImpl.java with 59% similarity]
pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/GnpyUtilitiesImpl.java [new file with mode: 0644]
pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/ServiceDataStoreOperationsImpl.java
pce/src/main/java/org/opendaylight/transportpce/pce/graph/PceGraph.java
pce/src/main/java/org/opendaylight/transportpce/pce/networkanalyzer/PceCalculation.java
pce/src/main/java/org/opendaylight/transportpce/pce/service/PathComputationServiceImpl.java

index b837c277af1a5968f2820fcb76a2a605d179a3b8..57833306e7aaffdd5d99fe0948925ed8b7225710 100644 (file)
@@ -34,7 +34,7 @@ module gnpy-api {
           description
               "Describe the topology file to connect to gnpy";
       }
-  container service-file{
+      container service-file{
           uses gnpypc:service;
           description
               "Describe the service file to connect to gnpy";
index bf60b4d026d9e9356c234908ff7e91944a9eb68b..3ca6b942e03c490977db73bb19df3a2ef0ee7ba6 100755 (executable)
@@ -8,32 +8,23 @@
 
 package org.opendaylight.transportpce.pce;
 
-import java.util.List;
-
+import org.opendaylight.transportpce.common.ResponseCodes;
 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
 import org.opendaylight.transportpce.pce.constraints.PceConstraints;
 import org.opendaylight.transportpce.pce.constraints.PceConstraintsCalc;
 import org.opendaylight.transportpce.pce.gnpy.ConnectToGnpyServer;
-import org.opendaylight.transportpce.pce.gnpy.ExtractTopoDataStoreImpl;
 import org.opendaylight.transportpce.pce.gnpy.GnpyResult;
-import org.opendaylight.transportpce.pce.gnpy.ServiceDataStoreOperationsImpl;
+import org.opendaylight.transportpce.pce.gnpy.GnpyUtilitiesImpl;
 import org.opendaylight.transportpce.pce.graph.PceGraph;
 import org.opendaylight.transportpce.pce.networkanalyzer.PceCalculation;
 import org.opendaylight.transportpce.pce.networkanalyzer.PceResult;
-import org.opendaylight.yang.gen.v1.gnpy.gnpy.api.rev190103.GnpyApi;
-import org.opendaylight.yang.gen.v1.gnpy.gnpy.api.rev190103.GnpyApiBuilder;
-import org.opendaylight.yang.gen.v1.gnpy.gnpy.api.rev190103.gnpy.api.ServiceFileBuilder;
-import org.opendaylight.yang.gen.v1.gnpy.gnpy.api.rev190103.gnpy.api.TopologyFileBuilder;
-import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.topo.Connections;
-import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.topo.Elements;
-import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.service.PathRequest;
-import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.synchronization.info.Synchronization;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev190624.PathComputationRequestInput;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev190624.PathComputationRequestInputBuilder;
 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev190624.service.path.rpc.result.PathDescriptionBuilder;
 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.AToZDirection;
 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.ZToADirection;
 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.RoutingConstraintsSp.PceMetric;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.routing.constraints.sp.HardConstraints;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -61,20 +52,20 @@ public class PceSendingPceRPCs {
     private NetworkTransactionService networkTransaction;
     private PceConstraints pceHardConstraints = new PceConstraints();
     private PceConstraints pceSoftConstraints = new PceConstraints();
-    private Long gnpyRequestId = new Long(0);
     private GnpyResult gnpyAtoZ;
     private GnpyResult gnpyZtoA;
+    private Boolean success;
+    private String message;
+    private String responseCode;
 
     public PceSendingPceRPCs() {
         setPathDescription(null);
         this.input = null;
         this.networkTransaction = null;
-        this.gnpyAtoZ = null;
-        this.gnpyZtoA = null;
     }
 
     public PceSendingPceRPCs(PathComputationRequestInput input,
-            NetworkTransactionService networkTransaction) {
+        NetworkTransactionService networkTransaction) {
         setPathDescription(null);
 
         // TODO compliance check to check that input is not empty
@@ -83,6 +74,7 @@ public class PceSendingPceRPCs {
     }
 
     public void cancelResourceReserve() {
+        success = false;
         LOG.info("Wait for 10s til beginning the PCE cancelResourceReserve request");
         try {
             // sleep for 10s
@@ -90,136 +82,127 @@ public class PceSendingPceRPCs {
         } catch (InterruptedException e) {
             LOG.error(e.toString());
         }
+        success = true;
         LOG.info("cancelResourceReserve ...");
     }
 
-    public void pathComputation() throws Exception {
-        LOG.info("PathComputation ...");
+    public void pathComputationWithConstraints(PceConstraints hardConstraints, PceConstraints softConstraints)
+            throws Exception {
 
-        PceConstraintsCalc constraints = new PceConstraintsCalc(input,networkTransaction);
-        pceHardConstraints = constraints.getPceHardConstraints();
-        pceSoftConstraints = constraints.getPceSoftConstraints();
-        LOG.info("nwAnalizer ...");
         PceCalculation nwAnalizer =
-            new PceCalculation(input,networkTransaction, pceHardConstraints, pceSoftConstraints, rc);
+            new PceCalculation(input, networkTransaction, hardConstraints, softConstraints, rc);
         nwAnalizer.calcPath();
         rc = nwAnalizer.getReturnStructure();
         if (!rc.getStatus()) {
-            LOG.error("In pathComputation nwAnalizer: result = {}", rc.toString());
+            LOG.error("In pathComputationWithConstraints, nwAnalizer: result = {}", rc.toString());
             return;
         }
-
         LOG.info("PceGraph ...");
         PceGraph graph = new PceGraph(nwAnalizer.getaendPceNode(),
-                nwAnalizer.getzendPceNode(), nwAnalizer.getAllPceNodes(),
-                pceHardConstraints, pceSoftConstraints, rc);
+            nwAnalizer.getzendPceNode(), nwAnalizer.getAllPceNodes(),
+            hardConstraints, softConstraints, rc);
         graph.calcPath();
         rc = graph.getReturnStructure();
         if (!rc.getStatus()) {
             LOG.warn("In pathComputation : Graph return without Path ");
             // TODO fix. This is quick workaround for algorithm problem
             if ((rc.getLocalCause() == PceResult.LocalCause.TOO_HIGH_LATENCY)
-                    && (pceHardConstraints.getPceMetrics() == PceMetric.HopCount)
-                    && (pceHardConstraints.getMaxLatency() != -1)) {
-                pceHardConstraints.setPceMetrics(PceMetric.PropagationDelay);
+                && (hardConstraints.getPceMetrics() == PceMetric.HopCount)
+                && (hardConstraints.getMaxLatency() != -1)) {
+                hardConstraints.setPceMetrics(PceMetric.PropagationDelay);
                 graph = patchRerunGraph(graph);
             }
-
             if (!rc.getStatus()) {
-                LOG.error("In pathComputation graph.calcPath: result = {}", rc.toString());
+                LOG.error("In pathComputationWithConstraints, graph.calcPath: result = {}", rc.toString());
                 return;
             }
         }
-
         LOG.info("PcePathDescription ...");
         PcePathDescription description = new PcePathDescription(graph.getPathAtoZ(), nwAnalizer.getAllPceLinks(), rc);
         description.buildDescriptions();
         rc = description.getReturnStructure();
         if (!rc.getStatus()) {
-            LOG.error("In pathComputation description: result = {}", rc.toString());
+            LOG.error("In pathComputationWithConstraints, description: result = {}", rc.toString());
+            return;
+        }
+    }
+
+    public void pathComputation() throws Exception {
+
+        PceConstraintsCalc constraints = new PceConstraintsCalc(input, networkTransaction);
+        pceHardConstraints = constraints.getPceHardConstraints();
+        pceSoftConstraints = constraints.getPceSoftConstraints();
+        pathComputationWithConstraints(pceHardConstraints, pceSoftConstraints);
+        this.success = rc.getStatus();
+        this.message = rc.getMessage();
+        this.responseCode = rc.getResponseCode();
+
+        if (!rc.getStatus()) {
+            LOG.error("In pathComputation, pathComputationWithConstraints: result = {}", rc.toString());
             return;
         }
 
-        LOG.info("setPathDescription ...");
+        // Verify the path with GNPy
         AToZDirection atoz = rc.getAtoZDirection();
         ZToADirection ztoa = rc.getZtoADirection();
         ConnectToGnpyServer connectToGnpy = new ConnectToGnpyServer();
-        if (atoz == null || atoz.getAToZ() == null) {
-            rc.setRC("400");
-            LOG.error("In pathComputation empty atoz path after description: result = {}", rc.toString());
-            return;
-        } else {
-            // Send the computed path A-to-Z to GNPY tool
-            if (connectToGnpy.isGnpyURLExist()) {
-                ExtractTopoDataStoreImpl xtrTopo = new ExtractTopoDataStoreImpl(networkTransaction, input, atoz,
-                        gnpyRequestId);
-                gnpyRequestId++;
-                List<Elements> elementsList1 = xtrTopo.getElements();
-                List<Connections> connectionsList1 = xtrTopo.getConnections();
-                List<PathRequest> pathRequestList1 = xtrTopo.getPathRequest();
-                List<Synchronization> synchronizationList1 = xtrTopo.getSynchronization();
-                String gnpyResponse1 = getGnpyResponse(elementsList1, connectionsList1, pathRequestList1,
-                    synchronizationList1);
-                // Analyze the response
-                if (gnpyResponse1 != null) {
-                    GnpyResult result = new GnpyResult(gnpyResponse1);
-                    LOG.debug("GNPy result created");
-                    result.analyzeResult();
-                    this.gnpyAtoZ = result;
-                } else {
-                    LOG.error("No response from the GNPy server");
-                }
-            }
-        }
 
-        if (ztoa == null || ztoa.getZToA() == null) {
-            rc.setRC("400");
-            LOG.error("In pathComputation empty ztoa path after description: result = {}", rc.toString());
-            return;
-        } else {
-            // Send the computed path Z-to-A to GNPY tool
-            if (connectToGnpy.isGnpyURLExist()) {
-                ExtractTopoDataStoreImpl xtrTopo = new ExtractTopoDataStoreImpl(networkTransaction, input, ztoa,
-                        gnpyRequestId);
-                gnpyRequestId++;
-                List<Elements> elementsList2 = xtrTopo.getElements();
-                List<Connections> connectionsList2 = xtrTopo.getConnections();
-                List<PathRequest> pathRequestList2 = xtrTopo.getPathRequest();
-                List<Synchronization> synchronizationList2 = xtrTopo.getSynchronization();
-                String gnpyResponse2 = getGnpyResponse(elementsList2, connectionsList2, pathRequestList2,
-                        synchronizationList2);
-                // Analyze the response
-                if (gnpyResponse2 != null) {
-                    GnpyResult result = new GnpyResult(gnpyResponse2);
-                    LOG.debug("GNPy result created");
-                    result.analyzeResult();
-                    this.gnpyZtoA = result;
+        // Verify that the GNPy server exists
+        if (connectToGnpy.isGnpyURLExist()) {
+            LOG.info("Gnpy instance is connected T-PCE");
+            GnpyUtilitiesImpl gnpy = new GnpyUtilitiesImpl(networkTransaction, input);
+            if (gnpy.verifyComputationByGnpy(atoz, ztoa, pceHardConstraints)) {
+                LOG.info("The path is feasible according to Gnpy");
+                setPathDescription(new PathDescriptionBuilder().setAToZDirection(atoz).setZToADirection(ztoa));
+            }
+            else {
+                LOG.info("The path is not feasible according to Gnpy");
+                HardConstraints gnpyPathAsHC = null;
+                gnpyPathAsHC = gnpy.askNewPathFromGnpy(atoz, ztoa, gnpyPathAsHC, pceHardConstraints);
+                if (gnpyPathAsHC != null) {
+                    LOG.info("GNPy succeed to find another path");
+                    // Compute the path
+                    PathComputationRequestInput inputFromGnpy = new PathComputationRequestInputBuilder()
+                        .setServiceName(input.getServiceName())
+                        .setHardConstraints(gnpyPathAsHC)
+                        .setSoftConstraints(input.getSoftConstraints())
+                        .setPceMetric(PceMetric.HopCount)
+                        .setServiceAEnd(input.getServiceAEnd())
+                        .setServiceZEnd(input.getServiceZEnd())
+                        .build();
+                    PceConstraintsCalc constraintsGnpy = new PceConstraintsCalc(inputFromGnpy, networkTransaction);
+                    PceConstraints gnpyHardConstraints = constraintsGnpy.getPceHardConstraints();
+                    PceConstraints gnpySoftConstraints = constraintsGnpy.getPceSoftConstraints();
+                    pathComputationWithConstraints(gnpyHardConstraints, gnpySoftConstraints);
+                    atoz = rc.getAtoZDirection();
+                    ztoa = rc.getZtoADirection();
+                    setPathDescription(new PathDescriptionBuilder().setAToZDirection(atoz).setZToADirection(ztoa));
+                    if (gnpy.verifyComputationByGnpy(atoz, ztoa, pceHardConstraints)) {
+                        LOG.info("In pathComputation: the new path computed by GNPy is valid");
+                        setPathDescription(new PathDescriptionBuilder().setAToZDirection(atoz).setZToADirection(ztoa));
+                        this.success = true;
+                        this.message = "Path is calculated by GNPy ";
+                        this.responseCode = ResponseCodes.RESPONSE_OK;
+                    } else {
+                        LOG.info("In pathComputation: the new path computed by GNPy is not valid");
+                        this.success = false;
+                        this.message = "No path available ";
+                        this.responseCode = ResponseCodes.RESPONSE_FAILED;
+                    }
                 } else {
-                    LOG.info("No response from the GNPy server");
+                    LOG.info("GNPy failed to find another path");
+                    this.success = false;
+                    this.message = "No path available by PCE and GNPy ";
+                    this.responseCode = ResponseCodes.RESPONSE_FAILED;
                 }
             }
+            gnpyAtoZ = gnpy.getGnpyAtoZ();
+            gnpyZtoA = gnpy.getGnpyZtoA();
+        } else {
+            LOG.info("in PCESendingPceRPCs: Cannot connect to GNPy!!");
+            setPathDescription(new PathDescriptionBuilder().setAToZDirection(atoz).setZToADirection(ztoa));
+            LOG.info("In pathComputation Graph is Found");
         }
-
-        setPathDescription(new PathDescriptionBuilder().setAToZDirection(atoz).setZToADirection(ztoa));
-        LOG.info("In pathComputation Graph is Found");
-    }
-
-    private String getGnpyResponse(List<Elements> elementsList, List<Connections> connectionsList,
-            List<PathRequest> pathRequestList, List<Synchronization> synchronizationList) throws Exception {
-        GnpyApi gnpyApi = new GnpyApiBuilder()
-                .setTopologyFile(
-                        new TopologyFileBuilder().setElements(elementsList).setConnections(connectionsList).build())
-                .setServiceFile(new ServiceFileBuilder().setPathRequest(pathRequestList).build()).build();
-        InstanceIdentifier<GnpyApi> idGnpyApi = InstanceIdentifier.builder(GnpyApi.class).build();
-        String gnpyJson;
-        ServiceDataStoreOperationsImpl sd = new ServiceDataStoreOperationsImpl(networkTransaction);
-        gnpyJson = sd.createJsonStringFromDataObject(idGnpyApi, gnpyApi);
-        LOG.debug("GNPy  Id: {} / json created : {}", idGnpyApi, gnpyJson);
-        ConnectToGnpyServer connect = new ConnectToGnpyServer();
-        String gnpyJsonModified = gnpyJson.replace("gnpy-eqpt-config:", "")
-                .replace("gnpy-path-computation-simplified:", "").replace("gnpy-network-topology:", "");
-        String gnpyResponse = connect.gnpyCnx(gnpyJsonModified);
-        return gnpyResponse;
     }
 
     private PceGraph patchRerunGraph(PceGraph graph) {
@@ -238,15 +221,15 @@ public class PceSendingPceRPCs {
     }
 
     public Boolean getSuccess() {
-        return rc.getStatus();
+        return this.success;
     }
 
     public String getMessage() {
-        return rc.getMessage();
+        return this.message;
     }
 
     public String getResponseCode() {
-        return rc.getResponseCode();
+        return this.responseCode;
     }
 
     public GnpyResult getGnpyAtoZ() {
index 94c632fcc1d2670d88a8ccd4a6f649b12240bf5c..ef5a7054b4483d2dfd1fe46b8a3d8ec99c864e51 100644 (file)
@@ -50,11 +50,11 @@ public class ConnectToGnpyServer {
             os.write(jsonTxt.getBytes());
             os.flush();
             if (conn.getResponseCode() != HttpURLConnection.HTTP_CREATED) {
-                throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
+                LOG.error("No valid response from GNPy : HTTP error code : {}", conn.getResponseCode());
+                return null;
             }
             InputStreamReader response = new InputStreamReader((conn.getInputStream()));
             if (response != null) {
-                jsonRespTxt = null;
                 try {
                     jsonRespTxt = CharStreams.toString(response);
                 } catch (IOException e1) {
index a039bfe68721d7fb2e3ff15c4a42cf95bfecf44b..6d7e4a946e32560350d38e1ea0877710a27dc6c5 100644 (file)
@@ -17,24 +17,24 @@ import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.math.BigDecimal;
 import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
-
-import javassist.ClassPool;
+import java.util.Set;
 
 import javax.annotation.Nonnull;
 
 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
-import org.opendaylight.mdsal.binding.dom.codec.gen.impl.StreamWriterGenerator;
 import org.opendaylight.mdsal.binding.dom.codec.impl.BindingNormalizedNodeCodecRegistry;
 import org.opendaylight.mdsal.binding.generator.impl.ModuleInfoBackedContext;
 import org.opendaylight.mdsal.binding.generator.util.BindingRuntimeContext;
-import org.opendaylight.mdsal.binding.generator.util.JavassistUtils;
 import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
 import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.Result;
-import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.explicit.route.hop.type.num.unnum.hop.NumUnnumHop;
+import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.explicit.route.hop.type.NumUnnumHop;
 import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.generic.path.properties.path.properties.PathMetric;
 import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.generic.path.properties.path.properties.PathRouteObjects;
 import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.result.Response;
@@ -51,6 +51,8 @@ import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing
 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.ordered.constraints.sp.hop.type.hop.type.NodeBuilder;
 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.routing.constraints.sp.HardConstraints;
 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.routing.constraints.sp.HardConstraintsBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -80,9 +82,12 @@ public class GnpyResult {
 
     private static final Logger LOG = LoggerFactory.getLogger(GnpyResult.class);
     private Response response = null;
+    private Map<String, IpAddress> mapNodeRefIp = new HashMap<String, IpAddress>();
+    //private Map<String, IpAddress> mapFiberIp = new HashMap<String, IpAddress>();
 
-    public GnpyResult(String gnpyResponseString) throws Exception {
+    public GnpyResult(String gnpyResponseString, GnpyTopoImpl gnpyTopo) throws Exception {
 
+        this.mapNodeRefIp = gnpyTopo.getMapNodeRefIp();
         // Create the schema context
         final ModuleInfoBackedContext moduleContext = ModuleInfoBackedContext.create();
         Iterable<? extends YangModuleInfo> moduleInfos;
@@ -92,27 +97,24 @@ public class GnpyResult {
 
         // Create the binding binding normalized node codec registry
         BindingRuntimeContext bindingRuntimeContext = BindingRuntimeContext.create(moduleContext, schemaContext);
-        final BindingNormalizedNodeCodecRegistry codecRegistry = new BindingNormalizedNodeCodecRegistry(
-                StreamWriterGenerator.create(JavassistUtils.forClassPool(ClassPool.getDefault())));
-        codecRegistry.onBindingRuntimeContextUpdated(bindingRuntimeContext);
+        final BindingNormalizedNodeCodecRegistry codecRegistry =
+            new BindingNormalizedNodeCodecRegistry(bindingRuntimeContext);
 
         // Create the data object
         QName pathQname = QName.create("gnpy:path", "2019-05-02", "result");
         LOG.debug("the Qname is {} / namesapce {} ; module {}; ", pathQname.toString(), pathQname.getNamespace(),
-                pathQname.getModule());
+            pathQname.getModule());
         YangInstanceIdentifier yangId = YangInstanceIdentifier.of(pathQname);
         DataObject dataObject = null;
-        //Create the object response
-        //Create JsonReader from String
+        // Create the object response
+        // Create JsonReader from String
         InputStream streamGnpyRespnse = new ByteArrayInputStream(gnpyResponseString.getBytes(StandardCharsets.UTF_8));
         InputStreamReader gnpyResultReader = new InputStreamReader(streamGnpyRespnse);
         JsonReader jsonReader = new JsonReader(gnpyResultReader);
         Optional<NormalizedNode<? extends PathArgument, ?>> transformIntoNormalizedNode = parseInputJSON(jsonReader,
-                Result.class);
+            Result.class);
         NormalizedNode<? extends PathArgument, ?> normalizedNode = transformIntoNormalizedNode.get();
         if (codecRegistry.fromNormalizedNode(yangId, normalizedNode) != null) {
-            LOG.debug("The key of the generated object",
-                    codecRegistry.fromNormalizedNode(yangId, normalizedNode).getKey());
             dataObject = codecRegistry.fromNormalizedNode(yangId, normalizedNode).getValue();
         } else {
             LOG.warn("The codec registry from the normalized node is null!");
@@ -142,16 +144,15 @@ public class GnpyResult {
         return isFeasible;
     }
 
-    public void analyzeResult() {
+    public List<PathRouteObjects> analyzeResult() {
+        List<PathRouteObjects> pathRouteObjectList = null;
         if (response != null) {
-            Long responseId = response.getResponseId();
-            LOG.info("Response-Id {}", responseId);
             if (response.getResponseType() instanceof NoPathCase) {
                 NoPathCase noPathCase = (NoPathCase) response.getResponseType();
                 String noPathType = noPathCase.getNoPath().getNoPath();
-                LOG.info("GNPy: No path - {}",noPathType);
+                LOG.info("GNPy: No path - {}", noPathType);
                 if (((noPathType.equals("NO_FEASIBLE_BAUDRATE_WITH_SPACING"))
-                        && (noPathType.equals("NO_FEASIBLE_MODE"))) && ((noPathType.equals("MODE_NOT_FEASIBLE"))
+                    && (noPathType.equals("NO_FEASIBLE_MODE"))) && ((noPathType.equals("MODE_NOT_FEASIBLE"))
                         && (noPathType.equals("NO_SPECTRUM")))) {
                     List<PathMetric> pathMetricList = noPathCase.getNoPath().getPathProperties().getPathMetric();
                     LOG.info("GNPy : path is not feasible : {}", noPathType);
@@ -165,80 +166,82 @@ public class GnpyResult {
                 LOG.info("GNPy : path is feasible");
                 PathCase pathCase = (PathCase) response.getResponseType();
                 List<PathMetric> pathMetricList = pathCase.getPathProperties().getPathMetric();
+                // Path metrics
                 for (PathMetric pathMetric : pathMetricList) {
                     String metricType = pathMetric.getMetricType().getSimpleName();
                     BigDecimal accumulativeValue = pathMetric.getAccumulativeValue();
                     LOG.info("Metric type {} // AccumulatriveValue {}", metricType, accumulativeValue);
                 }
+                // Path route objects
+                pathRouteObjectList = pathCase.getPathProperties().getPathRouteObjects();
+                LOG.info("in GnpyResult: finishing the computation of pathRouteObjectList");
             }
         }
+        return pathRouteObjectList;
     }
 
-    public HardConstraints analyzeGnpyPath() {
+    public HardConstraints computeHardConstraintsFromGnpyPath(List<PathRouteObjects> pathRouteObjectList) {
         HardConstraints hardConstraints = null;
-        if (response != null) {
-            Long responseId = response.getResponseId();
-            LOG.info("Response-Id {}", responseId);
-            if (response.getResponseType() instanceof NoPathCase) {
-                NoPathCase noPathCase = (NoPathCase) response.getResponseType();
-                LOG.info("No path feasible {}", noPathCase.toString());
-            } else if (response.getResponseType() instanceof PathCase) {
-                PathCase pathCase = (PathCase) response.getResponseType();
-                List<PathMetric> pathMetricList = pathCase.getPathProperties().getPathMetric();
-                for (PathMetric pathMetric : pathMetricList) {
-                    String metricType = pathMetric.getMetricType().getSimpleName();
-                    BigDecimal accumulativeValue = pathMetric.getAccumulativeValue();
-                    LOG.info("Metric type {} // AccumulatriveValue {}", metricType, accumulativeValue);
-                }
-
-                // Includes the list of nodes in the GNPy computed path as constraints for the PCE
-                List<OrderedHops> orderedHopsList = null;
-                List<PathRouteObjects> pathRouteObjectList = pathCase.getPathProperties().getPathRouteObjects();
-                int counter = 0;
-                for (PathRouteObjects pathRouteObjects : pathRouteObjectList) {
-                    if (pathRouteObjects.getPathRouteObject().getType() instanceof NumUnnumHop) {
-                        NumUnnumHop numUnnumHop = (NumUnnumHop) pathRouteObjects.getPathRouteObject().getType();
-                        String nodeId = numUnnumHop.getNodeId();
+        // Includes the list of nodes in the GNPy computed path as constraints
+        // for the PCE
+        List<OrderedHops> orderedHopsList = new ArrayList<>();
+        int counter = 0;
+        for (PathRouteObjects pathRouteObjects : pathRouteObjectList) {
+            if (pathRouteObjects.getPathRouteObject().getType() instanceof NumUnnumHop) {
+                NumUnnumHop numUnnumHop = (org.opendaylight.yang.gen.v1.gnpy.path.rev190502.explicit.route.hop.type
+                    .NumUnnumHop) pathRouteObjects.getPathRouteObject().getType();
+                String nodeIp = numUnnumHop.getNumUnnumHop().getNodeId();
+                try {
+                    IpAddress nodeIpAddress = new IpAddress(new Ipv4Address(nodeIp));
+                    // find the corresponding node-id (in ord-ntw) corresponding to nodeId (in gnpy response)
+                    String nodeId = findOrdNetworkNodeId(nodeIpAddress);
+                    if (nodeId != null) {
                         org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017
-                                .ordered.constraints.sp.hop.type.hop.type.Node node = new NodeBuilder()
-                                .setNodeId(nodeId).build();
+                            .ordered.constraints.sp.hop.type.hop.type.Node node = new NodeBuilder().setNodeId(nodeId)
+                            .build();
                         HopType hopType = new HopTypeBuilder().setHopType(node).build();
                         OrderedHops orderedHops = new OrderedHopsBuilder().setHopNumber(counter).setHopType(hopType)
-                                .build();
-                        LOG.info("- gnpyResult class : Hard Constraint: {} // - Hop Node {}", counter, nodeId);
+                            .build();
                         orderedHopsList.add(orderedHops);
                         counter++;
                     }
+                } catch (IllegalArgumentException e) {
+                    LOG.debug(" in GnpyResult: the element {} is not a ipv4Address ", nodeIp);
                 }
-                Include include = new IncludeBuilder().setOrderedHops(orderedHopsList).build();
-                General general = new GeneralBuilder().setInclude(include).build();
-                hardConstraints = new HardConstraintsBuilder().setCoRoutingOrGeneral(general).build();
             }
         }
+        Include include = new IncludeBuilder().setOrderedHops(orderedHopsList).build();
+        General general = new GeneralBuilder().setInclude(include).build();
+        hardConstraints = new HardConstraintsBuilder().setCoRoutingOrGeneral(general).build();
         return hardConstraints;
     }
 
+    private String findOrdNetworkNodeId(IpAddress nodeIpAddress) {
+        String nodeId;
+        Set<String> keySet = this.mapNodeRefIp.keySet();
+        Iterator<String> it = keySet.iterator();
+        while (it.hasNext()) {
+            nodeId = it.next();
+            if (this.mapNodeRefIp.get(nodeId).equals(nodeIpAddress)) {
+                return nodeId;
+            }
+        }
+        return null;
+    }
+
     /**
-     * Parses the input json with concrete implementation of
-     * {@link JsonParserStream}.
-     *
-     * @param reader
-     *            of the given JSON
-     * @throws Exception
-     *
+     * Parses the input json with concrete implementation of {@link JsonParserStream}.
+     * @param reader of the given JSON
+     * @throws Exception exception
      */
     private Optional<NormalizedNode<? extends YangInstanceIdentifier.PathArgument, ?>> parseInputJSON(JsonReader reader,
-            Class<? extends DataObject> objectClass) throws Exception {
+        Class<? extends DataObject> objectClass) throws Exception {
         NormalizedNodeResult result = new NormalizedNodeResult();
         SchemaContext schemaContext = getSchemaContext(objectClass);
         try (NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
-                JsonParserStream jsonParser = JsonParserStream.create(streamWriter,
-                    JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(schemaContext),
-                    schemaContext);) {
-            LOG.debug("GNPy: the path to the reader {}", reader.getPath());
-            LOG.debug("GNPy: the reader {}", reader.toString());
-            LOG.debug("GNPy: the jsonParser class {} // jsonParser to string {}", jsonParser.getClass(),
-                    jsonParser.toString());
+            JsonParserStream jsonParser = JsonParserStream.create(streamWriter,
+                JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(schemaContext),
+                schemaContext);) {
             jsonParser.parse(reader);
         } catch (IOException e) {
             LOG.warn("GNPy: exception {} occured during parsing Json input stream", e.getMessage());
@@ -258,20 +261,11 @@ public class GnpyResult {
     }
 
     /**
-     * Transforms the given input {@link NormalizedNode} into the given
-     * {@link DataObject}.
-     *
-     * @param normalizedNode
-     *            normalized node you want to convert
-     * @param rootNode
-     *            {@link QName} of converted normalized node root
-     *
-     *            <p>
-     *            The input object should be {@link ContainerNode}
-     *            </p>
+     * Transforms the given input {@link NormalizedNode} into the given {@link DataObject}.
      */
+    @SuppressWarnings("unchecked")
     public <T extends DataObject> Optional<T> getDataObject(@Nonnull NormalizedNode<?, ?> normalizedNode,
-            @Nonnull QName rootNode, BindingNormalizedNodeSerializer codecRegistry) {
+        @Nonnull QName rootNode, BindingNormalizedNodeSerializer codecRegistry) {
         if (normalizedNode != null) {
             LOG.debug("GNPy: The codecRegistry is ", codecRegistry.toString());
         } else {
@@ -280,9 +274,9 @@ public class GnpyResult {
         Preconditions.checkNotNull(normalizedNode);
         if (normalizedNode instanceof ContainerNode) {
             YangInstanceIdentifier.PathArgument directChildIdentifier = YangInstanceIdentifier.of(rootNode)
-                    .getLastPathArgument();
+                .getLastPathArgument();
             Optional<NormalizedNode<?, ?>> directChild = NormalizedNodes.getDirectChild(normalizedNode,
-                    directChildIdentifier);
+                directChildIdentifier);
             if (!directChild.isPresent()) {
                 throw new IllegalStateException(String.format("Could not get the direct child of %s", rootNode));
             }
@@ -292,7 +286,7 @@ public class GnpyResult {
         YangInstanceIdentifier rootNodeYangInstanceIdentifier = YangInstanceIdentifier.of(rootNode);
         LOG.debug("GNPy: the root Node Yang Instance Identifier is ", rootNodeYangInstanceIdentifier.toString());
         Map.Entry<?, ?> bindingNodeEntry = codecRegistry.fromNormalizedNode(rootNodeYangInstanceIdentifier,
-                normalizedNode);
+            normalizedNode);
         if (bindingNodeEntry == null) {
             LOG.debug("The binding Node Entry is null");
             return Optional.empty();
diff --git a/pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/GnpyServiceImpl.java b/pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/GnpyServiceImpl.java
new file mode 100644 (file)
index 0000000..34fc4ec
--- /dev/null
@@ -0,0 +1,383 @@
+/*
+ * Copyright © 2019 Orange, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.transportpce.pce.gnpy;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.opendaylight.transportpce.pce.constraints.PceConstraints;
+import org.opendaylight.transportpce.pce.constraints.PceConstraints.ResourcePair;
+import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.topo.Elements;
+import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.RouteIncludeEro;
+import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.TeHopType;
+import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.TeNodeId;
+import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.TePathDisjointness;
+import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.TeTpId;
+import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.common.constraints_config.TeBandwidth;
+import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.common.constraints_config.TeBandwidthBuilder;
+import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.explicit.route.hop.Type;
+import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.explicit.route.hop.type.NumUnnumHopBuilder;
+import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.explicit.route.hop.type.num.unnum.hop.NumUnnumHop;
+import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.generic.path.constraints.PathConstraints;
+import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.generic.path.constraints.PathConstraintsBuilder;
+import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.gnpy.specific.parameters.EffectiveFreqSlot;
+import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.gnpy.specific.parameters.EffectiveFreqSlotBuilder;
+import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.path.route.objects.ExplicitRouteObjects;
+import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.path.route.objects.ExplicitRouteObjectsBuilder;
+import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.path.route.objects.explicit.route.objects.RouteObjectIncludeExclude;
+import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.path.route.objects.explicit.route.objects.RouteObjectIncludeExcludeBuilder;
+import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.service.PathRequest;
+import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.service.PathRequestBuilder;
+import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.synchronization.info.Synchronization;
+import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.synchronization.info.SynchronizationBuilder;
+import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.synchronization.info.synchronization.Svec;
+import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.synchronization.info.synchronization.SvecBuilder;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev190624.PathComputationRequestInput;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.AToZDirection;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.ZToADirection;
+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.ztoa.direction.ZToA;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Class to create the topology corresponding to GNPy requirements.
+ *
+ * @author Ahmed Triki ( ahmed.triki@orange.com )
+ *
+ */
+
+public class GnpyServiceImpl {
+    private static final Logger LOG = LoggerFactory.getLogger(GnpyServiceImpl.class);
+    private List<PathRequest> pathRequest = new ArrayList<>();
+    private List<Synchronization> synchronization = new ArrayList<>();
+    private Map<String, String> mapDisgNodeRefNode = new HashMap<String, String>();
+    private Map<String, IpAddress> mapNodeRefIp = new HashMap<String, IpAddress>();
+    private Map<String, String> mapLinkFiber = new HashMap<String, String>();
+    private Map<String, IpAddress> mapFiberIp = new HashMap<String, IpAddress>();
+    private List<Elements> elements = new ArrayList<>();
+
+    /*
+     * Construct the GnpyServiceImpl
+     */
+    public GnpyServiceImpl(PathComputationRequestInput input, AToZDirection atoz, Long requestId, GnpyTopoImpl gnpyTopo,
+        PceConstraints pceHardConstraints) {
+        this.elements = gnpyTopo.getElements();
+        this.mapDisgNodeRefNode = gnpyTopo.getMapDisgNodeRefNode();
+        this.mapNodeRefIp = gnpyTopo.getMapNodeRefIp();
+        this.mapLinkFiber = gnpyTopo.getMapLinkFiber();
+        this.mapFiberIp = gnpyTopo.getMapFiberIp();
+
+        this.pathRequest = extractPathRequest(input, atoz, requestId, pceHardConstraints);
+        this.synchronization = extractSynchronization(requestId);
+    }
+
+    public GnpyServiceImpl(PathComputationRequestInput input, ZToADirection ztoa, Long requestId, GnpyTopoImpl gnpyTopo,
+        PceConstraints pceHardConstraints) {
+        this.elements = gnpyTopo.getElements();
+        this.mapDisgNodeRefNode = gnpyTopo.getMapDisgNodeRefNode();
+        this.mapNodeRefIp = gnpyTopo.getMapNodeRefIp();
+        this.mapLinkFiber = gnpyTopo.getMapLinkFiber();
+        this.mapFiberIp = gnpyTopo.getMapFiberIp();
+
+        pathRequest = extractPathRequest(input, ztoa, requestId, pceHardConstraints);
+        synchronization = extractSynchronization(requestId);
+    }
+
+    //Create the pathRequest
+    public List<PathRequest> extractPathRequest(PathComputationRequestInput input, AToZDirection atoz, Long requestId,
+        PceConstraints pceHardConstraints) {
+        // 1.1 Create explicitRouteObjects
+        // 1.1.1. create RouteObjectIncludeExclude list
+        List<RouteObjectIncludeExclude> routeObjectIncludeExcludes = new ArrayList<>();
+        IpAddress ipAddressCurrent = null;
+        Long index = (long) 0;
+        // List of A to Z
+        List<AToZ> listAtoZ = atoz.getAToZ();
+        if (listAtoZ != null) {
+            int atozSize = listAtoZ.size();
+            for (int i = 0; i < atozSize; i++) {
+                String nodeId = null;
+                if (listAtoZ.get(i).getResource().getResource()
+                    instanceof
+                        org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017
+                            .pce.resource.resource.resource.Node) {
+                    org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017
+                        .pce.resource.resource.resource.Node node =
+                        (org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017
+                            .pce.resource.resource.resource.Node) listAtoZ.get(i).getResource().getResource();
+
+                    nodeId = node.getNodeId();
+                    if (nodeId != null) {
+                        String nodeRef = this.mapDisgNodeRefNode.get(nodeId);
+                        IpAddress ipAddress = this.mapNodeRefIp.get(nodeRef);
+                        for (Elements element : this.elements) {
+                            if (element.getUid().contains(ipAddress.getIpv4Address().getValue().toString())) {
+                                if ((ipAddressCurrent == null) || (ipAddressCurrent != ipAddress)) {
+                                    ipAddressCurrent = ipAddress;
+                                    // Fill in routeObjectIncludeExcludes
+                                    RouteObjectIncludeExclude routeObjectIncludeExclude1 = addRouteObjectIncludeExclude(
+                                        ipAddress, 1, index);
+                                    routeObjectIncludeExcludes.add(routeObjectIncludeExclude1);
+                                    index++;
+                                }
+                                break;
+                            }
+                        }
+                    } else {
+                        LOG.warn("node ID is null");
+                    }
+                    // TODO else if termination point not implemented in this
+                    // version
+                } else if (listAtoZ.get(i).getResource().getResource()
+                    instanceof
+                        org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017
+                            .pce.resource.resource.resource.Link) {
+                    org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017
+                        .pce.resource.resource.resource.Link link =
+                        (org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017
+                            .pce.resource.resource.resource.Link) listAtoZ.get(i).getResource().getResource();
+
+                    String clfi = this.mapLinkFiber.get(link.getLinkId());
+                    IpAddress fiberIp = this.mapFiberIp.get(clfi);
+                    if (clfi != null) {
+                        RouteObjectIncludeExclude routeObjectIncludeExclude1 = addRouteObjectIncludeExclude(fiberIp, 1,
+                            index);
+                        routeObjectIncludeExcludes.add(routeObjectIncludeExclude1);
+                        index++;
+                    }
+                }
+            }
+        }
+        else {
+            routeObjectIncludeExcludes = extractHardConstraints(pceHardConstraints);
+            //TODO integrate the maxLatency/ Metric and max OSNR as additional constraints to GNPy
+        }
+
+        // 1.1. Create ExplicitRouteObjects
+        ExplicitRouteObjects explicitRouteObjects = new ExplicitRouteObjectsBuilder()
+            .setRouteObjectIncludeExclude(routeObjectIncludeExcludes).build();
+        // 1.2 Create a path constraints
+        Long rate = atoz.getRate();
+        // 1.2.1. Create EffectiveFreqSlot
+        List<EffectiveFreqSlot> effectiveFreqSlot = new ArrayList<>();
+        EffectiveFreqSlot effectiveFreqSlot1 = new EffectiveFreqSlotBuilder().setM(5).setN(8).build();
+        effectiveFreqSlot.add(effectiveFreqSlot1);
+        // 1.2.2. Create Te-Bandwidth
+        TeBandwidth teBandwidth = new TeBandwidthBuilder().setPathBandwidth(new BigDecimal(rate))
+            .setTechnology("flexi-grid").setTrxType("openroadm-beta1").setTrxMode("W100G")
+            .setEffectiveFreqSlot(effectiveFreqSlot).setSpacing(new BigDecimal(50000000000.0)).build();
+        PathConstraints pathConstraints = new PathConstraintsBuilder().setTeBandwidth(teBandwidth).build();
+        // 1.3. Create the source and destination nodes
+        String sourceNode = input.getServiceAEnd().getNodeId();
+        String destNode = input.getServiceZEnd().getNodeId();
+        // Create the path-request elements
+        // Create the path request
+        List<PathRequest> pathRequestList = new ArrayList<>();
+        PathRequest pathRequest1 = new PathRequestBuilder().setRequestId(requestId)
+            .setSource(this.mapNodeRefIp.get(sourceNode)).setDestination(this.mapNodeRefIp.get(destNode))
+            .setSrcTpId("srcTpId".getBytes()).setDstTpId("dstTpId".getBytes()).setPathConstraints(pathConstraints)
+            .setExplicitRouteObjects(explicitRouteObjects).build();
+        pathRequestList.add(pathRequest1);
+        return pathRequestList;
+    }
+
+    public List<PathRequest> extractPathRequest(PathComputationRequestInput input, ZToADirection ztoa, Long requestId,
+        PceConstraints pceHardConstraints) {
+        // 1.1 Create explicitRouteObjects
+        // 1.1.1. create RouteObjectIncludeExclude list
+        List<RouteObjectIncludeExclude> routeObjectIncludeExcludes = new ArrayList<>();
+        IpAddress ipAddressCurrent = null;
+        Long index = (long) 0;
+        List<ZToA> listZtoA = ztoa.getZToA();
+        if (listZtoA != null) {
+            int ztoaSize = listZtoA.size();
+            for (int i = 0; i < ztoaSize; i++) {
+                String nodeId = null;
+                if (listZtoA.get(i).getResource().getResource()
+                    instanceof
+                        org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017
+                            .pce.resource.resource.resource.Node) {
+                    org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017
+                        .pce.resource.resource.resource.Node node =
+                        (org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017
+                            .pce.resource.resource.resource.Node) listZtoA.get(i).getResource().getResource();
+                    nodeId = node.getNodeId();
+                    if (nodeId != null) {
+                        String nodeRef = this.mapDisgNodeRefNode.get(nodeId);
+                        IpAddress ipAddress = this.mapNodeRefIp.get(nodeRef);
+                        for (Elements element : this.elements) {
+                            if (element.getUid().contains(ipAddress.getIpv4Address().getValue().toString())) {
+                                if ((ipAddressCurrent == null) || (ipAddressCurrent != ipAddress)) {
+                                    ipAddressCurrent = ipAddress;
+                                    // Fill in routeObjectIncludeExcludes
+                                    RouteObjectIncludeExclude routeObjectIncludeExclude1 = addRouteObjectIncludeExclude(
+                                        ipAddress, 1, index);
+                                    routeObjectIncludeExcludes.add(routeObjectIncludeExclude1);
+                                    index++;
+                                }
+                                break;
+                            }
+                        }
+                    } else {
+                        LOG.warn("node ID is null");
+                    }
+                    // TODO else if termination point not implemented in this
+                    // version
+                } else if (listZtoA.get(i).getResource().getResource()
+                    instanceof
+                        org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017
+                            .pce.resource.resource.resource.Link) {
+
+                    org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017
+                        .pce.resource.resource.resource.Link link =
+                        (org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017
+                            .pce.resource.resource.resource.Link) listZtoA.get(i).getResource().getResource();
+                    String clfi = this.mapLinkFiber.get(link.getLinkId());
+                    IpAddress fiberIp = this.mapFiberIp.get(clfi);
+                    if (clfi != null) {
+                        RouteObjectIncludeExclude routeObjectIncludeExclude1 =
+                            addRouteObjectIncludeExclude(fiberIp, 1, index);
+                        routeObjectIncludeExcludes.add(routeObjectIncludeExclude1);
+                        index++;
+                    }
+
+                }
+            }
+        } else {
+            routeObjectIncludeExcludes = extractHardConstraints(pceHardConstraints);
+        }
+
+        // 1.1. Create ExplicitRouteObjects
+        ExplicitRouteObjects explicitRouteObjects = new ExplicitRouteObjectsBuilder()
+            .setRouteObjectIncludeExclude(routeObjectIncludeExcludes).build();
+        // 1.2 Create a path constraints
+        Long rate = ztoa.getRate();
+        // 1.2.1. Create EffectiveFreqSlot
+        List<EffectiveFreqSlot> effectiveFreqSlot = new ArrayList<>();
+        EffectiveFreqSlot effectiveFreqSlot1 = new EffectiveFreqSlotBuilder().setM(5).setN(8).build();
+        effectiveFreqSlot.add(effectiveFreqSlot1);
+        // 1.2.2. Create Te-Bandwidth
+        TeBandwidth teBandwidth = new TeBandwidthBuilder().setPathBandwidth(new BigDecimal(rate))
+            .setTechnology("flexi-grid").setTrxType("openroadm-beta1").setTrxMode("W100G")
+            .setEffectiveFreqSlot(effectiveFreqSlot).setSpacing(new BigDecimal(50000000000.0)).build();
+        PathConstraints pathConstraints = new PathConstraintsBuilder().setTeBandwidth(teBandwidth).build();
+        // 1.3. Create the source and destination nodes
+        String sourceNode = input.getServiceZEnd().getNodeId();
+        String destNode = input.getServiceAEnd().getNodeId();
+        // Create the path-request elements
+        // Create the path request
+        List<PathRequest> pathRequestList = new ArrayList<>();
+        PathRequest pathRequest1 = new PathRequestBuilder().setRequestId(requestId)
+            .setSource(this.mapNodeRefIp.get(sourceNode)).setDestination(this.mapNodeRefIp.get(destNode))
+            .setSrcTpId("srcTpId".getBytes()).setDstTpId("dstTpId".getBytes()).setPathConstraints(pathConstraints)
+            .setExplicitRouteObjects(explicitRouteObjects).build();
+        pathRequestList.add(pathRequest1);
+        return pathRequestList;
+    }
+
+  //Create RouteObjectIncludeExclude list
+    public List<RouteObjectIncludeExclude> extractHardConstraints(PceConstraints pceHardConstraints) {
+        List<String> listNodeToInclude = getListToInclude(pceHardConstraints);
+        List<RouteObjectIncludeExclude> routeObjectIncludeExcludes = new ArrayList<>();
+        IpAddress ipAddressCurrent = null;
+        Long index = (long) 0;
+        if (listNodeToInclude != null) {
+            for (int i = 0; i < listNodeToInclude.size(); i++) {
+                String nodeId = listNodeToInclude.get(i);
+                if (nodeId != null) {
+                    IpAddress ipAddress = this.mapNodeRefIp.get(nodeId);
+                    for (Elements element : this.elements) {
+                        if (element.getUid().contains(ipAddress.getIpv4Address().getValue().toString())) {
+                            if ((ipAddressCurrent == null) || (ipAddressCurrent != ipAddress)) {
+                                ipAddressCurrent = ipAddress;
+                                // Fill in routeObjectIncludeExcludes
+                                RouteObjectIncludeExclude routeObjectIncludeExclude1 = addRouteObjectIncludeExclude(
+                                    ipAddress, 1, index);
+                                routeObjectIncludeExcludes.add(routeObjectIncludeExclude1);
+                                index++;
+                            }
+                            break;
+                        }
+                    }
+                } else {
+                    LOG.warn("node ID is null");
+                }
+            }
+        }
+        return routeObjectIncludeExcludes;
+    }
+
+    // Create the synchronization
+    public List<Synchronization> extractSynchronization(Long requestId) {
+        // Create RequestIdNumber
+        List<Long> requestIdNumber = new ArrayList<>();
+        requestIdNumber.add(requestId);
+        // Create a synchronization
+        Svec svec = new SvecBuilder().setRelaxable(true).setDisjointness(new TePathDisjointness(true, true, false))
+            .setRequestIdNumber(requestIdNumber).build();
+        List<Synchronization> synchro = new ArrayList<>();
+        Synchronization synchronization1 = new SynchronizationBuilder().setSynchronizationId(new Long(0)).setSvec(svec)
+            .build();
+        synchro.add(synchronization1);
+        return (synchro);
+    }
+
+    // Add routeObjectIncludeExclude
+    private RouteObjectIncludeExclude addRouteObjectIncludeExclude(IpAddress ipAddress, long teTpValue, long index) {
+        TeNodeId teNodeId = new TeNodeId(ipAddress);
+        TeTpId teTpId = new TeTpId(teTpValue);
+        NumUnnumHop numUnnumHop = new org.opendaylight.yang.gen.v1.gnpy.path.rev190502.explicit.route.hop.type.num
+            .unnum.hop.NumUnnumHopBuilder().setNodeId(teNodeId.getIpv4Address().getValue().toString())
+            .setLinkTpId(teTpId.getUint32().toString()).setHopType(TeHopType.STRICT).build();
+        Type type1 = new NumUnnumHopBuilder().setNumUnnumHop(numUnnumHop).build();
+        // Create routeObjectIncludeExclude element 1
+        RouteObjectIncludeExclude routeObjectIncludeExclude1 = new RouteObjectIncludeExcludeBuilder().setIndex(index)
+            .setExplicitRouteUsage(RouteIncludeEro.class).setType(type1).build();
+        return routeObjectIncludeExclude1;
+    }
+
+    // Create the list of nodes to include
+    private List<String> getListToInclude(PceConstraints pceHardConstraints) {
+        List<String> listNodeToInclude = new ArrayList<>();
+        if (pceHardConstraints != null) {
+            List<ResourcePair> listToInclude = pceHardConstraints.getListToInclude();
+            Iterator<ResourcePair> it = listToInclude.iterator();
+            while (it.hasNext()) {
+                ResourcePair rs = it.next();
+                if (rs.getType().name().equals("NODE")) {
+                    listNodeToInclude.add(rs.getName());
+                }
+            }
+        }
+        return listNodeToInclude;
+    }
+
+    public List<PathRequest> getPathRequest() {
+        return pathRequest;
+    }
+
+    public void setPathRequest(List<PathRequest> pathRequest) {
+        this.pathRequest = pathRequest;
+    }
+
+    public List<Synchronization> getSynchronization() {
+        return synchronization;
+    }
+
+    public void setSynchronization(List<Synchronization> synchronization) {
+        this.synchronization = synchronization;
+    }
+
+}
similarity index 59%
rename from pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/ExtractTopoDataStoreImpl.java
rename to pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/GnpyTopoImpl.java
index 0ad7f2e1a64e688ead695126a14efa72e17c69bf..de0f7b56c16f7e6ed996903e03b70e48f943c9fa 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2018 Orange, Inc. and others.  All rights reserved.
+ * Copyright © 2019 Orange, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -43,31 +43,6 @@ import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.topo.El
 import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.topo.ElementsBuilder;
 import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.topo.elements.Metadata;
 import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.topo.elements.MetadataBuilder;
-import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.RouteIncludeEro;
-import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.TeHopType;
-import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.TeNodeId;
-import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.TePathDisjointness;
-import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.TeTpId;
-import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.common.constraints_config.TeBandwidth;
-import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.common.constraints_config.TeBandwidthBuilder;
-import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.explicit.route.hop.Type;
-import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.explicit.route.hop.type.NumUnnumHopBuilder;
-import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.explicit.route.hop.type.num.unnum.hop.NumUnnumHop;
-import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.generic.path.constraints.PathConstraints;
-import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.generic.path.constraints.PathConstraintsBuilder;
-import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.gnpy.specific.parameters.EffectiveFreqSlot;
-import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.gnpy.specific.parameters.EffectiveFreqSlotBuilder;
-import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.path.route.objects.ExplicitRouteObjects;
-import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.path.route.objects.ExplicitRouteObjectsBuilder;
-import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.path.route.objects.explicit.route.objects.RouteObjectIncludeExclude;
-import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.path.route.objects.explicit.route.objects.RouteObjectIncludeExcludeBuilder;
-import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.service.PathRequest;
-import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.service.PathRequestBuilder;
-import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.synchronization.info.Synchronization;
-import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.synchronization.info.SynchronizationBuilder;
-import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.synchronization.info.synchronization.Svec;
-import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.synchronization.info.synchronization.SvecBuilder;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev190624.PathComputationRequestInput;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.link.rev181130.amplified.link.attributes.AmplifiedLink;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.link.rev181130.amplified.link.attributes.amplified.link.section.element.section.element.Span;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.link.rev181130.amplified.link.attributes.amplified.link.section.element.section.element.ila.Ila;
@@ -75,10 +50,6 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.link.rev181130.span.attri
 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.rev181130.Node1;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.Link1;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130.networks.network.link.OMSAttributes;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.AToZDirection;
-import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.ZToADirection;
-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.ztoa.direction.ZToA;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NetworkId;
@@ -100,16 +71,19 @@ import org.slf4j.LoggerFactory;
  *
  */
 
-public class ExtractTopoDataStoreImpl {
-    private static final Logger LOG = LoggerFactory.getLogger(ExtractTopoDataStoreImpl.class);
+public class GnpyTopoImpl {
+    private static final Logger LOG = LoggerFactory.getLogger(GnpyTopoImpl.class);
     private final NetworkTransactionService networkTransactionService;
     private List<Elements> elements = new ArrayList<>();
     private List<Connections> connections = new ArrayList<>();
-    private List<PathRequest> pathRequest = new ArrayList<>();
-    private List<Synchronization> synchronization = new ArrayList<>();
+    //Mapping elements
+    //Mapping between the ord-topo and ord-ntw node
     private Map<String, String> mapDisgNodeRefNode = new HashMap<String, String>();
+    //Mapping between the ord-ntw and node ip
     private Map<String, IpAddress> mapNodeRefIp = new HashMap<String, IpAddress>();
+    //Mapping between link id and clfi
     private Map<String, String> mapLinkFiber = new HashMap<String, String>();
+    //Mapping between fiber clfi and ipAddress
     private Map<String, IpAddress> mapFiberIp = new HashMap<String, IpAddress>();
     private static int convertKmM = 1000;
 
@@ -117,8 +91,7 @@ public class ExtractTopoDataStoreImpl {
      * Construct the ExtractTopoDataStoreImpl.
      */
     @SuppressWarnings("unchecked")
-    public ExtractTopoDataStoreImpl(final NetworkTransactionService networkTransactionService,
-            PathComputationRequestInput input,AToZDirection atoz, Long requestId) {
+    public GnpyTopoImpl(final NetworkTransactionService networkTransactionService) {
         this.networkTransactionService = networkTransactionService;
         Map<String, List<?>> map = extractTopo();
         if (map.containsKey("Elements")) {
@@ -131,27 +104,6 @@ public class ExtractTopoDataStoreImpl {
         } else {
             connections = null;
         }
-
-        pathRequest = extractPathRequest(input, atoz, requestId);
-        synchronization = extractSynchronization(requestId);
-    }
-
-    public ExtractTopoDataStoreImpl(final NetworkTransactionService networkTransactionService,
-            PathComputationRequestInput input, ZToADirection ztoa, Long requestId) {
-        this.networkTransactionService = networkTransactionService;
-        Map<String, List<?>> map = extractTopo();
-        if (map.containsKey("Elements")) {
-            elements = (List<Elements>) map.get("Elements");
-        } else {
-            elements = null;
-        }
-        if (map.containsKey("Connections")) {
-            connections = (List<Connections>) map.get("Connections");
-        } else {
-            connections = null;
-        }
-        pathRequest = extractPathRequest(input, ztoa, requestId);
-        synchronization = extractSynchronization(requestId);
     }
 
     /*
@@ -173,7 +125,6 @@ public class ExtractTopoDataStoreImpl {
         InstanceIdentifier<Network> insIdrOpenRoadmNet = InstanceIdentifier
                 .builder(Networks.class)
                 .child(Network.class, new NetworkKey(new NetworkId(NetworkUtils.UNDERLAY_NETWORK_ID))).build();
-        // Read the data broker
         try {
             // Initialize the reading of the networkTransactionService
             // read the configuration part of the data broker that concerns
@@ -295,7 +246,7 @@ public class ExtractTopoDataStoreImpl {
                                                     destId = element1.getUid();
                                                     destIp = null;
                                                     // Create a new link
-                                                    if (!destId.equals(srcId)) {
+                                                    if (srcId != destId) {
                                                         Connections connection = createNewConnection(srcId, srcIp,
                                                                 destId, destIp);
                                                         topoConnections.add(connection);
@@ -309,18 +260,15 @@ public class ExtractTopoDataStoreImpl {
                                         org.opendaylight.yang.gen.v1.http.org.openroadm.network.topology.rev181130
                                             .networks.network.link.oms.attributes.@Nullable Span span
                                                 = omsAttributes.getSpan();
-
                                         String clfi = span.getClfi();
                                         IpAddress ipFiber = new IpAddress(new Ipv4Address("2.2.2." + idFiber));
                                         mapLinkFiber.put(link.getLinkId().getValue(), clfi);
                                         mapFiberIp.put(clfi, ipFiber);
                                         idFiber++;
-
                                         double attIn = 0;
                                         double connIn = 0;
                                         double connOut = 0;
                                         String typeVariety = "SSMF";
-
                                         double length = 0;
                                         // Compute the length of the link
                                         List<LinkConcatenation> linkConcatenationList = span.getLinkConcatenation();
@@ -330,16 +278,14 @@ public class ExtractTopoDataStoreImpl {
                                             length += srlgLength / convertKmM;
                                         }
                                         double lossCoef = span.getSpanlossCurrent().getValue().doubleValue() / length;
-
                                         Elements element1 = addElementsFiber(2, 0, "RLD", "Lannion_CAS",
                                                 ipFiber.getIpv4Address().getValue(), length, attIn, lossCoef, connIn,
                                                 connOut, typeVariety);
-
                                         topoElements.add(element1);
                                         // Create a new link
                                         destId = element1.getUid();
                                         destIp = null;
-                                        if (!destId.equals(srcId)) {
+                                        if (srcId != destId) {
                                             Connections connection = createNewConnection(srcId, srcIp, destId, destIp);
                                             topoConnections.add(connection);
                                             srcId = destId;
@@ -359,7 +305,7 @@ public class ExtractTopoDataStoreImpl {
                                         // Create a new link
                                         destId = element1.getUid();
                                         destIp = null;
-                                        if (!destId.equals(srcId)) {
+                                        if (srcId != destId) {
                                             Connections connection = createNewConnection(srcId, srcIp, destId, destIp);
                                             topoConnections.add(connection);
                                             srcId = destId;
@@ -367,7 +313,7 @@ public class ExtractTopoDataStoreImpl {
                                         }
                                     }
                                 } else {
-                                    LOG.warn("The oms attributes is null!");
+                                    LOG.warn("The oms attributes is null {} !",link1.getLinkType().getName());
                                 }
                                 // Create a new link
                                 destId = mapDisgNodeRefNode.get(link.getDestination().getDestNode().getValue());
@@ -393,200 +339,6 @@ public class ExtractTopoDataStoreImpl {
         return map;
     }
 
-    /*
-     * Create the pathRequest
-     */
-    public List<PathRequest> extractPathRequest(PathComputationRequestInput input, AToZDirection atoz, Long requestId) {
-        // List of A to Z
-        List<AToZ> listAtoZ = atoz.getAToZ();
-        int atozSize = listAtoZ.size();
-        // Create the path request
-        List<PathRequest> pathRequestList = new ArrayList<>();
-
-        // 1.1 Create explicitRouteObjects
-        // 1.1.1. create RouteObjectIncludeExclude list
-        List<RouteObjectIncludeExclude> routeObjectIncludeExcludes = new ArrayList<>();
-        IpAddress ipAddressCurrent = null;
-        Long index = (long) 0;
-        for (int i = 0; i < atozSize; i++) {
-            String nodeId = null;
-            if (listAtoZ.get(i).getResource()
-                    .getResource() instanceof org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
-                    .pathdescription.rev171017.pce.resource.resource.resource.Node) {
-                org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
-                    .resource.resource.resource.Node node = (org.opendaylight.yang.gen.v1.http.org.transportpce.b.c
-                            ._interface.pathdescription.rev171017.pce.resource.resource.resource.Node) listAtoZ
-                        .get(i).getResource().getResource();
-                nodeId = node.getNodeId();
-                if (nodeId != null) {
-                    String nodeRef = mapDisgNodeRefNode.get(nodeId);
-                    IpAddress ipAddress = mapNodeRefIp.get(nodeRef);
-                    for (Elements element : elements) {
-                        if (element.getUid().contains(ipAddress.getIpv4Address().getValue().toString())) {
-                            if ((ipAddressCurrent == null) || (!ipAddress.equals(ipAddressCurrent))) {
-                                ipAddressCurrent = ipAddress;
-                                // Fill in routeObjectIncludeExcludes
-                                RouteObjectIncludeExclude routeObjectIncludeExclude1 = addRouteObjectIncludeExclude(
-                                        ipAddress, 1, index);
-                                routeObjectIncludeExcludes.add(routeObjectIncludeExclude1);
-                                index++;
-                            }
-                            break;
-                        }
-                    }
-                } else {
-                    LOG.warn("node ID is null");
-                }
-            //TODO else if termination point not implemented in this version
-            } else if (listAtoZ.get(i).getResource()
-                    .getResource() instanceof org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
-                    .pathdescription.rev171017.pce.resource.resource.resource.Link) {
-                org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
-                    .resource.resource.resource.Link link = (org.opendaylight.yang.gen.v1.http.org.transportpce
-                            .b.c._interface.pathdescription.rev171017.pce.resource.resource.resource.Link) listAtoZ
-                        .get(i).getResource().getResource();
-                String clfi = mapLinkFiber.get(link.getLinkId());
-                IpAddress fiberIp = mapFiberIp.get(clfi);
-                if (clfi != null) {
-                    RouteObjectIncludeExclude routeObjectIncludeExclude1 = addRouteObjectIncludeExclude(fiberIp, 1,
-                            index);
-                    routeObjectIncludeExcludes.add(routeObjectIncludeExclude1);
-                    index++;
-                }
-            }
-        }
-        // Create ExplicitRouteObjects
-        ExplicitRouteObjects explicitRouteObjects = new ExplicitRouteObjectsBuilder()
-                .setRouteObjectIncludeExclude(routeObjectIncludeExcludes).build();
-
-        // 1. Create the path request element 1
-        // Find parameters
-        String sourceNode = input.getServiceAEnd().getNodeId();
-        String destNode = input.getServiceZEnd().getNodeId();
-
-        // 1.2 Create a path constraints
-        Long rate = atoz.getRate();
-        // Create EffectiveFreqSlot
-        List<EffectiveFreqSlot> effectiveFreqSlot = new ArrayList<>();
-        EffectiveFreqSlot effectiveFreqSlot1 = new EffectiveFreqSlotBuilder().setM(5).setN(8).build();
-        effectiveFreqSlot.add(effectiveFreqSlot1);
-        // Create Te-Bandwidth
-        TeBandwidth teBandwidth = new TeBandwidthBuilder().setPathBandwidth(new BigDecimal(rate))
-                .setTechnology("flexi-grid").setTrxType("openroadm-beta1").setTrxMode("W100G")
-                .setEffectiveFreqSlot(effectiveFreqSlot).setSpacing(new BigDecimal(50000000000.0)).build();
-        PathConstraints pathConstraints = new PathConstraintsBuilder().setTeBandwidth(teBandwidth).build();
-        PathRequest pathRequest1 = new PathRequestBuilder().setRequestId(requestId)
-                .setSource(mapNodeRefIp.get(sourceNode)).setDestination(mapNodeRefIp.get(destNode))
-                .setSrcTpId("srcTpId".getBytes()).setDstTpId("dstTpId".getBytes()).setPathConstraints(pathConstraints)
-                .setExplicitRouteObjects(explicitRouteObjects).build();
-        pathRequestList.add(pathRequest1);
-        return pathRequestList;
-    }
-
-    public List<PathRequest> extractPathRequest(PathComputationRequestInput input, ZToADirection ztoa, Long requestId) {
-        // List of A to Z
-        List<ZToA> listZToA = ztoa.getZToA();
-        int ztoaSize = listZToA.size();
-        // Create the path request
-        List<PathRequest> servicePathRequest = new ArrayList<>();
-
-        // 1.1 Create explicitRouteObjects
-        // 1.1.1. create RouteObjectIncludeExclude list
-        List<RouteObjectIncludeExclude> routeObjectIncludeExcludes = new ArrayList<>();
-        IpAddress ipAddressCurrent = null;
-        Long index = (long) 0;
-        for (int i = 0; i < ztoaSize; i++) {
-            String nodeId = null;
-            if (listZToA.get(i).getResource()
-                    .getResource() instanceof org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
-                    .pathdescription.rev171017.pce.resource.resource.resource.Node) {
-                org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
-                    .resource.resource.resource.Node node = (org.opendaylight.yang.gen.v1.http.org.transportpce.b.c
-                    ._interface.pathdescription.rev171017.pce.resource.resource.resource.Node) listZToA.get(i)
-                    .getResource().getResource();
-                nodeId = node.getNodeId();
-                if (nodeId != null) {
-                    String nodeRef = mapDisgNodeRefNode.get(nodeId);
-                    IpAddress ipAddress = mapNodeRefIp.get(nodeRef);
-                    for (Elements element : elements) {
-                        if (element.getUid().contains(ipAddress.getIpv4Address().getValue().toString())) {
-                            if ((ipAddressCurrent == null) || (!ipAddress.equals(ipAddressCurrent))) {
-                                ipAddressCurrent = ipAddress;
-                                // Fill in routeObjectIncludeExcludes
-                                RouteObjectIncludeExclude routeObjectIncludeExclude1 = addRouteObjectIncludeExclude(
-                                        ipAddress, 1, index);
-                                routeObjectIncludeExcludes.add(routeObjectIncludeExclude1);
-                                index++;
-                            }
-                            break;
-                        }
-                    }
-                } else {
-                    LOG.warn("node ID is null");
-                }
-            //TODO else if termination point not implemented in this version
-            } else if (listZToA.get(i).getResource()
-                    .getResource() instanceof org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
-                    .pathdescription.rev171017.pce.resource.resource.resource.Link) {
-                org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.pce
-                    .resource.resource.resource.Link link = (org.opendaylight.yang.gen.v1.http.org.transportpce
-                    .b.c._interface.pathdescription.rev171017.pce.resource.resource.resource.Link) listZToA.get(i)
-                    .getResource().getResource();
-                String clfi = mapLinkFiber.get(link.getLinkId());
-                IpAddress fiberIp = mapFiberIp.get(clfi);
-                if (clfi != null) {
-                    RouteObjectIncludeExclude routeObjectIncludeExclude1 = addRouteObjectIncludeExclude(fiberIp, 1,
-                            index);
-                    routeObjectIncludeExcludes.add(routeObjectIncludeExclude1);
-                    index++;
-                }
-            }
-        }
-        // Create ExplicitRouteObjects
-        ExplicitRouteObjects explicitRouteObjects = new ExplicitRouteObjectsBuilder()
-                .setRouteObjectIncludeExclude(routeObjectIncludeExcludes).build();
-
-        // 1. Create the path request element 1
-        // Find parameters
-        String sourceNode = input.getServiceZEnd().getNodeId();
-        String destNode = input.getServiceAEnd().getNodeId();
-
-        // 1.2 Create a path constraints
-        Long rate = ztoa.getRate();
-        // Create EffectiveFreqSlot
-        List<EffectiveFreqSlot> effectiveFreqSlot = new ArrayList<>();
-        EffectiveFreqSlot effectiveFreqSlot1 = new EffectiveFreqSlotBuilder().setM(5).setN(8).build();
-        effectiveFreqSlot.add(effectiveFreqSlot1);
-        // Create Te-Bandwidth
-        TeBandwidth teBandwidth = new TeBandwidthBuilder().setPathBandwidth(new BigDecimal(rate))
-                .setTechnology("flexi-grid").setTrxType("openroadm-beta1").setTrxMode("W100G")
-                .setEffectiveFreqSlot(effectiveFreqSlot).setSpacing(new BigDecimal(50000000000.0)).build();
-        PathConstraints pathConstraints = new PathConstraintsBuilder().setTeBandwidth(teBandwidth).build();
-        PathRequest pathRequest1 = new PathRequestBuilder().setRequestId(requestId)
-                .setSource(mapNodeRefIp.get(sourceNode)).setDestination(mapNodeRefIp.get(destNode))
-                .setSrcTpId("srcTpId".getBytes()).setDstTpId("dstTpId".getBytes()).setPathConstraints(pathConstraints)
-                .setExplicitRouteObjects(explicitRouteObjects).build();
-        servicePathRequest.add(pathRequest1);
-        return servicePathRequest;
-    }
-
-    /*
-     * Create the synchronization
-     */
-    public List<Synchronization> extractSynchronization(Long requestId) {
-        // Create RequestIdNumber
-        List<Long> requestIdNumber = new ArrayList<>();
-        requestIdNumber.add(requestId);
-        // Create a synchronization
-        Svec svec = new SvecBuilder().setRelaxable(true).setDisjointness(new TePathDisjointness(true, true, false))
-                .setRequestIdNumber(requestIdNumber).build();
-        List<Synchronization> synchro = new ArrayList<>();
-        Synchronization synchronization1 = new SynchronizationBuilder().setSynchronizationId(new Long(0)).setSvec(svec)
-                .build();
-        synchro.add(synchronization1);
-        return (synchro);
-    }
-
     /*
      * Method to add Fiber
      */
@@ -668,23 +420,6 @@ public class ExtractTopoDataStoreImpl {
         return element1;
     }
 
-    /*
-     * Add routeObjectIncludeExclude
-     */
-    private RouteObjectIncludeExclude addRouteObjectIncludeExclude(IpAddress ipAddress, long teTpValue, long index) {
-        TeNodeId teNodeId = new TeNodeId(ipAddress);
-        TeTpId teTpId = new TeTpId(teTpValue);
-        NumUnnumHop numUnnumHop = new org.opendaylight.yang.gen.v1.gnpy.path.rev190502.explicit.route.hop.type.num
-            .unnum.hop.NumUnnumHopBuilder()
-            .setNodeId(teNodeId.getIpv4Address().getValue().toString()).setLinkTpId(teTpId.getUint32().toString())
-            .setHopType(TeHopType.STRICT).build();
-        Type type1 = new NumUnnumHopBuilder().setNumUnnumHop(numUnnumHop).build();
-        // Create routeObjectIncludeExclude element 1
-        RouteObjectIncludeExclude routeObjectIncludeExclude1 = new RouteObjectIncludeExcludeBuilder().setIndex(index)
-                .setExplicitRouteUsage(RouteIncludeEro.class).setType(type1).build();
-        return routeObjectIncludeExclude1;
-    }
-
     private Connections createNewConnection(String srcId, IpAddress srcIp, String destId, IpAddress destIp) {
         String fromNode = srcId;
         String toNode = destId;
@@ -714,50 +449,35 @@ public class ExtractTopoDataStoreImpl {
         this.connections = connections;
     }
 
-    public List<PathRequest> getPathRequest() {
-        return pathRequest;
+    public Map<String, String> getMapDisgNodeRefNode() {
+        return mapDisgNodeRefNode;
     }
 
-    public void setPathRequest(List<PathRequest> pathRequest) {
-        this.pathRequest = pathRequest;
+    public void setMapDisgNodeRefNode(Map<String, String> mapDisgNodeRefNode) {
+        this.mapDisgNodeRefNode = mapDisgNodeRefNode;
     }
 
-    public List<Synchronization> getSynchronization() {
-        return synchronization;
+    public Map<String, IpAddress> getMapNodeRefIp() {
+        return mapNodeRefIp;
     }
 
-    public void setSynchronization(List<Synchronization> synchronization) {
-        this.synchronization = synchronization;
+    public void setMapNodeRefIp(Map<String, IpAddress> mapNodeRefIp) {
+        this.mapNodeRefIp = mapNodeRefIp;
     }
 
-    public List<PathRequest> createEmptyPathRequest(PathComputationRequestInput input, AToZDirection atoz) {
-        // Create the path request
-        List<PathRequest> pathRequestList = new ArrayList<>();
-
-        // 1. Create the path request element 1
-        // Find parameters
-        String sourceNode = input.getServiceAEnd().getNodeId();
-        String destNode = input.getServiceZEnd().getNodeId();
-
-        // 1.2 Create a path constraints
-        Long rate = atoz.getRate();
+    public Map<String, String> getMapLinkFiber() {
+        return mapLinkFiber;
+    }
 
-        // Create EffectiveFreqSlot
-        List<EffectiveFreqSlot> effectiveFreqSlot = new ArrayList<>();
-        EffectiveFreqSlot effectiveFreqSlot1 = new EffectiveFreqSlotBuilder().setM(5).setN(8).build();
-        effectiveFreqSlot.add(effectiveFreqSlot1);
+    public void setMapLinkFiber(Map<String, String> mapLinkFiber) {
+        this.mapLinkFiber = mapLinkFiber;
+    }
 
-        // Create Te-Bandwidth
-        TeBandwidth teBandwidth = new TeBandwidthBuilder().setPathBandwidth(new BigDecimal(rate))
-                .setTechnology("flexi-grid").setTrxType("openroadm-beta1").setTrxMode("W100G")
-                .setEffectiveFreqSlot(effectiveFreqSlot).setSpacing(new BigDecimal(50000000000.0)).build();
-        PathConstraints pathConstraints = new PathConstraintsBuilder().setTeBandwidth(teBandwidth).build();
-        PathRequest pathRequest1 = new PathRequestBuilder().setRequestId(new Long(0))
-                .setSource(mapNodeRefIp.get(sourceNode)).setDestination(mapNodeRefIp.get(destNode))
-                .setSrcTpId("srcTpId".getBytes()).setDstTpId("dstTpId".getBytes()).setPathConstraints(pathConstraints)
-                .build();
-        pathRequestList.add(pathRequest1);
-        return pathRequestList;
+    public Map<String, IpAddress> getMapFiberIp() {
+        return mapFiberIp;
     }
 
-}
+    public void setMapFiberIp(Map<String, IpAddress> mapFiberIp) {
+        this.mapFiberIp = mapFiberIp;
+    }
+}
\ No newline at end of file
diff --git a/pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/GnpyUtilitiesImpl.java b/pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/GnpyUtilitiesImpl.java
new file mode 100644 (file)
index 0000000..a850db0
--- /dev/null
@@ -0,0 +1,171 @@
+/*
+ * Copyright © 2018 Orange, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.transportpce.pce.gnpy;
+
+import java.util.List;
+
+import org.opendaylight.transportpce.common.network.NetworkTransactionService;
+import org.opendaylight.transportpce.pce.constraints.PceConstraints;
+import org.opendaylight.yang.gen.v1.gnpy.gnpy.api.rev190103.GnpyApi;
+import org.opendaylight.yang.gen.v1.gnpy.gnpy.api.rev190103.GnpyApiBuilder;
+import org.opendaylight.yang.gen.v1.gnpy.gnpy.api.rev190103.gnpy.api.ServiceFileBuilder;
+import org.opendaylight.yang.gen.v1.gnpy.gnpy.api.rev190103.gnpy.api.TopologyFileBuilder;
+import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.topo.Connections;
+import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev181214.topo.Elements;
+import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.generic.path.properties.path.properties.PathRouteObjects;
+import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.service.PathRequest;
+import org.opendaylight.yang.gen.v1.gnpy.path.rev190502.synchronization.info.Synchronization;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev190624.PathComputationRequestInput;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.AToZDirection;
+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.ZToADirection;
+import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.routing.constraints.sp.HardConstraints;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Class that implements the functions asked to gnpy.
+ *
+ * @author Ahmed Triki ( ahmed.triki@orange.com )
+ *
+ */
+
+public class GnpyUtilitiesImpl {
+
+    private static final Logger LOG = LoggerFactory.getLogger(GnpyResult.class);
+    private NetworkTransactionService networkTransaction;
+    private PathComputationRequestInput input;
+    private GnpyTopoImpl gnpyTopo = null;
+    private GnpyResult gnpyAtoZ;
+    private GnpyResult gnpyZtoA;
+    private Long requestId;
+
+    public GnpyUtilitiesImpl(NetworkTransactionService networkTransaction, PathComputationRequestInput input) {
+        this.networkTransaction = networkTransaction;
+        this.gnpyTopo = new GnpyTopoImpl(networkTransaction);
+        this.input = input;
+        this.gnpyAtoZ = null;
+        this.gnpyZtoA = null;
+        this.requestId = (long) 0;
+    }
+
+    public boolean verifyComputationByGnpy(AToZDirection atoz, ZToADirection ztoa, PceConstraints pceHardConstraints)
+        throws Exception {
+        boolean isPcePathFeasible = false;
+        List<Elements> elementsList = gnpyTopo.getElements();
+        List<Connections> connectionsList = gnpyTopo.getConnections();
+
+        if (atoz == null || atoz.getAToZ() == null) {
+            LOG.error("In pceSendingPceRPC: empty atoz path");
+        } else {
+            GnpyServiceImpl gnpySvc = new GnpyServiceImpl(input, atoz, requestId, gnpyTopo, pceHardConstraints);
+            requestId++;
+            List<PathRequest> pathRequestList1 = gnpySvc.getPathRequest();
+            List<Synchronization> synchronizationList1 = gnpySvc.getSynchronization();
+            // Send the computed path A-to-Z to GNPY tool
+            String gnpyResponse1 = getGnpyResponse(elementsList, connectionsList, pathRequestList1,
+                synchronizationList1);
+            // Analyze the response
+            if (gnpyResponse1 != null) {
+                GnpyResult result = new GnpyResult(gnpyResponse1, gnpyTopo);
+                result.analyzeResult();
+                this.gnpyAtoZ = result;
+                isPcePathFeasible = this.gnpyAtoZ.getPathFeasibility();
+            } else {
+                LOG.error("No response from the GNPy server");
+            }
+        }
+
+        if (ztoa == null || ztoa.getZToA() == null) {
+            LOG.error("In pceSendingPceRPC: empty ztoa path");
+            isPcePathFeasible = false;
+        } else {
+            GnpyServiceImpl gnpySvc = new GnpyServiceImpl(input, ztoa, requestId, gnpyTopo, pceHardConstraints);
+            requestId++;
+            List<PathRequest> pathRequestList2 = gnpySvc.getPathRequest();
+            List<Synchronization> synchronizationList2 = gnpySvc.getSynchronization();
+            // Send the computed path Z-to-A to GNPY tool
+            String gnpyResponse2 = getGnpyResponse(elementsList, connectionsList, pathRequestList2,
+                synchronizationList2);
+            // Analyze the response
+            if (gnpyResponse2 != null) {
+                GnpyResult result = new GnpyResult(gnpyResponse2, gnpyTopo);
+                result.analyzeResult();
+                this.gnpyZtoA = result;
+                isPcePathFeasible &= this.gnpyZtoA.getPathFeasibility();
+            } else {
+                LOG.error("No response from the GNPy server");
+            }
+        }
+        return isPcePathFeasible;
+    }
+
+    public HardConstraints askNewPathFromGnpy(AToZDirection atoz, ZToADirection ztoa,
+        HardConstraints gnpyPathAsHC, PceConstraints pceHardConstraints) throws Exception {
+        boolean isPcePathFeasible = false;
+        List<Elements> elementsList = gnpyTopo.getElements();
+        List<Connections> connectionsList = gnpyTopo.getConnections();
+
+        // Ask a new path A-to-Z
+        if (atoz.getAToZWavelengthNumber() == null) {
+            LOG.info("The wavelength is null!");
+        }
+
+        AToZDirection atoztmp = new AToZDirectionBuilder().setRate(atoz.getRate())
+            .setAToZ(null).build();
+        GnpyServiceImpl gnpySvc = new GnpyServiceImpl(input, atoztmp, requestId, gnpyTopo, pceHardConstraints);
+        requestId++;
+        List<PathRequest> pathRequestList1 = gnpySvc.getPathRequest();
+        List<Synchronization> synchronizationList1 = gnpySvc.getSynchronization();
+
+        // Send the computed path A-to-Z to GNPY tool
+        String gnpyResponse1 = getGnpyResponse(elementsList, connectionsList, pathRequestList1, synchronizationList1);
+        // Analyze the response
+        if (gnpyResponse1 != null) {
+            GnpyResult result = new GnpyResult(gnpyResponse1, gnpyTopo);
+            LOG.debug("GNPy result created");
+            isPcePathFeasible = result.getPathFeasibility();
+            this.gnpyAtoZ = result;
+            if (isPcePathFeasible) {
+                List<PathRouteObjects> pathRouteObjectList = result.analyzeResult();
+                gnpyPathAsHC = result.computeHardConstraintsFromGnpyPath(pathRouteObjectList);
+            }
+        } else {
+            LOG.error("No response from the GNPy server");
+        }
+        return gnpyPathAsHC;
+    }
+
+    public String getGnpyResponse(List<Elements> elementsList, List<Connections> connectionsList,
+        List<PathRequest> pathRequestList, List<Synchronization> synchronizationList) throws Exception {
+        GnpyApi gnpyApi = new GnpyApiBuilder()
+            .setTopologyFile(
+                new TopologyFileBuilder().setElements(elementsList).setConnections(connectionsList).build())
+            .setServiceFile(new ServiceFileBuilder().setPathRequest(pathRequestList).build()).build();
+        InstanceIdentifier<GnpyApi> idGnpyApi = InstanceIdentifier.builder(GnpyApi.class).build();
+        String gnpyJson;
+        ServiceDataStoreOperationsImpl sd = new ServiceDataStoreOperationsImpl(networkTransaction);
+        gnpyJson = sd.createJsonStringFromDataObject(idGnpyApi, gnpyApi);
+        LOG.debug("GNPy Id: {} / json created : {}", idGnpyApi, gnpyJson);
+        ConnectToGnpyServer connect = new ConnectToGnpyServer();
+        String gnpyJsonModified = gnpyJson.replace("gnpy-eqpt-config:", "")
+            .replace("gnpy-path-computation-simplified:", "").replace("gnpy-network-topology:", "");
+        String gnpyResponse = connect.gnpyCnx(gnpyJsonModified);
+        return gnpyResponse;
+    }
+
+    public GnpyResult getGnpyAtoZ() {
+        return gnpyAtoZ;
+    }
+
+    public GnpyResult getGnpyZtoA() {
+        return gnpyZtoA;
+    }
+}
index 3910c996c503b8bfa891082160b0d3e2b2cf122d..6d4343627d9af3fab1db00184af43639b5237314 100644 (file)
@@ -19,13 +19,9 @@ import java.io.Writer;
 import java.util.Collections;
 import java.util.Optional;
 
-import javassist.ClassPool;
-
-import org.opendaylight.mdsal.binding.dom.codec.gen.impl.StreamWriterGenerator;
 import org.opendaylight.mdsal.binding.dom.codec.impl.BindingNormalizedNodeCodecRegistry;
 import org.opendaylight.mdsal.binding.generator.impl.ModuleInfoBackedContext;
 import org.opendaylight.mdsal.binding.generator.util.BindingRuntimeContext;
-import org.opendaylight.mdsal.binding.generator.util.JavassistUtils;
 import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
 import org.opendaylight.transportpce.common.DataStoreContext;
 import org.opendaylight.transportpce.common.converter.XMLDataObjectConverter;
@@ -80,8 +76,6 @@ public class ServiceDataStoreOperationsImpl implements ServiceDataStoreOperation
 
     public String createJsonStringFromDataObject(final InstanceIdentifier<?> id, DataObject object) throws Exception {
 
-        // See this link for more info :
-        // https://github.com/opendaylight/fpc/blob/master/impl/src/main/java/org/opendaylight/fpc/utils/FpcCodecUtils.java
         final SchemaPath scPath = SchemaPath
                 .create(FluentIterable.from(id.getPathArguments()).transform(new Function<PathArgument, QName>() {
                     @Override
@@ -101,10 +95,8 @@ public class ServiceDataStoreOperationsImpl implements ServiceDataStoreOperation
             SchemaContext schemaContext = moduleContext.tryToCreateSchemaContext().get();
             BindingRuntimeContext bindingContext;
             bindingContext = BindingRuntimeContext.create(moduleContext, schemaContext);
-            final BindingNormalizedNodeCodecRegistry bindingStreamCodecs = new BindingNormalizedNodeCodecRegistry(
-                    StreamWriterGenerator.create(JavassistUtils.forClassPool(ClassPool.getDefault())));
-            bindingStreamCodecs.onBindingRuntimeContextUpdated(bindingContext);
-            BindingNormalizedNodeCodecRegistry codecRegistry = bindingStreamCodecs;
+            final BindingNormalizedNodeCodecRegistry codecRegistry =
+                new BindingNormalizedNodeCodecRegistry(bindingContext);
 
             /*
              * This function needs : - context - scPath.getParent() -
@@ -118,6 +110,7 @@ public class ServiceDataStoreOperationsImpl implements ServiceDataStoreOperation
             // The write part
             final BindingStreamEventWriter bindingWriter = codecRegistry.newWriter(id, domWriter);
             codecRegistry.getSerializer(id.getTargetType()).serialize(object, bindingWriter);
+            domWriter.close();
             writer.close();
         } catch (IOException e) {
             LOG.error("GNPy: writer error ");
index 484da76953d8b1503a35b5b233f3bb45c07aabba..f4132e04cc37ba2efac2b76e09faf5a829e5d3d9 100644 (file)
@@ -138,7 +138,6 @@ public class PceGraph {
         // KShortestPaths on weightedGraph
         KShortestSimplePaths<String, PceGraphEdge> swp =
             new KShortestSimplePaths<String, PceGraphEdge>(weightedGraph, mhopsPerPath, wpv);
-
         allWPaths = swp.getPaths(apceNode.getNodeId().getValue(), zpceNode.getNodeId().getValue(), kpathsToBring);
 
         if (allWPaths.isEmpty()) {
@@ -152,7 +151,6 @@ public class PceGraph {
         for (GraphPath<String, PceGraphEdge> path : allWPaths) {
             LOG.info("path Weight: {} : {}", path.getWeight(), path.getVertexList().toString());
         }
-        // debug print
 
         return true;
     }
@@ -170,10 +168,8 @@ public class PceGraph {
             LOG.error("In addLinkToGraph link dest node is null : {}", pcelink.toString());
             return false;
         }
-
         LOG.debug("In addLinkToGraph link to nodes : {}{} {}", pcelink.toString(), source.toString(), dest.toString());
         return true;
-
     }
 
     private void populateWithNodes(DefaultDirectedWeightedGraph<String, PceGraphEdge> weightedGraph) {
index 21e68ee7217ab28f19d95ce82009b2e69248463d..08de48d1af5bfcfebb1d99aded882911ddba4d46 100644 (file)
@@ -66,7 +66,7 @@ public class PceCalculation {
 
     // this List serves graph calculation
     private Map<NodeId, PceNode> allPceNodes = new HashMap<NodeId, PceNode>();
-    // this List serves calculation of ZtoA path descritopn
+    // this List serves calculation of ZtoA path description
     // TODO maybe better solution is possible
     private Map<LinkId, PceLink> allPceLinks = new HashMap<LinkId, PceLink>();
     private Set<LinkId> linksToExclude = new HashSet<LinkId>();
@@ -395,7 +395,7 @@ public class PceCalculation {
 
     private ConstraintTypes validateNodeConstraints(PceNode pcenode) {
 
-        if (pceHardConstraints.getExcludeSupNodes().isEmpty()  && pceHardConstraints.getExcludeCLLI().isEmpty()) {
+        if (pceHardConstraints.getExcludeSupNodes().isEmpty() && pceHardConstraints.getExcludeCLLI().isEmpty()) {
             return ConstraintTypes.NONE;
         }
 
index e733599b053eec0a12fa3136eb0807dc960fcded..5c0579d6698991c1b0521cbec873fd2a44a01178 100644 (file)
@@ -157,6 +157,21 @@ public class PathComputationServiceImpl implements PathComputationService {
                 PathDescriptionBuilder path = null;
                 path = sendingPCE.getPathDescription();
                 LOG.info("PCE response: {} {}", message, responseCode);
+
+                //add the GNPy result
+                GnpyResult gnpyAtoZ = sendingPCE.getGnpyAtoZ();
+                GnpyResult gnpyZtoA = sendingPCE.getGnpyZtoA();
+                List<GnpyResponse> listResponse = new ArrayList<>();
+                if (gnpyAtoZ != null) {
+                    GnpyResponse respAtoZ = generateGnpyResponse(gnpyAtoZ.getResponse(),"A-to-Z");
+                    listResponse.add(respAtoZ);
+                }
+                if (gnpyZtoA != null) {
+                    GnpyResponse respZtoA = generateGnpyResponse(gnpyZtoA.getResponse(),"Z-to-A");
+                    listResponse.add(respZtoA);
+                }
+                output.setGnpyResponse(listResponse);
+
                 if (!(sendingPCE.getSuccess()) || (path == null)) {
                     configurationResponseCommon.setAckFinalIndicator("Yes")
                             .setRequestId(input.getServiceHandlerHeader().getRequestId()).setResponseCode(responseCode)
@@ -186,20 +201,6 @@ public class PathComputationServiceImpl implements PathComputationService {
                 output.setConfigurationResponseCommon(configurationResponseCommon.build())
                         .setResponseParameters(rpb.build());
 
-              //add the GNPy result
-                GnpyResult gnpyAtoZ = sendingPCE.getGnpyAtoZ();
-                GnpyResult gnpyZtoA = sendingPCE.getGnpyZtoA();
-                List<GnpyResponse> listResponse = new ArrayList<>();
-                if (gnpyAtoZ != null) {
-                    GnpyResponse respAtoZ = generateGnpyResponse(gnpyAtoZ.getResponse(),"A-to-Z");
-                    listResponse.add(respAtoZ);
-                }
-                if (gnpyZtoA != null) {
-                    GnpyResponse respZtoA = generateGnpyResponse(gnpyZtoA.getResponse(),"Z-to-A");
-                    listResponse.add(respZtoA);
-                }
-                output.setGnpyResponse(listResponse);
-
                 //debug prints
                 AToZDirection atoz = pathDescription.getAToZDirection();
                 if ((atoz != null) && (atoz.getAToZ() != null)) {
@@ -226,6 +227,7 @@ public class PathComputationServiceImpl implements PathComputationService {
         if (responseGnpy != null) {
             if (responseGnpy.getResponseType() instanceof org.opendaylight.yang.gen.v1.gnpy.path.rev190502.result
                     .response.response.type.NoPathCase) {
+                LOG.info("GNPy : path is not feasible");
                 org.opendaylight.yang.gen.v1.gnpy.path.rev190502.result.response.response.type.NoPathCase
                     noPathGnpy = (org.opendaylight.yang.gen.v1.gnpy.path.rev190502.result.response.response.type
                     .NoPathCase) responseGnpy.getResponseType();