2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.openflowplugin.openflow.md.core.sal;
10 import static org.opendaylight.openflowplugin.api.OFConstants.OFP_VERSION_1_0;
11 import static org.opendaylight.openflowplugin.api.OFConstants.OFP_VERSION_1_3;
13 import java.util.HashMap;
16 import org.opendaylight.openflowplugin.api.openflow.md.core.sal.BuildSwitchFeatures;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.flow.node.SwitchFeatures;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
26 public final class SwitchFeaturesUtil {
28 private static final Logger LOG = LoggerFactory.getLogger(SwitchFeaturesUtil.class);
30 private static SwitchFeaturesUtil instance = new SwitchFeaturesUtil();
31 private Map<Short, BuildSwitchFeatures> swFeaturesBuilders;
33 private SwitchFeaturesUtil() {
34 swFeaturesBuilders = new HashMap<>();
35 swFeaturesBuilders.put(OFP_VERSION_1_0, BuildSwitchCapabilitiesOF10.getInstance());
36 swFeaturesBuilders.put(OFP_VERSION_1_3, BuildSwitchCapabilitiesOF13.getInstance());
40 * Get singleton instance
44 public static SwitchFeaturesUtil getInstance() {
49 * @param features {@link org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput}
50 * @return switch features
52 public SwitchFeatures buildSwitchFeatures(GetFeaturesOutput features) {
54 if(swFeaturesBuilders.containsKey(features.getVersion())) {
55 LOG.debug("map contains version {}", features.getVersion());
57 return swFeaturesBuilders.get(features.getVersion()).build(features);
58 } catch (NullPointerException e) {
59 LOG.error("error while building switch features {}", e);
63 LOG.warn("unknown version: {}", features.getVersion());