2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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 package org.opendaylight.controller.protocol_plugins.stub.internal;
10 import java.net.InetAddress;
11 import java.net.UnknownHostException;
12 import java.util.ArrayList;
13 import java.util.List;
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;
52 * Stub Implementation for IPluginInReadService used by SAL
56 public class ReadService implements IPluginInReadService {
57 private static final Logger logger = LoggerFactory
58 .getLogger(ReadService.class);
61 * Function called by the dependency manager when all the required
62 * dependencies are satisfied
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.
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
86 * Function called by the dependency manager before the services exported by
87 * the component are unregistered, this will be followed by a "destroy ()"
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);
106 public List<FlowOnNode> readAllFlow(Node node, boolean cached) {
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());
118 actionList.add(new Output(new NodeConnector("STUB", 0xCAFE, node)));
119 } catch (ConstructionException e) {
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));
128 actionList.add(new SetVlanId(2));
129 actionList.add(new SetVlanPcp(3));
130 actionList.add(new SetVlanCfi(1));
132 actionList.add(new PopVlan());
133 actionList.add(new PushVlan(0x8100, 1, 1, 1234));
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) {
141 actionList.add(new SetNwTos(0x10));
142 actionList.add(new SetTpSrc(4201));
143 actionList.add(new SetTpDst(8080));
145 short priority = 3500; //IT assumes this value
146 for (Action a : actionList) {
147 Flow flow = new Flow();
148 Match match = new Match();
150 match.setField(MatchType.NW_DST,
151 InetAddress.getByName("1.1.1.1"));
152 } catch (UnknownHostException e) {
155 flow.setMatch(match);
156 List<Action> actions = new ArrayList<Action>();
158 flow.setActions(actions);
159 flow.setPriority(priority++);
160 flow.setIdleTimeout((short) 1000);
161 flow.setHardTimeout((short) 2000);
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);
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");
188 public NodeConnectorStatistics readNodeConnector(NodeConnector connector,
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);
209 public List<NodeConnectorStatistics> readAllNodeConnector(Node node,
211 NodeConnectorStatistics stats = new NodeConnectorStatistics();
213 NodeConnector nc = new NodeConnector("STUB", 0xCAFE, node);
214 stats.setNodeConnector(nc);
215 } catch (ConstructionException e) {
216 // couldn't create nodeconnector.
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);
231 List<NodeConnectorStatistics> result = new ArrayList<NodeConnectorStatistics>();
237 public long getTransmitRate(NodeConnector connector) {
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);
253 public List<NodeTableStatistics> readAllNodeTable(Node node, boolean cached) {
254 NodeTableStatistics stats = new NodeTableStatistics();
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.
262 stats.setActiveCount(4);
263 stats.setLookupCount(4);
264 stats.setMatchedCount(4);
266 List<NodeTableStatistics> result = new ArrayList<NodeTableStatistics>();