Bump MRI upstreams
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / device / SwitchFeaturesUtil.java
1 /*
2  * Copyright (c) 2013 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 package org.opendaylight.openflowplugin.impl.device;
9
10 import static org.opendaylight.openflowplugin.api.OFConstants.OFP_VERSION_1_0;
11 import static org.opendaylight.openflowplugin.api.OFConstants.OFP_VERSION_1_3;
12
13 import java.util.Map;
14 import org.opendaylight.openflowplugin.api.openflow.md.core.sal.BuildSwitchFeatures;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.flow.node.SwitchFeatures;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
17 import org.opendaylight.yangtools.yang.common.Uint8;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 public final class SwitchFeaturesUtil {
22     private static final Logger LOG = LoggerFactory.getLogger(SwitchFeaturesUtil.class);
23
24     private static final Map<Uint8, BuildSwitchFeatures> SWITCH_FEATURES_BUILDERS = Map.of(
25         OFP_VERSION_1_0, BuildSwitchCapabilitiesOF10.getInstance(),
26         OFP_VERSION_1_3, BuildSwitchCapabilitiesOF13.getInstance());
27
28     private SwitchFeaturesUtil() {
29         // Hidden on purpose
30     }
31
32     /**
33      * Returns the features of the switch.
34      *
35      * @param features
36      *        {@link org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput}
37      * @return switch features
38      */
39     public static SwitchFeatures buildSwitchFeatures(final GetFeaturesOutput features) {
40         final var version = features.getVersion();
41         final var builder = SWITCH_FEATURES_BUILDERS.get(version);
42         if (builder != null) {
43             LOG.debug("map contains version {}", version);
44             return builder.build(features);
45         }
46         LOG.warn("unknown version: {}", version);
47         return null;
48     }
49 }