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