1 package org.opendaylight.controller.protocol_plugins.stub.internal;
3 import java.net.InetAddress;
4 import java.net.UnknownHostException;
5 import java.util.ArrayList;
6 import java.util.Dictionary;
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;
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;
49 * Stub Implementation for IPluginInReadService used by SAL
53 public class ReadService implements IPluginInReadService {
54 private static final Logger logger = LoggerFactory
55 .getLogger(ReadService.class);
58 * Function called by the dependency manager when all the required
59 * dependencies are satisfied
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.
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
83 * Function called by the dependency manager before the services exported by
84 * the component are unregistered, this will be followed by a "destroy ()"
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);
103 public List<FlowOnNode> readAllFlow(Node node, boolean cached) {
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());
115 actionList.add(new Output(new NodeConnector("STUB", 0xCAFE, node)));
116 } catch (ConstructionException e) {
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));
125 actionList.add(new SetVlanId(2));
126 actionList.add(new SetVlanPcp(3));
127 actionList.add(new SetVlanCfi(1));
129 actionList.add(new PopVlan());
130 actionList.add(new PushVlan(0x8100, 1, 1, 1234));
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) {
138 actionList.add(new SetNwTos(0x10));
139 actionList.add(new SetTpSrc(4201));
140 actionList.add(new SetTpDst(8080));
142 for (Action a : actionList) {
143 Flow flow = new Flow();
144 Match match = new Match();
146 match.setField(MatchType.NW_DST,
147 InetAddress.getByName("1.1.1.1"));
148 } catch (UnknownHostException e) {
151 flow.setMatch(match);
152 List<Action> actions = new ArrayList<Action>();
154 flow.setActions(actions);
155 flow.setPriority((short) 3500);
156 flow.setIdleTimeout((short) 1000);
157 flow.setHardTimeout((short) 2000);
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);
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");
184 public NodeConnectorStatistics readNodeConnector(NodeConnector connector,
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);
205 public List<NodeConnectorStatistics> readAllNodeConnector(Node node,
207 NodeConnectorStatistics stats = new NodeConnectorStatistics();
209 NodeConnector nc = new NodeConnector("STUB", 0xCAFE, node);
210 stats.setNodeConnector(nc);
211 } catch (ConstructionException e) {
212 // couldn't create nodeconnector.
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);
227 List<NodeConnectorStatistics> result = new ArrayList<NodeConnectorStatistics>();
233 public long getTransmitRate(NodeConnector connector) {
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);
249 public List<NodeTableStatistics> readAllNodeTable(Node node, boolean cached) {
250 NodeTableStatistics stats = new NodeTableStatistics();
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.
258 stats.setActiveCount(4);
259 stats.setLookupCount(4);
260 stats.setMatchedCount(4);
262 List<NodeTableStatistics> result = new ArrayList<NodeTableStatistics>();