blob: b44905eec278be6a80c7b78a034f17e0a128600c [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.
24 * Instance ID type is defined in draft-ietf-lisp-lcaf-13
25 * https://tools.ietf.org/html/draft-ietf-lisp-lcaf-13#page-7
26 *
27 * 0 1 2 3
28 * 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
29 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
30 * | AFI = 16387 | Rsvd1 | Flags |
31 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
32 * | Type = 2 | IID mask-len | 4 + n |
33 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
34 * | Instance ID |
35 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
36 * | AFI = x | Address ... |
37 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38 */
39public class LispSegmentLcafAddress extends LispLcafAddress {
40
41 private final LispAfiAddress address;
42 private final int instanceId;
43
44 /**
45 * Initializes segment type LCAF address.
46 *
47 * @param idMaskLength Id mask length
48 * @param instanceId instance id
49 * @param address address
50 */
51 public LispSegmentLcafAddress(byte idMaskLength, int instanceId, LispAfiAddress address) {
52 super(LispCanonicalAddressFormatEnum.SEGMENT, idMaskLength);
53 this.address = address;
54 this.instanceId = instanceId;
55 }
56
57 /**
58 * Obtains address.
59 *
60 * @return address
61 */
62 public LispAfiAddress getAddress() {
63 return address;
64 }
65
66 /**
67 * Obtains instance id.
68 *
69 * @return instance id
70 */
71 public int getInstanceId() {
72 return instanceId;
73 }
74
75 /**
76 * Obtains id mask length.
77 *
78 * @return id mask length
79 */
80 public byte getIdMaskLength() {
81 return reserved2;
82 }
83
84 @Override
85 public int hashCode() {
86 final int prime = 31;
87 int result = super.hashCode();
88 result = prime * result + ((address == null) ? 0 : address.hashCode());
89 result = prime * result + instanceId;
90 result = prime * result + reserved2;
91 return result;
92 }
93
94 @Override
95 public boolean equals(Object obj) {
96 if (this == obj) {
97 return true;
98 }
99
100 if (obj instanceof LispSegmentLcafAddress) {
101 final LispSegmentLcafAddress other = (LispSegmentLcafAddress) obj;
102 return Objects.equals(this.address, other.address) &&
103 Objects.equals(this.instanceId, other.instanceId) &&
104 Objects.equals(this.reserved2, other.reserved2);
105 }
106 return false;
107 }
108
109 @Override
110 public String toString() {
111 return toStringHelper(this)
112 .add("address", address)
113 .add("instanceId", instanceId)
114 .add("idMaskLength", reserved2)
115 .toString();
116 }
117}