blob: 773992957b585eed6cba331e4b020b7db7900cde [file] [log] [blame]
Jian Li09596002016-07-15 17:46:49 +09001/*
2 * Copyright 2016-present Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.lisp.msg.types;
17
18import java.util.Objects;
19
20import static com.google.common.base.MoreObjects.toStringHelper;
21
22/**
23 * LISP Canonical Address Formatted address class.
Jian Lic7e20a52016-07-18 19:03:49 +090024 *
Jian Li8fc2d2f2016-08-08 14:43:53 +090025 * <pre>
26 * {@literal
Jian Lic7e20a52016-07-18 19:03:49 +090027 * 0 1 2 3
28 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
29 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
30 * | AFI = 16387 | Rsvd1 | Flags |
31 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
32 * | Type | Rsvd2 | Length |
33 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Jian Li8fc2d2f2016-08-08 14:43:53 +090034 * }</pre>
Jian Li09596002016-07-15 17:46:49 +090035 */
36public class LispLcafAddress extends LispAfiAddress {
37
38 protected final LispCanonicalAddressFormatEnum lcafType;
Jian Lic7e20a52016-07-18 19:03:49 +090039 protected final byte reserved1;
40 protected final byte reserved2;
41 protected final byte flag;
42 protected final byte length;
Jian Li09596002016-07-15 17:46:49 +090043
44 /**
45 * Initializes LCAF address.
46 *
47 * @param lcafType LCAF type
Jian Lic7e20a52016-07-18 19:03:49 +090048 * @param reserved1 reserved1 field
49 * @param reserved2 reserved2 field
50 * @param flag flag field
51 * @param length length field
Jian Li09596002016-07-15 17:46:49 +090052 */
Jian Lic7e20a52016-07-18 19:03:49 +090053 protected LispLcafAddress(LispCanonicalAddressFormatEnum lcafType,
54 byte reserved1, byte reserved2, byte flag, byte length) {
Jian Li09596002016-07-15 17:46:49 +090055 super(AddressFamilyIdentifierEnum.LCAF);
56 this.lcafType = lcafType;
Jian Lic7e20a52016-07-18 19:03:49 +090057 this.reserved1 = reserved1;
58 this.reserved2 = reserved2;
59 this.flag = flag;
60 this.length = length;
61 }
62
63 /**
64 * Initializes LCAF address.
65 *
66 * @param lcafType LCAF type
67 * @param reserved2 reserved2 field
68 * @param flag flag field
69 * @param length length field
70 */
71 protected LispLcafAddress(LispCanonicalAddressFormatEnum lcafType,
72 byte reserved2, byte flag, byte length) {
73 super(AddressFamilyIdentifierEnum.LCAF);
74 this.lcafType = lcafType;
75 this.reserved2 = reserved2;
76 this.flag = flag;
77 this.length = length;
78 this.reserved1 = 0;
79 }
80
81 /**
82 * Initializes LCAF address.
83 *
84 * @param lcafType LCAF type
85 * @param reserved2 reserved2 field
86 * @param length length field
87 */
88 protected LispLcafAddress(LispCanonicalAddressFormatEnum lcafType,
89 byte reserved2, byte length) {
90 super(AddressFamilyIdentifierEnum.LCAF);
91 this.lcafType = lcafType;
92 this.reserved2 = reserved2;
93 this.length = length;
94 this.reserved1 = 0;
95 this.flag = 0;
96 }
97
98 /**
99 * Initializes LCAF address.
100 *
101 * @param lcafType LCAF type
102 * @param reserved2 reserved2 field
103 */
104 protected LispLcafAddress(LispCanonicalAddressFormatEnum lcafType, byte reserved2) {
105 super(AddressFamilyIdentifierEnum.LCAF);
106 this.lcafType = lcafType;
107 this.reserved2 = reserved2;
108 this.reserved1 = 0;
109 this.flag = 0;
110 this.length = 0;
111 }
112
113 /**
114 * Initializes LCAF address.
115 *
116 * @param lcafType LCAF type
117 */
118 protected LispLcafAddress(LispCanonicalAddressFormatEnum lcafType) {
119 super(AddressFamilyIdentifierEnum.LCAF);
120 this.lcafType = lcafType;
121 this.reserved1 = 0;
122 this.reserved2 = 0;
123 this.flag = 0;
124 this.length = 0;
Jian Li09596002016-07-15 17:46:49 +0900125 }
126
127 /**
128 * Obtains LCAF type.
129 *
130 * @return LCAF type
131 */
132 public LispCanonicalAddressFormatEnum getType() {
133 return lcafType;
134 }
135
136 /**
Jian Lic7e20a52016-07-18 19:03:49 +0900137 * Obtains LCAF reserved1 value.
Jian Li09596002016-07-15 17:46:49 +0900138 *
Jian Lic7e20a52016-07-18 19:03:49 +0900139 * @return LCAF reserved1 value
Jian Li09596002016-07-15 17:46:49 +0900140 */
Jian Lic7e20a52016-07-18 19:03:49 +0900141 public byte getReserved1() {
142 return reserved1;
143 }
144
145 /**
146 * Obtains LCAF reserved2 value.
147 *
148 * @return LCAF reserved2 value
149 */
150 public byte getReserved2() {
151 return reserved2;
152 }
153
154 /**
155 * Obtains LCAF flag value.
156 *
157 * @return LCAF flag value
158 */
159 public byte getFlag() {
160 return flag;
161 }
162
163 /**
164 * Obtains LCAF length value.
165 *
166 * @return LCAF length value
167 */
168 public byte getLength() {
169 return length;
Jian Li09596002016-07-15 17:46:49 +0900170 }
171
172 @Override
173 public int hashCode() {
Jian Lid56f97e2016-07-19 15:48:15 +0900174 return Objects.hash(lcafType, reserved1, reserved2, flag, length);
Jian Li09596002016-07-15 17:46:49 +0900175 }
176
177 @Override
178 public boolean equals(Object obj) {
179 if (this == obj) {
180 return true;
181 }
182
183 if (obj instanceof LispLcafAddress) {
184 final LispLcafAddress other = (LispLcafAddress) obj;
185 return Objects.equals(this.lcafType, other.lcafType) &&
Jian Lic7e20a52016-07-18 19:03:49 +0900186 Objects.equals(this.reserved1, other.reserved1) &&
187 Objects.equals(this.reserved2, other.reserved2) &&
188 Objects.equals(this.flag, other.flag) &&
189 Objects.equals(this.length, other.length);
Jian Li09596002016-07-15 17:46:49 +0900190 }
191 return false;
192 }
193
194 @Override
195 public String toString() {
196 return toStringHelper(this)
197 .add("lcafType", lcafType)
Jian Lic7e20a52016-07-18 19:03:49 +0900198 .add("reserved1", reserved1)
199 .add("reserved2", reserved2)
200 .add("flag", flag)
201 .add("length", length)
Jian Li09596002016-07-15 17:46:49 +0900202 .toString();
203 }
204}