Jian Li
Committed by Thomas Vachuska

Add unit tests for LISP address serializer and deserializer

Change-Id: I56538221f3951d18c1feb9343d87cbb46c3ed04d
...@@ -126,6 +126,10 @@ public abstract class LispAfiAddress { ...@@ -126,6 +126,10 @@ public abstract class LispAfiAddress {
126 126
127 @Override 127 @Override
128 public void writeTo(ByteBuf byteBuf, LispAfiAddress address) throws LispWriterException { 128 public void writeTo(ByteBuf byteBuf, LispAfiAddress address) throws LispWriterException {
129 +
130 + // AFI code
131 + byteBuf.writeShort(address.getAfi().getIanaCode());
132 +
129 switch (address.getAfi()) { 133 switch (address.getAfi()) {
130 case IP: 134 case IP:
131 new LispIpAddress.IpAddressWriter().writeTo(byteBuf, (LispIpv4Address) address); 135 new LispIpAddress.IpAddressWriter().writeTo(byteBuf, (LispIpv4Address) address);
......
...@@ -21,6 +21,7 @@ import org.onosproject.lisp.msg.exceptions.LispReaderException; ...@@ -21,6 +21,7 @@ import org.onosproject.lisp.msg.exceptions.LispReaderException;
21 import org.onosproject.lisp.msg.exceptions.LispWriterException; 21 import org.onosproject.lisp.msg.exceptions.LispWriterException;
22 22
23 import java.nio.ByteBuffer; 23 import java.nio.ByteBuffer;
24 +import java.util.Arrays;
24 import java.util.Objects; 25 import java.util.Objects;
25 26
26 import static com.google.common.base.MoreObjects.toStringHelper; 27 import static com.google.common.base.MoreObjects.toStringHelper;
...@@ -352,7 +353,7 @@ public final class LispAppDataLcafAddress extends LispLcafAddress { ...@@ -352,7 +353,7 @@ public final class LispAppDataLcafAddress extends LispLcafAddress {
352 } 353 }
353 354
354 /** 355 /**
355 - * A utility function that obtains the partial int value from byte arrays. 356 + * An utility function that obtains the partial int value from byte arrays.
356 * 357 *
357 * @param bytes an array of bytes 358 * @param bytes an array of bytes
358 * @return converted integer 359 * @return converted integer
...@@ -378,8 +379,8 @@ public final class LispAppDataLcafAddress extends LispLcafAddress { ...@@ -378,8 +379,8 @@ public final class LispAppDataLcafAddress extends LispLcafAddress {
378 379
379 LispLcafAddress.serializeCommon(byteBuf, address); 380 LispLcafAddress.serializeCommon(byteBuf, address);
380 381
381 - // TODO: need to handle TOS 382 + byte[] tos = getPartialByteArray(address.getIpTos());
382 - 383 + byteBuf.writeBytes(tos);
383 byteBuf.writeByte(address.getProtocol()); 384 byteBuf.writeByte(address.getProtocol());
384 byteBuf.writeShort(address.getLocalPortLow()); 385 byteBuf.writeShort(address.getLocalPortLow());
385 byteBuf.writeShort(address.getLocalPortHigh()); 386 byteBuf.writeShort(address.getLocalPortHigh());
...@@ -389,5 +390,17 @@ public final class LispAppDataLcafAddress extends LispLcafAddress { ...@@ -389,5 +390,17 @@ public final class LispAppDataLcafAddress extends LispLcafAddress {
389 AfiAddressWriter writer = new LispAfiAddress.AfiAddressWriter(); 390 AfiAddressWriter writer = new LispAfiAddress.AfiAddressWriter();
390 writer.writeTo(byteBuf, address.getAddress()); 391 writer.writeTo(byteBuf, address.getAddress());
391 } 392 }
393 +
394 + /**
395 + * An utility function that obtains byte array from partial int value.
396 + *
397 + * @param value integer value
398 + * @return an array of bytes
399 + */
400 + public static byte[] getPartialByteArray(int value) {
401 + ByteBuffer buffer = ByteBuffer.allocate(4);
402 + byte[] array = buffer.putInt(value).array();
403 + return Arrays.copyOfRange(array, 1, 4);
404 + }
392 } 405 }
393 } 406 }
......
...@@ -84,10 +84,10 @@ public class LispDistinguishedNameAddress extends LispAfiAddress { ...@@ -84,10 +84,10 @@ public class LispDistinguishedNameAddress extends LispAfiAddress {
84 public LispDistinguishedNameAddress readFrom(ByteBuf byteBuf) throws LispParseError { 84 public LispDistinguishedNameAddress readFrom(ByteBuf byteBuf) throws LispParseError {
85 85
86 StringBuilder sb = new StringBuilder(); 86 StringBuilder sb = new StringBuilder();
87 - byte character = byteBuf.readByte(); 87 + byte character;
88 - while (character != 0) { 88 + while (byteBuf.readerIndex() < byteBuf.writerIndex()) {
89 - sb.append((char) character);
90 character = byteBuf.readByte(); 89 character = byteBuf.readByte();
90 + sb.append((char) character);
91 } 91 }
92 92
93 return new LispDistinguishedNameAddress(sb.toString()); 93 return new LispDistinguishedNameAddress(sb.toString());
...@@ -105,7 +105,7 @@ public class LispDistinguishedNameAddress extends LispAfiAddress { ...@@ -105,7 +105,7 @@ public class LispDistinguishedNameAddress extends LispAfiAddress {
105 String distinguishedName = address.getDistinguishedName(); 105 String distinguishedName = address.getDistinguishedName();
106 byte[] nameBytes = distinguishedName.getBytes(); 106 byte[] nameBytes = distinguishedName.getBytes();
107 for (int i = 0; i < nameBytes.length; i++) { 107 for (int i = 0; i < nameBytes.length; i++) {
108 - byteBuf.writeChar(nameBytes[i]); 108 + byteBuf.writeByte(nameBytes[i]);
109 } 109 }
110 } 110 }
111 } 111 }
......
...@@ -35,7 +35,7 @@ public class LispIpv6Address extends LispIpAddress { ...@@ -35,7 +35,7 @@ public class LispIpv6Address extends LispIpAddress {
35 * @param address IP address 35 * @param address IP address
36 */ 36 */
37 public LispIpv6Address(IpAddress address) { 37 public LispIpv6Address(IpAddress address) {
38 - super(address, AddressFamilyIdentifierEnum.IP); 38 + super(address, AddressFamilyIdentifierEnum.IP6);
39 checkArgument(address.isIp6()); 39 checkArgument(address.isIp6());
40 } 40 }
41 41
......
...@@ -128,8 +128,10 @@ public final class LispListLcafAddress extends LispLcafAddress { ...@@ -128,8 +128,10 @@ public final class LispListLcafAddress extends LispLcafAddress {
128 128
129 LispLcafAddress lcafAddress = LispLcafAddress.deserializeCommon(byteBuf); 129 LispLcafAddress lcafAddress = LispLcafAddress.deserializeCommon(byteBuf);
130 130
131 - LispAfiAddress ipv4 = new LispAfiAddress.AfiAddressReader().readFrom(byteBuf); 131 + AfiAddressReader reader = new AfiAddressReader();
132 - LispAfiAddress ipv6 = new LispAfiAddress.AfiAddressReader().readFrom(byteBuf); 132 +
133 + LispAfiAddress ipv4 = reader.readFrom(byteBuf);
134 + LispAfiAddress ipv6 = reader.readFrom(byteBuf);
133 135
134 return new LispListLcafAddress(lcafAddress.getReserved1(), lcafAddress.getReserved2(), 136 return new LispListLcafAddress(lcafAddress.getReserved1(), lcafAddress.getReserved2(),
135 lcafAddress.getFlag(), ImmutableList.of(ipv4, ipv6)); 137 lcafAddress.getFlag(), ImmutableList.of(ipv4, ipv6));
...@@ -141,6 +143,9 @@ public final class LispListLcafAddress extends LispLcafAddress { ...@@ -141,6 +143,9 @@ public final class LispListLcafAddress extends LispLcafAddress {
141 */ 143 */
142 public static class ListLcafAddressWriter implements LispAddressWriter<LispListLcafAddress> { 144 public static class ListLcafAddressWriter implements LispAddressWriter<LispListLcafAddress> {
143 145
146 + private static final int IPV4_ADDRESS_INDEX = 0;
147 + private static final int IPV6_ADDRESS_INDEX = 1;
148 +
144 @Override 149 @Override
145 public void writeTo(ByteBuf byteBuf, LispListLcafAddress address) throws LispWriterException { 150 public void writeTo(ByteBuf byteBuf, LispListLcafAddress address) throws LispWriterException {
146 151
...@@ -149,8 +154,16 @@ public final class LispListLcafAddress extends LispLcafAddress { ...@@ -149,8 +154,16 @@ public final class LispListLcafAddress extends LispLcafAddress {
149 LispIpv4Address.Ipv4AddressWriter v4Writer = new LispIpv4Address.Ipv4AddressWriter(); 154 LispIpv4Address.Ipv4AddressWriter v4Writer = new LispIpv4Address.Ipv4AddressWriter();
150 LispIpv6Address.Ipv6AddressWriter v6Writer = new LispIpv6Address.Ipv6AddressWriter(); 155 LispIpv6Address.Ipv6AddressWriter v6Writer = new LispIpv6Address.Ipv6AddressWriter();
151 156
152 - v4Writer.writeTo(byteBuf, (LispIpv4Address) address.getAddresses().get(0)); 157 + LispAfiAddress ipv4 = address.getAddresses().get(IPV4_ADDRESS_INDEX);
153 - v6Writer.writeTo(byteBuf, (LispIpv6Address) address.getAddresses().get(1)); 158 + LispAfiAddress ipv6 = address.getAddresses().get(IPV6_ADDRESS_INDEX);
159 +
160 + // IPv4 address
161 + byteBuf.writeShort(ipv4.getAfi().getIanaCode());
162 + v4Writer.writeTo(byteBuf, (LispIpv4Address) ipv4);
163 +
164 + // IPv6 address
165 + byteBuf.writeShort(ipv6.getAfi().getIanaCode());
166 + v6Writer.writeTo(byteBuf, (LispIpv6Address) ipv6);
154 } 167 }
155 } 168 }
156 } 169 }
......
...@@ -227,7 +227,8 @@ public final class LispSegmentLcafAddress extends LispLcafAddress { ...@@ -227,7 +227,8 @@ public final class LispSegmentLcafAddress extends LispLcafAddress {
227 LispLcafAddress.serializeCommon(byteBuf, address); 227 LispLcafAddress.serializeCommon(byteBuf, address);
228 228
229 byteBuf.writeInt(address.getInstanceId()); 229 byteBuf.writeInt(address.getInstanceId());
230 - new LispIpAddress.IpAddressWriter().writeTo(byteBuf, (LispIpAddress) address.getAddress()); 230 +
231 + new LispAfiAddress.AfiAddressWriter().writeTo(byteBuf, address.getAddress());
231 } 232 }
232 } 233 }
233 } 234 }
......
...@@ -16,12 +16,20 @@ ...@@ -16,12 +16,20 @@
16 package org.onosproject.lisp.msg.types; 16 package org.onosproject.lisp.msg.types;
17 17
18 import com.google.common.testing.EqualsTester; 18 import com.google.common.testing.EqualsTester;
19 +import io.netty.buffer.ByteBuf;
20 +import io.netty.buffer.Unpooled;
19 import org.junit.Before; 21 import org.junit.Before;
20 import org.junit.Test; 22 import org.junit.Test;
21 import org.onlab.packet.IpAddress; 23 import org.onlab.packet.IpAddress;
24 +import org.onosproject.lisp.msg.exceptions.LispParseError;
25 +import org.onosproject.lisp.msg.exceptions.LispReaderException;
26 +import org.onosproject.lisp.msg.exceptions.LispWriterException;
27 +import org.onosproject.lisp.msg.types.LispAppDataLcafAddress.AppDataLcafAddressWriter;
22 28
23 import static org.hamcrest.MatcherAssert.assertThat; 29 import static org.hamcrest.MatcherAssert.assertThat;
24 import static org.hamcrest.Matchers.is; 30 import static org.hamcrest.Matchers.is;
31 +import static org.onosproject.lisp.msg.types.LispAppDataLcafAddress.AppDataAddressBuilder;
32 +import static org.onosproject.lisp.msg.types.LispAppDataLcafAddress.AppDataLcafAddressReader;
25 33
26 /** 34 /**
27 * Unit tests for LispAppDataLcafAddress class. 35 * Unit tests for LispAppDataLcafAddress class.
...@@ -35,8 +43,8 @@ public class LispAppDataLcafAddressTest { ...@@ -35,8 +43,8 @@ public class LispAppDataLcafAddressTest {
35 @Before 43 @Before
36 public void setup() { 44 public void setup() {
37 45
38 - LispAppDataLcafAddress.AppDataAddressBuilder builder1 = 46 + AppDataAddressBuilder builder1 =
39 - new LispAppDataLcafAddress.AppDataAddressBuilder(); 47 + new AppDataAddressBuilder();
40 48
41 LispAfiAddress ipv4Address1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.1")); 49 LispAfiAddress ipv4Address1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.1"));
42 50
...@@ -50,8 +58,8 @@ public class LispAppDataLcafAddressTest { ...@@ -50,8 +58,8 @@ public class LispAppDataLcafAddressTest {
50 .withAddress(ipv4Address1) 58 .withAddress(ipv4Address1)
51 .build(); 59 .build();
52 60
53 - LispAppDataLcafAddress.AppDataAddressBuilder builder2 = 61 + AppDataAddressBuilder builder2 =
54 - new LispAppDataLcafAddress.AppDataAddressBuilder(); 62 + new AppDataAddressBuilder();
55 63
56 sameAsAddress1 = builder2 64 sameAsAddress1 = builder2
57 .withProtocol((byte) 0x01) 65 .withProtocol((byte) 0x01)
...@@ -63,8 +71,8 @@ public class LispAppDataLcafAddressTest { ...@@ -63,8 +71,8 @@ public class LispAppDataLcafAddressTest {
63 .withAddress(ipv4Address1) 71 .withAddress(ipv4Address1)
64 .build(); 72 .build();
65 73
66 - LispAppDataLcafAddress.AppDataAddressBuilder builder3 = 74 + AppDataAddressBuilder builder3 =
67 - new LispAppDataLcafAddress.AppDataAddressBuilder(); 75 + new AppDataAddressBuilder();
68 76
69 LispAfiAddress ipv4Address2 = new LispIpv4Address(IpAddress.valueOf("192.168.2.1")); 77 LispAfiAddress ipv4Address2 = new LispIpv4Address(IpAddress.valueOf("192.168.2.1"));
70 78
...@@ -100,4 +108,18 @@ public class LispAppDataLcafAddressTest { ...@@ -100,4 +108,18 @@ public class LispAppDataLcafAddressTest {
100 assertThat(appDataLcafAddress.getRemotePortHigh(), is((short) 254)); 108 assertThat(appDataLcafAddress.getRemotePortHigh(), is((short) 254));
101 assertThat(appDataLcafAddress.getAddress(), is(ipv4Address)); 109 assertThat(appDataLcafAddress.getAddress(), is(ipv4Address));
102 } 110 }
111 +
112 + @Test
113 + public void testSerialization() throws LispWriterException, LispParseError, LispReaderException {
114 + ByteBuf byteBuf = Unpooled.buffer();
115 +
116 + AppDataLcafAddressWriter writer = new AppDataLcafAddressWriter();
117 + writer.writeTo(byteBuf, address1);
118 +
119 + AppDataLcafAddressReader reader = new AppDataLcafAddressReader();
120 + LispAppDataLcafAddress deserialized = reader.readFrom(byteBuf);
121 +
122 + new EqualsTester()
123 + .addEqualityGroup(address1, deserialized).testEquals();
124 + }
103 } 125 }
......
...@@ -16,12 +16,18 @@ ...@@ -16,12 +16,18 @@
16 package org.onosproject.lisp.msg.types; 16 package org.onosproject.lisp.msg.types;
17 17
18 import com.google.common.testing.EqualsTester; 18 import com.google.common.testing.EqualsTester;
19 +import io.netty.buffer.ByteBuf;
20 +import io.netty.buffer.Unpooled;
19 import org.junit.Before; 21 import org.junit.Before;
20 import org.junit.Test; 22 import org.junit.Test;
23 +import org.onosproject.lisp.msg.exceptions.LispParseError;
24 +import org.onosproject.lisp.msg.exceptions.LispWriterException;
21 25
22 import static org.hamcrest.MatcherAssert.assertThat; 26 import static org.hamcrest.MatcherAssert.assertThat;
23 import static org.hamcrest.Matchers.is; 27 import static org.hamcrest.Matchers.is;
24 28
29 +import static org.onosproject.lisp.msg.types.LispDistinguishedNameAddress.*;
30 +
25 /** 31 /**
26 * Unit tests for LispDistinguishedNameAddress class. 32 * Unit tests for LispDistinguishedNameAddress class.
27 */ 33 */
...@@ -52,4 +58,18 @@ public class LispDistinguishedNameAddressTest { ...@@ -52,4 +58,18 @@ public class LispDistinguishedNameAddressTest {
52 58
53 assertThat(distinguishedNameAddress.getDistinguishedName(), is("distAddress1")); 59 assertThat(distinguishedNameAddress.getDistinguishedName(), is("distAddress1"));
54 } 60 }
61 +
62 + @Test
63 + public void testSerialization() throws LispWriterException, LispParseError {
64 + ByteBuf byteBuf = Unpooled.buffer();
65 +
66 + DistinguishedNameAddressWriter writer = new DistinguishedNameAddressWriter();
67 + writer.writeTo(byteBuf, address1);
68 +
69 + DistinguishedNameAddressReader reader = new DistinguishedNameAddressReader();
70 + LispDistinguishedNameAddress deserialized = reader.readFrom(byteBuf);
71 +
72 + new EqualsTester()
73 + .addEqualityGroup(address1, deserialized).testEquals();
74 + }
55 } 75 }
......
...@@ -16,12 +16,18 @@ ...@@ -16,12 +16,18 @@
16 package org.onosproject.lisp.msg.types; 16 package org.onosproject.lisp.msg.types;
17 17
18 import com.google.common.testing.EqualsTester; 18 import com.google.common.testing.EqualsTester;
19 +import io.netty.buffer.ByteBuf;
20 +import io.netty.buffer.Unpooled;
19 import org.junit.Before; 21 import org.junit.Before;
20 import org.junit.Test; 22 import org.junit.Test;
21 import org.onlab.packet.IpAddress; 23 import org.onlab.packet.IpAddress;
24 +import org.onosproject.lisp.msg.exceptions.LispParseError;
25 +import org.onosproject.lisp.msg.exceptions.LispWriterException;
22 26
23 import static org.hamcrest.MatcherAssert.assertThat; 27 import static org.hamcrest.MatcherAssert.assertThat;
24 import static org.hamcrest.Matchers.is; 28 import static org.hamcrest.Matchers.is;
29 +import static org.onosproject.lisp.msg.types.LispIpv4Address.Ipv4AddressReader;
30 +import static org.onosproject.lisp.msg.types.LispIpv4Address.Ipv4AddressWriter;
25 31
26 /** 32 /**
27 * Unit tests for LispIpv4Address class. 33 * Unit tests for LispIpv4Address class.
...@@ -52,4 +58,18 @@ public class LispIpv4AddressTest { ...@@ -52,4 +58,18 @@ public class LispIpv4AddressTest {
52 LispIpv4Address ipv4Address = address1; 58 LispIpv4Address ipv4Address = address1;
53 assertThat(ipv4Address.getAddress(), is(IpAddress.valueOf("192.168.1.1"))); 59 assertThat(ipv4Address.getAddress(), is(IpAddress.valueOf("192.168.1.1")));
54 } 60 }
61 +
62 + @Test
63 + public void testSerialization() throws LispWriterException, LispParseError {
64 + ByteBuf byteBuf = Unpooled.buffer();
65 +
66 + Ipv4AddressWriter writer = new Ipv4AddressWriter();
67 + writer.writeTo(byteBuf, address1);
68 +
69 + Ipv4AddressReader reader = new Ipv4AddressReader();
70 + LispIpv4Address deserialized = reader.readFrom(byteBuf);
71 +
72 + new EqualsTester()
73 + .addEqualityGroup(address1, deserialized).testEquals();
74 + }
55 } 75 }
......
...@@ -16,12 +16,19 @@ ...@@ -16,12 +16,19 @@
16 package org.onosproject.lisp.msg.types; 16 package org.onosproject.lisp.msg.types;
17 17
18 import com.google.common.testing.EqualsTester; 18 import com.google.common.testing.EqualsTester;
19 +import io.netty.buffer.ByteBuf;
20 +import io.netty.buffer.Unpooled;
19 import org.junit.Before; 21 import org.junit.Before;
20 import org.junit.Test; 22 import org.junit.Test;
21 import org.onlab.packet.IpAddress; 23 import org.onlab.packet.IpAddress;
24 +import org.onosproject.lisp.msg.exceptions.LispParseError;
25 +import org.onosproject.lisp.msg.exceptions.LispWriterException;
22 26
23 import static org.hamcrest.MatcherAssert.assertThat; 27 import static org.hamcrest.MatcherAssert.assertThat;
24 import static org.hamcrest.Matchers.is; 28 import static org.hamcrest.Matchers.is;
29 +import static org.onosproject.lisp.msg.types.LispIpv6Address.Ipv6AddressReader;
30 +import static org.onosproject.lisp.msg.types.LispIpv6Address.Ipv6AddressWriter;
31 +
25 32
26 /** 33 /**
27 * Unit tests for LispIpv6Address class. 34 * Unit tests for LispIpv6Address class.
...@@ -52,4 +59,18 @@ public class LispIpv6AddressTest { ...@@ -52,4 +59,18 @@ public class LispIpv6AddressTest {
52 LispIpv6Address ipv6Address = address1; 59 LispIpv6Address ipv6Address = address1;
53 assertThat(ipv6Address.getAddress(), is(IpAddress.valueOf("1111:2222:3333:4444:5555:6666:7777:8885"))); 60 assertThat(ipv6Address.getAddress(), is(IpAddress.valueOf("1111:2222:3333:4444:5555:6666:7777:8885")));
54 } 61 }
62 +
63 + @Test
64 + public void testSerialization() throws LispWriterException, LispParseError {
65 + ByteBuf byteBuf = Unpooled.buffer();
66 +
67 + Ipv6AddressWriter writer = new Ipv6AddressWriter();
68 + writer.writeTo(byteBuf, address1);
69 +
70 + Ipv6AddressReader reader = new Ipv6AddressReader();
71 + LispIpv6Address deserialized = reader.readFrom(byteBuf);
72 +
73 + new EqualsTester()
74 + .addEqualityGroup(address1, deserialized).testEquals();
75 + }
55 } 76 }
......
...@@ -17,14 +17,21 @@ package org.onosproject.lisp.msg.types; ...@@ -17,14 +17,21 @@ package org.onosproject.lisp.msg.types;
17 17
18 import com.google.common.collect.Lists; 18 import com.google.common.collect.Lists;
19 import com.google.common.testing.EqualsTester; 19 import com.google.common.testing.EqualsTester;
20 +import io.netty.buffer.ByteBuf;
21 +import io.netty.buffer.Unpooled;
20 import org.junit.Before; 22 import org.junit.Before;
21 import org.junit.Test; 23 import org.junit.Test;
22 import org.onlab.packet.IpAddress; 24 import org.onlab.packet.IpAddress;
25 +import org.onosproject.lisp.msg.exceptions.LispParseError;
26 +import org.onosproject.lisp.msg.exceptions.LispReaderException;
27 +import org.onosproject.lisp.msg.exceptions.LispWriterException;
23 28
24 import java.util.List; 29 import java.util.List;
25 30
26 import static org.hamcrest.MatcherAssert.assertThat; 31 import static org.hamcrest.MatcherAssert.assertThat;
27 import static org.hamcrest.Matchers.is; 32 import static org.hamcrest.Matchers.is;
33 +import static org.onosproject.lisp.msg.types.LispListLcafAddress.ListLcafAddressReader;
34 +import static org.onosproject.lisp.msg.types.LispListLcafAddress.ListLcafAddressWriter;
28 35
29 /** 36 /**
30 * Unit tests for LispListLcafAddress class. 37 * Unit tests for LispListLcafAddress class.
...@@ -79,4 +86,18 @@ public class LispListLcafAddressTest { ...@@ -79,4 +86,18 @@ public class LispListLcafAddressTest {
79 86
80 assertThat(listLcafAddress.getAddresses(), is(afiAddresses1)); 87 assertThat(listLcafAddress.getAddresses(), is(afiAddresses1));
81 } 88 }
89 +
90 + @Test
91 + public void testSerialization() throws LispWriterException, LispParseError, LispReaderException {
92 + ByteBuf byteBuf = Unpooled.buffer();
93 +
94 + ListLcafAddressWriter writer = new ListLcafAddressWriter();
95 + writer.writeTo(byteBuf, address1);
96 +
97 + ListLcafAddressReader reader = new ListLcafAddressReader();
98 + LispListLcafAddress deserialized = reader.readFrom(byteBuf);
99 +
100 + new EqualsTester()
101 + .addEqualityGroup(address1, deserialized).testEquals();
102 + }
82 } 103 }
......
...@@ -16,12 +16,18 @@ ...@@ -16,12 +16,18 @@
16 package org.onosproject.lisp.msg.types; 16 package org.onosproject.lisp.msg.types;
17 17
18 import com.google.common.testing.EqualsTester; 18 import com.google.common.testing.EqualsTester;
19 +import io.netty.buffer.ByteBuf;
20 +import io.netty.buffer.Unpooled;
19 import org.junit.Before; 21 import org.junit.Before;
20 import org.junit.Test; 22 import org.junit.Test;
21 import org.onlab.packet.MacAddress; 23 import org.onlab.packet.MacAddress;
24 +import org.onosproject.lisp.msg.exceptions.LispParseError;
25 +import org.onosproject.lisp.msg.exceptions.LispWriterException;
22 26
23 import static org.hamcrest.MatcherAssert.assertThat; 27 import static org.hamcrest.MatcherAssert.assertThat;
24 import static org.hamcrest.Matchers.is; 28 import static org.hamcrest.Matchers.is;
29 +import static org.onosproject.lisp.msg.types.LispMacAddress.MacAddressReader;
30 +import static org.onosproject.lisp.msg.types.LispMacAddress.MacAddressWriter;
25 31
26 /** 32 /**
27 * Unit tests for LispMacAddress class. 33 * Unit tests for LispMacAddress class.
...@@ -52,4 +58,18 @@ public class LispMacAddressTest { ...@@ -52,4 +58,18 @@ public class LispMacAddressTest {
52 LispMacAddress macAddress = address1; 58 LispMacAddress macAddress = address1;
53 assertThat(macAddress.getAddress(), is(MacAddress.valueOf("00:00:00:00:00:01"))); 59 assertThat(macAddress.getAddress(), is(MacAddress.valueOf("00:00:00:00:00:01")));
54 } 60 }
61 +
62 + @Test
63 + public void testSerialization() throws LispWriterException, LispParseError {
64 + ByteBuf byteBuf = Unpooled.buffer();
65 +
66 + MacAddressWriter writer = new MacAddressWriter();
67 + writer.writeTo(byteBuf, address1);
68 +
69 + MacAddressReader reader = new MacAddressReader();
70 + LispMacAddress deserialized = reader.readFrom(byteBuf);
71 +
72 + new EqualsTester()
73 + .addEqualityGroup(address1, deserialized).testEquals();
74 + }
55 } 75 }
......
...@@ -16,12 +16,19 @@ ...@@ -16,12 +16,19 @@
16 package org.onosproject.lisp.msg.types; 16 package org.onosproject.lisp.msg.types;
17 17
18 import com.google.common.testing.EqualsTester; 18 import com.google.common.testing.EqualsTester;
19 +import io.netty.buffer.ByteBuf;
20 +import io.netty.buffer.Unpooled;
19 import org.junit.Before; 21 import org.junit.Before;
20 import org.junit.Test; 22 import org.junit.Test;
21 import org.onlab.packet.IpAddress; 23 import org.onlab.packet.IpAddress;
24 +import org.onosproject.lisp.msg.exceptions.LispParseError;
25 +import org.onosproject.lisp.msg.exceptions.LispReaderException;
26 +import org.onosproject.lisp.msg.exceptions.LispWriterException;
22 27
23 import static org.hamcrest.MatcherAssert.assertThat; 28 import static org.hamcrest.MatcherAssert.assertThat;
24 import static org.hamcrest.Matchers.is; 29 import static org.hamcrest.Matchers.is;
30 +import static org.onosproject.lisp.msg.types.LispSegmentLcafAddress.SegmentLcafAddressReader;
31 +import static org.onosproject.lisp.msg.types.LispSegmentLcafAddress.SegmentLcafAddressWriter;
25 32
26 /** 33 /**
27 * Unit tests for LispSegmentLcafAddress class. 34 * Unit tests for LispSegmentLcafAddress class.
...@@ -83,4 +90,18 @@ public class LispSegmentLcafAddressTest { ...@@ -83,4 +90,18 @@ public class LispSegmentLcafAddressTest {
83 assertThat(segmentLcafAddress.getInstanceId(), is(1)); 90 assertThat(segmentLcafAddress.getInstanceId(), is(1));
84 assertThat(segmentLcafAddress.getAddress(), is(ipv4Address)); 91 assertThat(segmentLcafAddress.getAddress(), is(ipv4Address));
85 } 92 }
93 +
94 + @Test
95 + public void testSerialization() throws LispWriterException, LispParseError, LispReaderException {
96 + ByteBuf byteBuf = Unpooled.buffer();
97 +
98 + SegmentLcafAddressWriter writer = new SegmentLcafAddressWriter();
99 + writer.writeTo(byteBuf, address1);
100 +
101 + SegmentLcafAddressReader reader = new SegmentLcafAddressReader();
102 + LispSegmentLcafAddress deserialized = reader.readFrom(byteBuf);
103 +
104 + new EqualsTester()
105 + .addEqualityGroup(address1, deserialized).testEquals();
106 + }
86 } 107 }
......
...@@ -16,12 +16,19 @@ ...@@ -16,12 +16,19 @@
16 package org.onosproject.lisp.msg.types; 16 package org.onosproject.lisp.msg.types;
17 17
18 import com.google.common.testing.EqualsTester; 18 import com.google.common.testing.EqualsTester;
19 +import io.netty.buffer.ByteBuf;
20 +import io.netty.buffer.Unpooled;
19 import org.junit.Before; 21 import org.junit.Before;
20 import org.junit.Test; 22 import org.junit.Test;
21 import org.onlab.packet.IpAddress; 23 import org.onlab.packet.IpAddress;
24 +import org.onosproject.lisp.msg.exceptions.LispParseError;
25 +import org.onosproject.lisp.msg.exceptions.LispReaderException;
26 +import org.onosproject.lisp.msg.exceptions.LispWriterException;
22 27
23 import static org.hamcrest.MatcherAssert.assertThat; 28 import static org.hamcrest.MatcherAssert.assertThat;
24 import static org.hamcrest.Matchers.is; 29 import static org.hamcrest.Matchers.is;
30 +import static org.onosproject.lisp.msg.types.LispSourceDestLcafAddress.SourceDestLcafAddressReader;
31 +import static org.onosproject.lisp.msg.types.LispSourceDestLcafAddress.SourceDestLcafAddressWriter;
25 32
26 /** 33 /**
27 * Unit tests for LispSourceDestLcafAddress class. 34 * Unit tests for LispSourceDestLcafAddress class.
...@@ -95,4 +102,18 @@ public class LispSourceDestLcafAddressTest { ...@@ -95,4 +102,18 @@ public class LispSourceDestLcafAddressTest {
95 assertThat(sourceDestLcafAddress.getSrcPrefix(), is(srcAddress)); 102 assertThat(sourceDestLcafAddress.getSrcPrefix(), is(srcAddress));
96 assertThat(sourceDestLcafAddress.getDstPrefix(), is(dstAddress)); 103 assertThat(sourceDestLcafAddress.getDstPrefix(), is(dstAddress));
97 } 104 }
105 +
106 + @Test
107 + public void testSerialization() throws LispWriterException, LispParseError, LispReaderException {
108 + ByteBuf byteBuf = Unpooled.buffer();
109 +
110 + SourceDestLcafAddressWriter writer = new SourceDestLcafAddressWriter();
111 + writer.writeTo(byteBuf, address1);
112 +
113 + SourceDestLcafAddressReader reader = new SourceDestLcafAddressReader();
114 + LispSourceDestLcafAddress deserialized = reader.readFrom(byteBuf);
115 +
116 + new EqualsTester()
117 + .addEqualityGroup(address1, deserialized).testEquals();
118 + }
98 } 119 }
......