64d4fc167597e39e2ca479ad5984221071ed346a
[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 are maintained in global container only
46     private ConcurrentMap<NodeConnector, Map<String, Property>> nodeConnectorProps; // properties are maintained in global container only
47
48
49     /**
50      * Function called by the dependency manager when all the required
51      * dependencies are satisfied
52      *
53      */
54     void init() {
55         nodeProps = new ConcurrentHashMap<Node, Map<String, Property>>();
56         nodeConnectorProps = new ConcurrentHashMap<NodeConnector, Map<String, Property>>();
57         Node.NodeIDType.registerIDType("STUB", Integer.class);
58         NodeConnector.NodeConnectorIDType.registerIDType("STUB", Integer.class, "STUB");
59     }
60
61     /**
62      * Function called by the dependency manager when at least one dependency
63      * become unsatisfied or when the component is shutting down because for
64      * example bundle is being stopped.
65      *
66      */
67     void destroy() {
68     }
69
70     /**
71      * Function called by dependency manager after "init ()" is called and after
72      * the services provided by the class are registered in the service registry
73      *
74      */
75     void start() {
76     }
77
78     /**
79      * Function called by the dependency manager before the services exported by
80      * the component are unregistered, this will be followed by a "destroy ()"
81      * calls
82      *
83      */
84     void stop() {
85     }
86
87     /**
88      * Retrieve nodes from openflow
89      */
90     @Override
91     public ConcurrentMap<Node, Map<String, Property>> getNodeProps() {
92
93         //  setup nodeProps
94         Map<String, Property> propMap = new HashMap<String, Property>();
95
96         Tables t = new Tables((byte)1);
97         propMap.put(Tables.TablesPropName, t);
98         Capabilities c = new Capabilities((int)3);
99         propMap.put(Capabilities.CapabilitiesPropName, c);
100         Actions a = new Actions((int)2);
101         propMap.put(Actions.ActionsPropName, a);
102         Buffers b = new Buffers((int)1);
103         propMap.put(Buffers.BuffersPropName, b);
104         Long connectedSinceTime = 100000L;
105         TimeStamp timeStamp = new TimeStamp(connectedSinceTime,
106                 "connectedSince");
107         propMap.put(TimeStamp.TimeStampPropName, timeStamp);
108
109         // setup property map for all nodes
110         Node node;
111         try{
112             node = new Node("STUB", new Integer(0xCAFE));
113         }catch(ConstructionException e){
114             node = null;
115         }       
116      
117         nodeProps.put(node, propMap);
118         return nodeProps;
119     }
120
121     /**
122      * Retrieve nodeConnectors from openflow
123      */
124     @Override
125     public ConcurrentMap<NodeConnector, Map<String, Property>> getNodeConnectorProps(
126             Boolean refresh) {
127
128         //  setup nodeConnectorProps
129         Map<String, Property> ncPropMap = new HashMap<String, Property>();
130         Capabilities cap = new Capabilities
131                 (CapabilitiesType.FLOW_STATS_CAPABILITY.getValue());
132         ncPropMap.put(Capabilities.CapabilitiesPropName, cap);
133         Bandwidth bw = new Bandwidth (Bandwidth.BW1Gbps);
134         ncPropMap.put(Bandwidth.BandwidthPropName, bw);
135         State st = new State (State.EDGE_UP);
136         ncPropMap.put(State.StatePropName, st);
137
138         // setup property map for all node connectors
139         NodeConnector nc;
140         Node node;
141         try{
142             node = new Node("STUB", new Integer(0xCAFE));
143             nc = new NodeConnector("STUB", 0xCAFE, node);
144         }catch(ConstructionException e){
145             nc = null;
146             node = null;
147         }
148         nodeConnectorProps.put(nc, ncPropMap);
149         return nodeConnectorProps;
150     }
151
152
153 }