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