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