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.flowprogrammer.Flow;
40 import org.opendaylight.controller.sal.match.Match;
41 import org.opendaylight.controller.sal.match.MatchType;
42 import org.opendaylight.controller.sal.reader.FlowOnNode;
43 import org.opendaylight.controller.sal.reader.IPluginInReadService;
44 import org.opendaylight.controller.sal.reader.NodeConnectorStatistics;
45 import org.opendaylight.controller.sal.reader.NodeDescription;
48 * Stub Implementation for IPluginInReadService used by SAL
52 public class ReadService implements IPluginInReadService {
53 private static final Logger logger = LoggerFactory
54 .getLogger(ReadService.class);
57 * Function called by the dependency manager when all the required
58 * dependencies are satisfied
65 * Function called by the dependency manager when at least one dependency
66 * become unsatisfied or when the component is shutting down because for
67 * example bundle is being stopped.
74 * Function called by dependency manager after "init ()" is called and after
75 * the services provided by the class are registered in the service registry
82 * Function called by the dependency manager before the services exported by
83 * the component are unregistered, this will be followed by a "destroy ()"
91 public FlowOnNode readFlow(Node node, Flow flow, boolean cached) {
92 FlowOnNode fn1 = new FlowOnNode(flow);
93 fn1.setByteCount(100);
94 fn1.setDurationNanoseconds(400);
95 fn1.setDurationSeconds(40);
96 fn1.setTableId((byte) 0x1);
97 fn1.setPacketCount(200);
102 public List<FlowOnNode> readAllFlow(Node node, boolean cached) {
104 ArrayList<FlowOnNode> list = new ArrayList<FlowOnNode>();
105 ArrayList<Action> actionList = new ArrayList<Action>();
106 actionList.add(new Drop());
107 actionList.add(new Loopback());
108 actionList.add(new Flood());
109 actionList.add(new FloodAll());
110 actionList.add(new Controller());
111 actionList.add(new SwPath());
112 actionList.add(new HwPath());
114 actionList.add(new Output(new NodeConnector("STUB", 0xCAFE, node)));
115 } catch (ConstructionException e) {
118 byte dst[] = { (byte) 1, (byte) 2, (byte) 3, (byte) 4, (byte) 5 };
119 byte src[] = { (byte) 5, (byte) 4, (byte) 3, (byte) 2, (byte) 1 };
120 actionList.add(new SetDlSrc(src));
121 actionList.add(new SetDlDst(dst));
122 actionList.add(new SetDlType(10));
124 actionList.add(new SetVlanId(2));
125 actionList.add(new SetVlanPcp(3));
126 actionList.add(new SetVlanCfi(1));
128 actionList.add(new PopVlan());
129 actionList.add(new PushVlan(0x8100, 1, 1, 1234));
132 actionList.add(new SetNwSrc(InetAddress.getByName("2.2.2.2")));
133 actionList.add(new SetNwDst(InetAddress.getByName("1.1.1.1")));
134 } catch (UnknownHostException e) {
137 actionList.add(new SetNwTos(0x10));
138 actionList.add(new SetTpSrc(4201));
139 actionList.add(new SetTpDst(8080));
141 for (Action a : actionList) {
142 Flow flow = new Flow();
143 Match match = new Match();
145 match.setField(MatchType.NW_DST,
146 InetAddress.getByName("1.1.1.1"));
147 } catch (UnknownHostException e) {
150 flow.setMatch(match);
151 List<Action> actions = new ArrayList<Action>();
153 flow.setActions(actions);
154 flow.setPriority((short) 3500);
155 flow.setIdleTimeout((short) 1000);
156 flow.setHardTimeout((short) 2000);
159 FlowOnNode fn1 = new FlowOnNode(flow);
160 fn1.setByteCount(100);
161 fn1.setDurationNanoseconds(400);
162 fn1.setDurationSeconds(40);
163 fn1.setTableId((byte) 0x1);
164 fn1.setPacketCount(200);
172 public NodeDescription readDescription(Node node, boolean cached) {
173 NodeDescription desc = new NodeDescription();
174 desc.setDescription("This is a sample node description");
175 desc.setHardware("stub hardware");
176 desc.setSoftware("stub software");
177 desc.setSerialNumber("123");
178 desc.setManufacturer("opendaylight");
183 public NodeConnectorStatistics readNodeConnector(NodeConnector connector,
185 NodeConnectorStatistics stats = new NodeConnectorStatistics();
186 stats.setNodeConnector(connector);
187 stats.setCollisionCount(4);
188 stats.setReceiveByteCount(1000);
189 stats.setReceiveCRCErrorCount(1);
190 stats.setReceiveDropCount(2);
191 stats.setReceiveErrorCount(3);
192 stats.setReceiveFrameErrorCount(5);
193 stats.setReceiveOverRunErrorCount(6);
194 stats.setReceivePacketCount(250);
195 stats.setTransmitByteCount(5000);
196 stats.setTransmitDropCount(50);
197 stats.setTransmitErrorCount(10);
198 stats.setTransmitPacketCount(500);
204 public List<NodeConnectorStatistics> readAllNodeConnector(Node node,
206 NodeConnectorStatistics stats = new NodeConnectorStatistics();
208 NodeConnector nc = new NodeConnector("STUB", 0xCAFE, node);
209 stats.setNodeConnector(nc);
210 } catch (ConstructionException e) {
211 // couldn't create nodeconnector.
213 stats.setCollisionCount(4);
214 stats.setReceiveByteCount(1000);
215 stats.setReceiveCRCErrorCount(1);
216 stats.setReceiveDropCount(2);
217 stats.setReceiveErrorCount(3);
218 stats.setReceiveFrameErrorCount(5);
219 stats.setReceiveOverRunErrorCount(6);
220 stats.setReceivePacketCount(250);
221 stats.setTransmitByteCount(5000);
222 stats.setTransmitDropCount(50);
223 stats.setTransmitErrorCount(10);
224 stats.setTransmitPacketCount(500);
226 List<NodeConnectorStatistics> result = new ArrayList<NodeConnectorStatistics>();
232 public long getTransmitRate(NodeConnector connector) {