1 package org.opendaylight.controller.protocol_plugins.stub.internal;
3 import java.net.InetAddress;
4 import java.net.UnknownHostException;
5 import java.util.ArrayList;
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;
45 * Stub Implementation for IPluginInReadService used by SAL
49 public class ReadService implements IPluginInReadService {
50 private static final Logger logger = LoggerFactory
51 .getLogger(ReadService.class);
54 * Function called by the dependency manager when all the required
55 * dependencies are satisfied
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.
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
79 * Function called by the dependency manager before the services exported by
80 * the component are unregistered, this will be followed by a "destroy ()"
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);
99 public List<FlowOnNode> readAllFlow(Node node, boolean cached) {
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());
111 actionList.add(new Output(new NodeConnector("STUB", 0xCAFE, node)));
112 } catch (ConstructionException e) {
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));
121 actionList.add(new SetVlanId(2));
122 actionList.add(new SetVlanPcp(3));
123 actionList.add(new SetVlanCfi(1));
125 actionList.add(new PopVlan());
126 actionList.add(new PushVlan(0x8100, 1, 1, 1234));
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) {
134 actionList.add(new SetNwTos(0x10));
135 actionList.add(new SetTpSrc(4201));
136 actionList.add(new SetTpDst(8080));
138 short priority = 3500; //IT assumes this value
139 for (Action a : actionList) {
140 Flow flow = new Flow();
141 Match match = new Match();
143 match.setField(MatchType.NW_DST,
144 InetAddress.getByName("1.1.1.1"));
145 } catch (UnknownHostException e) {
148 flow.setMatch(match);
149 List<Action> actions = new ArrayList<Action>();
151 flow.setActions(actions);
152 flow.setPriority(priority++);
153 flow.setIdleTimeout((short) 1000);
154 flow.setHardTimeout((short) 2000);
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);
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");
181 public NodeConnectorStatistics readNodeConnector(NodeConnector connector,
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);
202 public List<NodeConnectorStatistics> readAllNodeConnector(Node node,
204 NodeConnectorStatistics stats = new NodeConnectorStatistics();
206 NodeConnector nc = new NodeConnector("STUB", 0xCAFE, node);
207 stats.setNodeConnector(nc);
208 } catch (ConstructionException e) {
209 // couldn't create nodeconnector.
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);
224 List<NodeConnectorStatistics> result = new ArrayList<NodeConnectorStatistics>();
230 public long getTransmitRate(NodeConnector connector) {
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);
246 public List<NodeTableStatistics> readAllNodeTable(Node node, boolean cached) {
247 NodeTableStatistics stats = new NodeTableStatistics();
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.
255 stats.setActiveCount(4);
256 stats.setLookupCount(4);
257 stats.setMatchedCount(4);
259 List<NodeTableStatistics> result = new ArrayList<NodeTableStatistics>();