blob: ef628ed3fcc2c5448b94aeb1b704d47340588fc5 [file] [log] [blame]
Avantika-Huawei56c11842016-04-28 00:56:56 +05301/*
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 */
16package org.onosproject.provider.pcep.tunnel.impl;
17
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
54 */
55 public static PcepLspStatus getLspStatusFromTunnelStatus(State tunnelState) {
56
57 switch (tunnelState) {
58
59 case INIT:
60 return PcepLspStatus.DOWN;
61
62 case ESTABLISHED:
63 return PcepLspStatus.GOING_UP;
64
65 case ACTIVE:
66 return PcepLspStatus.UP;
67
68 case FAILED: // fall through
69 case INACTIVE: // LSP is administratively down.
70 default:
71 return PcepLspStatus.DOWN;
72 }
73 }
74
75 /**
76 * Returns the applicable ONOS tunnel state corresponding to PCEP LSP status.
77 *
78 * @param lspState PCEP LSP status
79 */
80 public static State getTunnelStatusFromLspStatus(PcepLspStatus lspState) {
81
82 switch (lspState) {
83
84 case DOWN:
85 return State.FAILED;
86
87 case UP: // fall through
88 case ACTIVE:
89 return State.ACTIVE;
90
91 case GOING_DOWN:
92 return State.FAILED;
93
94 case GOING_UP:
95 return State.ESTABLISHED;
96
97 default:
98 return State.FAILED;
99 }
100 }
101}