X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=pce%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Ftransportpce%2Fpce%2Fgnpy%2FGnpyUtilitiesImpl.java;h=e7de91fe68e34f071e53b056ae18152c0f48f8ba;hb=1e2f9a502de80450411761fd2f636e2b7ee32301;hp=d8560b60ba9cf315ba583681e91827d22597b736;hpb=98de423782828b8b44b9cb341a581e1e90a16971;p=transportpce.git 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 index d8560b60b..e7de91fe6 100644 --- a/pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/GnpyUtilitiesImpl.java +++ b/pce/src/main/java/org/opendaylight/transportpce/pce/gnpy/GnpyUtilitiesImpl.java @@ -10,26 +10,25 @@ package org.opendaylight.transportpce.pce.gnpy; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; 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.rev200202.generic.path.properties.path.properties.PathRouteObjects; -import org.opendaylight.yang.gen.v1.gnpy.path.rev200202.service.PathRequest; -import org.opendaylight.yang.gen.v1.gnpy.path.rev200202.synchronization.info.Synchronization; -import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.PathComputationRequestInput; -import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.path.description.AToZDirection; -import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.path.description.AToZDirectionBuilder; -import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.path.description.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.opendaylight.transportpce.pce.gnpy.consumer.GnpyConsumer; +import org.opendaylight.yang.gen.v1.gnpy.gnpy.api.rev220221.RequestBuilder; +import org.opendaylight.yang.gen.v1.gnpy.gnpy.api.rev220221.request.ServiceBuilder; +import org.opendaylight.yang.gen.v1.gnpy.gnpy.api.rev220221.request.TopologyBuilder; +import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev220221.topo.Connections; +import org.opendaylight.yang.gen.v1.gnpy.gnpy.network.topology.rev220221.topo.Elements; +import org.opendaylight.yang.gen.v1.gnpy.path.rev220221.Result; +import org.opendaylight.yang.gen.v1.gnpy.path.rev220221.generic.path.properties.path.properties.PathRouteObjects; +import org.opendaylight.yang.gen.v1.gnpy.path.rev220221.service.PathRequest; +import org.opendaylight.yang.gen.v1.gnpy.path.rev220221.synchronization.info.Synchronization; +import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220118.PathComputationRequestInput; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.routing.constraints.HardConstraints; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.AToZDirection; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.AToZDirectionBuilder; +import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev210705.path.description.ZToADirection; import org.opendaylight.yangtools.yang.common.Uint32; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * Class that implements the functions asked to gnpy. @@ -40,27 +39,26 @@ import org.slf4j.LoggerFactory; public class GnpyUtilitiesImpl { - private static final Logger LOG = LoggerFactory.getLogger(GnpyUtilitiesImpl.class); - private NetworkTransactionService networkTransaction; private PathComputationRequestInput input; private GnpyTopoImpl gnpyTopo = null; private GnpyResult gnpyAtoZ; private GnpyResult gnpyZtoA; private Uint32 requestId; + private final GnpyConsumer gnpyConsumer; - public GnpyUtilitiesImpl(NetworkTransactionService networkTransaction, PathComputationRequestInput input) + public GnpyUtilitiesImpl(NetworkTransactionService networkTransaction, PathComputationRequestInput input, + GnpyConsumer gnpyConsumer) throws GnpyException { - - this.networkTransaction = networkTransaction; this.gnpyTopo = new GnpyTopoImpl(networkTransaction); this.input = input; this.gnpyAtoZ = null; this.gnpyZtoA = null; this.requestId = Uint32.valueOf(0); + this.gnpyConsumer = gnpyConsumer; } public boolean verifyComputationByGnpy(AToZDirection atoz, ZToADirection ztoa, PceConstraints pceHardConstraints) - throws GnpyException, Exception { + throws GnpyException { if (atoz == null || atoz.getAToZ() == null || ztoa == null || ztoa.getZToA() == null) { throw new GnpyException("In GnpyUtilities: the path transmitted to Gnpy is null"); @@ -76,15 +74,15 @@ public class GnpyUtilitiesImpl { return isPcePathFeasible; } - public GnpyResult gnpyResponseOneDirection(GnpyServiceImpl gnpySvc) throws GnpyException, Exception { + public GnpyResult gnpyResponseOneDirection(GnpyServiceImpl gnpySvc) throws GnpyException { requestId = Uint32.valueOf((requestId.toJava()) + 1); - List pathRequestList = new ArrayList(gnpySvc.getPathRequest().values()); + List pathRequestList = new ArrayList<>(gnpySvc.getPathRequest().values()); List synchronizationList = gnpySvc.getSynchronization(); // Send the computed path to GNPY tool - List elementsList = new ArrayList(gnpyTopo.getElements().values()); + List elementsList = new ArrayList<>(gnpyTopo.getElements().values()); List connectionsList = gnpyTopo.getConnections(); - String gnpyResponse = getGnpyResponse(elementsList, connectionsList, pathRequestList, - synchronizationList); + Result gnpyResponse = getGnpyResponse(elementsList, connectionsList, pathRequestList, + synchronizationList); // Analyze the response if (gnpyResponse == null) { throw new GnpyException("In GnpyUtilities: no response from GNPy server"); @@ -95,7 +93,7 @@ public class GnpyUtilitiesImpl { } public HardConstraints askNewPathFromGnpy(PceConstraints pceHardConstraints) - throws GnpyException, Exception { + throws GnpyException { AToZDirection atoztmp = new AToZDirectionBuilder() .setRate(input.getServiceAEnd().getServiceRate()) @@ -114,27 +112,20 @@ public class GnpyUtilitiesImpl { return result.computeHardConstraintsFromGnpyPath(pathRouteObjectList); } - public String getGnpyResponse(List elementsList, List connectionsList, - List pathRequestList, List synchronizationList) - throws GnpyException, Exception { - GnpyApi gnpyApi = new GnpyApiBuilder() - .setTopologyFile( - new TopologyFileBuilder().setElements(elementsList).setConnections(connectionsList).build()) - .setServiceFile( - new ServiceFileBuilder().setPathRequest(pathRequestList).build()) - .build(); - InstanceIdentifier 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:", ""); - - return connect.returnGnpyResponse(gnpyJsonModified); + public Result getGnpyResponse(List elementsList, List connectionsList, + List pathRequestList, List synchronizationList) { + + return gnpyConsumer.computePaths(new RequestBuilder() + .setTopology( + new TopologyBuilder() + .setElements(elementsList.stream().collect(Collectors.toMap(Elements::key, element -> element))) + .setConnections(connectionsList).build()) + .setService( + new ServiceBuilder() + .setPathRequest(pathRequestList.stream() + .collect(Collectors.toMap(PathRequest::key, pathRequest -> pathRequest))) + .build()) + .build()); } public GnpyResult getGnpyAtoZ() {