blob: c1b2df3f429b239930ce774402756eefbd051716 [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 *
25 * 0 1 2 3
26 * 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
27 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
28 * | AFI = 16387 | Rsvd1 | Flags |
29 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
30 * | Type | Rsvd2 | Length |
31 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Jian Li09596002016-07-15 17:46:49 +090032 */
33public class LispLcafAddress extends LispAfiAddress {
34
35 protected final LispCanonicalAddressFormatEnum lcafType;
Jian Lic7e20a52016-07-18 19:03:49 +090036 protected final byte reserved1;
37 protected final byte reserved2;
38 protected final byte flag;
39 protected final byte length;
Jian Li09596002016-07-15 17:46:49 +090040
41 /**
42 * Initializes LCAF address.
43 *
44 * @param lcafType LCAF type
Jian Lic7e20a52016-07-18 19:03:49 +090045 * @param reserved1 reserved1 field
46 * @param reserved2 reserved2 field
47 * @param flag flag field
48 * @param length length field
Jian Li09596002016-07-15 17:46:49 +090049 */
Jian Lic7e20a52016-07-18 19:03:49 +090050 protected LispLcafAddress(LispCanonicalAddressFormatEnum lcafType,
51 byte reserved1, byte reserved2, byte flag, byte length) {
Jian Li09596002016-07-15 17:46:49 +090052 super(AddressFamilyIdentifierEnum.LCAF);
53 this.lcafType = lcafType;
Jian Lic7e20a52016-07-18 19:03:49 +090054 this.reserved1 = reserved1;
55 this.reserved2 = reserved2;
56 this.flag = flag;
57 this.length = length;
58 }
59
60 /**
61 * Initializes LCAF address.
62 *
63 * @param lcafType LCAF type
64 * @param reserved2 reserved2 field
65 * @param flag flag field
66 * @param length length field
67 */
68 protected LispLcafAddress(LispCanonicalAddressFormatEnum lcafType,
69 byte reserved2, byte flag, byte length) {
70 super(AddressFamilyIdentifierEnum.LCAF);
71 this.lcafType = lcafType;
72 this.reserved2 = reserved2;
73 this.flag = flag;
74 this.length = length;
75 this.reserved1 = 0;
76 }
77
78 /**
79 * Initializes LCAF address.
80 *
81 * @param lcafType LCAF type
82 * @param reserved2 reserved2 field
83 * @param length length field
84 */
85 protected LispLcafAddress(LispCanonicalAddressFormatEnum lcafType,
86 byte reserved2, byte length) {
87 super(AddressFamilyIdentifierEnum.LCAF);
88 this.lcafType = lcafType;
89 this.reserved2 = reserved2;
90 this.length = length;
91 this.reserved1 = 0;
92 this.flag = 0;
93 }
94
95 /**
96 * Initializes LCAF address.
97 *
98 * @param lcafType LCAF type
99 * @param reserved2 reserved2 field
100 */
101 protected LispLcafAddress(LispCanonicalAddressFormatEnum lcafType, byte reserved2) {
102 super(AddressFamilyIdentifierEnum.LCAF);
103 this.lcafType = lcafType;
104 this.reserved2 = reserved2;
105 this.reserved1 = 0;
106 this.flag = 0;
107 this.length = 0;
108 }
109
110 /**
111 * Initializes LCAF address.
112 *
113 * @param lcafType LCAF type
114 */
115 protected LispLcafAddress(LispCanonicalAddressFormatEnum lcafType) {
116 super(AddressFamilyIdentifierEnum.LCAF);
117 this.lcafType = lcafType;
118 this.reserved1 = 0;
119 this.reserved2 = 0;
120 this.flag = 0;
121 this.length = 0;
Jian Li09596002016-07-15 17:46:49 +0900122 }
123
124 /**
125 * Obtains LCAF type.
126 *
127 * @return LCAF type
128 */
129 public LispCanonicalAddressFormatEnum getType() {
130 return lcafType;
131 }
132
133 /**
Jian Lic7e20a52016-07-18 19:03:49 +0900134 * Obtains LCAF reserved1 value.
Jian Li09596002016-07-15 17:46:49 +0900135 *
Jian Lic7e20a52016-07-18 19:03:49 +0900136 * @return LCAF reserved1 value
Jian Li09596002016-07-15 17:46:49 +0900137 */
Jian Lic7e20a52016-07-18 19:03:49 +0900138 public byte getReserved1() {
139 return reserved1;
140 }
141
142 /**
143 * Obtains LCAF reserved2 value.
144 *
145 * @return LCAF reserved2 value
146 */
147 public byte getReserved2() {
148 return reserved2;
149 }
150
151 /**
152 * Obtains LCAF flag value.
153 *
154 * @return LCAF flag value
155 */
156 public byte getFlag() {
157 return flag;
158 }
159
160 /**
161 * Obtains LCAF length value.
162 *
163 * @return LCAF length value
164 */
165 public byte getLength() {
166 return length;
Jian Li09596002016-07-15 17:46:49 +0900167 }
168
169 @Override
170 public int hashCode() {
Jian Lid56f97e2016-07-19 15:48:15 +0900171 return Objects.hash(lcafType, reserved1, reserved2, flag, length);
Jian Li09596002016-07-15 17:46:49 +0900172 }
173
174 @Override
175 public boolean equals(Object obj) {
176 if (this == obj) {
177 return true;
178 }
179
180 if (obj instanceof LispLcafAddress) {
181 final LispLcafAddress other = (LispLcafAddress) obj;
182 return Objects.equals(this.lcafType, other.lcafType) &&
Jian Lic7e20a52016-07-18 19:03:49 +0900183 Objects.equals(this.reserved1, other.reserved1) &&
184 Objects.equals(this.reserved2, other.reserved2) &&
185 Objects.equals(this.flag, other.flag) &&
186 Objects.equals(this.length, other.length);
Jian Li09596002016-07-15 17:46:49 +0900187 }
188 return false;
189 }
190
191 @Override
192 public String toString() {
193 return toStringHelper(this)
194 .add("lcafType", lcafType)
Jian Lic7e20a52016-07-18 19:03:49 +0900195 .add("reserved1", reserved1)
196 .add("reserved2", reserved2)
197 .add("flag", flag)
198 .add("length", length)
Jian Li09596002016-07-15 17:46:49 +0900199 .toString();
200 }
201}