diff --git a/src/main/java/net/floodlightcontroller/core/internal/Controller.java b/src/main/java/net/floodlightcontroller/core/internal/Controller.java index a2de33dd27ca5da397c6e77635e44e775d1e0bf4..381c2ad9aae40a77857bbc7b6c0e7dd7580190da 100644 --- a/src/main/java/net/floodlightcontroller/core/internal/Controller.java +++ b/src/main/java/net/floodlightcontroller/core/internal/Controller.java @@ -354,6 +354,10 @@ public class Controller implements IFloodlightProviderService, @Override public void setRole(Role role) { if (role == null) throw new NullPointerException("Role can not be null."); + if (role == Role.MASTER && this.role == Role.SLAVE) { + // Reset db state to Inactive for all switches. + updateAllInactiveSwitchInfo(); + } // Need to synchronize to ensure a reliable ordering on role request // messages send and to ensure the list of connected switches is stable @@ -369,10 +373,6 @@ public class Controller implements IFloodlightProviderService, Role oldRole = this.role; this.role = role; - if (role == Role.MASTER) { - updateAllInactiveSwitchInfo(); - } - log.debug("Submitting role change request to role {}", role); roleChanger.submitRequest(connectedSwitches, role); @@ -1487,6 +1487,9 @@ public class Controller implements IFloodlightProviderService, // ************** protected void updateAllInactiveSwitchInfo() { + if (role == Role.SLAVE) { + return; + } String controllerId = getControllerId(); String[] switchColumns = { SWITCH_DATAPATH_ID, SWITCH_CONTROLLER_ID, @@ -1544,6 +1547,9 @@ public class Controller implements IFloodlightProviderService, } protected void updateActiveSwitchInfo(IOFSwitch sw) { + if (role == Role.SLAVE) { + return; + } // Obtain the row info for the switch Map<String, Object> switchInfo = new HashMap<String, Object>(); String datapathIdString = sw.getStringId(); @@ -1588,6 +1594,9 @@ public class Controller implements IFloodlightProviderService, } protected void updateInactiveSwitchInfo(IOFSwitch sw) { + if (role == Role.SLAVE) { + return; + } log.debug("Update DB with inactiveSW {}", sw); // Update the controller info in the storage source to be inactive Map<String, Object> switchInfo = new HashMap<String, Object>(); @@ -1599,6 +1608,9 @@ public class Controller implements IFloodlightProviderService, } protected void updatePortInfo(IOFSwitch sw, OFPhysicalPort port) { + if (role == Role.SLAVE) { + return; + } String datapathIdString = sw.getStringId(); Map<String, Object> portInfo = new HashMap<String, Object>(); int portNumber = U16.f(port.getPortNumber()); @@ -1672,6 +1684,9 @@ public class Controller implements IFloodlightProviderService, } protected void removePortInfo(IOFSwitch sw, short portNumber) { + if (role == Role.SLAVE) { + return; + } String datapathIdString = sw.getStringId(); String id = datapathIdString + "|" + portNumber; storageSource.deleteRowAsync(PORT_TABLE_NAME, id);