SwitchNorthbound tests
[controller.git] / opendaylight / protocol_plugins / stub / src / main / java / org / opendaylight / controller / protocol_plugins / stub / internal / InventoryService.java
index b3909a775bbe36156fa127e9b54841f02556a40e..22a4343f332ed2e79e7f7ecc979d8535acc4ea26 100644 (file)
@@ -42,9 +42,19 @@ public class InventoryService implements IPluginInInventoryService {
     private static final Logger logger = LoggerFactory
             .getLogger(InventoryService.class);
 
-    private ConcurrentMap<Node, Map<String, Property>> nodeProps; // properties are maintained in global container only
-    private ConcurrentMap<NodeConnector, Map<String, Property>> nodeConnectorProps; // properties are maintained in global container only
-
+    private ConcurrentMap<Node, Map<String, Property>> nodeProps; // properties
+                                                                  // are
+                                                                  // maintained
+                                                                  // in global
+                                                                  // container
+                                                                  // only
+    private ConcurrentMap<NodeConnector, Map<String, Property>> nodeConnectorProps; // properties
+                                                                                    // are
+                                                                                    // maintained
+                                                                                    // in
+                                                                                    // global
+                                                                                    // container
+                                                                                    // only
 
     /**
      * Function called by the dependency manager when all the required
@@ -55,51 +65,65 @@ public class InventoryService implements IPluginInInventoryService {
         nodeProps = new ConcurrentHashMap<Node, Map<String, Property>>();
         nodeConnectorProps = new ConcurrentHashMap<NodeConnector, Map<String, Property>>();
         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<String, Property> ncPropMap = new HashMap<String, Property>();
+        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<Node, Map<String, Property>> 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<String, Property> propMap = new HashMap<String, Property>();
 
-        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,28 +132,61 @@ 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);
 
+    }
+
+    /**
+     * 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() {
+    }
+
+    /**
+     * 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() {
+    }
+
+    /**
+     * 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() {
+    }
+
+    /**
+     * Retrieve nodes from openflow
+     */
+    @Override
+    public ConcurrentMap<Node, Map<String, Property>> getNodeProps() {
         return nodeProps;
     }
 
@@ -139,49 +196,7 @@ public class InventoryService implements IPluginInInventoryService {
     @Override
     public ConcurrentMap<NodeConnector, Map<String, Property>> getNodeConnectorProps(
             Boolean refresh) {
-
-        //  setup nodeConnectorProps
-        Map<String, Property> ncPropMap = new HashMap<String, Property>();
-        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);
-
-        // 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);
-
-        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);
-
-         return nodeConnectorProps;
+        return nodeConnectorProps;
     }
 
-
 }