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