diff --git a/src/main/java/net/floodlightcontroller/core/IOFSwitch.java b/src/main/java/net/floodlightcontroller/core/IOFSwitch.java index c3721843ba8b9fee0e9cfc6baf9faf3803b707e0..b69474565c1c31079344b533e2d0f0976ad90b81 100644 --- a/src/main/java/net/floodlightcontroller/core/IOFSwitch.java +++ b/src/main/java/net/floodlightcontroller/core/IOFSwitch.java @@ -305,15 +305,19 @@ public interface IOFSwitch { * Get the current role of the controller for the switch * @return the role of the controller */ - public Role getRole(); + public Role getHARole(); /** - * Check if the controller is an active controller for the switch. - * The controller is active if its role is MASTER or EQUAL. - * @return whether the controller is active + * Set switch's HA role to role. The haRoleReplyReceived indicates + * if a reply was received from the switch (error replies excluded). + * + * If role is null, the switch should close the channel connection. + * + * @param role + * @param haRoleReplyReceived */ - public boolean isActive(); - + public void setHARole(Role role, boolean haRoleReplyReceived); + /** * Deliver the statistics future reply * @param reply the reply to deliver @@ -399,17 +403,6 @@ public interface IOFSwitch { */ public void flush(); - /** - * Set switch's HA role to role. The haRoleReplyReceived indicates - * if a reply was received from the switch (error replies excluded). - * - * If role is null, the switch should close the channel connection. - * - * @param role - * @param haRoleReplyReceived - */ - public void setHARole(Role role, boolean haRoleReplyReceived); - /** * Return a read lock that must be held while calling the listeners for * messages from the switch. Holding the read lock prevents the active diff --git a/src/main/java/net/floodlightcontroller/core/internal/Controller.java b/src/main/java/net/floodlightcontroller/core/internal/Controller.java index 04440cf77c474fcda34d7dd18459797cddd2aca2..cd840ece73b93f9bd6db935454bfe373aac0a725 100644 --- a/src/main/java/net/floodlightcontroller/core/internal/Controller.java +++ b/src/main/java/net/floodlightcontroller/core/internal/Controller.java @@ -876,7 +876,7 @@ public class Controller implements IFloodlightProviderService, roleChanger.deliverRoleReply(sw, vendorMessage.getXid(), role); - if (sw.isActive()) { + if (sw.getHARole() != Role.SLAVE) { // Transition from SLAVE to MASTER. boolean shouldClearFlowMods = false; if (!state.firstRoleReplyReceived || @@ -1176,7 +1176,7 @@ public class Controller implements IFloodlightProviderService, // to them. On the other hand there might be special // modules that care about all of the connected switches // and would like to receive port status notifications. - if (sw.getRole() == Role.SLAVE) { + if (sw.getHARole() == Role.SLAVE) { // Don't log message if it's a port status message // since we expect to receive those from the switch // and don't want to emit spurious messages. diff --git a/src/main/java/net/floodlightcontroller/core/internal/OFSwitchImpl.java b/src/main/java/net/floodlightcontroller/core/internal/OFSwitchImpl.java index e3b5abcf556d779815ca4f193304bb2de794535c..7f108a5e9444e4ff5c4164159acd63b3d5baa3c4 100644 --- a/src/main/java/net/floodlightcontroller/core/internal/OFSwitchImpl.java +++ b/src/main/java/net/floodlightcontroller/core/internal/OFSwitchImpl.java @@ -464,16 +464,10 @@ public class OFSwitchImpl implements IOFSwitch { } @Override - public Role getRole() { + public Role getHARole() { return role; } - @JsonIgnore - @Override - public boolean isActive() { - return (role != Role.SLAVE); - } - @Override @JsonIgnore public void setSwitchProperties(OFDescriptionStatistics description) { diff --git a/src/main/java/net/floodlightcontroller/core/web/SwitchRoleResource.java b/src/main/java/net/floodlightcontroller/core/web/SwitchRoleResource.java index 0d73f93f12130c1df48fc995b1ccd50ad53ef82e..cf7c6ad43bf64e71ccb93824cf691471cdbd3426 100644 --- a/src/main/java/net/floodlightcontroller/core/web/SwitchRoleResource.java +++ b/src/main/java/net/floodlightcontroller/core/web/SwitchRoleResource.java @@ -29,18 +29,18 @@ public class SwitchRoleResource extends ServerResource { if (switchId.equalsIgnoreCase("all")) { HashMap<String,RoleInfo> model = new HashMap<String,RoleInfo>(); for (IOFSwitch sw: floodlightProvider.getSwitches().values()) { - switchId = sw.getStringId(); - roleInfo = new RoleInfo(sw.getRole()); - model.put(switchId, roleInfo); + switchId = sw.getStringId(); + roleInfo = new RoleInfo(sw.getHARole()); + model.put(switchId, roleInfo); } return model; } - Long dpid = HexString.toLong(switchId); - IOFSwitch sw = floodlightProvider.getSwitches().get(dpid); - if (sw == null) - return null; - roleInfo = new RoleInfo(sw.getRole()); - return roleInfo; + Long dpid = HexString.toLong(switchId); + IOFSwitch sw = floodlightProvider.getSwitches().get(dpid); + if (sw == null) + return null; + roleInfo = new RoleInfo(sw.getHARole()); + return roleInfo; } } diff --git a/src/test/java/net/floodlightcontroller/core/internal/ControllerTest.java b/src/test/java/net/floodlightcontroller/core/internal/ControllerTest.java index 96e374e4002cfa671ae00bfdcdccc5ae2def70e0..e37b752cb52731f7266c05cc4fdb043701b8691d 100644 --- a/src/test/java/net/floodlightcontroller/core/internal/ControllerTest.java +++ b/src/test/java/net/floodlightcontroller/core/internal/ControllerTest.java @@ -484,6 +484,7 @@ public class ControllerTest extends FloodlightTestCase Channel channel = createMock(Channel.class); oldsw.setChannel(channel); + expect(channel.getRemoteAddress()).andReturn(null); expect(channel.close()).andReturn(null); IOFSwitch newsw = createMock(IOFSwitch.class); @@ -511,6 +512,7 @@ public class ControllerTest extends FloodlightTestCase Channel channel = createMock(Channel.class); oldsw.setChannel(channel); expect(channel.close()).andReturn(null); + expect(channel.getRemoteAddress()).andReturn(null); IOFSwitch newsw = createMock(IOFSwitch.class); expect(newsw.getId()).andReturn(0L).anyTimes(); @@ -549,7 +551,7 @@ public class ControllerTest extends FloodlightTestCase return "dummy"; } @Override - public void switchPortChanged(Long switchId) { + public synchronized void switchPortChanged(Long switchId) { nPortChanged++; notifyAll(); } @@ -1039,7 +1041,7 @@ public class ControllerTest extends FloodlightTestCase chdlr.sw.setHARole(controller.role, false); setupSwitchForAddSwitch(chdlr.sw, 0L); chdlr.sw.clearAllFlowMods(); - expect(chdlr.sw.getRole()).andReturn(null).anyTimes(); + expect(chdlr.sw.getHARole()).andReturn(null).anyTimes(); replay(ch, chdlr.sw); chdlr.processOFMessage(msg); @@ -1122,7 +1124,7 @@ public class ControllerTest extends FloodlightTestCase setupPendingRoleRequest(chdlr.sw, xid, Role.MASTER, 123456); chdlr.sw.setHARole(Role.MASTER, true); - expect(chdlr.sw.isActive()).andReturn(true); + expect(chdlr.sw.getHARole()).andReturn(Role.MASTER); setupSwitchForAddSwitch(chdlr.sw, 1L); chdlr.sw.clearAllFlowMods(); chdlr.state.firstRoleReplyReceived = false; @@ -1147,7 +1149,7 @@ public class ControllerTest extends FloodlightTestCase setupPendingRoleRequest(chdlr.sw, xid, Role.MASTER, 123456); chdlr.sw.setHARole(Role.MASTER, true); - expect(chdlr.sw.isActive()).andReturn(true); + expect(chdlr.sw.getHARole()).andReturn(Role.MASTER); setupSwitchForAddSwitch(chdlr.sw, 1L); chdlr.state.firstRoleReplyReceived = true; // Flow table shouldn't be wipe @@ -1171,7 +1173,7 @@ public class ControllerTest extends FloodlightTestCase setupPendingRoleRequest(chdlr.sw, xid, Role.EQUAL, 123456); chdlr.sw.setHARole(Role.EQUAL, true); - expect(chdlr.sw.isActive()).andReturn(true); + expect(chdlr.sw.getHARole()).andReturn(Role.EQUAL); setupSwitchForAddSwitch(chdlr.sw, 1L); chdlr.sw.clearAllFlowMods(); chdlr.state.firstRoleReplyReceived = false; @@ -1197,7 +1199,7 @@ public class ControllerTest extends FloodlightTestCase expect(chdlr.sw.getId()).andReturn(1L).anyTimes(); expect(chdlr.sw.getStringId()).andReturn("00:00:00:00:00:00:00:01") .anyTimes(); - expect(chdlr.sw.isActive()).andReturn(false); + expect(chdlr.sw.getHARole()).andReturn(Role.SLAVE); // don't add switch to activeSwitches ==> slave2slave chdlr.state.firstRoleReplyReceived = false; replay(chdlr.sw); @@ -1222,7 +1224,7 @@ public class ControllerTest extends FloodlightTestCase expect(chdlr.sw.getId()).andReturn(1L).anyTimes(); expect(chdlr.sw.getStringId()).andReturn("00:00:00:00:00:00:00:01") .anyTimes(); - expect(chdlr.sw.isActive()).andReturn(true); + expect(chdlr.sw.getHARole()).andReturn(Role.MASTER); controller.activeSwitches.put(1L, chdlr.sw); chdlr.state.firstRoleReplyReceived = false; // Must not clear flow mods @@ -1249,7 +1251,7 @@ public class ControllerTest extends FloodlightTestCase expect(chdlr.sw.getStringId()).andReturn("00:00:00:00:00:00:00:01") .anyTimes(); controller.activeSwitches.put(1L, chdlr.sw); - expect(chdlr.sw.isActive()).andReturn(false).anyTimes(); + expect(chdlr.sw.getHARole()).andReturn(Role.SLAVE).anyTimes(); expect(chdlr.sw.isConnected()).andReturn(true); chdlr.sw.cancelAllStatisticsReplies(); chdlr.state.firstRoleReplyReceived = false; diff --git a/src/test/java/net/floodlightcontroller/util/OFMessageDamperMockSwitch.java b/src/test/java/net/floodlightcontroller/util/OFMessageDamperMockSwitch.java index 195d15f597aacc6185458524ccd8b88e790c4dad..c8caf91ba8d43251f2ac8d929e611e41d253c02d 100644 --- a/src/test/java/net/floodlightcontroller/util/OFMessageDamperMockSwitch.java +++ b/src/test/java/net/floodlightcontroller/util/OFMessageDamperMockSwitch.java @@ -223,17 +223,11 @@ public class OFMessageDamperMockSwitch implements IOFSwitch { } @Override - public Role getRole() { + public Role getHARole() { assertTrue("Unexpected method call", false); return null; } - @Override - public boolean isActive() { - assertTrue("Unexpected method call", false); - return false; - } - @Override public void deliverStatisticsReply(OFMessage reply) { assertTrue("Unexpected method call", false);