blob: d7ed01d9139f6aa67b24cb5fed6d4a00fe25ce18 [file] [log] [blame]
Michele Santuari02e47a42015-11-23 16:54:51 +01001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Michele Santuari02e47a42015-11-23 16:54:51 +01003 *
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.net;
18
19public enum EncapsulationType {
20 /**
Luca Prete092e8952016-10-26 16:25:56 +020021 * Indicates no encapsulation.
22 */
23 NONE,
24 /**
Michele Santuari02e47a42015-11-23 16:54:51 +010025 * Indicates an MPLS encapsulation.
26 */
27 MPLS,
28 /**
29 * Indicates a VLAN encapsulation.
30 */
Luca Prete092e8952016-10-26 16:25:56 +020031 VLAN;
Michele Santuari02e47a42015-11-23 16:54:51 +010032
Luca Prete092e8952016-10-26 16:25:56 +020033 /**
34 * Alternative method to valueOf. It returns the encapsulation type constant
35 * corresponding to the given string. If the parameter does not match a
36 * constant name, or is null, {@link #NONE} is returned.
37 *
38 * @param encap the string representing the encapsulation type
39 * @return the EncapsulationType constant corresponding to the string given
40 */
41 public static EncapsulationType enumFromString(String encap) {
42 // Return EncapsulationType.NONE if the value is not found, or if null
43 // or an empty string are given
44 EncapsulationType type = NONE;
45 if (encap != null && !encap.isEmpty()) {
46 for (EncapsulationType t : values()) {
47 if (encap.equalsIgnoreCase(t.toString())) {
48 type = valueOf(encap.toUpperCase());
49 break;
50 }
51 }
52 }
53 return type;
54 }
55}