Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 1 | package net.floodlightcontroller.util; |
| 2 | |
Jonathan Hart | a88fd24 | 2014-04-03 11:24:54 -0700 | [diff] [blame] | 3 | import static org.junit.Assert.assertEquals; |
| 4 | import static org.junit.Assert.assertNotNull; |
| 5 | import static org.junit.Assert.assertNull; |
| 6 | import static org.junit.Assert.assertTrue; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 7 | |
Jonathan Hart | a88fd24 | 2014-04-03 11:24:54 -0700 | [diff] [blame] | 8 | import java.io.IOException; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 9 | import java.util.Collection; |
| 10 | import java.util.Date; |
| 11 | import java.util.List; |
| 12 | import java.util.Map; |
| 13 | import java.util.concurrent.Future; |
| 14 | |
| 15 | import net.floodlightcontroller.core.FloodlightContext; |
Jonathan Hart | a88fd24 | 2014-04-03 11:24:54 -0700 | [diff] [blame] | 16 | import net.floodlightcontroller.core.IFloodlightProviderService.Role; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 17 | import net.floodlightcontroller.core.IOFMessageListener; |
| 18 | import net.floodlightcontroller.core.IOFSwitch; |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 19 | |
| 20 | import org.jboss.netty.channel.Channel; |
| 21 | import org.openflow.protocol.OFFeaturesReply; |
| 22 | import org.openflow.protocol.OFMessage; |
| 23 | import org.openflow.protocol.OFPhysicalPort; |
| 24 | import org.openflow.protocol.OFStatisticsRequest; |
| 25 | import org.openflow.protocol.statistics.OFDescriptionStatistics; |
| 26 | import org.openflow.protocol.statistics.OFStatistics; |
| 27 | |
| 28 | |
| 29 | /** |
| 30 | * A mock implementation of IFOSwitch we use for {@link OFMessageDamper} |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 31 | * <p/> |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 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 |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 34 | * methods. |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 35 | * |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 36 | * @author gregor |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 37 | */ |
| 38 | public class OFMessageDamperMockSwitch implements IOFSwitch { |
| 39 | OFMessage writtenMessage; |
| 40 | FloodlightContext writtenContext; |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 41 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 42 | public OFMessageDamperMockSwitch() { |
| 43 | reset(); |
| 44 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 45 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 46 | /* reset this mock. I.e., clear the stored message previously written */ |
| 47 | public void reset() { |
| 48 | writtenMessage = null; |
| 49 | writtenContext = null; |
| 50 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 51 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 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 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 57 | public void assertMessageWasWritten(OFMessage expected, |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 58 | FloodlightContext expectedContext) { |
| 59 | assertNotNull("No OFMessage was written", writtenMessage); |
| 60 | assertEquals(expected, writtenMessage); |
| 61 | assertEquals(expectedContext, writtenContext); |
| 62 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 63 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 64 | /* |
| 65 | * assert that no message was written |
| 66 | */ |
| 67 | public void assertNoMessageWritten() { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 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); |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | /* |
| 75 | * use hashCode() and equals() from Object |
| 76 | */ |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 77 | |
| 78 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 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 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 88 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 89 | //------------------------------------------------------- |
| 90 | // IOFSwitch: not-implemented methods |
| 91 | @Override |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 92 | public void write(List<OFMessage> msglist, FloodlightContext bc) |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 93 | throws IOException { |
| 94 | assertTrue("Unexpected method call", false); |
| 95 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 96 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 97 | @Override |
| 98 | public void disconnectOutputStream() { |
| 99 | assertTrue("Unexpected method call", false); |
| 100 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 101 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 102 | @Override |
| 103 | public Channel getChannel() { |
| 104 | assertTrue("Unexpected method call", false); |
| 105 | return null; |
| 106 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 107 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 108 | @Override |
| 109 | public void setFeaturesReply(OFFeaturesReply featuresReply) { |
| 110 | assertTrue("Unexpected method call", false); |
| 111 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 112 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 113 | @Override |
| 114 | public void setSwitchProperties(OFDescriptionStatistics description) { |
| 115 | assertTrue("Unexpected method call", false); |
| 116 | // TODO Auto-generated method stub |
| 117 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 118 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 119 | @Override |
| 120 | public Collection<OFPhysicalPort> getEnabledPorts() { |
| 121 | assertTrue("Unexpected method call", false); |
| 122 | return null; |
| 123 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 124 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 125 | @Override |
| 126 | public Collection<Short> getEnabledPortNumbers() { |
| 127 | assertTrue("Unexpected method call", false); |
| 128 | return null; |
| 129 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 130 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 131 | @Override |
| 132 | public OFPhysicalPort getPort(short portNumber) { |
| 133 | assertTrue("Unexpected method call", false); |
| 134 | return null; |
| 135 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 136 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 137 | @Override |
| 138 | public OFPhysicalPort getPort(String portName) { |
| 139 | assertTrue("Unexpected method call", false); |
| 140 | return null; |
| 141 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 142 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 143 | @Override |
| 144 | public void setPort(OFPhysicalPort port) { |
| 145 | assertTrue("Unexpected method call", false); |
| 146 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 147 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 148 | @Override |
| 149 | public void deletePort(short portNumber) { |
| 150 | assertTrue("Unexpected method call", false); |
| 151 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 152 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 153 | @Override |
| 154 | public void deletePort(String portName) { |
| 155 | assertTrue("Unexpected method call", false); |
| 156 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 157 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 158 | @Override |
| 159 | public Collection<OFPhysicalPort> getPorts() { |
| 160 | assertTrue("Unexpected method call", false); |
| 161 | return null; |
| 162 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 163 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 164 | @Override |
| 165 | public boolean portEnabled(short portName) { |
| 166 | assertTrue("Unexpected method call", false); |
| 167 | return false; |
| 168 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 169 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 170 | @Override |
| 171 | public boolean portEnabled(String portName) { |
| 172 | assertTrue("Unexpected method call", false); |
| 173 | return false; |
| 174 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 175 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 176 | @Override |
| 177 | public boolean portEnabled(OFPhysicalPort port) { |
| 178 | assertTrue("Unexpected method call", false); |
| 179 | return false; |
| 180 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 181 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 182 | @Override |
| 183 | public long getId() { |
| 184 | assertTrue("Unexpected method call", false); |
| 185 | return 0; |
| 186 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 187 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 188 | @Override |
| 189 | public String getStringId() { |
| 190 | assertTrue("Unexpected method call", false); |
| 191 | return null; |
| 192 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 193 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 194 | @Override |
| 195 | public Map<Object, Object> getAttributes() { |
| 196 | assertTrue("Unexpected method call", false); |
| 197 | return null; |
| 198 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 199 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 200 | @Override |
| 201 | public Date getConnectedSince() { |
| 202 | assertTrue("Unexpected method call", false); |
| 203 | return null; |
| 204 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 205 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 206 | @Override |
| 207 | public int getNextTransactionId() { |
| 208 | assertTrue("Unexpected method call", false); |
| 209 | return 0; |
| 210 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 211 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 212 | @Override |
| 213 | public Future<List<OFStatistics>> |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 214 | getStatistics(OFStatisticsRequest request) throws IOException { |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 215 | assertTrue("Unexpected method call", false); |
| 216 | return null; |
| 217 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 218 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 219 | @Override |
| 220 | public boolean isConnected() { |
| 221 | assertTrue("Unexpected method call", false); |
| 222 | return false; |
| 223 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 224 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 225 | @Override |
| 226 | public void setConnected(boolean connected) { |
| 227 | assertTrue("Unexpected method call", false); |
| 228 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 229 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 230 | @Override |
| 231 | public Role getRole() { |
| 232 | assertTrue("Unexpected method call", false); |
| 233 | return null; |
| 234 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 235 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 236 | @Override |
| 237 | public boolean isActive() { |
| 238 | assertTrue("Unexpected method call", false); |
| 239 | return false; |
| 240 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 241 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 242 | @Override |
| 243 | public void deliverStatisticsReply(OFMessage reply) { |
| 244 | assertTrue("Unexpected method call", false); |
| 245 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 246 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 247 | @Override |
| 248 | public void cancelStatisticsReply(int transactionId) { |
| 249 | assertTrue("Unexpected method call", false); |
| 250 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 251 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 252 | @Override |
| 253 | public void cancelAllStatisticsReplies() { |
| 254 | assertTrue("Unexpected method call", false); |
| 255 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 256 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 257 | @Override |
| 258 | public boolean hasAttribute(String name) { |
| 259 | assertTrue("Unexpected method call", false); |
| 260 | return false; |
| 261 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 262 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 263 | @Override |
| 264 | public Object getAttribute(String name) { |
| 265 | assertTrue("Unexpected method call", false); |
| 266 | return null; |
| 267 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 268 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 269 | @Override |
| 270 | public void setAttribute(String name, Object value) { |
| 271 | assertTrue("Unexpected method call", false); |
| 272 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 273 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 274 | @Override |
| 275 | public Object removeAttribute(String name) { |
| 276 | assertTrue("Unexpected method call", false); |
| 277 | return null; |
| 278 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 279 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 280 | @Override |
| 281 | public void clearAllFlowMods() { |
| 282 | assertTrue("Unexpected method call", false); |
| 283 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 284 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 285 | @Override |
| 286 | public boolean updateBroadcastCache(Long entry, Short port) { |
| 287 | assertTrue("Unexpected method call", false); |
| 288 | return false; |
| 289 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 290 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 291 | @Override |
| 292 | public Map<Short, Long> getPortBroadcastHits() { |
| 293 | assertTrue("Unexpected method call", false); |
| 294 | return null; |
| 295 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 296 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 297 | @Override |
| 298 | public void sendStatsQuery(OFStatisticsRequest request, int xid, |
| 299 | IOFMessageListener caller) |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 300 | throws IOException { |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 301 | assertTrue("Unexpected method call", false); |
| 302 | } |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 303 | |
Umesh Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 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 Krishnaswamy | 345ee99 | 2012-12-13 20:29:48 -0800 | [diff] [blame] | 352 | } |