- 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(dataBroker);
- 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 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();
+
+ AToZDirection atoz = null;
+ ZToADirection ztoa = null;
+ if (rc.getStatus()) {
+ atoz = rc.getAtoZDirection();
+ ztoa = rc.getZtoADirection();
+ }
+
+ //Connect to Gnpy to check path feasibility and recompute another path in case of path non-feasibility
+ try {
+ ConnectToGnpyServer connectToGnpy = new ConnectToGnpyServer();
+ if (connectToGnpy.isGnpyURLExist()) {
+ GnpyUtilitiesImpl gnpy = new GnpyUtilitiesImpl(networkTransaction, input,
+ bindingDOMCodecServices);
+ if (rc.getStatus() && gnpyToCheckFeasiblity(atoz,ztoa,gnpy)) {
+ setPathDescription(new PathDescriptionBuilder().setAToZDirection(atoz).setZToADirection(ztoa));
+ return;
+ }
+ callGnpyToComputeNewPath(gnpy);
+ } else {
+ setPathDescription(new PathDescriptionBuilder().setAToZDirection(atoz).setZToADirection(ztoa));
+ }
+ }
+ catch (GnpyException e) {
+ LOG.error("Exception raised by GNPy {}",e.getMessage());
+ setPathDescription(new PathDescriptionBuilder().setAToZDirection(atoz).setZToADirection(ztoa));
+ }
+ }
+
+ private boolean gnpyToCheckFeasiblity(AToZDirection atoz, ZToADirection ztoa, GnpyUtilitiesImpl gnpy)
+ throws GnpyException {
+
+ //Call GNPy for path verification
+ if (gnpy.verifyComputationByGnpy(atoz, ztoa, pceHardConstraints)) {
+ LOG.info("In pceSendingPceRPC: the path is feasible according to Gnpy");
+ gnpyAtoZ = gnpy.getGnpyAtoZ();
+ gnpyZtoA = gnpy.getGnpyZtoA();
+ return true;
+ }
+ return false;
+ }
+
+ private void callGnpyToComputeNewPath(GnpyUtilitiesImpl gnpy) throws GnpyException {
+
+ //Call GNPy in the case of non feasibility
+ LOG.info("In pceSendingPceRPC: the path is not feasible according to Gnpy");
+ HardConstraints gnpyPathAsHC = null;
+ gnpyPathAsHC = gnpy.askNewPathFromGnpy(pceHardConstraints);
+ if (gnpyPathAsHC == null) {
+ LOG.info("In pceSendingPceRPC: 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();
+ return;
+ }
+
+ LOG.info("In pceSendingPceRPC: 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);
+ AToZDirection atoz = rc.getAtoZDirection();
+ ZToADirection ztoa = rc.getZtoADirection();
+ if (gnpyToCheckFeasiblity(atoz, ztoa,gnpy)) {
+ LOG.info("In pceSendingPceRPC: the new path computed by GNPy is valid");
+ this.success = true;
+ this.message = "Path is calculated by GNPy";
+ this.responseCode = ResponseCodes.RESPONSE_OK;
+ setPathDescription(new PathDescriptionBuilder().setAToZDirection(atoz).setZToADirection(ztoa));
+ } else {
+ LOG.info("In pceSendingPceRPC: the new path computed by GNPy is not valid");
+ this.success = false;
+ this.message = "No path available";
+ this.responseCode = ResponseCodes.RESPONSE_FAILED;
+ setPathDescription(new PathDescriptionBuilder().setAToZDirection(null).setZToADirection(null));
+ }