Merge "Updated POM files and versions to SNAPSHOT"
[controller.git] / opendaylight / protocol_plugins / stub / src / main / java / org / opendaylight / controller / protocol_plugins / stub / internal / InventoryService.java
1 package org.opendaylight.controller.protocol_plugins.stub.internal;
2
3 import java.net.InetAddress;
4 import java.net.UnknownHostException;
5 import java.util.ArrayList;
6 import java.util.Date;
7 import java.util.Dictionary;
8 import java.util.HashMap;
9 import java.util.HashSet;
10 import java.util.List;
11 import java.util.Map;
12 import java.util.Set;
13 import java.util.concurrent.ConcurrentHashMap;
14 import java.util.concurrent.ConcurrentMap;
15
16 import org.apache.felix.dm.Component;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
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.Node;
26 import org.opendaylight.controller.sal.core.NodeConnector;
27 import org.opendaylight.controller.sal.core.Property;
28 import org.opendaylight.controller.sal.core.State;
29 import org.opendaylight.controller.sal.core.Tables;
30 import org.opendaylight.controller.sal.core.TimeStamp;
31 import org.opendaylight.controller.sal.inventory.IPluginInInventoryService;
32 import org.opendaylight.controller.sal.utils.NodeCreator;
33 import org.opendaylight.controller.sal.utils.NodeConnectorCreator;
34
35 /**
36  * Stub Implementation for IPluginInReadService used by SAL
37  *
38  *
39  */
40 public class InventoryService implements IPluginInInventoryService {
41     private static final Logger logger = LoggerFactory
42             .getLogger(InventoryService.class);
43
44     private ConcurrentMap<Node, Map<String, Property>> nodeProps; // properties are maintained in global container only
45     private ConcurrentMap<NodeConnector, Map<String, Property>> nodeConnectorProps; // properties are maintained in global container only
46
47
48     /**
49      * Function called by the dependency manager when all the required
50      * dependencies are satisfied
51      *
52      */
53     void init() {
54         nodeProps = new ConcurrentHashMap<Node, Map<String, Property>>();
55         nodeConnectorProps = new ConcurrentHashMap<NodeConnector, Map<String, Property>>();
56
57     }
58
59     /**
60      * Function called by the dependency manager when at least one dependency
61      * become unsatisfied or when the component is shutting down because for
62      * example bundle is being stopped.
63      *
64      */
65     void destroy() {
66     }
67
68     /**
69      * Function called by dependency manager after "init ()" is called and after
70      * the services provided by the class are registered in the service registry
71      *
72      */
73     void start() {
74     }
75
76     /**
77      * Function called by the dependency manager before the services exported by
78      * the component are unregistered, this will be followed by a "destroy ()"
79      * calls
80      *
81      */
82     void stop() {
83     }
84
85     /**
86      * Retrieve nodes from openflow
87      */
88     @Override
89     public ConcurrentMap<Node, Map<String, Property>> getNodeProps() {
90
91         //  setup nodeProps
92         Map<String, Property> propMap = new HashMap<String, Property>();
93
94         Tables t = new Tables((byte)1);
95         propMap.put(Tables.TablesPropName, t);
96         Capabilities c = new Capabilities((int)3);
97         propMap.put(Capabilities.CapabilitiesPropName, c);
98         Actions a = new Actions((int)2);
99         propMap.put(Actions.ActionsPropName, a);
100         Buffers b = new Buffers((int)1);
101         propMap.put(Buffers.BuffersPropName, b);
102         Long connectedSinceTime = 100000L;
103         TimeStamp timeStamp = new TimeStamp(connectedSinceTime,
104                 "connectedSince");
105         propMap.put(TimeStamp.TimeStampPropName, timeStamp);
106
107         // setup property map for all nodes
108         Node node;
109         node = NodeCreator.createOFNode(2L);
110         nodeProps.put(node, propMap);
111
112         return nodeProps;
113     }
114
115     /**
116      * Retrieve nodeConnectors from openflow
117      */
118     @Override
119     public ConcurrentMap<NodeConnector, Map<String, Property>> getNodeConnectorProps(
120             Boolean refresh) {
121
122         //  setup nodeConnectorProps
123         Map<String, Property> ncPropMap = new HashMap<String, Property>();
124         Capabilities cap = new Capabilities
125                 (CapabilitiesType.FLOW_STATS_CAPABILITY.getValue());
126         ncPropMap.put(Capabilities.CapabilitiesPropName, cap);
127         Bandwidth bw = new Bandwidth (Bandwidth.BW1Gbps);
128         ncPropMap.put(Bandwidth.BandwidthPropName, bw);
129         State st = new State (State.EDGE_UP);
130         ncPropMap.put(State.StatePropName, st);
131
132         // setup property map for all node connectors
133         NodeConnector nc = NodeConnectorCreator.createOFNodeConnector
134                 ((short)2, NodeCreator.createOFNode(3L));
135         nodeConnectorProps.put(nc, ncPropMap);
136
137         return nodeConnectorProps;
138     }
139
140
141 }