sunishvk | a1dfc3e | 2016-04-16 12:24:47 +0530 | [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.isis.io.isispacket.tlv.subtlv; |
| 17 | |
| 18 | import java.util.EnumSet; |
| 19 | import java.util.HashMap; |
| 20 | import java.util.Map; |
| 21 | |
| 22 | /** |
| 23 | * Representation of sub tlv type. |
| 24 | */ |
| 25 | public enum SubTlvType { |
| 26 | ADMINISTRATIVEGROUP(9), |
| 27 | MAXIMUMBANDWIDTH(6), |
| 28 | MAXIMUMRESERVABLEBANDWIDTH(7), |
| 29 | TRAFFICENGINEERINGMETRIC(5), |
| 30 | UNRESERVEDBANDWIDTH(8); |
| 31 | |
| 32 | // Reverse lookup table |
| 33 | private static final Map<Integer, SubTlvType> LOOKUP = new HashMap<>(); |
| 34 | |
| 35 | // Populate the lookup table on loading time |
| 36 | static { |
| 37 | for (SubTlvType subTlvType : EnumSet.allOf(SubTlvType.class)) { |
| 38 | LOOKUP.put(subTlvType.value(), subTlvType); |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | private int value; |
| 43 | |
| 44 | /** |
| 45 | * Sets the sub TLV type value. |
| 46 | * |
| 47 | * @param value value. |
| 48 | */ |
| 49 | SubTlvType(int value) { |
| 50 | this.value = value; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Gets the enum instance from type value - reverse lookup purpose. |
| 55 | * |
| 56 | * @param subTlvTypeValue TLV type value |
| 57 | * @return ISIS sub TLV type instance |
| 58 | */ |
| 59 | public static SubTlvType get(int subTlvTypeValue) { |
| 60 | return LOOKUP.get(subTlvTypeValue); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Gets value. |
| 65 | * |
| 66 | * @return value |
| 67 | */ |
| 68 | public int value() { |
| 69 | return value; |
| 70 | } |
| 71 | } |