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