[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);
}
}
}
diff --git a/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/protocols/DefaultLispMapRegister.java b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/protocols/DefaultLispMapRegister.java
index 1b2987e..f041d2b 100644
--- a/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/protocols/DefaultLispMapRegister.java
+++ b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/protocols/DefaultLispMapRegister.java
@@ -15,22 +15,58 @@
*/
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 register message class.
*/
-public class DefaultLispMapRegister implements LispMapRegister {
+public final class DefaultLispMapRegister implements LispMapRegister {
+
+ private final long nonce;
+ private final short keyId;
+ private final byte[] authenticationData;
+ private final byte recordCount;
+ private final List<LispMapRecord> mapRecords;
+ private final boolean proxyMapReply;
+ private final boolean wantMapNotify;
+
+ /**
+ * 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
+ * @param proxyMapReply proxy map reply flag
+ * @param wantMapNotify want map notify flag
+ */
+ private DefaultLispMapRegister(long nonce, short keyId,
+ byte[] authenticationData, byte recordCount,
+ List<LispMapRecord> mapRecords,
+ boolean proxyMapReply, boolean wantMapNotify) {
+ this.nonce = nonce;
+ this.keyId = keyId;
+ this.authenticationData = authenticationData;
+ this.recordCount = recordCount;
+ this.mapRecords = mapRecords;
+ this.proxyMapReply = proxyMapReply;
+ this.wantMapNotify = wantMapNotify;
+ }
+
@Override
public LispType getType() {
- return null;
+ return LispType.LISP_MAP_REGISTER;
}
@Override
public void writeTo(ByteBuf byteBuf) {
-
+ // TODO: serialize LispMapRegister message
}
@Override
@@ -40,84 +76,100 @@
@Override
public boolean isProxyMapReply() {
- return false;
+ return proxyMapReply;
}
@Override
public boolean isWantMapNotify() {
- return false;
+ return wantMapNotify;
}
@Override
public byte getRecordCount() {
- return 0;
+ return recordCount;
}
@Override
public long getNonce() {
- return 0;
+ return nonce;
}
@Override
public short getKeyId() {
- return 0;
+ return 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 DefaultRegisterBuilder implements RegisterBuilder {
- @Override
- public LispMessage build() {
- return null;
- }
+ private long nonce;
+ private short keyId;
+ private byte[] authenticationData;
+ private byte recordCount;
+ private final List<LispMapRecord> mapRecords = Lists.newArrayList();
+ private boolean proxyMapReply;
+ private boolean wantMapNotify;
@Override
public LispType getType() {
- return null;
+ return LispType.LISP_MAP_REGISTER;
}
@Override
- public RegisterBuilder withIsProxyMapReply(boolean isProxyMapReply) {
- return null;
+ public RegisterBuilder withIsProxyMapReply(boolean proxyMapReply) {
+ this.proxyMapReply = proxyMapReply;
+ return this;
}
@Override
- public RegisterBuilder withIsWantMapNotify(boolean isWantMapNotify) {
- return null;
+ public RegisterBuilder withIsWantMapNotify(boolean wantMapNotify) {
+ this.wantMapNotify = wantMapNotify;
+ return this;
}
@Override
public RegisterBuilder withRecordCount(byte recordCount) {
- return null;
+ this.recordCount = recordCount;
+ return this;
}
@Override
public RegisterBuilder withNonce(long nonce) {
- return null;
+ this.nonce = nonce;
+ return this;
}
@Override
public RegisterBuilder withKeyId(short keyId) {
- return null;
+ this.keyId = keyId;
+ return this;
}
@Override
public RegisterBuilder withAuthenticationData(byte[] authenticationData) {
- return null;
+ this.authenticationData = authenticationData;
+ return this;
}
@Override
public RegisterBuilder addRecord(LispMapRecord record) {
- return null;
+ this.mapRecords.add(record);
+ return this;
+ }
+
+ @Override
+ public LispMessage build() {
+ return new DefaultLispMapRegister(nonce, keyId, authenticationData,
+ recordCount, mapRecords, proxyMapReply, wantMapNotify);
}
}
}
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 7f89dc0..94322e1 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
@@ -20,15 +20,40 @@
/**
* Default LISP map reply message class.
*/
-public class DefaultLispMapReply implements LispMapReply {
+public final class DefaultLispMapReply implements LispMapReply {
+
+ private final long nonce;
+ private final byte recordCount;
+ private final boolean probe;
+ private final boolean etr;
+ private final boolean security;
+
+ /**
+ * A private constructor that protects object instantiation from external.
+ *
+ * @param nonce nonce
+ * @param recordCount record count number
+ * @param probe probe flag
+ * @param etr etr flag
+ * @param security security flag
+ */
+ private DefaultLispMapReply(long nonce, byte recordCount, boolean probe,
+ boolean etr, boolean security) {
+ this.nonce = nonce;
+ this.recordCount = recordCount;
+ this.probe = probe;
+ this.etr = etr;
+ this.security = security;
+ }
+
@Override
public LispType getType() {
- return null;
+ return LispType.LISP_MAP_REPLY;
}
@Override
public void writeTo(ByteBuf byteBuf) {
-
+ // TODO: serialize LispMapReply message
}
@Override
@@ -38,64 +63,75 @@
@Override
public boolean isProbe() {
- return false;
+ return this.probe;
}
@Override
public boolean isEtr() {
- return false;
+ return this.etr;
}
@Override
public boolean isSecurity() {
- return false;
+ return this.security;
}
@Override
public byte getRecordCount() {
- return 0;
+ return this.recordCount;
}
@Override
public long getNonce() {
- return 0;
+ return this.nonce;
}
public static final class DefaultReplyBuilder implements ReplyBuilder {
- @Override
- public LispMessage build() {
- return null;
- }
+ private long nonce;
+ private byte recordCount;
+ private boolean probe;
+ private boolean etr;
+ private boolean security;
@Override
public LispType getType() {
- return null;
+ return LispType.LISP_MAP_REPLY;
}
@Override
- public ReplyBuilder withIsProbe(boolean isProbe) {
- return null;
+ public ReplyBuilder withIsProbe(boolean probe) {
+ this.probe = probe;
+ return this;
}
@Override
- public ReplyBuilder withIsEtr(boolean isEtr) {
- return null;
+ public ReplyBuilder withIsEtr(boolean etr) {
+ this.etr = etr;
+ return this;
}
@Override
- public ReplyBuilder withIsSecurity(boolean isSecurity) {
- return null;
+ public ReplyBuilder withIsSecurity(boolean security) {
+ this.security = security;
+ return this;
}
@Override
public ReplyBuilder withRecordCount(byte recordCount) {
- return null;
+ this.recordCount = recordCount;
+ return this;
}
@Override
public ReplyBuilder withNonce(long nonce) {
- return null;
+ this.nonce = nonce;
+ return this;
+ }
+
+ @Override
+ public LispMessage build() {
+ return new DefaultLispMapReply(nonce, recordCount, probe, etr, security);
}
}
}
diff --git a/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/protocols/DefaultLispMapRequest.java b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/protocols/DefaultLispMapRequest.java
index ab109d1..313f926 100644
--- a/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/protocols/DefaultLispMapRequest.java
+++ b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/protocols/DefaultLispMapRequest.java
@@ -15,6 +15,8 @@
*/
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.onosproject.lisp.msg.types.LispAfiAddress;
@@ -23,15 +25,60 @@
/**
* Default LISP map request message class.
*/
-public class DefaultLispMapRequest implements LispMapRequest {
+public final class DefaultLispMapRequest implements LispMapRequest {
+
+ private final long nonce;
+ private final byte recordCount;
+ private final LispAfiAddress sourceEid;
+ private final List<LispAfiAddress> itrRlocs;
+ private final List<LispEidRecord> eidRecords;
+ private final boolean authoritative;
+ private final boolean mapDataPresent;
+ private final boolean probe;
+ private final boolean smr;
+ private final boolean pitr;
+ private final boolean smrInvoked;
+
+ /**
+ * A private constructor that protects object instantiation from external.
+ *
+ * @param nonce nonce
+ * @param recordCount record count number
+ * @param sourceEid source EID address
+ * @param itrRlocs a collection of ITR RLOCs
+ * @param eidRecords a collection of EID records
+ * @param authoritative authoritative flag
+ * @param mapDataPresent map data present flag
+ * @param probe probe flag
+ * @param smr smr flag
+ * @param pitr pitr flag
+ * @param smrInvoked smrInvoked flag
+ */
+ private DefaultLispMapRequest(long nonce, byte recordCount, LispAfiAddress sourceEid,
+ List<LispAfiAddress> itrRlocs, List<LispEidRecord> eidRecords,
+ boolean authoritative, boolean mapDataPresent, boolean probe,
+ boolean smr, boolean pitr, boolean smrInvoked) {
+ this.nonce = nonce;
+ this.recordCount = recordCount;
+ this.sourceEid = sourceEid;
+ this.itrRlocs = itrRlocs;
+ this.eidRecords = eidRecords;
+ this.authoritative = authoritative;
+ this.mapDataPresent = mapDataPresent;
+ this.probe = probe;
+ this.smr = smr;
+ this.pitr = pitr;
+ this.smrInvoked = smrInvoked;
+ }
+
@Override
public LispType getType() {
- return null;
+ return LispType.LISP_MAP_REQUEST;
}
@Override
public void writeTo(ByteBuf byteBuf) {
-
+ // TODO: serialize LispMapRequest message
}
@Override
@@ -41,109 +88,149 @@
@Override
public boolean isAuthoritative() {
- return false;
+ return this.authoritative;
+ }
+
+ @Override
+ public boolean isMapDataPresent() {
+ return this.mapDataPresent;
}
@Override
public boolean isProbe() {
- return false;
+ return this.probe;
}
@Override
public boolean isSmr() {
- return false;
+ return this.smr;
}
@Override
public boolean isPitr() {
- return false;
+ return this.pitr;
}
@Override
public boolean isSmrInvoked() {
- return false;
+ return this.smrInvoked;
}
@Override
public byte getRecordCount() {
- return 0;
+ return this.recordCount;
}
@Override
public long getNonce() {
- return 0;
+ return this.nonce;
}
@Override
public LispAfiAddress getSourceEid() {
- return null;
+ return this.sourceEid;
}
@Override
public List<LispAfiAddress> getItrRlocs() {
- return null;
+ return ImmutableList.copyOf(itrRlocs);
}
@Override
public List<LispEidRecord> getEids() {
- return null;
+ return ImmutableList.copyOf(eidRecords);
}
public static final class DefaultRequestBuilder implements RequestBuilder {
- @Override
- public LispMessage build() {
- return null;
- }
+ private long nonce;
+ private byte recordCount;
+ private LispAfiAddress sourceEid;
+ private List<LispAfiAddress> itrRlocs = Lists.newArrayList();
+ private List<LispEidRecord> eidRecords = Lists.newArrayList();
+ private boolean authoritative;
+ private boolean mapDataPresent;
+ private boolean probe;
+ private boolean smr;
+ private boolean pitr;
+ private boolean smrInvoked;
@Override
public LispType getType() {
- return null;
+ return LispType.LISP_MAP_REQUEST;
}
@Override
- public RequestBuilder withIsAuthoritative(boolean isAuthoritative) {
- return null;
+ public RequestBuilder withIsAuthoritative(boolean authoritative) {
+ this.authoritative = authoritative;
+ return this;
}
@Override
- public RequestBuilder withIsProbe(boolean isProbe) {
- return null;
+ public RequestBuilder withIsProbe(boolean probe) {
+ this.probe = probe;
+ return this;
}
@Override
- public RequestBuilder withIsSmr(boolean isSmr) {
- return null;
+ public RequestBuilder withIsMapDataPresent(boolean mapDataPresent) {
+ this.mapDataPresent = mapDataPresent;
+ return this;
+ }
+
+
+ @Override
+ public RequestBuilder withIsSmr(boolean smr) {
+ this.smr = smr;
+ return this;
}
@Override
- public RequestBuilder withIsPitr(boolean isPitr) {
- return null;
+ public RequestBuilder withIsPitr(boolean pitr) {
+ this.pitr = pitr;
+ return this;
}
@Override
- public RequestBuilder withIsSmrInvoked(boolean isSmrInvoked) {
- return null;
+ public RequestBuilder withIsSmrInvoked(boolean smrInvoked) {
+ this.smrInvoked = smrInvoked;
+ return this;
}
@Override
public RequestBuilder withRecordCount(byte recordCount) {
- return null;
+ this.recordCount = recordCount;
+ return this;
}
@Override
public RequestBuilder withNonce(long nonce) {
- return null;
+ this.nonce = nonce;
+ return this;
}
@Override
- public RequestBuilder withItrRloc(LispAfiAddress itrRloc) {
- return null;
+ public RequestBuilder withSourceEid(LispAfiAddress sourceEid) {
+ this.sourceEid = sourceEid;
+ return this;
+ }
+
+ @Override
+ public RequestBuilder addItrRloc(LispAfiAddress itrRloc) {
+ this.itrRlocs.add(itrRloc);
+ return this;
}
@Override
public RequestBuilder addEidRecord(LispEidRecord record) {
- return null;
+ this.eidRecords.add(record);
+ return this;
+ }
+
+ @Override
+ public LispMessage build() {
+ return new DefaultLispMapRequest(nonce, recordCount, sourceEid, itrRlocs,
+ eidRecords, authoritative, mapDataPresent, probe, smr, pitr, smrInvoked);
}
}
}
diff --git a/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/protocols/LispMapReply.java b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/protocols/LispMapReply.java
index 13a5b5e..a128814 100644
--- a/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/protocols/LispMapReply.java
+++ b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/protocols/LispMapReply.java
@@ -91,28 +91,28 @@
interface ReplyBuilder extends Builder {
/**
- * Sets isProbe flag.
+ * Sets probe flag.
*
- * @param isProbe isProbe flag
+ * @param probe probe flag
* @return ReplyBuilder object
*/
- ReplyBuilder withIsProbe(boolean isProbe);
+ ReplyBuilder withIsProbe(boolean probe);
/**
- * Sets isEtr flag.
+ * Sets etr flag.
*
- * @param isEtr isEtr flag
+ * @param etr etr flag
* @return ReplyBuilder object
*/
- ReplyBuilder withIsEtr(boolean isEtr);
+ ReplyBuilder withIsEtr(boolean etr);
/**
- * Sets isSecurity flag.
+ * Sets security flag.
*
- * @param isSecurity isSecurity flag
+ * @param security security flag
* @return ReplyBuilder object
*/
- ReplyBuilder withIsSecurity(boolean isSecurity);
+ ReplyBuilder withIsSecurity(boolean security);
/**
* Sets record count.
diff --git a/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/protocols/LispMapRequest.java b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/protocols/LispMapRequest.java
index f0a49e8..0783368 100644
--- a/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/protocols/LispMapRequest.java
+++ b/protocols/lisp/msg/src/main/java/org/onosproject/lisp/msg/protocols/LispMapRequest.java
@@ -21,12 +21,13 @@
/**
* LISP map request message interface.
- *
+ * <p>
* LISP map request message format is defined in RFC6830.
* https://tools.ietf.org/html/rfc6830#page-27
*
* <pre>
* {@literal
+ * <p>
* 0 1 2 3
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
@@ -62,6 +63,13 @@
boolean isAuthoritative();
/**
+ * Obtains map data present flag.
+ *
+ * @return map data present flag
+ */
+ boolean isMapDataPresent();
+
+ /**
* Obtains probe flag.
*
* @return probe flag
@@ -130,44 +138,52 @@
interface RequestBuilder extends Builder {
/**
- * Sets isAuthoritative flag.
+ * Sets authoritative flag.
*
- * @param isAuthoritative isAuthoritative flag
+ * @param authoritative authoritative flag
* @return RequestBuilder object
*/
- RequestBuilder withIsAuthoritative(boolean isAuthoritative);
+ RequestBuilder withIsAuthoritative(boolean authoritative);
/**
- * Sets isProbe flag.
+ * Sets probe flag.
*
- * @param isProbe isProbe flag
+ * @param probe probe flag
* @return RequestBuilder object
*/
- RequestBuilder withIsProbe(boolean isProbe);
+ RequestBuilder withIsProbe(boolean probe);
/**
- * Sets isSmr flag.
+ * Sets map data resent flag.
*
- * @param isSmr isSmr flag
+ * @param mapDataPresent map data present flag
* @return RequestBuilder object
*/
- RequestBuilder withIsSmr(boolean isSmr);
+ RequestBuilder withIsMapDataPresent(boolean mapDataPresent);
/**
- * Sets isPitr flag.
+ * Sets smr flag.
*
- * @param isPitr isPitr flag
+ * @param smr smr flag
* @return RequestBuilder object
*/
- RequestBuilder withIsPitr(boolean isPitr);
+ RequestBuilder withIsSmr(boolean smr);
/**
- * Sets isSmrInvoked flag.
+ * Sets pitr flag.
*
- * @param isSmrInvoked isSmrInvoked flag
+ * @param pitr pitr flag
* @return RequestBuilder object
*/
- RequestBuilder withIsSmrInvoked(boolean isSmrInvoked);
+ RequestBuilder withIsPitr(boolean pitr);
+
+ /**
+ * Sets smrInvoked flag.
+ *
+ * @param smrInvoked smrInvoked flag
+ * @return RequestBuilder object
+ */
+ RequestBuilder withIsSmrInvoked(boolean smrInvoked);
/**
* Sets record count.
@@ -186,12 +202,20 @@
RequestBuilder withNonce(long nonce);
/**
+ * Sets source EID address.
+ *
+ * @param sourceEid source EID
+ * @return RequestBuilder object
+ */
+ RequestBuilder withSourceEid(LispAfiAddress sourceEid);
+
+ /**
* Adds ITR RLOC into RLOC collection.
*
* @param itrRloc ITR RLOC
* @return RequestBuilder object
*/
- RequestBuilder withItrRloc(LispAfiAddress itrRloc);
+ RequestBuilder addItrRloc(LispAfiAddress itrRloc);
/**
* Adds EID record into record collection.