blob: e3ded96b43cbc901f1762320aa6d65dafc0eb377 [file] [log] [blame]
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08001package net.floodlightcontroller.util;
2
Jonathan Harta88fd242014-04-03 11:24:54 -07003import static org.junit.Assert.assertEquals;
4import static org.junit.Assert.assertNotNull;
5import static org.junit.Assert.assertNull;
6import static org.junit.Assert.assertTrue;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08007
Jonathan Harta88fd242014-04-03 11:24:54 -07008import java.io.IOException;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -08009import java.util.Collection;
10import java.util.Date;
11import java.util.List;
12import java.util.Map;
13import java.util.concurrent.Future;
14
15import net.floodlightcontroller.core.FloodlightContext;
Jonathan Harta88fd242014-04-03 11:24:54 -070016import net.floodlightcontroller.core.IFloodlightProviderService.Role;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080017import net.floodlightcontroller.core.IOFMessageListener;
18import net.floodlightcontroller.core.IOFSwitch;
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080019
20import org.jboss.netty.channel.Channel;
21import org.openflow.protocol.OFFeaturesReply;
22import org.openflow.protocol.OFMessage;
23import org.openflow.protocol.OFPhysicalPort;
24import org.openflow.protocol.OFStatisticsRequest;
25import org.openflow.protocol.statistics.OFDescriptionStatistics;
26import org.openflow.protocol.statistics.OFStatistics;
27
28
29/**
30 * A mock implementation of IFOSwitch we use for {@link OFMessageDamper}
31 *
32 * We need to mock equals() and hashCode() but alas, EasyMock doesn't support
33 * this. Sigh. And of course this happens to be the interface with the most
34 * methods.
35 * @author gregor
36 *
37 */
38public class OFMessageDamperMockSwitch implements IOFSwitch {
39 OFMessage writtenMessage;
40 FloodlightContext writtenContext;
41
42 public OFMessageDamperMockSwitch() {
43 reset();
44 }
45
46 /* reset this mock. I.e., clear the stored message previously written */
47 public void reset() {
48 writtenMessage = null;
49 writtenContext = null;
50 }
51
52 /* assert that a message was written to this switch and that the
53 * written message and context matches the expected values
54 * @param expected
55 * @param expectedContext
56 */
57 public void assertMessageWasWritten(OFMessage expected,
58 FloodlightContext expectedContext) {
59 assertNotNull("No OFMessage was written", writtenMessage);
60 assertEquals(expected, writtenMessage);
61 assertEquals(expectedContext, writtenContext);
62 }
63
64 /*
65 * assert that no message was written
66 */
67 public void assertNoMessageWritten() {
68 assertNull("OFMessage was written but didn't expect one",
69 writtenMessage);
70 assertNull("There was a context but didn't expect one",
71 writtenContext);
72 }
73
74 /*
75 * use hashCode() and equals() from Object
76 */
77
78
79 //-------------------------------------------------------
80 // IOFSwitch: mocked methods
81 @Override
82 public void write(OFMessage m, FloodlightContext bc) throws IOException {
83 assertNull("write() called but already have message", writtenMessage);
84 assertNull("write() called but already have context", writtenContext);
85 writtenContext = bc;
86 writtenMessage = m;
87 }
88
89 //-------------------------------------------------------
90 // IOFSwitch: not-implemented methods
91 @Override
92 public void write(List<OFMessage> msglist, FloodlightContext bc)
93 throws IOException {
94 assertTrue("Unexpected method call", false);
95 }
96
97 @Override
98 public void disconnectOutputStream() {
99 assertTrue("Unexpected method call", false);
100 }
101
102 @Override
103 public Channel getChannel() {
104 assertTrue("Unexpected method call", false);
105 return null;
106 }
107
108 @Override
109 public void setFeaturesReply(OFFeaturesReply featuresReply) {
110 assertTrue("Unexpected method call", false);
111 }
112
113 @Override
114 public void setSwitchProperties(OFDescriptionStatistics description) {
115 assertTrue("Unexpected method call", false);
116 // TODO Auto-generated method stub
117 }
118
119 @Override
120 public Collection<OFPhysicalPort> getEnabledPorts() {
121 assertTrue("Unexpected method call", false);
122 return null;
123 }
124
125 @Override
126 public Collection<Short> getEnabledPortNumbers() {
127 assertTrue("Unexpected method call", false);
128 return null;
129 }
130
131 @Override
132 public OFPhysicalPort getPort(short portNumber) {
133 assertTrue("Unexpected method call", false);
134 return null;
135 }
136
137 @Override
138 public OFPhysicalPort getPort(String portName) {
139 assertTrue("Unexpected method call", false);
140 return null;
141 }
142
143 @Override
144 public void setPort(OFPhysicalPort port) {
145 assertTrue("Unexpected method call", false);
146 }
147
148 @Override
149 public void deletePort(short portNumber) {
150 assertTrue("Unexpected method call", false);
151 }
152
153 @Override
154 public void deletePort(String portName) {
155 assertTrue("Unexpected method call", false);
156 }
157
158 @Override
159 public Collection<OFPhysicalPort> getPorts() {
160 assertTrue("Unexpected method call", false);
161 return null;
162 }
163
164 @Override
165 public boolean portEnabled(short portName) {
166 assertTrue("Unexpected method call", false);
167 return false;
168 }
169
170 @Override
171 public boolean portEnabled(String portName) {
172 assertTrue("Unexpected method call", false);
173 return false;
174 }
175
176 @Override
177 public boolean portEnabled(OFPhysicalPort port) {
178 assertTrue("Unexpected method call", false);
179 return false;
180 }
181
182 @Override
183 public long getId() {
184 assertTrue("Unexpected method call", false);
185 return 0;
186 }
187
188 @Override
189 public String getStringId() {
190 assertTrue("Unexpected method call", false);
191 return null;
192 }
193
194 @Override
195 public Map<Object, Object> getAttributes() {
196 assertTrue("Unexpected method call", false);
197 return null;
198 }
199
200 @Override
201 public Date getConnectedSince() {
202 assertTrue("Unexpected method call", false);
203 return null;
204 }
205
206 @Override
207 public int getNextTransactionId() {
208 assertTrue("Unexpected method call", false);
209 return 0;
210 }
211
212 @Override
213 public Future<List<OFStatistics>>
214 getStatistics(OFStatisticsRequest request) throws IOException {
215 assertTrue("Unexpected method call", false);
216 return null;
217 }
218
219 @Override
220 public boolean isConnected() {
221 assertTrue("Unexpected method call", false);
222 return false;
223 }
224
225 @Override
226 public void setConnected(boolean connected) {
227 assertTrue("Unexpected method call", false);
228 }
229
230 @Override
231 public Role getRole() {
232 assertTrue("Unexpected method call", false);
233 return null;
234 }
235
236 @Override
237 public boolean isActive() {
238 assertTrue("Unexpected method call", false);
239 return false;
240 }
241
242 @Override
243 public void deliverStatisticsReply(OFMessage reply) {
244 assertTrue("Unexpected method call", false);
245 }
246
247 @Override
248 public void cancelStatisticsReply(int transactionId) {
249 assertTrue("Unexpected method call", false);
250 }
251
252 @Override
253 public void cancelAllStatisticsReplies() {
254 assertTrue("Unexpected method call", false);
255 }
256
257 @Override
258 public boolean hasAttribute(String name) {
259 assertTrue("Unexpected method call", false);
260 return false;
261 }
262
263 @Override
264 public Object getAttribute(String name) {
265 assertTrue("Unexpected method call", false);
266 return null;
267 }
268
269 @Override
270 public void setAttribute(String name, Object value) {
271 assertTrue("Unexpected method call", false);
272 }
273
274 @Override
275 public Object removeAttribute(String name) {
276 assertTrue("Unexpected method call", false);
277 return null;
278 }
279
280 @Override
281 public void clearAllFlowMods() {
282 assertTrue("Unexpected method call", false);
283 }
284
285 @Override
286 public boolean updateBroadcastCache(Long entry, Short port) {
287 assertTrue("Unexpected method call", false);
288 return false;
289 }
290
291 @Override
292 public Map<Short, Long> getPortBroadcastHits() {
293 assertTrue("Unexpected method call", false);
294 return null;
295 }
296
297 @Override
298 public void sendStatsQuery(OFStatisticsRequest request, int xid,
299 IOFMessageListener caller)
300 throws IOException {
301 assertTrue("Unexpected method call", false);
302 }
303
304 @Override
305 public void flush() {
306 assertTrue("Unexpected method call", false);
307 }
308
309 @Override
310 public Future<OFFeaturesReply> getFeaturesReplyFromSwitch()
311 throws IOException {
312 // TODO Auto-generated method stub
313 return null;
314 }
315
316 @Override
317 public void deliverOFFeaturesReply(OFMessage reply) {
318 // TODO Auto-generated method stub
319
320 }
321
322 @Override
323 public void cancelFeaturesReply(int transactionId) {
324 // TODO Auto-generated method stub
325
326 }
327
328 @Override
329 public int getBuffers() {
330 // TODO Auto-generated method stub
331 return 0;
332 }
333
334 @Override
335 public int getActions() {
336 // TODO Auto-generated method stub
337 return 0;
338 }
339
340 @Override
341 public int getCapabilities() {
342 // TODO Auto-generated method stub
343 return 0;
344 }
345
346 @Override
347 public byte getTables() {
348 // TODO Auto-generated method stub
349 return 0;
350 }
351
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800352}