Committed by
Gerrit Code Review
[ONOS-4718] Initial implementation of LISP address deserializer
Change-Id: I522e16e7fd197380cf4c99038561fe9aa8f93730
Showing
16 changed files
with
732 additions
and
68 deletions
protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/exceptions/LispReaderException.java
0 → 100644
1 | +/* | ||
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 | + */ | ||
16 | +package org.onosproject.lisp.msg.exceptions; | ||
17 | + | ||
18 | +/** | ||
19 | + * LISP address or message reader exception. | ||
20 | + */ | ||
21 | +public class LispReaderException extends Exception { | ||
22 | + | ||
23 | + /** | ||
24 | + * Constructor for LispReaderException. | ||
25 | + */ | ||
26 | + public LispReaderException() { | ||
27 | + super(); | ||
28 | + } | ||
29 | + | ||
30 | + /** | ||
31 | + * Constructor for LispReaderException with message and cause parameters. | ||
32 | + * | ||
33 | + * @param message exception message | ||
34 | + * @param cause throwable cause | ||
35 | + */ | ||
36 | + public LispReaderException(final String message, final Throwable cause) { | ||
37 | + super(message, cause); | ||
38 | + } | ||
39 | + | ||
40 | + /** | ||
41 | + * Constructor for LispReaderException with message parameter. | ||
42 | + * | ||
43 | + * @param message exception message | ||
44 | + */ | ||
45 | + public LispReaderException(final String message) { | ||
46 | + super(message); | ||
47 | + } | ||
48 | + | ||
49 | + /** | ||
50 | + * Constructor for LispReaderException with cause parameter. | ||
51 | + * | ||
52 | + * @param cause throwable cause | ||
53 | + */ | ||
54 | + public LispReaderException(final Throwable cause) { | ||
55 | + super(cause); | ||
56 | + } | ||
57 | +} |
1 | +/* | ||
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 | + */ | ||
16 | +package org.onosproject.lisp.msg.types; | ||
17 | + | ||
18 | +import io.netty.buffer.ByteBuf; | ||
19 | +import org.onosproject.lisp.msg.exceptions.LispParseError; | ||
20 | +import org.onosproject.lisp.msg.exceptions.LispReaderException; | ||
21 | + | ||
22 | +/** | ||
23 | + * An interface for de-serializing LISP address. | ||
24 | + */ | ||
25 | +public interface LispAddressReader<T> { | ||
26 | + | ||
27 | + /** | ||
28 | + * Reads from byte buffer and de-serialize the LISP address. | ||
29 | + * | ||
30 | + * @param byteBuf byte buffer | ||
31 | + * @return LISP address type instance | ||
32 | + * @throws LispParseError LISP address parse error | ||
33 | + */ | ||
34 | + T readFrom(ByteBuf byteBuf) throws LispParseError, LispReaderException; | ||
35 | +} |
... | @@ -15,6 +15,11 @@ | ... | @@ -15,6 +15,11 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.lisp.msg.types; | 16 | package org.onosproject.lisp.msg.types; |
17 | 17 | ||
18 | +import io.netty.buffer.ByteBuf; | ||
19 | +import org.onosproject.lisp.msg.exceptions.LispParseError; | ||
20 | +import org.onosproject.lisp.msg.exceptions.LispReaderException; | ||
21 | + | ||
22 | +import java.nio.ByteBuffer; | ||
18 | import java.util.Objects; | 23 | import java.util.Objects; |
19 | 24 | ||
20 | import static com.google.common.base.MoreObjects.toStringHelper; | 25 | import static com.google.common.base.MoreObjects.toStringHelper; |
... | @@ -44,41 +49,35 @@ import static com.google.common.base.MoreObjects.toStringHelper; | ... | @@ -44,41 +49,35 @@ import static com.google.common.base.MoreObjects.toStringHelper; |
44 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 49 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
45 | * }</pre> | 50 | * }</pre> |
46 | */ | 51 | */ |
47 | -public class LispAppDataLcafAddress extends LispLcafAddress { | 52 | +public final class LispAppDataLcafAddress extends LispLcafAddress { |
48 | 53 | ||
49 | private final byte protocol; | 54 | private final byte protocol; |
50 | private final int ipTos; | 55 | private final int ipTos; |
51 | - private final short localPort; | 56 | + private final short localPortLow; |
52 | - private final short remotePort; | 57 | + private final short localPortHigh; |
58 | + private final short remotePortLow; | ||
59 | + private final short remotePortHigh; | ||
53 | private LispAfiAddress address; | 60 | private LispAfiAddress address; |
54 | 61 | ||
55 | /** | 62 | /** |
56 | - * Initializes application data type LCAF address. | ||
57 | - */ | ||
58 | - public LispAppDataLcafAddress() { | ||
59 | - super(LispCanonicalAddressFormatEnum.APPLICATION_DATA); | ||
60 | - this.protocol = 0; | ||
61 | - this.ipTos = 0; | ||
62 | - this.localPort = 0; | ||
63 | - this.remotePort = 0; | ||
64 | - } | ||
65 | - | ||
66 | - /** | ||
67 | - * Initializes application data type LCAF address. | ||
68 | - * | ||
69 | * @param protocol protocol number | 63 | * @param protocol protocol number |
70 | - * @param ipTos ip type of service | 64 | + * @param ipTos IP type of service |
71 | - * @param localPort local port number | 65 | + * @param localPortLow low-ranged local port number |
72 | - * @param remotePort remote port number | 66 | + * @param localPortHigh high-ranged local port number |
67 | + * @param remotePortLow low-ranged remote port number | ||
68 | + * @param remotePortHigh high-ranged remote port number | ||
73 | * @param address address | 69 | * @param address address |
74 | */ | 70 | */ |
75 | - public LispAppDataLcafAddress(byte protocol, int ipTos, short localPort, short remotePort, | 71 | + private LispAppDataLcafAddress(byte protocol, int ipTos, short localPortLow, |
76 | - LispAfiAddress address) { | 72 | + short localPortHigh, short remotePortLow, |
73 | + short remotePortHigh, LispAfiAddress address) { | ||
77 | super(LispCanonicalAddressFormatEnum.APPLICATION_DATA); | 74 | super(LispCanonicalAddressFormatEnum.APPLICATION_DATA); |
78 | this.protocol = protocol; | 75 | this.protocol = protocol; |
79 | this.ipTos = ipTos; | 76 | this.ipTos = ipTos; |
80 | - this.localPort = localPort; | 77 | + this.localPortLow = localPortLow; |
81 | - this.remotePort = remotePort; | 78 | + this.localPortHigh = localPortHigh; |
79 | + this.remotePortLow = remotePortLow; | ||
80 | + this.remotePortHigh = remotePortHigh; | ||
82 | this.address = address; | 81 | this.address = address; |
83 | } | 82 | } |
84 | 83 | ||
... | @@ -101,21 +100,39 @@ public class LispAppDataLcafAddress extends LispLcafAddress { | ... | @@ -101,21 +100,39 @@ public class LispAppDataLcafAddress extends LispLcafAddress { |
101 | } | 100 | } |
102 | 101 | ||
103 | /** | 102 | /** |
104 | - * Obtains local port number. | 103 | + * Obtains low-ranged local port number. |
104 | + * | ||
105 | + * @return low-ranged local port number | ||
106 | + */ | ||
107 | + public short getLocalPortLow() { | ||
108 | + return localPortLow; | ||
109 | + } | ||
110 | + | ||
111 | + /** | ||
112 | + * Obtains high-ranged local port number. | ||
113 | + * | ||
114 | + * @return high-ranged local port number | ||
115 | + */ | ||
116 | + public short getLocalPortHigh() { | ||
117 | + return localPortHigh; | ||
118 | + } | ||
119 | + | ||
120 | + /** | ||
121 | + * Obtains low-ranged remote port number. | ||
105 | * | 122 | * |
106 | - * @return local port number | 123 | + * @return low-ranged remote port number |
107 | */ | 124 | */ |
108 | - public short getLocalPort() { | 125 | + public short getRemotePortLow() { |
109 | - return localPort; | 126 | + return remotePortLow; |
110 | } | 127 | } |
111 | 128 | ||
112 | /** | 129 | /** |
113 | - * Obtains remote port number. | 130 | + * Obtains high-ranged remote port number. |
114 | * | 131 | * |
115 | - * @return remote port number | 132 | + * @return high-ranged remote port number |
116 | */ | 133 | */ |
117 | - public short getRemotePort() { | 134 | + public short getRemotePortHigh() { |
118 | - return remotePort; | 135 | + return remotePortHigh; |
119 | } | 136 | } |
120 | 137 | ||
121 | /** | 138 | /** |
... | @@ -129,7 +146,8 @@ public class LispAppDataLcafAddress extends LispLcafAddress { | ... | @@ -129,7 +146,8 @@ public class LispAppDataLcafAddress extends LispLcafAddress { |
129 | 146 | ||
130 | @Override | 147 | @Override |
131 | public int hashCode() { | 148 | public int hashCode() { |
132 | - return Objects.hash(address, protocol, ipTos, localPort, remotePort); | 149 | + return Objects.hash(address, protocol, ipTos, localPortLow, |
150 | + localPortHigh, remotePortLow, remotePortHigh); | ||
133 | } | 151 | } |
134 | 152 | ||
135 | @Override | 153 | @Override |
... | @@ -143,8 +161,10 @@ public class LispAppDataLcafAddress extends LispLcafAddress { | ... | @@ -143,8 +161,10 @@ public class LispAppDataLcafAddress extends LispLcafAddress { |
143 | return Objects.equals(this.address, other.address) && | 161 | return Objects.equals(this.address, other.address) && |
144 | Objects.equals(this.protocol, other.protocol) && | 162 | Objects.equals(this.protocol, other.protocol) && |
145 | Objects.equals(this.ipTos, other.ipTos) && | 163 | Objects.equals(this.ipTos, other.ipTos) && |
146 | - Objects.equals(this.localPort, other.localPort) && | 164 | + Objects.equals(this.localPortLow, other.localPortLow) && |
147 | - Objects.equals(this.remotePort, other.remotePort); | 165 | + Objects.equals(this.localPortHigh, other.localPortHigh) && |
166 | + Objects.equals(this.remotePortLow, other.remotePortLow) && | ||
167 | + Objects.equals(this.remotePortHigh, other.remotePortHigh); | ||
148 | } | 168 | } |
149 | return false; | 169 | return false; |
150 | } | 170 | } |
... | @@ -155,8 +175,154 @@ public class LispAppDataLcafAddress extends LispLcafAddress { | ... | @@ -155,8 +175,154 @@ public class LispAppDataLcafAddress extends LispLcafAddress { |
155 | .add("address", address) | 175 | .add("address", address) |
156 | .add("protocol", protocol) | 176 | .add("protocol", protocol) |
157 | .add("ip type of service", ipTos) | 177 | .add("ip type of service", ipTos) |
158 | - .add("local port number", localPort) | 178 | + .add("low-ranged local port number", localPortLow) |
159 | - .add("remote port number", remotePort) | 179 | + .add("high-ranged local port number", localPortHigh) |
180 | + .add("low-ranged remote port number", remotePortLow) | ||
181 | + .add("high-ranged remote port number", remotePortHigh) | ||
160 | .toString(); | 182 | .toString(); |
161 | } | 183 | } |
184 | + | ||
185 | + public static final class AppDataAddressBuilder { | ||
186 | + private byte protocol; | ||
187 | + private int ipTos; | ||
188 | + private short localPortLow; | ||
189 | + private short localPortHigh; | ||
190 | + private short remotePortLow; | ||
191 | + private short remotePortHigh; | ||
192 | + private LispAfiAddress address; | ||
193 | + | ||
194 | + /** | ||
195 | + * Sets protocol number. | ||
196 | + * | ||
197 | + * @param protocol protocol number | ||
198 | + * @return AppDataAddressBuilder object | ||
199 | + */ | ||
200 | + AppDataAddressBuilder withProtocol(byte protocol) { | ||
201 | + this.protocol = protocol; | ||
202 | + return this; | ||
203 | + } | ||
204 | + | ||
205 | + /** | ||
206 | + * Sets IP type of service. | ||
207 | + * | ||
208 | + * @param ipTos IP type of service | ||
209 | + * @return AppDataAddressBuilder object | ||
210 | + */ | ||
211 | + AppDataAddressBuilder withIpTos(int ipTos) { | ||
212 | + this.ipTos = ipTos; | ||
213 | + return this; | ||
214 | + } | ||
215 | + | ||
216 | + /** | ||
217 | + * Sets low-ranged local port number. | ||
218 | + * | ||
219 | + * @param localPortLow low-ranged local port number | ||
220 | + * @return AppDataAddressBuilder object | ||
221 | + */ | ||
222 | + AppDataAddressBuilder withLocalPortLow(short localPortLow) { | ||
223 | + this.localPortLow = localPortLow; | ||
224 | + return this; | ||
225 | + } | ||
226 | + | ||
227 | + /** | ||
228 | + * Sets high-ranged local port number. | ||
229 | + * | ||
230 | + * @param localPortHigh high-ranged local port number | ||
231 | + * @return AppDataAddressBuilder object | ||
232 | + */ | ||
233 | + AppDataAddressBuilder withLocalPortHigh(short localPortHigh) { | ||
234 | + this.localPortHigh = localPortHigh; | ||
235 | + return this; | ||
236 | + } | ||
237 | + | ||
238 | + /** | ||
239 | + * Sets low-ranged remote port number. | ||
240 | + * | ||
241 | + * @param remotePortLow low-ranged remote port number | ||
242 | + * @return AppDataAddressBuilder object | ||
243 | + */ | ||
244 | + AppDataAddressBuilder withRemotePortLow(short remotePortLow) { | ||
245 | + this.remotePortLow = remotePortLow; | ||
246 | + return this; | ||
247 | + } | ||
248 | + | ||
249 | + /** | ||
250 | + * Sets high-ranged remote port number. | ||
251 | + * | ||
252 | + * @param remotePortHigh high-ranged remote port number | ||
253 | + * @return AppDataAddressBuilder object | ||
254 | + */ | ||
255 | + AppDataAddressBuilder withRemotePortHigh(short remotePortHigh) { | ||
256 | + this.remotePortHigh = remotePortHigh; | ||
257 | + return this; | ||
258 | + } | ||
259 | + | ||
260 | + /** | ||
261 | + * Sets AFI address. | ||
262 | + * | ||
263 | + * @param address AFI address | ||
264 | + * @return AppDataAddressBuilder object | ||
265 | + */ | ||
266 | + AppDataAddressBuilder withAddress(LispAfiAddress address) { | ||
267 | + this.address = address; | ||
268 | + return this; | ||
269 | + } | ||
270 | + | ||
271 | + /** | ||
272 | + * Builds LispAppDataLcafAddress instance. | ||
273 | + * | ||
274 | + * @return LispAddDataLcafAddress instance | ||
275 | + */ | ||
276 | + LispAppDataLcafAddress build() { | ||
277 | + return new LispAppDataLcafAddress(protocol, ipTos, localPortLow, | ||
278 | + localPortHigh, remotePortLow, remotePortHigh, address); | ||
279 | + } | ||
280 | + } | ||
281 | + | ||
282 | + /** | ||
283 | + * Application data LCAF address reader class. | ||
284 | + */ | ||
285 | + public static class AppDataLcafAddressReader | ||
286 | + implements LispAddressReader<LispAppDataLcafAddress> { | ||
287 | + | ||
288 | + @Override | ||
289 | + public LispAppDataLcafAddress readFrom(ByteBuf byteBuf) throws LispParseError, LispReaderException { | ||
290 | + | ||
291 | + byte[] ipTosByte = new byte[3]; | ||
292 | + byteBuf.readBytes(ipTosByte); | ||
293 | + | ||
294 | + byte protocol = (byte) byteBuf.readUnsignedByte(); | ||
295 | + int ipTos = getPartialInt(ipTosByte); | ||
296 | + short localPortLow = (short) byteBuf.readUnsignedShort(); | ||
297 | + short localPortHigh = (short) byteBuf.readUnsignedShort(); | ||
298 | + short remotePortLow = (short) byteBuf.readUnsignedShort(); | ||
299 | + short remotePortHigh = (short) byteBuf.readUnsignedShort(); | ||
300 | + | ||
301 | + LispAfiAddress address = new LispIpAddress.IpAddressReader().readFrom(byteBuf); | ||
302 | + | ||
303 | + return new AppDataAddressBuilder() | ||
304 | + .withProtocol(protocol) | ||
305 | + .withIpTos(ipTos) | ||
306 | + .withLocalPortLow(localPortLow) | ||
307 | + .withLocalPortHigh(localPortHigh) | ||
308 | + .withRemotePortLow(remotePortLow) | ||
309 | + .withRemotePortHigh(remotePortHigh) | ||
310 | + .withAddress(address) | ||
311 | + .build(); | ||
312 | + } | ||
313 | + | ||
314 | + /** | ||
315 | + * A utility function that obtains the partial int value from byte arrays. | ||
316 | + * | ||
317 | + * @param bytes an array of bytes | ||
318 | + * @return converted integer | ||
319 | + */ | ||
320 | + public static int getPartialInt(byte[] bytes) { | ||
321 | + ByteBuffer buffer = ByteBuffer.allocate(4); | ||
322 | + buffer.position(4 - bytes.length); | ||
323 | + buffer.put(bytes); | ||
324 | + buffer.position(0); | ||
325 | + return buffer.getInt(); | ||
326 | + } | ||
327 | + } | ||
162 | } | 328 | } | ... | ... |
... | @@ -15,6 +15,10 @@ | ... | @@ -15,6 +15,10 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.lisp.msg.types; | 16 | package org.onosproject.lisp.msg.types; |
17 | 17 | ||
18 | +import io.netty.buffer.ByteBuf; | ||
19 | +import org.onosproject.lisp.msg.exceptions.LispParseError; | ||
20 | +import org.onosproject.lisp.msg.exceptions.LispReaderException; | ||
21 | + | ||
18 | import java.util.Objects; | 22 | import java.util.Objects; |
19 | 23 | ||
20 | /** | 24 | /** |
... | @@ -73,4 +77,15 @@ public class LispAsAddress extends LispAfiAddress { | ... | @@ -73,4 +77,15 @@ public class LispAsAddress extends LispAfiAddress { |
73 | public String toString() { | 77 | public String toString() { |
74 | return String.valueOf(asNum); | 78 | return String.valueOf(asNum); |
75 | } | 79 | } |
80 | + | ||
81 | + /** | ||
82 | + * Autonomous system address reader class. | ||
83 | + */ | ||
84 | + public static class AsAddressReader implements LispAddressReader<LispAsAddress> { | ||
85 | + | ||
86 | + @Override | ||
87 | + public LispAsAddress readFrom(ByteBuf byteBuf) throws LispParseError, LispReaderException { | ||
88 | + throw new LispReaderException("Unimplemented method"); | ||
89 | + } | ||
90 | + } | ||
76 | } | 91 | } | ... | ... |
... | @@ -15,6 +15,9 @@ | ... | @@ -15,6 +15,9 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.lisp.msg.types; | 16 | package org.onosproject.lisp.msg.types; |
17 | 17 | ||
18 | +import io.netty.buffer.ByteBuf; | ||
19 | +import org.onosproject.lisp.msg.exceptions.LispParseError; | ||
20 | + | ||
18 | import java.util.Objects; | 21 | import java.util.Objects; |
19 | 22 | ||
20 | import static com.google.common.base.MoreObjects.toStringHelper; | 23 | import static com.google.common.base.MoreObjects.toStringHelper; |
... | @@ -69,4 +72,24 @@ public class LispDistinguishedNameAddress extends LispAfiAddress { | ... | @@ -69,4 +72,24 @@ public class LispDistinguishedNameAddress extends LispAfiAddress { |
69 | .add("distinguished name", distinguishedName) | 72 | .add("distinguished name", distinguishedName) |
70 | .toString(); | 73 | .toString(); |
71 | } | 74 | } |
75 | + | ||
76 | + /** | ||
77 | + * Distinguished name address reader class. | ||
78 | + */ | ||
79 | + public static class DistinguishedNameAddressReader | ||
80 | + implements LispAddressReader<LispDistinguishedNameAddress> { | ||
81 | + | ||
82 | + @Override | ||
83 | + public LispDistinguishedNameAddress readFrom(ByteBuf byteBuf) throws LispParseError { | ||
84 | + | ||
85 | + StringBuilder sb = new StringBuilder(); | ||
86 | + byte character = byteBuf.readByte(); | ||
87 | + while (character != 0) { | ||
88 | + sb.append((char) character); | ||
89 | + character = byteBuf.readByte(); | ||
90 | + } | ||
91 | + | ||
92 | + return new LispDistinguishedNameAddress(sb.toString()); | ||
93 | + } | ||
94 | + } | ||
72 | } | 95 | } | ... | ... |
... | @@ -15,7 +15,10 @@ | ... | @@ -15,7 +15,10 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.lisp.msg.types; | 16 | package org.onosproject.lisp.msg.types; |
17 | 17 | ||
18 | +import io.netty.buffer.ByteBuf; | ||
18 | import org.onlab.packet.IpAddress; | 19 | import org.onlab.packet.IpAddress; |
20 | +import org.onosproject.lisp.msg.exceptions.LispParseError; | ||
21 | +import org.onosproject.lisp.msg.exceptions.LispReaderException; | ||
19 | 22 | ||
20 | /** | 23 | /** |
21 | * IP address that is used by LISP Locator. | 24 | * IP address that is used by LISP Locator. |
... | @@ -58,4 +61,25 @@ public abstract class LispIpAddress extends LispAfiAddress { | ... | @@ -58,4 +61,25 @@ public abstract class LispIpAddress extends LispAfiAddress { |
58 | public String toString() { | 61 | public String toString() { |
59 | return address.toString(); | 62 | return address.toString(); |
60 | } | 63 | } |
64 | + | ||
65 | + /** | ||
66 | + * IP Address reader class. | ||
67 | + */ | ||
68 | + public static class IpAddressReader implements LispAddressReader<LispIpAddress> { | ||
69 | + | ||
70 | + @Override | ||
71 | + public LispIpAddress readFrom(ByteBuf byteBuf) throws LispParseError, LispReaderException { | ||
72 | + | ||
73 | + // AFI code -> 16 bits | ||
74 | + short afiCode = (short) byteBuf.readUnsignedShort(); | ||
75 | + | ||
76 | + if (afiCode == 1) { | ||
77 | + return new LispIpv4Address.Ipv4AddressReader().readFrom(byteBuf); | ||
78 | + } else if (afiCode == 2) { | ||
79 | + return new LispIpv6Address.Ipv6AddressReader().readFrom(byteBuf); | ||
80 | + } | ||
81 | + | ||
82 | + return null; | ||
83 | + } | ||
84 | + } | ||
61 | } | 85 | } | ... | ... |
... | @@ -15,7 +15,9 @@ | ... | @@ -15,7 +15,9 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.lisp.msg.types; | 16 | package org.onosproject.lisp.msg.types; |
17 | 17 | ||
18 | +import io.netty.buffer.ByteBuf; | ||
18 | import org.onlab.packet.IpAddress; | 19 | import org.onlab.packet.IpAddress; |
20 | +import org.onosproject.lisp.msg.exceptions.LispParseError; | ||
19 | 21 | ||
20 | import java.util.Objects; | 22 | import java.util.Objects; |
21 | 23 | ||
... | @@ -54,4 +56,22 @@ public class LispIpv4Address extends LispIpAddress { | ... | @@ -54,4 +56,22 @@ public class LispIpv4Address extends LispIpAddress { |
54 | public int hashCode() { | 56 | public int hashCode() { |
55 | return Objects.hash(address, getAfi()); | 57 | return Objects.hash(address, getAfi()); |
56 | } | 58 | } |
59 | + | ||
60 | + /** | ||
61 | + * IPv4 address reader class. | ||
62 | + */ | ||
63 | + public static class Ipv4AddressReader implements LispAddressReader<LispIpv4Address> { | ||
64 | + | ||
65 | + private static final int SIZE_OF_IPV4_ADDRESS = 4; | ||
66 | + | ||
67 | + @Override | ||
68 | + public LispIpv4Address readFrom(ByteBuf byteBuf) throws LispParseError { | ||
69 | + | ||
70 | + byte[] ipByte = new byte[SIZE_OF_IPV4_ADDRESS]; | ||
71 | + byteBuf.readBytes(ipByte); | ||
72 | + IpAddress ipAddress = IpAddress.valueOf(IpAddress.Version.INET, ipByte); | ||
73 | + | ||
74 | + return new LispIpv4Address(ipAddress); | ||
75 | + } | ||
76 | + } | ||
57 | } | 77 | } | ... | ... |
... | @@ -15,7 +15,9 @@ | ... | @@ -15,7 +15,9 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.lisp.msg.types; | 16 | package org.onosproject.lisp.msg.types; |
17 | 17 | ||
18 | +import io.netty.buffer.ByteBuf; | ||
18 | import org.onlab.packet.IpAddress; | 19 | import org.onlab.packet.IpAddress; |
20 | +import org.onosproject.lisp.msg.exceptions.LispParseError; | ||
19 | 21 | ||
20 | import java.util.Objects; | 22 | import java.util.Objects; |
21 | 23 | ||
... | @@ -54,4 +56,22 @@ public class LispIpv6Address extends LispIpAddress { | ... | @@ -54,4 +56,22 @@ public class LispIpv6Address extends LispIpAddress { |
54 | public int hashCode() { | 56 | public int hashCode() { |
55 | return Objects.hash(address, getAfi()); | 57 | return Objects.hash(address, getAfi()); |
56 | } | 58 | } |
59 | + | ||
60 | + /** | ||
61 | + * IPv6 address reader class. | ||
62 | + */ | ||
63 | + public static class Ipv6AddressReader implements LispAddressReader<LispIpv6Address> { | ||
64 | + | ||
65 | + private static final int SIZE_OF_IPV6_ADDRESS = 16; | ||
66 | + | ||
67 | + @Override | ||
68 | + public LispIpv6Address readFrom(ByteBuf byteBuf) throws LispParseError { | ||
69 | + | ||
70 | + byte[] ipByte = new byte[SIZE_OF_IPV6_ADDRESS]; | ||
71 | + byteBuf.readBytes(ipByte); | ||
72 | + IpAddress ipAddress = IpAddress.valueOf(IpAddress.Version.INET6, ipByte); | ||
73 | + | ||
74 | + return new LispIpv6Address(ipAddress); | ||
75 | + } | ||
76 | + } | ||
57 | } | 77 | } | ... | ... |
... | @@ -16,6 +16,9 @@ | ... | @@ -16,6 +16,9 @@ |
16 | package org.onosproject.lisp.msg.types; | 16 | package org.onosproject.lisp.msg.types; |
17 | 17 | ||
18 | import com.google.common.collect.ImmutableList; | 18 | import com.google.common.collect.ImmutableList; |
19 | +import io.netty.buffer.ByteBuf; | ||
20 | +import org.onosproject.lisp.msg.exceptions.LispParseError; | ||
21 | +import org.onosproject.lisp.msg.exceptions.LispReaderException; | ||
19 | 22 | ||
20 | import java.util.List; | 23 | import java.util.List; |
21 | import java.util.Objects; | 24 | import java.util.Objects; |
... | @@ -51,7 +54,7 @@ import static com.google.common.base.MoreObjects.toStringHelper; | ... | @@ -51,7 +54,7 @@ import static com.google.common.base.MoreObjects.toStringHelper; |
51 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 54 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
52 | * }</pre> | 55 | * }</pre> |
53 | */ | 56 | */ |
54 | -public class LispListLcafAddress extends LispLcafAddress { | 57 | +public final class LispListLcafAddress extends LispLcafAddress { |
55 | 58 | ||
56 | private static final byte LENGTH = 24; | 59 | private static final byte LENGTH = 24; |
57 | List<LispAfiAddress> addresses; | 60 | List<LispAfiAddress> addresses; |
... | @@ -99,4 +102,20 @@ public class LispListLcafAddress extends LispLcafAddress { | ... | @@ -99,4 +102,20 @@ public class LispListLcafAddress extends LispLcafAddress { |
99 | .add("addresses", addresses) | 102 | .add("addresses", addresses) |
100 | .toString(); | 103 | .toString(); |
101 | } | 104 | } |
105 | + | ||
106 | + /** | ||
107 | + * List LCAF address reader class. | ||
108 | + */ | ||
109 | + public static class ListLcafAddressReader implements LispAddressReader<LispListLcafAddress> { | ||
110 | + | ||
111 | + @Override | ||
112 | + public LispListLcafAddress readFrom(ByteBuf byteBuf) throws LispParseError, LispReaderException { | ||
113 | + | ||
114 | + | ||
115 | + LispAfiAddress ipv4 = new LispIpAddress.IpAddressReader().readFrom(byteBuf); | ||
116 | + LispAfiAddress ipv6 = new LispIpAddress.IpAddressReader().readFrom(byteBuf); | ||
117 | + | ||
118 | + return new LispListLcafAddress(ImmutableList.of(ipv4, ipv6)); | ||
119 | + } | ||
120 | + } | ||
102 | } | 121 | } | ... | ... |
... | @@ -15,7 +15,9 @@ | ... | @@ -15,7 +15,9 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.lisp.msg.types; | 16 | package org.onosproject.lisp.msg.types; |
17 | 17 | ||
18 | +import io.netty.buffer.ByteBuf; | ||
18 | import org.onlab.packet.MacAddress; | 19 | import org.onlab.packet.MacAddress; |
20 | +import org.onosproject.lisp.msg.exceptions.LispParseError; | ||
19 | 21 | ||
20 | import java.util.Objects; | 22 | import java.util.Objects; |
21 | 23 | ||
... | @@ -68,4 +70,22 @@ public class LispMacAddress extends LispAfiAddress { | ... | @@ -68,4 +70,22 @@ public class LispMacAddress extends LispAfiAddress { |
68 | public String toString() { | 70 | public String toString() { |
69 | return address.toString(); | 71 | return address.toString(); |
70 | } | 72 | } |
73 | + | ||
74 | + /** | ||
75 | + * MAC address reader class. | ||
76 | + */ | ||
77 | + public static class MacAddressReader implements LispAddressReader<LispMacAddress> { | ||
78 | + | ||
79 | + private static final int SIZE_OF_MAC_ADDRESS = 6; | ||
80 | + | ||
81 | + @Override | ||
82 | + public LispMacAddress readFrom(ByteBuf byteBuf) throws LispParseError { | ||
83 | + | ||
84 | + byte[] macByte = new byte[SIZE_OF_MAC_ADDRESS]; | ||
85 | + byteBuf.readBytes(macByte); | ||
86 | + MacAddress macAddress = MacAddress.valueOf(macByte); | ||
87 | + | ||
88 | + return new LispMacAddress(macAddress); | ||
89 | + } | ||
90 | + } | ||
71 | } | 91 | } | ... | ... |
... | @@ -15,6 +15,9 @@ | ... | @@ -15,6 +15,9 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.lisp.msg.types; | 16 | package org.onosproject.lisp.msg.types; |
17 | 17 | ||
18 | +import io.netty.buffer.ByteBuf; | ||
19 | +import org.onosproject.lisp.msg.exceptions.LispParseError; | ||
20 | + | ||
18 | /** | 21 | /** |
19 | * No address. | 22 | * No address. |
20 | */ | 23 | */ |
... | @@ -26,4 +29,15 @@ public class LispNoAddress extends LispAfiAddress { | ... | @@ -26,4 +29,15 @@ public class LispNoAddress extends LispAfiAddress { |
26 | public LispNoAddress() { | 29 | public LispNoAddress() { |
27 | super(AddressFamilyIdentifierEnum.NO_ADDRESS); | 30 | super(AddressFamilyIdentifierEnum.NO_ADDRESS); |
28 | } | 31 | } |
32 | + | ||
33 | + /** | ||
34 | + * LISP no address reader class. | ||
35 | + */ | ||
36 | + public static class NoAddressReader implements LispAddressReader<LispNoAddress> { | ||
37 | + | ||
38 | + @Override | ||
39 | + public LispNoAddress readFrom(ByteBuf byteBuf) throws LispParseError { | ||
40 | + return new LispNoAddress(); | ||
41 | + } | ||
42 | + } | ||
29 | } | 43 | } | ... | ... |
... | @@ -15,6 +15,10 @@ | ... | @@ -15,6 +15,10 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.lisp.msg.types; | 16 | package org.onosproject.lisp.msg.types; |
17 | 17 | ||
18 | +import io.netty.buffer.ByteBuf; | ||
19 | +import org.onosproject.lisp.msg.exceptions.LispParseError; | ||
20 | +import org.onosproject.lisp.msg.exceptions.LispReaderException; | ||
21 | + | ||
18 | import java.util.Objects; | 22 | import java.util.Objects; |
19 | 23 | ||
20 | import static com.google.common.base.MoreObjects.toStringHelper; | 24 | import static com.google.common.base.MoreObjects.toStringHelper; |
... | @@ -40,7 +44,7 @@ import static com.google.common.base.MoreObjects.toStringHelper; | ... | @@ -40,7 +44,7 @@ import static com.google.common.base.MoreObjects.toStringHelper; |
40 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 44 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
41 | * }</pre> | 45 | * }</pre> |
42 | */ | 46 | */ |
43 | -public class LispSegmentLcafAddress extends LispLcafAddress { | 47 | +public final class LispSegmentLcafAddress extends LispLcafAddress { |
44 | 48 | ||
45 | private final LispAfiAddress address; | 49 | private final LispAfiAddress address; |
46 | private final int instanceId; | 50 | private final int instanceId; |
... | @@ -52,7 +56,7 @@ public class LispSegmentLcafAddress extends LispLcafAddress { | ... | @@ -52,7 +56,7 @@ public class LispSegmentLcafAddress extends LispLcafAddress { |
52 | * @param instanceId instance id | 56 | * @param instanceId instance id |
53 | * @param address address | 57 | * @param address address |
54 | */ | 58 | */ |
55 | - public LispSegmentLcafAddress(byte idMaskLength, int instanceId, LispAfiAddress address) { | 59 | + private LispSegmentLcafAddress(byte idMaskLength, int instanceId, LispAfiAddress address) { |
56 | super(LispCanonicalAddressFormatEnum.SEGMENT, idMaskLength); | 60 | super(LispCanonicalAddressFormatEnum.SEGMENT, idMaskLength); |
57 | this.address = address; | 61 | this.address = address; |
58 | this.instanceId = instanceId; | 62 | this.instanceId = instanceId; |
... | @@ -113,4 +117,75 @@ public class LispSegmentLcafAddress extends LispLcafAddress { | ... | @@ -113,4 +117,75 @@ public class LispSegmentLcafAddress extends LispLcafAddress { |
113 | .add("idMaskLength", reserved2) | 117 | .add("idMaskLength", reserved2) |
114 | .toString(); | 118 | .toString(); |
115 | } | 119 | } |
120 | + | ||
121 | + public static final class SegmentAddressBuilder { | ||
122 | + private byte idMaskLength; | ||
123 | + private LispAfiAddress address; | ||
124 | + private int instanceId; | ||
125 | + | ||
126 | + /** | ||
127 | + * Sets identifier mask length. | ||
128 | + * | ||
129 | + * @param idMaskLength identifier mask length | ||
130 | + * @return SegmentAddressBuilder object | ||
131 | + */ | ||
132 | + public SegmentAddressBuilder withIdMaskLength(byte idMaskLength) { | ||
133 | + this.idMaskLength = idMaskLength; | ||
134 | + return this; | ||
135 | + } | ||
136 | + | ||
137 | + /** | ||
138 | + * Sets instance identifer. | ||
139 | + * | ||
140 | + * @param instanceId instance identifier | ||
141 | + * @return SegmentAddressBuilder object | ||
142 | + */ | ||
143 | + public SegmentAddressBuilder withInstanceId(int instanceId) { | ||
144 | + this.instanceId = instanceId; | ||
145 | + return this; | ||
146 | + } | ||
147 | + | ||
148 | + /** | ||
149 | + * Sets AFI address. | ||
150 | + * | ||
151 | + * @param address AFI address | ||
152 | + * @return SegmentAddressBuilder object | ||
153 | + */ | ||
154 | + public SegmentAddressBuilder withAddress(LispAfiAddress address) { | ||
155 | + this.address = address; | ||
156 | + return this; | ||
157 | + } | ||
158 | + | ||
159 | + /** | ||
160 | + * Builds LispSegmentLcafAddress instance. | ||
161 | + * | ||
162 | + * @return LispSegmentLcafAddress instance | ||
163 | + */ | ||
164 | + public LispSegmentLcafAddress build() { | ||
165 | + return new LispSegmentLcafAddress(idMaskLength, instanceId, address); | ||
166 | + } | ||
167 | + } | ||
168 | + | ||
169 | + /** | ||
170 | + * Segment LCAF address reader class. | ||
171 | + */ | ||
172 | + public static class SegmentLcafAddressReader | ||
173 | + implements LispAddressReader<LispSegmentLcafAddress> { | ||
174 | + | ||
175 | + @Override | ||
176 | + public LispSegmentLcafAddress readFrom(ByteBuf byteBuf) | ||
177 | + throws LispParseError, LispReaderException { | ||
178 | + | ||
179 | + // TODO: need to de-serialize IdMaskLength | ||
180 | + byte idMaskLength = 0x01; | ||
181 | + int instanceId = (int) byteBuf.readUnsignedInt(); | ||
182 | + LispAfiAddress address = new LispIpAddress.IpAddressReader().readFrom(byteBuf); | ||
183 | + | ||
184 | + return new SegmentAddressBuilder() | ||
185 | + .withIdMaskLength(idMaskLength) | ||
186 | + .withInstanceId(instanceId) | ||
187 | + .withAddress(address) | ||
188 | + .build(); | ||
189 | + } | ||
190 | + } | ||
116 | } | 191 | } | ... | ... |
... | @@ -15,6 +15,10 @@ | ... | @@ -15,6 +15,10 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.lisp.msg.types; | 16 | package org.onosproject.lisp.msg.types; |
17 | 17 | ||
18 | +import io.netty.buffer.ByteBuf; | ||
19 | +import org.onosproject.lisp.msg.exceptions.LispParseError; | ||
20 | +import org.onosproject.lisp.msg.exceptions.LispReaderException; | ||
21 | + | ||
18 | import java.util.Objects; | 22 | import java.util.Objects; |
19 | 23 | ||
20 | import static com.google.common.base.MoreObjects.toStringHelper; | 24 | import static com.google.common.base.MoreObjects.toStringHelper; |
... | @@ -42,26 +46,16 @@ import static com.google.common.base.MoreObjects.toStringHelper; | ... | @@ -42,26 +46,16 @@ import static com.google.common.base.MoreObjects.toStringHelper; |
42 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 46 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
43 | * }</pre> | 47 | * }</pre> |
44 | */ | 48 | */ |
45 | -public class LispSourceDestLcafAddress extends LispLcafAddress { | 49 | +public final class LispSourceDestLcafAddress extends LispLcafAddress { |
46 | 50 | ||
47 | - private LispAfiAddress srcPrefix; | 51 | + private final LispAfiAddress srcPrefix; |
48 | - private LispAfiAddress dstPrefix; | 52 | + private final LispAfiAddress dstPrefix; |
49 | private final byte srcMaskLength; | 53 | private final byte srcMaskLength; |
50 | private final byte dstMaskLength; | 54 | private final byte dstMaskLength; |
51 | private final short reserved; | 55 | private final short reserved; |
52 | 56 | ||
53 | /** | 57 | /** |
54 | * Initializes source/dest key type LCAF address. | 58 | * 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 | * | 59 | * |
66 | * @param reserved reserved | 60 | * @param reserved reserved |
67 | * @param srcMaskLength source mask length | 61 | * @param srcMaskLength source mask length |
... | @@ -69,7 +63,7 @@ public class LispSourceDestLcafAddress extends LispLcafAddress { | ... | @@ -69,7 +63,7 @@ public class LispSourceDestLcafAddress extends LispLcafAddress { |
69 | * @param srcPrefix source address prefix | 63 | * @param srcPrefix source address prefix |
70 | * @param dstPrefix destination address prefix | 64 | * @param dstPrefix destination address prefix |
71 | */ | 65 | */ |
72 | - public LispSourceDestLcafAddress(short reserved, byte srcMaskLength, | 66 | + private LispSourceDestLcafAddress(short reserved, byte srcMaskLength, |
73 | byte dstMaskLength, | 67 | byte dstMaskLength, |
74 | LispAfiAddress srcPrefix, | 68 | LispAfiAddress srcPrefix, |
75 | LispAfiAddress dstPrefix) { | 69 | LispAfiAddress dstPrefix) { |
... | @@ -158,4 +152,103 @@ public class LispSourceDestLcafAddress extends LispLcafAddress { | ... | @@ -158,4 +152,103 @@ public class LispSourceDestLcafAddress extends LispLcafAddress { |
158 | .add("reserved", reserved) | 152 | .add("reserved", reserved) |
159 | .toString(); | 153 | .toString(); |
160 | } | 154 | } |
155 | + | ||
156 | + public static final class SourceDestAddressBuilder { | ||
157 | + private LispAfiAddress srcPrefix; | ||
158 | + private LispAfiAddress dstPrefix; | ||
159 | + private byte srcMaskLength; | ||
160 | + private byte dstMaskLength; | ||
161 | + private short reserved; | ||
162 | + | ||
163 | + /** | ||
164 | + * Sets source address prefix. | ||
165 | + * | ||
166 | + * @param srcPrefix source prefix | ||
167 | + * @return SourceDestAddressBuilder object | ||
168 | + */ | ||
169 | + public SourceDestAddressBuilder withSrcPrefix(LispAfiAddress srcPrefix) { | ||
170 | + this.srcPrefix = srcPrefix; | ||
171 | + return this; | ||
172 | + } | ||
173 | + | ||
174 | + /** | ||
175 | + * Sets destination address prefix. | ||
176 | + * | ||
177 | + * @param dstPrefix | ||
178 | + * @return SourceDestAddressBuilder object | ||
179 | + */ | ||
180 | + public SourceDestAddressBuilder withDstPrefix(LispAfiAddress dstPrefix) { | ||
181 | + this.dstPrefix = dstPrefix; | ||
182 | + return this; | ||
183 | + } | ||
184 | + | ||
185 | + /** | ||
186 | + * Sets source mask length. | ||
187 | + * | ||
188 | + * @param srcMaskLength source mask length | ||
189 | + * @return SourceDestAddressBuilder object | ||
190 | + */ | ||
191 | + public SourceDestAddressBuilder withSrcMaskLength(byte srcMaskLength) { | ||
192 | + this.srcMaskLength = srcMaskLength; | ||
193 | + return this; | ||
194 | + } | ||
195 | + | ||
196 | + /** | ||
197 | + * Sets destination mask length. | ||
198 | + * | ||
199 | + * @param dstMaskLength destination mask length | ||
200 | + * @return SourceDestAddressBuilder object | ||
201 | + */ | ||
202 | + public SourceDestAddressBuilder withDstMaskLength(byte dstMaskLength) { | ||
203 | + this.dstMaskLength = dstMaskLength; | ||
204 | + return this; | ||
205 | + } | ||
206 | + | ||
207 | + /** | ||
208 | + * Sets reserved value. | ||
209 | + * | ||
210 | + * @param reserved reserved field value | ||
211 | + * @return SourceDestAddressBuilder object | ||
212 | + */ | ||
213 | + public SourceDestAddressBuilder withReserved(short reserved) { | ||
214 | + this.reserved = reserved; | ||
215 | + return this; | ||
216 | + } | ||
217 | + | ||
218 | + /** | ||
219 | + * Builds LispSourceDestLcafAddress instance. | ||
220 | + * | ||
221 | + * @return LispSourceDestLcafAddress instance | ||
222 | + */ | ||
223 | + public LispSourceDestLcafAddress build() { | ||
224 | + return new LispSourceDestLcafAddress(reserved, srcMaskLength, | ||
225 | + dstMaskLength, srcPrefix, dstPrefix); | ||
226 | + } | ||
227 | + } | ||
228 | + | ||
229 | + /** | ||
230 | + * SourceDest LCAF address reader class. | ||
231 | + */ | ||
232 | + public static class SourceDestLcafAddressReader | ||
233 | + implements LispAddressReader<LispSourceDestLcafAddress> { | ||
234 | + | ||
235 | + @Override | ||
236 | + public LispSourceDestLcafAddress readFrom(ByteBuf byteBuf) throws LispParseError, LispReaderException { | ||
237 | + | ||
238 | + short reserved = byteBuf.readShort(); | ||
239 | + byte srcMaskLength = (byte) byteBuf.readUnsignedByte(); | ||
240 | + byte dstMaskLength = (byte) byteBuf.readUnsignedByte(); | ||
241 | + | ||
242 | + LispAfiAddress srcPrefix = new LispIpAddress.IpAddressReader().readFrom(byteBuf); | ||
243 | + LispAfiAddress dstPrefix = new LispIpAddress.IpAddressReader().readFrom(byteBuf); | ||
244 | + | ||
245 | + return new SourceDestAddressBuilder() | ||
246 | + .withReserved(reserved) | ||
247 | + .withSrcMaskLength(srcMaskLength) | ||
248 | + .withDstMaskLength(dstMaskLength) | ||
249 | + .withSrcPrefix(srcPrefix) | ||
250 | + .withDstPrefix(dstPrefix) | ||
251 | + .build(); | ||
252 | + } | ||
253 | + } | ||
161 | } | 254 | } | ... | ... |
... | @@ -35,13 +35,48 @@ public class LispAppDataLcafAddressTest { | ... | @@ -35,13 +35,48 @@ public class LispAppDataLcafAddressTest { |
35 | @Before | 35 | @Before |
36 | public void setup() { | 36 | public void setup() { |
37 | 37 | ||
38 | + LispAppDataLcafAddress.AppDataAddressBuilder builder1 = | ||
39 | + new LispAppDataLcafAddress.AppDataAddressBuilder(); | ||
40 | + | ||
38 | LispAfiAddress ipv4Address1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.1")); | 41 | LispAfiAddress ipv4Address1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.1")); |
39 | - address1 = new LispAppDataLcafAddress((byte) 0x01, 1, (short) 10, (short) 20, ipv4Address1); | ||
40 | 42 | ||
41 | - sameAsAddress1 = new LispAppDataLcafAddress((byte) 0x01, 1, (short) 10, (short) 20, ipv4Address1); | 43 | + address1 = builder1 |
44 | + .withProtocol((byte) 0x01) | ||
45 | + .withIpTos((short) 10) | ||
46 | + .withLocalPortLow((short) 1) | ||
47 | + .withLocalPortHigh((short) 255) | ||
48 | + .withRemotePortLow((short) 2) | ||
49 | + .withRemotePortHigh((short) 254) | ||
50 | + .withAddress(ipv4Address1) | ||
51 | + .build(); | ||
52 | + | ||
53 | + LispAppDataLcafAddress.AppDataAddressBuilder builder2 = | ||
54 | + new LispAppDataLcafAddress.AppDataAddressBuilder(); | ||
55 | + | ||
56 | + sameAsAddress1 = builder2 | ||
57 | + .withProtocol((byte) 0x01) | ||
58 | + .withIpTos((short) 10) | ||
59 | + .withLocalPortLow((short) 1) | ||
60 | + .withLocalPortHigh((short) 255) | ||
61 | + .withRemotePortLow((short) 2) | ||
62 | + .withRemotePortHigh((short) 254) | ||
63 | + .withAddress(ipv4Address1) | ||
64 | + .build(); | ||
65 | + | ||
66 | + LispAppDataLcafAddress.AppDataAddressBuilder builder3 = | ||
67 | + new LispAppDataLcafAddress.AppDataAddressBuilder(); | ||
42 | 68 | ||
43 | LispAfiAddress ipv4Address2 = new LispIpv4Address(IpAddress.valueOf("192.168.2.1")); | 69 | LispAfiAddress ipv4Address2 = new LispIpv4Address(IpAddress.valueOf("192.168.2.1")); |
44 | - address2 = new LispAppDataLcafAddress((byte) 0x02, 2, (short) 20, (short) 40, ipv4Address2); | 70 | + |
71 | + address2 = builder3 | ||
72 | + .withProtocol((byte) 0x02) | ||
73 | + .withIpTos((short) 20) | ||
74 | + .withLocalPortLow((short) 1) | ||
75 | + .withLocalPortHigh((short) 255) | ||
76 | + .withRemotePortLow((short) 2) | ||
77 | + .withRemotePortHigh((short) 254) | ||
78 | + .withAddress(ipv4Address2) | ||
79 | + .build(); | ||
45 | } | 80 | } |
46 | 81 | ||
47 | @Test | 82 | @Test |
... | @@ -58,9 +93,11 @@ public class LispAppDataLcafAddressTest { | ... | @@ -58,9 +93,11 @@ public class LispAppDataLcafAddressTest { |
58 | LispAfiAddress ipv4Address = new LispIpv4Address(IpAddress.valueOf("192.168.1.1")); | 93 | LispAfiAddress ipv4Address = new LispIpv4Address(IpAddress.valueOf("192.168.1.1")); |
59 | 94 | ||
60 | assertThat(appDataLcafAddress.getProtocol(), is((byte) 0x01)); | 95 | assertThat(appDataLcafAddress.getProtocol(), is((byte) 0x01)); |
61 | - assertThat(appDataLcafAddress.getIpTos(), is(1)); | 96 | + assertThat(appDataLcafAddress.getIpTos(), is(10)); |
62 | - assertThat(appDataLcafAddress.getLocalPort(), is((short) 10)); | 97 | + assertThat(appDataLcafAddress.getLocalPortLow(), is((short) 1)); |
63 | - assertThat(appDataLcafAddress.getRemotePort(), is((short) 20)); | 98 | + assertThat(appDataLcafAddress.getLocalPortHigh(), is((short) 255)); |
99 | + assertThat(appDataLcafAddress.getRemotePortLow(), is((short) 2)); | ||
100 | + assertThat(appDataLcafAddress.getRemotePortHigh(), is((short) 254)); | ||
64 | assertThat(appDataLcafAddress.getAddress(), is(ipv4Address)); | 101 | assertThat(appDataLcafAddress.getAddress(), is(ipv4Address)); |
65 | } | 102 | } |
66 | } | 103 | } | ... | ... |
... | @@ -35,13 +35,35 @@ public class LispSegmentLcafAddressTest { | ... | @@ -35,13 +35,35 @@ public class LispSegmentLcafAddressTest { |
35 | @Before | 35 | @Before |
36 | public void setup() { | 36 | public void setup() { |
37 | 37 | ||
38 | + LispSegmentLcafAddress.SegmentAddressBuilder builder1 = | ||
39 | + new LispSegmentLcafAddress.SegmentAddressBuilder(); | ||
40 | + | ||
38 | LispIpv4Address ipv4Address1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.1")); | 41 | LispIpv4Address ipv4Address1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.1")); |
39 | - address1 = new LispSegmentLcafAddress((byte) 0x01, 1, ipv4Address1); | ||
40 | 42 | ||
41 | - sameAsAddress1 = new LispSegmentLcafAddress((byte) 0x01, 1, ipv4Address1); | 43 | + address1 = builder1 |
44 | + .withIdMaskLength((byte) 0x01) | ||
45 | + .withInstanceId(1) | ||
46 | + .withAddress(ipv4Address1) | ||
47 | + .build(); | ||
48 | + | ||
49 | + LispSegmentLcafAddress.SegmentAddressBuilder builder2 = | ||
50 | + new LispSegmentLcafAddress.SegmentAddressBuilder(); | ||
51 | + | ||
52 | + sameAsAddress1 = builder2 | ||
53 | + .withIdMaskLength((byte) 0x01) | ||
54 | + .withInstanceId(1) | ||
55 | + .withAddress(ipv4Address1) | ||
56 | + .build(); | ||
57 | + | ||
58 | + LispSegmentLcafAddress.SegmentAddressBuilder builder3 = | ||
59 | + new LispSegmentLcafAddress.SegmentAddressBuilder(); | ||
42 | 60 | ||
43 | LispIpv4Address ipv4Address2 = new LispIpv4Address(IpAddress.valueOf("192.168.2.1")); | 61 | LispIpv4Address ipv4Address2 = new LispIpv4Address(IpAddress.valueOf("192.168.2.1")); |
44 | - address2 = new LispSegmentLcafAddress((byte) 0x02, 2, ipv4Address2); | 62 | + address2 = builder3 |
63 | + .withIdMaskLength((byte) 0x02) | ||
64 | + .withInstanceId(2) | ||
65 | + .withAddress(ipv4Address2) | ||
66 | + .build(); | ||
45 | } | 67 | } |
46 | 68 | ||
47 | @Test | 69 | @Test | ... | ... |
... | @@ -35,20 +35,44 @@ public class LispSourceDestLcafAddressTest { | ... | @@ -35,20 +35,44 @@ public class LispSourceDestLcafAddressTest { |
35 | @Before | 35 | @Before |
36 | public void setup() { | 36 | public void setup() { |
37 | 37 | ||
38 | + LispSourceDestLcafAddress.SourceDestAddressBuilder builder1 = | ||
39 | + new LispSourceDestLcafAddress.SourceDestAddressBuilder(); | ||
40 | + | ||
38 | LispIpv4Address srcAddress1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.1")); | 41 | LispIpv4Address srcAddress1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.1")); |
39 | LispIpv4Address dstAddress1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.2")); | 42 | LispIpv4Address dstAddress1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.2")); |
40 | 43 | ||
41 | - address1 = new LispSourceDestLcafAddress((short) 1, (byte) 0x01, | 44 | + address1 = builder1 |
42 | - (byte) 0x01, srcAddress1, dstAddress1); | 45 | + .withReserved((short) 1) |
46 | + .withSrcMaskLength((byte) 0x01) | ||
47 | + .withDstMaskLength((byte) 0x01) | ||
48 | + .withSrcPrefix(srcAddress1) | ||
49 | + .withDstPrefix(dstAddress1) | ||
50 | + .build(); | ||
51 | + | ||
52 | + LispSourceDestLcafAddress.SourceDestAddressBuilder builder2 = | ||
53 | + new LispSourceDestLcafAddress.SourceDestAddressBuilder(); | ||
54 | + | ||
55 | + sameAsAddress1 = builder2 | ||
56 | + .withReserved((short) 1) | ||
57 | + .withSrcMaskLength((byte) 0x01) | ||
58 | + .withDstMaskLength((byte) 0x01) | ||
59 | + .withSrcPrefix(srcAddress1) | ||
60 | + .withDstPrefix(dstAddress1) | ||
61 | + .build(); | ||
43 | 62 | ||
44 | - sameAsAddress1 = new LispSourceDestLcafAddress((short) 1, (byte) 0x01, | 63 | + LispSourceDestLcafAddress.SourceDestAddressBuilder builder3 = |
45 | - (byte) 0x01, srcAddress1, dstAddress1); | 64 | + new LispSourceDestLcafAddress.SourceDestAddressBuilder(); |
46 | 65 | ||
47 | LispIpv4Address srcAddress2 = new LispIpv4Address(IpAddress.valueOf("192.168.2.1")); | 66 | LispIpv4Address srcAddress2 = new LispIpv4Address(IpAddress.valueOf("192.168.2.1")); |
48 | LispIpv4Address dstAddress2 = new LispIpv4Address(IpAddress.valueOf("192.168.2.2")); | 67 | LispIpv4Address dstAddress2 = new LispIpv4Address(IpAddress.valueOf("192.168.2.2")); |
49 | 68 | ||
50 | - address2 = new LispSourceDestLcafAddress((short) 2, (byte) 0x02, | 69 | + address2 = builder3 |
51 | - (byte) 0x02, srcAddress2, dstAddress2); | 70 | + .withReserved((short) 2) |
71 | + .withSrcMaskLength((byte) 0x02) | ||
72 | + .withDstMaskLength((byte) 0x02) | ||
73 | + .withSrcPrefix(srcAddress2) | ||
74 | + .withDstPrefix(dstAddress2) | ||
75 | + .build(); | ||
52 | } | 76 | } |
53 | 77 | ||
54 | @Test | 78 | @Test | ... | ... |
-
Please register or login to post a comment