From cb07c688a275222f8c47f3e076b807deaceafde4 Mon Sep 17 00:00:00 2001
From: Monoreet Mutsuddi <monoreet@gmail.com>
Date: Sat, 28 Jul 2012 14:36:20 -0700
Subject: [PATCH] dont update Switch/Port table on SLAVE

---
 .../core/internal/Controller.java             | 23 +++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/src/main/java/net/floodlightcontroller/core/internal/Controller.java b/src/main/java/net/floodlightcontroller/core/internal/Controller.java
index a2de33dd2..381c2ad9a 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);
-- 
GitLab