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.rev181130.NodeIdType;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.constraints.co.routing.or.general.General;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.constraints.co.routing.or.general.GeneralBuilder;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.constraints.co.routing.or.general.general.Include;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.constraints.co.routing.or.general.general.IncludeBuilder;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.routing.constraints.HardConstraints;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.routing.constraints.HardConstraintsBuilder;
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);
56 public boolean getPathFeasibility() {
57 boolean isFeasible = false;
58 if (response != null) {
59 if (response.getResponseType() instanceof NoPathCase) {
60 LOG.info("In GnpyResult: The path is not feasible ");
61 } else if (response.getResponseType() instanceof PathCase) {
63 LOG.info("In GnpyResult: The path is feasible ");
69 public List<PathRouteObjects> analyzeResult() {
70 List<PathRouteObjects> pathRouteObjectList = null;
71 if (response != null) {
72 if (response.getResponseType() instanceof NoPathCase) {
73 NoPathCase noPathCase = (NoPathCase) response.getResponseType();
74 String noPathType = noPathCase.getNoPath().getNoPath();
75 LOG.info("GNPy: No path - {}", noPathType);
76 if (((noPathType.equals("NO_FEASIBLE_BAUDRATE_WITH_SPACING"))
77 && (noPathType.equals("NO_FEASIBLE_MODE"))) && ((noPathType.equals("MODE_NOT_FEASIBLE"))
78 && (noPathType.equals("NO_SPECTRUM")))) {
79 Collection<PathMetric> pathMetricList = noPathCase.getNoPath()
80 .getPathProperties().nonnullPathMetric().values();
81 LOG.info("GNPy : path is not feasible : {}", noPathType);
82 for (PathMetric pathMetric : pathMetricList) {
83 String metricType = pathMetric.getMetricType().getSimpleName();
84 BigDecimal accumulativeValue = pathMetric.getAccumulativeValue();
85 LOG.info("Metric type {} // AccumulatriveValue {}", metricType, accumulativeValue);
88 } else if (response.getResponseType() instanceof PathCase) {
89 LOG.info("GNPy : path is feasible");
90 PathCase pathCase = (PathCase) response.getResponseType();
91 Collection<PathMetric> pathMetricList = pathCase
92 .getPathProperties().nonnullPathMetric().values();
94 for (PathMetric pathMetric : pathMetricList) {
95 String metricType = pathMetric.getMetricType().getSimpleName();
96 BigDecimal accumulativeValue = pathMetric.getAccumulativeValue();
97 LOG.info("Metric type {} // AccumulatriveValue {}", metricType, accumulativeValue);
100 pathRouteObjectList = pathCase.getPathProperties().getPathRouteObjects();
101 LOG.info("in GnpyResult: finishing the computation of pathRouteObjectList");
104 return pathRouteObjectList;
107 public HardConstraints computeHardConstraintsFromGnpyPath(List<PathRouteObjects> pathRouteObjectList) {
108 HardConstraints hardConstraints = null;
109 // Includes the list of nodes in the GNPy computed path as constraints
111 List<NodeIdType> nodeIdList = new ArrayList<>();
112 for (PathRouteObjects pathRouteObjects : pathRouteObjectList) {
113 if (pathRouteObjects.getPathRouteObject().getType() instanceof NumUnnumHop) {
114 NumUnnumHop numUnnumHop = (NumUnnumHop) pathRouteObjects.getPathRouteObject().getType();
115 String nodeId = numUnnumHop.getNumUnnumHop().getNodeId();
116 if (nodeId != null && this.ordNodeList.contains(nodeId)) {
117 nodeIdList.add(new NodeIdType(nodeId));
122 Include include = new IncludeBuilder().setNodeId(nodeIdList).build();
123 General general = new GeneralBuilder().setInclude(include).build();
124 hardConstraints = new HardConstraintsBuilder().setCoRoutingOrGeneral(general).build();
125 return hardConstraints;
128 public Response getResponse() {