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 LOG.warn("PathComputation: aPceNode '{}' - zPceNode '{}'", nwAnalizer.getaPceNode(), nwAnalizer.getzPceNode());
93 PceGraph graph = new PceGraph(
94 nwAnalizer.getaPceNode(),
95 nwAnalizer.getzPceNode(),
96 nwAnalizer.getAllPceNodes(),
97 pceHardConstraints, pceSoftConstraints, rc);
99 rc = graph.getReturnStructure();
100 if (!rc.getStatus()) {
102 LOG.warn("In pathComputation : Graph return without Path ");
104 // TODO fix. This is quick workaround for algorithm problem
105 if ((rc.getLocalCause() == LocalCause.TOO_HIGH_LATENCY)
106 && (pceHardConstraints.getPceMetrics() == PceMetric.HopCount)
107 && (pceHardConstraints.getMaxLatency() != -1)) {
109 pceHardConstraints.setPceMetrics(PceMetric.PropagationDelay);
110 graph = patchRerunGraph(graph);
113 if (!rc.getStatus()) {
114 LOG.error("In pathComputation graph.calcPath: result = {}", rc.toString());
119 LOG.info("PcePathDescription ...");
120 PcePathDescription description = new PcePathDescription(
122 nwAnalizer.getAllPceLinks(), rc);
123 description.buildDescriptions();
124 rc = description.getReturnStructure();
125 if (!rc.getStatus()) {
126 LOG.error("In pathComputation description: result = {}", rc.toString());
130 LOG.info("setPathDescription ...");
131 AToZDirection atoz = rc.getAtoZDirection();
132 ZToADirection ztoa = rc.getZtoADirection();
133 if ((atoz == null) || (atoz.getAToZ() == null)) {
135 LOG.error("In pathComputation empty atoz path after description: result = {}", rc.toString());
138 if ((ztoa == null) || (ztoa.getZToA() == null)) {
140 LOG.error("In pathComputation empty ztoa path after description: result = {}", rc.toString());
143 setPathDescription(new PathDescriptionBuilder()
144 .setAToZDirection(atoz)
145 .setZToADirection(ztoa));
146 LOG.info("In pathComputation Graph is Found");
149 private PceGraph patchRerunGraph(PceGraph graph) {
150 LOG.info("In pathComputation patchRerunGraph : rerun Graph with metric = PROPAGATION-DELAY ");
151 graph.setConstrains(pceHardConstraints, pceSoftConstraints);
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();