2 * Copyright © 2018 Orange, Inc. 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.gnpy;
11 import java.math.BigDecimal;
12 import java.util.ArrayList;
13 import java.util.Collection;
14 import java.util.List;
15 import org.opendaylight.yang.gen.v1.gnpy.path.rev220221.Result;
16 import org.opendaylight.yang.gen.v1.gnpy.path.rev220221.explicit.route.hop.type.NumUnnumHop;
17 import org.opendaylight.yang.gen.v1.gnpy.path.rev220221.generic.path.properties.path.properties.PathMetric;
18 import org.opendaylight.yang.gen.v1.gnpy.path.rev220221.generic.path.properties.path.properties.PathRouteObjects;
19 import org.opendaylight.yang.gen.v1.gnpy.path.rev220221.result.Response;
20 import org.opendaylight.yang.gen.v1.gnpy.path.rev220221.result.response.response.type.NoPathCase;
21 import org.opendaylight.yang.gen.v1.gnpy.path.rev220221.result.response.response.type.PathCase;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.node.types.rev210528.NodeIdType;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.Include;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.IncludeBuilder;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.routing.constraints.HardConstraints;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.routing.constraints.HardConstraintsBuilder;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
31 * Class for analyzing the result sent by GNPy.
33 * @author Ahmed Triki ( ahmed.triki@orange.com )
37 public class GnpyResult {
39 private static final Logger LOG = LoggerFactory.getLogger(GnpyResult.class);
40 private Response response = null;
41 private List<String> ordNodeList = new ArrayList<>();
43 public GnpyResult(Result result, GnpyTopoImpl gnpyTopo) throws GnpyException {
44 this.ordNodeList = gnpyTopo.getElementsList();
45 List<Response> responses = new ArrayList<>(result.nonnullResponse().values());
46 if (responses.isEmpty()) {
47 throw new GnpyException("In GnpyResult: the response from GNpy is null!");
49 LOG.info("The response id is {}; ", responses.get(0).getResponseId());
50 this.response = responses.get(0);
54 public boolean getPathFeasibility() {
55 boolean isFeasible = false;
56 if (response != null) {
57 if (response.getResponseType() instanceof NoPathCase) {
58 LOG.info("In GnpyResult: The path is not feasible ");
59 } else if (response.getResponseType() instanceof PathCase) {
61 LOG.info("In GnpyResult: The path is feasible ");
67 public List<PathRouteObjects> analyzeResult() {
68 List<PathRouteObjects> pathRouteObjectList = null;
69 if (response != null) {
70 if (response.getResponseType() instanceof NoPathCase) {
71 NoPathCase noPathCase = (NoPathCase) response.getResponseType();
72 String noPathType = noPathCase.getNoPath().getNoPath();
73 LOG.info("GNPy: No path - {}", noPathType);
74 if (((noPathType.equals("NO_FEASIBLE_BAUDRATE_WITH_SPACING"))
75 && (noPathType.equals("NO_FEASIBLE_MODE"))) && ((noPathType.equals("MODE_NOT_FEASIBLE"))
76 && (noPathType.equals("NO_SPECTRUM")))) {
77 Collection<PathMetric> pathMetricList = noPathCase.getNoPath()
78 .getPathProperties().nonnullPathMetric().values();
79 LOG.info("GNPy : path is not feasible : {}", noPathType);
80 for (PathMetric pathMetric : pathMetricList) {
81 String metricType = pathMetric.getMetricType().getSimpleName();
82 BigDecimal accumulativeValue = pathMetric.getAccumulativeValue();
83 LOG.info("Metric type {} // AccumulatriveValue {}", metricType, accumulativeValue);
86 } else if (response.getResponseType() instanceof PathCase) {
87 LOG.info("GNPy : path is feasible");
88 PathCase pathCase = (PathCase) response.getResponseType();
89 Collection<PathMetric> pathMetricList = pathCase
90 .getPathProperties().nonnullPathMetric().values();
92 for (PathMetric pathMetric : pathMetricList) {
93 String metricType = pathMetric.getMetricType().getSimpleName();
94 BigDecimal accumulativeValue = pathMetric.getAccumulativeValue();
95 LOG.info("Metric type {} // AccumulatriveValue {}", metricType, accumulativeValue);
98 pathRouteObjectList = pathCase.getPathProperties().getPathRouteObjects();
99 LOG.info("in GnpyResult: finishing the computation of pathRouteObjectList");
102 return pathRouteObjectList;
105 public HardConstraints computeHardConstraintsFromGnpyPath(List<PathRouteObjects> pathRouteObjectList) {
106 HardConstraints hardConstraints = null;
107 // Includes the list of nodes in the GNPy computed path as constraints
109 List<NodeIdType> nodeIdList = new ArrayList<>();
110 for (PathRouteObjects pathRouteObjects : pathRouteObjectList) {
111 if (pathRouteObjects.getPathRouteObject().getType() instanceof NumUnnumHop) {
112 NumUnnumHop numUnnumHop = (NumUnnumHop) pathRouteObjects.getPathRouteObject().getType();
113 String nodeId = numUnnumHop.getNumUnnumHop().getNodeId();
114 if (nodeId != null && this.ordNodeList.contains(nodeId)) {
115 nodeIdList.add(new NodeIdType(nodeId));
120 Include include = new IncludeBuilder().setNodeId(nodeIdList).build();
121 hardConstraints = new HardConstraintsBuilder().setInclude(include).build();
122 return hardConstraints;
125 public Response getResponse() {