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.mapping.PortMapping;
13 import org.opendaylight.transportpce.common.network.NetworkTransactionService;
14 import org.opendaylight.transportpce.pce.constraints.PceConstraints;
15 import org.opendaylight.transportpce.pce.constraints.PceConstraintsCalc;
16 import org.opendaylight.transportpce.pce.gnpy.GnpyException;
17 import org.opendaylight.transportpce.pce.gnpy.GnpyResult;
18 import org.opendaylight.transportpce.pce.gnpy.GnpyUtilitiesImpl;
19 import org.opendaylight.transportpce.pce.gnpy.consumer.GnpyConsumer;
20 import org.opendaylight.transportpce.pce.graph.PceGraph;
21 import org.opendaylight.transportpce.pce.networkanalyzer.PceCalculation;
22 import org.opendaylight.transportpce.pce.networkanalyzer.PceResult;
23 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev230925.PathComputationRequestInput;
24 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev230925.PathComputationRequestInputBuilder;
25 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev230925.PceConstraintMode;
26 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev230925.path.computation.reroute.request.input.Endpoints;
27 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev230925.service.path.rpc.result.PathDescriptionBuilder;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.routing.constraints.HardConstraints;
29 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.AToZDirection;
30 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.ZToADirection;
31 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.PceMetric;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
38 * - path-computation-request
39 * - path-computation-reroute
40 * - cancel-resource-reserve.
41 * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange
44 public class PceSendingPceRPCs {
47 private static final Logger LOG = LoggerFactory.getLogger(PceSendingPceRPCs.class);
48 /* define procedure success (or not ). */
49 private PceResult rc = new PceResult();
52 * define type of request<br> <code>true</code> pathcomputation <br>
53 * <code>false</code> cancelresourcereserve .
55 private PathDescriptionBuilder pathDescription;
56 private PathComputationRequestInput input;
57 private NetworkTransactionService networkTransaction;
58 private PceConstraints pceHardConstraints = new PceConstraints();
59 private PceConstraints pceSoftConstraints = new PceConstraints();
60 private GnpyResult gnpyAtoZ;
61 private GnpyResult gnpyZtoA;
62 private Boolean success;
63 private String message;
64 private String responseCode;
65 private final GnpyConsumer gnpyConsumer;
66 private PortMapping portMapping;
67 // Define the termination points whose reservation status is not taken into account during the pruning process
68 private Endpoints endpoints;
70 public PceSendingPceRPCs(GnpyConsumer gnpyConsumer) {
71 setPathDescription(null);
73 this.networkTransaction = null;
74 this.gnpyConsumer = gnpyConsumer;
77 public PceSendingPceRPCs(PathComputationRequestInput input, NetworkTransactionService networkTransaction,
78 GnpyConsumer gnpyConsumer, PortMapping portMapping) {
79 this.gnpyConsumer = gnpyConsumer;
80 setPathDescription(null);
81 // TODO compliance check to check that input is not empty
83 this.networkTransaction = networkTransaction;
84 this.portMapping = portMapping;
85 this.endpoints = null;
88 public PceSendingPceRPCs(PathComputationRequestInput input, NetworkTransactionService networkTransaction,
89 GnpyConsumer gnpyConsumer, PortMapping portMapping,
90 Endpoints endpoints) {
91 this.gnpyConsumer = gnpyConsumer;
92 setPathDescription(null);
94 this.networkTransaction = networkTransaction;
95 this.portMapping = portMapping;
96 this.endpoints = endpoints;
99 public void cancelResourceReserve() {
101 LOG.info("Wait for 10s til beginning the PCE cancelResourceReserve request");
105 } catch (InterruptedException e) {
106 LOG.error("in PCESendingPceRPC: ",e);
109 LOG.info("cancelResourceReserve ...");
112 private void pathComputationWithConstraints(PceConstraints hardConstraints, PceConstraints softConstraints,
113 PceConstraintMode mode) {
115 PceCalculation nwAnalizer = new PceCalculation(input, networkTransaction, hardConstraints, softConstraints, rc,
116 portMapping, endpoints);
117 nwAnalizer.retrievePceNetwork();
118 rc = nwAnalizer.getReturnStructure();
119 String serviceType = nwAnalizer.getServiceType();
120 if (!rc.getStatus()) {
121 LOG.error("In pathComputationWithConstraints, nwAnalizer: result = {}", rc);
124 LOG.info("PceGraph ...");
125 PceGraph graph = new PceGraph(nwAnalizer.getaendPceNode(), nwAnalizer.getzendPceNode(),
126 nwAnalizer.getAllPceNodes(), nwAnalizer.getAllPceLinks(), hardConstraints,
127 rc, serviceType, networkTransaction, mode);
129 rc = graph.getReturnStructure();
130 if (!rc.getStatus()) {
131 LOG.warn("In pathComputationWithConstraints : Graph return without Path ");
132 // TODO fix. This is quick workaround for algorithm problem
133 if ((rc.getLocalCause() == PceResult.LocalCause.TOO_HIGH_LATENCY)
134 && (hardConstraints.getPceMetrics() == PceMetric.HopCount)
135 && (hardConstraints.getMaxLatency() != -1)) {
136 hardConstraints.setPceMetrics(PceMetric.PropagationDelay);
137 graph = patchRerunGraph(graph);
140 if (rc.getLocalCause() == PceResult.LocalCause.HD_NODE_INCLUDE) {
141 graph.setKpathsToBring(graph.getKpathsToBring() * 10);
142 graph = patchRerunGraph(graph);
145 if (!rc.getStatus()) {
146 LOG.error("In pathComputationWithConstraints, graph.calcPath: result = {}", rc);
150 LOG.info("PcePathDescription ...");
151 PcePathDescription description = new PcePathDescription(graph.getPathAtoZ(), nwAnalizer.getAllPceLinks(), rc);
152 description.buildDescriptions();
153 rc = description.getReturnStructure();
154 if (!rc.getStatus()) {
155 LOG.error("In pathComputationWithConstraints, description: result = {}", rc);
159 public void pathComputation() throws Exception {
161 PceConstraintsCalc constraints = new PceConstraintsCalc(input, networkTransaction);
162 pceHardConstraints = constraints.getPceHardConstraints();
163 pceSoftConstraints = constraints.getPceSoftConstraints();
164 pathComputationWithConstraints(pceHardConstraints, pceSoftConstraints, PceConstraintMode.Loose);
165 this.success = rc.getStatus();
166 this.message = rc.getMessage();
167 this.responseCode = rc.getResponseCode();
169 AToZDirection atoz = null;
170 ZToADirection ztoa = null;
171 if (rc.getStatus()) {
172 atoz = rc.getAtoZDirection();
173 ztoa = rc.getZtoADirection();
176 //Connect to Gnpy to check path feasibility and recompute another path in case of path non-feasibility
178 if (gnpyConsumer.isAvailable()) {
179 GnpyUtilitiesImpl gnpy = new GnpyUtilitiesImpl(networkTransaction, input,
181 if (rc.getStatus() && gnpyToCheckFeasiblity(atoz,ztoa,gnpy)) {
182 setPathDescription(new PathDescriptionBuilder().setAToZDirection(atoz).setZToADirection(ztoa));
185 callGnpyToComputeNewPath(gnpy);
187 setPathDescription(new PathDescriptionBuilder().setAToZDirection(atoz).setZToADirection(ztoa));
190 catch (GnpyException e) {
191 LOG.error("Exception raised by GNPy {}",e.getMessage());
192 setPathDescription(new PathDescriptionBuilder().setAToZDirection(atoz).setZToADirection(ztoa));
196 private boolean gnpyToCheckFeasiblity(AToZDirection atoz, ZToADirection ztoa, GnpyUtilitiesImpl gnpy)
197 throws GnpyException {
199 //Call GNPy for path verification
200 if (gnpy.verifyComputationByGnpy(atoz, ztoa, pceHardConstraints)) {
201 LOG.info("In pceSendingPceRPC: the path is feasible according to Gnpy");
202 gnpyAtoZ = gnpy.getGnpyAtoZ();
203 gnpyZtoA = gnpy.getGnpyZtoA();
209 private void callGnpyToComputeNewPath(GnpyUtilitiesImpl gnpy) throws GnpyException {
211 //Call GNPy in the case of non feasibility
212 LOG.info("In pceSendingPceRPC: the path is not feasible according to Gnpy");
213 HardConstraints gnpyPathAsHC = null;
214 gnpyPathAsHC = gnpy.askNewPathFromGnpy(pceHardConstraints);
215 if (gnpyPathAsHC == null) {
216 LOG.info("In pceSendingPceRPC: GNPy failed to find another path");
217 this.success = false;
218 this.message = "No path available by PCE and GNPy ";
219 this.responseCode = ResponseCodes.RESPONSE_FAILED;
220 gnpyAtoZ = gnpy.getGnpyAtoZ();
221 gnpyZtoA = gnpy.getGnpyZtoA();
225 LOG.info("In pceSendingPceRPC: GNPy succeed to find another path");
227 PathComputationRequestInput inputFromGnpy = new PathComputationRequestInputBuilder()
228 .setServiceName(input.getServiceName())
229 .setHardConstraints(gnpyPathAsHC)
230 .setSoftConstraints(input.getSoftConstraints())
231 .setPceRoutingMetric(PceMetric.HopCount)
232 .setServiceAEnd(input.getServiceAEnd())
233 .setServiceZEnd(input.getServiceZEnd())
235 PceConstraintsCalc constraintsGnpy = new PceConstraintsCalc(inputFromGnpy, networkTransaction);
236 PceConstraints gnpyHardConstraints = constraintsGnpy.getPceHardConstraints();
237 PceConstraints gnpySoftConstraints = constraintsGnpy.getPceSoftConstraints();
238 pathComputationWithConstraints(gnpyHardConstraints, gnpySoftConstraints, PceConstraintMode.Strict);
239 AToZDirection atoz = rc.getAtoZDirection();
240 ZToADirection ztoa = rc.getZtoADirection();
241 if (gnpyToCheckFeasiblity(atoz, ztoa,gnpy)) {
242 LOG.info("In pceSendingPceRPC: the new path computed by GNPy is valid");
244 this.message = "Path is calculated by GNPy";
245 this.responseCode = ResponseCodes.RESPONSE_OK;
246 setPathDescription(new PathDescriptionBuilder().setAToZDirection(atoz).setZToADirection(ztoa));
248 LOG.info("In pceSendingPceRPC: the new path computed by GNPy is not valid");
249 this.success = false;
250 this.message = "No path available";
251 this.responseCode = ResponseCodes.RESPONSE_FAILED;
252 setPathDescription(new PathDescriptionBuilder().setAToZDirection(null).setZToADirection(null));
256 private PceGraph patchRerunGraph(PceGraph graph) {
257 LOG.info("In pathComputation patchRerunGraph : rerun Graph with metric = PROPAGATION-DELAY ");
258 graph.setConstrains(pceHardConstraints);
263 public PathDescriptionBuilder getPathDescription() {
264 return pathDescription;
267 private void setPathDescription(PathDescriptionBuilder pathDescription) {
268 this.pathDescription = pathDescription;
271 public Boolean getSuccess() {
275 public String getMessage() {
279 public String getResponseCode() {
280 return this.responseCode;
283 public GnpyResult getGnpyAtoZ() {
287 public GnpyResult getGnpyZtoA() {