Improve unit test coverage by considering MapRecord and EidRecord
Change-Id: I156d9ce8a4c3becedb188a53b6ce1b8f24a5e41b
diff --git a/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/protocols/DefaultLispMapReply.java b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/protocols/DefaultLispMapReply.java
index 3cdfa42..b412cdb 100644
--- a/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/protocols/DefaultLispMapReply.java
+++ b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/protocols/DefaultLispMapReply.java
@@ -232,6 +232,7 @@
.withIsEtr(etr)
.withIsSecurity(security)
.withNonce(nonce)
+ .withMapRecords(mapRecords)
.build();
}
}
diff --git a/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/protocols/LispEidRecord.java b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/protocols/LispEidRecord.java
index 9ceef6c..e4ea7db 100644
--- a/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/protocols/LispEidRecord.java
+++ b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/protocols/LispEidRecord.java
@@ -77,7 +77,8 @@
// let's skip the reserved field
byteBuf.skipBytes(RESERVED_SKIP_LENGTH);
- short maskLength = (short) byteBuf.readUnsignedShort();
+ // mask length -> 8 bits
+ short maskLength = byteBuf.readUnsignedByte();
LispAfiAddress prefix = new LispAfiAddress.AfiAddressReader().readFrom(byteBuf);
diff --git a/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/protocols/DefaultLispMapNotifyTest.java b/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/protocols/DefaultLispMapNotifyTest.java
index 3cea68e..434e22a 100644
--- a/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/protocols/DefaultLispMapNotifyTest.java
+++ b/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/protocols/DefaultLispMapNotifyTest.java
@@ -15,18 +15,25 @@
*/
package org.onosproject.lisp.msg.protocols;
+import com.google.common.collect.ImmutableList;
import com.google.common.testing.EqualsTester;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.junit.Before;
import org.junit.Test;
+import org.onlab.packet.IpAddress;
import org.onosproject.lisp.msg.exceptions.LispParseError;
import org.onosproject.lisp.msg.exceptions.LispReaderException;
import org.onosproject.lisp.msg.exceptions.LispWriterException;
+import org.onosproject.lisp.msg.protocols.LispMapRecord.MapRecordBuilder;
+import org.onosproject.lisp.msg.types.LispIpv4Address;
+
+import java.util.List;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.onosproject.lisp.msg.protocols.DefaultLispMapNotify.*;
+import static org.onosproject.lisp.msg.protocols.DefaultLispMapRecord.DefaultMapRecordBuilder;
/**
* Unit tests for DefaultLispMapNotify class.
@@ -40,23 +47,29 @@
@Before
public void setup() {
- LispMapNotify.NotifyBuilder builder1 =
+ NotifyBuilder builder1 =
new DefaultNotifyBuilder();
+ List<LispMapRecord> records1 = ImmutableList.of(getMapRecord(), getMapRecord());
+
notify1 = builder1
.withKeyId((short) 1)
.withNonce(1L)
+ .withMapRecords(records1)
.build();
- LispMapNotify.NotifyBuilder builder2 =
+ NotifyBuilder builder2 =
new DefaultNotifyBuilder();
+ List<LispMapRecord> records2 = ImmutableList.of(getMapRecord(), getMapRecord());
+
sameAsNotify1 = builder2
.withKeyId((short) 1)
.withNonce(1L)
+ .withMapRecords(records2)
.build();
- LispMapNotify.NotifyBuilder builder3 =
+ NotifyBuilder builder3 =
new DefaultNotifyBuilder();
notify2 = builder3
@@ -65,6 +78,21 @@
.build();
}
+ private LispMapRecord getMapRecord() {
+ MapRecordBuilder builder1 = new DefaultMapRecordBuilder();
+
+ LispIpv4Address ipv4Locator1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.1"));
+
+ return builder1
+ .withRecordTtl(100)
+ .withAuthoritative(true)
+ .withMapVersionNumber((short) 1)
+ .withMaskLength((byte) 0x01)
+ .withAction(LispMapReplyAction.NativelyForward)
+ .withEidPrefixAfi(ipv4Locator1)
+ .build();
+ }
+
@Test
public void testEquality() {
new EqualsTester()
@@ -78,6 +106,7 @@
assertThat(notify.getKeyId(), is((short) 1));
assertThat(notify.getNonce(), is(1L));
+ assertThat(notify.getRecordCount(), is(2));
}
@Test
diff --git a/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/protocols/DefaultLispMapRecordTest.java b/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/protocols/DefaultLispMapRecordTest.java
index 8a1190e..aa1c7df 100644
--- a/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/protocols/DefaultLispMapRecordTest.java
+++ b/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/protocols/DefaultLispMapRecordTest.java
@@ -42,8 +42,7 @@
@Before
public void setup() {
- LispMapRecord.MapRecordBuilder builder1 =
- new DefaultMapRecordBuilder();
+ MapRecordBuilder builder1 = new DefaultMapRecordBuilder();
LispIpv4Address ipv4Locator1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.1"));
@@ -56,8 +55,7 @@
.withEidPrefixAfi(ipv4Locator1)
.build();
- LispMapRecord.MapRecordBuilder builder2 =
- new DefaultMapRecordBuilder();
+ MapRecordBuilder builder2 = new DefaultMapRecordBuilder();
sameAsRecord1 = builder2
.withRecordTtl(100)
@@ -68,8 +66,7 @@
.withEidPrefixAfi(ipv4Locator1)
.build();
- LispMapRecord.MapRecordBuilder builder3 =
- new DefaultMapRecordBuilder();
+ MapRecordBuilder builder3 = new DefaultMapRecordBuilder();
LispIpv4Address ipv4Locator2 = new LispIpv4Address(IpAddress.valueOf("192.168.1.2"));
diff --git a/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/protocols/DefaultLispMapRegisterTest.java b/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/protocols/DefaultLispMapRegisterTest.java
index f7d8d46..ff2c104 100644
--- a/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/protocols/DefaultLispMapRegisterTest.java
+++ b/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/protocols/DefaultLispMapRegisterTest.java
@@ -15,19 +15,28 @@
*/
package org.onosproject.lisp.msg.protocols;
+import com.google.common.collect.ImmutableList;
import com.google.common.testing.EqualsTester;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.junit.Before;
import org.junit.Test;
+import org.onlab.packet.IpAddress;
import org.onosproject.lisp.msg.exceptions.LispParseError;
import org.onosproject.lisp.msg.exceptions.LispReaderException;
import org.onosproject.lisp.msg.exceptions.LispWriterException;
import org.onosproject.lisp.msg.protocols.DefaultLispMapRegister.RegisterReader;
import org.onosproject.lisp.msg.protocols.DefaultLispMapRegister.RegisterWriter;
+import org.onosproject.lisp.msg.protocols.LispMapRecord.MapRecordBuilder;
+import org.onosproject.lisp.msg.protocols.LispMapRegister.RegisterBuilder;
+import org.onosproject.lisp.msg.types.LispIpv4Address;
+
+import java.util.List;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
+import static org.onosproject.lisp.msg.protocols.DefaultLispMapRecord.DefaultMapRecordBuilder;
+import static org.onosproject.lisp.msg.protocols.DefaultLispMapRegister.DefaultRegisterBuilder;
/**
* Unit tests for DefaultLispMapRegister class.
@@ -41,28 +50,31 @@
@Before
public void setup() {
- LispMapRegister.RegisterBuilder builder1 =
- new DefaultLispMapRegister.DefaultRegisterBuilder();
+ RegisterBuilder builder1 = new DefaultRegisterBuilder();
+
+ List<LispMapRecord> records1 = ImmutableList.of(getMapRecord(), getMapRecord());
register1 = builder1
.withIsProxyMapReply(true)
.withIsWantMapNotify(false)
.withKeyId((short) 1)
.withNonce(1L)
+ .withMapRecords(records1)
.build();
- LispMapRegister.RegisterBuilder builder2 =
- new DefaultLispMapRegister.DefaultRegisterBuilder();
+ RegisterBuilder builder2 = new DefaultRegisterBuilder();
+
+ List<LispMapRecord> records2 = ImmutableList.of(getMapRecord(), getMapRecord());
sameAsRegister1 = builder2
.withIsProxyMapReply(true)
.withIsWantMapNotify(false)
.withKeyId((short) 1)
.withNonce(1L)
+ .withMapRecords(records2)
.build();
- LispMapRegister.RegisterBuilder builder3 =
- new DefaultLispMapRegister.DefaultRegisterBuilder();
+ RegisterBuilder builder3 = new DefaultRegisterBuilder();
register2 = builder3
.withIsProxyMapReply(true)
@@ -72,6 +84,21 @@
.build();
}
+ private LispMapRecord getMapRecord() {
+ MapRecordBuilder builder1 = new DefaultMapRecordBuilder();
+
+ LispIpv4Address ipv4Locator1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.1"));
+
+ return builder1
+ .withRecordTtl(100)
+ .withAuthoritative(true)
+ .withMapVersionNumber((short) 1)
+ .withMaskLength((byte) 0x01)
+ .withAction(LispMapReplyAction.NativelyForward)
+ .withEidPrefixAfi(ipv4Locator1)
+ .build();
+ }
+
@Test
public void testEquality() {
new EqualsTester()
@@ -87,6 +114,7 @@
assertThat(register.isWantMapNotify(), is(false));
assertThat(register.getKeyId(), is((short) 1));
assertThat(register.getNonce(), is(1L));
+ assertThat(register.getRecordCount(), is(2));
}
@Test
diff --git a/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/protocols/DefaultLispMapReplyTest.java b/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/protocols/DefaultLispMapReplyTest.java
index e771d15..e72b6ca 100644
--- a/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/protocols/DefaultLispMapReplyTest.java
+++ b/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/protocols/DefaultLispMapReplyTest.java
@@ -15,19 +15,28 @@
*/
package org.onosproject.lisp.msg.protocols;
+import com.google.common.collect.ImmutableList;
import com.google.common.testing.EqualsTester;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.junit.Before;
import org.junit.Test;
+import org.onlab.packet.IpAddress;
import org.onosproject.lisp.msg.exceptions.LispParseError;
import org.onosproject.lisp.msg.exceptions.LispReaderException;
import org.onosproject.lisp.msg.exceptions.LispWriterException;
import org.onosproject.lisp.msg.protocols.DefaultLispMapReply.ReplyReader;
import org.onosproject.lisp.msg.protocols.DefaultLispMapReply.ReplyWriter;
+import org.onosproject.lisp.msg.types.LispIpv4Address;
+
+import java.util.List;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
+import static org.onosproject.lisp.msg.protocols.DefaultLispMapRecord.DefaultMapRecordBuilder;
+import static org.onosproject.lisp.msg.protocols.DefaultLispMapRecord.MapRecordBuilder;
+import static org.onosproject.lisp.msg.protocols.DefaultLispMapReply.DefaultReplyBuilder;
+import static org.onosproject.lisp.msg.protocols.DefaultLispMapReply.ReplyBuilder;
/**
* Unit tests for DefaultLispMapReply class.
@@ -41,28 +50,32 @@
@Before
public void setup() {
- LispMapReply.ReplyBuilder builder1 =
- new DefaultLispMapReply.DefaultReplyBuilder();
+ ReplyBuilder builder1 = new DefaultReplyBuilder();
+
+ List<LispMapRecord> records1 = ImmutableList.of(getMapRecord(), getMapRecord());
reply1 = builder1
.withIsEtr(true)
.withIsProbe(false)
.withIsSecurity(true)
.withNonce(1L)
+ .withMapRecords(records1)
.build();
- LispMapReply.ReplyBuilder builder2 =
- new DefaultLispMapReply.DefaultReplyBuilder();
+ ReplyBuilder builder2 = new DefaultReplyBuilder();
+
+ List<LispMapRecord> records2 = ImmutableList.of(getMapRecord(), getMapRecord());
sameAsReply1 = builder2
.withIsEtr(true)
.withIsProbe(false)
.withIsSecurity(true)
.withNonce(1L)
+ .withMapRecords(records2)
.build();
- LispMapReply.ReplyBuilder builder3 =
- new DefaultLispMapReply.DefaultReplyBuilder();
+ ReplyBuilder builder3 = new DefaultReplyBuilder();
+
reply2 = builder3
.withIsEtr(false)
.withIsProbe(true)
@@ -71,6 +84,21 @@
.build();
}
+ private LispMapRecord getMapRecord() {
+ MapRecordBuilder builder1 = new DefaultMapRecordBuilder();
+
+ LispIpv4Address ipv4Locator1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.1"));
+
+ return builder1
+ .withRecordTtl(100)
+ .withAuthoritative(true)
+ .withMapVersionNumber((short) 1)
+ .withMaskLength((byte) 0x01)
+ .withAction(LispMapReplyAction.NativelyForward)
+ .withEidPrefixAfi(ipv4Locator1)
+ .build();
+ }
+
@Test
public void testEquality() {
new EqualsTester()
@@ -86,6 +114,7 @@
assertThat(reply.isProbe(), is(false));
assertThat(reply.isSecurity(), is(true));
assertThat(reply.getNonce(), is(1L));
+ assertThat(reply.getRecordCount(), is(2));
}
@Test
diff --git a/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/protocols/DefaultLispMapRequestTest.java b/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/protocols/DefaultLispMapRequestTest.java
index 469ce50..6a4fd54 100644
--- a/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/protocols/DefaultLispMapRequestTest.java
+++ b/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/protocols/DefaultLispMapRequestTest.java
@@ -54,6 +54,7 @@
LispIpv4Address ipv4Rloc2 = new LispIpv4Address(IpAddress.valueOf("10.1.1.2"));
List<LispAfiAddress> rlocs1 = ImmutableList.of(ipv4Rloc1, ipv4Rloc2);
+ List<LispEidRecord> records1 = ImmutableList.of(getEidRecord(), getEidRecord());
request1 = builder1
.withIsAuthoritative(true)
@@ -64,10 +65,12 @@
.withIsSmrInvoked(false)
.withSourceEid(ipv4Eid1)
.withItrRlocs(rlocs1)
+ .withEidRecords(records1)
.withNonce(1L)
.build();
RequestBuilder builder2 = new DefaultRequestBuilder();
+ List<LispEidRecord> records2 = ImmutableList.of(getEidRecord(), getEidRecord());
sameAsRequest1 = builder2
.withIsAuthoritative(true)
@@ -78,6 +81,7 @@
.withIsSmrInvoked(false)
.withSourceEid(ipv4Eid1)
.withItrRlocs(rlocs1)
+ .withEidRecords(records2)
.withNonce(1L)
.build();
@@ -85,8 +89,8 @@
LispIpv4Address ipv4Eid2 = new LispIpv4Address(IpAddress.valueOf("192.168.1.2"));
- LispIpv4Address ipv4Rloc3 = new LispIpv4Address(IpAddress.valueOf("10.1.1.1"));
- LispIpv4Address ipv4Rloc4 = new LispIpv4Address(IpAddress.valueOf("10.1.1.2"));
+ LispIpv4Address ipv4Rloc3 = new LispIpv4Address(IpAddress.valueOf("20.1.1.1"));
+ LispIpv4Address ipv4Rloc4 = new LispIpv4Address(IpAddress.valueOf("20.1.1.2"));
List<LispAfiAddress> rlocs2 = ImmutableList.of(ipv4Rloc3, ipv4Rloc4);
@@ -103,6 +107,11 @@
.build();
}
+ private LispEidRecord getEidRecord() {
+ LispIpv4Address eid = new LispIpv4Address(IpAddress.valueOf("20.1.1.1"));
+ return new LispEidRecord((byte) 24, eid);
+ }
+
@Test
public void testEquality() {
new EqualsTester()
@@ -121,6 +130,7 @@
assertThat(request.isSmr(), is(true));
assertThat(request.isSmrInvoked(), is(false));
assertThat(request.getNonce(), is(1L));
+ assertThat(request.getRecordCount(), is(2));
}
@Test