mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-10-17 10:21:52 +02:00
Improve unit test coverage by considering MapRecord and EidRecord
Change-Id: I156d9ce8a4c3becedb188a53b6ce1b8f24a5e41b
This commit is contained in:
parent
42b3e4383c
commit
b26d350b58
@ -232,6 +232,7 @@ public final class DefaultLispMapReply implements LispMapReply {
|
||||
.withIsEtr(etr)
|
||||
.withIsSecurity(security)
|
||||
.withNonce(nonce)
|
||||
.withMapRecords(mapRecords)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
@ -77,7 +77,8 @@ public final class LispEidRecord {
|
||||
// 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);
|
||||
|
||||
|
@ -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 @@ public final class DefaultLispMapNotifyTest {
|
||||
@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 @@ public final class DefaultLispMapNotifyTest {
|
||||
.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 @@ public final class DefaultLispMapNotifyTest {
|
||||
|
||||
assertThat(notify.getKeyId(), is((short) 1));
|
||||
assertThat(notify.getNonce(), is(1L));
|
||||
assertThat(notify.getRecordCount(), is(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -42,8 +42,7 @@ public final class DefaultLispMapRecordTest {
|
||||
@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 @@ public final class DefaultLispMapRecordTest {
|
||||
.withEidPrefixAfi(ipv4Locator1)
|
||||
.build();
|
||||
|
||||
LispMapRecord.MapRecordBuilder builder2 =
|
||||
new DefaultMapRecordBuilder();
|
||||
MapRecordBuilder builder2 = new DefaultMapRecordBuilder();
|
||||
|
||||
sameAsRecord1 = builder2
|
||||
.withRecordTtl(100)
|
||||
@ -68,8 +66,7 @@ public final class DefaultLispMapRecordTest {
|
||||
.withEidPrefixAfi(ipv4Locator1)
|
||||
.build();
|
||||
|
||||
LispMapRecord.MapRecordBuilder builder3 =
|
||||
new DefaultMapRecordBuilder();
|
||||
MapRecordBuilder builder3 = new DefaultMapRecordBuilder();
|
||||
|
||||
LispIpv4Address ipv4Locator2 = new LispIpv4Address(IpAddress.valueOf("192.168.1.2"));
|
||||
|
||||
|
@ -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 @@ public final class DefaultLispMapRegisterTest {
|
||||
@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 @@ public final class DefaultLispMapRegisterTest {
|
||||
.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 @@ public final class DefaultLispMapRegisterTest {
|
||||
assertThat(register.isWantMapNotify(), is(false));
|
||||
assertThat(register.getKeyId(), is((short) 1));
|
||||
assertThat(register.getNonce(), is(1L));
|
||||
assertThat(register.getRecordCount(), is(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -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 @@ public final class DefaultLispMapReplyTest {
|
||||
@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 @@ public final class DefaultLispMapReplyTest {
|
||||
.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 @@ public final class DefaultLispMapReplyTest {
|
||||
assertThat(reply.isProbe(), is(false));
|
||||
assertThat(reply.isSecurity(), is(true));
|
||||
assertThat(reply.getNonce(), is(1L));
|
||||
assertThat(reply.getRecordCount(), is(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -54,6 +54,7 @@ public final class DefaultLispMapRequestTest {
|
||||
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 @@ public final class DefaultLispMapRequestTest {
|
||||
.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 @@ public final class DefaultLispMapRequestTest {
|
||||
.withIsSmrInvoked(false)
|
||||
.withSourceEid(ipv4Eid1)
|
||||
.withItrRlocs(rlocs1)
|
||||
.withEidRecords(records2)
|
||||
.withNonce(1L)
|
||||
.build();
|
||||
|
||||
@ -85,8 +89,8 @@ public final class DefaultLispMapRequestTest {
|
||||
|
||||
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 @@ public final class DefaultLispMapRequestTest {
|
||||
.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 @@ public final class DefaultLispMapRequestTest {
|
||||
assertThat(request.isSmr(), is(true));
|
||||
assertThat(request.isSmrInvoked(), is(false));
|
||||
assertThat(request.getNonce(), is(1L));
|
||||
assertThat(request.getRecordCount(), is(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
x
Reference in New Issue
Block a user