1 package org.opendaylight.controller.protocol_plugins.stub.internal;
3 import java.net.InetAddress;
4 import java.net.UnknownHostException;
5 import java.util.ArrayList;
7 import java.util.Dictionary;
8 import java.util.HashMap;
9 import java.util.HashSet;
10 import java.util.List;
13 import java.util.concurrent.ConcurrentHashMap;
14 import java.util.concurrent.ConcurrentMap;
15 import java.util.concurrent.CopyOnWriteArraySet;
17 import org.apache.felix.dm.Component;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20 import org.opendaylight.controller.sal.core.Actions;
21 import org.opendaylight.controller.sal.core.Bandwidth;
22 import org.opendaylight.controller.sal.core.Buffers;
23 import org.opendaylight.controller.sal.core.Capabilities;
24 import org.opendaylight.controller.sal.core.Capabilities.CapabilitiesType;
25 import org.opendaylight.controller.sal.core.ConstructionException;
26 import org.opendaylight.controller.sal.core.Node;
27 import org.opendaylight.controller.sal.core.NodeConnector;
28 import org.opendaylight.controller.sal.core.Property;
29 import org.opendaylight.controller.sal.core.State;
30 import org.opendaylight.controller.sal.core.Tables;
31 import org.opendaylight.controller.sal.core.TimeStamp;
32 import org.opendaylight.controller.sal.core.UpdateType;
33 import org.opendaylight.controller.sal.inventory.IPluginInInventoryService;
34 import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService;
35 import org.opendaylight.controller.sal.utils.NodeCreator;
36 import org.opendaylight.controller.sal.utils.NodeConnectorCreator;
39 * Stub Implementation for IPluginInReadService used by SAL
43 public class InventoryService implements IPluginInInventoryService {
44 private static final Logger logger = LoggerFactory
45 .getLogger(InventoryService.class);
47 private ConcurrentMap<Node, Map<String, Property>> nodeProps; // properties
53 private ConcurrentMap<NodeConnector, Map<String, Property>> nodeConnectorProps; // properties
60 private final Set<IPluginOutInventoryService> pluginOutInventoryServices =
61 new CopyOnWriteArraySet<IPluginOutInventoryService>();
63 public void setPluginOutInventoryServices(IPluginOutInventoryService service) {
64 logger.trace("Got a service set request {}", service);
65 if (this.pluginOutInventoryServices != null) {
66 this.pluginOutInventoryServices.add(service);
70 public void unsetPluginOutInventoryServices(IPluginOutInventoryService service) {
71 logger.trace("Got a service UNset request");
72 if (this.pluginOutInventoryServices != null) {
73 this.pluginOutInventoryServices.remove(service);
78 * Function called by the dependency manager when all the required
79 * dependencies are satisfied
83 nodeProps = new ConcurrentHashMap<Node, Map<String, Property>>();
84 nodeConnectorProps = new ConcurrentHashMap<NodeConnector, Map<String, Property>>();
85 Node.NodeIDType.registerIDType("STUB", Integer.class);
86 NodeConnector.NodeConnectorIDType.registerIDType("STUB", Integer.class,
90 setupNodeConnectorProps();
93 private void setupNodeConnectorProps() {
94 Map<String, Property> ncPropMap = new HashMap<String, Property>();
95 Capabilities cap = new Capabilities(
96 CapabilitiesType.FLOW_STATS_CAPABILITY.getValue());
97 ncPropMap.put(Capabilities.CapabilitiesPropName, cap);
98 Bandwidth bw = new Bandwidth(Bandwidth.BW1Gbps);
99 ncPropMap.put(Bandwidth.BandwidthPropName, bw);
100 State st = new State(State.EDGE_UP);
101 ncPropMap.put(State.StatePropName, st);
103 // setup property map for all node connectors
107 node = new Node("STUB", new Integer(0xCAFE));
108 nc = new NodeConnector("STUB", 0xCAFE, node);
109 } catch (ConstructionException e) {
113 nodeConnectorProps.put(nc, ncPropMap);
116 node = new Node("STUB", 3366);
117 nc = new NodeConnector("STUB", 12, node);
118 } catch (ConstructionException e) {
122 nodeConnectorProps.put(nc, ncPropMap);
125 node = new Node("STUB", 4477);
126 nc = new NodeConnector("STUB", 34, node);
127 } catch (ConstructionException e) {
131 nodeConnectorProps.put(nc, ncPropMap);
135 private void setupNodeProps() {
136 Map<String, Property> propMap = new HashMap<String, Property>();
138 Tables t = new Tables((byte) 1);
139 propMap.put(Tables.TablesPropName, t);
140 Capabilities c = new Capabilities((int) 3);
141 propMap.put(Capabilities.CapabilitiesPropName, c);
142 Actions a = new Actions((int) 2);
143 propMap.put(Actions.ActionsPropName, a);
144 Buffers b = new Buffers((int) 1);
145 propMap.put(Buffers.BuffersPropName, b);
146 Long connectedSinceTime = 100000L;
147 TimeStamp timeStamp = new TimeStamp(connectedSinceTime,
149 propMap.put(TimeStamp.TimeStampPropName, timeStamp);
151 // setup property map for all nodes
154 node = new Node("STUB", new Integer(0xCAFE));
155 } catch (ConstructionException e) {
159 nodeProps.put(node, propMap);
162 node = new Node("STUB", 3366);
163 } catch (ConstructionException e) {
166 nodeProps.put(node, propMap);
169 node = new Node("STUB", 4477);
170 } catch (ConstructionException e) {
173 nodeProps.put(node, propMap);
178 * Function called by the dependency manager when at least one dependency
179 * become unsatisfied or when the component is shutting down because for
180 * example bundle is being stopped.
187 * Function called by dependency manager after "init ()" is called and after
188 * the services provided by the class are registered in the service registry
195 * Method called when the plugin has exposed it's services, this will be
196 * used to publish the updates so connection manager can think the
197 * connection is local
200 // update sal and discovery
201 for (IPluginOutInventoryService service : pluginOutInventoryServices) {
202 for (Node node : nodeProps.keySet()) {
203 Set<Property> props = new HashSet<Property>(nodeProps.get(node)
205 service.updateNode(node, UpdateType.ADDED, props);
206 logger.trace("Adding Node {} with props {}", node, props);
208 for (NodeConnector nc : nodeConnectorProps.keySet()) {
209 Set<Property> props = new HashSet<Property>(nodeConnectorProps.get(nc)
211 service.updateNodeConnector(nc, UpdateType.ADDED, props);
212 logger.trace("Adding NodeConnectors {} with props {}", nc, props);
218 * Function called by the dependency manager before the services exported by
219 * the component are unregistered, this will be followed by a "destroy ()"
224 pluginOutInventoryServices.clear();
228 * Retrieve nodes from openflow
231 public ConcurrentMap<Node, Map<String, Property>> getNodeProps() {
236 * Retrieve nodeConnectors from openflow
239 public ConcurrentMap<NodeConnector, Map<String, Property>> getNodeConnectorProps(
241 return nodeConnectorProps;