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