BUG-47: more subobject models
[bgpcep.git] / pcep / api / src / main / java / org / opendaylight / protocol / pcep / subobject / RROIPAddressSubobject.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.subobject;
10
11 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
12
13 /**
14  * Parametrized structure of RRO IP Address Subobject.
15  * 
16  * @see <a href="http://tools.ietf.org/html/rfc3209#section-4.4.1.1">Section 4.4.1.1: Subobject 1: IPv4 address</a> and
17  *      <a href="http://tools.ietf.org/html/rfc3209#section-4.4.1.2">Section 4.4.1.2: Subobject 2: IPv6 address</a>
18  * 
19  * @param <T> subtype of Prefix
20  */
21 public class RROIPAddressSubobject extends ReportedRouteSubobject {
22
23         private final IpPrefix prefix;
24
25         /**
26          * Local protection available
27          */
28         private final boolean localProtectionAvailable;
29
30         /**
31          * Local protection in use
32          */
33         private final boolean localProtectionInUse;
34
35         /**
36          * Constructs IPPrefix Subobject.
37          * 
38          * @param prefix T
39          * @param localProtectionAvailable boolean
40          * @param localProtectionInUse boolean
41          */
42         public RROIPAddressSubobject(final IpPrefix prefix, final boolean localProtectionAvailable, final boolean localProtectionInUse) {
43                 super();
44                 this.prefix = prefix;
45                 this.localProtectionAvailable = localProtectionAvailable;
46                 this.localProtectionInUse = localProtectionInUse;
47         }
48
49         /**
50          * Gets specific {@link Prefix}.
51          * 
52          * @return prefix T
53          */
54         public IpPrefix getPrefix() {
55                 return this.prefix;
56         }
57
58         /**
59          * Returns tru if local protection is available.
60          * 
61          * @return boolean
62          */
63         public boolean isLocalProtectionAvailable() {
64                 return this.localProtectionAvailable;
65         }
66
67         /**
68          * Returns true if local protection is in use
69          * 
70          * @return boolean
71          */
72         public boolean isLocalProtectionInUse() {
73                 return this.localProtectionInUse;
74         }
75
76         @Override
77         public int hashCode() {
78                 final int prime = 31;
79                 int result = 1;
80                 result = prime * result + (this.localProtectionAvailable ? 1231 : 1237);
81                 result = prime * result + (this.localProtectionInUse ? 1231 : 1237);
82                 result = prime * result + ((this.prefix == null) ? 0 : this.prefix.hashCode());
83                 return result;
84         }
85
86         @Override
87         public boolean equals(final Object obj) {
88                 if (this == obj)
89                         return true;
90                 if (obj == null)
91                         return false;
92                 if (this.getClass() != obj.getClass())
93                         return false;
94                 final RROIPAddressSubobject other = (RROIPAddressSubobject) obj;
95                 if (this.localProtectionAvailable != other.localProtectionAvailable)
96                         return false;
97                 if (this.localProtectionInUse != other.localProtectionInUse)
98                         return false;
99                 if (this.prefix == null) {
100                         if (other.prefix != null)
101                                 return false;
102                 } else if (!this.prefix.equals(other.prefix))
103                         return false;
104                 return true;
105         }
106
107         @Override
108         public String toString() {
109                 final StringBuilder builder = new StringBuilder();
110                 builder.append("RROIPAddressSubobject [prefix=");
111                 builder.append(this.prefix);
112                 builder.append(", lpa=");
113                 builder.append(this.localProtectionAvailable);
114                 builder.append(", lpiu=");
115                 builder.append(this.localProtectionInUse);
116                 builder.append("]");
117                 return builder.toString();
118         }
119
120 }