External api proposal
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / session / PortFeaturesUtil.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
9 package org.opendaylight.openflowplugin.openflow.md.core.session;
10
11 import java.util.HashMap;
12 import java.util.Map;
13
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatus;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17
18 /**
19  * Wrapper for bandwidth extracting utilities
20  * 
21  * @author jsebin
22  *
23  */
24 public class PortFeaturesUtil {
25         
26     private static PortFeaturesUtil instance = new PortFeaturesUtil();
27     
28     private final Map<Short, IGetBandwith> portVersionBandwidth;
29     protected static final Logger LOG = LoggerFactory.getLogger(PortFeaturesUtil.class); 
30     
31     private PortFeaturesUtil() {
32         this.portVersionBandwidth = new HashMap<>();
33         
34         portVersionBandwidth.put((short) 1, FeaturesV10Bandwidth.getInstance());
35         portVersionBandwidth.put((short) 4, FeaturesV13Bandwidth.getInstance());
36     }
37     
38     /**
39      * 
40      * @return instance
41      */
42     public static PortFeaturesUtil getInstance() {
43         return instance;    
44     }
45     
46     /**
47      * 
48      * @param msg {@link org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatus}
49      * @return port bandwidth
50      */
51     public Boolean getPortBandwidth(PortStatus msg) {        
52     
53         if(portVersionBandwidth.containsKey(msg.getVersion()) == true) {
54                 try {
55                         return portVersionBandwidth.get(msg.getVersion()).getBandwidth(msg);
56                 } catch (NullPointerException e) {
57                 LOG.error("error while getting port features {}", e);            
58             }
59         }
60         else {
61             LOG.warn("unknown port version: {}", msg.getVersion());                
62         }                
63         
64         return null;
65     }
66         
67 }