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