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
Showing
5 changed files
with
40 additions
and
12 deletions
... | @@ -253,7 +253,6 @@ public final class DefaultLispMapNotify implements LispMapNotify { | ... | @@ -253,7 +253,6 @@ public final class DefaultLispMapNotify implements LispMapNotify { |
253 | */ | 253 | */ |
254 | public static final class NotifyWriter implements LispMessageWriter<LispMapNotify> { | 254 | public static final class NotifyWriter implements LispMessageWriter<LispMapNotify> { |
255 | 255 | ||
256 | - private static final int NOTIFY_MSG_TYPE = 4; | ||
257 | private static final int NOTIFY_SHIFT_BIT = 4; | 256 | private static final int NOTIFY_SHIFT_BIT = 4; |
258 | 257 | ||
259 | private static final int UNUSED_ZERO = 0; | 258 | private static final int UNUSED_ZERO = 0; |
... | @@ -262,7 +261,7 @@ public final class DefaultLispMapNotify implements LispMapNotify { | ... | @@ -262,7 +261,7 @@ public final class DefaultLispMapNotify implements LispMapNotify { |
262 | public void writeTo(ByteBuf byteBuf, LispMapNotify message) throws LispWriterException { | 261 | public void writeTo(ByteBuf byteBuf, LispMapNotify message) throws LispWriterException { |
263 | 262 | ||
264 | // specify LISP message type | 263 | // specify LISP message type |
265 | - byte msgType = (byte) (NOTIFY_MSG_TYPE << NOTIFY_SHIFT_BIT); | 264 | + byte msgType = (byte) (LispType.LISP_MAP_NOTIFY.getTypeCode() << NOTIFY_SHIFT_BIT); |
266 | byteBuf.writeByte(msgType); | 265 | byteBuf.writeByte(msgType); |
267 | 266 | ||
268 | // reserved field | 267 | // reserved field | ... | ... |
... | @@ -296,7 +296,6 @@ public final class DefaultLispMapRegister implements LispMapRegister { | ... | @@ -296,7 +296,6 @@ public final class DefaultLispMapRegister implements LispMapRegister { |
296 | */ | 296 | */ |
297 | public static class RegisterWriter implements LispMessageWriter<LispMapRegister> { | 297 | public static class RegisterWriter implements LispMessageWriter<LispMapRegister> { |
298 | 298 | ||
299 | - private static final int REGISTER_MSG_TYPE = 3; | ||
300 | private static final int REGISTER_SHIFT_BIT = 4; | 299 | private static final int REGISTER_SHIFT_BIT = 4; |
301 | 300 | ||
302 | private static final int PROXY_MAP_REPLY_SHIFT_BIT = 3; | 301 | private static final int PROXY_MAP_REPLY_SHIFT_BIT = 3; |
... | @@ -310,7 +309,7 @@ public final class DefaultLispMapRegister implements LispMapRegister { | ... | @@ -310,7 +309,7 @@ public final class DefaultLispMapRegister implements LispMapRegister { |
310 | public void writeTo(ByteBuf byteBuf, LispMapRegister message) throws LispWriterException { | 309 | public void writeTo(ByteBuf byteBuf, LispMapRegister message) throws LispWriterException { |
311 | 310 | ||
312 | // specify LISP message type | 311 | // specify LISP message type |
313 | - byte msgType = (byte) (REGISTER_MSG_TYPE << REGISTER_SHIFT_BIT); | 312 | + byte msgType = (byte) (LispType.LISP_MAP_REGISTER.getTypeCode() << REGISTER_SHIFT_BIT); |
314 | 313 | ||
315 | // proxy map reply flag | 314 | // proxy map reply flag |
316 | byte proxyMapReply = DISABLE_BIT; | 315 | byte proxyMapReply = DISABLE_BIT; | ... | ... |
... | @@ -242,7 +242,6 @@ public final class DefaultLispMapReply implements LispMapReply { | ... | @@ -242,7 +242,6 @@ public final class DefaultLispMapReply implements LispMapReply { |
242 | */ | 242 | */ |
243 | public static final class ReplyWriter implements LispMessageWriter<LispMapReply> { | 243 | public static final class ReplyWriter implements LispMessageWriter<LispMapReply> { |
244 | 244 | ||
245 | - private static final int REPLY_MSG_TYPE = 2; | ||
246 | private static final int REPLY_SHIFT_BIT = 4; | 245 | private static final int REPLY_SHIFT_BIT = 4; |
247 | 246 | ||
248 | private static final int PROBE_FLAG_SHIFT_BIT = 3; | 247 | private static final int PROBE_FLAG_SHIFT_BIT = 3; |
... | @@ -258,7 +257,7 @@ public final class DefaultLispMapReply implements LispMapReply { | ... | @@ -258,7 +257,7 @@ public final class DefaultLispMapReply implements LispMapReply { |
258 | public void writeTo(ByteBuf byteBuf, LispMapReply message) throws LispWriterException { | 257 | public void writeTo(ByteBuf byteBuf, LispMapReply message) throws LispWriterException { |
259 | 258 | ||
260 | // specify LISP message type | 259 | // specify LISP message type |
261 | - byte msgType = (byte) (REPLY_MSG_TYPE << REPLY_SHIFT_BIT); | 260 | + byte msgType = (byte) (LispType.LISP_MAP_REPLY.getTypeCode() << REPLY_SHIFT_BIT); |
262 | 261 | ||
263 | // probe flag | 262 | // probe flag |
264 | byte probe = DISABLE_BIT; | 263 | byte probe = DISABLE_BIT; | ... | ... |
... | @@ -369,7 +369,6 @@ public final class DefaultLispMapRequest implements LispMapRequest { | ... | @@ -369,7 +369,6 @@ public final class DefaultLispMapRequest implements LispMapRequest { |
369 | */ | 369 | */ |
370 | public static final class RequestWriter implements LispMessageWriter<LispMapRequest> { | 370 | public static final class RequestWriter implements LispMessageWriter<LispMapRequest> { |
371 | 371 | ||
372 | - private static final int REQUEST_MSG_TYPE = 1; | ||
373 | private static final int REQUEST_SHIFT_BIT = 4; | 372 | private static final int REQUEST_SHIFT_BIT = 4; |
374 | 373 | ||
375 | private static final int AUTHORITATIVE_SHIFT_BIT = 3; | 374 | private static final int AUTHORITATIVE_SHIFT_BIT = 3; |
... | @@ -386,7 +385,7 @@ public final class DefaultLispMapRequest implements LispMapRequest { | ... | @@ -386,7 +385,7 @@ public final class DefaultLispMapRequest implements LispMapRequest { |
386 | public void writeTo(ByteBuf byteBuf, LispMapRequest message) throws LispWriterException { | 385 | public void writeTo(ByteBuf byteBuf, LispMapRequest message) throws LispWriterException { |
387 | 386 | ||
388 | // specify LISP message type | 387 | // specify LISP message type |
389 | - byte msgType = (byte) (REQUEST_MSG_TYPE << REQUEST_SHIFT_BIT); | 388 | + byte msgType = (byte) (LispType.LISP_MAP_REQUEST.getTypeCode() << REQUEST_SHIFT_BIT); |
390 | 389 | ||
391 | // authoritative flag | 390 | // authoritative flag |
392 | byte authoritative = DISABLE_BIT; | 391 | byte authoritative = DISABLE_BIT; | ... | ... |
... | @@ -22,8 +22,40 @@ package org.onosproject.lisp.msg.protocols; | ... | @@ -22,8 +22,40 @@ package org.onosproject.lisp.msg.protocols; |
22 | * https://tools.ietf.org/html/rfc6830 | 22 | * https://tools.ietf.org/html/rfc6830 |
23 | */ | 23 | */ |
24 | public enum LispType { | 24 | public enum LispType { |
25 | - LISP_MAP_REGISTER, // LISP Map-Register Message | 25 | + |
26 | - LISP_MAP_NOTIFY, // LISP Map-Notify Message | 26 | + LISP_MAP_REQUEST(1), // LISP Map-Request Message |
27 | - LISP_MAP_REQUEST, // LISP Map-Request Message | 27 | + LISP_MAP_REPLY(2), // LISP Map-Reply Message |
28 | - LISP_MAP_REPLY // LISP Map-Reply Message | 28 | + LISP_MAP_REGISTER(3), // LISP Map-Register Message |
29 | + LISP_MAP_NOTIFY(4), // LISP Map-Notify Message | ||
30 | + UNKNOWN(-1); // Other Enums for internal use | ||
31 | + | ||
32 | + private final short type; | ||
33 | + | ||
34 | + LispType(int type) { | ||
35 | + this.type = (short) type; | ||
36 | + } | ||
37 | + | ||
38 | + /** | ||
39 | + * Obtains LISP type code value. | ||
40 | + * | ||
41 | + * @return LISP type code value | ||
42 | + */ | ||
43 | + public short getTypeCode() { | ||
44 | + return type; | ||
45 | + } | ||
46 | + | ||
47 | + /** | ||
48 | + * Obtains LISP type enum by providing type code value. | ||
49 | + * | ||
50 | + * @param typeCode LISP type code value | ||
51 | + * @return LISP type enum | ||
52 | + */ | ||
53 | + public static LispType valueOf(short typeCode) { | ||
54 | + for (LispType val : values()) { | ||
55 | + if (val.getTypeCode() == typeCode) { | ||
56 | + return val; | ||
57 | + } | ||
58 | + } | ||
59 | + return UNKNOWN; | ||
60 | + } | ||
29 | } | 61 | } | ... | ... |
-
Please register or login to post a comment