PCE update to support constraints
[transportpce.git] / pce / src / main / java / org / opendaylight / transportpce / pce / graph / PostAlgoPathValidator.java
1 /*
2  * Copyright © 2017 AT&T, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.transportpce.pce.graph;
10
11 import java.util.Map;
12
13 import org.jgrapht.GraphPath;
14 import org.opendaylight.transportpce.common.ResponseCodes;
15 import org.opendaylight.transportpce.pce.networkanalyzer.PceNode;
16 import org.opendaylight.transportpce.pce.networkanalyzer.PceResult;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 public class PostAlgoPathValidator {
22     /* Logging. */
23     private static final Logger LOG = LoggerFactory.getLogger(PceGraph.class);
24
25     // TODO hard-coded 96
26     private static final int MAX_WAWELENGTH = 96;
27
28     public PceResult checkPath(GraphPath<String, PceGraphEdge> path,
29             Map<NodeId, PceNode> allPceNodes, PceResult pceResult) {
30
31         if (path.getEdgeList().size() == 0) {
32             pceResult.setRC(ResponseCodes.RESPONSE_FAILED);
33             return pceResult;
34         }
35
36         // choose wavelength available in all nodes of the path
37         pceResult.setRC(ResponseCodes.RESPONSE_FAILED);
38         Long waveL = chooseWavelength(path, allPceNodes);
39         if (waveL > 0) {
40             pceResult.setResultWavelength(waveL);
41             pceResult.setRC(ResponseCodes.RESPONSE_OK);
42             LOG.info("In PostAlgoPathValidator: chooseWavelength WL found {} {}", waveL, path.toString());
43         }
44
45         // TODO here other post algo validations can be added
46         // more data can be sent to PceGraph module via PceResult structure if
47         // required
48         stubCheckOSNR(path);
49
50         return pceResult;
51     }
52
53     private Long chooseWavelength(GraphPath<String, PceGraphEdge> path, Map<NodeId, PceNode> allPceNodes) {
54         Long wavelength = -1L;
55
56         for (long i = 1; i <= MAX_WAWELENGTH; i++) {
57             boolean completed = true;
58             LOG.debug("In chooseWavelength: {} {}", path.getLength(), path.toString());
59             for (PceGraphEdge edge : path.getEdgeList()) {
60                 LOG.debug("In chooseWavelength: source {} ", edge.link().getSourceId().toString());
61                 PceNode pceNode = allPceNodes.get(edge.link().getSourceId());
62                 if (!pceNode.checkWL(i)) {
63                     completed = false;
64                     break;
65                 }
66             }
67             if (completed) {
68                 wavelength = i;
69                 break;
70             }
71         }
72         return wavelength;
73     }
74
75     private boolean stubCheckOSNR(GraphPath<String, PceGraphEdge> path) {
76         double localOsnr = 0L;
77         for (PceGraphEdge edge : path.getEdgeList()) {
78             localOsnr = localOsnr + edge.link().getosnr();
79         }
80         LOG.info("In OSNR Stub: {}", localOsnr);
81         return true;
82     }
83 }