Merge "Randomize port to allow concurrent execution"
[bgpcep.git] / pcep / api / src / main / java / org / opendaylight / protocol / pcep / object / PCEPGlobalConstraintsObject.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, 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.protocol.pcep.object;
9
10 import java.util.Collections;
11 import java.util.List;
12
13 import org.opendaylight.protocol.pcep.PCEPObject;
14 import org.opendaylight.protocol.pcep.PCEPTlv;
15 import com.google.common.base.Objects.ToStringHelper;
16
17 /**
18  * The GLOBAL CONSTRAINTS Object is used in a PCReq message to specify the
19  * necessary global constraints that should be applied to all individual path
20  * computations for a global concurrent path optimization request.
21  *
22  * @see <a href="http://tools.ietf.org/html/rfc5557#section-5.5">GLOBAL
23  *      CONSTRAINTS (GC) Object</a>
24  */
25 public class PCEPGlobalConstraintsObject extends PCEPObject {
26
27     private final short maxHop;
28     private final short maxUtilization;
29     private final short minUtilization;
30     private final short overBookingFactor;
31
32     private List<PCEPTlv> tlvs;
33
34     /**
35      * Constructs Global Constraints Object with all mandatory fields.
36      *
37      * @param maxhop
38      *            8-bit integer
39      * @param maxUtilization
40      *            8-bit integer between 0 and 100
41      * @param minUtilization
42      *            8-bit integer between 0 and 100
43      * @param overBookingFactor
44      *            8-bit integer
45      * @param processed
46      *            boolean
47      * @param ignored
48      *            boolean
49      */
50     public PCEPGlobalConstraintsObject(short maxhop, short maxUtilization, short minUtilization, short overBookingFactor, boolean processed, boolean ignored) {
51         this(maxhop, maxUtilization, minUtilization, overBookingFactor, null, processed, ignored);
52     }
53
54     /**
55      * Constructs Global Constraints Object with all mandatory fields and
56      * optional list of tlvs.
57      *
58      * @param maxhop
59      *            8-bit integer
60      * @param maxUtilization
61      *            8-bit integer between 0 and 100
62      * @param minUtilization
63      *            8-bit integer between 0 and 100
64      * @param overBookingFactor
65      *            8-bit integer
66      * @param tlvs
67      *            list of tlvs
68      * @param processed
69      *            boolean
70      * @param ignored
71      *            boolean
72      */
73     public PCEPGlobalConstraintsObject(short maxhop, short maxUtilization, short minUtilization, short overBookingFactor, List<PCEPTlv> tlvs,
74             boolean processed, boolean ignored) {
75         super(processed, ignored);
76         this.maxHop = maxhop;
77
78         if (maxUtilization < 0 || maxUtilization > 100)
79             throw new IllegalArgumentException("Maximu utilization can be only between 0 and 100. Passed: " + maxUtilization);
80         this.maxUtilization = maxUtilization;
81
82         if (minUtilization < 0 || minUtilization > 100)
83             throw new IllegalArgumentException("Minimum utilization can be only between 0 and 100. Passed: " + minUtilization);
84         this.minUtilization = minUtilization;
85
86         this.overBookingFactor = overBookingFactor;
87
88         if (tlvs == null)
89             this.tlvs = Collections.emptyList();
90         else
91             this.tlvs = tlvs;
92     }
93
94     /**
95      * Gets the maximum hop count for all the TE LSPs
96      *
97      * @return the maximum hop count
98      */
99     public short getMaxHop() {
100         return this.maxHop;
101     }
102
103     /**
104      * Gets the maximum utilization percentage by which all links should be
105      * bound
106      *
107      * @return the maximum utilization percentage
108      */
109     public short getMaxUtilization() {
110         return this.maxUtilization;
111     }
112
113     /**
114      * Gets the minimum utilization percentage by which all links should be
115      * bound
116      *
117      * @return the maximum utilization percentage
118      */
119     public short getMinUtilization() {
120         return this.minUtilization;
121     }
122
123     /**
124      * Gets the over booking factor percentage that allows the reserved
125      * bandwidth to be overbooked on each link beyond its physical capacity
126      * limit
127      *
128      * @return the over booking factor percentage
129      */
130     public short getOverBookingFactor() {
131         return this.overBookingFactor;
132     }
133
134     /**
135      * Gets the list of optional tlvs
136      *
137      * @return List<PCEPTlv>. Can be empty but not null.
138      */
139     public List<PCEPTlv> getTlvs() {
140         return this.tlvs;
141     }
142
143         @Override
144         protected ToStringHelper addToStringAttributes(ToStringHelper toStringHelper) {
145                 toStringHelper.add("maxHop", this.maxHop);
146                 toStringHelper.add("maxUtilization", this.maxUtilization);
147                 toStringHelper.add("minUtilization", this.minUtilization);
148                 toStringHelper.add("overBookingFactor", this.overBookingFactor);
149                 toStringHelper.add("tlvs", this.tlvs);
150                 return super.addToStringAttributes(toStringHelper);
151         }
152
153     @Override
154     public int hashCode() {
155         final int prime = 31;
156         int result = super.hashCode();
157         result = prime * result + this.maxHop;
158         result = prime * result + this.maxUtilization;
159         result = prime * result + this.minUtilization;
160         result = prime * result + this.overBookingFactor;
161         return result;
162     }
163
164     @Override
165     public boolean equals(Object obj) {
166         if (this == obj)
167             return true;
168         if (!super.equals(obj))
169             return false;
170         if (this.getClass() != obj.getClass())
171             return false;
172         final PCEPGlobalConstraintsObject other = (PCEPGlobalConstraintsObject) obj;
173         if (this.maxHop != other.maxHop)
174             return false;
175         if (this.maxUtilization != other.maxUtilization)
176             return false;
177         if (this.minUtilization != other.minUtilization)
178             return false;
179         if (this.overBookingFactor != other.overBookingFactor)
180             return false;
181         return true;
182     }
183 }