blob: 9ced00a079f14f37ed4214a415c50e007e37092a [file] [log] [blame]
Avantika-Huawei56c11842016-04-28 00:56:56 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Avantika-Huawei56c11842016-04-28 00:56:56 +05303 *
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 */
harikrushna-Huaweia2c7c202017-04-10 18:22:00 +053016package org.onosproject.pcep.server;
Avantika-Huawei56c11842016-04-28 00:56:56 +053017
18import org.onosproject.incubator.net.tunnel.Tunnel.State;
19
20/**
21 * Representation of the PCEP LSP state.
22 */
23public 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-Huaweid1e36bd2016-05-26 12:47:16 +053054 * @return LSP status as per protocol
Avantika-Huawei56c11842016-04-28 00:56:56 +053055 */
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-Huaweid1e36bd2016-05-26 12:47:16 +053080 * @return tunnel state
Avantika-Huawei56c11842016-04-28 00:56:56 +053081 */
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}