diff --git a/src/test/java/net/floodlightcontroller/core/internal/ControllerTest.java b/src/test/java/net/floodlightcontroller/core/internal/ControllerTest.java index cc5d14a35c4735bf93f2171080854ec8105c9670..7d728affe4fb1659c0149505021c17fdd4b6f14c 100644 --- a/src/test/java/net/floodlightcontroller/core/internal/ControllerTest.java +++ b/src/test/java/net/floodlightcontroller/core/internal/ControllerTest.java @@ -2042,51 +2042,4 @@ public class ControllerTest extends FloodlightTestCase { verify(driver, driver2); } - -// @Test -// public void testErrorEPERM() throws Exception { -// // Check behavior with a BAD_REQUEST/EPERM error -// // Ensure controller attempts to reset switch role. -// OFChannelState state = new OFChannelState(); -// state.hsState = HandshakeState.READY; -// OFChannelHandler chdlr = new OFChannelHandler(controller, state); -// OFError error = new OFError(); -// error.setErrorType(OFErrorType.OFPET_BAD_REQUEST); -// error.setErrorCode(OFBadRequestCode.OFPBRC_EPERM); -// IOFSwitch sw = createMock(IOFSwitch.class); -// chdlr.sw = sw; -// controller.activeSwitches.put(1L, sw); -// -// // prepare the switch and lock expectations -// Lock lock = createNiceMock(Lock.class); -// expect(sw.getListenerReadLock()).andReturn(lock).anyTimes(); -// expect(sw.isConnected()).andReturn(true).anyTimes(); -// expect(sw.getHARole()).andReturn(Role.MASTER).anyTimes(); -// expect(sw.getId()).andReturn(1L).anyTimes(); -// -// // Make sure controller attempts to reset switch master -// expect(sw.getAttribute("supportsNxRole")).andReturn(true).anyTimes(); -// expect(sw.getNextTransactionId()).andReturn(0).anyTimes(); -// sw.write(EasyMock.<List<OFMessage>> anyObject(), -// (FloodlightContext)anyObject()); -// -// // test -// replay(sw, lock); -// chdlr.processOFMessage(error); -// DelayQueue<RoleChangeTask> pendingTasks = -// controller.roleChanger.pendingTasks; -// synchronized (pendingTasks) { -// RoleChangeTask t; -// while ((t = pendingTasks.peek()) == null || -// RoleChanger.RoleChangeTask.Type.TIMEOUT != t.type) { -// pendingTasks.wait(); -// } -// } -// // Now there should be exactly one timeout task pending -// assertEquals(1, pendingTasks.size()); -// } -// - - - } diff --git a/src/test/java/net/floodlightcontroller/core/internal/OFChannelHandlerTest.java b/src/test/java/net/floodlightcontroller/core/internal/OFChannelHandlerTest.java index 45cef6bd228a2248687f8bf9b0cd58f6b46b9b29..7adfffe650c8f3395c5e5525be166b1437e1aa37 100644 --- a/src/test/java/net/floodlightcontroller/core/internal/OFChannelHandlerTest.java +++ b/src/test/java/net/floodlightcontroller/core/internal/OFChannelHandlerTest.java @@ -9,6 +9,7 @@ import java.util.List; import java.util.Set; import net.floodlightcontroller.core.FloodlightContext; +import net.floodlightcontroller.core.IOFMessageListener; import net.floodlightcontroller.core.IOFSwitch; import net.floodlightcontroller.core.IFloodlightProviderService.Role; import net.floodlightcontroller.debugcounter.DebugCounter; @@ -30,6 +31,7 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; import org.openflow.protocol.OFError; +import org.openflow.protocol.OFError.OFBadRequestCode; import org.openflow.protocol.OFError.OFErrorType; import org.openflow.protocol.OFFeaturesReply; import org.openflow.protocol.OFFlowMod; @@ -1236,8 +1238,34 @@ public class OFChannelHandlerTest { Collections.<OFMessage>singletonList(ps)); verify(sw); verify(controller); + } + + /** + * Test re-assert MASTER + * + */ + @Test + public void testReassertMaster() throws Exception { + testInitialMoveToMasterWithRole(); + + OFError err = (OFError) + BasicFactory.getInstance().getMessage(OFType.ERROR); + err.setXid(42); + err.setErrorType(OFErrorType.OFPET_BAD_REQUEST); + err.setErrorCode(OFBadRequestCode.OFPBRC_EPERM); + reset(controller); + controller.reassertRole(handler, Role.MASTER); + expectLastCall().once(); + controller.handleMessage(sw, err, null); + expectLastCall().once(); + + sendMessageToHandlerNoControllerReset( + Collections.<OFMessage>singletonList(err)); + verify(sw); + verify(controller); } + }