Konstantinos Kanonakis | 0a9031d | 2016-09-22 11:35:11 -0500 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Konstantinos Kanonakis | 0a9031d | 2016-09-22 11:35:11 -0500 | [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 | */ |
| 16 | package org.onlab.packet; |
| 17 | |
| 18 | /** |
| 19 | * Represents the deprecated IPv4 IP precedence. |
| 20 | * IP precedence occupied the 3 most-significant bits of the IPv4 ToS field |
| 21 | */ |
| 22 | public enum IPPrecedence { |
| 23 | |
| 24 | BEST_EFFORT((short) 0b000), |
| 25 | PRIORITY((short) 0b001), |
| 26 | IMMEDIATE((short) 0b010), |
| 27 | FLASH((short) 0b011), |
| 28 | FLASH_OVERRIDE((short) 0b100), |
| 29 | CRITICAL((short) 0b101), |
| 30 | INTERNETWORK_CONTROL((short) 0b110), |
| 31 | NETWORK_CONTROL((short) 0b111); |
| 32 | |
| 33 | private short value; |
| 34 | |
| 35 | IPPrecedence(short value) { |
| 36 | this.value = value; |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Returns the IP precedence Enum corresponding to the specified short. |
| 41 | * |
| 42 | * @param value the short value of the IP precedence |
| 43 | * @return the IP precedence Enum corresponding to the specified short |
| 44 | * @throws IllegalArgumentException if the short provided does not correspond to an IP precedence Enum value |
| 45 | */ |
| 46 | public static IPPrecedence fromShort(short value) { |
| 47 | for (IPPrecedence b : IPPrecedence.values()) { |
| 48 | if (value == b.value) { |
| 49 | return b; |
| 50 | } |
| 51 | } |
| 52 | throw new IllegalArgumentException("IP precedence " + value + " is not valid"); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Returns the short value of this IP precedence Enum. |
| 57 | * |
| 58 | * @return the short value of this IP precedence Enum |
| 59 | */ |
| 60 | public short getValue() { |
| 61 | return value; |
| 62 | } |
| 63 | } |