blob: 34174a0718e4ec20f679c802e273fab83b4c8e8a [file] [log] [blame]
Henry Yu4b4a7eb2016-11-09 20:07:53 -05001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Henry Yu4b4a7eb2016-11-09 20:07:53 -05003 *
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
17package org.onosproject.tetopology.management.api.link;
18
19/**
20 * Represents the tunnel protection type.
21 */
22public enum TunnelProtectionType {
23
24 /**
25 * Represents unprotected.
26 */
27 UNPROTECTED(0),
28
29 /**
30 * Represents extra traffic.
31 */
32 EXTRA_TRAFFIC(1),
33
34 /**
35 * Represents shared.
36 */
37 SHARED(2),
38
39 /**
40 * Represents one-for-one.
41 */
42 ONE_FOR_ONE(3),
43
44 /**
45 * Represents one-plus-one.
46 */
47 ONE_PLUS_ONE(4),
48
49 /**
50 * Represents enhanced.
51 */
52 ENHANCED(5);
53
54 private int value;
55
56 TunnelProtectionType(int value) {
57 this.value = value;
58 }
59
60 /**
61 * Returns the value of the tunnel protection type.
62 *
63 * @return value of tunnel protection type
64 */
65 public int value() {
66 return value;
67 }
68
69 /**
70 * Returns the tunnel protection type constant corresponding to the given
71 * string. Returns null when string conversion fails or converted integer
72 * value is not recognized.
73 *
74 * @param s input string
75 * @return corresponding protection type constant
76 */
77 public static TunnelProtectionType of(String s) {
78 try {
79 int tmpVal = Integer.parseInt(s);
80 return of(tmpVal);
81 } catch (NumberFormatException ignored) {
82 }
83 return null;
84 }
85
86 /**
87 * Returns the tunnel protection type constant corresponding to the
88 * given integer. Returns null when the integer value is not recognized.
89 *
90 * @param value integer value
91 * @return corresponding protection type constant
92 */
93 public static TunnelProtectionType of(int value) {
94 switch (value) {
95 case 0:
96 return UNPROTECTED;
97 case 1:
98 return EXTRA_TRAFFIC;
99 case 2:
100 return SHARED;
101 case 3:
102 return ONE_FOR_ONE;
103 case 4:
104 return ONE_PLUS_ONE;
105 case 5:
106 return ENHANCED;
107 default:
108 return null;
109 }
110 }
111}