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