Committed by
Thomas Vachuska
[ONOS-4718] Initial implementation of LISP address serializer
Change-Id: I71e1923f6daf1abdf2bf9798a9e421c81926a45c
Showing
16 changed files
with
360 additions
and
2 deletions
protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/exceptions/LispWriterException.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 writer exception. | ||
20 | + */ | ||
21 | +public class LispWriterException extends Exception { | ||
22 | + | ||
23 | + /** | ||
24 | + * Constructor for LispWriterException. | ||
25 | + */ | ||
26 | + public LispWriterException() { | ||
27 | + super(); | ||
28 | + } | ||
29 | + | ||
30 | + /** | ||
31 | + * Constructor for LispWriterException with message and cause parameters. | ||
32 | + * | ||
33 | + * @param message exception message | ||
34 | + * @param cause throwable cause | ||
35 | + */ | ||
36 | + public LispWriterException(final String message, final Throwable cause) { | ||
37 | + super(message, cause); | ||
38 | + } | ||
39 | + | ||
40 | + /** | ||
41 | + * Constructor for LispWriterException with message parameter. | ||
42 | + * | ||
43 | + * @param message exception message | ||
44 | + */ | ||
45 | + public LispWriterException(final String message) { | ||
46 | + super(message); | ||
47 | + } | ||
48 | + | ||
49 | + /** | ||
50 | + * Constructor for LispWriterException with cause parameter. | ||
51 | + * | ||
52 | + * @param cause throwable cause | ||
53 | + */ | ||
54 | + public LispWriterException(final Throwable cause) { | ||
55 | + super(cause); | ||
56 | + } | ||
57 | +} |
... | @@ -30,6 +30,7 @@ public interface LispAddressReader<T> { | ... | @@ -30,6 +30,7 @@ public interface LispAddressReader<T> { |
30 | * @param byteBuf byte buffer | 30 | * @param byteBuf byte buffer |
31 | * @return LISP address type instance | 31 | * @return LISP address type instance |
32 | * @throws LispParseError LISP address parse error | 32 | * @throws LispParseError LISP address parse error |
33 | + * @throws LispReaderException LISP reader exception | ||
33 | */ | 34 | */ |
34 | T readFrom(ByteBuf byteBuf) throws LispParseError, LispReaderException; | 35 | T readFrom(ByteBuf byteBuf) throws LispParseError, LispReaderException; |
35 | } | 36 | } | ... | ... |
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.LispWriterException; | ||
20 | + | ||
21 | +/** | ||
22 | + * An interface for serializing LISP address. | ||
23 | + */ | ||
24 | +public interface LispAddressWriter<T> { | ||
25 | + | ||
26 | + /** | ||
27 | + * Writes from LISP address object and serialize to byte buffer. | ||
28 | + * | ||
29 | + * @param byteBuf byte buffer | ||
30 | + * @param address LISP address type instance | ||
31 | + * @throws LispWriterException Lisp writer exception | ||
32 | + */ | ||
33 | + void writeTo(ByteBuf byteBuf, T address) throws LispWriterException; | ||
34 | + | ||
35 | +} |
... | @@ -18,6 +18,7 @@ package org.onosproject.lisp.msg.types; | ... | @@ -18,6 +18,7 @@ package org.onosproject.lisp.msg.types; |
18 | import io.netty.buffer.ByteBuf; | 18 | import io.netty.buffer.ByteBuf; |
19 | import org.onosproject.lisp.msg.exceptions.LispParseError; | 19 | import org.onosproject.lisp.msg.exceptions.LispParseError; |
20 | import org.onosproject.lisp.msg.exceptions.LispReaderException; | 20 | import org.onosproject.lisp.msg.exceptions.LispReaderException; |
21 | +import org.onosproject.lisp.msg.exceptions.LispWriterException; | ||
21 | 22 | ||
22 | import java.util.Objects; | 23 | import java.util.Objects; |
23 | 24 | ||
... | @@ -74,6 +75,9 @@ public abstract class LispAfiAddress { | ... | @@ -74,6 +75,9 @@ public abstract class LispAfiAddress { |
74 | return true; | 75 | return true; |
75 | } | 76 | } |
76 | 77 | ||
78 | + /** | ||
79 | + * AFI address reader class. | ||
80 | + */ | ||
77 | public static class AfiAddressReader implements LispAddressReader<LispAfiAddress> { | 81 | public static class AfiAddressReader implements LispAddressReader<LispAfiAddress> { |
78 | 82 | ||
79 | @Override | 83 | @Override |
... | @@ -114,4 +118,36 @@ public abstract class LispAfiAddress { | ... | @@ -114,4 +118,36 @@ public abstract class LispAfiAddress { |
114 | return null; | 118 | return null; |
115 | } | 119 | } |
116 | } | 120 | } |
121 | + | ||
122 | + /** | ||
123 | + * AFI address writer class. | ||
124 | + */ | ||
125 | + public static class AfiAddressWriter implements LispAddressWriter<LispAfiAddress> { | ||
126 | + | ||
127 | + @Override | ||
128 | + public void writeTo(ByteBuf byteBuf, LispAfiAddress address) throws LispWriterException { | ||
129 | + switch (address.getAfi()) { | ||
130 | + case IP: | ||
131 | + new LispIpAddress.IpAddressWriter().writeTo(byteBuf, (LispIpv4Address) address); | ||
132 | + break; | ||
133 | + case IP6: | ||
134 | + new LispIpAddress.IpAddressWriter().writeTo(byteBuf, (LispIpv6Address) address); | ||
135 | + break; | ||
136 | + case DISTINGUISHED_NAME: | ||
137 | + new LispDistinguishedNameAddress.DistinguishedNameAddressWriter().writeTo(byteBuf, | ||
138 | + (LispDistinguishedNameAddress) address); | ||
139 | + break; | ||
140 | + case MAC: | ||
141 | + new LispMacAddress.MacAddressWriter().writeTo(byteBuf, (LispMacAddress) address); | ||
142 | + break; | ||
143 | + case LCAF: | ||
144 | + new LispLcafAddress.LcafAddressWriter().writeTo(byteBuf, (LispLcafAddress) address); | ||
145 | + break; | ||
146 | + case AS: | ||
147 | + new LispAsAddress.AsAddressWriter().writeTo(byteBuf, (LispAsAddress) address); | ||
148 | + break; | ||
149 | + default: break; // TODO: need log warning message | ||
150 | + } | ||
151 | + } | ||
152 | + } | ||
117 | } | 153 | } | ... | ... |
... | @@ -18,6 +18,7 @@ package org.onosproject.lisp.msg.types; | ... | @@ -18,6 +18,7 @@ package org.onosproject.lisp.msg.types; |
18 | import io.netty.buffer.ByteBuf; | 18 | import io.netty.buffer.ByteBuf; |
19 | import org.onosproject.lisp.msg.exceptions.LispParseError; | 19 | import org.onosproject.lisp.msg.exceptions.LispParseError; |
20 | import org.onosproject.lisp.msg.exceptions.LispReaderException; | 20 | import org.onosproject.lisp.msg.exceptions.LispReaderException; |
21 | +import org.onosproject.lisp.msg.exceptions.LispWriterException; | ||
21 | 22 | ||
22 | import java.nio.ByteBuffer; | 23 | import java.nio.ByteBuffer; |
23 | import java.util.Objects; | 24 | import java.util.Objects; |
... | @@ -364,4 +365,29 @@ public final class LispAppDataLcafAddress extends LispLcafAddress { | ... | @@ -364,4 +365,29 @@ public final class LispAppDataLcafAddress extends LispLcafAddress { |
364 | return buffer.getInt(); | 365 | return buffer.getInt(); |
365 | } | 366 | } |
366 | } | 367 | } |
368 | + | ||
369 | + /** | ||
370 | + * Application data LCAF address writer class. | ||
371 | + */ | ||
372 | + public static class AppDataLcafAddressWriter | ||
373 | + implements LispAddressWriter<LispAppDataLcafAddress> { | ||
374 | + | ||
375 | + @Override | ||
376 | + public void writeTo(ByteBuf byteBuf, LispAppDataLcafAddress address) | ||
377 | + throws LispWriterException { | ||
378 | + | ||
379 | + LispLcafAddress.serializeCommon(byteBuf, address); | ||
380 | + | ||
381 | + // TODO: need to handle TOS | ||
382 | + | ||
383 | + byteBuf.writeByte(address.getProtocol()); | ||
384 | + byteBuf.writeShort(address.getLocalPortLow()); | ||
385 | + byteBuf.writeShort(address.getLocalPortHigh()); | ||
386 | + byteBuf.writeShort(address.getRemotePortLow()); | ||
387 | + byteBuf.writeShort(address.getRemotePortHigh()); | ||
388 | + | ||
389 | + AfiAddressWriter writer = new LispAfiAddress.AfiAddressWriter(); | ||
390 | + writer.writeTo(byteBuf, address.getAddress()); | ||
391 | + } | ||
392 | + } | ||
367 | } | 393 | } | ... | ... |
... | @@ -18,6 +18,7 @@ package org.onosproject.lisp.msg.types; | ... | @@ -18,6 +18,7 @@ package org.onosproject.lisp.msg.types; |
18 | import io.netty.buffer.ByteBuf; | 18 | import io.netty.buffer.ByteBuf; |
19 | import org.onosproject.lisp.msg.exceptions.LispParseError; | 19 | import org.onosproject.lisp.msg.exceptions.LispParseError; |
20 | import org.onosproject.lisp.msg.exceptions.LispReaderException; | 20 | import org.onosproject.lisp.msg.exceptions.LispReaderException; |
21 | +import org.onosproject.lisp.msg.exceptions.LispWriterException; | ||
21 | 22 | ||
22 | import java.util.Objects; | 23 | import java.util.Objects; |
23 | 24 | ||
... | @@ -88,4 +89,15 @@ public class LispAsAddress extends LispAfiAddress { | ... | @@ -88,4 +89,15 @@ public class LispAsAddress extends LispAfiAddress { |
88 | throw new LispReaderException("Unimplemented method"); | 89 | throw new LispReaderException("Unimplemented method"); |
89 | } | 90 | } |
90 | } | 91 | } |
92 | + | ||
93 | + /** | ||
94 | + * Autonomous system address writer class. | ||
95 | + */ | ||
96 | + public static class AsAddressWriter implements LispAddressWriter<LispAsAddress> { | ||
97 | + | ||
98 | + @Override | ||
99 | + public void writeTo(ByteBuf byteBuf, LispAsAddress address) throws LispWriterException { | ||
100 | + throw new LispWriterException("Unimplemented method"); | ||
101 | + } | ||
102 | + } | ||
91 | } | 103 | } | ... | ... |
... | @@ -17,6 +17,7 @@ package org.onosproject.lisp.msg.types; | ... | @@ -17,6 +17,7 @@ package org.onosproject.lisp.msg.types; |
17 | 17 | ||
18 | import io.netty.buffer.ByteBuf; | 18 | import io.netty.buffer.ByteBuf; |
19 | import org.onosproject.lisp.msg.exceptions.LispParseError; | 19 | import org.onosproject.lisp.msg.exceptions.LispParseError; |
20 | +import org.onosproject.lisp.msg.exceptions.LispWriterException; | ||
20 | 21 | ||
21 | import java.util.Objects; | 22 | import java.util.Objects; |
22 | 23 | ||
... | @@ -92,4 +93,20 @@ public class LispDistinguishedNameAddress extends LispAfiAddress { | ... | @@ -92,4 +93,20 @@ public class LispDistinguishedNameAddress extends LispAfiAddress { |
92 | return new LispDistinguishedNameAddress(sb.toString()); | 93 | return new LispDistinguishedNameAddress(sb.toString()); |
93 | } | 94 | } |
94 | } | 95 | } |
96 | + | ||
97 | + /** | ||
98 | + * Distinguished name address writer class. | ||
99 | + */ | ||
100 | + public static class DistinguishedNameAddressWriter | ||
101 | + implements LispAddressWriter<LispDistinguishedNameAddress> { | ||
102 | + | ||
103 | + @Override | ||
104 | + public void writeTo(ByteBuf byteBuf, LispDistinguishedNameAddress address) throws LispWriterException { | ||
105 | + String distinguishedName = address.getDistinguishedName(); | ||
106 | + byte[] nameBytes = distinguishedName.getBytes(); | ||
107 | + for (int i = 0; i < nameBytes.length; i++) { | ||
108 | + byteBuf.writeChar(nameBytes[i]); | ||
109 | + } | ||
110 | + } | ||
111 | + } | ||
95 | } | 112 | } | ... | ... |
... | @@ -19,6 +19,7 @@ import io.netty.buffer.ByteBuf; | ... | @@ -19,6 +19,7 @@ import io.netty.buffer.ByteBuf; |
19 | import org.onlab.packet.IpAddress; | 19 | import org.onlab.packet.IpAddress; |
20 | import org.onosproject.lisp.msg.exceptions.LispParseError; | 20 | import org.onosproject.lisp.msg.exceptions.LispParseError; |
21 | import org.onosproject.lisp.msg.exceptions.LispReaderException; | 21 | import org.onosproject.lisp.msg.exceptions.LispReaderException; |
22 | +import org.onosproject.lisp.msg.exceptions.LispWriterException; | ||
22 | 23 | ||
23 | /** | 24 | /** |
24 | * IP address that is used by LISP Locator. | 25 | * IP address that is used by LISP Locator. |
... | @@ -63,7 +64,7 @@ public abstract class LispIpAddress extends LispAfiAddress { | ... | @@ -63,7 +64,7 @@ public abstract class LispIpAddress extends LispAfiAddress { |
63 | } | 64 | } |
64 | 65 | ||
65 | /** | 66 | /** |
66 | - * IP Address reader class. | 67 | + * IP address reader class. |
67 | */ | 68 | */ |
68 | public static class IpAddressReader implements LispAddressReader<LispIpAddress> { | 69 | public static class IpAddressReader implements LispAddressReader<LispIpAddress> { |
69 | 70 | ||
... | @@ -82,4 +83,20 @@ public abstract class LispIpAddress extends LispAfiAddress { | ... | @@ -82,4 +83,20 @@ public abstract class LispIpAddress extends LispAfiAddress { |
82 | return null; | 83 | return null; |
83 | } | 84 | } |
84 | } | 85 | } |
86 | + | ||
87 | + /** | ||
88 | + * IP address writer class. | ||
89 | + */ | ||
90 | + public static class IpAddressWriter implements LispAddressWriter<LispIpAddress> { | ||
91 | + | ||
92 | + @Override | ||
93 | + public void writeTo(ByteBuf byteBuf, LispIpAddress address) throws LispWriterException { | ||
94 | + if (address.getAddress().isIp4()) { | ||
95 | + new LispIpv4Address.Ipv4AddressWriter().writeTo(byteBuf, (LispIpv4Address) address); | ||
96 | + } | ||
97 | + if (address.getAddress().isIp6()) { | ||
98 | + new LispIpv6Address.Ipv6AddressWriter().writeTo(byteBuf, (LispIpv6Address) address); | ||
99 | + } | ||
100 | + } | ||
101 | + } | ||
85 | } | 102 | } | ... | ... |
... | @@ -18,6 +18,7 @@ package org.onosproject.lisp.msg.types; | ... | @@ -18,6 +18,7 @@ package org.onosproject.lisp.msg.types; |
18 | import io.netty.buffer.ByteBuf; | 18 | import io.netty.buffer.ByteBuf; |
19 | import org.onlab.packet.IpAddress; | 19 | import org.onlab.packet.IpAddress; |
20 | import org.onosproject.lisp.msg.exceptions.LispParseError; | 20 | import org.onosproject.lisp.msg.exceptions.LispParseError; |
21 | +import org.onosproject.lisp.msg.exceptions.LispWriterException; | ||
21 | 22 | ||
22 | import java.util.Objects; | 23 | import java.util.Objects; |
23 | 24 | ||
... | @@ -74,4 +75,16 @@ public class LispIpv4Address extends LispIpAddress { | ... | @@ -74,4 +75,16 @@ public class LispIpv4Address extends LispIpAddress { |
74 | return new LispIpv4Address(ipAddress); | 75 | return new LispIpv4Address(ipAddress); |
75 | } | 76 | } |
76 | } | 77 | } |
78 | + | ||
79 | + /** | ||
80 | + * IPv4 address writer class. | ||
81 | + */ | ||
82 | + public static class Ipv4AddressWriter implements LispAddressWriter<LispIpv4Address> { | ||
83 | + | ||
84 | + @Override | ||
85 | + public void writeTo(ByteBuf byteBuf, LispIpv4Address address) throws LispWriterException { | ||
86 | + byte[] ipByte = address.getAddress().getIp4Address().toOctets(); | ||
87 | + byteBuf.writeBytes(ipByte); | ||
88 | + } | ||
89 | + } | ||
77 | } | 90 | } | ... | ... |
... | @@ -18,6 +18,7 @@ package org.onosproject.lisp.msg.types; | ... | @@ -18,6 +18,7 @@ package org.onosproject.lisp.msg.types; |
18 | import io.netty.buffer.ByteBuf; | 18 | import io.netty.buffer.ByteBuf; |
19 | import org.onlab.packet.IpAddress; | 19 | import org.onlab.packet.IpAddress; |
20 | import org.onosproject.lisp.msg.exceptions.LispParseError; | 20 | import org.onosproject.lisp.msg.exceptions.LispParseError; |
21 | +import org.onosproject.lisp.msg.exceptions.LispWriterException; | ||
21 | 22 | ||
22 | import java.util.Objects; | 23 | import java.util.Objects; |
23 | 24 | ||
... | @@ -74,4 +75,16 @@ public class LispIpv6Address extends LispIpAddress { | ... | @@ -74,4 +75,16 @@ public class LispIpv6Address extends LispIpAddress { |
74 | return new LispIpv6Address(ipAddress); | 75 | return new LispIpv6Address(ipAddress); |
75 | } | 76 | } |
76 | } | 77 | } |
78 | + | ||
79 | + /** | ||
80 | + * Ipv6 address writer class. | ||
81 | + */ | ||
82 | + public static class Ipv6AddressWriter implements LispAddressWriter<LispIpv6Address> { | ||
83 | + | ||
84 | + @Override | ||
85 | + public void writeTo(ByteBuf byteBuf, LispIpv6Address address) throws LispWriterException { | ||
86 | + byte[] ipByte = address.getAddress().getIp6Address().toOctets(); | ||
87 | + byteBuf.writeBytes(ipByte); | ||
88 | + } | ||
89 | + } | ||
77 | } | 90 | } | ... | ... |
... | @@ -18,6 +18,7 @@ package org.onosproject.lisp.msg.types; | ... | @@ -18,6 +18,7 @@ package org.onosproject.lisp.msg.types; |
18 | import io.netty.buffer.ByteBuf; | 18 | import io.netty.buffer.ByteBuf; |
19 | import org.onosproject.lisp.msg.exceptions.LispParseError; | 19 | import org.onosproject.lisp.msg.exceptions.LispParseError; |
20 | import org.onosproject.lisp.msg.exceptions.LispReaderException; | 20 | import org.onosproject.lisp.msg.exceptions.LispReaderException; |
21 | +import org.onosproject.lisp.msg.exceptions.LispWriterException; | ||
21 | 22 | ||
22 | import java.util.Objects; | 23 | import java.util.Objects; |
23 | 24 | ||
... | @@ -216,6 +217,20 @@ public class LispLcafAddress extends LispAfiAddress { | ... | @@ -216,6 +217,20 @@ public class LispLcafAddress extends LispAfiAddress { |
216 | reserved1, reserved2, flag, length); | 217 | reserved1, reserved2, flag, length); |
217 | } | 218 | } |
218 | 219 | ||
220 | + /** | ||
221 | + * Serializes common fields to byte buffer. | ||
222 | + * | ||
223 | + * @param byteBuf byte buffer | ||
224 | + * @param address LISP LCAF address instance | ||
225 | + */ | ||
226 | + public static void serializeCommon(ByteBuf byteBuf, LispLcafAddress address) { | ||
227 | + byteBuf.writeByte(address.getReserved1()); | ||
228 | + byteBuf.writeByte(address.getFlag()); | ||
229 | + byteBuf.writeByte(address.getType().getLispCode()); | ||
230 | + byteBuf.writeByte(address.getReserved2()); | ||
231 | + byteBuf.writeShort(address.getLength()); | ||
232 | + } | ||
233 | + | ||
219 | @Override | 234 | @Override |
220 | public int hashCode() { | 235 | public int hashCode() { |
221 | return Objects.hash(lcafType, reserved1, reserved2, flag, length); | 236 | return Objects.hash(lcafType, reserved1, reserved2, flag, length); |
... | @@ -323,6 +338,9 @@ public class LispLcafAddress extends LispAfiAddress { | ... | @@ -323,6 +338,9 @@ public class LispLcafAddress extends LispAfiAddress { |
323 | } | 338 | } |
324 | } | 339 | } |
325 | 340 | ||
341 | + /** | ||
342 | + * LISP LCAF reader class. | ||
343 | + */ | ||
326 | public static class LcafAddressReader implements LispAddressReader<LispLcafAddress> { | 344 | public static class LcafAddressReader implements LispAddressReader<LispLcafAddress> { |
327 | 345 | ||
328 | private static final int LCAF_TYPE_FIELD_INDEX = 4; | 346 | private static final int LCAF_TYPE_FIELD_INDEX = 4; |
... | @@ -354,4 +372,33 @@ public class LispLcafAddress extends LispAfiAddress { | ... | @@ -354,4 +372,33 @@ public class LispLcafAddress extends LispAfiAddress { |
354 | return null; | 372 | return null; |
355 | } | 373 | } |
356 | } | 374 | } |
375 | + | ||
376 | + /** | ||
377 | + * LISP LCAF address writer class. | ||
378 | + */ | ||
379 | + public static class LcafAddressWriter implements LispAddressWriter<LispLcafAddress> { | ||
380 | + | ||
381 | + @Override | ||
382 | + public void writeTo(ByteBuf byteBuf, LispLcafAddress address) throws LispWriterException { | ||
383 | + switch (address.getType()) { | ||
384 | + case APPLICATION_DATA: | ||
385 | + new LispAppDataLcafAddress.AppDataLcafAddressWriter().writeTo(byteBuf, | ||
386 | + (LispAppDataLcafAddress) address); | ||
387 | + break; | ||
388 | + case LIST: | ||
389 | + new LispListLcafAddress.ListLcafAddressWriter().writeTo(byteBuf, | ||
390 | + (LispListLcafAddress) address); | ||
391 | + break; | ||
392 | + case SEGMENT: | ||
393 | + new LispSegmentLcafAddress.SegmentLcafAddressWriter().writeTo(byteBuf, | ||
394 | + (LispSegmentLcafAddress) address); | ||
395 | + break; | ||
396 | + case SOURCE_DEST: | ||
397 | + new LispSourceDestLcafAddress.SourceDestLcafAddressWriter().writeTo(byteBuf, | ||
398 | + (LispSourceDestLcafAddress) address); | ||
399 | + break; | ||
400 | + default: break; // TODO: need to log warning message | ||
401 | + } | ||
402 | + } | ||
403 | + } | ||
357 | } | 404 | } | ... | ... |
... | @@ -19,6 +19,7 @@ import com.google.common.collect.ImmutableList; | ... | @@ -19,6 +19,7 @@ import com.google.common.collect.ImmutableList; |
19 | import io.netty.buffer.ByteBuf; | 19 | import io.netty.buffer.ByteBuf; |
20 | import org.onosproject.lisp.msg.exceptions.LispParseError; | 20 | import org.onosproject.lisp.msg.exceptions.LispParseError; |
21 | import org.onosproject.lisp.msg.exceptions.LispReaderException; | 21 | import org.onosproject.lisp.msg.exceptions.LispReaderException; |
22 | +import org.onosproject.lisp.msg.exceptions.LispWriterException; | ||
22 | 23 | ||
23 | import java.util.List; | 24 | import java.util.List; |
24 | import java.util.Objects; | 25 | import java.util.Objects; |
... | @@ -134,4 +135,22 @@ public final class LispListLcafAddress extends LispLcafAddress { | ... | @@ -134,4 +135,22 @@ public final class LispListLcafAddress extends LispLcafAddress { |
134 | lcafAddress.getFlag(), ImmutableList.of(ipv4, ipv6)); | 135 | lcafAddress.getFlag(), ImmutableList.of(ipv4, ipv6)); |
135 | } | 136 | } |
136 | } | 137 | } |
138 | + | ||
139 | + /** | ||
140 | + * List LCAF address writer class. | ||
141 | + */ | ||
142 | + public static class ListLcafAddressWriter implements LispAddressWriter<LispListLcafAddress> { | ||
143 | + | ||
144 | + @Override | ||
145 | + public void writeTo(ByteBuf byteBuf, LispListLcafAddress address) throws LispWriterException { | ||
146 | + | ||
147 | + LispLcafAddress.serializeCommon(byteBuf, address); | ||
148 | + | ||
149 | + LispIpv4Address.Ipv4AddressWriter v4Writer = new LispIpv4Address.Ipv4AddressWriter(); | ||
150 | + LispIpv6Address.Ipv6AddressWriter v6Writer = new LispIpv6Address.Ipv6AddressWriter(); | ||
151 | + | ||
152 | + v4Writer.writeTo(byteBuf, (LispIpv4Address) address.getAddresses().get(0)); | ||
153 | + v6Writer.writeTo(byteBuf, (LispIpv6Address) address.getAddresses().get(1)); | ||
154 | + } | ||
155 | + } | ||
137 | } | 156 | } | ... | ... |
... | @@ -18,6 +18,7 @@ package org.onosproject.lisp.msg.types; | ... | @@ -18,6 +18,7 @@ package org.onosproject.lisp.msg.types; |
18 | import io.netty.buffer.ByteBuf; | 18 | import io.netty.buffer.ByteBuf; |
19 | import org.onlab.packet.MacAddress; | 19 | import org.onlab.packet.MacAddress; |
20 | import org.onosproject.lisp.msg.exceptions.LispParseError; | 20 | import org.onosproject.lisp.msg.exceptions.LispParseError; |
21 | +import org.onosproject.lisp.msg.exceptions.LispWriterException; | ||
21 | 22 | ||
22 | import java.util.Objects; | 23 | import java.util.Objects; |
23 | 24 | ||
... | @@ -88,4 +89,16 @@ public class LispMacAddress extends LispAfiAddress { | ... | @@ -88,4 +89,16 @@ public class LispMacAddress extends LispAfiAddress { |
88 | return new LispMacAddress(macAddress); | 89 | return new LispMacAddress(macAddress); |
89 | } | 90 | } |
90 | } | 91 | } |
92 | + | ||
93 | + /** | ||
94 | + * MAC address writer class. | ||
95 | + */ | ||
96 | + public static class MacAddressWriter implements LispAddressWriter<LispMacAddress> { | ||
97 | + | ||
98 | + @Override | ||
99 | + public void writeTo(ByteBuf byteBuf, LispMacAddress address) throws LispWriterException { | ||
100 | + byte[] macByte = address.getAddress().toBytes(); | ||
101 | + byteBuf.writeBytes(macByte); | ||
102 | + } | ||
103 | + } | ||
91 | } | 104 | } | ... | ... |
... | @@ -17,6 +17,7 @@ package org.onosproject.lisp.msg.types; | ... | @@ -17,6 +17,7 @@ package org.onosproject.lisp.msg.types; |
17 | 17 | ||
18 | import io.netty.buffer.ByteBuf; | 18 | import io.netty.buffer.ByteBuf; |
19 | import org.onosproject.lisp.msg.exceptions.LispParseError; | 19 | import org.onosproject.lisp.msg.exceptions.LispParseError; |
20 | +import org.onosproject.lisp.msg.exceptions.LispWriterException; | ||
20 | 21 | ||
21 | /** | 22 | /** |
22 | * No address. | 23 | * No address. |
... | @@ -40,4 +41,15 @@ public class LispNoAddress extends LispAfiAddress { | ... | @@ -40,4 +41,15 @@ public class LispNoAddress extends LispAfiAddress { |
40 | return new LispNoAddress(); | 41 | return new LispNoAddress(); |
41 | } | 42 | } |
42 | } | 43 | } |
44 | + | ||
45 | + /** | ||
46 | + * LISP no address writer class. | ||
47 | + */ | ||
48 | + public static class NoAddressWriter implements LispAddressWriter<LispNoAddress> { | ||
49 | + | ||
50 | + @Override | ||
51 | + public void writeTo(ByteBuf byteBuf, LispNoAddress address) throws LispWriterException { | ||
52 | + | ||
53 | + } | ||
54 | + } | ||
43 | } | 55 | } | ... | ... |
... | @@ -18,6 +18,7 @@ package org.onosproject.lisp.msg.types; | ... | @@ -18,6 +18,7 @@ package org.onosproject.lisp.msg.types; |
18 | import io.netty.buffer.ByteBuf; | 18 | import io.netty.buffer.ByteBuf; |
19 | import org.onosproject.lisp.msg.exceptions.LispParseError; | 19 | import org.onosproject.lisp.msg.exceptions.LispParseError; |
20 | import org.onosproject.lisp.msg.exceptions.LispReaderException; | 20 | import org.onosproject.lisp.msg.exceptions.LispReaderException; |
21 | +import org.onosproject.lisp.msg.exceptions.LispWriterException; | ||
21 | 22 | ||
22 | import java.util.Objects; | 23 | import java.util.Objects; |
23 | 24 | ||
... | @@ -212,4 +213,21 @@ public final class LispSegmentLcafAddress extends LispLcafAddress { | ... | @@ -212,4 +213,21 @@ public final class LispSegmentLcafAddress extends LispLcafAddress { |
212 | .build(); | 213 | .build(); |
213 | } | 214 | } |
214 | } | 215 | } |
216 | + | ||
217 | + /** | ||
218 | + * Segment LCAF address writer class. | ||
219 | + */ | ||
220 | + public static class SegmentLcafAddressWriter | ||
221 | + implements LispAddressWriter<LispSegmentLcafAddress> { | ||
222 | + | ||
223 | + @Override | ||
224 | + public void writeTo(ByteBuf byteBuf, LispSegmentLcafAddress address) | ||
225 | + throws LispWriterException { | ||
226 | + | ||
227 | + LispLcafAddress.serializeCommon(byteBuf, address); | ||
228 | + | ||
229 | + byteBuf.writeInt(address.getInstanceId()); | ||
230 | + new LispIpAddress.IpAddressWriter().writeTo(byteBuf, (LispIpAddress) address.getAddress()); | ||
231 | + } | ||
232 | + } | ||
215 | } | 233 | } | ... | ... |
... | @@ -18,6 +18,7 @@ package org.onosproject.lisp.msg.types; | ... | @@ -18,6 +18,7 @@ package org.onosproject.lisp.msg.types; |
18 | import io.netty.buffer.ByteBuf; | 18 | import io.netty.buffer.ByteBuf; |
19 | import org.onosproject.lisp.msg.exceptions.LispParseError; | 19 | import org.onosproject.lisp.msg.exceptions.LispParseError; |
20 | import org.onosproject.lisp.msg.exceptions.LispReaderException; | 20 | import org.onosproject.lisp.msg.exceptions.LispReaderException; |
21 | +import org.onosproject.lisp.msg.exceptions.LispWriterException; | ||
21 | 22 | ||
22 | import java.util.Objects; | 23 | import java.util.Objects; |
23 | 24 | ||
... | @@ -200,7 +201,7 @@ public final class LispSourceDestLcafAddress extends LispLcafAddress { | ... | @@ -200,7 +201,7 @@ public final class LispSourceDestLcafAddress extends LispLcafAddress { |
200 | /** | 201 | /** |
201 | * Sets destination address prefix. | 202 | * Sets destination address prefix. |
202 | * | 203 | * |
203 | - * @param dstPrefix | 204 | + * @param dstPrefix destination prefix |
204 | * @return SourceDestAddressBuilder object | 205 | * @return SourceDestAddressBuilder object |
205 | */ | 206 | */ |
206 | public SourceDestAddressBuilder withDstPrefix(LispAfiAddress dstPrefix) { | 207 | public SourceDestAddressBuilder withDstPrefix(LispAfiAddress dstPrefix) { |
... | @@ -283,4 +284,25 @@ public final class LispSourceDestLcafAddress extends LispLcafAddress { | ... | @@ -283,4 +284,25 @@ public final class LispSourceDestLcafAddress extends LispLcafAddress { |
283 | .build(); | 284 | .build(); |
284 | } | 285 | } |
285 | } | 286 | } |
287 | + | ||
288 | + /** | ||
289 | + * SourceDest LCAF address writer class. | ||
290 | + */ | ||
291 | + public static class SourceDestLcafAddressWriter | ||
292 | + implements LispAddressWriter<LispSourceDestLcafAddress> { | ||
293 | + | ||
294 | + @Override | ||
295 | + public void writeTo(ByteBuf byteBuf, LispSourceDestLcafAddress address) | ||
296 | + throws LispWriterException { | ||
297 | + | ||
298 | + LispLcafAddress.serializeCommon(byteBuf, address); | ||
299 | + | ||
300 | + byteBuf.writeShort(address.getReserved()); | ||
301 | + byteBuf.writeByte(address.getSrcMaskLength()); | ||
302 | + byteBuf.writeByte(address.getDstMaskLength()); | ||
303 | + AfiAddressWriter writer = new LispAfiAddress.AfiAddressWriter(); | ||
304 | + writer.writeTo(byteBuf, address.getSrcPrefix()); | ||
305 | + writer.writeTo(byteBuf, address.getDstPrefix()); | ||
306 | + } | ||
307 | + } | ||
286 | } | 308 | } | ... | ... |
-
Please register or login to post a comment