Chidambar babu | 86b3b1a | 2016-02-16 17:39:52 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Chidambar babu | 86b3b1a | 2016-02-16 17:39:52 +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 | */ |
| 16 | package org.onosproject.ospf.protocol.util; |
| 17 | |
| 18 | /** |
| 19 | * Representation of an OSPF Interface states. |
| 20 | */ |
| 21 | public enum OspfInterfaceState { |
| 22 | |
| 23 | DOWN(1), |
| 24 | LOOPBACK(2), |
| 25 | WAITING(3), |
| 26 | POINT2POINT(4), |
| 27 | DROTHER(5), |
| 28 | BDR(6), |
| 29 | DR(7); |
| 30 | |
| 31 | private int value; |
| 32 | |
| 33 | /** |
sunishvk | f7c5655 | 2016-07-18 16:02:39 +0530 | [diff] [blame] | 34 | * Creates an instance of interface state. |
Chidambar babu | 86b3b1a | 2016-02-16 17:39:52 +0530 | [diff] [blame] | 35 | * |
sunishvk | f7c5655 | 2016-07-18 16:02:39 +0530 | [diff] [blame] | 36 | * @param value Interface state value |
Chidambar babu | 86b3b1a | 2016-02-16 17:39:52 +0530 | [diff] [blame] | 37 | */ |
| 38 | OspfInterfaceState(int value) { |
| 39 | this.value = value; |
| 40 | } |
| 41 | |
| 42 | /** |
sunishvk | f7c5655 | 2016-07-18 16:02:39 +0530 | [diff] [blame] | 43 | * Gets value for Interface state. |
Chidambar babu | 86b3b1a | 2016-02-16 17:39:52 +0530 | [diff] [blame] | 44 | * |
sunishvk | f7c5655 | 2016-07-18 16:02:39 +0530 | [diff] [blame] | 45 | * @return value Interface state |
Chidambar babu | 86b3b1a | 2016-02-16 17:39:52 +0530 | [diff] [blame] | 46 | */ |
| 47 | public int value() { |
| 48 | return value; |
| 49 | } |
sunishvk | f7c5655 | 2016-07-18 16:02:39 +0530 | [diff] [blame] | 50 | |
| 51 | /** |
| 52 | * Gets interface state. |
| 53 | * |
| 54 | * @return interface state |
| 55 | */ |
| 56 | public String interfaceState() { |
| 57 | String state = null; |
| 58 | switch (value) { |
| 59 | case 1: |
| 60 | state = "DOWN"; |
| 61 | break; |
| 62 | case 2: |
| 63 | state = "LOOPBACK"; |
| 64 | break; |
| 65 | case 3: |
| 66 | state = "WAITING"; |
| 67 | break; |
| 68 | case 4: |
| 69 | state = "POINT2POINT"; |
| 70 | break; |
| 71 | case 5: |
| 72 | state = "DROTHER"; |
| 73 | break; |
| 74 | case 6: |
| 75 | state = "BDR"; |
| 76 | break; |
| 77 | case 7: |
| 78 | state = "DR"; |
| 79 | break; |
| 80 | default: |
| 81 | break; |
| 82 | } |
| 83 | return state; |
| 84 | } |
Chidambar babu | 86b3b1a | 2016-02-16 17:39:52 +0530 | [diff] [blame] | 85 | } |