Northbound cleanup for Switch Manager
[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.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.inventory.IPluginInInventoryService;
33 import org.opendaylight.controller.sal.utils.NodeCreator;
34 import org.opendaylight.controller.sal.utils.NodeConnectorCreator;
35
36 /**
37  * Stub Implementation for IPluginInReadService used by SAL
38  *
39  *
40  */
41 public class InventoryService implements IPluginInInventoryService {
42     private static final Logger logger = LoggerFactory
43             .getLogger(InventoryService.class);
44
45     private ConcurrentMap<Node, Map<String, Property>> nodeProps; // properties
46                                                                   // are
47                                                                   // maintained
48                                                                   // in global
49                                                                   // container
50                                                                   // only
51     private ConcurrentMap<NodeConnector, Map<String, Property>> nodeConnectorProps; // properties
52                                                                                     // are
53                                                                                     // maintained
54                                                                                     // in
55                                                                                     // global
56                                                                                     // container
57                                                                                     // only
58
59     /**
60      * Function called by the dependency manager when all the required
61      * dependencies are satisfied
62      *
63      */
64     void init() {
65         nodeProps = new ConcurrentHashMap<Node, Map<String, Property>>();
66         nodeConnectorProps = new ConcurrentHashMap<NodeConnector, Map<String, Property>>();
67         Node.NodeIDType.registerIDType("STUB", Integer.class);
68         NodeConnector.NodeConnectorIDType.registerIDType("STUB", Integer.class,
69                 "STUB");
70
71         setupNodeProps();
72         setupNodeConnectorProps();
73     }
74
75     private void setupNodeConnectorProps() {
76         Map<String, Property> ncPropMap = new HashMap<String, Property>();
77         Capabilities cap = new Capabilities(
78                 CapabilitiesType.FLOW_STATS_CAPABILITY.getValue());
79         ncPropMap.put(Capabilities.CapabilitiesPropName, cap);
80         Bandwidth bw = new Bandwidth(Bandwidth.BW1Gbps);
81         ncPropMap.put(Bandwidth.BandwidthPropName, bw);
82         State st = new State(State.EDGE_UP);
83         ncPropMap.put(State.StatePropName, st);
84
85         // setup property map for all node connectors
86         NodeConnector nc;
87         Node node;
88         try {
89             node = new Node("STUB", new Integer(0xCAFE));
90             nc = new NodeConnector("STUB", 0xCAFE, node);
91         } catch (ConstructionException e) {
92             nc = null;
93             node = null;
94         }
95         nodeConnectorProps.put(nc, ncPropMap);
96
97         try {
98             node = new Node("STUB", 3366);
99             nc = new NodeConnector("STUB", 12, node);
100         } catch (ConstructionException e) {
101             nc = null;
102             node = null;
103         }
104         nodeConnectorProps.put(nc, ncPropMap);
105
106         try {
107             node = new Node("STUB", 4477);
108             nc = new NodeConnector("STUB", 34, node);
109         } catch (ConstructionException e) {
110             nc = null;
111             node = null;
112         }
113         nodeConnectorProps.put(nc, ncPropMap);
114
115     }
116
117     private void setupNodeProps() {
118         Map<String, Property> propMap = new HashMap<String, Property>();
119
120         Tables t = new Tables((byte) 1);
121         propMap.put(Tables.TablesPropName, t);
122         Capabilities c = new Capabilities((int) 3);
123         propMap.put(Capabilities.CapabilitiesPropName, c);
124         Actions a = new Actions((int) 2);
125         propMap.put(Actions.ActionsPropName, a);
126         Buffers b = new Buffers((int) 1);
127         propMap.put(Buffers.BuffersPropName, b);
128         Long connectedSinceTime = 100000L;
129         TimeStamp timeStamp = new TimeStamp(connectedSinceTime,
130                 "connectedSince");
131         propMap.put(TimeStamp.TimeStampPropName, timeStamp);
132
133         // setup property map for all nodes
134         Node node;
135         try {
136             node = new Node("STUB", new Integer(0xCAFE));
137         } catch (ConstructionException e) {
138             node = null;
139         }
140
141         nodeProps.put(node, propMap);
142
143         try {
144             node = new Node("STUB", 3366);
145         } catch (ConstructionException e) {
146             node = null;
147         }
148         nodeProps.put(node, propMap);
149
150         try {
151             node = new Node("STUB", 4477);
152         } catch (ConstructionException e) {
153             node = null;
154         }
155         nodeProps.put(node, propMap);
156
157     }
158
159     /**
160      * Function called by the dependency manager when at least one dependency
161      * become unsatisfied or when the component is shutting down because for
162      * example bundle is being stopped.
163      *
164      */
165     void destroy() {
166     }
167
168     /**
169      * Function called by dependency manager after "init ()" is called and after
170      * the services provided by the class are registered in the service registry
171      *
172      */
173     void start() {
174     }
175
176     /**
177      * Function called by the dependency manager before the services exported by
178      * the component are unregistered, this will be followed by a "destroy ()"
179      * calls
180      *
181      */
182     void stop() {
183     }
184
185     /**
186      * Retrieve nodes from openflow
187      */
188     @Override
189     public ConcurrentMap<Node, Map<String, Property>> getNodeProps() {
190         return nodeProps;
191     }
192
193     /**
194      * Retrieve nodeConnectors from openflow
195      */
196     @Override
197     public ConcurrentMap<NodeConnector, Map<String, Property>> getNodeConnectorProps(
198             Boolean refresh) {
199         return nodeConnectorProps;
200     }
201
202 }