Revert "BUG-47 : unfinished PCEP migration to generated DTOs."
[bgpcep.git] / pcep / api / src / main / java / org / opendaylight / protocol / pcep / object / PCEPLspaObject.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  * Structure for PCEP LSPA Object.
19  *
20  * @see <a href="http://tools.ietf.org/html/rfc5440#section-7.11">PCEP LSPA
21  *      Object</a>
22  * @see <a
23  *      href="http://tools.ietf.org/html/rfc3209#section-4.7">SessionAttribute
24  *      Object</a>
25  * @see <a
26  *      href="http://tools.ietf.org/html/draft-crabbe-pce-stateful-pce-protection-00#section-4.1">
27  *      The Standby flag in the LSPA object</a>
28  */
29 public class PCEPLspaObject extends PCEPObject {
30
31     private final long excludedAny;
32
33     private final long includeAny;
34
35     private final long includeAll;
36
37     private final short setupPriority;
38
39     private final short holdingPriority;
40
41     private final boolean standByPath;
42
43     private final boolean localProtected;
44
45     private final List<PCEPTlv> tlvs;
46
47     /**
48      * Constructs object only with mandatory objects.
49      *
50      * @param excludedAny
51      *            long
52      * @param includeAny
53      *            long
54      * @param includeAll
55      *            long
56      * @param setupPriority
57      *            short
58      * @param holdingPriority
59      *            short
60      * @param standByPath
61      *            boolean
62      * @param localProtected
63      *            boolean
64      * @param processed
65      *            boolean
66      * @param ignored
67      *            boolean
68      */
69     public PCEPLspaObject(long excludedAny, long includeAny, long includeAll, short setupPriority, short holdingPriority, boolean standByPath,
70             boolean localProtected, boolean processed, boolean ignored) {
71         this(excludedAny, includeAny, includeAll, setupPriority, holdingPriority, standByPath, localProtected, null, processed, ignored);
72     }
73
74     /**
75      * Constructs object also with optional objects.
76      *
77      * @param excludedAny
78      *            long
79      * @param includeAny
80      *            long
81      * @param includeAll
82      *            long
83      * @param setupPriority
84      *            short
85      * @param holdingPriority
86      *            short
87      * @param localProtected
88      *            boolean
89      * @param tlvs
90      *            List<PCEPTlv>
91      * @param processed
92      *            boolean
93      * @param ignored
94      *            boolean
95      */
96     public PCEPLspaObject(long excludedAny, long includeAny, long includeAll, short setupPriority, short holdingPriority, boolean standByPath,
97             boolean localProtected, List<PCEPTlv> tlvs, boolean processed, boolean ignored) {
98         super(processed, ignored);
99         this.excludedAny = excludedAny;
100         this.includeAny = includeAny;
101         this.includeAll = includeAll;
102         this.setupPriority = setupPriority;
103         this.holdingPriority = holdingPriority;
104         this.standByPath = standByPath;
105         this.localProtected = localProtected;
106         if (tlvs != null)
107             this.tlvs = tlvs;
108         else
109             this.tlvs = Collections.emptyList();
110     }
111
112     /**
113      * A 32-bit vector representing a set of attribute filters associated with a
114      * tunnel any of which renders a link unacceptable.
115      *
116      * @return long
117      */
118     public long getExcludeAny() {
119         return this.excludedAny;
120     }
121
122     /**
123      * A 32-bit vector representing a set of attribute filters associated with a
124      * tunnel any of which renders a link acceptable (with respect to this
125      * test). A null set (all bits set to zero) automatically passes.
126      *
127      * @return long
128      */
129     public long getIncludeAny() {
130         return this.includeAny;
131     }
132
133     /**
134      * A 32-bit vector representing a set of attribute filters associated with a
135      * tunnel all of which must be present for a link to be acceptable (with
136      * respect to this test). A null set (all bits set to zero) automatically
137      * passes.
138      *
139      * @return long
140      */
141     public long getIncludeAll() {
142         return this.includeAll;
143     }
144
145     /**
146      * The priority of TE LSP with respect to taking resources, in the range of
147      * 0 to 7 (validation not included). The value 0 is the highest priority.
148      * The Setup Priority is used in deciding whether this session can preempt
149      * another session.
150      *
151      * @return short
152      */
153     public short getSetupPriority() {
154         return this.setupPriority;
155     }
156
157     /**
158      * The priority of TE LSP with respect to holding resources, in the range of
159      * 0 to 7 (validation not included). The value 0 is the highest priority.
160      * Holding Priority is used in deciding whether this session can be
161      * preempted by another session.
162      *
163      * @return short
164      */
165     public short getHoldingPriority() {
166         return this.holdingPriority;
167     }
168
169     /**
170      * Corresponds to the "Local Protection Desired" bit ([RFC3209]) of
171      * SESSION-ATTRIBUTE Object. When set, this means that the computed path
172      * must include links protected with Fast REroute as defined in [RFC4090].
173      *
174      * @return boolean
175      */
176     public boolean isLocalProtected() {
177         return this.localProtected;
178     }
179
180     /**
181      * The protection path setup regimen (standby or not) is specified in the
182      * path using a new per-path flag in the LSPA object, the S (standby) flag
183      *
184      * @return boolean
185      */
186     public boolean isStandByPath() {
187         return this.standByPath;
188     }
189
190     /**
191      * Gets list of {@link PCEPTlv}
192      *
193      * @return List<PCEPTlv>. Can't be null, but may be empty.
194      */
195     public List<PCEPTlv> getTlvs() {
196         return this.tlvs;
197     }
198
199     /*
200      * (non-Javadoc)
201      *
202      * @see java.lang.Object#hashCode()
203      */
204     @Override
205     public int hashCode() {
206         final int prime = 31;
207         int result = super.hashCode();
208         result = prime * result + (int) (this.excludedAny ^ (this.excludedAny >>> 32));
209         result = prime * result + this.holdingPriority;
210         result = prime * result + (int) (this.includeAll ^ (this.includeAll >>> 32));
211         result = prime * result + (int) (this.includeAny ^ (this.includeAny >>> 32));
212         result = prime * result + (this.localProtected ? 1231 : 1237);
213         result = prime * result + this.setupPriority;
214         result = prime * result + (this.standByPath ? 1231 : 1237);
215         result = prime * result + ((this.tlvs == null) ? 0 : this.tlvs.hashCode());
216         return result;
217     }
218
219     /*
220      * (non-Javadoc)
221      *
222      * @see java.lang.Object#equals(java.lang.Object)
223      */
224     @Override
225     public boolean equals(Object obj) {
226         if (this == obj)
227             return true;
228         if (!super.equals(obj))
229             return false;
230         if (!(obj instanceof PCEPLspaObject))
231             return false;
232         final PCEPLspaObject other = (PCEPLspaObject) obj;
233         if (this.excludedAny != other.excludedAny)
234             return false;
235         if (this.holdingPriority != other.holdingPriority)
236             return false;
237         if (this.includeAll != other.includeAll)
238             return false;
239         if (this.includeAny != other.includeAny)
240             return false;
241         if (this.localProtected != other.localProtected)
242             return false;
243         if (this.setupPriority != other.setupPriority)
244             return false;
245         if (this.standByPath != other.standByPath)
246             return false;
247         if (this.tlvs == null) {
248             if (other.tlvs != null)
249                 return false;
250         } else if (!this.tlvs.equals(other.tlvs))
251             return false;
252         return true;
253     }
254
255         @Override
256         protected ToStringHelper addToStringAttributes(ToStringHelper toStringHelper) {
257                 toStringHelper.add("excludedAny", this.excludedAny);
258                 toStringHelper.add("includeAny", this.includeAny);
259                 toStringHelper.add("includeAll", this.includeAll);
260                 toStringHelper.add("setupPriority", this.setupPriority);
261                 toStringHelper.add("holdingPriority", this.holdingPriority);
262                 toStringHelper.add("standByPath", this.standByPath);
263                 toStringHelper.add("localProtected", this.localProtected);
264                 toStringHelper.add("tlvs", this.tlvs);
265                 return super.addToStringAttributes(toStringHelper);
266         }
267 }