Jian Li | c7e20a5 | 2016-07-18 19:03: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.List; |
| 19 | import java.util.Objects; |
| 20 | |
| 21 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 22 | |
| 23 | /** |
| 24 | * List type LCAF address class. |
| 25 | * |
| 26 | * List type is defined in draft-ietf-lisp-lcaf-13 |
| 27 | * https://tools.ietf.org/html/draft-ietf-lisp-lcaf-13#page-21 |
| 28 | * |
| 29 | * 0 1 2 3 |
| 30 | * 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 |
| 31 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 32 | * | AFI = 16387 | Rsvd1 | Flags | |
| 33 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 34 | * | Type = 1 | Rsvd2 | 2 + 4 + 2 + 16 | |
| 35 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 36 | * | AFI = 1 | IPv4 Address ... | |
| 37 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 38 | * | ... IPv4 Address | AFI = 2 | |
| 39 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 40 | * | IPv6 Address ... | |
| 41 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 42 | * | ... IPv6 Address ... | |
| 43 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 44 | * | ... IPv6 Address ... | |
| 45 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 46 | * | ... IPv6 Address | |
| 47 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 48 | */ |
| 49 | public class LispListLcafAddress extends LispLcafAddress { |
| 50 | |
| 51 | private static final byte LENGTH = 24; |
| 52 | List<LispAfiAddress> addresses; |
| 53 | |
| 54 | /** |
| 55 | * Initializes list type LCAF address. |
| 56 | * |
| 57 | * @param addresses a set of IPv4 and IPv6 addresses |
| 58 | */ |
| 59 | public LispListLcafAddress(List<LispAfiAddress> addresses) { |
| 60 | super(LispCanonicalAddressFormatEnum.LIST, LENGTH); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Obtains a set of AFI addresses including IPv4 and IPv6. |
| 65 | * |
| 66 | * @return a set of AFI addresses |
| 67 | */ |
| 68 | public List<LispAfiAddress> getAddresses() { |
| 69 | return addresses; |
| 70 | } |
| 71 | |
| 72 | @Override |
| 73 | public int hashCode() { |
Jian Li | d56f97e | 2016-07-19 15:48:15 +0900 | [diff] [blame^] | 74 | return Objects.hash(addresses); |
Jian Li | c7e20a5 | 2016-07-18 19:03:49 +0900 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | @Override |
| 78 | public boolean equals(Object obj) { |
| 79 | if (this == obj) { |
| 80 | return true; |
| 81 | } |
| 82 | |
| 83 | if (obj instanceof LispListLcafAddress) { |
| 84 | final LispListLcafAddress other = (LispListLcafAddress) obj; |
| 85 | return Objects.equals(this.addresses, other.addresses); |
| 86 | } |
| 87 | return false; |
| 88 | } |
| 89 | |
| 90 | @Override |
| 91 | public String toString() { |
| 92 | return toStringHelper(this) |
| 93 | .add("addresses", addresses) |
| 94 | .toString(); |
| 95 | } |
| 96 | } |