[ONOS-4718] Implement LISP control message classes
Change-Id: I26ab3b8da383d8967c08e14b4f11f03e0663de73
diff --git a/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/protocols/DefaultLispMapNotify.java b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/protocols/DefaultLispMapNotify.java
index 6a41ad3..261b863 100644
--- a/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/protocols/DefaultLispMapNotify.java
+++ b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/protocols/DefaultLispMapNotify.java
@@ -15,23 +15,50 @@
*/
package org.onosproject.lisp.msg.protocols;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Lists;
import io.netty.buffer.ByteBuf;
+import org.onlab.util.ImmutableByteSequence;
import java.util.List;
/**
* Default LISP map notify message class.
*/
-public class DefaultLispMapNotify implements LispMapNotify {
+public final class DefaultLispMapNotify implements LispMapNotify {
+
+ private final long nonce;
+ private final short keyId;
+ private final byte[] authenticationData;
+ private final byte recordCount;
+ private final List<LispMapRecord> mapRecords;
+
+ /**
+ * A private constructor that protects object instantiation from external.
+ *
+ * @param nonce nonce
+ * @param keyId key identifier
+ * @param authenticationData authentication data
+ * @param recordCount record count number
+ * @param mapRecords a collection of map records
+ */
+ private DefaultLispMapNotify(long nonce, short keyId, byte[] authenticationData,
+ byte recordCount, List<LispMapRecord> mapRecords) {
+ this.nonce = nonce;
+ this.keyId = keyId;
+ this.authenticationData = authenticationData;
+ this.recordCount = recordCount;
+ this.mapRecords = mapRecords;
+ }
@Override
public LispType getType() {
- return null;
+ return LispType.LISP_MAP_NOTIFY;
}
@Override
public void writeTo(ByteBuf byteBuf) {
-
+ // TODO: serialize LispMapRegister message
}
@Override
@@ -41,64 +68,76 @@
@Override
public long getNonce() {
- return 0;
+ return this.nonce;
}
@Override
public byte getRecordCount() {
- return 0;
+ return this.recordCount;
}
@Override
public short getKeyId() {
- return 0;
+ return this.keyId;
}
@Override
public byte[] getAuthenticationData() {
- return new byte[0];
+ return ImmutableByteSequence.copyFrom(this.authenticationData).asArray();
}
@Override
public List<LispMapRecord> getLispRecords() {
- return null;
+ return ImmutableList.copyOf(mapRecords);
}
public static final class DefaultNotifyBuilder implements NotifyBuilder {
- @Override
- public LispMessage build() {
- return null;
- }
+ private long nonce;
+ private short keyId;
+ private byte[] authenticationData;
+ private byte recordCount;
+ private List<LispMapRecord> mapRecords = Lists.newArrayList();
@Override
public LispType getType() {
- return null;
+ return LispType.LISP_MAP_NOTIFY;
}
@Override
public NotifyBuilder withNonce(long nonce) {
- return null;
+ this.nonce = nonce;
+ return this;
}
@Override
public NotifyBuilder withRecordCount(byte recordCount) {
- return null;
+ this.recordCount = recordCount;
+ return this;
}
@Override
public NotifyBuilder withKeyId(short keyId) {
- return null;
+ this.keyId = keyId;
+ return this;
}
@Override
public NotifyBuilder withAuthenticationData(byte[] authenticationData) {
- return null;
+ this.authenticationData = authenticationData;
+ return this;
}
@Override
public NotifyBuilder addRecord(LispMapRecord record) {
- return null;
+ this.mapRecords.add(record);
+ return this;
+ }
+
+ @Override
+ public LispMessage build() {
+ return new DefaultLispMapNotify(nonce, keyId, authenticationData,
+ recordCount, mapRecords);
}
}
}