0224e3ade6ea16d319b2b18572b7eaf89f5d3f1c
[controller.git] / opendaylight / protocol_plugins / stub / src / main / java / org / opendaylight / controller / protocol_plugins / stub / internal / ReadService.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.Dictionary;
7 import java.util.List;
8
9 import org.apache.felix.dm.Component;
10 //import org.opendaylight.controller.protocol_plugin_stubs.IPluginReadServiceFilter;
11 import org.slf4j.Logger;
12 import org.slf4j.LoggerFactory;
13
14 import org.opendaylight.controller.sal.action.Action;
15 import org.opendaylight.controller.sal.action.Drop;
16 import org.opendaylight.controller.sal.core.ConstructionException;
17 import org.opendaylight.controller.sal.core.Node;
18 import org.opendaylight.controller.sal.core.NodeConnector;
19 import org.opendaylight.controller.sal.flowprogrammer.Flow;
20 import org.opendaylight.controller.sal.match.Match;
21 import org.opendaylight.controller.sal.match.MatchType;
22 import org.opendaylight.controller.sal.reader.FlowOnNode;
23 import org.opendaylight.controller.sal.reader.IPluginInReadService;
24 import org.opendaylight.controller.sal.reader.NodeConnectorStatistics;
25 import org.opendaylight.controller.sal.reader.NodeDescription;
26
27 /**
28  * Stub Implementation for IPluginInReadService used by SAL
29  * 
30  * 
31  */
32 public class ReadService implements IPluginInReadService {
33     private static final Logger logger = LoggerFactory
34             .getLogger(ReadService.class);
35
36     /**
37      * Function called by the dependency manager when all the required
38      * dependencies are satisfied
39      * 
40      */
41     void init() {
42     }
43
44     /**
45      * Function called by the dependency manager when at least one dependency
46      * become unsatisfied or when the component is shutting down because for
47      * example bundle is being stopped.
48      * 
49      */
50     void destroy() {
51     }
52
53     /**
54      * Function called by dependency manager after "init ()" is called and after
55      * the services provided by the class are registered in the service registry
56      * 
57      */
58     void start() {
59     }
60
61     /**
62      * Function called by the dependency manager before the services exported by
63      * the component are unregistered, this will be followed by a "destroy ()"
64      * calls
65      * 
66      */
67     void stop() {
68     }
69
70     @Override
71     public FlowOnNode readFlow(Node node, Flow flow, boolean cached) {
72         FlowOnNode fn1 = new FlowOnNode(flow);
73         fn1.setByteCount(100);
74         fn1.setDurationNanoseconds(400);
75         fn1.setDurationSeconds(40);
76         fn1.setTableId((byte) 0x1);
77         fn1.setPacketCount(200);
78         return fn1;
79     }
80
81     @Override
82     public List<FlowOnNode> readAllFlow(Node node, boolean cached) {
83         Flow flow = new Flow();
84
85         Match match = new Match();
86         try {
87             match.setField(MatchType.NW_DST, InetAddress.getByName("1.1.1.1"));
88         } catch (UnknownHostException e) {
89
90         }
91         flow.setMatch(match);
92         Action action = new Drop();
93
94         List<Action> actions = new ArrayList<Action>();
95         actions.add(action);
96         flow.setActions(actions);
97
98         FlowOnNode fn1 = new FlowOnNode(flow);
99         fn1.setByteCount(100);
100         fn1.setDurationNanoseconds(400);
101         fn1.setDurationSeconds(40);
102         fn1.setTableId((byte) 0x1);
103         fn1.setPacketCount(200);
104
105         ArrayList<FlowOnNode> list = new ArrayList<FlowOnNode>();
106         list.add(fn1);
107         return list;
108     }
109
110     @Override
111     public NodeDescription readDescription(Node node, boolean cached) {
112         NodeDescription desc = new NodeDescription();
113         desc.setDescription("This is a sample node description");
114         desc.setHardware("stub hardware");
115         desc.setSoftware("stub software");
116         desc.setSerialNumber("123");
117         desc.setManufacturer("opendaylight");
118         return desc;
119     }
120
121     @Override
122     public NodeConnectorStatistics readNodeConnector(NodeConnector connector,
123             boolean cached) {
124         NodeConnectorStatistics stats = new NodeConnectorStatistics();
125         stats.setNodeConnector(connector);
126         stats.setCollisionCount(4);
127         stats.setReceiveByteCount(1000);
128         stats.setReceiveCRCErrorCount(1);
129         stats.setReceiveDropCount(2);
130         stats.setReceiveErrorCount(3);
131         stats.setReceiveFrameErrorCount(5);
132         stats.setReceiveOverRunErrorCount(6);
133         stats.setReceivePacketCount(250);
134         stats.setTransmitByteCount(5000);
135         stats.setTransmitDropCount(50);
136         stats.setTransmitErrorCount(10);
137         stats.setTransmitPacketCount(500);
138
139         return stats;
140     }
141
142     @Override
143     public List<NodeConnectorStatistics> readAllNodeConnector(Node node,
144             boolean cached) {
145         NodeConnectorStatistics stats = new NodeConnectorStatistics();
146         try{
147             NodeConnector nc = new NodeConnector("STUB", 0xCAFE, node);
148             stats.setNodeConnector(nc);
149         }catch(ConstructionException e){
150             //couldn't create nodeconnector.
151         }
152         stats.setCollisionCount(4);
153         stats.setReceiveByteCount(1000);
154         stats.setReceiveCRCErrorCount(1);
155         stats.setReceiveDropCount(2);
156         stats.setReceiveErrorCount(3);
157         stats.setReceiveFrameErrorCount(5);
158         stats.setReceiveOverRunErrorCount(6);
159         stats.setReceivePacketCount(250);
160         stats.setTransmitByteCount(5000);
161         stats.setTransmitDropCount(50);
162         stats.setTransmitErrorCount(10);
163         stats.setTransmitPacketCount(500);
164
165         List<NodeConnectorStatistics> result = new ArrayList<NodeConnectorStatistics>();
166         result.add(stats);
167         return result;
168     }
169
170     @Override
171     public long getTransmitRate(NodeConnector connector) {
172         return 100;
173     }
174
175 }