92ffaea23da8a9e5fe3cbe6f8a818ce1fadefea5
[transportpce.git] / pce / src / main / java / org / opendaylight / transportpce / pce / graph / InAlgoPathValidator.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 org.jgrapht.GraphPath;
12 import org.jgrapht.alg.shortestpath.PathValidator;
13 import org.opendaylight.yang.gen.v1.http.org.openroadm.network.types.rev181130.OpenroadmLinkType;
14 //import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.networks.network.Link;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17
18 public class InAlgoPathValidator implements PathValidator<String, PceGraphEdge> {
19     /* Logging. */
20     private static final Logger LOG = LoggerFactory.getLogger(PceGraph.class);
21
22     public InAlgoPathValidator() {
23         super();
24     }
25
26     @Override
27     public boolean isValidPath(GraphPath<String, PceGraphEdge> partialPath, PceGraphEdge edge) {
28         int size = partialPath.getEdgeList().size();
29         if (size == 0) {
30             return true;
31         }
32         LOG.debug("InAlgoPathValidator: partialPath size: {} prev edge {} new edge {}",
33             size, edge.link().getlinkType(), partialPath.getEdgeList().get(size - 1).link().getlinkType());
34
35         if ((!checkTurn(partialPath.getEdgeList().get(size - 1).link().getlinkType(), edge.link().getlinkType()))) {
36             return false;
37         } else {
38             return true;
39         }
40     }
41
42     private boolean checkTurn(OpenroadmLinkType prevType, OpenroadmLinkType nextType) {
43
44         if (nextType == OpenroadmLinkType.ADDLINK && prevType != OpenroadmLinkType.XPONDEROUTPUT) {
45             LOG.debug("in checkPath dropped {} {} ", prevType, nextType);
46             return false;
47         }
48
49         if (nextType == OpenroadmLinkType.EXPRESSLINK && prevType != OpenroadmLinkType.ROADMTOROADM) {
50             LOG.debug("in checkPath dropped {} {} ", prevType, nextType);
51             return false;
52         }
53
54         if (nextType == OpenroadmLinkType.DROPLINK && prevType != OpenroadmLinkType.ROADMTOROADM) {
55             LOG.debug("in checkPath dropped {} {} ", prevType, nextType);
56             return false;
57         }
58
59         if (nextType == OpenroadmLinkType.XPONDERINPUT && prevType != OpenroadmLinkType.DROPLINK) {
60             LOG.debug("in checkPath dropped {} {} ", prevType, nextType);
61             return false;
62         }
63
64         if (prevType == OpenroadmLinkType.EXPRESSLINK && nextType != OpenroadmLinkType.ROADMTOROADM) {
65             LOG.debug("in checkPath dropped {} {} ", prevType, nextType);
66             return false;
67         }
68
69         if (prevType == OpenroadmLinkType.ADDLINK && nextType != OpenroadmLinkType.ROADMTOROADM) {
70             LOG.debug("in checkPath dropped {} {} ", prevType, nextType);
71             return false;
72         }
73
74         return true;
75     }
76 }
77