963ce456413e58fa0ec5b49bd7c8acf222ec61f1
[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.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16
17 public class InAlgoPathValidator implements PathValidator<String, PceGraphEdge> {
18     /* Logging. */
19     private static final Logger LOG = LoggerFactory.getLogger(PceGraph.class);
20
21     public InAlgoPathValidator() {
22         super();
23     }
24
25     @Override
26     public boolean isValidPath(GraphPath<String, PceGraphEdge> partialPath, PceGraphEdge edge) {
27         int size = partialPath.getEdgeList().size();
28         if (size == 0) {
29             return true;
30         }
31         LOG.debug("InAlgoPathValidator: partialPath size: {} prev edge {} new edge {}",
32             size, edge.link().getlinkType(), partialPath.getEdgeList().get(size - 1).link().getlinkType());
33
34         if ((!checkTurn(partialPath.getEdgeList().get(size - 1).link().getlinkType(), edge.link().getlinkType()))) {
35             return false;
36         } else {
37             return true;
38         }
39     }
40
41     private boolean checkTurn(OpenroadmLinkType prevType, OpenroadmLinkType nextType) {
42
43         if (nextType == OpenroadmLinkType.ADDLINK && prevType != OpenroadmLinkType.XPONDEROUTPUT) {
44             LOG.debug("in checkPath dropped {} {} ", prevType, nextType);
45             return false;
46         }
47
48         if (nextType == OpenroadmLinkType.EXPRESSLINK && prevType != OpenroadmLinkType.ROADMTOROADM) {
49             LOG.debug("in checkPath dropped {} {} ", prevType, nextType);
50             return false;
51         }
52
53         if (nextType == OpenroadmLinkType.DROPLINK && prevType != OpenroadmLinkType.ROADMTOROADM) {
54             LOG.debug("in checkPath dropped {} {} ", prevType, nextType);
55             return false;
56         }
57
58         if (nextType == OpenroadmLinkType.XPONDERINPUT && prevType != OpenroadmLinkType.DROPLINK) {
59             LOG.debug("in checkPath dropped {} {} ", prevType, nextType);
60             return false;
61         }
62
63         if (prevType == OpenroadmLinkType.EXPRESSLINK && nextType != OpenroadmLinkType.ROADMTOROADM) {
64             LOG.debug("in checkPath dropped {} {} ", prevType, nextType);
65             return false;
66         }
67
68         if (prevType == OpenroadmLinkType.ADDLINK && nextType != OpenroadmLinkType.ROADMTOROADM) {
69             LOG.debug("in checkPath dropped {} {} ", prevType, nextType);
70             return false;
71         }
72
73         return true;
74     }
75
76 }