Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +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 | */ |
Priyanka B | 259847d | 2016-06-03 21:28:35 +0530 | [diff] [blame] | 16 | package org.onosproject.pcep.controller; |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 17 | |
| 18 | import org.onosproject.incubator.net.tunnel.Tunnel.State; |
| 19 | |
| 20 | /** |
| 21 | * Representation of the PCEP LSP state. |
| 22 | */ |
| 23 | public enum PcepLspStatus { |
| 24 | |
| 25 | /** |
| 26 | * Signifies that the LSP is not active. |
| 27 | */ |
| 28 | DOWN, |
| 29 | |
| 30 | /** |
| 31 | * Signifies that the LSP is signalled. |
| 32 | */ |
| 33 | UP, |
| 34 | |
| 35 | /** |
| 36 | * Signifies that the LSP is up and carrying traffic. |
| 37 | */ |
| 38 | ACTIVE, |
| 39 | |
| 40 | /** |
| 41 | * Signifies that the LSP is being torn down, resources are being released. |
| 42 | */ |
| 43 | GOING_DOWN, |
| 44 | |
| 45 | /** |
| 46 | * Signifies that the LSP is being signalled. |
| 47 | */ |
| 48 | GOING_UP; |
| 49 | |
| 50 | /** |
| 51 | * Returns the applicable PCEP LSP status corresponding to ONOS tunnel state. |
| 52 | * |
| 53 | * @param tunnelState ONOS tunnel state |
Avantika-Huawei | d1e36bd | 2016-05-26 12:47:16 +0530 | [diff] [blame] | 54 | * @return LSP status as per protocol |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 55 | */ |
| 56 | public static PcepLspStatus getLspStatusFromTunnelStatus(State tunnelState) { |
| 57 | |
| 58 | switch (tunnelState) { |
| 59 | |
| 60 | case INIT: |
| 61 | return PcepLspStatus.DOWN; |
| 62 | |
| 63 | case ESTABLISHED: |
| 64 | return PcepLspStatus.GOING_UP; |
| 65 | |
| 66 | case ACTIVE: |
| 67 | return PcepLspStatus.UP; |
| 68 | |
| 69 | case FAILED: // fall through |
| 70 | case INACTIVE: // LSP is administratively down. |
| 71 | default: |
| 72 | return PcepLspStatus.DOWN; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Returns the applicable ONOS tunnel state corresponding to PCEP LSP status. |
| 78 | * |
| 79 | * @param lspState PCEP LSP status |
Avantika-Huawei | d1e36bd | 2016-05-26 12:47:16 +0530 | [diff] [blame] | 80 | * @return tunnel state |
Avantika-Huawei | 56c1184 | 2016-04-28 00:56:56 +0530 | [diff] [blame] | 81 | */ |
| 82 | public static State getTunnelStatusFromLspStatus(PcepLspStatus lspState) { |
| 83 | |
| 84 | switch (lspState) { |
| 85 | |
| 86 | case DOWN: |
| 87 | return State.FAILED; |
| 88 | |
| 89 | case UP: // fall through |
| 90 | case ACTIVE: |
| 91 | return State.ACTIVE; |
| 92 | |
| 93 | case GOING_DOWN: |
| 94 | return State.FAILED; |
| 95 | |
| 96 | case GOING_UP: |
| 97 | return State.ESTABLISHED; |
| 98 | |
| 99 | default: |
| 100 | return State.FAILED; |
| 101 | } |
| 102 | } |
| 103 | } |