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.util.ArrayList;
12 import java.util.Collection;
13 import java.util.List;
14 import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.Result;
15 import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.explicit.route.hop.type.NumUnnumHop;
16 import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.generic.path.properties.path.properties.PathMetric;
17 import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.generic.path.properties.path.properties.PathRouteObjects;
18 import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.result.Response;
19 import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.result.response.response.type.NoPathCase;
20 import org.opendaylight.yang.gen.v1.gnpy.path.rev220615.result.response.response.type.PathCase;
21 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.node.types.rev210528.NodeIdType;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.constraints.Include;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.constraints.IncludeBuilder;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.routing.constraints.HardConstraints;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.routing.constraints.HardConstraintsBuilder;
26 import org.opendaylight.yangtools.yang.common.Decimal64;
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);
53 public boolean getPathFeasibility() {
54 boolean isFeasible = false;
55 if (response != null) {
56 if (response.getResponseType() instanceof NoPathCase) {
57 LOG.info("In GnpyResult: The path is not feasible ");
58 } else if (response.getResponseType() instanceof PathCase) {
60 LOG.info("In GnpyResult: The path is feasible ");
66 public List<PathRouteObjects> analyzeResult() {
67 List<PathRouteObjects> pathRouteObjectList = null;
68 if (response != null) {
69 if (response.getResponseType() instanceof NoPathCase) {
70 NoPathCase noPathCase = (NoPathCase) response.getResponseType();
71 String noPathType = noPathCase.getNoPath().getNoPath();
72 LOG.info("GNPy: No path - {}", noPathType);
73 if (((noPathType.equals("NO_FEASIBLE_BAUDRATE_WITH_SPACING"))
74 && (noPathType.equals("NO_FEASIBLE_MODE"))) && ((noPathType.equals("MODE_NOT_FEASIBLE"))
75 && (noPathType.equals("NO_SPECTRUM")))) {
76 Collection<PathMetric> pathMetricList = noPathCase.getNoPath()
77 .getPathProperties().nonnullPathMetric().values();
78 LOG.info("GNPy : path is not feasible : {}", noPathType);
79 for (PathMetric pathMetric : pathMetricList) {
80 String metricType = pathMetric.getMetricType().toString();
81 Decimal64 accumulativeValue = pathMetric.getAccumulativeValue();
82 LOG.info("Metric type {} // AccumulatriveValue {}", metricType, accumulativeValue);
85 } else if (response.getResponseType() instanceof PathCase) {
86 LOG.info("GNPy : path is feasible");
87 PathCase pathCase = (PathCase) response.getResponseType();
88 Collection<PathMetric> pathMetricList = pathCase
89 .getPathProperties().nonnullPathMetric().values();
91 for (PathMetric pathMetric : pathMetricList) {
92 String metricType = pathMetric.getMetricType().toString();
93 Decimal64 accumulativeValue = pathMetric.getAccumulativeValue();
94 LOG.info("Metric type {} // AccumulatriveValue {}", metricType, accumulativeValue);
97 pathRouteObjectList = pathCase.getPathProperties().getPathRouteObjects();
98 LOG.info("in GnpyResult: finishing the computation of pathRouteObjectList");
101 return pathRouteObjectList;
104 public HardConstraints computeHardConstraintsFromGnpyPath(List<PathRouteObjects> pathRouteObjectList) {
105 HardConstraints hardConstraints = null;
106 // Includes the list of nodes in the GNPy computed path as constraints
108 List<NodeIdType> nodeIdList = new ArrayList<>();
109 for (PathRouteObjects pathRouteObjects : pathRouteObjectList) {
110 if (pathRouteObjects.getPathRouteObject().getType() instanceof NumUnnumHop) {
111 NumUnnumHop numUnnumHop = (NumUnnumHop) pathRouteObjects.getPathRouteObject().getType();
112 String nodeId = numUnnumHop.getNumUnnumHop().getNodeId();
113 if (nodeId != null && this.ordNodeList.contains(nodeId)) {
114 nodeIdList.add(new NodeIdType(nodeId));
119 Include include = new IncludeBuilder().setNodeId(nodeIdList).build();
120 hardConstraints = new HardConstraintsBuilder().setInclude(include).build();
121 return hardConstraints;
124 public Response getResponse() {