blob: 6204983074ee9a59aee19e24609bdc4e590456b6 [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.Objects;
19
20import static com.google.common.base.MoreObjects.toStringHelper;
21
22/**
23 * Instance ID type LCAF address class.
Jian Li8fc2d2f2016-08-08 14:43:53 +090024 * <p>
Jian Lic7e20a52016-07-18 19:03:49 +090025 * Instance ID type is defined in draft-ietf-lisp-lcaf-13
26 * https://tools.ietf.org/html/draft-ietf-lisp-lcaf-13#page-7
27 *
Jian Li8fc2d2f2016-08-08 14:43:53 +090028 * <pre>
29 * {@literal
Jian Lic7e20a52016-07-18 19:03:49 +090030 * 0 1 2 3
31 * 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
32 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
33 * | AFI = 16387 | Rsvd1 | Flags |
34 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
35 * | Type = 2 | IID mask-len | 4 + n |
36 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
37 * | Instance ID |
38 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
39 * | AFI = x | Address ... |
40 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Jian Li8fc2d2f2016-08-08 14:43:53 +090041 * }</pre>
Jian Lic7e20a52016-07-18 19:03:49 +090042 */
43public class LispSegmentLcafAddress extends LispLcafAddress {
44
45 private final LispAfiAddress address;
46 private final int instanceId;
47
48 /**
49 * Initializes segment type LCAF address.
50 *
51 * @param idMaskLength Id mask length
52 * @param instanceId instance id
53 * @param address address
54 */
55 public LispSegmentLcafAddress(byte idMaskLength, int instanceId, LispAfiAddress address) {
56 super(LispCanonicalAddressFormatEnum.SEGMENT, idMaskLength);
57 this.address = address;
58 this.instanceId = instanceId;
59 }
60
61 /**
62 * Obtains address.
63 *
64 * @return address
65 */
66 public LispAfiAddress getAddress() {
67 return address;
68 }
69
70 /**
71 * Obtains instance id.
72 *
73 * @return instance id
74 */
75 public int getInstanceId() {
76 return instanceId;
77 }
78
79 /**
80 * Obtains id mask length.
81 *
82 * @return id mask length
83 */
84 public byte getIdMaskLength() {
85 return reserved2;
86 }
87
88 @Override
89 public int hashCode() {
Jian Lid56f97e2016-07-19 15:48:15 +090090 return Objects.hash(address, instanceId, reserved2);
Jian Lic7e20a52016-07-18 19:03:49 +090091 }
92
93 @Override
94 public boolean equals(Object obj) {
95 if (this == obj) {
96 return true;
97 }
98
99 if (obj instanceof LispSegmentLcafAddress) {
100 final LispSegmentLcafAddress other = (LispSegmentLcafAddress) obj;
101 return Objects.equals(this.address, other.address) &&
102 Objects.equals(this.instanceId, other.instanceId) &&
103 Objects.equals(this.reserved2, other.reserved2);
104 }
105 return false;
106 }
107
108 @Override
109 public String toString() {
110 return toStringHelper(this)
111 .add("address", address)
112 .add("instanceId", instanceId)
113 .add("idMaskLength", reserved2)
114 .toString();
115 }
116}