X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflowplugin-api%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowplugin%2Fapi%2Fopenflow%2Fmd%2Futil%2FOpenflowVersion.java;h=ca315493f0a8ac2640843eda7159ced74bd82405;hb=13e1d5e6c0237b9378d60526dd8c1d79db6d2b49;hp=99d7cc8d0043b364fd21ec0cc82fcfd3535df593;hpb=2bef52d5eb4c32ddd3d51be53760926ca2138f04;p=openflowplugin.git diff --git a/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/md/util/OpenflowVersion.java b/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/md/util/OpenflowVersion.java index 99d7cc8d00..ca315493f0 100644 --- a/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/md/util/OpenflowVersion.java +++ b/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/md/util/OpenflowVersion.java @@ -8,6 +8,11 @@ package org.opendaylight.openflowplugin.api.openflow.md.util; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Maps; +import java.util.Arrays; +import org.opendaylight.yangtools.yang.common.Uint8; + /** * List of Openflow versions supported by the plugin. * Note: If you add a version here, @@ -20,6 +25,8 @@ public enum OpenflowVersion { OF13((short)0x04), UNSUPPORTED((short)0x00); + private static final ImmutableMap VERSIONS = Maps.uniqueIndex(Arrays.asList(values()), + ver -> Uint8.valueOf(ver.version)); private short version; @@ -27,6 +34,11 @@ public enum OpenflowVersion { this.version = version; } + public static OpenflowVersion get(final Uint8 version) { + final OpenflowVersion ver = VERSIONS.get(version); + return ver != null ? ver : UNSUPPORTED; + } + public static OpenflowVersion get(final Short version) { for (final OpenflowVersion ofv : OpenflowVersion.values()) { if (ofv.version == version) {