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