Revert "BUG-47 : unfinished PCEP migration to generated DTOs."
[bgpcep.git] / pcep / api / src / main / java / org / opendaylight / protocol / pcep / tlv / AbstractLSPIdentifiersTlv.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.concepts.ExtendedTunnelIdentifier;
13 import org.opendaylight.protocol.pcep.concepts.LSPIdentifier;
14 import org.opendaylight.protocol.pcep.concepts.TunnelIdentifier;
15
16 /**
17  * Basic structure of LSP Identifiers TLV.
18  *
19  * @see <a
20  *      href="http://tools.ietf.org/html/draft-crabbe-pce-stateful-pce-02#section-7.2.2">LSP
21  *      Identifiers TLVs</a>
22  * @param <T>
23  */
24 public abstract class AbstractLSPIdentifiersTlv<T extends NetworkAddress<T>> implements LSPIdentifiersTlv<T> {
25         private static final long serialVersionUID = 2386922658825295806L;
26
27         private final T senderAddress;
28
29         private final LSPIdentifier lspID;
30
31         private final TunnelIdentifier tunnelID;
32
33         private final ExtendedTunnelIdentifier<T> extendedTunnelID;
34
35         /**
36          * Construct LSP Identifier TLV with mandatory objects.
37          *
38          * @param senderAddress
39          * @param lspID
40          * @param tunnelID
41          * @param extendedTunnelID
42          */
43         protected AbstractLSPIdentifiersTlv(T senderAddress, LSPIdentifier lspID, TunnelIdentifier tunnelID, ExtendedTunnelIdentifier<T> extendedTunnelID) {
44                 if (senderAddress == null)
45                         throw new IllegalArgumentException("SenderAdress is mandatory.");
46                 this.senderAddress = senderAddress;
47
48                 if (lspID == null)
49                         throw new IllegalArgumentException("LspID is mandatory.");
50                 this.lspID = lspID;
51
52                 if (tunnelID == null)
53                         throw new IllegalArgumentException("TunnelID is mandatory.");
54                 this.tunnelID = tunnelID;
55
56                 if (extendedTunnelID == null)
57                         throw new IllegalArgumentException("ExtendedTunnelID is mandatory.");
58                 this.extendedTunnelID = extendedTunnelID;
59         }
60
61         @Override
62         public T getSenderAddress() {
63                 return this.senderAddress;
64         }
65
66         @Override
67         public LSPIdentifier getLspID() {
68                 return this.lspID;
69         }
70
71         @Override
72         public TunnelIdentifier getTunnelID() {
73                 return this.tunnelID;
74         }
75
76         @Override
77         public ExtendedTunnelIdentifier<T> getExtendedTunnelID() {
78                 return this.extendedTunnelID;
79         }
80
81         @Override
82         public int hashCode() {
83                 final int prime = 31;
84                 int result = 1;
85                 result = prime * result + ((this.extendedTunnelID == null) ? 0 : this.extendedTunnelID.hashCode());
86                 result = prime * result + ((this.lspID == null) ? 0 : this.lspID.hashCode());
87                 result = prime * result + ((this.senderAddress == null) ? 0 : this.senderAddress.hashCode());
88                 result = prime * result + ((this.tunnelID == null) ? 0 : this.tunnelID.hashCode());
89                 return result;
90         }
91
92         @Override
93         public boolean equals(Object obj) {
94                 if (this == obj)
95                         return true;
96                 if (obj == null)
97                         return false;
98                 if (this.getClass() != obj.getClass())
99                         return false;
100                 final AbstractLSPIdentifiersTlv<?> other = (AbstractLSPIdentifiersTlv<?>) obj;
101                 if (this.extendedTunnelID == null) {
102                         if (other.extendedTunnelID != null)
103                                 return false;
104                 } else if (!this.extendedTunnelID.equals(other.extendedTunnelID))
105                         return false;
106                 if (this.lspID == null) {
107                         if (other.lspID != null)
108                                 return false;
109                 } else if (!this.lspID.equals(other.lspID))
110                         return false;
111                 if (this.senderAddress == null) {
112                         if (other.senderAddress != null)
113                                 return false;
114                 } else if (!this.senderAddress.equals(other.senderAddress))
115                         return false;
116                 if (this.tunnelID == null) {
117                         if (other.tunnelID != null)
118                                 return false;
119                 } else if (!this.tunnelID.equals(other.tunnelID))
120                         return false;
121                 return true;
122         }
123
124         @Override
125         public String toString() {
126                 final StringBuilder builder = new StringBuilder();
127                 builder.append("AbstractLSPIdentifiersTlv [senderAddress=");
128                 builder.append(this.senderAddress);
129                 builder.append(", lspID=");
130                 builder.append(this.lspID);
131                 builder.append(", tunnelID=");
132                 builder.append(this.tunnelID);
133                 builder.append(", extendedTunnelID=");
134                 builder.append(this.extendedTunnelID);
135                 builder.append("]");
136                 return builder.toString();
137         }
138
139 }