Bump mdsal to 5.0.2
[openflowplugin.git] / openflowplugin-api / src / main / java / org / opendaylight / openflowplugin / api / openflow / md / util / OpenflowVersion.java
1 /*
2  * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.openflowplugin.api.openflow.md.util;
10
11 import com.google.common.collect.ImmutableMap;
12 import com.google.common.collect.Maps;
13 import java.util.Arrays;
14 import org.opendaylight.yangtools.yang.common.Uint8;
15
16 /**
17  * List of Openflow versions supported by the plugin.
18  * Note: If you add a version here,
19  * make sure to update org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil as well.
20  * @deprecated enum in api is not something what we would like to see in case it is evolving.
21  */
22 public enum OpenflowVersion {
23
24     OF10((short)0x01),
25     OF13((short)0x04),
26     UNSUPPORTED((short)0x00);
27
28     private static final ImmutableMap<Uint8, OpenflowVersion> VERSIONS = Maps.uniqueIndex(Arrays.asList(values()),
29         ver -> Uint8.valueOf(ver.version));
30
31     private short version;
32
33     OpenflowVersion(final short version) {
34         this.version = version;
35     }
36
37     public static OpenflowVersion get(final Uint8 version) {
38         final OpenflowVersion ver = VERSIONS.get(version);
39         return ver != null ? ver : UNSUPPORTED;
40     }
41
42     public static OpenflowVersion get(final Short version) {
43         for (final OpenflowVersion ofv : OpenflowVersion.values()) {
44             if (ofv.version == version) {
45                 return ofv;
46             }
47         }
48         return UNSUPPORTED;
49     }
50
51     /**
52      * Getter.
53      * @return the version
54      */
55     public short getVersion() {
56         return version;
57     }
58
59 }