Send node details notification up to the application,
[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 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatus;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16
17 /**
18  * Wrapper for bandwidth extracting utilities
19  *
20  * @author jsebin
21  *
22  */
23 public class PortFeaturesUtil {
24
25     private static PortFeaturesUtil instance = new PortFeaturesUtil();
26
27     private final Map<Short, IGetBandwith> portVersionBandwidth;
28     private static final Logger LOG = LoggerFactory.getLogger(PortFeaturesUtil.class);
29
30     private PortFeaturesUtil() {
31         this.portVersionBandwidth = new HashMap<>();
32
33         portVersionBandwidth.put((short) 1, FeaturesV10Bandwidth.getInstance());
34         portVersionBandwidth.put((short) 4, FeaturesV13Bandwidth.getInstance());
35     }
36
37     /**
38      *
39      * @return instance
40      */
41     public static PortFeaturesUtil getInstance() {
42         return instance;
43     }
44
45     /**
46      *
47      * @param msg {@link org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatus}
48      * @return port bandwidth
49      */
50     public Boolean getPortBandwidth(PortStatus msg) {
51
52         if(portVersionBandwidth.containsKey(msg.getVersion()) == true) {
53             try {
54                 return portVersionBandwidth.get(msg.getVersion()).getBandwidth(msg);
55             } catch (NullPointerException e) {
56                 LOG.warn("error while getting port features: {}", e.getMessage());
57                 LOG.debug("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 }