blob: e92810a22b227fc2106b033f40221c20ebf97d63 [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.
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 */
49public 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() {
74 final int prime = 31;
75 int result = super.hashCode();
76 result = prime * result + ((addresses == null) ? 0 : addresses.hashCode());
77 return result;
78 }
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}