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.controller.md.sal.binding.api.DataBroker;
12 import org.opendaylight.transportpce.pce.PceResult.LocalCause;
13 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.PathComputationRequestInput;
14 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.service.path.rpc.result.PathDescriptionBuilder;
15 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.AToZDirection;
16 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev171017.path.description.ZToADirection;
17 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.RoutingConstraintsSp.PceMetric;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
24 * - path-computation-request
25 * - cancel-resource-reserve.
26 * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange
29 public class PceSendingPceRPCs {
32 private static final Logger LOG = LoggerFactory.getLogger(PceSendingPceRPCs.class);
33 /* define procedure success (or not ). */
34 private PceResult rc = new PceResult();
37 * define type of request<br> <code>true</code> pathcomputation <br>
38 * <code>false</code> cancelresourcereserve .
40 private PathDescriptionBuilder pathDescription;
42 private PathComputationRequestInput input;
43 private DataBroker dataBroker;
45 private PceConstraints pceHardConstraints = new PceConstraints();
46 private PceConstraints pceSoftConstraints = new PceConstraints();
48 public PceSendingPceRPCs() {
49 setPathDescription(null);
52 this.dataBroker = null;
55 public PceSendingPceRPCs(PathComputationRequestInput input, DataBroker dataBroker) {
56 setPathDescription(null);
58 // TODO compliance check to check that input is not empty
60 this.dataBroker = dataBroker;
63 public void cancelResourceReserve() {
64 LOG.info("Wait for 10s til beginning the PCE cancelResourceReserve request");
66 Thread.sleep(10000); // sleep for 10s
67 } catch (InterruptedException e) {
68 LOG.error(e.toString());
70 LOG.info("cancelResourceReserve ...");
73 public void pathComputation() {
74 LOG.info("PathComputation ...");
76 PceConstraintsCalc constraints = new PceConstraintsCalc(input, dataBroker);
77 pceHardConstraints = constraints.getPceHardConstraints();
78 pceSoftConstraints = constraints.getPceSoftConstraints();
81 LOG.info("nwAnalizer ...");
82 PceCalculation nwAnalizer = new PceCalculation(input, dataBroker,
83 pceHardConstraints, pceSoftConstraints, rc);
84 nwAnalizer.calcPath();
85 rc = nwAnalizer.getReturnStructure();
86 if (!rc.getStatus()) {
87 LOG.error("In pathComputation nwAnalizer: result = {}", rc.toString());
91 LOG.info("PceGraph ...");
92 PceGraph graph = new PceGraph(
93 nwAnalizer.getaPceNode(),
94 nwAnalizer.getzPceNode(),
95 nwAnalizer.getAllPceNodes(),
96 pceHardConstraints, pceSoftConstraints, rc);
98 rc = graph.getReturnStructure();
99 if (!rc.getStatus()) {
101 LOG.warn("In pathComputation : Graph return without Path ");
103 // TODO fix. This is quick workaround for algorithm problem
104 if ((rc.getLocalCause() == LocalCause.TOO_HIGH_LATENCY)
105 && (pceHardConstraints.getPceMetrics() == PceMetric.HopCount)
106 && (pceHardConstraints.getMaxLatency() != -1)) {
108 pceHardConstraints.setPceMetrics(PceMetric.PropagationDelay);
109 graph = patchRerunGraph(graph, pceHardConstraints, pceSoftConstraints);
112 if (!rc.getStatus()) {
113 LOG.error("In pathComputation graph.calcPath: result = {}", rc.toString());
118 LOG.info("PcePathDescription ...");
119 PcePathDescription description = new PcePathDescription(
121 nwAnalizer.getAllPceLinks(), rc);
122 description.buildDescriptions();
123 rc = description.getReturnStructure();
124 if (!rc.getStatus()) {
125 LOG.error("In pathComputation description: result = {}", rc.toString());
129 LOG.info("setPathDescription ...");
130 AToZDirection atoz = rc.getAtoZDirection();
131 ZToADirection ztoa = rc.getZtoADirection();
132 if ((atoz == null) || (atoz.getAToZ() == null)) {
134 LOG.error("In pathComputation empty atoz path after description: result = {}", rc.toString());
137 if ((ztoa == null) || (ztoa.getZToA() == null)) {
139 LOG.error("In pathComputation empty ztoa path after description: result = {}", rc.toString());
142 setPathDescription(new PathDescriptionBuilder()
143 .setAToZDirection(atoz)
144 .setZToADirection(ztoa));
145 LOG.info("In pathComputation Graph is Found");
148 private PceGraph patchRerunGraph(PceGraph graph, PceConstraints pceHardCons, PceConstraints pceSoftCons) {
150 LOG.info("In pathComputation patchRerunGraph : rerun Graph with metric = PROPAGATION-DELAY ");
151 graph.setConstrains(pceHardCons, pceSoftCons);
157 public PathDescriptionBuilder getPathDescription() {
158 return pathDescription;
161 private void setPathDescription(PathDescriptionBuilder pathDescription) {
162 this.pathDescription = pathDescription;
165 public Boolean getSuccess() {
166 return rc.getStatus();
169 public String getMessage() {
170 return rc.getMessage();
173 public String getResponseCode() {
174 return rc.getResponseCode();