3 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 * and is available at http://www.eclipse.org/legal/epl-v10.html
10 package org.opendaylight.openflowplugin.openflow.internal;
12 import java.util.HashMap;
13 import java.util.HashSet;
17 import org.opendaylight.controller.sal.core.Bandwidth;
18 import org.opendaylight.controller.sal.core.AdvertisedBandwidth;
19 import org.opendaylight.controller.sal.core.SupportedBandwidth;
20 import org.opendaylight.controller.sal.core.PeerBandwidth;
21 import org.opendaylight.controller.sal.core.Config;
22 import org.opendaylight.controller.sal.core.Name;
23 import org.opendaylight.controller.sal.core.Node;
24 import org.opendaylight.controller.sal.core.NodeConnector;
25 import org.opendaylight.controller.sal.core.Property;
26 import org.opendaylight.controller.sal.core.State;
28 import org.opendaylight.controller.sal.utils.NodeCreator;
30 import org.opendaylight.openflowplugin.openflow.core.ISwitch;
31 import org.openflow.protocol.OFPhysicalPort;
32 import org.openflow.protocol.OFPhysicalPort.OFPortConfig;
33 import org.openflow.protocol.OFPhysicalPort.OFPortFeatures;
34 import org.openflow.protocol.OFPhysicalPort.OFPortState;
37 * The class provides helper functions to retrieve inventory properties from
40 public class InventoryServiceHelper {
42 * Returns BandWidth property from OpenFlow OFPhysicalPort features
44 public static Bandwidth OFPortToBandWidth(int portFeatures) {
46 int value = portFeatures
47 & (OFPortFeatures.OFPPF_10MB_FD.getValue()
48 | OFPortFeatures.OFPPF_10MB_HD.getValue()
49 | OFPortFeatures.OFPPF_100MB_FD.getValue()
50 | OFPortFeatures.OFPPF_100MB_HD.getValue()
51 | OFPortFeatures.OFPPF_1GB_FD.getValue()
52 | OFPortFeatures.OFPPF_1GB_HD.getValue() | OFPortFeatures.OFPPF_10GB_FD
58 bw = new Bandwidth(Bandwidth.BW10Mbps);
62 bw = new Bandwidth(Bandwidth.BW100Mbps);
66 bw = new Bandwidth(Bandwidth.BW1Gbps);
69 bw = new Bandwidth(Bandwidth.BW10Gbps);
78 * Returns Config property from OpenFLow OFPhysicalPort config
80 public static Config OFPortToConfig(int portConfig) {
82 if ((OFPortConfig.OFPPC_PORT_DOWN.getValue() & portConfig) != 0)
83 config = new Config(Config.ADMIN_DOWN);
85 config = new Config(Config.ADMIN_UP);
90 * Returns State property from OpenFLow OFPhysicalPort state
92 public static State OFPortToState(int portState) {
94 if ((OFPortState.OFPPS_LINK_DOWN.getValue() & portState) != 0)
95 state = new State(State.EDGE_DOWN);
97 state = new State(State.EDGE_UP);
102 * Returns set of properties from OpenFLow OFPhysicalPort
104 public static Set<Property> OFPortToProps(OFPhysicalPort port) {
105 Set<Property> props = new HashSet<Property>();
106 Bandwidth bw = InventoryServiceHelper.OFPortToBandWidth(port
107 .getCurrentFeatures());
112 Bandwidth abw = InventoryServiceHelper.OFPortToBandWidth(port.getAdvertisedFeatures());
114 AdvertisedBandwidth a = new AdvertisedBandwidth(abw.getValue());
119 Bandwidth sbw = InventoryServiceHelper.OFPortToBandWidth(port.getSupportedFeatures());
121 SupportedBandwidth s = new SupportedBandwidth(sbw.getValue());
126 Bandwidth pbw = InventoryServiceHelper.OFPortToBandWidth(port.getPeerFeatures());
128 PeerBandwidth p = new PeerBandwidth(pbw.getValue());
133 props.add(new Name(port.getName()));
134 props.add(InventoryServiceHelper.OFPortToConfig(port.getConfig()));
135 props.add(InventoryServiceHelper.OFPortToState(port.getState()));
140 * Returns set of properties for each nodeConnector in an OpenFLow switch
142 public static Map<NodeConnector, Set<Property>> OFSwitchToProps(ISwitch sw) {
143 Map<NodeConnector, Set<Property>> ncProps = new HashMap<NodeConnector, Set<Property>>();
149 Node node = NodeCreator.createOFNode(sw.getId());
155 NodeConnector nodeConnector;
157 Map<Short, OFPhysicalPort> ports = sw.getPhysicalPorts();
158 for (Map.Entry<Short, OFPhysicalPort> entry : ports.entrySet()) {
159 nodeConnector = PortConverter.toNodeConnector(entry.getKey(), node);
160 port = entry.getValue();
161 props = InventoryServiceHelper.OFPortToProps(port);
162 ncProps.put(nodeConnector, props);