Jian Li | 0959600 | 2016-07-15 17:46:49 +0900 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.lisp.msg.types; |
| 17 | |
| 18 | import java.util.Objects; |
| 19 | |
| 20 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 21 | |
| 22 | /** |
| 23 | * LISP Canonical Address Formatted address class. |
Jian Li | c7e20a5 | 2016-07-18 19:03:49 +0900 | [diff] [blame] | 24 | * |
Jian Li | 8fc2d2f | 2016-08-08 14:43:53 +0900 | [diff] [blame^] | 25 | * <pre> |
| 26 | * {@literal |
Jian Li | c7e20a5 | 2016-07-18 19:03:49 +0900 | [diff] [blame] | 27 | * 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 Li | 8fc2d2f | 2016-08-08 14:43:53 +0900 | [diff] [blame^] | 34 | * }</pre> |
Jian Li | 0959600 | 2016-07-15 17:46:49 +0900 | [diff] [blame] | 35 | */ |
| 36 | public class LispLcafAddress extends LispAfiAddress { |
| 37 | |
| 38 | protected final LispCanonicalAddressFormatEnum lcafType; |
Jian Li | c7e20a5 | 2016-07-18 19:03:49 +0900 | [diff] [blame] | 39 | protected final byte reserved1; |
| 40 | protected final byte reserved2; |
| 41 | protected final byte flag; |
| 42 | protected final byte length; |
Jian Li | 0959600 | 2016-07-15 17:46:49 +0900 | [diff] [blame] | 43 | |
| 44 | /** |
| 45 | * Initializes LCAF address. |
| 46 | * |
| 47 | * @param lcafType LCAF type |
Jian Li | c7e20a5 | 2016-07-18 19:03:49 +0900 | [diff] [blame] | 48 | * @param reserved1 reserved1 field |
| 49 | * @param reserved2 reserved2 field |
| 50 | * @param flag flag field |
| 51 | * @param length length field |
Jian Li | 0959600 | 2016-07-15 17:46:49 +0900 | [diff] [blame] | 52 | */ |
Jian Li | c7e20a5 | 2016-07-18 19:03:49 +0900 | [diff] [blame] | 53 | protected LispLcafAddress(LispCanonicalAddressFormatEnum lcafType, |
| 54 | byte reserved1, byte reserved2, byte flag, byte length) { |
Jian Li | 0959600 | 2016-07-15 17:46:49 +0900 | [diff] [blame] | 55 | super(AddressFamilyIdentifierEnum.LCAF); |
| 56 | this.lcafType = lcafType; |
Jian Li | c7e20a5 | 2016-07-18 19:03:49 +0900 | [diff] [blame] | 57 | 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 Li | 0959600 | 2016-07-15 17:46:49 +0900 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Obtains LCAF type. |
| 129 | * |
| 130 | * @return LCAF type |
| 131 | */ |
| 132 | public LispCanonicalAddressFormatEnum getType() { |
| 133 | return lcafType; |
| 134 | } |
| 135 | |
| 136 | /** |
Jian Li | c7e20a5 | 2016-07-18 19:03:49 +0900 | [diff] [blame] | 137 | * Obtains LCAF reserved1 value. |
Jian Li | 0959600 | 2016-07-15 17:46:49 +0900 | [diff] [blame] | 138 | * |
Jian Li | c7e20a5 | 2016-07-18 19:03:49 +0900 | [diff] [blame] | 139 | * @return LCAF reserved1 value |
Jian Li | 0959600 | 2016-07-15 17:46:49 +0900 | [diff] [blame] | 140 | */ |
Jian Li | c7e20a5 | 2016-07-18 19:03:49 +0900 | [diff] [blame] | 141 | 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 Li | 0959600 | 2016-07-15 17:46:49 +0900 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | @Override |
| 173 | public int hashCode() { |
Jian Li | d56f97e | 2016-07-19 15:48:15 +0900 | [diff] [blame] | 174 | return Objects.hash(lcafType, reserved1, reserved2, flag, length); |
Jian Li | 0959600 | 2016-07-15 17:46:49 +0900 | [diff] [blame] | 175 | } |
| 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 Li | c7e20a5 | 2016-07-18 19:03:49 +0900 | [diff] [blame] | 186 | 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 Li | 0959600 | 2016-07-15 17:46:49 +0900 | [diff] [blame] | 190 | } |
| 191 | return false; |
| 192 | } |
| 193 | |
| 194 | @Override |
| 195 | public String toString() { |
| 196 | return toStringHelper(this) |
| 197 | .add("lcafType", lcafType) |
Jian Li | c7e20a5 | 2016-07-18 19:03:49 +0900 | [diff] [blame] | 198 | .add("reserved1", reserved1) |
| 199 | .add("reserved2", reserved2) |
| 200 | .add("flag", flag) |
| 201 | .add("length", length) |
Jian Li | 0959600 | 2016-07-15 17:46:49 +0900 | [diff] [blame] | 202 | .toString(); |
| 203 | } |
| 204 | } |