blob: 574dc23434388fa3772e3e88de7ffbd613bccaa3 [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}
Ray Milkey269ffb92014-04-03 14:43:30 -070031 * <p/>
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080032 * 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
Ray Milkey269ffb92014-04-03 14:43:30 -070034 * methods.
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080035 *
Ray Milkey269ffb92014-04-03 14:43:30 -070036 * @author gregor
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080037 */
38public class OFMessageDamperMockSwitch implements IOFSwitch {
39 OFMessage writtenMessage;
40 FloodlightContext writtenContext;
Ray Milkey269ffb92014-04-03 14:43:30 -070041
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080042 public OFMessageDamperMockSwitch() {
43 reset();
44 }
Ray Milkey269ffb92014-04-03 14:43:30 -070045
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080046 /* reset this mock. I.e., clear the stored message previously written */
47 public void reset() {
48 writtenMessage = null;
49 writtenContext = null;
50 }
Ray Milkey269ffb92014-04-03 14:43:30 -070051
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080052 /* 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 */
Ray Milkey269ffb92014-04-03 14:43:30 -070057 public void assertMessageWasWritten(OFMessage expected,
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080058 FloodlightContext expectedContext) {
59 assertNotNull("No OFMessage was written", writtenMessage);
60 assertEquals(expected, writtenMessage);
61 assertEquals(expectedContext, writtenContext);
62 }
Ray Milkey269ffb92014-04-03 14:43:30 -070063
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080064 /*
65 * assert that no message was written
66 */
67 public void assertNoMessageWritten() {
Ray Milkey269ffb92014-04-03 14:43:30 -070068 assertNull("OFMessage was written but didn't expect one",
69 writtenMessage);
70 assertNull("There was a context but didn't expect one",
71 writtenContext);
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080072 }
73
74 /*
75 * use hashCode() and equals() from Object
76 */
Ray Milkey269ffb92014-04-03 14:43:30 -070077
78
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080079 //-------------------------------------------------------
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 }
Ray Milkey269ffb92014-04-03 14:43:30 -070088
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080089 //-------------------------------------------------------
90 // IOFSwitch: not-implemented methods
91 @Override
Ray Milkey269ffb92014-04-03 14:43:30 -070092 public void write(List<OFMessage> msglist, FloodlightContext bc)
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080093 throws IOException {
94 assertTrue("Unexpected method call", false);
95 }
Ray Milkey269ffb92014-04-03 14:43:30 -070096
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -080097 @Override
98 public void disconnectOutputStream() {
99 assertTrue("Unexpected method call", false);
100 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700101
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800102 @Override
103 public Channel getChannel() {
104 assertTrue("Unexpected method call", false);
105 return null;
106 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700107
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800108 @Override
109 public void setFeaturesReply(OFFeaturesReply featuresReply) {
110 assertTrue("Unexpected method call", false);
111 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700112
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800113 @Override
114 public void setSwitchProperties(OFDescriptionStatistics description) {
115 assertTrue("Unexpected method call", false);
116 // TODO Auto-generated method stub
117 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700118
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800119 @Override
120 public Collection<OFPhysicalPort> getEnabledPorts() {
121 assertTrue("Unexpected method call", false);
122 return null;
123 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700124
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800125 @Override
126 public Collection<Short> getEnabledPortNumbers() {
127 assertTrue("Unexpected method call", false);
128 return null;
129 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700130
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800131 @Override
132 public OFPhysicalPort getPort(short portNumber) {
133 assertTrue("Unexpected method call", false);
134 return null;
135 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700136
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800137 @Override
138 public OFPhysicalPort getPort(String portName) {
139 assertTrue("Unexpected method call", false);
140 return null;
141 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700142
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800143 @Override
144 public void setPort(OFPhysicalPort port) {
145 assertTrue("Unexpected method call", false);
146 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700147
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800148 @Override
149 public void deletePort(short portNumber) {
150 assertTrue("Unexpected method call", false);
151 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700152
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800153 @Override
154 public void deletePort(String portName) {
155 assertTrue("Unexpected method call", false);
156 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700157
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800158 @Override
159 public Collection<OFPhysicalPort> getPorts() {
160 assertTrue("Unexpected method call", false);
161 return null;
162 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700163
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800164 @Override
165 public boolean portEnabled(short portName) {
166 assertTrue("Unexpected method call", false);
167 return false;
168 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700169
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800170 @Override
171 public boolean portEnabled(String portName) {
172 assertTrue("Unexpected method call", false);
173 return false;
174 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700175
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800176 @Override
177 public boolean portEnabled(OFPhysicalPort port) {
178 assertTrue("Unexpected method call", false);
179 return false;
180 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700181
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800182 @Override
183 public long getId() {
184 assertTrue("Unexpected method call", false);
185 return 0;
186 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700187
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800188 @Override
189 public String getStringId() {
190 assertTrue("Unexpected method call", false);
191 return null;
192 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700193
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800194 @Override
195 public Map<Object, Object> getAttributes() {
196 assertTrue("Unexpected method call", false);
197 return null;
198 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700199
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800200 @Override
201 public Date getConnectedSince() {
202 assertTrue("Unexpected method call", false);
203 return null;
204 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700205
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800206 @Override
207 public int getNextTransactionId() {
208 assertTrue("Unexpected method call", false);
209 return 0;
210 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700211
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800212 @Override
213 public Future<List<OFStatistics>>
Ray Milkey269ffb92014-04-03 14:43:30 -0700214 getStatistics(OFStatisticsRequest request) throws IOException {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800215 assertTrue("Unexpected method call", false);
216 return null;
217 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700218
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800219 @Override
220 public boolean isConnected() {
221 assertTrue("Unexpected method call", false);
222 return false;
223 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700224
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800225 @Override
226 public void setConnected(boolean connected) {
227 assertTrue("Unexpected method call", false);
228 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700229
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800230 @Override
231 public Role getRole() {
232 assertTrue("Unexpected method call", false);
233 return null;
234 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700235
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800236 @Override
237 public boolean isActive() {
238 assertTrue("Unexpected method call", false);
239 return false;
240 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700241
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800242 @Override
243 public void deliverStatisticsReply(OFMessage reply) {
244 assertTrue("Unexpected method call", false);
245 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700246
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800247 @Override
248 public void cancelStatisticsReply(int transactionId) {
249 assertTrue("Unexpected method call", false);
250 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700251
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800252 @Override
253 public void cancelAllStatisticsReplies() {
254 assertTrue("Unexpected method call", false);
255 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700256
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800257 @Override
258 public boolean hasAttribute(String name) {
259 assertTrue("Unexpected method call", false);
260 return false;
261 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700262
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800263 @Override
264 public Object getAttribute(String name) {
265 assertTrue("Unexpected method call", false);
266 return null;
267 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700268
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800269 @Override
270 public void setAttribute(String name, Object value) {
271 assertTrue("Unexpected method call", false);
272 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700273
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800274 @Override
275 public Object removeAttribute(String name) {
276 assertTrue("Unexpected method call", false);
277 return null;
278 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700279
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800280 @Override
281 public void clearAllFlowMods() {
282 assertTrue("Unexpected method call", false);
283 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700284
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800285 @Override
286 public boolean updateBroadcastCache(Long entry, Short port) {
287 assertTrue("Unexpected method call", false);
288 return false;
289 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700290
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800291 @Override
292 public Map<Short, Long> getPortBroadcastHits() {
293 assertTrue("Unexpected method call", false);
294 return null;
295 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700296
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800297 @Override
298 public void sendStatsQuery(OFStatisticsRequest request, int xid,
299 IOFMessageListener caller)
Ray Milkey269ffb92014-04-03 14:43:30 -0700300 throws IOException {
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800301 assertTrue("Unexpected method call", false);
302 }
Ray Milkey269ffb92014-04-03 14:43:30 -0700303
Umesh Krishnaswamy345ee992012-12-13 20:29:48 -0800304 @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}