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 * Function called by the dependency manager when all the required
70 * dependencies are satisfied
74 nodeProps = new ConcurrentHashMap<Node, Map<String, Property>>();
75 nodeConnectorProps = new ConcurrentHashMap<NodeConnector, Map<String, Property>>();
76 Node.NodeIDType.registerIDType("STUB", Integer.class);
77 NodeConnector.NodeConnectorIDType.registerIDType("STUB", Integer.class,
81 setupNodeConnectorProps();
84 private void setupNodeConnectorProps() {
85 Map<String, Property> ncPropMap = new HashMap<String, Property>();
86 Capabilities cap = new Capabilities(
87 CapabilitiesType.FLOW_STATS_CAPABILITY.getValue());
88 ncPropMap.put(Capabilities.CapabilitiesPropName, cap);
89 Bandwidth bw = new Bandwidth(Bandwidth.BW1Gbps);
90 ncPropMap.put(Bandwidth.BandwidthPropName, bw);
91 State st = new State(State.EDGE_UP);
92 ncPropMap.put(State.StatePropName, st);
94 // setup property map for all node connectors
98 node = new Node("STUB", new Integer(0xCAFE));
99 nc = new NodeConnector("STUB", 0xCAFE, node);
100 } catch (ConstructionException e) {
104 nodeConnectorProps.put(nc, ncPropMap);
107 node = new Node("STUB", 3366);
108 nc = new NodeConnector("STUB", 12, node);
109 } catch (ConstructionException e) {
113 nodeConnectorProps.put(nc, ncPropMap);
116 node = new Node("STUB", 4477);
117 nc = new NodeConnector("STUB", 34, node);
118 } catch (ConstructionException e) {
122 nodeConnectorProps.put(nc, ncPropMap);
126 private void setupNodeProps() {
127 Map<String, Property> propMap = new HashMap<String, Property>();
129 Tables t = new Tables((byte) 1);
130 propMap.put(Tables.TablesPropName, t);
131 Capabilities c = new Capabilities((int) 3);
132 propMap.put(Capabilities.CapabilitiesPropName, c);
133 Actions a = new Actions((int) 2);
134 propMap.put(Actions.ActionsPropName, a);
135 Buffers b = new Buffers((int) 1);
136 propMap.put(Buffers.BuffersPropName, b);
137 Long connectedSinceTime = 100000L;
138 TimeStamp timeStamp = new TimeStamp(connectedSinceTime,
140 propMap.put(TimeStamp.TimeStampPropName, timeStamp);
142 // setup property map for all nodes
145 node = new Node("STUB", new Integer(0xCAFE));
146 } catch (ConstructionException e) {
150 nodeProps.put(node, propMap);
153 node = new Node("STUB", 3366);
154 } catch (ConstructionException e) {
157 nodeProps.put(node, propMap);
160 node = new Node("STUB", 4477);
161 } catch (ConstructionException e) {
164 nodeProps.put(node, propMap);
169 * Function called by the dependency manager when at least one dependency
170 * become unsatisfied or when the component is shutting down because for
171 * example bundle is being stopped.
178 * Function called by dependency manager after "init ()" is called and after
179 * the services provided by the class are registered in the service registry
186 * Method called when the plugin has exposed it's services, this will be
187 * used to publish the updates so connection manager can think the
188 * connection is local
191 // update sal and discovery
192 for (IPluginOutInventoryService service : pluginOutInventoryServices) {
193 for (Node node : nodeProps.keySet()) {
194 Set<Property> props = new HashSet<Property>(nodeProps.get(node)
196 service.updateNode(node, UpdateType.ADDED, props);
197 logger.trace("Adding Node {} with props {}", node, props);
199 for (NodeConnector nc : nodeConnectorProps.keySet()) {
200 Set<Property> props = new HashSet<Property>(nodeConnectorProps.get(nc)
202 service.updateNodeConnector(nc, UpdateType.ADDED, props);
203 logger.trace("Adding NodeConnectors {} with props {}", nc, props);
209 * Function called by the dependency manager before the services exported by
210 * the component are unregistered, this will be followed by a "destroy ()"
215 pluginOutInventoryServices.clear();
219 * Retrieve nodes from openflow
222 public ConcurrentMap<Node, Map<String, Property>> getNodeProps() {
227 * Retrieve nodeConnectors from openflow
230 public ConcurrentMap<NodeConnector, Map<String, Property>> getNodeConnectorProps(
232 return nodeConnectorProps;