blob: 6c026e7f0cd929c04ed94347b571e9f109b38af0 [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 * Source/Dest key type LCAF address class.
Jian Li8fc2d2f2016-08-08 14:43:53 +090024 * <p>
Jian Lic7e20a52016-07-18 19:03:49 +090025 * Source destination key type is defined in draft-ietf-lisp-lcaf-13
26 * https://tools.ietf.org/html/draft-ietf-lisp-lcaf-13#page-18
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 = 12 | Rsvd2 | 4 + n |
36 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
37 * | Reserved | Source-ML | Dest-ML |
38 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
39 * | AFI = x | Source-Prefix ... |
40 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
41 * | AFI = x | Destination-Prefix ... |
42 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Jian Li8fc2d2f2016-08-08 14:43:53 +090043 * }</pre>
Jian Lic7e20a52016-07-18 19:03:49 +090044 */
45public class LispSourceDestLcafAddress extends LispLcafAddress {
46
47 private LispAfiAddress srcPrefix;
48 private LispAfiAddress dstPrefix;
49 private final byte srcMaskLength;
50 private final byte dstMaskLength;
51 private final short reserved;
52
53 /**
54 * Initializes source/dest key type LCAF address.
55 */
56 public LispSourceDestLcafAddress() {
57 super(LispCanonicalAddressFormatEnum.SOURCE_DEST);
58 srcMaskLength = 0;
59 dstMaskLength = 0;
60 reserved = 0;
61 }
62
63 /**
64 * Initializes source/dest key type LCAF address.
65 *
66 * @param reserved reserved
67 * @param srcMaskLength source mask length
68 * @param dstMaskLength destination mask length
69 * @param srcPrefix source address prefix
70 * @param dstPrefix destination address prefix
71 */
72 public LispSourceDestLcafAddress(short reserved, byte srcMaskLength,
73 byte dstMaskLength,
74 LispAfiAddress srcPrefix,
75 LispAfiAddress dstPrefix) {
76 super(LispCanonicalAddressFormatEnum.SOURCE_DEST);
77 this.reserved = reserved;
78 this.srcMaskLength = srcMaskLength;
79 this.dstMaskLength = dstMaskLength;
80 this.srcPrefix = srcPrefix;
81 this.dstPrefix = dstPrefix;
82 }
83
84 /**
85 * Obtains source address prefix.
86 *
87 * @return source address prefix
88 */
89 public LispAfiAddress getSrcPrefix() {
90 return srcPrefix;
91 }
92
93 /**
94 * Obtains destination address prefix.
95 *
96 * @return destination address prefix
97 */
98 public LispAfiAddress getDstPrefix() {
99 return dstPrefix;
100 }
101
102 /**
103 * Obtains source mask length.
104 *
105 * @return source mask length
106 */
107 public byte getSrcMaskLength() {
108 return srcMaskLength;
109 }
110
111 /**
112 * Obtains destination mask length.
113 *
114 * @return destination mask length
115 */
116 public byte getDstMaskLength() {
117 return dstMaskLength;
118 }
119
120 /**
121 * Obtains reserved value.
122 *
123 * @return reserved value
124 */
125 public short getReserved() {
126 return reserved;
127 }
128
129 @Override
130 public int hashCode() {
Jian Lid56f97e2016-07-19 15:48:15 +0900131 return Objects.hash(srcPrefix, dstPrefix, srcMaskLength, dstMaskLength, reserved);
Jian Lic7e20a52016-07-18 19:03:49 +0900132 }
133
134 @Override
135 public boolean equals(Object obj) {
136 if (this == obj) {
137 return true;
138 }
139
140 if (obj instanceof LispSourceDestLcafAddress) {
141 final LispSourceDestLcafAddress other = (LispSourceDestLcafAddress) obj;
142 return Objects.equals(this.srcPrefix, other.srcPrefix) &&
143 Objects.equals(this.dstPrefix, other.dstPrefix) &&
144 Objects.equals(this.srcMaskLength, other.srcMaskLength) &&
145 Objects.equals(this.dstMaskLength, other.dstMaskLength) &&
146 Objects.equals(this.reserved, other.reserved);
147 }
148 return false;
149 }
150
151 @Override
152 public String toString() {
153 return toStringHelper(this)
154 .add("source prefix", srcPrefix)
155 .add("destination prefix", dstPrefix)
156 .add("source mask length", srcMaskLength)
157 .add("destination mask length", dstMaskLength)
158 .add("reserved", reserved)
159 .toString();
160 }
161}