Jian Li
Committed by Thomas Vachuska

Add unit tests for LISP control message serializer and deserializer

Change-Id: Id517db99635ad8e055d6581e5c0f3ac9f45f2869
......@@ -99,7 +99,11 @@ public final class DefaultLispMapNotify implements LispMapNotify {
@Override
public byte[] getAuthenticationData() {
if (authenticationData != null && authenticationData.length != 0) {
return ImmutableByteSequence.copyFrom(authenticationData).asArray();
} else {
return new byte[0];
}
}
@Override
......@@ -132,12 +136,13 @@ public final class DefaultLispMapNotify implements LispMapNotify {
Objects.equal(recordCount, that.recordCount) &&
Objects.equal(keyId, that.keyId) &&
Objects.equal(authDataLength, that.authDataLength) &&
Objects.equal(authenticationData, that.authenticationData);
Arrays.equals(authenticationData, that.authenticationData);
}
@Override
public int hashCode() {
return Objects.hashCode(nonce, recordCount, keyId, authDataLength, authenticationData);
return Objects.hashCode(nonce, recordCount, keyId, authDataLength) +
Arrays.hashCode(authenticationData);
}
public static final class DefaultNotifyBuilder implements NotifyBuilder {
......@@ -180,18 +185,35 @@ public final class DefaultLispMapNotify implements LispMapNotify {
@Override
public NotifyBuilder withAuthenticationData(byte[] authenticationData) {
if (authenticationData != null) {
this.authenticationData = authenticationData;
} else {
this.authenticationData = new byte[0];
}
return this;
}
@Override
public NotifyBuilder withMapRecords(List<LispMapRecord> mapRecords) {
if (mapRecords != null) {
this.mapRecords = ImmutableList.copyOf(mapRecords);
} else {
this.mapRecords = Lists.newArrayList();
}
return this;
}
@Override
public LispMapNotify build() {
if (authenticationData == null) {
authenticationData = new byte[0];
}
if (mapRecords == null) {
mapRecords = Lists.newArrayList();
}
return new DefaultLispMapNotify(nonce, keyId, authDataLength,
authenticationData, recordCount, mapRecords);
}
......
......@@ -209,12 +209,21 @@ public final class DefaultLispMapRecord implements LispMapRecord {
@Override
public MapRecordBuilder withLocators(List<LispLocatorRecord> records) {
if (records != null) {
this.locatorRecords = ImmutableList.copyOf(records);
} else {
this.locatorRecords = Lists.newArrayList();
}
return this;
}
@Override
public LispMapRecord build() {
if (locatorRecords == null) {
locatorRecords = Lists.newArrayList();
}
return new DefaultLispMapRecord(recordTtl, locatorCount, maskLength,
action, authoritative, mapVersionNumber, eidPrefixAfi, locatorRecords);
}
......@@ -228,6 +237,8 @@ public final class DefaultLispMapRecord implements LispMapRecord {
private static final int AUTHORITATIVE_INDEX = 4;
private static final int RESERVED_SKIP_LENGTH = 1;
private static final int REPLY_ACTION_SHIFT_BIT = 5;
@Override
public LispMapRecord readFrom(ByteBuf byteBuf) throws LispParseError, LispReaderException {
......@@ -235,17 +246,22 @@ public final class DefaultLispMapRecord implements LispMapRecord {
int recordTtl = byteBuf.readInt();
// Locator count -> 8 bits
int locatorCount = byteBuf.readUnsignedShort();
int locatorCount = byteBuf.readUnsignedByte();
// EID mask length -> 8 bits
byte maskLength = (byte) byteBuf.readUnsignedByte();
// TODO: need to de-serialize LispMapReplyAction
byte actionWithFlag = (byte) byteBuf.readUnsignedByte();
byte actionWithFlag = byteBuf.readByte();
// action -> 3 bit
int actionByte = actionWithFlag >> REPLY_ACTION_SHIFT_BIT;
LispMapReplyAction action = LispMapReplyAction.valueOf(actionByte);
if (action == null) {
action = LispMapReplyAction.NoAction;
}
// authoritative flag -> 1 bit
boolean authoritative = ByteOperator.getBit(actionWithFlag, AUTHORITATIVE_INDEX);
boolean authoritative = ByteOperator.getBit((byte) (actionWithFlag >> AUTHORITATIVE_INDEX), 0);
// let's skip the reserved field
byteBuf.skipBytes(RESERVED_SKIP_LENGTH);
......@@ -264,6 +280,7 @@ public final class DefaultLispMapRecord implements LispMapRecord {
.withRecordTtl(recordTtl)
.withLocatorCount(locatorCount)
.withMaskLength(maskLength)
.withAction(action)
.withAuthoritative(authoritative)
.withMapVersionNumber(mapVersionNumber)
.withLocators(locators)
......@@ -301,9 +318,8 @@ public final class DefaultLispMapRecord implements LispMapRecord {
// authoritative bit
byte authoritative = DISABLE_BIT;
if (message.isAuthoritative()) {
authoritative = ENABLE_BIT;
authoritative = ENABLE_BIT << AUTHORITATIVE_FLAG_SHIFT_BIT;
}
authoritative = (byte) (authoritative << AUTHORITATIVE_FLAG_SHIFT_BIT);
byteBuf.writeByte((byte) (action + authoritative));
......
......@@ -29,6 +29,8 @@ import java.util.Arrays;
import java.util.List;
import static com.google.common.base.MoreObjects.toStringHelper;
import static org.onosproject.lisp.msg.protocols.DefaultLispMapRecord.MapRecordReader;
import static org.onosproject.lisp.msg.protocols.DefaultLispMapRecord.MapRecordWriter;
/**
......@@ -117,7 +119,11 @@ public final class DefaultLispMapRegister implements LispMapRegister {
@Override
public byte[] getAuthenticationData() {
return ImmutableByteSequence.copyFrom(this.authenticationData).asArray();
if (authenticationData != null && authenticationData.length != 0) {
return ImmutableByteSequence.copyFrom(authenticationData).asArray();
} else {
return new byte[0];
}
}
@Override
......@@ -153,7 +159,7 @@ public final class DefaultLispMapRegister implements LispMapRegister {
Objects.equal(recordCount, that.recordCount) &&
Objects.equal(keyId, that.keyId) &&
Objects.equal(authDataLength, that.authDataLength) &&
Objects.equal(authenticationData, that.authenticationData) &&
Arrays.equals(authenticationData, that.authenticationData) &&
Objects.equal(proxyMapReply, that.proxyMapReply) &&
Objects.equal(wantMapNotify, that.wantMapNotify);
}
......@@ -161,7 +167,7 @@ public final class DefaultLispMapRegister implements LispMapRegister {
@Override
public int hashCode() {
return Objects.hashCode(nonce, recordCount, keyId, authDataLength,
authenticationData, proxyMapReply, wantMapNotify);
proxyMapReply, wantMapNotify) + Arrays.hashCode(authenticationData);
}
public static final class DefaultRegisterBuilder implements RegisterBuilder {
......@@ -218,18 +224,34 @@ public final class DefaultLispMapRegister implements LispMapRegister {
@Override
public RegisterBuilder withAuthenticationData(byte[] authenticationData) {
if (authenticationData != null) {
this.authenticationData = authenticationData;
} else {
this.authenticationData = new byte[0];
}
return this;
}
@Override
public RegisterBuilder withMapRecords(List<LispMapRecord> mapRecords) {
if (mapRecords != null) {
this.mapRecords = ImmutableList.copyOf(mapRecords);
} else {
this.mapRecords = Lists.newArrayList();
}
return this;
}
@Override
public LispMapRegister build() {
if (authenticationData == null) {
authenticationData = new byte[0];
}
if (mapRecords == null) {
mapRecords = Lists.newArrayList();
}
return new DefaultLispMapRegister(nonce, keyId, authDataLength,
authenticationData, recordCount, mapRecords, proxyMapReply, wantMapNotify);
}
......@@ -280,7 +302,7 @@ public final class DefaultLispMapRegister implements LispMapRegister {
List<LispMapRecord> mapRecords = Lists.newArrayList();
for (int i = 0; i < recordCount; i++) {
mapRecords.add(new DefaultLispMapRecord.MapRecordReader().readFrom(byteBuf));
mapRecords.add(new MapRecordReader().readFrom(byteBuf));
}
return new DefaultRegisterBuilder()
......@@ -360,7 +382,7 @@ public final class DefaultLispMapRegister implements LispMapRegister {
// TODO: need to implement MAC authentication mechanism
// serialize map records
DefaultLispMapRecord.MapRecordWriter writer = new DefaultLispMapRecord.MapRecordWriter();
MapRecordWriter writer = new MapRecordWriter();
List<LispMapRecord> records = message.getMapRecords();
for (int i = 0; i < records.size(); i++) {
......
......@@ -185,12 +185,22 @@ public final class DefaultLispMapReply implements LispMapReply {
@Override
public ReplyBuilder withMapRecords(List<LispMapRecord> mapRecords) {
if (this.mapRecords != null) {
this.mapRecords = ImmutableList.copyOf(mapRecords);
} else {
this.mapRecords = Lists.newArrayList();
}
return this;
}
@Override
public LispMapReply build() {
if (mapRecords == null) {
mapRecords = Lists.newArrayList();
}
return new DefaultLispMapReply(nonce, recordCount, probe, etr, security, mapRecords);
}
}
......
......@@ -28,6 +28,8 @@ import org.onosproject.lisp.msg.types.LispAfiAddress;
import java.util.List;
import static com.google.common.base.MoreObjects.toStringHelper;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.onosproject.lisp.msg.types.LispAfiAddress.AfiAddressWriter;
import static org.onosproject.lisp.msg.protocols.LispEidRecord.EidRecordWriter;
......@@ -179,8 +181,6 @@ public final class DefaultLispMapRequest implements LispMapRequest {
return Objects.equal(nonce, that.nonce) &&
Objects.equal(recordCount, that.recordCount) &&
Objects.equal(sourceEid, that.sourceEid) &&
Objects.equal(itrRlocs, that.itrRlocs) &&
Objects.equal(eidRecords, that.eidRecords) &&
Objects.equal(authoritative, that.authoritative) &&
Objects.equal(mapDataPresent, that.mapDataPresent) &&
Objects.equal(probe, that.probe) &&
......@@ -191,8 +191,8 @@ public final class DefaultLispMapRequest implements LispMapRequest {
@Override
public int hashCode() {
return Objects.hashCode(nonce, recordCount, sourceEid, itrRlocs, eidRecords,
authoritative, mapDataPresent, probe, smr, pitr, smrInvoked);
return Objects.hashCode(nonce, recordCount, sourceEid, authoritative,
mapDataPresent, probe, smr, pitr, smrInvoked);
}
public static final class DefaultRequestBuilder implements RequestBuilder {
......@@ -270,18 +270,33 @@ public final class DefaultLispMapRequest implements LispMapRequest {
@Override
public RequestBuilder withItrRlocs(List<LispAfiAddress> itrRlocs) {
if (itrRlocs != null) {
this.itrRlocs = ImmutableList.copyOf(itrRlocs);
} else {
this.itrRlocs = Lists.newArrayList();
}
return this;
}
@Override
public RequestBuilder withEidRecords(List<LispEidRecord> records) {
if (records != null) {
this.eidRecords = ImmutableList.copyOf(records);
} else {
this.eidRecords = Lists.newArrayList();
}
return this;
}
@Override
public LispMapRequest build() {
checkNotNull(sourceEid, "Must have a source EID");
checkArgument((itrRlocs != null) && (itrRlocs.size() > 0), "Must have an ITR RLOC entry");
return new DefaultLispMapRequest(nonce, recordCount, sourceEid, itrRlocs,
eidRecords, authoritative, mapDataPresent, probe, smr, pitr, smrInvoked);
}
......@@ -331,10 +346,10 @@ public final class DefaultLispMapRequest implements LispMapRequest {
// let's skip reserved field, only obtains ITR counter value
// assume that first 3 bits are all set as 0,
// remain 5 bits represent Itr Rloc Counter (IRC)
int irc = byteBuf.readUnsignedShort();
int irc = byteBuf.readUnsignedByte();
// record count -> 8 bits
int recordCount = byteBuf.readUnsignedShort();
int recordCount = byteBuf.readUnsignedByte();
// nonce -> 64 bits
long nonce = byteBuf.readLong();
......@@ -387,8 +402,6 @@ public final class DefaultLispMapRequest implements LispMapRequest {
private static final int ENABLE_BIT = 1;
private static final int DISABLE_BIT = 0;
private static final int UNUSED_ZERO = 0;
@Override
public void writeTo(ByteBuf byteBuf, LispMapRequest message) throws LispWriterException {
......@@ -435,8 +448,8 @@ public final class DefaultLispMapRequest implements LispMapRequest {
byteBuf.writeByte((byte) (pitr + smrInvoked));
// TODO: ITR RLOC count
byteBuf.writeByte((byte) UNUSED_ZERO);
// ITR Rloc count
byteBuf.writeByte((byte) message.getItrRlocs().size());
// record count
byteBuf.writeByte(message.getRecordCount());
......
......@@ -16,11 +16,19 @@
package org.onosproject.lisp.msg.protocols;
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.types.LispIpv4Address;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.onosproject.lisp.msg.protocols.DefaultLispLocatorRecord.*;
/**
* Unit tests for DefaultLispLocatorRecord class.
......@@ -35,7 +43,9 @@ public final class DefaultLispLocatorRecordTest {
public void setup() {
LispLocatorRecord.LocatorRecordBuilder builder1 =
new DefaultLispLocatorRecord.DefaultLocatorRecordBuilder();
new DefaultLocatorRecordBuilder();
LispIpv4Address ipv4Locator1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.1"));
record1 = builder1
.withPriority((byte) 0x01)
......@@ -45,10 +55,11 @@ public final class DefaultLispLocatorRecordTest {
.withLocalLocator(true)
.withRlocProbed(false)
.withRouted(true)
.withLocatorAfi(ipv4Locator1)
.build();
LispLocatorRecord.LocatorRecordBuilder builder2 =
new DefaultLispLocatorRecord.DefaultLocatorRecordBuilder();
new DefaultLocatorRecordBuilder();
sameAsRecord1 = builder2
.withPriority((byte) 0x01)
......@@ -58,10 +69,13 @@ public final class DefaultLispLocatorRecordTest {
.withLocalLocator(true)
.withRlocProbed(false)
.withRouted(true)
.withLocatorAfi(ipv4Locator1)
.build();
LispLocatorRecord.LocatorRecordBuilder builder3 =
new DefaultLispLocatorRecord.DefaultLocatorRecordBuilder();
new DefaultLocatorRecordBuilder();
LispIpv4Address ipv4Locator2 = new LispIpv4Address(IpAddress.valueOf("192.168.1.2"));
record2 = builder3
.withPriority((byte) 0x02)
......@@ -71,6 +85,7 @@ public final class DefaultLispLocatorRecordTest {
.withLocalLocator(false)
.withRlocProbed(true)
.withRouted(false)
.withLocatorAfi(ipv4Locator2)
.build();
}
......@@ -85,6 +100,8 @@ public final class DefaultLispLocatorRecordTest {
public void testConstruction() {
DefaultLispLocatorRecord record = (DefaultLispLocatorRecord) record1;
LispIpv4Address ipv4Locator = new LispIpv4Address(IpAddress.valueOf("192.168.1.1"));
assertThat(record.getPriority(), is((byte) 0x01));
assertThat(record.getWeight(), is((byte) 0x01));
assertThat(record.getMulticastPriority(), is((byte) 0x01));
......@@ -92,5 +109,20 @@ public final class DefaultLispLocatorRecordTest {
assertThat(record.isLocalLocator(), is(true));
assertThat(record.isRlocProbed(), is(false));
assertThat(record.isRouted(), is(true));
assertThat(record.getLocatorAfi(), is(ipv4Locator));
}
@Test
public void testSerialization() throws LispReaderException, LispWriterException, LispParseError {
ByteBuf byteBuf = Unpooled.buffer();
LocatorRecordWriter writer = new LocatorRecordWriter();
writer.writeTo(byteBuf, record1);
LocatorRecordReader reader = new LocatorRecordReader();
LispLocatorRecord deserialized = reader.readFrom(byteBuf);
new EqualsTester()
.addEqualityGroup(record1, deserialized).testEquals();
}
}
......
......@@ -16,11 +16,17 @@
package org.onosproject.lisp.msg.protocols;
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.onosproject.lisp.msg.exceptions.LispParseError;
import org.onosproject.lisp.msg.exceptions.LispReaderException;
import org.onosproject.lisp.msg.exceptions.LispWriterException;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.onosproject.lisp.msg.protocols.DefaultLispMapNotify.*;
/**
* Unit tests for DefaultLispMapNotify class.
......@@ -35,25 +41,25 @@ public final class DefaultLispMapNotifyTest {
public void setup() {
LispMapNotify.NotifyBuilder builder1 =
new DefaultLispMapNotify.DefaultNotifyBuilder();
new DefaultNotifyBuilder();
notify1 = builder1
.withKeyId((short) 1)
.withNonce(1L)
.withRecordCount((byte) 0x01)
.withRecordCount((byte) 0)
.build();
LispMapNotify.NotifyBuilder builder2 =
new DefaultLispMapNotify.DefaultNotifyBuilder();
new DefaultNotifyBuilder();
sameAsNotify1 = builder2
.withKeyId((short) 1)
.withNonce(1L)
.withRecordCount((byte) 0x01)
.withRecordCount((byte) 0)
.build();
LispMapNotify.NotifyBuilder builder3 =
new DefaultLispMapNotify.DefaultNotifyBuilder();
new DefaultNotifyBuilder();
notify2 = builder3
.withKeyId((short) 2)
......@@ -75,6 +81,20 @@ public final class DefaultLispMapNotifyTest {
assertThat(notify.getKeyId(), is((short) 1));
assertThat(notify.getNonce(), is(1L));
assertThat(notify.getRecordCount(), is((byte) 0x01));
assertThat(notify.getRecordCount(), is((byte) 0));
}
@Test
public void testSerialization() throws LispReaderException, LispWriterException, LispParseError {
ByteBuf byteBuf = Unpooled.buffer();
NotifyWriter writer = new NotifyWriter();
writer.writeTo(byteBuf, notify1);
NotifyReader reader = new NotifyReader();
LispMapNotify deserialized = reader.readFrom(byteBuf);
new EqualsTester()
.addEqualityGroup(notify1, deserialized).testEquals();
}
}
......
......@@ -16,11 +16,19 @@
package org.onosproject.lisp.msg.protocols;
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.types.LispIpv4Address;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.onosproject.lisp.msg.protocols.DefaultLispMapRecord.*;
/**
* Unit tests for DefaultLispMapRecord class.
......@@ -35,29 +43,37 @@ public final class DefaultLispMapRecordTest {
public void setup() {
LispMapRecord.MapRecordBuilder builder1 =
new DefaultLispMapRecord.DefaultMapRecordBuilder();
new DefaultMapRecordBuilder();
LispIpv4Address ipv4Locator1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.1"));
record1 = builder1
.withRecordTtl(100)
.withAuthoritative(true)
.withLocatorCount(100)
.withLocatorCount(0)
.withMapVersionNumber((short) 1)
.withMaskLength((byte) 0x01)
.withAction(LispMapReplyAction.NativelyForward)
.withEidPrefixAfi(ipv4Locator1)
.build();
LispMapRecord.MapRecordBuilder builder2 =
new DefaultLispMapRecord.DefaultMapRecordBuilder();
new DefaultMapRecordBuilder();
sameAsRecord1 = builder2
.withRecordTtl(100)
.withAuthoritative(true)
.withLocatorCount(100)
.withLocatorCount(0)
.withMapVersionNumber((short) 1)
.withMaskLength((byte) 0x01)
.withAction(LispMapReplyAction.NativelyForward)
.withEidPrefixAfi(ipv4Locator1)
.build();
LispMapRecord.MapRecordBuilder builder3 =
new DefaultLispMapRecord.DefaultMapRecordBuilder();
new DefaultMapRecordBuilder();
LispIpv4Address ipv4Locator2 = new LispIpv4Address(IpAddress.valueOf("192.168.1.2"));
record2 = builder3
.withRecordTtl(200)
......@@ -65,6 +81,8 @@ public final class DefaultLispMapRecordTest {
.withLocatorCount(200)
.withMapVersionNumber((short) 2)
.withMaskLength((byte) 0x02)
.withAction(LispMapReplyAction.Drop)
.withEidPrefixAfi(ipv4Locator2)
.build();
}
......@@ -79,10 +97,28 @@ public final class DefaultLispMapRecordTest {
public void testConstruction() {
DefaultLispMapRecord record = (DefaultLispMapRecord) record1;
LispIpv4Address ipv4Locator = new LispIpv4Address(IpAddress.valueOf("192.168.1.1"));
assertThat(record.getRecordTtl(), is(100));
assertThat(record.isAuthoritative(), is(true));
assertThat(record.getLocatorCount(), is(100));
assertThat(record.getLocatorCount(), is(0));
assertThat(record.getMapVersionNumber(), is((short) 1));
assertThat(record.getMaskLength(), is((byte) 0x01));
assertThat(record.getAction(), is(LispMapReplyAction.NativelyForward));
assertThat(record.getEidPrefixAfi(), is(ipv4Locator));
}
@Test
public void testSerialization() throws LispReaderException, LispWriterException, LispParseError {
ByteBuf byteBuf = Unpooled.buffer();
MapRecordWriter writer = new MapRecordWriter();
writer.writeTo(byteBuf, record1);
MapRecordReader reader = new MapRecordReader();
LispMapRecord deserialized = reader.readFrom(byteBuf);
new EqualsTester()
.addEqualityGroup(record1, deserialized).testEquals();
}
}
......
......@@ -16,8 +16,15 @@
package org.onosproject.lisp.msg.protocols;
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.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 static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
......@@ -42,7 +49,7 @@ public final class DefaultLispMapRegisterTest {
.withIsWantMapNotify(false)
.withKeyId((short) 1)
.withNonce(1L)
.withRecordCount((byte) 0x01)
.withRecordCount((byte) 0)
.build();
LispMapRegister.RegisterBuilder builder2 =
......@@ -53,7 +60,7 @@ public final class DefaultLispMapRegisterTest {
.withIsWantMapNotify(false)
.withKeyId((short) 1)
.withNonce(1L)
.withRecordCount((byte) 0x01)
.withRecordCount((byte) 0)
.build();
LispMapRegister.RegisterBuilder builder3 =
......@@ -83,6 +90,20 @@ public final class DefaultLispMapRegisterTest {
assertThat(register.isWantMapNotify(), is(false));
assertThat(register.getKeyId(), is((short) 1));
assertThat(register.getNonce(), is(1L));
assertThat(register.getRecordCount(), is((byte) 0x01));
assertThat(register.getRecordCount(), is((byte) 0));
}
@Test
public void testSerialization() throws LispReaderException, LispWriterException, LispParseError {
ByteBuf byteBuf = Unpooled.buffer();
RegisterWriter writer = new RegisterWriter();
writer.writeTo(byteBuf, register1);
RegisterReader reader = new RegisterReader();
LispMapRegister deserialized = reader.readFrom(byteBuf);
new EqualsTester()
.addEqualityGroup(register1, deserialized).testEquals();
}
}
......
......@@ -16,8 +16,15 @@
package org.onosproject.lisp.msg.protocols;
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.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 static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
......@@ -42,7 +49,7 @@ public final class DefaultLispMapReplyTest {
.withIsProbe(false)
.withIsSecurity(true)
.withNonce(1L)
.withRecordCount((byte) 0x01)
.withRecordCount((byte) 0)
.build();
LispMapReply.ReplyBuilder builder2 =
......@@ -53,7 +60,7 @@ public final class DefaultLispMapReplyTest {
.withIsProbe(false)
.withIsSecurity(true)
.withNonce(1L)
.withRecordCount((byte) 0x01)
.withRecordCount((byte) 0)
.build();
LispMapReply.ReplyBuilder builder3 =
......@@ -82,6 +89,19 @@ public final class DefaultLispMapReplyTest {
assertThat(reply.isProbe(), is(false));
assertThat(reply.isSecurity(), is(true));
assertThat(reply.getNonce(), is(1L));
assertThat(reply.getRecordCount(), is((byte) 0x01));
assertThat(reply.getRecordCount(), is((byte) 0));
}
@Test
public void testSerialization() throws LispReaderException, LispWriterException, LispParseError {
ByteBuf byteBuf = Unpooled.buffer();
ReplyWriter writer = new ReplyWriter();
writer.writeTo(byteBuf, reply1);
ReplyReader reader = new ReplyReader();
LispMapReply deserialized = reader.readFrom(byteBuf);
new EqualsTester()
.addEqualityGroup(reply1, deserialized).testEquals();
}
}
......
......@@ -15,12 +15,24 @@
*/
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.types.LispAfiAddress;
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.DefaultLispMapRequest.*;
/**
* Unit tests for DefaultLispMapRequest class.
......@@ -34,8 +46,14 @@ public final class DefaultLispMapRequestTest {
@Before
public void setup() {
LispMapRequest.RequestBuilder builder1 =
new DefaultLispMapRequest.DefaultRequestBuilder();
RequestBuilder builder1 = new DefaultRequestBuilder();
LispIpv4Address ipv4Eid1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.1"));
LispIpv4Address ipv4Rloc1 = new LispIpv4Address(IpAddress.valueOf("10.1.1.1"));
LispIpv4Address ipv4Rloc2 = new LispIpv4Address(IpAddress.valueOf("10.1.1.2"));
List<LispAfiAddress> rlocs1 = ImmutableList.of(ipv4Rloc1, ipv4Rloc2);
request1 = builder1
.withIsAuthoritative(true)
......@@ -44,12 +62,13 @@ public final class DefaultLispMapRequestTest {
.withIsProbe(false)
.withIsSmr(true)
.withIsSmrInvoked(false)
.withSourceEid(ipv4Eid1)
.withItrRlocs(rlocs1)
.withNonce(1L)
.withRecordCount((byte) 0x01)
.withRecordCount((byte) 0)
.build();
LispMapRequest.RequestBuilder builder2 =
new DefaultLispMapRequest.DefaultRequestBuilder();
RequestBuilder builder2 = new DefaultRequestBuilder();
sameAsRequest1 = builder2
.withIsAuthoritative(true)
......@@ -58,12 +77,20 @@ public final class DefaultLispMapRequestTest {
.withIsProbe(false)
.withIsSmr(true)
.withIsSmrInvoked(false)
.withSourceEid(ipv4Eid1)
.withItrRlocs(rlocs1)
.withNonce(1L)
.withRecordCount((byte) 0x01)
.withRecordCount((byte) 0)
.build();
LispMapRequest.RequestBuilder builder3 =
new DefaultLispMapRequest.DefaultRequestBuilder();
RequestBuilder builder3 = new DefaultRequestBuilder();
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"));
List<LispAfiAddress> rlocs2 = ImmutableList.of(ipv4Rloc3, ipv4Rloc4);
request2 = builder3
.withIsAuthoritative(false)
......@@ -72,6 +99,8 @@ public final class DefaultLispMapRequestTest {
.withIsProbe(true)
.withIsSmr(false)
.withIsSmrInvoked(true)
.withSourceEid(ipv4Eid2)
.withItrRlocs(rlocs2)
.withNonce(2L)
.withRecordCount((byte) 0x02)
.build();
......@@ -95,6 +124,19 @@ public final class DefaultLispMapRequestTest {
assertThat(request.isSmr(), is(true));
assertThat(request.isSmrInvoked(), is(false));
assertThat(request.getNonce(), is(1L));
assertThat(request.getRecordCount(), is((byte) 0x01));
assertThat(request.getRecordCount(), is((byte) 0));
}
@Test
public void testSerialization() throws LispReaderException, LispWriterException, LispParseError {
ByteBuf byteBuf = Unpooled.buffer();
RequestWriter writer = new RequestWriter();
writer.writeTo(byteBuf, request1);
RequestReader reader = new RequestReader();
LispMapRequest deserialized = reader.readFrom(byteBuf);
new EqualsTester()
.addEqualityGroup(request1, deserialized).testEquals();
}
}
......
......@@ -61,7 +61,7 @@ public final class ByteOperator {
* @param decimal decimal formatted integer
* @return hex formatted integer
*/
private static int getHex(int decimal) {
public static int getHex(int decimal) {
return Integer.valueOf(String.valueOf(decimal), 16);
}
}
......