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 | * |
| 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 Li | 0959600 | 2016-07-15 17:46:49 +0900 | [diff] [blame] | 32 | */ |
| 33 | public class LispLcafAddress extends LispAfiAddress { |
| 34 | |
| 35 | protected final LispCanonicalAddressFormatEnum lcafType; |
Jian Li | c7e20a5 | 2016-07-18 19:03:49 +0900 | [diff] [blame^] | 36 | protected final byte reserved1; |
| 37 | protected final byte reserved2; |
| 38 | protected final byte flag; |
| 39 | protected final byte length; |
Jian Li | 0959600 | 2016-07-15 17:46:49 +0900 | [diff] [blame] | 40 | |
| 41 | /** |
| 42 | * Initializes LCAF address. |
| 43 | * |
| 44 | * @param lcafType LCAF type |
Jian Li | c7e20a5 | 2016-07-18 19:03:49 +0900 | [diff] [blame^] | 45 | * @param reserved1 reserved1 field |
| 46 | * @param reserved2 reserved2 field |
| 47 | * @param flag flag field |
| 48 | * @param length length field |
Jian Li | 0959600 | 2016-07-15 17:46:49 +0900 | [diff] [blame] | 49 | */ |
Jian Li | c7e20a5 | 2016-07-18 19:03:49 +0900 | [diff] [blame^] | 50 | protected LispLcafAddress(LispCanonicalAddressFormatEnum lcafType, |
| 51 | byte reserved1, byte reserved2, byte flag, byte length) { |
Jian Li | 0959600 | 2016-07-15 17:46:49 +0900 | [diff] [blame] | 52 | super(AddressFamilyIdentifierEnum.LCAF); |
| 53 | this.lcafType = lcafType; |
Jian Li | c7e20a5 | 2016-07-18 19:03:49 +0900 | [diff] [blame^] | 54 | 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 Li | 0959600 | 2016-07-15 17:46:49 +0900 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Obtains LCAF type. |
| 126 | * |
| 127 | * @return LCAF type |
| 128 | */ |
| 129 | public LispCanonicalAddressFormatEnum getType() { |
| 130 | return lcafType; |
| 131 | } |
| 132 | |
| 133 | /** |
Jian Li | c7e20a5 | 2016-07-18 19:03:49 +0900 | [diff] [blame^] | 134 | * Obtains LCAF reserved1 value. |
Jian Li | 0959600 | 2016-07-15 17:46:49 +0900 | [diff] [blame] | 135 | * |
Jian Li | c7e20a5 | 2016-07-18 19:03:49 +0900 | [diff] [blame^] | 136 | * @return LCAF reserved1 value |
Jian Li | 0959600 | 2016-07-15 17:46:49 +0900 | [diff] [blame] | 137 | */ |
Jian Li | c7e20a5 | 2016-07-18 19:03:49 +0900 | [diff] [blame^] | 138 | 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 Li | 0959600 | 2016-07-15 17:46:49 +0900 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | @Override |
| 170 | public int hashCode() { |
| 171 | final int prime = 31; |
| 172 | int result = super.hashCode(); |
| 173 | result = prime * result + ((lcafType == null) ? 0 : lcafType.hashCode()); |
Jian Li | c7e20a5 | 2016-07-18 19:03:49 +0900 | [diff] [blame^] | 174 | result = prime * result + reserved1; |
| 175 | result = prime * result + reserved2; |
| 176 | result = prime * result + flag; |
| 177 | result = prime * result + length; |
Jian Li | 0959600 | 2016-07-15 17:46:49 +0900 | [diff] [blame] | 178 | return result; |
| 179 | } |
| 180 | |
| 181 | @Override |
| 182 | public boolean equals(Object obj) { |
| 183 | if (this == obj) { |
| 184 | return true; |
| 185 | } |
| 186 | |
| 187 | if (obj instanceof LispLcafAddress) { |
| 188 | final LispLcafAddress other = (LispLcafAddress) obj; |
| 189 | return Objects.equals(this.lcafType, other.lcafType) && |
Jian Li | c7e20a5 | 2016-07-18 19:03:49 +0900 | [diff] [blame^] | 190 | Objects.equals(this.reserved1, other.reserved1) && |
| 191 | Objects.equals(this.reserved2, other.reserved2) && |
| 192 | Objects.equals(this.flag, other.flag) && |
| 193 | Objects.equals(this.length, other.length); |
Jian Li | 0959600 | 2016-07-15 17:46:49 +0900 | [diff] [blame] | 194 | } |
| 195 | return false; |
| 196 | } |
| 197 | |
| 198 | @Override |
| 199 | public String toString() { |
| 200 | return toStringHelper(this) |
| 201 | .add("lcafType", lcafType) |
Jian Li | c7e20a5 | 2016-07-18 19:03:49 +0900 | [diff] [blame^] | 202 | .add("reserved1", reserved1) |
| 203 | .add("reserved2", reserved2) |
| 204 | .add("flag", flag) |
| 205 | .add("length", length) |
Jian Li | 0959600 | 2016-07-15 17:46:49 +0900 | [diff] [blame] | 206 | .toString(); |
| 207 | } |
| 208 | } |