Kiran Ramachandra | c92a122 | 2016-03-30 13:05:31 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Kiran Ramachandra | c92a122 | 2016-03-30 13:05:31 +0530 | [diff] [blame] | 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 | */ |
Kiran Ramachandra | c92a122 | 2016-03-30 13:05:31 +0530 | [diff] [blame] | 16 | package org.onosproject.isis.controller; |
| 17 | |
mohamed rahil | 8ea09d4 | 2016-04-19 20:47:21 +0530 | [diff] [blame] | 18 | import java.util.EnumSet; |
| 19 | import java.util.HashMap; |
| 20 | import java.util.Map; |
| 21 | |
Kiran Ramachandra | c92a122 | 2016-03-30 13:05:31 +0530 | [diff] [blame] | 22 | /** |
| 23 | * Representation of ISIS PDU types. |
| 24 | */ |
| 25 | public enum IsisPduType { |
| 26 | |
| 27 | /** |
| 28 | * Represents Level-1 LAN hello packet. |
| 29 | */ |
| 30 | L1HELLOPDU(15), |
| 31 | /** |
| 32 | * Represents Level-2 LAN hello packet. |
| 33 | */ |
| 34 | L2HELLOPDU(16), |
| 35 | /** |
| 36 | * Represents point-to-point hello packet. |
| 37 | */ |
| 38 | P2PHELLOPDU(17), |
| 39 | /** |
| 40 | * Represents Level-1 link state packet. |
| 41 | */ |
| 42 | L1LSPDU(18), |
| 43 | /** |
| 44 | * Represents Level-2 link state packet. |
| 45 | */ |
| 46 | L2LSPDU(20), |
| 47 | /** |
| 48 | * Represents Level-1 complete sequence number packet. |
| 49 | */ |
| 50 | L1CSNP(24), |
| 51 | /** |
| 52 | * Represents Level-2 complete sequence number packet. |
| 53 | */ |
| 54 | L2CSNP(25), |
| 55 | /** |
| 56 | * Represents Level-1 partial sequence number packet. |
| 57 | */ |
| 58 | L1PSNP(26), |
| 59 | /** |
| 60 | * Represents Level-2 partial sequence number packet. |
| 61 | */ |
| 62 | L2PSNP(27); |
| 63 | |
mohamed rahil | 8ea09d4 | 2016-04-19 20:47:21 +0530 | [diff] [blame] | 64 | // Reverse lookup table |
| 65 | private static final Map<Integer, IsisPduType> LOOKUP = new HashMap<>(); |
Kiran Ramachandra | c92a122 | 2016-03-30 13:05:31 +0530 | [diff] [blame] | 66 | |
mohamed rahil | 8ea09d4 | 2016-04-19 20:47:21 +0530 | [diff] [blame] | 67 | // Populate the lookup table on loading time |
| 68 | static { |
| 69 | for (IsisPduType isisPduType : EnumSet.allOf(IsisPduType.class)) { |
| 70 | LOOKUP.put(isisPduType.value(), isisPduType); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | private int value; |
Kiran Ramachandra | c92a122 | 2016-03-30 13:05:31 +0530 | [diff] [blame] | 75 | |
| 76 | /** |
| 77 | * Creates an instance of ISIS PDU type. |
| 78 | * |
| 79 | * @param value represents ISIS PDU type |
| 80 | */ |
| 81 | private IsisPduType(int value) { |
| 82 | this.value = value; |
| 83 | } |
| 84 | |
| 85 | /** |
mohamed rahil | 8ea09d4 | 2016-04-19 20:47:21 +0530 | [diff] [blame] | 86 | * Gets the enum instance from type value - reverse lookup purpose. |
| 87 | * |
| 88 | * @param pduTypeValue PDU type value |
| 89 | * @return ISIS PDU type instance |
| 90 | */ |
| 91 | public static IsisPduType get(int pduTypeValue) { |
| 92 | return LOOKUP.get(pduTypeValue); |
| 93 | } |
| 94 | |
| 95 | /** |
Kiran Ramachandra | c92a122 | 2016-03-30 13:05:31 +0530 | [diff] [blame] | 96 | * Gets the value representing PDU type. |
| 97 | * |
| 98 | * @return value represents PDU type |
| 99 | */ |
| 100 | public int value() { |
| 101 | return value; |
| 102 | } |
| 103 | } |