Merge "Refactored yang-maven-plugin. Updated tests. Removed backup files."
[controller.git] / opendaylight / protocol_plugins / stub / src / main / java / org / opendaylight / controller / protocol_plugins / stub / internal / ReadService.java
1 package org.opendaylight.controller.protocol_plugins.stub.internal;
2
3 import java.net.InetAddress;
4 import java.net.UnknownHostException;
5 import java.util.ArrayList;
6 import java.util.Dictionary;
7 import java.util.List;
8
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;
13
14 import org.opendaylight.controller.sal.action.Action;
15 import org.opendaylight.controller.sal.action.Drop;
16 import org.opendaylight.controller.sal.core.ConstructionException;
17 import org.opendaylight.controller.sal.core.Node;
18 import org.opendaylight.controller.sal.core.NodeConnector;
19 import org.opendaylight.controller.sal.flowprogrammer.Flow;
20 import org.opendaylight.controller.sal.match.Match;
21 import org.opendaylight.controller.sal.match.MatchType;
22 import org.opendaylight.controller.sal.reader.FlowOnNode;
23 import org.opendaylight.controller.sal.reader.IPluginInReadService;
24 import org.opendaylight.controller.sal.reader.NodeConnectorStatistics;
25 import org.opendaylight.controller.sal.reader.NodeDescription;
26
27 /**
28  * Stub Implementation for IPluginInReadService used by SAL
29  * 
30  * 
31  */
32 public class ReadService implements IPluginInReadService {
33     private static final Logger logger = LoggerFactory
34             .getLogger(ReadService.class);
35
36     /**
37      * Function called by the dependency manager when all the required
38      * dependencies are satisfied
39      * 
40      */
41     void init() {
42     }
43
44     /**
45      * Function called by the dependency manager when at least one dependency
46      * become unsatisfied or when the component is shutting down because for
47      * example bundle is being stopped.
48      * 
49      */
50     void destroy() {
51     }
52
53     /**
54      * Function called by dependency manager after "init ()" is called and after
55      * the services provided by the class are registered in the service registry
56      * 
57      */
58     void start() {
59     }
60
61     /**
62      * Function called by the dependency manager before the services exported by
63      * the component are unregistered, this will be followed by a "destroy ()"
64      * calls
65      * 
66      */
67     void stop() {
68     }
69
70     @Override
71     public FlowOnNode readFlow(Node node, Flow flow, boolean cached) {
72         FlowOnNode fn1 = new FlowOnNode(flow);
73         fn1.setByteCount(100);
74         fn1.setDurationNanoseconds(400);
75         fn1.setDurationSeconds(40);
76         fn1.setTableId((byte) 0x1);
77         fn1.setPacketCount(200);
78         return fn1;
79     }
80
81     @Override
82     public List<FlowOnNode> readAllFlow(Node node, boolean cached) {
83         Flow flow = new Flow();
84
85         Match match = new Match();
86         try {
87             match.setField(MatchType.NW_DST, InetAddress.getByName("1.1.1.1"));
88         } catch (UnknownHostException e) {
89
90         }
91         flow.setMatch(match);
92         Action action = new Drop();
93
94         List<Action> actions = new ArrayList<Action>();
95         actions.add(action);
96         flow.setActions(actions);
97         flow.setPriority((short)3500);
98         flow.setIdleTimeout((short)1000);
99         flow.setHardTimeout((short)2000);
100         flow.setId(12345);
101         
102         FlowOnNode fn1 = new FlowOnNode(flow);
103         fn1.setByteCount(100);
104         fn1.setDurationNanoseconds(400);
105         fn1.setDurationSeconds(40);
106         fn1.setTableId((byte) 0x1);
107         fn1.setPacketCount(200);
108
109         ArrayList<FlowOnNode> list = new ArrayList<FlowOnNode>();
110         list.add(fn1);
111         return list;
112     }
113
114     @Override
115     public NodeDescription readDescription(Node node, boolean cached) {
116         NodeDescription desc = new NodeDescription();
117         desc.setDescription("This is a sample node description");
118         desc.setHardware("stub hardware");
119         desc.setSoftware("stub software");
120         desc.setSerialNumber("123");
121         desc.setManufacturer("opendaylight");
122         return desc;
123     }
124
125     @Override
126     public NodeConnectorStatistics readNodeConnector(NodeConnector connector,
127             boolean cached) {
128         NodeConnectorStatistics stats = new NodeConnectorStatistics();
129         stats.setNodeConnector(connector);
130         stats.setCollisionCount(4);
131         stats.setReceiveByteCount(1000);
132         stats.setReceiveCRCErrorCount(1);
133         stats.setReceiveDropCount(2);
134         stats.setReceiveErrorCount(3);
135         stats.setReceiveFrameErrorCount(5);
136         stats.setReceiveOverRunErrorCount(6);
137         stats.setReceivePacketCount(250);
138         stats.setTransmitByteCount(5000);
139         stats.setTransmitDropCount(50);
140         stats.setTransmitErrorCount(10);
141         stats.setTransmitPacketCount(500);
142
143         return stats;
144     }
145
146     @Override
147     public List<NodeConnectorStatistics> readAllNodeConnector(Node node,
148             boolean cached) {
149         NodeConnectorStatistics stats = new NodeConnectorStatistics();
150         try{
151             NodeConnector nc = new NodeConnector("STUB", 0xCAFE, node);
152             stats.setNodeConnector(nc);
153         }catch(ConstructionException e){
154             //couldn't create nodeconnector.
155         }
156         stats.setCollisionCount(4);
157         stats.setReceiveByteCount(1000);
158         stats.setReceiveCRCErrorCount(1);
159         stats.setReceiveDropCount(2);
160         stats.setReceiveErrorCount(3);
161         stats.setReceiveFrameErrorCount(5);
162         stats.setReceiveOverRunErrorCount(6);
163         stats.setReceivePacketCount(250);
164         stats.setTransmitByteCount(5000);
165         stats.setTransmitDropCount(50);
166         stats.setTransmitErrorCount(10);
167         stats.setTransmitPacketCount(500);
168
169         List<NodeConnectorStatistics> result = new ArrayList<NodeConnectorStatistics>();
170         result.add(stats);
171         return result;
172     }
173
174     @Override
175     public long getTransmitRate(NodeConnector connector) {
176         return 100;
177     }
178
179 }