BUG-47: more subobject models
[bgpcep.git] / pcep / api / src / main / java / org / opendaylight / protocol / pcep / subobject / EROUnnumberedInterfaceSubobject.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.Ipv4Address;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev130820.UnnumberedSubobject;
13
14 import com.google.common.base.Objects.ToStringHelper;
15
16 /**
17  * Structure of unnumbered Interface Subobject.
18  * 
19  * @see <a href="http://tools.ietf.org/html/rfc3477">Section 4: Signalling Unnumbered Links in EROs</a>
20  */
21 public class EROUnnumberedInterfaceSubobject extends ExplicitRouteSubobject {
22         private final UnnumberedSubobject interfaceID;
23         private final Ipv4Address routerID;
24
25         /**
26          * Constructs new Unnumbered Interface Subobject.
27          * 
28          * @param routerID IPv4Address
29          * @param interfaceID UnnumberedInterfaceIdentifier
30          * @param loose boolean
31          */
32         public EROUnnumberedInterfaceSubobject(final Ipv4Address routerID, final UnnumberedSubobject interfaceID, final boolean loose) {
33                 super(loose);
34                 this.routerID = routerID;
35                 this.interfaceID = interfaceID;
36         }
37
38         /**
39          * Gets {@link IPv4Address} representation of router ID.
40          * 
41          * @return IPv4Address
42          */
43         public Ipv4Address getRouterID() {
44                 return this.routerID;
45         }
46
47         /**
48          * Gets {@link UnnumberedSubobject} representation of Interface ID.
49          * 
50          * @return UnnumberedSubobject
51          */
52         public UnnumberedSubobject getInterfaceID() {
53                 return this.interfaceID;
54         }
55
56         @Override
57         public int hashCode() {
58                 final int prime = 31;
59                 int result = 1;
60                 result = prime * result + ((this.interfaceID == null) ? 0 : this.interfaceID.hashCode());
61                 result = prime * result + ((this.routerID == null) ? 0 : this.routerID.hashCode());
62                 return result;
63         }
64
65         @Override
66         public boolean equals(final Object obj) {
67                 if (this == obj)
68                         return true;
69                 if (obj == null)
70                         return false;
71                 if (this.getClass() != obj.getClass())
72                         return false;
73                 final EROUnnumberedInterfaceSubobject other = (EROUnnumberedInterfaceSubobject) obj;
74                 if (this.interfaceID == null) {
75                         if (other.interfaceID != null)
76                                 return false;
77                 } else if (!this.interfaceID.equals(other.interfaceID))
78                         return false;
79                 if (this.routerID == null) {
80                         if (other.routerID != null)
81                                 return false;
82                 } else if (!this.routerID.equals(other.routerID))
83                         return false;
84                 return true;
85         }
86
87         @Override
88         public String toString() {
89                 final StringBuilder builder = new StringBuilder();
90                 builder.append("EROUnnumberedInterfaceSubobject [interfaceID=");
91                 builder.append(this.interfaceID);
92                 builder.append(", routerID=");
93                 builder.append(this.routerID);
94                 builder.append(", loose=");
95                 builder.append(this.loose);
96                 builder.append("]");
97                 return builder.toString();
98         }
99
100         @Override
101         protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
102                 toStringHelper.add("interfaceID", this.interfaceID);
103                 toStringHelper.add("routerID", this.routerID);
104                 toStringHelper.add("loose", this.loose);
105                 return super.addToStringAttributes(toStringHelper);
106         }
107
108 }