2 * [[ Authors will Fill in the Copyright header ]]
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
8 * Authors : Brent Salisbury, Evan Zeller
10 package org.opendaylight.ovsdb.plugin;
12 import java.net.InetAddress;
13 import java.net.UnknownHostException;
14 import java.util.ArrayList;
15 import java.util.List;
17 import org.opendaylight.controller.sal.action.Action;
18 import org.opendaylight.controller.sal.action.Controller;
19 import org.opendaylight.controller.sal.action.Drop;
20 import org.opendaylight.controller.sal.action.Flood;
21 import org.opendaylight.controller.sal.action.FloodAll;
22 import org.opendaylight.controller.sal.action.HwPath;
23 import org.opendaylight.controller.sal.action.Loopback;
24 import org.opendaylight.controller.sal.action.Output;
25 import org.opendaylight.controller.sal.action.PopVlan;
26 import org.opendaylight.controller.sal.action.PushVlan;
27 import org.opendaylight.controller.sal.action.SetDlDst;
28 import org.opendaylight.controller.sal.action.SetDlSrc;
29 import org.opendaylight.controller.sal.action.SetDlType;
30 import org.opendaylight.controller.sal.action.SetNwDst;
31 import org.opendaylight.controller.sal.action.SetNwSrc;
32 import org.opendaylight.controller.sal.action.SetNwTos;
33 import org.opendaylight.controller.sal.action.SetTpDst;
34 import org.opendaylight.controller.sal.action.SetTpSrc;
35 import org.opendaylight.controller.sal.action.SetVlanCfi;
36 import org.opendaylight.controller.sal.action.SetVlanId;
37 import org.opendaylight.controller.sal.action.SetVlanPcp;
38 import org.opendaylight.controller.sal.action.SwPath;
39 import org.opendaylight.controller.sal.core.ConstructionException;
40 import org.opendaylight.controller.sal.core.Node;
41 import org.opendaylight.controller.sal.core.NodeConnector;
42 import org.opendaylight.controller.sal.core.NodeTable;
43 import org.opendaylight.controller.sal.flowprogrammer.Flow;
44 import org.opendaylight.controller.sal.match.Match;
45 import org.opendaylight.controller.sal.match.MatchType;
46 import org.opendaylight.controller.sal.reader.FlowOnNode;
47 import org.opendaylight.controller.sal.reader.IPluginInReadService;
48 import org.opendaylight.controller.sal.reader.NodeConnectorStatistics;
49 import org.opendaylight.controller.sal.reader.NodeDescription;
50 import org.opendaylight.controller.sal.reader.NodeTableStatistics;
51 import org.slf4j.Logger;
52 import org.slf4j.LoggerFactory;
54 * Stub Implementation for IPluginInReadService used by SAL
58 public class ReadService implements IPluginInReadService {
59 private static final Logger logger = LoggerFactory
60 .getLogger(ReadService.class);
63 * Function called by the dependency manager when all the required
64 * dependencies are satisfied
71 * Function called by the dependency manager when at least one dependency
72 * become unsatisfied or when the component is shutting down because for
73 * example bundle is being stopped.
80 * Function called by dependency manager after "init ()" is called and after
81 * the services provided by the class are registered in the service registry
88 * Function called by the dependency manager before the services exported by
89 * the component are unregistered, this will be followed by a "destroy ()"
97 public FlowOnNode readFlow(Node node, Flow flow, boolean cached) {
98 FlowOnNode fn1 = new FlowOnNode(flow);
99 fn1.setByteCount(100);
100 fn1.setDurationNanoseconds(400);
101 fn1.setDurationSeconds(40);
102 fn1.setTableId((byte) 0x1);
103 fn1.setPacketCount(200);
108 public List<FlowOnNode> readAllFlow(Node node, boolean cached) {
110 ArrayList<FlowOnNode> list = new ArrayList<FlowOnNode>();
111 ArrayList<Action> actionList = new ArrayList<Action>();
112 actionList.add(new Drop()); //IT assumes this is first element
113 actionList.add(new Loopback());
114 actionList.add(new Flood());
115 actionList.add(new FloodAll());
116 actionList.add(new Controller());
117 actionList.add(new SwPath());
118 actionList.add(new HwPath());
120 actionList.add(new Output(new NodeConnector("STUB", 0xCAFE, node)));
121 } catch (ConstructionException e) {
124 byte dst[] = { (byte) 1, (byte) 2, (byte) 3, (byte) 4, (byte) 5 };
125 byte src[] = { (byte) 5, (byte) 4, (byte) 3, (byte) 2, (byte) 1 };
126 actionList.add(new SetDlSrc(src));
127 actionList.add(new SetDlDst(dst));
128 actionList.add(new SetDlType(10));
130 actionList.add(new SetVlanId(2));
131 actionList.add(new SetVlanPcp(3));
132 actionList.add(new SetVlanCfi(1));
134 actionList.add(new PopVlan());
135 actionList.add(new PushVlan(0x8100, 1, 1, 1234));
138 actionList.add(new SetNwSrc(InetAddress.getByName("2.2.2.2")));
139 actionList.add(new SetNwDst(InetAddress.getByName("1.1.1.1")));
140 } catch (UnknownHostException e) {
143 actionList.add(new SetNwTos(0x10));
144 actionList.add(new SetTpSrc(4201));
145 actionList.add(new SetTpDst(8080));
147 short priority = 3500; //IT assumes this value
148 for (Action a : actionList) {
149 Flow flow = new Flow();
150 Match match = new Match();
152 match.setField(MatchType.NW_DST,
153 InetAddress.getByName("1.1.1.1"));
154 } catch (UnknownHostException e) {
157 flow.setMatch(match);
158 List<Action> actions = new ArrayList<Action>();
160 flow.setActions(actions);
161 flow.setPriority(priority++);
162 flow.setIdleTimeout((short) 1000);
163 flow.setHardTimeout((short) 2000);
166 FlowOnNode fn1 = new FlowOnNode(flow);
167 fn1.setByteCount(100);
168 fn1.setDurationNanoseconds(400);
169 fn1.setDurationSeconds(40);
170 fn1.setTableId((byte) 0x1);
171 fn1.setPacketCount(200);
179 public NodeDescription readDescription(Node node, boolean cached) {
180 NodeDescription desc = new NodeDescription();
181 desc.setDescription("This is a sample node description");
182 desc.setHardware("stub hardware");
183 desc.setSoftware("stub software");
184 desc.setSerialNumber("123");
185 desc.setManufacturer("opendaylight");
190 public NodeConnectorStatistics readNodeConnector(NodeConnector connector,
192 NodeConnectorStatistics stats = new NodeConnectorStatistics();
193 stats.setNodeConnector(connector);
194 stats.setCollisionCount(4);
195 stats.setReceiveByteCount(1000);
196 stats.setReceiveCRCErrorCount(1);
197 stats.setReceiveDropCount(2);
198 stats.setReceiveErrorCount(3);
199 stats.setReceiveFrameErrorCount(5);
200 stats.setReceiveOverRunErrorCount(6);
201 stats.setReceivePacketCount(250);
202 stats.setTransmitByteCount(5000);
203 stats.setTransmitDropCount(50);
204 stats.setTransmitErrorCount(10);
205 stats.setTransmitPacketCount(500);
211 public List<NodeConnectorStatistics> readAllNodeConnector(Node node,
213 NodeConnectorStatistics stats = new NodeConnectorStatistics();
215 NodeConnector nc = new NodeConnector("STUB", 0xCAFE, node);
216 stats.setNodeConnector(nc);
217 } catch (ConstructionException e) {
218 // couldn't create nodeconnector.
220 stats.setCollisionCount(4);
221 stats.setReceiveByteCount(1000);
222 stats.setReceiveCRCErrorCount(1);
223 stats.setReceiveDropCount(2);
224 stats.setReceiveErrorCount(3);
225 stats.setReceiveFrameErrorCount(5);
226 stats.setReceiveOverRunErrorCount(6);
227 stats.setReceivePacketCount(250);
228 stats.setTransmitByteCount(5000);
229 stats.setTransmitDropCount(50);
230 stats.setTransmitErrorCount(10);
231 stats.setTransmitPacketCount(500);
233 List<NodeConnectorStatistics> result = new ArrayList<NodeConnectorStatistics>();
239 public long getTransmitRate(NodeConnector connector) {
244 public NodeTableStatistics readNodeTable(NodeTable table, boolean b) {
245 NodeTableStatistics stats = new NodeTableStatistics();
246 stats.setNodeTable(table);
247 stats.setActiveCount(4);
248 stats.setLookupCount(4);
249 stats.setMatchedCount(4);
255 public List<NodeTableStatistics> readAllNodeTable(Node node, boolean cached) {
256 NodeTableStatistics stats = new NodeTableStatistics();
258 NodeTable nt = new NodeTable(NodeTable.NodeTableIDType.OPENFLOW, Byte.valueOf("10"), node);
259 stats.setNodeTable(nt);
260 } catch (ConstructionException e) {
261 // couldn't create nodetable.
264 stats.setActiveCount(4);
265 stats.setLookupCount(4);
266 stats.setMatchedCount(4);
268 List<NodeTableStatistics> result = new ArrayList<NodeTableStatistics>();