Revert "BUG-47 : unfinished PCEP migration to generated DTOs."
[bgpcep.git] / pcep / api / src / main / java / org / opendaylight / protocol / pcep / object / PCEPOpenObject.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 of PCEP Open Object.
19  *
20  * @see <a href="http://tools.ietf.org/html/rfc5440#section-7.3">PCEP Open
21  *      Object</a>
22  */
23 public class PCEPOpenObject extends PCEPObject {
24
25     public static final int PCEP_VERSION = 1;
26
27     private final int keepAliveTimerValue;
28
29     private final int deadTimerValue;
30
31     private final int sessionId;
32
33     private final List<PCEPTlv> tlvs;
34
35     /**
36      * Constructs PCEP Open Object also with optional Objects.
37      *
38      * @param keepAliveTimerValue
39      *            int
40      * @param deadTimerValue
41      *            int
42      * @param sessionId
43      *            int
44      * @param tlvs
45      *            List<PCEPTlv>
46      */
47     public PCEPOpenObject(int keepAliveTimerValue, int deadTimerValue, int sessionId, List<PCEPTlv> tlvs) {
48         super(false, false);
49         this.keepAliveTimerValue = keepAliveTimerValue;
50         this.deadTimerValue = deadTimerValue;
51         this.sessionId = sessionId;
52         if (tlvs != null)
53             this.tlvs = tlvs;
54         else
55             this.tlvs = Collections.emptyList();
56     }
57
58     /**
59      * Constructs PCEP Open Object only with mandatory values.
60      *
61      * @param keepAliveTimerValue
62      *            int
63      * @param deadTimerValue
64      *            int
65      * @param sessionId
66      *            int
67      */
68     public PCEPOpenObject(int keepAliveTimerValue, int deadTimerValue, int sessionId) {
69         this(keepAliveTimerValue, deadTimerValue, sessionId, Collections.<PCEPTlv> emptyList());
70     }
71
72     /**
73      * Returns integer representation of Keep Alive Timer.
74      *
75      * @return int
76      */
77     public int getKeepAliveTimerValue() {
78         return this.keepAliveTimerValue;
79     }
80
81     /**
82      * Returns integer representation of Dead Timer.
83      *
84      * @return int
85      */
86     public int getDeadTimerValue() {
87         return this.deadTimerValue;
88     }
89
90     /**
91      * Returns integer representation of Session ID.
92      *
93      * @return int
94      */
95     public int getSessionId() {
96         return this.sessionId;
97     }
98
99     /**
100      * Gets list of {@link PCEPTlv}.
101      *
102      * @return List<PCEPTlv>
103      */
104     public List<PCEPTlv> getTlvs() {
105         return this.tlvs;
106     }
107
108     @Override
109     public int hashCode() {
110         final int prime = 31;
111         int result = 1;
112         result = prime * result + this.deadTimerValue;
113         result = prime * result + this.keepAliveTimerValue;
114         result = prime * result + this.sessionId;
115         result = prime * result + ((this.tlvs == null) ? 0 : this.tlvs.hashCode());
116         return result;
117     }
118
119     @Override
120     public boolean equals(Object obj) {
121         if (this == obj)
122             return true;
123         if (obj == null)
124             return false;
125         if (this.getClass() != obj.getClass())
126             return false;
127         final PCEPOpenObject other = (PCEPOpenObject) obj;
128         if (this.deadTimerValue != other.deadTimerValue)
129             return false;
130         if (this.keepAliveTimerValue != other.keepAliveTimerValue)
131             return false;
132         if (this.sessionId != other.sessionId)
133             return false;
134         if (this.tlvs == null) {
135             if (other.tlvs != null)
136                 return false;
137         } else if (!this.tlvs.equals(other.tlvs))
138             return false;
139         return true;
140     }
141
142     @Override
143         protected ToStringHelper addToStringAttributes(ToStringHelper toStringHelper) {
144                 toStringHelper.add("keepAliveTimerValue", this.keepAliveTimerValue);
145                 toStringHelper.add("deadTimerValue", this.deadTimerValue);
146                 toStringHelper.add("sessionId", this.sessionId);
147                 toStringHelper.add("tlvs", this.tlvs);
148                 return super.addToStringAttributes(toStringHelper);
149         }
150 }