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