blob: 85e5a86baeba14e620d5ee737e6b17d3f90d961c [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
Jian Lie9af3b42016-08-08 15:50:01 +090018import com.google.common.collect.ImmutableList;
19
Jian Lic7e20a52016-07-18 19:03:49 +090020import java.util.List;
21import java.util.Objects;
22
23import static com.google.common.base.MoreObjects.toStringHelper;
24
25/**
26 * List type LCAF address class.
Jian Li8fc2d2f2016-08-08 14:43:53 +090027 * <p>
Jian Lic7e20a52016-07-18 19:03:49 +090028 * 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 Li8fc2d2f2016-08-08 14:43:53 +090031 * <pre>
32 * {@literal
Jian Lic7e20a52016-07-18 19:03:49 +090033 * 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 Li8fc2d2f2016-08-08 14:43:53 +090052 * }</pre>
Jian Lic7e20a52016-07-18 19:03:49 +090053 */
54public 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 Lie9af3b42016-08-08 15:50:01 +090066 this.addresses = addresses;
Jian Lic7e20a52016-07-18 19:03:49 +090067 }
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 Lie9af3b42016-08-08 15:50:01 +090075 return ImmutableList.copyOf(addresses);
Jian Lic7e20a52016-07-18 19:03:49 +090076 }
77
78 @Override
79 public int hashCode() {
Jian Lid56f97e2016-07-19 15:48:15 +090080 return Objects.hash(addresses);
Jian Lic7e20a52016-07-18 19:03:49 +090081 }
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}