X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fprotocol_plugins%2Fstub%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fprotocol_plugins%2Fstub%2Finternal%2FInventoryService.java;h=9f2454bbffa9d6ace80c29fafaf6e8ea770f460c;hb=e269f57182ae65e67c6fd7699e257bb63f7a4dc6;hp=b3909a775bbe36156fa127e9b54841f02556a40e;hpb=541d0a36997f292bb037a2199463431eee538358;p=controller.git diff --git a/opendaylight/protocol_plugins/stub/src/main/java/org/opendaylight/controller/protocol_plugins/stub/internal/InventoryService.java b/opendaylight/protocol_plugins/stub/src/main/java/org/opendaylight/controller/protocol_plugins/stub/internal/InventoryService.java index b3909a775b..9f2454bbff 100644 --- a/opendaylight/protocol_plugins/stub/src/main/java/org/opendaylight/controller/protocol_plugins/stub/internal/InventoryService.java +++ b/opendaylight/protocol_plugins/stub/src/main/java/org/opendaylight/controller/protocol_plugins/stub/internal/InventoryService.java @@ -1,22 +1,15 @@ package org.opendaylight.controller.protocol_plugins.stub.internal; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.ArrayList; -import java.util.Date; -import java.util.Dictionary; import java.util.HashMap; import java.util.HashSet; -import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.CopyOnWriteArraySet; -import org.apache.felix.dm.Component; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - import org.opendaylight.controller.sal.core.Actions; import org.opendaylight.controller.sal.core.Bandwidth; import org.opendaylight.controller.sal.core.Buffers; @@ -29,9 +22,9 @@ import org.opendaylight.controller.sal.core.Property; import org.opendaylight.controller.sal.core.State; import org.opendaylight.controller.sal.core.Tables; import org.opendaylight.controller.sal.core.TimeStamp; +import org.opendaylight.controller.sal.core.UpdateType; import org.opendaylight.controller.sal.inventory.IPluginInInventoryService; -import org.opendaylight.controller.sal.utils.NodeCreator; -import org.opendaylight.controller.sal.utils.NodeConnectorCreator; +import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService; /** * Stub Implementation for IPluginInReadService used by SAL @@ -42,9 +35,41 @@ public class InventoryService implements IPluginInInventoryService { private static final Logger logger = LoggerFactory .getLogger(InventoryService.class); - private ConcurrentMap> nodeProps; // properties are maintained in global container only - private ConcurrentMap> nodeConnectorProps; // properties are maintained in global container only + private ConcurrentMap> nodeProps; // properties + // are + // maintained + // in global + // container + // only + private ConcurrentMap> nodeConnectorProps; // properties + // are + // maintained + // in + // global + // container + // only + private final Set pluginOutInventoryServices = + new CopyOnWriteArraySet(); + + public void setPluginOutInventoryServices(IPluginOutInventoryService service) { + logger.trace("Got a service set request {}", service); + if (this.pluginOutInventoryServices != null) { + this.pluginOutInventoryServices.add(service); + } + } + + public void unsetPluginOutInventoryServices(IPluginOutInventoryService service) { + logger.trace("Got a service UNset request"); + if (this.pluginOutInventoryServices != null) { + this.pluginOutInventoryServices.remove(service); + } + } + @Override + public Set getConfiguredNotConnectedNodes() { + // TODO + return null; + } /** * Function called by the dependency manager when all the required @@ -55,51 +80,65 @@ public class InventoryService implements IPluginInInventoryService { nodeProps = new ConcurrentHashMap>(); nodeConnectorProps = new ConcurrentHashMap>(); Node.NodeIDType.registerIDType("STUB", Integer.class); - NodeConnector.NodeConnectorIDType.registerIDType("STUB", Integer.class, "STUB"); - } + NodeConnector.NodeConnectorIDType.registerIDType("STUB", Integer.class, + "STUB"); - /** - * Function called by the dependency manager when at least one dependency - * become unsatisfied or when the component is shutting down because for - * example bundle is being stopped. - * - */ - void destroy() { + setupNodeProps(); + setupNodeConnectorProps(); } - /** - * Function called by dependency manager after "init ()" is called and after - * the services provided by the class are registered in the service registry - * - */ - void start() { - } + private void setupNodeConnectorProps() { + Map ncPropMap = new HashMap(); + Capabilities cap = new Capabilities( + CapabilitiesType.FLOW_STATS_CAPABILITY.getValue()); + ncPropMap.put(Capabilities.CapabilitiesPropName, cap); + Bandwidth bw = new Bandwidth(Bandwidth.BW1Gbps); + ncPropMap.put(Bandwidth.BandwidthPropName, bw); + State st = new State(State.EDGE_UP); + ncPropMap.put(State.StatePropName, st); - /** - * Function called by the dependency manager before the services exported by - * the component are unregistered, this will be followed by a "destroy ()" - * calls - * - */ - void stop() { - } + // setup property map for all node connectors + NodeConnector nc; + Node node; + try { + node = new Node("STUB", new Integer(0xCAFE)); + nc = new NodeConnector("STUB", 0xCAFE, node); + } catch (ConstructionException e) { + nc = null; + node = null; + } + nodeConnectorProps.put(nc, ncPropMap); - /** - * Retrieve nodes from openflow - */ - @Override - public ConcurrentMap> getNodeProps() { + try { + node = new Node("STUB", 3366); + nc = new NodeConnector("STUB", 12, node); + } catch (ConstructionException e) { + nc = null; + node = null; + } + nodeConnectorProps.put(nc, ncPropMap); + + try { + node = new Node("STUB", 4477); + nc = new NodeConnector("STUB", 34, node); + } catch (ConstructionException e) { + nc = null; + node = null; + } + nodeConnectorProps.put(nc, ncPropMap); + + } - // setup nodeProps + private void setupNodeProps() { Map propMap = new HashMap(); - Tables t = new Tables((byte)1); + Tables t = new Tables((byte) 1); propMap.put(Tables.TablesPropName, t); - Capabilities c = new Capabilities((int)3); + Capabilities c = new Capabilities((int) 3); propMap.put(Capabilities.CapabilitiesPropName, c); - Actions a = new Actions((int)2); + Actions a = new Actions((int) 2); propMap.put(Actions.ActionsPropName, a); - Buffers b = new Buffers((int)1); + Buffers b = new Buffers((int) 1); propMap.put(Buffers.BuffersPropName, b); Long connectedSinceTime = 100000L; TimeStamp timeStamp = new TimeStamp(connectedSinceTime, @@ -108,80 +147,95 @@ public class InventoryService implements IPluginInInventoryService { // setup property map for all nodes Node node; - try{ + try { node = new Node("STUB", new Integer(0xCAFE)); - }catch(ConstructionException e){ + } catch (ConstructionException e) { node = null; } nodeProps.put(node, propMap); - try{ + try { node = new Node("STUB", 3366); - }catch(ConstructionException e){ + } catch (ConstructionException e) { node = null; } nodeProps.put(node, propMap); - try{ + try { node = new Node("STUB", 4477); - }catch(ConstructionException e){ + } catch (ConstructionException e) { node = null; } nodeProps.put(node, propMap); - return nodeProps; } /** - * Retrieve nodeConnectors from openflow + * Function called by the dependency manager when at least one dependency + * become unsatisfied or when the component is shutting down because for + * example bundle is being stopped. + * */ - @Override - public ConcurrentMap> getNodeConnectorProps( - Boolean refresh) { + void destroy() { + } - // setup nodeConnectorProps - Map ncPropMap = new HashMap(); - Capabilities cap = new Capabilities - (CapabilitiesType.FLOW_STATS_CAPABILITY.getValue()); - ncPropMap.put(Capabilities.CapabilitiesPropName, cap); - Bandwidth bw = new Bandwidth (Bandwidth.BW1Gbps); - ncPropMap.put(Bandwidth.BandwidthPropName, bw); - State st = new State (State.EDGE_UP); - ncPropMap.put(State.StatePropName, st); + /** + * Function called by dependency manager after "init ()" is called and after + * the services provided by the class are registered in the service registry + * + */ + void start() { + } - // setup property map for all node connectors - NodeConnector nc; - Node node; - try{ - node = new Node("STUB", new Integer(0xCAFE)); - nc = new NodeConnector("STUB", 0xCAFE, node); - }catch(ConstructionException e){ - nc = null; - node = null; + /** + * Method called when the plugin has exposed it's services, this will be + * used to publish the updates so connection manager can think the + * connection is local + */ + void started() { + // update sal and discovery + for (IPluginOutInventoryService service : pluginOutInventoryServices) { + for (Node node : nodeProps.keySet()) { + Set props = new HashSet(nodeProps.get(node) + .values()); + service.updateNode(node, UpdateType.ADDED, props); + logger.trace("Adding Node {} with props {}", node, props); + } + for (NodeConnector nc : nodeConnectorProps.keySet()) { + Set props = new HashSet(nodeConnectorProps.get(nc) + .values()); + service.updateNodeConnector(nc, UpdateType.ADDED, props); + logger.trace("Adding NodeConnectors {} with props {}", nc, props); + } } - nodeConnectorProps.put(nc, ncPropMap); - - try{ - node = new Node("STUB", 3366); - nc = new NodeConnector("STUB", 12, node); - } catch(ConstructionException e){ - nc = null; - node = null; - } - nodeConnectorProps.put(nc, ncPropMap); + } - try{ - node = new Node("STUB", 4477); - nc = new NodeConnector("STUB", 34, node); - }catch(ConstructionException e){ - nc = null; - node = null; - } - nodeConnectorProps.put(nc, ncPropMap); + /** + * Function called by the dependency manager before the services exported by + * the component are unregistered, this will be followed by a "destroy ()" + * calls + * + */ + void stop() { + pluginOutInventoryServices.clear(); + } - return nodeConnectorProps; + /** + * Retrieve nodes from openflow + */ + @Override + public ConcurrentMap> getNodeProps() { + return nodeProps; } + /** + * Retrieve nodeConnectors from openflow + */ + @Override + public ConcurrentMap> getNodeConnectorProps( + Boolean refresh) { + return nodeConnectorProps; + } }