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