2 * Copyright © 2017 AT&T and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.transportpce.pce;
11 import org.opendaylight.transportpce.common.ResponseCodes;
12 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
13 import org.opendaylight.transportpce.pce.constraints.PceConstraints;
14 import org.opendaylight.transportpce.pce.constraints.PceConstraintsCalc;
15 import org.opendaylight.transportpce.pce.gnpy.GnpyException;
16 import org.opendaylight.transportpce.pce.gnpy.GnpyResult;
17 import org.opendaylight.transportpce.pce.gnpy.GnpyUtilitiesImpl;
18 import org.opendaylight.transportpce.pce.gnpy.consumer.GnpyConsumer;
19 import org.opendaylight.transportpce.pce.graph.PceGraph;
20 import org.opendaylight.transportpce.pce.networkanalyzer.PceCalculation;
21 import org.opendaylight.transportpce.pce.networkanalyzer.PceResult;
22 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.PathComputationRequestInput;
23 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.PathComputationRequestInputBuilder;
24 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.service.path.rpc.result.PathDescriptionBuilder;
25 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201210.path.description.AToZDirection;
26 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev201210.path.description.ZToADirection;
27 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.RoutingConstraintsSp.PceMetric;
28 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.routing.constraints.sp.HardConstraints;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
35 * - path-computation-request
36 * - cancel-resource-reserve.
37 * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange
40 public class PceSendingPceRPCs {
43 private static final Logger LOG = LoggerFactory.getLogger(PceSendingPceRPCs.class);
44 /* define procedure success (or not ). */
45 private PceResult rc = new PceResult();
48 * define type of request<br> <code>true</code> pathcomputation <br>
49 * <code>false</code> cancelresourcereserve .
51 private PathDescriptionBuilder pathDescription;
52 private PathComputationRequestInput input;
53 private NetworkTransactionService networkTransaction;
54 private PceConstraints pceHardConstraints = new PceConstraints();
55 private PceConstraints pceSoftConstraints = new PceConstraints();
56 private GnpyResult gnpyAtoZ;
57 private GnpyResult gnpyZtoA;
58 private Boolean success;
59 private String message;
60 private String responseCode;
61 private final GnpyConsumer gnpyConsumer;
63 public PceSendingPceRPCs(GnpyConsumer gnpyConsumer) {
64 setPathDescription(null);
66 this.networkTransaction = null;
67 this.gnpyConsumer = gnpyConsumer;
70 public PceSendingPceRPCs(PathComputationRequestInput input,
71 NetworkTransactionService networkTransaction, GnpyConsumer gnpyConsumer) {
72 this.gnpyConsumer = gnpyConsumer;
73 setPathDescription(null);
75 // TODO compliance check to check that input is not empty
77 this.networkTransaction = networkTransaction;
80 public void cancelResourceReserve() {
82 LOG.info("Wait for 10s til beginning the PCE cancelResourceReserve request");
86 } catch (InterruptedException e) {
87 LOG.error("in PCESendingPceRPC: ",e);
90 LOG.info("cancelResourceReserve ...");
93 public void pathComputationWithConstraints(PceConstraints hardConstraints, PceConstraints softConstraints) {
95 PceCalculation nwAnalizer =
96 new PceCalculation(input, networkTransaction, hardConstraints, softConstraints, rc);
97 nwAnalizer.retrievePceNetwork();
98 rc = nwAnalizer.getReturnStructure();
99 String serviceType = nwAnalizer.getServiceType();
100 if (!rc.getStatus()) {
101 LOG.error("In pathComputationWithConstraints, nwAnalizer: result = {}", rc);
104 LOG.info("PceGraph ...");
105 PceGraph graph = new PceGraph(nwAnalizer.getaendPceNode(),
106 nwAnalizer.getzendPceNode(), nwAnalizer.getAllPceNodes(),
107 hardConstraints, softConstraints, rc, serviceType);
109 rc = graph.getReturnStructure();
110 if (!rc.getStatus()) {
111 LOG.warn("In pathComputationWithConstraints : Graph return without Path ");
112 // TODO fix. This is quick workaround for algorithm problem
113 if ((rc.getLocalCause() == PceResult.LocalCause.TOO_HIGH_LATENCY)
114 && (hardConstraints.getPceMetrics() == PceMetric.HopCount)
115 && (hardConstraints.getMaxLatency() != -1)) {
116 hardConstraints.setPceMetrics(PceMetric.PropagationDelay);
117 graph = patchRerunGraph(graph);
120 if (rc.getLocalCause() == PceResult.LocalCause.HD_NODE_INCLUDE) {
121 graph.setKpathsToBring(graph.getKpathsToBring() * 10);
122 graph = patchRerunGraph(graph);
125 if (!rc.getStatus()) {
126 LOG.error("In pathComputationWithConstraints, graph.calcPath: result = {}", rc);
130 LOG.info("PcePathDescription ...");
131 PcePathDescription description = new PcePathDescription(graph.getPathAtoZ(), nwAnalizer.getAllPceLinks(), rc);
132 description.buildDescriptions();
133 rc = description.getReturnStructure();
134 if (!rc.getStatus()) {
135 LOG.error("In pathComputationWithConstraints, description: result = {}", rc);
139 public void pathComputation() throws Exception {
141 PceConstraintsCalc constraints = new PceConstraintsCalc(input, networkTransaction);
142 pceHardConstraints = constraints.getPceHardConstraints();
143 pceSoftConstraints = constraints.getPceSoftConstraints();
144 pathComputationWithConstraints(pceHardConstraints, pceSoftConstraints);
145 this.success = rc.getStatus();
146 this.message = rc.getMessage();
147 this.responseCode = rc.getResponseCode();
149 AToZDirection atoz = null;
150 ZToADirection ztoa = null;
151 if (rc.getStatus()) {
152 atoz = rc.getAtoZDirection();
153 ztoa = rc.getZtoADirection();
156 //Connect to Gnpy to check path feasibility and recompute another path in case of path non-feasibility
158 if (gnpyConsumer.isAvailable()) {
159 GnpyUtilitiesImpl gnpy = new GnpyUtilitiesImpl(networkTransaction, input,
161 if (rc.getStatus() && gnpyToCheckFeasiblity(atoz,ztoa,gnpy)) {
162 setPathDescription(new PathDescriptionBuilder().setAToZDirection(atoz).setZToADirection(ztoa));
165 callGnpyToComputeNewPath(gnpy);
167 setPathDescription(new PathDescriptionBuilder().setAToZDirection(atoz).setZToADirection(ztoa));
170 catch (GnpyException e) {
171 LOG.error("Exception raised by GNPy {}",e.getMessage());
172 setPathDescription(new PathDescriptionBuilder().setAToZDirection(atoz).setZToADirection(ztoa));
176 private boolean gnpyToCheckFeasiblity(AToZDirection atoz, ZToADirection ztoa, GnpyUtilitiesImpl gnpy)
177 throws GnpyException {
179 //Call GNPy for path verification
180 if (gnpy.verifyComputationByGnpy(atoz, ztoa, pceHardConstraints)) {
181 LOG.info("In pceSendingPceRPC: the path is feasible according to Gnpy");
182 gnpyAtoZ = gnpy.getGnpyAtoZ();
183 gnpyZtoA = gnpy.getGnpyZtoA();
189 private void callGnpyToComputeNewPath(GnpyUtilitiesImpl gnpy) throws GnpyException {
191 //Call GNPy in the case of non feasibility
192 LOG.info("In pceSendingPceRPC: the path is not feasible according to Gnpy");
193 HardConstraints gnpyPathAsHC = null;
194 gnpyPathAsHC = gnpy.askNewPathFromGnpy(pceHardConstraints);
195 if (gnpyPathAsHC == null) {
196 LOG.info("In pceSendingPceRPC: GNPy failed to find another path");
197 this.success = false;
198 this.message = "No path available by PCE and GNPy ";
199 this.responseCode = ResponseCodes.RESPONSE_FAILED;
200 gnpyAtoZ = gnpy.getGnpyAtoZ();
201 gnpyZtoA = gnpy.getGnpyZtoA();
205 LOG.info("In pceSendingPceRPC: GNPy succeed to find another path");
207 PathComputationRequestInput inputFromGnpy = new PathComputationRequestInputBuilder()
208 .setServiceName(input.getServiceName()).setHardConstraints(gnpyPathAsHC)
209 .setSoftConstraints(input.getSoftConstraints()).setPceMetric(PceMetric.HopCount)
210 .setServiceAEnd(input.getServiceAEnd()).setServiceZEnd(input.getServiceZEnd()).build();
211 PceConstraintsCalc constraintsGnpy = new PceConstraintsCalc(inputFromGnpy, networkTransaction);
212 PceConstraints gnpyHardConstraints = constraintsGnpy.getPceHardConstraints();
213 PceConstraints gnpySoftConstraints = constraintsGnpy.getPceSoftConstraints();
214 pathComputationWithConstraints(gnpyHardConstraints, gnpySoftConstraints);
215 AToZDirection atoz = rc.getAtoZDirection();
216 ZToADirection ztoa = rc.getZtoADirection();
217 if (gnpyToCheckFeasiblity(atoz, ztoa,gnpy)) {
218 LOG.info("In pceSendingPceRPC: the new path computed by GNPy is valid");
220 this.message = "Path is calculated by GNPy";
221 this.responseCode = ResponseCodes.RESPONSE_OK;
222 setPathDescription(new PathDescriptionBuilder().setAToZDirection(atoz).setZToADirection(ztoa));
224 LOG.info("In pceSendingPceRPC: the new path computed by GNPy is not valid");
225 this.success = false;
226 this.message = "No path available";
227 this.responseCode = ResponseCodes.RESPONSE_FAILED;
228 setPathDescription(new PathDescriptionBuilder().setAToZDirection(null).setZToADirection(null));
232 private PceGraph patchRerunGraph(PceGraph graph) {
233 LOG.info("In pathComputation patchRerunGraph : rerun Graph with metric = PROPAGATION-DELAY ");
234 graph.setConstrains(pceHardConstraints, pceSoftConstraints);
239 public PathDescriptionBuilder getPathDescription() {
240 return pathDescription;
243 private void setPathDescription(PathDescriptionBuilder pathDescription) {
244 this.pathDescription = pathDescription;
247 public Boolean getSuccess() {
251 public String getMessage() {
255 public String getResponseCode() {
256 return this.responseCode;
259 public GnpyResult getGnpyAtoZ() {
263 public GnpyResult getGnpyZtoA() {