fix PCE vulnerabilities identified in sonar
[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.PceNode;
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     /////////////// EXCLUDE ///////////////////
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     private List<String> nodesToInclude = new ArrayList<String>();
41     private List<PceNode> pceNodesToInclude = new ArrayList<PceNode>();
42
43     public static final Long CONST_OSNR = 1L;
44     private double maxOSNR = (CONST_OSNR / (Math.pow(10, (24 / 10.0))));
45
46     /**.
47      * /////////////// INCLUDE CONSTRAINTS.///////////////////
48      */
49     private List<ResourcePair> listToInclude = new ArrayList<ResourcePair>();
50     private List<String> srlgNames = new ArrayList<String>();
51
52     public enum ResourceType {
53         NONE, NODE, SRLG, CLLI;
54     }
55
56     public RoutingConstraintsSp.PceMetric getPceMetrics() {
57         return pceMetrics;
58     }
59
60     public void setPceMetrics(RoutingConstraintsSp.PceMetric pceMetrics) {
61         this.pceMetrics = pceMetrics;
62     }
63
64     // Latency of path is used by Graph to validate path
65     // if -1 , latency is not applicable (not mentioned in constraints)
66     public Long getMaxLatency() {
67         LOG.debug("in Pceconstraints getMaxLatency = {}", maxLatency);
68         return maxLatency;
69     }
70
71     public void setMaxLatency(Long maxLatency) {
72         LOG.debug("in Pceconstraints setMaxLatency = {}", maxLatency);
73         this.maxLatency = maxLatency;
74     }
75
76     // Exclude nodes / SRLD / CLLI
77
78     public List<String> getExcludeSupNodes() {
79         LOG.debug("in Pceconstraints getExcludeSupNodes size = {}", supNodesToExclude.size());
80         return supNodesToExclude;
81     }
82
83     public void setExcludeSupNodes(List<String> supNodes) {
84         LOG.debug("in Pceconstraints setExcludeSupNodes size = {}", supNodes.size());
85         supNodesToExclude.addAll(supNodes);
86     }
87
88     public List<Long> getExcludeSRLG() {
89         LOG.debug("in Pceconstraints getExcludeSRLG size = {}", srlgToExclude.size());
90         return srlgToExclude;
91     }
92
93     public void setExcludeSRLG(List<Long> srlg) {
94         LOG.info("in Pceconstraints setExcludeSRLG size = {}", srlg.size());
95         srlgToExclude.addAll(srlg);
96     }
97
98     public List<String> getExcludeCLLI() {
99         LOG.debug("in Pceconstraints getExcludeCLLI size = {}", clliToExclude.size());
100         return clliToExclude;
101     }
102
103     public void setExcludeCLLI(List<String> clli) {
104         LOG.debug("in Pceconstraints setExcludeCLLI size = {}", clli.size());
105         clliToExclude.addAll(clli);
106     }
107
108     // CLLI nodes are defined as result of 'diversity 'node'' constraints
109     // clliNodesToExclude are saved as nodes, during NW analysis the relevant
110     // CLLI IDs are added to clliToExclude
111     public List<String> getExcludeClliNodes() {
112         LOG.info("in Pceconstraints getExcludeClliNodes size = {}", clliNodesToExclude.size());
113         return clliNodesToExclude;
114     }
115
116     public void setExcludeClliNodes(List<String> clli) {
117         LOG.debug("in Pceconstraints setExcludeCLLI size = {}", clli.size());
118         clliNodesToExclude.addAll(clli);
119     }
120
121     public List<String> getExcludeSrlgLinks() {
122         LOG.info("in Pceconstraints getExcludeSrlgNodes size = {}", srlgLinksToExclude.size());
123         return srlgLinksToExclude;
124     }
125
126     public void setExcludeSrlgLinks(List<String> srlg) {
127         LOG.debug("in Pceconstraints setExcludeSRLG size = {}", srlg.size());
128         srlgLinksToExclude.addAll(srlg);
129     }
130
131     public List<String> getExcludeNodes() {
132         LOG.info("in Pceconstraints getExcludeNodes size = {}", nodesToExclude.size());
133         return nodesToExclude;
134     }
135
136     public void setExcludeNodes(List<String> nodes) {
137         LOG.debug("in Pceconstraints setExcludeNodes size = {}", nodes.size());
138         nodesToExclude.addAll(nodes);
139     }
140
141     // Include nodes
142     public List<String> getIncludeNodes() {
143         LOG.debug("in Pceconstraints getIncludeNodes size = {}", nodesToInclude.size());
144         return nodesToInclude;
145     }
146
147     public void setIncludeNodes(List<String> nodes) {
148         LOG.debug("in Pceconstraints setIncludeNodes size = {}", nodes.size());
149         nodesToInclude.addAll(nodes);
150     }
151
152     public List<PceNode> getIncludePceNodes() {
153         LOG.debug("in Pceconstraints getIncludePceNodes size = {}", pceNodesToInclude.size());
154         return pceNodesToInclude;
155     }
156
157     public void setIncludePceNode(PceNode node) {
158         LOG.info("in Pceconstraints setIncludePceNode new node = {}", node.toString());
159         this.pceNodesToInclude.add(node);
160     }
161
162     public Double getMaxOSNR() {
163         LOG.debug("in Pceconstraints getMaxOSNR = {}", maxOSNR);
164         return maxOSNR;
165     }
166
167     public class ResourcePair {
168         public ResourcePair(ResourceType type, String name) {
169             super();
170             this.type = type;
171             this.name = name;
172         }
173
174         private ResourceType type = ResourceType.NODE;
175
176         private String name = "";
177
178         public ResourceType getType() {
179             return type;
180         }
181
182         public String getName() {
183             return name;
184         }
185
186     }
187
188     public List<ResourcePair> getListToInclude() {
189         return listToInclude;
190     }
191
192     public void setListToInclude(ResourcePair elementToInclude) {
193         this.listToInclude.add(elementToInclude);
194         switch (elementToInclude.type) {
195             case SRLG:
196                 srlgNames.add(elementToInclude.name);
197                 break;
198             default:
199                 break;
200         }
201     }
202
203     public List<String> getSRLGnames() {
204         return srlgNames;
205     }
206 }