Merge "Randomize port to allow concurrent execution"
[bgpcep.git] / pcep / api / src / main / java / org / opendaylight / protocol / pcep / tlv / RSVPErrorSpecTlv.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
9 package org.opendaylight.protocol.pcep.tlv;
10
11 import org.opendaylight.protocol.concepts.NetworkAddress;
12 import org.opendaylight.protocol.pcep.PCEPTlv;
13
14 /**
15  * Structure of RSVP Error Spec Tlv.
16  * 
17  * @see <a href="http://tools.ietf.org/html/rfc2205">Apendix A.5: ERROR_SPEC
18  *      Class</a>
19  * @param <T>
20  */
21 public class RSVPErrorSpecTlv<T extends NetworkAddress<T>> implements PCEPTlv {
22         private static final long serialVersionUID = 3948879942549682846L;
23
24         private final T errorNodeAddress;
25
26         private final boolean inPlace;
27
28         private final boolean guilty;
29
30         private final int errorCode;
31
32         private final int errorValue;
33
34         /**
35          * 
36          * Constructs new RSVP Error Spec Tlv.
37          * 
38          * @param errorNodeAddress
39          *            T
40          * @param inPlace
41          *            boolean
42          * @param guilty
43          *            boolean
44          * @param errorCode
45          *            int
46          * @param errorValue
47          *            int
48          */
49         public RSVPErrorSpecTlv(T errorNodeAddress, boolean inPlace, boolean guilty, int errorCode, int errorValue) {
50                 this.errorNodeAddress = errorNodeAddress;
51                 this.inPlace = inPlace;
52                 this.guilty = guilty;
53                 this.errorCode = errorCode;
54                 this.errorValue = errorValue;
55         }
56
57         /**
58          * Gets {@link NetworkAddress} of Error Node.
59          * 
60          * @return T
61          */
62         public T getErrorNodeAddress() {
63                 return this.errorNodeAddress;
64         }
65
66         /**
67          * Setting of InPlace flag.
68          * 
69          * @return boolean
70          */
71         public boolean isInPlace() {
72                 return this.inPlace;
73         }
74
75         /**
76          * Setting of Guilty flag.
77          * 
78          * @return boolean
79          */
80         public boolean isGuilty() {
81                 return this.guilty;
82         }
83
84         /**
85          * Gets int representation of Error Code.
86          * 
87          * @return int
88          */
89         public int getErrorCode() {
90                 return this.errorCode;
91         }
92
93         /**
94          * Gets int representation of Error Value.
95          * 
96          * @return int
97          */
98         public int getErrorValue() {
99                 return this.errorValue;
100         }
101
102         @Override
103         public int hashCode() {
104                 final int prime = 31;
105                 int result = 1;
106                 result = prime * result + this.errorCode;
107                 result = prime * result + ((this.errorNodeAddress == null) ? 0 : this.errorNodeAddress.hashCode());
108                 result = prime * result + this.errorValue;
109                 result = prime * result + (this.guilty ? 1231 : 1237);
110                 result = prime * result + (this.inPlace ? 1231 : 1237);
111                 return result;
112         }
113
114         @Override
115         public boolean equals(Object obj) {
116                 if (this == obj)
117                         return true;
118                 if (obj == null)
119                         return false;
120                 if (this.getClass() != obj.getClass())
121                         return false;
122                 final RSVPErrorSpecTlv<?> other = (RSVPErrorSpecTlv<?>) obj;
123                 if (this.errorCode != other.errorCode)
124                         return false;
125                 if (this.errorNodeAddress == null) {
126                         if (other.errorNodeAddress != null)
127                                 return false;
128                 } else if (!this.errorNodeAddress.equals(other.errorNodeAddress))
129                         return false;
130                 if (this.errorValue != other.errorValue)
131                         return false;
132                 if (this.guilty != other.guilty)
133                         return false;
134                 if (this.inPlace != other.inPlace)
135                         return false;
136                 return true;
137         }
138
139         @Override
140         public String toString() {
141                 final StringBuilder builder = new StringBuilder();
142                 builder.append("RSVPErrorSpecTlv [errorNodeAddress=");
143                 builder.append(this.errorNodeAddress);
144                 builder.append(", inPlace=");
145                 builder.append(this.inPlace);
146                 builder.append(", guilty=");
147                 builder.append(this.guilty);
148                 builder.append(", errorCode=");
149                 builder.append(this.errorCode);
150                 builder.append(", errorValue=");
151                 builder.append(this.errorValue);
152                 builder.append("]");
153                 return builder.toString();
154         }
155 }