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.ConnectToGnpyServer;
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.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.rev171017.path.description.AToZDirection;
26 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.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;
62 public PceSendingPceRPCs() {
63 setPathDescription(null);
65 this.networkTransaction = null;
68 public PceSendingPceRPCs(PathComputationRequestInput input,
69 NetworkTransactionService networkTransaction) {
70 setPathDescription(null);
72 // TODO compliance check to check that input is not empty
74 this.networkTransaction = networkTransaction;
77 public void cancelResourceReserve() {
79 LOG.info("Wait for 10s til beginning the PCE cancelResourceReserve request");
83 } catch (InterruptedException e) {
84 LOG.error("in PCESendingPceRPC: ",e);
87 LOG.info("cancelResourceReserve ...");
90 public void pathComputationWithConstraints(PceConstraints hardConstraints, PceConstraints softConstraints) {
92 PceCalculation nwAnalizer =
93 new PceCalculation(input, networkTransaction, hardConstraints, softConstraints, rc);
94 nwAnalizer.retrievePceNetwork();
95 rc = nwAnalizer.getReturnStructure();
96 String serviceType = nwAnalizer.getServiceType();
97 if (!rc.getStatus()) {
98 LOG.error("In pathComputationWithConstraints, nwAnalizer: result = {}", rc);
101 LOG.info("PceGraph ...");
102 PceGraph graph = new PceGraph(nwAnalizer.getaendPceNode(),
103 nwAnalizer.getzendPceNode(), nwAnalizer.getAllPceNodes(),
104 hardConstraints, softConstraints, rc, serviceType);
106 rc = graph.getReturnStructure();
107 if (!rc.getStatus()) {
108 LOG.warn("In pathComputationWithConstraints : Graph return without Path ");
109 // TODO fix. This is quick workaround for algorithm problem
110 if ((rc.getLocalCause() == PceResult.LocalCause.TOO_HIGH_LATENCY)
111 && (hardConstraints.getPceMetrics() == PceMetric.HopCount)
112 && (hardConstraints.getMaxLatency() != -1)) {
113 hardConstraints.setPceMetrics(PceMetric.PropagationDelay);
114 graph = patchRerunGraph(graph);
117 if (rc.getLocalCause() == PceResult.LocalCause.HD_NODE_INCLUDE) {
118 graph.setKpathsToBring(graph.getKpathsToBring() * 10);
119 graph = patchRerunGraph(graph);
122 if (!rc.getStatus()) {
123 LOG.error("In pathComputationWithConstraints, graph.calcPath: result = {}", rc);
127 LOG.info("PcePathDescription ...");
128 PcePathDescription description = new PcePathDescription(graph.getPathAtoZ(), nwAnalizer.getAllPceLinks(), rc);
129 description.buildDescriptions();
130 rc = description.getReturnStructure();
131 if (!rc.getStatus()) {
132 LOG.error("In pathComputationWithConstraints, description: result = {}", rc);
136 public void pathComputation() throws Exception {
138 PceConstraintsCalc constraints = new PceConstraintsCalc(input, networkTransaction);
139 pceHardConstraints = constraints.getPceHardConstraints();
140 pceSoftConstraints = constraints.getPceSoftConstraints();
141 pathComputationWithConstraints(pceHardConstraints, pceSoftConstraints);
142 this.success = rc.getStatus();
143 this.message = rc.getMessage();
144 this.responseCode = rc.getResponseCode();
146 AToZDirection atoz = null;
147 ZToADirection ztoa = null;
148 if (rc.getStatus()) {
149 atoz = rc.getAtoZDirection();
150 ztoa = rc.getZtoADirection();
153 //Connect to Gnpy to check path feasibility and recompute another path in case of path non-feasibility
155 ConnectToGnpyServer connectToGnpy = new ConnectToGnpyServer();
156 if (connectToGnpy.isGnpyURLExist()) {
157 GnpyUtilitiesImpl gnpy = new GnpyUtilitiesImpl(networkTransaction, input);
158 if (rc.getStatus() && gnpyToCheckFeasiblity(atoz,ztoa,gnpy)) {
159 setPathDescription(new PathDescriptionBuilder().setAToZDirection(atoz).setZToADirection(ztoa));
162 callGnpyToComputeNewPath(gnpy);
164 setPathDescription(new PathDescriptionBuilder().setAToZDirection(atoz).setZToADirection(ztoa));
167 catch (GnpyException e) {
168 LOG.error("Exception raised by GNPy {}",e.getMessage());
169 setPathDescription(new PathDescriptionBuilder().setAToZDirection(atoz).setZToADirection(ztoa));
173 private boolean gnpyToCheckFeasiblity(AToZDirection atoz, ZToADirection ztoa, GnpyUtilitiesImpl gnpy)
174 throws GnpyException, Exception {
176 //Call GNPy for path verification
177 if (gnpy.verifyComputationByGnpy(atoz, ztoa, pceHardConstraints)) {
178 LOG.info("In pceSendingPceRPC: the path is feasible according to Gnpy");
179 gnpyAtoZ = gnpy.getGnpyAtoZ();
180 gnpyZtoA = gnpy.getGnpyZtoA();
186 private void callGnpyToComputeNewPath(GnpyUtilitiesImpl gnpy) throws GnpyException, Exception {
188 //Call GNPy in the case of non feasibility
189 LOG.info("In pceSendingPceRPC: the path is not feasible according to Gnpy");
190 HardConstraints gnpyPathAsHC = null;
191 gnpyPathAsHC = gnpy.askNewPathFromGnpy(pceHardConstraints);
192 if (gnpyPathAsHC == null) {
193 LOG.info("In pceSendingPceRPC: GNPy failed to find another path");
194 this.success = false;
195 this.message = "No path available by PCE and GNPy ";
196 this.responseCode = ResponseCodes.RESPONSE_FAILED;
197 gnpyAtoZ = gnpy.getGnpyAtoZ();
198 gnpyZtoA = gnpy.getGnpyZtoA();
202 LOG.info("In pceSendingPceRPC: GNPy succeed to find another path");
204 PathComputationRequestInput inputFromGnpy = new PathComputationRequestInputBuilder()
205 .setServiceName(input.getServiceName()).setHardConstraints(gnpyPathAsHC)
206 .setSoftConstraints(input.getSoftConstraints()).setPceMetric(PceMetric.HopCount)
207 .setServiceAEnd(input.getServiceAEnd()).setServiceZEnd(input.getServiceZEnd()).build();
208 PceConstraintsCalc constraintsGnpy = new PceConstraintsCalc(inputFromGnpy, networkTransaction);
209 PceConstraints gnpyHardConstraints = constraintsGnpy.getPceHardConstraints();
210 PceConstraints gnpySoftConstraints = constraintsGnpy.getPceSoftConstraints();
211 pathComputationWithConstraints(gnpyHardConstraints, gnpySoftConstraints);
212 AToZDirection atoz = rc.getAtoZDirection();
213 ZToADirection ztoa = rc.getZtoADirection();
214 if (gnpyToCheckFeasiblity(atoz, ztoa,gnpy)) {
215 LOG.info("In pceSendingPceRPC: the new path computed by GNPy is valid");
217 this.message = "Path is calculated by GNPy";
218 this.responseCode = ResponseCodes.RESPONSE_OK;
219 setPathDescription(new PathDescriptionBuilder().setAToZDirection(atoz).setZToADirection(ztoa));
221 LOG.info("In pceSendingPceRPC: the new path computed by GNPy is not valid");
222 this.success = false;
223 this.message = "No path available";
224 this.responseCode = ResponseCodes.RESPONSE_FAILED;
225 setPathDescription(new PathDescriptionBuilder().setAToZDirection(null).setZToADirection(null));
229 private PceGraph patchRerunGraph(PceGraph graph) {
230 LOG.info("In pathComputation patchRerunGraph : rerun Graph with metric = PROPAGATION-DELAY ");
231 graph.setConstrains(pceHardConstraints, pceSoftConstraints);
236 public PathDescriptionBuilder getPathDescription() {
237 return pathDescription;
240 private void setPathDescription(PathDescriptionBuilder pathDescription) {
241 this.pathDescription = pathDescription;
244 public Boolean getSuccess() {
248 public String getMessage() {
252 public String getResponseCode() {
253 return this.responseCode;
256 public GnpyResult getGnpyAtoZ() {
260 public GnpyResult getGnpyZtoA() {