blob: 2b5ee7ce0bdf3b8a272f0d81957022562d4d1e08 [file] [log] [blame]
rohitsharana127ba82018-01-16 02:17:30 +05301/*
2 * Copyright 2017-present Open Networking Foundation
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.net.behaviour;
17
18
19import java.util.ArrayList;
20import java.util.Arrays;
21import java.util.List;
22import java.util.stream.Collectors;
23
24public enum ControlProtocolVersion {
25 OF_1_0("OpenFlow10"),
26 OF_1_1("OpenFlow11"),
27 OF_1_2("OpenFlow12"),
28 OF_1_3("OpenFlow13"),
29 OF_1_4("OpenFlow14"),
30 OF_1_5("OpenFlow15");
31
32 private final String versionString;
33
34 /**
35 * Creates the enum from a string representing the control protoocol version.
36 *
37 * @param versionString the text representing the control protocol version.
38 */
39 ControlProtocolVersion(final String versionString) {
40 this.versionString = versionString;
41 }
42
43 @Override
44 public String toString() {
45 return versionString;
46 }
47
48 /**
49 * Returns a list of control protocol version string values.
50 *
51 * @return the list of string values corresponding to the enums
52 */
53 public static List<String> toStringList() {
54 return Arrays.stream(values())
55 .map(ControlProtocolVersion::toString)
56 .collect(Collectors.toCollection(ArrayList::new));
57 }
58
59 /**
60 * Alternative method to valueOf. It returns the ControlProtocolVersion type
61 * corresponding to the given string. If the parameter does not match a
62 * constant name, or is null, null is returned.
63 *
64 * @param versionString the string representing the encapsulation type
65 * @return the EncapsulationType constant corresponding to the string given
66 */
67 public static ControlProtocolVersion enumFromString(String versionString) {
68 if (versionString != null && !versionString.isEmpty()) {
69 for (ControlProtocolVersion c : values()) {
70 if (versionString.equalsIgnoreCase(c.toString())) {
71 return c;
72 }
73 }
74 }
75 return null;
76 }
77
78}