1 package org.opendaylight.controller.protocol_plugins.stub.internal;
3 import java.util.HashMap;
4 import java.util.HashSet;
7 import java.util.concurrent.ConcurrentHashMap;
8 import java.util.concurrent.ConcurrentMap;
9 import java.util.concurrent.CopyOnWriteArraySet;
11 import org.slf4j.Logger;
12 import org.slf4j.LoggerFactory;
13 import org.opendaylight.controller.sal.core.Actions;
14 import org.opendaylight.controller.sal.core.Bandwidth;
15 import org.opendaylight.controller.sal.core.Buffers;
16 import org.opendaylight.controller.sal.core.Capabilities;
17 import org.opendaylight.controller.sal.core.Capabilities.CapabilitiesType;
18 import org.opendaylight.controller.sal.core.ConstructionException;
19 import org.opendaylight.controller.sal.core.Node;
20 import org.opendaylight.controller.sal.core.NodeConnector;
21 import org.opendaylight.controller.sal.core.Property;
22 import org.opendaylight.controller.sal.core.State;
23 import org.opendaylight.controller.sal.core.Tables;
24 import org.opendaylight.controller.sal.core.TimeStamp;
25 import org.opendaylight.controller.sal.core.UpdateType;
26 import org.opendaylight.controller.sal.inventory.IPluginInInventoryService;
27 import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService;
30 * Stub Implementation for IPluginInReadService used by SAL
34 public class InventoryService implements IPluginInInventoryService {
35 private static final Logger logger = LoggerFactory
36 .getLogger(InventoryService.class);
38 private ConcurrentMap<Node, Map<String, Property>> nodeProps; // properties
44 private ConcurrentMap<NodeConnector, Map<String, Property>> nodeConnectorProps; // properties
51 private final Set<IPluginOutInventoryService> pluginOutInventoryServices =
52 new CopyOnWriteArraySet<IPluginOutInventoryService>();
54 public void setPluginOutInventoryServices(IPluginOutInventoryService service) {
55 logger.trace("Got a service set request {}", service);
56 if (this.pluginOutInventoryServices != null) {
57 this.pluginOutInventoryServices.add(service);
61 public void unsetPluginOutInventoryServices(IPluginOutInventoryService service) {
62 logger.trace("Got a service UNset request");
63 if (this.pluginOutInventoryServices != null) {
64 this.pluginOutInventoryServices.remove(service);
69 public Set<Node> getConfiguredNotConnectedNodes() {
75 * Function called by the dependency manager when all the required
76 * dependencies are satisfied
80 nodeProps = new ConcurrentHashMap<Node, Map<String, Property>>();
81 nodeConnectorProps = new ConcurrentHashMap<NodeConnector, Map<String, Property>>();
82 Node.NodeIDType.registerIDType("STUB", Integer.class);
83 NodeConnector.NodeConnectorIDType.registerIDType("STUB", Integer.class,
87 setupNodeConnectorProps();
90 private void setupNodeConnectorProps() {
91 Map<String, Property> ncPropMap = new HashMap<String, Property>();
92 Capabilities cap = new Capabilities(
93 CapabilitiesType.FLOW_STATS_CAPABILITY.getValue());
94 ncPropMap.put(Capabilities.CapabilitiesPropName, cap);
95 Bandwidth bw = new Bandwidth(Bandwidth.BW1Gbps);
96 ncPropMap.put(Bandwidth.BandwidthPropName, bw);
97 State st = new State(State.EDGE_UP);
98 ncPropMap.put(State.StatePropName, st);
100 // setup property map for all node connectors
104 node = new Node("STUB", new Integer(0xCAFE));
105 nc = new NodeConnector("STUB", 0xCAFE, node);
106 } catch (ConstructionException e) {
110 nodeConnectorProps.put(nc, ncPropMap);
113 node = new Node("STUB", 3366);
114 nc = new NodeConnector("STUB", 12, node);
115 } catch (ConstructionException e) {
119 nodeConnectorProps.put(nc, ncPropMap);
122 node = new Node("STUB", 4477);
123 nc = new NodeConnector("STUB", 34, node);
124 } catch (ConstructionException e) {
128 nodeConnectorProps.put(nc, ncPropMap);
132 private void setupNodeProps() {
133 Map<String, Property> propMap = new HashMap<String, Property>();
135 Tables t = new Tables((byte) 1);
136 propMap.put(Tables.TablesPropName, t);
137 Capabilities c = new Capabilities((int) 3);
138 propMap.put(Capabilities.CapabilitiesPropName, c);
139 Actions a = new Actions((int) 2);
140 propMap.put(Actions.ActionsPropName, a);
141 Buffers b = new Buffers((int) 1);
142 propMap.put(Buffers.BuffersPropName, b);
143 Long connectedSinceTime = 100000L;
144 TimeStamp timeStamp = new TimeStamp(connectedSinceTime,
146 propMap.put(TimeStamp.TimeStampPropName, timeStamp);
148 // setup property map for all nodes
151 node = new Node("STUB", new Integer(0xCAFE));
152 } catch (ConstructionException e) {
156 nodeProps.put(node, propMap);
159 node = new Node("STUB", 3366);
160 } catch (ConstructionException e) {
163 nodeProps.put(node, propMap);
166 node = new Node("STUB", 4477);
167 } catch (ConstructionException e) {
170 nodeProps.put(node, propMap);
175 * Function called by the dependency manager when at least one dependency
176 * become unsatisfied or when the component is shutting down because for
177 * example bundle is being stopped.
184 * Function called by dependency manager after "init ()" is called and after
185 * the services provided by the class are registered in the service registry
192 * Method called when the plugin has exposed it's services, this will be
193 * used to publish the updates so connection manager can think the
194 * connection is local
197 // update sal and discovery
198 for (IPluginOutInventoryService service : pluginOutInventoryServices) {
199 for (Node node : nodeProps.keySet()) {
200 Set<Property> props = new HashSet<Property>(nodeProps.get(node)
202 service.updateNode(node, UpdateType.ADDED, props);
203 logger.trace("Adding Node {} with props {}", node, props);
205 for (NodeConnector nc : nodeConnectorProps.keySet()) {
206 Set<Property> props = new HashSet<Property>(nodeConnectorProps.get(nc)
208 service.updateNodeConnector(nc, UpdateType.ADDED, props);
209 logger.trace("Adding NodeConnectors {} with props {}", nc, props);
215 * Function called by the dependency manager before the services exported by
216 * the component are unregistered, this will be followed by a "destroy ()"
221 pluginOutInventoryServices.clear();
225 * Retrieve nodes from openflow
228 public ConcurrentMap<Node, Map<String, Property>> getNodeProps() {
233 * Retrieve nodeConnectors from openflow
236 public ConcurrentMap<NodeConnector, Map<String, Property>> getNodeConnectorProps(
238 return nodeConnectorProps;