X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=pce%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Ftransportpce%2Fpce%2Fservice%2FPathComputationServiceImpl.java;h=3d34aa1d2d9bd5dabd6af21df692a334b605a19f;hb=703ea2446974f96c2b57cd96c2d55edd4b3f99b2;hp=e93ea094ba9625ecfe8b0054dcdfa34f2a75a2f7;hpb=0779ad5796bb645690874959c9a891c42e2f7175;p=transportpce.git diff --git a/pce/src/main/java/org/opendaylight/transportpce/pce/service/PathComputationServiceImpl.java b/pce/src/main/java/org/opendaylight/transportpce/pce/service/PathComputationServiceImpl.java index e93ea094b..3d34aa1d2 100644 --- a/pce/src/main/java/org/opendaylight/transportpce/pce/service/PathComputationServiceImpl.java +++ b/pce/src/main/java/org/opendaylight/transportpce/pce/service/PathComputationServiceImpl.java @@ -7,199 +7,383 @@ */ package org.opendaylight.transportpce.pce.service; -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.ListeningExecutorService; +import com.google.common.util.concurrent.MoreExecutors; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.Callable; +import java.util.concurrent.Executors; +import java.util.stream.Collectors; +import org.opendaylight.mdsal.binding.api.NotificationPublishService; +import org.opendaylight.transportpce.common.mapping.PortMapping; +import org.opendaylight.transportpce.common.network.NetworkTransactionService; import org.opendaylight.transportpce.pce.PceComplianceCheck; import org.opendaylight.transportpce.pce.PceComplianceCheckResult; import org.opendaylight.transportpce.pce.PceSendingPceRPCs; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.CancelResourceReserveInput; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.CancelResourceReserveOutput; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.CancelResourceReserveOutputBuilder; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.PathComputationRequestInput; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.PathComputationRequestOutput; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.PathComputationRequestOutputBuilder; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.ServicePathRpcResult; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.ServicePathRpcResultBuilder; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.service.path.rpc.result.PathDescription; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.service.path.rpc.result.PathDescriptionBuilder; -import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.configuration.response.common.ConfigurationResponseCommonBuilder; -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.service.types.rev171016.RpcStatusEx; -import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.ServicePathNotificationTypes; -import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev171016.response.parameters.sp.ResponseParametersBuilder; +import org.opendaylight.transportpce.pce.gnpy.GnpyResult; +import org.opendaylight.transportpce.pce.gnpy.consumer.GnpyConsumer; +import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.result.Response; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.CancelResourceReserveInput; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.CancelResourceReserveOutput; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.CancelResourceReserveOutputBuilder; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRequestInput; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRequestInputBuilder; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRequestOutput; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRequestOutputBuilder; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRerouteRequestInput; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRerouteRequestOutput; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRerouteRequestOutputBuilder; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.ServicePathRpcResult; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.ServicePathRpcResultBuilder; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.gnpy.GnpyResponse; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.gnpy.GnpyResponseBuilder; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.gnpy.gnpy.response.response.type.NoPathCaseBuilder; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.gnpy.gnpy.response.response.type.PathCaseBuilder; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.path.computation.request.input.ServiceAEndBuilder; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.path.computation.request.input.ServiceZEndBuilder; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.path.performance.PathPropertiesBuilder; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.path.performance.path.properties.PathMetric; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.path.performance.path.properties.PathMetricBuilder; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.service.path.rpc.result.PathDescription; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.service.path.rpc.result.PathDescriptionBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.configuration.response.common.ConfigurationResponseCommonBuilder; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.AToZDirection; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.ZToADirection; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.RpcStatusEx; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.ServicePathNotificationTypes; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.response.parameters.sp.ResponseParametersBuilder; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.service.handler.header.ServiceHandlerHeaderBuilder; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@Component(immediate = true) public class PathComputationServiceImpl implements PathComputationService { private static final Logger LOG = LoggerFactory.getLogger(PathComputationServiceImpl.class); - private final NotificationPublishService notificationPublishService; - private final DataBroker dataBroker; + private NetworkTransactionService networkTransactionService; + private final ListeningExecutorService executor; + private ServicePathRpcResult notification = null; + private final GnpyConsumer gnpyConsumer; + private PortMapping portMapping; - public PathComputationServiceImpl(DataBroker dataBroker, - NotificationPublishService notificationPublishService) { + @Activate + public PathComputationServiceImpl(@Reference NetworkTransactionService networkTransactionService, + @Reference NotificationPublishService notificationPublishService, + @Reference GnpyConsumer gnpyConsumer, + @Reference PortMapping portMapping) { this.notificationPublishService = notificationPublishService; - this.dataBroker = dataBroker; - } - - public void init() { - LOG.info("init ..."); + this.networkTransactionService = networkTransactionService; + this.executor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(5)); + this.gnpyConsumer = gnpyConsumer; + this.portMapping = portMapping; + LOG.info("PathComputationServiceImpl instantiated"); } - public void close() { - LOG.info("close."); - } - - @Override - public CancelResourceReserveOutput cancelResourceReserve(CancelResourceReserveInput input) { - LOG.info("cancelResourceReserve"); - String message = ""; - - ServicePathRpcResult notification = new ServicePathRpcResultBuilder() - .setNotificationType(ServicePathNotificationTypes.CancelResourceReserve) - .setServiceName(input.getServiceName()) - .setStatus(RpcStatusEx.Pending) - .setStatusMessage("Service compliant, submitting cancelResourceReserve Request ...") - .build(); + @SuppressFBWarnings( + value = "UPM_UNCALLED_PRIVATE_METHOD", + justification = "false positive, this method is used by public method cancelResourceReserve") + private void sendNotifications( + ServicePathNotificationTypes servicePathNotificationTypes, + String serviceName, + RpcStatusEx rpcStatusEx, + String message, + PathDescription pathDescription) { + ServicePathRpcResultBuilder servicePathRpcResultBuilder = + new ServicePathRpcResultBuilder() + .setNotificationType(servicePathNotificationTypes) + .setServiceName(serviceName) + .setStatus(rpcStatusEx) + .setStatusMessage(message); + if (pathDescription != null) { + servicePathRpcResultBuilder.setPathDescription(pathDescription); + } + this.notification = servicePathRpcResultBuilder.build(); try { - notificationPublishService.putNotification(notification); + notificationPublishService.putNotification(this.notification); } catch (InterruptedException e) { - LOG.info("notification offer rejected : ", e.getMessage()); + LOG.info("notification offer rejected: ", e); } - - PceSendingPceRPCs sendingPCE = new PceSendingPceRPCs(); - sendingPCE.cancelResourceReserve(); - if (sendingPCE.getSuccess()) { - message = "ResourceReserve cancelled !"; - } else { - message = "Cancelling ResourceReserve failed !"; - } - LOG.info(message); - ConfigurationResponseCommonBuilder configurationResponseCommon = new ConfigurationResponseCommonBuilder(); - configurationResponseCommon - .setAckFinalIndicator("Yes") - .setRequestId(input.getServiceHandlerHeader().getRequestId()) - .setResponseCode("200") - .setResponseMessage("") - .setResponseMessage(message); - CancelResourceReserveOutputBuilder output = new CancelResourceReserveOutputBuilder(); - output.setConfigurationResponseCommon(configurationResponseCommon.build()); - return output.build(); } @Override - public PathComputationRequestOutput pathComputationRequest(PathComputationRequestInput input) { - LOG.info("pathComputationRequest"); - - PathComputationRequestOutputBuilder output = new PathComputationRequestOutputBuilder(); - ConfigurationResponseCommonBuilder configurationResponseCommon = new ConfigurationResponseCommonBuilder(); - - PceComplianceCheckResult check = PceComplianceCheck.check(input); - if (!check.hasPassed()) { - configurationResponseCommon - .setAckFinalIndicator("Yes") - .setRequestId(input.getServiceHandlerHeader().getRequestId()) - .setResponseCode("Path not calculated") - .setResponseMessage(check.getMessage()); - - - output.setConfigurationResponseCommon(configurationResponseCommon.build()) - .setResponseParameters(null); + public ListenableFuture cancelResourceReserve(CancelResourceReserveInput input) { + LOG.info("cancelResourceReserve"); + return executor.submit(new Callable() { - return output.build(); - } - ServicePathRpcResult notification = new ServicePathRpcResultBuilder() - .setNotificationType(ServicePathNotificationTypes.PathComputationRequest) - .setServiceName(input.getServiceName()) - .setStatus(RpcStatusEx.Pending) - .setStatusMessage("Service compliant, submitting pathComputation Request ...") - .build(); - try { - notificationPublishService.putNotification(notification); - } catch (InterruptedException e) { - LOG.info("notification offer rejected : ", e.getMessage()); - } + @Override + public CancelResourceReserveOutput call() throws Exception { + sendNotifications( + ServicePathNotificationTypes.CancelResourceReserve, + input.getServiceName(), + RpcStatusEx.Pending, + "Service compliant, submitting cancelResourceReserve Request ...", + null); + PceSendingPceRPCs sendingPCE = new PceSendingPceRPCs(gnpyConsumer); + sendingPCE.cancelResourceReserve(); + LOG.info("in PathComputationServiceImpl : {}", + Boolean.TRUE.equals(sendingPCE.getSuccess()) + ? "ResourceReserve cancelled !" + : "Cancelling ResourceReserve failed !"); + sendNotifications( + ServicePathNotificationTypes.CancelResourceReserve, + input.getServiceName(), + RpcStatusEx.Successful, + "cancel Resource Reserve successful!", + null); + return new CancelResourceReserveOutputBuilder() + .setConfigurationResponseCommon( + new ConfigurationResponseCommonBuilder() + .setAckFinalIndicator("Yes") + .setRequestId(input.getServiceHandlerHeader().getRequestId()) + .setResponseCode("200") + .setResponseMessage("") + .build()) + .build(); + } + }); + } - String message = ""; - String responseCode = ""; - PceSendingPceRPCs sendingPCE = new PceSendingPceRPCs(input, dataBroker); - sendingPCE.pathComputation(); - message = sendingPCE.getMessage(); - responseCode = sendingPCE.getResponseCode(); - PathDescriptionBuilder path = null; - path = sendingPCE.getPathDescription(); + @Override + public ListenableFuture pathComputationRequest(PathComputationRequestInput input) { + LOG.debug("input parameters are : input = {}", input.toString()); + return executor.submit(new Callable() { + @Override + public PathComputationRequestOutput call() throws Exception { + PathComputationRequestOutputBuilder output = new PathComputationRequestOutputBuilder(); + ConfigurationResponseCommonBuilder configurationResponseCommon = + new ConfigurationResponseCommonBuilder(); + PceComplianceCheckResult check = PceComplianceCheck.check(input); + if (!check.hasPassed()) { + LOG.error("Path not calculated, service not compliant : {}", check.getMessage()); + sendNotifications( + ServicePathNotificationTypes.PathComputationRequest, + input.getServiceName(), + RpcStatusEx.Failed, + "Path not calculated, service not compliant", + null); + configurationResponseCommon + .setAckFinalIndicator("Yes") + .setRequestId(input.getServiceHandlerHeader().getRequestId()) + .setResponseCode("Path not calculated") + .setResponseMessage(check.getMessage()); + return output + .setConfigurationResponseCommon(configurationResponseCommon.build()) + .setResponseParameters(null) + .build(); + } + sendNotifications( + ServicePathNotificationTypes.PathComputationRequest, + input.getServiceName(), + RpcStatusEx.Pending, + "Service compliant, submitting pathComputation Request ...", + null); + PceSendingPceRPCs sendingPCE = + new PceSendingPceRPCs(input, networkTransactionService, gnpyConsumer, portMapping); + sendingPCE.pathComputation(); + String message = sendingPCE.getMessage(); + String responseCode = sendingPCE.getResponseCode(); + LOG.info("PCE response: {} {}", message, responseCode); - LOG.info("PCE response: {} {}", message, responseCode); - if ((sendingPCE.getSuccess() == false) || (path == null)) { - configurationResponseCommon - .setAckFinalIndicator("Yes") - .setRequestId(input.getServiceHandlerHeader().getRequestId()) - .setResponseCode(responseCode) - .setResponseMessage(message); + //add the GNPy result + GnpyResult gnpyAtoZ = sendingPCE.getGnpyAtoZ(); + GnpyResult gnpyZtoA = sendingPCE.getGnpyZtoA(); + List 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.stream() + .collect(Collectors.toMap(GnpyResponse::key, gnpyResponse -> gnpyResponse))); - output.setConfigurationResponseCommon(configurationResponseCommon.build()); - return output.build(); - } + PathDescriptionBuilder path = sendingPCE.getPathDescription(); + if (Boolean.FALSE.equals(sendingPCE.getSuccess()) || (path == null)) { + sendNotifications( + ServicePathNotificationTypes.PathComputationRequest, + input.getServiceName(), + RpcStatusEx.Failed, + "Path not calculated", + null); + return output + .setConfigurationResponseCommon( + configurationResponseCommon + .setAckFinalIndicator("Yes") + .setRequestId(input.getServiceHandlerHeader().getRequestId()) + .setResponseCode(responseCode) + .setResponseMessage(message) + .build()) + .build(); + } + // Path calculator returned Success + PathDescription pathDescription = + new PathDescriptionBuilder() + .setAToZDirection(path.getAToZDirection()) + .setZToADirection(path.getZToADirection()) + .build(); + sendNotifications( + ServicePathNotificationTypes.PathComputationRequest, + input.getServiceName(), + RpcStatusEx.Successful, + message, + pathDescription); + org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118 + .response.parameters.sp.response.parameters.PathDescription pathDescription1 = + new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118 + .response.parameters.sp.response.parameters.PathDescriptionBuilder() + .setAToZDirection(path.getAToZDirection()) + .setZToADirection(path.getZToADirection()) + .build(); + output + .setConfigurationResponseCommon( + configurationResponseCommon + .setAckFinalIndicator("Yes") + .setRequestId(input.getServiceHandlerHeader().getRequestId()) + .setResponseCode(responseCode) + .setResponseMessage(message) + .build()) + .setResponseParameters( + new ResponseParametersBuilder().setPathDescription(pathDescription1).build()); + //debug prints + AToZDirection atoz = pathDescription.getAToZDirection(); + if ((atoz != null) && (atoz.getAToZ() != null)) { + LOG.debug("Impl AtoZ Notification: [{}] elements in description", atoz.getAToZ().size()); + for (org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501 + .path.description.atoz.direction.AToZKey key : atoz.getAToZ().keySet()) { + LOG.debug("Impl AtoZ Notification: [{}] {}", key, atoz.getAToZ().get(key)); + } + } + ZToADirection ztoa = pathDescription.getZToADirection(); + if ((ztoa != null) && (ztoa.getZToA() != null)) { + LOG.debug("Impl ZtoA Notification: [{}] elements in description", ztoa.getZToA().size()); + for (org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501 + .path.description.ztoa.direction.ZToAKey key : ztoa.getZToA().keySet()) { + LOG.debug("Impl ZtoA Notification: [{}] {}", key, ztoa.getZToA().get(key)); + } + } + return output.build(); + } + }); + } - // Path calculator returned Success - configurationResponseCommon - .setAckFinalIndicator("Yes") - .setRequestId(input.getServiceHandlerHeader().getRequestId()) - .setResponseCode(responseCode) - .setResponseMessage(message); + @Override + public ListenableFuture pathComputationRerouteRequest( + PathComputationRerouteRequestInput input) { + return executor.submit(() -> { + PathComputationRerouteRequestOutputBuilder output = new PathComputationRerouteRequestOutputBuilder(); + ConfigurationResponseCommonBuilder configurationResponseCommon = new ConfigurationResponseCommonBuilder() + .setRequestId("none"); + PceComplianceCheckResult check = PceComplianceCheck.check(input); + if (!check.hasPassed()) { + LOG.error("Path not calculated, path computation reroute request not compliant : {}", + check.getMessage()); + configurationResponseCommon + .setAckFinalIndicator("Yes") + .setResponseCode("Path not calculated") + .setResponseMessage(check.getMessage()); + return output + .setConfigurationResponseCommon(configurationResponseCommon.build()) + .build(); + } + PathComputationRequestInput pathComputationInput = new PathComputationRequestInputBuilder() + .setServiceName("no_name") + .setServiceHandlerHeader(new ServiceHandlerHeaderBuilder().setRequestId("none").build()) + .setServiceAEnd(new ServiceAEndBuilder(input.getServiceAEnd()).build()) + .setServiceZEnd(new ServiceZEndBuilder(input.getServiceZEnd()).build()) + .setHardConstraints(input.getHardConstraints()) + .setPceRoutingMetric(input.getPceRoutingMetric()) + .setResourceReserve(false) + .setSoftConstraints(input.getSoftConstraints()) + .setRoutingMetric(input.getRoutingMetric()) + .build(); + PceSendingPceRPCs sendingPCE = new PceSendingPceRPCs(pathComputationInput, networkTransactionService, + gnpyConsumer, portMapping, input.getEndpoints()); + sendingPCE.pathComputation(); + String message = sendingPCE.getMessage(); + String responseCode = sendingPCE.getResponseCode(); + LOG.info("PCE response: {} {}", message, responseCode); + return output.setConfigurationResponseCommon( + configurationResponseCommon + .setAckFinalIndicator("Yes") + .setResponseCode(responseCode) + .setResponseMessage(message) + .build()) + .build(); + }); + } - ServicePathRpcResultBuilder tmp = new ServicePathRpcResultBuilder() - .setNotificationType(ServicePathNotificationTypes.PathComputationRequest) - .setServiceName(input.getServiceName()) - .setStatus(RpcStatusEx.Successful) - .setStatusMessage(message); - PathDescription pathDescription = new org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce - .pce.rev171017.service.path.rpc.result.PathDescriptionBuilder() - .setAToZDirection(path.getAToZDirection()) - .setZToADirection(path.getZToADirection()) + public GnpyResponse generateGnpyResponse(Response responseGnpy, String pathDir) { + if (responseGnpy == null) { + return new GnpyResponseBuilder() + .setPathDir(pathDir) + .setResponseType(null) + .setFeasibility(true) .build(); - tmp.setPathDescription(pathDescription); - - notification = tmp.build(); - try { - notificationPublishService.putNotification(notification); - } catch (InterruptedException e) { - LOG.error("notification offer rejected : {}", e.getMessage()); } - - org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types - .rev171016.response.parameters.sp.response.parameters.PathDescription pathDescription1 - = new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types - .rev171016.response.parameters.sp.response.parameters.PathDescriptionBuilder() - .setAToZDirection(path.getAToZDirection()) - .setZToADirection(path.getZToADirection()) + if (responseGnpy.getResponseType() + instanceof org.opendaylight.yang.gen.v1.gnpy.path.rev220615.result.response.response.type.NoPathCase) { + LOG.info("GNPy : path is not feasible"); + org.opendaylight.yang.gen.v1.gnpy.path.rev220615.result.response.response.type.NoPathCase + noPathGnpy = + (org.opendaylight.yang.gen.v1.gnpy.path.rev220615.result.response.response.type.NoPathCase) + responseGnpy.getResponseType(); + return new GnpyResponseBuilder() + .setPathDir(pathDir) + .setResponseType( + new NoPathCaseBuilder() + .setNoPath(noPathGnpy.getNoPath()) + .build()) + .setFeasibility(false) .build(); - ResponseParametersBuilder rpb = new ResponseParametersBuilder() - .setPathDescription(pathDescription1); - - output.setConfigurationResponseCommon(configurationResponseCommon.build()) - .setResponseParameters(rpb.build()); - - //debug prints - AToZDirection atoz = pathDescription.getAToZDirection(); - if ((atoz != null) && (atoz.getAToZ() != null)) { - LOG.info("Impl AtoZ Notification: [{}] elements in description", atoz.getAToZ().size()); - for (int i = 0; i < atoz.getAToZ().size(); i++) { - LOG.info("Impl AtoZ Notification: [{}] {}", i, atoz.getAToZ().get(i)); - } } - ZToADirection ztoa = pathDescription.getZToADirection(); - if ((ztoa != null) && (ztoa.getZToA() != null)) { - LOG.info("Impl ZtoA Notification: [{}] elements in description", ztoa.getZToA().size()); - for (int i = 0; i < ztoa.getZToA().size(); i++) { - LOG.info("Impl ZtoA Notification: [{}] {}", i, ztoa.getZToA().get(i)); + if (responseGnpy.getResponseType() + instanceof org.opendaylight.yang.gen.v1.gnpy.path.rev220615.result.response.response.type.PathCase) { + LOG.info("GNPy : path is feasible"); + org.opendaylight.yang.gen.v1.gnpy.path.rev220615.result.response.response.type.PathCase + pathCase = + (org.opendaylight.yang.gen.v1.gnpy.path.rev220615.result.response.response.type.PathCase) + responseGnpy.getResponseType(); + List + pathMetricList = + new ArrayList<>(pathCase.getPathProperties().getPathMetric().values()); + List gnpyPathMetricList = new ArrayList<>(); + for (org.opendaylight.yang.gen.v1.gnpy.path.rev220615.generic.path.properties.path.properties.PathMetric + pathMetricGnpy : pathMetricList) { + gnpyPathMetricList.add( + new PathMetricBuilder() + .setMetricType(pathMetricGnpy.getMetricType()) + .setAccumulativeValue(pathMetricGnpy.getAccumulativeValue()) + .build()); } + return new GnpyResponseBuilder() + .setPathDir(pathDir) + .setResponseType( + new PathCaseBuilder() + .setPathProperties( + new PathPropertiesBuilder() + .setPathMetric(gnpyPathMetricList.stream() + .collect(Collectors.toMap(PathMetric::key, pathMetric -> pathMetric))) + .build()) + .build()) + .setFeasibility(true) + .build(); } - //debug prints - return output.build(); + return new GnpyResponseBuilder() + .setPathDir(pathDir) + .setResponseType(null) + .setFeasibility(true) + .build(); } }