Jian Li | cb1fca2 | 2016-07-19 18:34:25 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.lisp.msg.protocols; |
| 17 | |
| 18 | /** |
| 19 | * LISP message type enumeration. |
| 20 | * |
| 21 | * An enumeration of LISP Message type defined in RFC6830 |
| 22 | * https://tools.ietf.org/html/rfc6830 |
| 23 | */ |
| 24 | public enum LispType { |
Jian Li | cbc57e3 | 2016-09-14 09:06:54 +0900 | [diff] [blame] | 25 | |
| 26 | LISP_MAP_REQUEST(1), // LISP Map-Request Message |
| 27 | LISP_MAP_REPLY(2), // LISP Map-Reply Message |
| 28 | LISP_MAP_REGISTER(3), // LISP Map-Register Message |
| 29 | LISP_MAP_NOTIFY(4), // LISP Map-Notify Message |
Jian Li | 2775935 | 2016-10-04 20:14:42 +0900 | [diff] [blame] | 30 | LISP_INFO(7), // LISP Info-Request or Info-Reply Message |
Jian Li | cbc57e3 | 2016-09-14 09:06:54 +0900 | [diff] [blame] | 31 | UNKNOWN(-1); // Other Enums for internal use |
| 32 | |
| 33 | private final short type; |
| 34 | |
| 35 | LispType(int type) { |
| 36 | this.type = (short) type; |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Obtains LISP type code value. |
| 41 | * |
| 42 | * @return LISP type code value |
| 43 | */ |
| 44 | public short getTypeCode() { |
| 45 | return type; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Obtains LISP type enum by providing type code value. |
| 50 | * |
| 51 | * @param typeCode LISP type code value |
| 52 | * @return LISP type enum |
| 53 | */ |
| 54 | public static LispType valueOf(short typeCode) { |
| 55 | for (LispType val : values()) { |
| 56 | if (val.getTypeCode() == typeCode) { |
| 57 | return val; |
| 58 | } |
| 59 | } |
| 60 | return UNKNOWN; |
| 61 | } |
Jian Li | cb1fca2 | 2016-07-19 18:34:25 +0900 | [diff] [blame] | 62 | } |