2 * Copyright © 2017 AT&T, 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.graph;
11 import java.util.ArrayList;
12 import java.util.List;
14 import org.jgrapht.GraphPath;
15 import org.jgrapht.alg.shortestpath.PathValidator;
16 import org.opendaylight.transportpce.pce.constraints.PceConstraints;
17 import org.opendaylight.transportpce.pce.constraints.PceConstraints.ResourcePair;
18 import org.opendaylight.transportpce.pce.networkanalyzer.PceNode;
19 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev181130.OpenroadmLinkType;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
23 public class InAlgoPathValidator implements PathValidator<String, PceGraphEdge> {
25 private static final Logger LOG = LoggerFactory.getLogger(PceGraph.class);
27 private PceConstraints pceHardConstraints = null;
28 private PceNode zendNode = null;
30 public InAlgoPathValidator(PceConstraints pceHardConstraints, PceNode zendNode) {
32 this.pceHardConstraints = pceHardConstraints;
33 this.zendNode = zendNode;
37 public boolean isValidPath(GraphPath<String, PceGraphEdge> partialPath, PceGraphEdge edge) {
38 int size = partialPath.getEdgeList().size();
42 LOG.debug("InAlgoPathValidator: partialPath size: {} prev edge {} new edge {}",
43 size, edge.link().getlinkType(), partialPath.getEdgeList().get(size - 1).link().getlinkType());
45 if ((!checkTurn(partialPath.getEdgeList().get(size - 1).link().getlinkType(), edge.link().getlinkType()))
46 || (!checkLimits(partialPath, edge, pceHardConstraints))
47 || (!checkInclude(partialPath, edge, zendNode, pceHardConstraints))) {
54 private boolean checkTurn(OpenroadmLinkType prevType, OpenroadmLinkType nextType) {
56 if (nextType == OpenroadmLinkType.ADDLINK && prevType != OpenroadmLinkType.XPONDEROUTPUT) {
57 LOG.debug("in checkPath dropped {} {} ", prevType, nextType);
61 if (nextType == OpenroadmLinkType.EXPRESSLINK && prevType != OpenroadmLinkType.ROADMTOROADM) {
62 LOG.debug("in checkPath dropped {} {} ", prevType, nextType);
66 if (nextType == OpenroadmLinkType.DROPLINK && prevType != OpenroadmLinkType.ROADMTOROADM) {
67 LOG.debug("in checkPath dropped {} {} ", prevType, nextType);
71 if (nextType == OpenroadmLinkType.XPONDERINPUT && prevType != OpenroadmLinkType.DROPLINK) {
72 LOG.debug("in checkPath dropped {} {} ", prevType, nextType);
76 if (prevType == OpenroadmLinkType.EXPRESSLINK && nextType != OpenroadmLinkType.ROADMTOROADM) {
77 LOG.debug("in checkPath dropped {} {} ", prevType, nextType);
81 if (prevType == OpenroadmLinkType.ADDLINK && nextType != OpenroadmLinkType.ROADMTOROADM) {
82 LOG.debug("in checkPath dropped {} {} ", prevType, nextType);
90 * this method should be added to JgraphT as accumulated values inside path
91 * (RankingPathElementList)
93 private boolean checkLimits(GraphPath<String, PceGraphEdge> partialPath,
94 PceGraphEdge edge, PceConstraints pceHardConstraintsInput) {
96 Long latencyConstraint = pceHardConstraintsInput.getMaxLatency();
97 if (latencyConstraint > 0) {
98 long newLatency = Math.round(calcLatency(partialPath) + edge.link().getLatency());
99 if (newLatency > latencyConstraint) {
100 LOG.warn("In validateLatency: AtoZ path is dropped because of MAX LATENCY {} > {}",
101 newLatency, latencyConstraint);
109 private double calcLatency(GraphPath<String, PceGraphEdge> path) {
111 for (PceGraphEdge edge : path.getEdgeList()) {
112 latency = latency + edge.link().getLatency();
118 * checkInclude this method ensures the path is going over path elements
119 * to be included, alway check target node in the new edge
122 private boolean checkInclude(GraphPath<String, PceGraphEdge> partialPath,
123 PceGraphEdge edge, PceNode zendNodeInput,
124 PceConstraints pceHardConstraintsInput) {
126 List<ResourcePair> listToInclude = pceHardConstraintsInput.getListToInclude();
127 if (listToInclude.isEmpty()) {
131 // run this check only for the last edge of path
132 if (!edge.link().getDestId().getValue().equals(zendNodeInput.getNodeId().getValue())) {
135 List<PceGraphEdge> pathEdges = partialPath.getEdgeList();
137 LOG.info(" in checkInclude vertex list: [{}]", partialPath.getVertexList());
139 List<String> listOfElementsSubNode = new ArrayList<String>();
140 listOfElementsSubNode.add(pathEdges.get(0).link().getsourceSupNodeId());
141 listOfElementsSubNode.addAll(listOfElementsBuild(pathEdges, PceConstraints.ResourceType.NODE));
143 List<String> listOfElementsCLLI = new ArrayList<String>();
144 listOfElementsCLLI.add(pathEdges.get(0).link().getsourceCLLI());
145 listOfElementsCLLI.addAll(listOfElementsBuild(pathEdges, PceConstraints.ResourceType.CLLI));
147 List<String> listOfElementsSRLG = new ArrayList<String>();
148 // first link is XPONDEROUTPUT, no SRLG for it
149 listOfElementsSRLG.add("NONE");
150 listOfElementsSRLG.addAll(listOfElementsBuild(pathEdges, PceConstraints.ResourceType.SRLG));
152 // validation: check each type for each element
153 for (ResourcePair next : listToInclude) {
155 switch (next.getType()) {
157 if (listOfElementsSubNode.contains(next.getName())) {
158 indx = listOfElementsSubNode.indexOf(next.getName());
162 if (listOfElementsSRLG.contains(next.getName())) {
163 indx = listOfElementsSRLG.indexOf(next.getName());
167 if (listOfElementsCLLI.contains(next.getName())) {
168 indx = listOfElementsCLLI.indexOf(next.getName());
172 LOG.warn(" in checkInclude vertex list unsupported resource type: [{}]", next.getType());
176 LOG.debug(" in checkInclude stopped : {} ", next.getName());
180 LOG.debug(" in checkInclude next found {} in {}", next.getName(), partialPath.getVertexList());
182 listOfElementsSubNode.subList(0, indx).clear();
183 listOfElementsCLLI.subList(0, indx).clear();
184 listOfElementsSRLG.subList(0, indx).clear();
187 LOG.info(" in checkInclude passed : {} ", partialPath.getVertexList());
191 private List<String> listOfElementsBuild(List<PceGraphEdge> pathEdges, PceConstraints.ResourceType type) {
192 List<String> listOfElements = new ArrayList<String>();
194 for (PceGraphEdge link: pathEdges) {
197 listOfElements.add(link.link().getdestSupNodeId());
200 listOfElements.add(link.link().getdestCLLI());
203 if (link.link().getlinkType() != OpenroadmLinkType.ROADMTOROADM) {
204 listOfElements.add("NONE");
208 // srlg of link is List<Long>. But in this algo we need string representation of one SRLG
209 // this should be any SRLG mentioned in include constraints if any of them if mentioned
210 boolean found = false;
211 for (Long srlg : link.link().getsrlgList()) {
212 String srlgStr = String.valueOf(srlg);
213 if (pceHardConstraints.getSRLGnames().contains(srlgStr)) {
214 listOfElements.add(srlgStr);
215 LOG.info("listOfElementsBuild. FOUND SRLG {} in link {}", srlgStr, link.link().toString());
221 // there is no specific srlg to include. thus add to list just the first one
222 listOfElements.add("NONE");
226 LOG.debug("listOfElementsBuild unsupported resource type");
230 return listOfElements;