Revert "BUG-47 : unfinished PCEP migration to generated DTOs."
[bgpcep.git] / pcep / api / src / main / java / org / opendaylight / protocol / pcep / tlv / ByPassTlv.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.tlv;
9
10 import org.opendaylight.protocol.concepts.IPv4Address;
11 import org.opendaylight.protocol.pcep.PCEPTlv;
12
13 /**
14  *      Structure of No Path Vector TLV.
15  *
16  *      @see <a href="http://tools.ietf.org/html/draft-crabbe-pce-stateful-pce-protection-00#section-4.3"
17  *                      Bypass Tlv</a>
18  */
19 public class ByPassTlv implements PCEPTlv {
20
21         private static final long serialVersionUID = 5879892226322401651L;
22
23         private final boolean nodeProtection;
24
25         private final boolean localProtectionInUse;
26
27         private final IPv4Address bypassAddress;
28
29         /**
30          * Constructs ByPass Tlv.
31          *
32          * @param nodeProtection
33          *              boolean
34          * @param localProtectionInUse
35          *              boolean
36          * @param bypassAddress
37          *              IPv4Address
38          */
39         public ByPassTlv(final boolean nodeProtection, final boolean localProtectionInUse,
40                         final IPv4Address bypassAddress) {
41                 this.nodeProtection = nodeProtection;
42                 this.localProtectionInUse = localProtectionInUse;
43                 this.bypassAddress = bypassAddress;
44         }
45
46         /**
47          * The N Flag indicates whether the Bypass is used for node-protection.
48          * If the N flag is set to 1, the Bypass is used for node-protection.
49          * If the N flag is 0, the Bypass is used for link-protection.
50          *
51          * @return the nodeProtection
52          */
53         public final boolean isNodeProtection() {
54                 return this.nodeProtection;
55         }
56
57         /**
58          * The I Flag indicates that local repair mechanism is in use.
59          *
60          * @return the localProtectionInUse
61          */
62         public final boolean isLocalProtectionInUse() {
63                 return this.localProtectionInUse;
64         }
65
66         /**
67          * For link protection, the Bypass IPv4 Address is
68      * the nexthop address of the protected link in the paths of the
69      * protected LSPs.  For node protection, the Bypass IPv4 Address is
70      * the node addresses of the protected node.
71      *
72          * @return the bypassAddress
73          */
74         public final IPv4Address getBypassAddress() {
75                 return this.bypassAddress;
76         }
77
78         /* (non-Javadoc)
79          * @see java.lang.Object#toString()
80          */
81         @Override
82         public String toString() {
83                 final StringBuilder builder = new StringBuilder();
84                 builder.append("ByPassTlv [nodeProtection=");
85                 builder.append(this.nodeProtection);
86                 builder.append(", localProtectionInUse=");
87                 builder.append(this.localProtectionInUse);
88                 builder.append(", bypassAddress=");
89                 builder.append(this.bypassAddress);
90                 builder.append("]");
91                 return builder.toString();
92         }
93
94         /* (non-Javadoc)
95          * @see java.lang.Object#hashCode()
96          */
97         @Override
98         public int hashCode() {
99                 final int prime = 31;
100                 int result = 1;
101                 result = prime * result
102                                 + ((this.bypassAddress == null) ? 0 : this.bypassAddress.hashCode());
103                 result = prime * result + (this.localProtectionInUse ? 1231 : 1237);
104                 result = prime * result + (this.nodeProtection ? 1231 : 1237);
105                 return result;
106         }
107
108         /* (non-Javadoc)
109          * @see java.lang.Object#equals(java.lang.Object)
110          */
111         @Override
112         public boolean equals(Object obj) {
113                 if (this == obj)
114                         return true;
115                 if (obj == null)
116                         return false;
117                 if (!(obj instanceof ByPassTlv))
118                         return false;
119                 final ByPassTlv other = (ByPassTlv) obj;
120                 if (this.bypassAddress == null) {
121                         if (other.bypassAddress != null)
122                                 return false;
123                 } else if (!this.bypassAddress.equals(other.bypassAddress))
124                         return false;
125                 if (this.localProtectionInUse != other.localProtectionInUse)
126                         return false;
127                 if (this.nodeProtection != other.nodeProtection)
128                         return false;
129                 return true;
130         }
131 }