2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.protocol_plugins.stub.internal;
10 import java.util.HashMap;
11 import java.util.HashSet;
14 import java.util.concurrent.ConcurrentHashMap;
15 import java.util.concurrent.ConcurrentMap;
16 import java.util.concurrent.CopyOnWriteArraySet;
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;
37 * Stub Implementation for IPluginInReadService used by SAL
41 public class InventoryService implements IPluginInInventoryService {
42 private static final Logger logger = LoggerFactory
43 .getLogger(InventoryService.class);
45 private ConcurrentMap<Node, Map<String, Property>> nodeProps; // properties
51 private ConcurrentMap<NodeConnector, Map<String, Property>> nodeConnectorProps; // properties
58 private final Set<IPluginOutInventoryService> pluginOutInventoryServices =
59 new CopyOnWriteArraySet<IPluginOutInventoryService>();
61 public void setPluginOutInventoryServices(IPluginOutInventoryService service) {
62 logger.trace("Got a service set request {}", service);
63 if (this.pluginOutInventoryServices != null) {
64 this.pluginOutInventoryServices.add(service);
68 public void unsetPluginOutInventoryServices(IPluginOutInventoryService service) {
69 logger.trace("Got a service UNset request");
70 if (this.pluginOutInventoryServices != null) {
71 this.pluginOutInventoryServices.remove(service);
76 public Set<Node> getConfiguredNotConnectedNodes() {
82 * Function called by the dependency manager when all the required
83 * dependencies are satisfied
87 nodeProps = new ConcurrentHashMap<Node, Map<String, Property>>();
88 nodeConnectorProps = new ConcurrentHashMap<NodeConnector, Map<String, Property>>();
89 Node.NodeIDType.registerIDType("STUB", Integer.class);
90 NodeConnector.NodeConnectorIDType.registerIDType("STUB", Integer.class,
94 setupNodeConnectorProps();
97 private void setupNodeConnectorProps() {
98 Map<String, Property> ncPropMap = new HashMap<String, Property>();
99 Capabilities cap = new Capabilities(
100 CapabilitiesType.FLOW_STATS_CAPABILITY.getValue());
101 ncPropMap.put(Capabilities.CapabilitiesPropName, cap);
102 Bandwidth bw = new Bandwidth(Bandwidth.BW1Gbps);
103 ncPropMap.put(Bandwidth.BandwidthPropName, bw);
104 State st = new State(State.EDGE_UP);
105 ncPropMap.put(State.StatePropName, st);
107 // setup property map for all node connectors
111 node = new Node("STUB", new Integer(0xCAFE));
112 nc = new NodeConnector("STUB", 0xCAFE, node);
113 } catch (ConstructionException e) {
117 nodeConnectorProps.put(nc, ncPropMap);
120 node = new Node("STUB", 3366);
121 nc = new NodeConnector("STUB", 12, node);
122 } catch (ConstructionException e) {
126 nodeConnectorProps.put(nc, ncPropMap);
129 node = new Node("STUB", 4477);
130 nc = new NodeConnector("STUB", 34, node);
131 } catch (ConstructionException e) {
135 nodeConnectorProps.put(nc, ncPropMap);
139 private void setupNodeProps() {
140 Map<String, Property> propMap = new HashMap<String, Property>();
142 Tables t = new Tables((byte) 1);
143 propMap.put(Tables.TablesPropName, t);
144 Capabilities c = new Capabilities((int) 3);
145 propMap.put(Capabilities.CapabilitiesPropName, c);
146 Actions a = new Actions((int) 2);
147 propMap.put(Actions.ActionsPropName, a);
148 Buffers b = new Buffers((int) 1);
149 propMap.put(Buffers.BuffersPropName, b);
150 Long connectedSinceTime = 100000L;
151 TimeStamp timeStamp = new TimeStamp(connectedSinceTime,
153 propMap.put(TimeStamp.TimeStampPropName, timeStamp);
155 // setup property map for all nodes
158 node = new Node("STUB", new Integer(0xCAFE));
159 } catch (ConstructionException e) {
163 nodeProps.put(node, propMap);
166 node = new Node("STUB", 3366);
167 } catch (ConstructionException e) {
170 nodeProps.put(node, propMap);
173 node = new Node("STUB", 4477);
174 } catch (ConstructionException e) {
177 nodeProps.put(node, propMap);
182 * Function called by the dependency manager when at least one dependency
183 * become unsatisfied or when the component is shutting down because for
184 * example bundle is being stopped.
191 * Function called by dependency manager after "init ()" is called and after
192 * the services provided by the class are registered in the service registry
199 * Method called when the plugin has exposed it's services, this will be
200 * used to publish the updates so connection manager can think the
201 * connection is local
204 // update sal and discovery
205 for (IPluginOutInventoryService service : pluginOutInventoryServices) {
206 for (Node node : nodeProps.keySet()) {
207 Set<Property> props = new HashSet<Property>(nodeProps.get(node)
209 service.updateNode(node, UpdateType.ADDED, props);
210 logger.trace("Adding Node {} with props {}", node, props);
212 for (NodeConnector nc : nodeConnectorProps.keySet()) {
213 Set<Property> props = new HashSet<Property>(nodeConnectorProps.get(nc)
215 service.updateNodeConnector(nc, UpdateType.ADDED, props);
216 logger.trace("Adding NodeConnectors {} with props {}", nc, props);
222 * Function called by the dependency manager before the services exported by
223 * the component are unregistered, this will be followed by a "destroy ()"
228 pluginOutInventoryServices.clear();
232 * Retrieve nodes from openflow
235 public ConcurrentMap<Node, Map<String, Property>> getNodeProps() {
240 * Retrieve nodeConnectors from openflow
243 public ConcurrentMap<NodeConnector, Map<String, Property>> getNodeConnectorProps(
245 return nodeConnectorProps;