Statistics Northbound Test
[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.Controller;
16 import org.opendaylight.controller.sal.action.Drop;
17 import org.opendaylight.controller.sal.action.Flood;
18 import org.opendaylight.controller.sal.action.FloodAll;
19 import org.opendaylight.controller.sal.action.HwPath;
20 import org.opendaylight.controller.sal.action.Loopback;
21 import org.opendaylight.controller.sal.action.Output;
22 import org.opendaylight.controller.sal.action.PopVlan;
23 import org.opendaylight.controller.sal.action.PushVlan;
24 import org.opendaylight.controller.sal.action.SetDlDst;
25 import org.opendaylight.controller.sal.action.SetDlSrc;
26 import org.opendaylight.controller.sal.action.SetDlType;
27 import org.opendaylight.controller.sal.action.SetNwDst;
28 import org.opendaylight.controller.sal.action.SetNwSrc;
29 import org.opendaylight.controller.sal.action.SetNwTos;
30 import org.opendaylight.controller.sal.action.SetTpDst;
31 import org.opendaylight.controller.sal.action.SetTpSrc;
32 import org.opendaylight.controller.sal.action.SetVlanCfi;
33 import org.opendaylight.controller.sal.action.SetVlanId;
34 import org.opendaylight.controller.sal.action.SetVlanPcp;
35 import org.opendaylight.controller.sal.action.SwPath;
36 import org.opendaylight.controller.sal.core.ConstructionException;
37 import org.opendaylight.controller.sal.core.Node;
38 import org.opendaylight.controller.sal.core.NodeConnector;
39 import org.opendaylight.controller.sal.flowprogrammer.Flow;
40 import org.opendaylight.controller.sal.match.Match;
41 import org.opendaylight.controller.sal.match.MatchType;
42 import org.opendaylight.controller.sal.reader.FlowOnNode;
43 import org.opendaylight.controller.sal.reader.IPluginInReadService;
44 import org.opendaylight.controller.sal.reader.NodeConnectorStatistics;
45 import org.opendaylight.controller.sal.reader.NodeDescription;
46
47 /**
48  * Stub Implementation for IPluginInReadService used by SAL
49  * 
50  * 
51  */
52 public class ReadService implements IPluginInReadService {
53     private static final Logger logger = LoggerFactory
54             .getLogger(ReadService.class);
55
56     /**
57      * Function called by the dependency manager when all the required
58      * dependencies are satisfied
59      * 
60      */
61     void init() {
62     }
63
64     /**
65      * Function called by the dependency manager when at least one dependency
66      * become unsatisfied or when the component is shutting down because for
67      * example bundle is being stopped.
68      * 
69      */
70     void destroy() {
71     }
72
73     /**
74      * Function called by dependency manager after "init ()" is called and after
75      * the services provided by the class are registered in the service registry
76      * 
77      */
78     void start() {
79     }
80
81     /**
82      * Function called by the dependency manager before the services exported by
83      * the component are unregistered, this will be followed by a "destroy ()"
84      * calls
85      * 
86      */
87     void stop() {
88     }
89
90     @Override
91     public FlowOnNode readFlow(Node node, Flow flow, boolean cached) {
92         FlowOnNode fn1 = new FlowOnNode(flow);
93         fn1.setByteCount(100);
94         fn1.setDurationNanoseconds(400);
95         fn1.setDurationSeconds(40);
96         fn1.setTableId((byte) 0x1);
97         fn1.setPacketCount(200);
98         return fn1;
99     }
100
101     @Override
102     public List<FlowOnNode> readAllFlow(Node node, boolean cached) {
103
104         ArrayList<FlowOnNode> list = new ArrayList<FlowOnNode>();
105         ArrayList<Action> actionList = new ArrayList<Action>();
106         actionList.add(new Drop());
107         actionList.add(new Loopback());
108         actionList.add(new Flood());
109         actionList.add(new FloodAll());
110         actionList.add(new Controller());
111         actionList.add(new SwPath());
112         actionList.add(new HwPath());
113         try {
114             actionList.add(new Output(new NodeConnector("STUB", 0xCAFE, node)));
115         } catch (ConstructionException e) {
116
117         }
118         byte dst[] = { (byte) 1, (byte) 2, (byte) 3, (byte) 4, (byte) 5 };
119         byte src[] = { (byte) 5, (byte) 4, (byte) 3, (byte) 2, (byte) 1 };
120         actionList.add(new SetDlSrc(src));
121         actionList.add(new SetDlDst(dst));
122         actionList.add(new SetDlType(10));
123
124         actionList.add(new SetVlanId(2));
125         actionList.add(new SetVlanPcp(3));
126         actionList.add(new SetVlanCfi(1));
127
128         actionList.add(new PopVlan());
129         actionList.add(new PushVlan(0x8100, 1, 1, 1234));
130
131         try {
132             actionList.add(new SetNwSrc(InetAddress.getByName("2.2.2.2")));
133             actionList.add(new SetNwDst(InetAddress.getByName("1.1.1.1")));
134         } catch (UnknownHostException e) {
135
136         }
137         actionList.add(new SetNwTos(0x10));
138         actionList.add(new SetTpSrc(4201));
139         actionList.add(new SetTpDst(8080));
140
141         for (Action a : actionList) {
142             Flow flow = new Flow();
143             Match match = new Match();
144             try {
145                 match.setField(MatchType.NW_DST,
146                         InetAddress.getByName("1.1.1.1"));
147             } catch (UnknownHostException e) {
148
149             }
150             flow.setMatch(match);
151             List<Action> actions = new ArrayList<Action>();
152             actions.add(a);
153             flow.setActions(actions);
154             flow.setPriority((short) 3500);
155             flow.setIdleTimeout((short) 1000);
156             flow.setHardTimeout((short) 2000);
157             flow.setId(12345);
158
159             FlowOnNode fn1 = new FlowOnNode(flow);
160             fn1.setByteCount(100);
161             fn1.setDurationNanoseconds(400);
162             fn1.setDurationSeconds(40);
163             fn1.setTableId((byte) 0x1);
164             fn1.setPacketCount(200);
165
166             list.add(fn1);
167         }
168         return list;
169     }
170
171     @Override
172     public NodeDescription readDescription(Node node, boolean cached) {
173         NodeDescription desc = new NodeDescription();
174         desc.setDescription("This is a sample node description");
175         desc.setHardware("stub hardware");
176         desc.setSoftware("stub software");
177         desc.setSerialNumber("123");
178         desc.setManufacturer("opendaylight");
179         return desc;
180     }
181
182     @Override
183     public NodeConnectorStatistics readNodeConnector(NodeConnector connector,
184             boolean cached) {
185         NodeConnectorStatistics stats = new NodeConnectorStatistics();
186         stats.setNodeConnector(connector);
187         stats.setCollisionCount(4);
188         stats.setReceiveByteCount(1000);
189         stats.setReceiveCRCErrorCount(1);
190         stats.setReceiveDropCount(2);
191         stats.setReceiveErrorCount(3);
192         stats.setReceiveFrameErrorCount(5);
193         stats.setReceiveOverRunErrorCount(6);
194         stats.setReceivePacketCount(250);
195         stats.setTransmitByteCount(5000);
196         stats.setTransmitDropCount(50);
197         stats.setTransmitErrorCount(10);
198         stats.setTransmitPacketCount(500);
199
200         return stats;
201     }
202
203     @Override
204     public List<NodeConnectorStatistics> readAllNodeConnector(Node node,
205             boolean cached) {
206         NodeConnectorStatistics stats = new NodeConnectorStatistics();
207         try {
208             NodeConnector nc = new NodeConnector("STUB", 0xCAFE, node);
209             stats.setNodeConnector(nc);
210         } catch (ConstructionException e) {
211             // couldn't create nodeconnector.
212         }
213         stats.setCollisionCount(4);
214         stats.setReceiveByteCount(1000);
215         stats.setReceiveCRCErrorCount(1);
216         stats.setReceiveDropCount(2);
217         stats.setReceiveErrorCount(3);
218         stats.setReceiveFrameErrorCount(5);
219         stats.setReceiveOverRunErrorCount(6);
220         stats.setReceivePacketCount(250);
221         stats.setTransmitByteCount(5000);
222         stats.setTransmitDropCount(50);
223         stats.setTransmitErrorCount(10);
224         stats.setTransmitPacketCount(500);
225
226         List<NodeConnectorStatistics> result = new ArrayList<NodeConnectorStatistics>();
227         result.add(stats);
228         return result;
229     }
230
231     @Override
232     public long getTransmitRate(NodeConnector connector) {
233         return 100;
234     }
235
236 }