Jian Li
Committed by Gerrit Code Review

Add type code into LispType enum to prevent arbitrary place holder

With the existing implementation, if we want to specify type value
8 to ECM Lisp type, we need to generate several place holders
inside LispType enumerator, otherwise ECM will be assigned a
subsequent number which is 5.
With this commit, we can specify arbitrary number for each Lisp
enum type, therefore, no need to add redundant placeholder for
the purpose of incrementing enum value.

Change-Id: I82a82a3f5bc313dc1f79aaa66a77889408e8c891
......@@ -253,7 +253,6 @@ public final class DefaultLispMapNotify implements LispMapNotify {
*/
public static final class NotifyWriter implements LispMessageWriter<LispMapNotify> {
private static final int NOTIFY_MSG_TYPE = 4;
private static final int NOTIFY_SHIFT_BIT = 4;
private static final int UNUSED_ZERO = 0;
......@@ -262,7 +261,7 @@ public final class DefaultLispMapNotify implements LispMapNotify {
public void writeTo(ByteBuf byteBuf, LispMapNotify message) throws LispWriterException {
// specify LISP message type
byte msgType = (byte) (NOTIFY_MSG_TYPE << NOTIFY_SHIFT_BIT);
byte msgType = (byte) (LispType.LISP_MAP_NOTIFY.getTypeCode() << NOTIFY_SHIFT_BIT);
byteBuf.writeByte(msgType);
// reserved field
......
......@@ -296,7 +296,6 @@ public final class DefaultLispMapRegister implements LispMapRegister {
*/
public static class RegisterWriter implements LispMessageWriter<LispMapRegister> {
private static final int REGISTER_MSG_TYPE = 3;
private static final int REGISTER_SHIFT_BIT = 4;
private static final int PROXY_MAP_REPLY_SHIFT_BIT = 3;
......@@ -310,7 +309,7 @@ public final class DefaultLispMapRegister implements LispMapRegister {
public void writeTo(ByteBuf byteBuf, LispMapRegister message) throws LispWriterException {
// specify LISP message type
byte msgType = (byte) (REGISTER_MSG_TYPE << REGISTER_SHIFT_BIT);
byte msgType = (byte) (LispType.LISP_MAP_REGISTER.getTypeCode() << REGISTER_SHIFT_BIT);
// proxy map reply flag
byte proxyMapReply = DISABLE_BIT;
......
......@@ -242,7 +242,6 @@ public final class DefaultLispMapReply implements LispMapReply {
*/
public static final class ReplyWriter implements LispMessageWriter<LispMapReply> {
private static final int REPLY_MSG_TYPE = 2;
private static final int REPLY_SHIFT_BIT = 4;
private static final int PROBE_FLAG_SHIFT_BIT = 3;
......@@ -258,7 +257,7 @@ public final class DefaultLispMapReply implements LispMapReply {
public void writeTo(ByteBuf byteBuf, LispMapReply message) throws LispWriterException {
// specify LISP message type
byte msgType = (byte) (REPLY_MSG_TYPE << REPLY_SHIFT_BIT);
byte msgType = (byte) (LispType.LISP_MAP_REPLY.getTypeCode() << REPLY_SHIFT_BIT);
// probe flag
byte probe = DISABLE_BIT;
......
......@@ -369,7 +369,6 @@ public final class DefaultLispMapRequest implements LispMapRequest {
*/
public static final class RequestWriter implements LispMessageWriter<LispMapRequest> {
private static final int REQUEST_MSG_TYPE = 1;
private static final int REQUEST_SHIFT_BIT = 4;
private static final int AUTHORITATIVE_SHIFT_BIT = 3;
......@@ -386,7 +385,7 @@ public final class DefaultLispMapRequest implements LispMapRequest {
public void writeTo(ByteBuf byteBuf, LispMapRequest message) throws LispWriterException {
// specify LISP message type
byte msgType = (byte) (REQUEST_MSG_TYPE << REQUEST_SHIFT_BIT);
byte msgType = (byte) (LispType.LISP_MAP_REQUEST.getTypeCode() << REQUEST_SHIFT_BIT);
// authoritative flag
byte authoritative = DISABLE_BIT;
......
......@@ -22,8 +22,40 @@ package org.onosproject.lisp.msg.protocols;
* https://tools.ietf.org/html/rfc6830
*/
public enum LispType {
LISP_MAP_REGISTER, // LISP Map-Register Message
LISP_MAP_NOTIFY, // LISP Map-Notify Message
LISP_MAP_REQUEST, // LISP Map-Request Message
LISP_MAP_REPLY // LISP Map-Reply Message
LISP_MAP_REQUEST(1), // LISP Map-Request Message
LISP_MAP_REPLY(2), // LISP Map-Reply Message
LISP_MAP_REGISTER(3), // LISP Map-Register Message
LISP_MAP_NOTIFY(4), // LISP Map-Notify Message
UNKNOWN(-1); // Other Enums for internal use
private final short type;
LispType(int type) {
this.type = (short) type;
}
/**
* Obtains LISP type code value.
*
* @return LISP type code value
*/
public short getTypeCode() {
return type;
}
/**
* Obtains LISP type enum by providing type code value.
*
* @param typeCode LISP type code value
* @return LISP type enum
*/
public static LispType valueOf(short typeCode) {
for (LispType val : values()) {
if (val.getTypeCode() == typeCode) {
return val;
}
}
return UNKNOWN;
}
}
......