Skip to content
Snippets Groups Projects
Commit 0d772acd authored by Gregor Maier's avatar Gregor Maier
Browse files

Must be able to accept null FloodlightContext in handleOutgoingMessage.

parent a83fa82a
No related branches found
No related tags found
No related merge requests found
......@@ -219,8 +219,9 @@ public interface IFloodlightProviderService extends
* Process written messages through the message listeners for the controller
* @param sw The switch being written to
* @param m the message
* @param bc any accompanying context object. Must not be null.
* @throws NullPointerException if switch or msg or bc is null
* @param bc any accompanying context object. Can be null in which case a
* new context will be allocated and passed to listeners
* @throws NullPointerException if switch or msg is null
*/
public void handleOutgoingMessage(IOFSwitch sw, OFMessage m,
FloodlightContext bc);
......
......@@ -1659,7 +1659,7 @@ public class Controller implements IFloodlightProviderService,
if (m == null)
throw new NullPointerException("OFMessage must not be null");
if (bc == null)
throw new NullPointerException("FloodlightContext must not be null");
bc = new FloodlightContext();
if (log.isTraceEnabled()) {
String str = OFMessage.getDataAsString(sw, m, bc);
log.trace("{}", str);
......
......@@ -642,6 +642,26 @@ public class ControllerTest extends FloodlightTestCase {
verify(test2);
verify(test3);
// Test inject with null switch and no message. Should not work.
reset(test1, test2, test3);
replay(test1, test2, test3, sw);
try {
controller.handleOutgoingMessage(null, pi, cntx);
fail("handleOutgoindMessage should have thrown a NPE");
} catch (NullPointerException e) {
// expected
}
try {
controller.handleOutgoingMessage(sw, null, cntx);
fail("handleOutgoingMessage should have thrown a NPE");
} catch (NullPointerException e) {
// expected
}
verify(test1);
verify(test2);
verify(test3);
verify(sw);
// Test the handleOutgoingMessage
reset(test1, test2, test3, sw);
expect(sw.getId()).andReturn(0L).anyTimes();
......@@ -658,6 +678,22 @@ public class ControllerTest extends FloodlightTestCase {
verify(test3);
verify(sw);
// Test the handleOutgoingMessage with null context
reset(test1, test2, test3, sw);
expect(sw.getId()).andReturn(0L).anyTimes();
expect(sw.getStringId()).andReturn("00:00:00:00:00:00:00").anyTimes();
expect(test2.receive(same(sw), same(m) , isA(FloodlightContext.class)))
.andReturn(Command.STOP);
expect(test3.receive(same(sw), same(m) , isA(FloodlightContext.class)))
.andReturn(Command.CONTINUE);
// test1 will not receive any message!
replay(test1, test2, test3, sw);
controller.handleOutgoingMessage(sw, m, null);
verify(test1);
verify(test2);
verify(test3);
verify(sw);
// Test for message without listeners
reset(test1, test2, test3, sw);
replay(test1, test2, test3, sw);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment