Adapt PCE code for OTN services
[transportpce.git] / pce / src / main / java / org / opendaylight / transportpce / pce / constraints / PceConstraints.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 package org.opendaylight.transportpce.pce.constraints;
9
10 import java.util.ArrayList;
11 import java.util.List;
12
13 import org.opendaylight.transportpce.pce.networkanalyzer.PceOpticalNode;
14 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev171017.RoutingConstraintsSp;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17
18 // internal type after parsing
19 public class PceConstraints {
20     /* Logging. */
21     private static final Logger LOG = LoggerFactory.getLogger(PceConstraints.class);
22
23     // TODO. for now metrics are set into hard structure
24     private RoutingConstraintsSp.PceMetric pceMetrics = RoutingConstraintsSp.PceMetric.HopCount;
25     private Long maxLatency = (long) -1;
26
27     // Structure related to  EXCLUDE constraints
28     // Nodes/CLLI/SRLG lists might consist of two types of elements : (1)from diversity constraints (2)from exclude list
29     // e.g.: nodesToExclude - topo-level nodes IDs - comes from diversity constraints
30     //     : supNodesToExclude - supporting nodes IDs - comes from exclude list
31     // "mapConstraints" class converts diversity elements into correct names
32     private List<String> nodesToExclude = new ArrayList<String>();
33     private List<String> supNodesToExclude = new ArrayList<String>();
34
35     private List<Long> srlgToExclude = new ArrayList<Long>();
36     private List<String> srlgLinksToExclude = new ArrayList<String>();
37
38     private List<String> clliToExclude = new ArrayList<String>();
39     private List<String> clliNodesToExclude = new ArrayList<String>();
40
41     ///Structures related to INCLUDE constraints
42     private List<String> nodesToInclude = new ArrayList<String>();
43     private List<PceOpticalNode> pceNodesToInclude = new ArrayList<PceOpticalNode>();
44     private List<ResourcePair> listToInclude = new ArrayList<ResourcePair>();
45
46     private List<String> srlgNames = new ArrayList<String>();
47
48     public enum ResourceType {
49         NONE, NODE, SRLG, CLLI;
50     }
51
52     public RoutingConstraintsSp.PceMetric getPceMetrics() {
53         return pceMetrics;
54     }
55
56     public void setPceMetrics(RoutingConstraintsSp.PceMetric pceMetrics) {
57         this.pceMetrics = pceMetrics;
58     }
59
60     // Latency of path is used by Graph to validate path
61     // if -1 , latency is not applicable (not mentioned in constraints)
62     public Long getMaxLatency() {
63         LOG.debug("in Pceconstraints getMaxLatency = {}", maxLatency);
64         return maxLatency;
65     }
66
67     public void setMaxLatency(Long maxLatency) {
68         LOG.debug("in Pceconstraints setMaxLatency = {}", maxLatency);
69         this.maxLatency = maxLatency;
70     }
71
72     // Exclude nodes / SRLD / CLLI
73
74     public List<String> getExcludeSupNodes() {
75         LOG.debug("in Pceconstraints getExcludeSupNodes size = {}", supNodesToExclude.size());
76         return supNodesToExclude;
77     }
78
79     public void setExcludeSupNodes(List<String> supNodes) {
80         LOG.debug("in Pceconstraints setExcludeSupNodes size = {}", supNodes.size());
81         supNodesToExclude.addAll(supNodes);
82     }
83
84     public List<Long> getExcludeSRLG() {
85         LOG.debug("in Pceconstraints getExcludeSRLG size = {}", srlgToExclude.size());
86         return srlgToExclude;
87     }
88
89     public void setExcludeSRLG(List<Long> srlg) {
90         LOG.info("in Pceconstraints setExcludeSRLG size = {}", srlg.size());
91         srlgToExclude.addAll(srlg);
92     }
93
94     public List<String> getExcludeCLLI() {
95         LOG.debug("in Pceconstraints getExcludeCLLI size = {}", clliToExclude.size());
96         return clliToExclude;
97     }
98
99     public void setExcludeCLLI(List<String> clli) {
100         LOG.debug("in Pceconstraints setExcludeCLLI size = {}", clli.size());
101         clliToExclude.addAll(clli);
102     }
103
104     // CLLI nodes are defined as result of 'diversity 'node'' constraints
105     // clliNodesToExclude are saved as nodes, during NW analysis the relevant
106     // CLLI IDs are added to clliToExclude
107     public List<String> getExcludeClliNodes() {
108         LOG.info("in Pceconstraints getExcludeClliNodes size = {}", clliNodesToExclude.size());
109         return clliNodesToExclude;
110     }
111
112     public void setExcludeClliNodes(List<String> clli) {
113         LOG.debug("in Pceconstraints setExcludeCLLI size = {}", clli.size());
114         clliNodesToExclude.addAll(clli);
115     }
116
117     public List<String> getExcludeSrlgLinks() {
118         LOG.info("in Pceconstraints getExcludeSrlgNodes size = {}", srlgLinksToExclude.size());
119         return srlgLinksToExclude;
120     }
121
122     public void setExcludeSrlgLinks(List<String> srlg) {
123         LOG.debug("in Pceconstraints setExcludeSRLG size = {}", srlg.size());
124         srlgLinksToExclude.addAll(srlg);
125     }
126
127     public List<String> getExcludeNodes() {
128         LOG.info("in Pceconstraints getExcludeNodes size = {}", nodesToExclude.size());
129         return nodesToExclude;
130     }
131
132     public void setExcludeNodes(List<String> nodes) {
133         LOG.debug("in Pceconstraints setExcludeNodes size = {}", nodes.size());
134         nodesToExclude.addAll(nodes);
135     }
136
137     // Include nodes
138     public List<String> getIncludeNodes() {
139         LOG.debug("in Pceconstraints getIncludeNodes size = {}", nodesToInclude.size());
140         return nodesToInclude;
141     }
142
143     public void setIncludeNodes(List<String> nodes) {
144         LOG.debug("in Pceconstraints setIncludeNodes size = {}", nodes.size());
145         nodesToInclude.addAll(nodes);
146     }
147
148     public List<PceOpticalNode> getIncludePceNodes() {
149         LOG.debug("in Pceconstraints getIncludePceNodes size = {}", pceNodesToInclude.size());
150         return pceNodesToInclude;
151     }
152
153     public void setIncludePceNode(PceOpticalNode node) {
154         LOG.info("in Pceconstraints setIncludePceNode new node = {}", node.toString());
155         this.pceNodesToInclude.add(node);
156     }
157
158     public class ResourcePair {
159         public ResourcePair(ResourceType type, String name) {
160             super();
161             this.type = type;
162             this.name = name;
163         }
164
165         private ResourceType type = ResourceType.NODE;
166
167         private String name = "";
168
169         public ResourceType getType() {
170             return type;
171         }
172
173         public String getName() {
174             return name;
175         }
176
177     }
178
179     public List<ResourcePair> getListToInclude() {
180         return listToInclude;
181     }
182
183     public void setListToInclude(ResourcePair elementToInclude) {
184         this.listToInclude.add(elementToInclude);
185         switch (elementToInclude.type) {
186             case SRLG:
187                 srlgNames.add(elementToInclude.name);
188                 break;
189             default:
190                 break;
191         }
192     }
193
194     public List<String> getSRLGnames() {
195         return srlgNames;
196     }
197 }