BUG-542 - adding overall statictics
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / sal / 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.openflow.md.core.sal;
9
10 import java.util.HashMap;
11 import java.util.Map;
12
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.flow.node.SwitchFeatures;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17
18 /**
19  * @author jsebin
20  *
21  */
22 public class SwitchFeaturesUtil {
23
24     protected static final Logger LOG = LoggerFactory.getLogger(SwitchFeaturesUtil.class);
25     
26     private static SwitchFeaturesUtil instance = new SwitchFeaturesUtil();
27     private Map<Short, BuildSwitchFeatures> swFeaturesBuilders;
28     
29     private SwitchFeaturesUtil() {
30         swFeaturesBuilders = new HashMap<>();
31         swFeaturesBuilders.put((short) 1, BuildSwitchCapabilitiesOF10.getInstance());
32         swFeaturesBuilders.put((short) 4, BuildSwitchCapabilitiesOF13.getInstance());
33     }
34     
35     /**
36      * Get singleton instance
37      * 
38      * @return instance
39      */
40     public static SwitchFeaturesUtil getInstance() {
41         return instance;
42     }
43     
44     /**
45      * @param features {@link org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput}
46      * @return switch features
47      */
48     public SwitchFeatures buildSwitchFeatures(GetFeaturesOutput features) {
49
50         if(swFeaturesBuilders.containsKey(features.getVersion()) == true) {
51             LOG.debug("map contains version {}", features.getVersion());
52             try {
53                 return swFeaturesBuilders.get(features.getVersion()).build(features);
54             } catch (NullPointerException e) {
55                 LOG.error("error while building switch features {}", e);
56             }
57         }
58         else {
59             LOG.warn("unknown version: {}", features.getVersion());            
60         }                
61         
62         return null;
63     }
64     
65 }