Merge "Randomize port to allow concurrent execution"
[bgpcep.git] / pcep / api / src / main / java / org / opendaylight / protocol / pcep / object / PCEPRequestParameterObject.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 org.opendaylight.protocol.pcep.tlv.OrderTlv;
16 import com.google.common.base.Objects.ToStringHelper;
17
18 /**
19  * Structure of PCEP Requested Parameter Object.
20  *
21  * @see <a href="http://tools.ietf.org/html/rfc5440#section-7.4">PCEP Request
22  *      Parameter Object [RFC5440]</a>
23  * @see <a href="http://tools.ietf.org/html/rfc5541#section-6.2.4">RP Object
24  *      Flag [RFC5541]</a>
25  * @see <a href="http://tools.ietf.org/html/rfc6006#section-3.3.1">The Extension
26  *      of the RP Object [RFC6006]</a>
27  */
28 public class PCEPRequestParameterObject extends PCEPObject {
29
30     private final boolean loose;
31
32     private final boolean bidirectional;
33
34     private final boolean reoptimized;
35
36     private final boolean makeBeforeBreak;
37
38     private final boolean reportRequestOrder;
39
40     private final boolean suplyOFOnResponse;
41
42     /*
43      * RFC6006 flags
44      */
45     private final boolean fragmentation;
46
47     private final boolean p2mp;
48
49     private final boolean eroCompression;
50
51     // End of flags
52
53     private final short priority;
54
55     private final long requestID;
56
57     private final List<PCEPTlv> tlvs;
58
59     /**
60      * Constructs PCEP Requested Parameter Object only with mandatory values.
61      *
62      * @param loose
63      *            boolean
64      * @param bidirectional
65      *            boolean
66      * @param reoptimized
67      *            boolean
68      * @param makeBeforeBreak
69      *            boolean
70      * @param suplyOFOnResponse
71      *            boolean
72      * @param priority
73      *            short
74      * @param requestID
75      *            long
76      * @param processed
77      *            boolean
78      * @param ignored
79      *            boolean;
80      */
81     public PCEPRequestParameterObject(boolean loose, boolean bidirectional, boolean reoptimized, boolean makeBeforeBreak, boolean suplyOFOnResponse,
82             boolean fragmentation, boolean p2mp, boolean eroCompression, short priority, long requestID, boolean processed, boolean ignored) {
83         this(loose, bidirectional, reoptimized, makeBeforeBreak, false, suplyOFOnResponse, fragmentation, p2mp, eroCompression, priority, requestID, null,
84                 processed, ignored);
85     }
86
87     /**
88      * Constructs PCEP Requested Parameter Object also with optional Objects.
89      *
90      * @param loose
91      *            boolean
92      * @param bidirectional
93      *            boolean
94      * @param reoptimized
95      *            boolean
96      * @param makeBeforeBreak
97      *            boolean
98      * @param reportRequestOrder
99      *            boolean
100      * @param suplyOFOnResponse
101      *            boolean
102      * @param priority
103      *            short
104      * @param requestID
105      *            long
106      * @param tlvs
107      *            List<PCEPTlv>
108      * @param processed
109      *            boolean
110      * @param ignored
111      *            boolean
112      */
113     public PCEPRequestParameterObject(boolean loose, boolean bidirectional, boolean reoptimized, boolean makeBeforeBreak, boolean reportRequestOrder,
114             boolean suplyOFOnResponse, boolean fragmentation, boolean p2mp, boolean eroCompression, short priority, long requestID, List<PCEPTlv> tlvs,
115             boolean processed, boolean ignored) {
116         super(processed, ignored);
117         this.loose = loose;
118         this.bidirectional = bidirectional;
119         this.reoptimized = reoptimized;
120         this.makeBeforeBreak = makeBeforeBreak;
121         this.reportRequestOrder = reportRequestOrder;
122         this.suplyOFOnResponse = suplyOFOnResponse;
123         this.fragmentation = fragmentation;
124         this.p2mp = p2mp;
125         this.eroCompression = eroCompression;
126
127         this.priority = priority;
128         this.requestID = requestID;
129         if (tlvs != null)
130             this.tlvs = tlvs;
131         else
132             this.tlvs = Collections.emptyList();
133
134         if (makeBeforeBreak && !reoptimized)
135             throw new IllegalArgumentException("M (make-before-break) can be set only if R (reoptimied) flag is set too.");
136
137         if (reportRequestOrder && !this.validateOrderTlv())
138             throw new IllegalArgumentException("D (report request order) flag is set, but missing OrderTlv.");
139     }
140
141     /**
142      * Gets Loose flag.
143      *
144      * @return boolean
145      */
146     public boolean isLoose() {
147         return this.loose;
148     }
149
150     /**
151      * Gets Bidirectional flag.
152      *
153      * @return boolean
154      */
155     public boolean isBidirectional() {
156         return this.bidirectional;
157     }
158
159     /**
160      * Gets Reoptimization flag.
161      *
162      * @return boolean
163      */
164     public boolean isReoptimized() {
165         return this.reoptimized;
166     }
167
168     /**
169      * Gets make-before-break flag
170      *
171      * @return boolean
172      */
173     public boolean isMakeBeforeBreak() {
174         return this.makeBeforeBreak;
175     }
176
177     /**
178      * Gets report requested order flag
179      *
180      * @return boolean
181      */
182     public boolean isReportRequestOrder() {
183         return this.reportRequestOrder;
184     }
185
186     /**
187      * Gets report supply objective function on response flag
188      *
189      * @return boolean
190      */
191     public boolean isSuplyOFOnResponse() {
192         return this.suplyOFOnResponse;
193     }
194
195     /**
196      * @return the fragmentation
197      */
198     public boolean isFragmentation() {
199         return this.fragmentation;
200     }
201
202     /**
203      * @return the p2mp
204      */
205     public boolean isP2mp() {
206         return this.p2mp;
207     }
208
209     /**
210      * @return the eroCompression
211      */
212     public boolean isEroCompression() {
213         return this.eroCompression;
214     }
215
216     /**
217      * Returns short representation of Priority.
218      *
219      * @return short
220      */
221     public short getPriority() {
222         return this.priority;
223     }
224
225     /**
226      * Returns long representation of Requested ID.
227      *
228      * @return long
229      */
230     public long getRequestID() {
231         return this.requestID;
232     }
233
234     /**
235      * Gets list of {@link PCEPTlv}
236      *
237      * @return List<PCEPTlv>. Can't be null, but may be empty.
238      */
239     public List<PCEPTlv> getTlvs() {
240         return this.tlvs;
241     }
242
243     private boolean validateOrderTlv() {
244         for (final PCEPTlv tlv : this.tlvs) {
245             if (tlv instanceof OrderTlv)
246                 return true;
247         }
248
249         return false;
250     }
251
252     @Override
253     public int hashCode() {
254         final int prime = 31;
255         int result = super.hashCode();
256         result = prime * result + (this.bidirectional ? 1231 : 1237);
257         result = prime * result + (this.eroCompression ? 1231 : 1237);
258         result = prime * result + (this.fragmentation ? 1231 : 1237);
259         result = prime * result + (this.loose ? 1231 : 1237);
260         result = prime * result + (this.makeBeforeBreak ? 1231 : 1237);
261         result = prime * result + (this.p2mp ? 1231 : 1237);
262         result = prime * result + this.priority;
263         result = prime * result + (this.reoptimized ? 1231 : 1237);
264         result = prime * result + (this.reportRequestOrder ? 1231 : 1237);
265         result = prime * result + (int) (this.requestID ^ (this.requestID >>> 32));
266         result = prime * result + (this.suplyOFOnResponse ? 1231 : 1237);
267         result = prime * result + ((this.tlvs == null) ? 0 : this.tlvs.hashCode());
268         return result;
269     }
270
271     @Override
272     public boolean equals(Object obj) {
273         if (this == obj)
274             return true;
275         if (!super.equals(obj))
276             return false;
277         if (this.getClass() != obj.getClass())
278             return false;
279         final PCEPRequestParameterObject other = (PCEPRequestParameterObject) obj;
280         if (this.bidirectional != other.bidirectional)
281             return false;
282         if (this.eroCompression != other.eroCompression)
283             return false;
284         if (this.fragmentation != other.fragmentation)
285             return false;
286         if (this.loose != other.loose)
287             return false;
288         if (this.makeBeforeBreak != other.makeBeforeBreak)
289             return false;
290         if (this.p2mp != other.p2mp)
291             return false;
292         if (this.priority != other.priority)
293             return false;
294         if (this.reoptimized != other.reoptimized)
295             return false;
296         if (this.reportRequestOrder != other.reportRequestOrder)
297             return false;
298         if (this.requestID != other.requestID)
299             return false;
300         if (this.suplyOFOnResponse != other.suplyOFOnResponse)
301             return false;
302         if (this.tlvs == null) {
303             if (other.tlvs != null)
304                 return false;
305         } else if (!this.tlvs.equals(other.tlvs))
306             return false;
307         return true;
308     }
309
310     @Override
311         protected ToStringHelper addToStringAttributes(ToStringHelper toStringHelper) {
312                 toStringHelper.add("loose", this.loose);
313                 toStringHelper.add("bidirectional", this.bidirectional);
314                 toStringHelper.add("reoptimized", this.reoptimized);
315                 toStringHelper.add("makeBeforeBreak", this.makeBeforeBreak);
316                 toStringHelper.add("reportRequestOrder", this.reportRequestOrder);
317                 toStringHelper.add("suplyOFOnResponse", this.suplyOFOnResponse);
318                 toStringHelper.add("fragmentation", this.fragmentation);
319                 toStringHelper.add("p2mp", this.p2mp);
320                 toStringHelper.add("eroCompression", this.eroCompression);
321                 toStringHelper.add("priority", this.priority);
322                 toStringHelper.add("requestID", this.requestID);
323                 toStringHelper.add("tlvs", this.tlvs);
324                 return super.addToStringAttributes(toStringHelper);
325         }
326
327 }