Renamed the Mastership API to use Registry terminology
diff --git a/mastership-test.sh b/mastership-test.sh
index 06907f0..4fa47d5 100755
--- a/mastership-test.sh
+++ b/mastership-test.sh
@@ -1 +1 @@
-java -Dlogback.configurationFile=logback.xml -cp target/floodlight-only.jar:lib/*:lib/titan/* net.floodlightcontroller.mastership.MastershipRunner $1
+java -Dlogback.configurationFile=logback.xml -cp target/floodlight-only.jar:lib/*:lib/titan/* net.onrc.onos.registry.controller.RegistryRunner $1
diff --git a/src/main/java/net/floodlightcontroller/core/FloodlightProvider.java b/src/main/java/net/floodlightcontroller/core/FloodlightProvider.java
index e84e0f6..3a1eb55 100644
--- a/src/main/java/net/floodlightcontroller/core/FloodlightProvider.java
+++ b/src/main/java/net/floodlightcontroller/core/FloodlightProvider.java
@@ -11,11 +11,11 @@
import net.floodlightcontroller.core.module.IFloodlightModule;
import net.floodlightcontroller.core.module.IFloodlightService;
import net.floodlightcontroller.counter.ICounterStoreService;
-import net.floodlightcontroller.mastership.IMastershipService;
import net.floodlightcontroller.perfmon.IPktInProcessingTimeService;
import net.floodlightcontroller.restserver.IRestApiService;
import net.floodlightcontroller.storage.IStorageSourceService;
import net.floodlightcontroller.threadpool.IThreadPoolService;
+import net.onrc.onos.registry.controller.IControllerRegistryService;
public class FloodlightProvider implements IFloodlightModule {
Controller controller;
@@ -50,7 +50,7 @@
dependencies.add(IRestApiService.class);
dependencies.add(ICounterStoreService.class);
dependencies.add(IThreadPoolService.class);
- dependencies.add(IMastershipService.class);
+ dependencies.add(IControllerRegistryService.class);
return dependencies;
}
@@ -66,7 +66,7 @@
context.getServiceImpl(IRestApiService.class));
controller.setThreadPoolService(
context.getServiceImpl(IThreadPoolService.class));
- controller.setMastershipService(context.getServiceImpl(IMastershipService.class));
+ controller.setMastershipService(context.getServiceImpl(IControllerRegistryService.class));
controller.init(context.getConfigParams(this));
}
diff --git a/src/main/java/net/floodlightcontroller/core/internal/Controller.java b/src/main/java/net/floodlightcontroller/core/internal/Controller.java
index d9cc5e1..0df0e19 100644
--- a/src/main/java/net/floodlightcontroller/core/internal/Controller.java
+++ b/src/main/java/net/floodlightcontroller/core/internal/Controller.java
@@ -65,7 +65,6 @@
import net.floodlightcontroller.core.util.ListenerDispatcher;
import net.floodlightcontroller.core.web.CoreWebRoutable;
import net.floodlightcontroller.counter.ICounterStoreService;
-import net.floodlightcontroller.mastership.IMastershipService;
import net.floodlightcontroller.packet.Ethernet;
import net.floodlightcontroller.perfmon.IPktInProcessingTimeService;
import net.floodlightcontroller.restserver.IRestApiService;
@@ -75,6 +74,7 @@
import net.floodlightcontroller.storage.OperatorPredicate;
import net.floodlightcontroller.storage.StorageException;
import net.floodlightcontroller.threadpool.IThreadPoolService;
+import net.onrc.onos.registry.controller.IControllerRegistryService;
import org.jboss.netty.bootstrap.ServerBootstrap;
import org.jboss.netty.buffer.ChannelBuffer;
@@ -189,7 +189,7 @@
protected IStorageSourceService storageSource;
protected IPktInProcessingTimeService pktinProcTime;
protected IThreadPoolService threadPool;
- protected IMastershipService masterHelper;
+ protected IControllerRegistryService masterHelper;
// Configuration options
protected int openFlowPort = 6633;
@@ -392,7 +392,7 @@
this.threadPool = tp;
}
- public void setMastershipService(IMastershipService serviceImpl) {
+ public void setMastershipService(IControllerRegistryService serviceImpl) {
this.masterHelper = serviceImpl;
}
diff --git a/src/main/java/net/floodlightcontroller/mastership/IMastershipService.java b/src/main/java/net/onrc/onos/registry/controller/IControllerRegistryService.java
similarity index 64%
rename from src/main/java/net/floodlightcontroller/mastership/IMastershipService.java
rename to src/main/java/net/onrc/onos/registry/controller/IControllerRegistryService.java
index bfb2e9a..f2794cc 100644
--- a/src/main/java/net/floodlightcontroller/mastership/IMastershipService.java
+++ b/src/main/java/net/onrc/onos/registry/controller/IControllerRegistryService.java
@@ -1,26 +1,26 @@
-package net.floodlightcontroller.mastership;
+package net.onrc.onos.registry.controller;
import java.util.Collection;
+import java.util.Map;
import net.floodlightcontroller.core.module.IFloodlightService;
-//Will change to something like IRegistryService
-public interface IMastershipService extends IFloodlightService {
+public interface IControllerRegistryService extends IFloodlightService {
// Callback for all mastership changes.
// Change callback is called when mastership is acquired or released
- public interface MastershipCallback {
- public void changeCallback(long dpid, boolean isMaster);
+ public interface ControlChangeCallback {
+ public void controlChanged(long dpid, boolean hasControl);
}
// Acquire mastership for a switch.
- public void acquireMastership(long dpid, MastershipCallback cb) throws Exception;
+ public void requestControl(long dpid, ControlChangeCallback cb) throws Exception;
// Release mastership for a switch
- public void releaseMastership(long dpid);
+ public void releaseControl(long dpid);
// Check if I am the master of a switch. This is a nonblocking call that checks if the caller is a
- public boolean amMaster(long dpid);
+ public boolean hasControl(long dpid);
// Set/Get mastership identifier.
// This is typically a unique identifier of the controller that does not change across restarts
@@ -29,8 +29,7 @@
/**
* Register a controller to the ONOS cluster
- * @param controller A string identifying the controller and (possibly) how to talk to it.
- * (We will have to develop a convention for this - most likely hostname:port)
+ * @param controller A string identifying the controller
*/
public void registerController(String controllerId) throws RegistryException;
@@ -43,5 +42,7 @@
public String getControllerForSwitch(long dpid) throws RegistryException;
+ public Collection<Map<String, String>> getAllSwitches();
+
public Collection<Long> getSwitchesControlledByController(String controllerId);
}
diff --git a/src/main/java/net/floodlightcontroller/mastership/IMastershipHelper.java b/src/main/java/net/onrc/onos/registry/controller/IMastershipHelper.java
similarity index 96%
rename from src/main/java/net/floodlightcontroller/mastership/IMastershipHelper.java
rename to src/main/java/net/onrc/onos/registry/controller/IMastershipHelper.java
index b4becfa..9e07d46 100644
--- a/src/main/java/net/floodlightcontroller/mastership/IMastershipHelper.java
+++ b/src/main/java/net/onrc/onos/registry/controller/IMastershipHelper.java
@@ -1,4 +1,4 @@
-package net.floodlightcontroller.mastership;
+package net.onrc.onos.registry.controller;
public interface IMastershipHelper {
diff --git a/src/main/java/net/floodlightcontroller/mastership/MastershipHelper.java b/src/main/java/net/onrc/onos/registry/controller/MastershipHelper.java
similarity index 92%
rename from src/main/java/net/floodlightcontroller/mastership/MastershipHelper.java
rename to src/main/java/net/onrc/onos/registry/controller/MastershipHelper.java
index fdac8ca..2fcd002 100644
--- a/src/main/java/net/floodlightcontroller/mastership/MastershipHelper.java
+++ b/src/main/java/net/onrc/onos/registry/controller/MastershipHelper.java
@@ -1,4 +1,4 @@
-package net.floodlightcontroller.mastership;
+package net.onrc.onos.registry.controller;
public class MastershipHelper implements IMastershipHelper {
diff --git a/src/main/java/net/floodlightcontroller/mastership/RegistryException.java b/src/main/java/net/onrc/onos/registry/controller/RegistryException.java
similarity index 91%
rename from src/main/java/net/floodlightcontroller/mastership/RegistryException.java
rename to src/main/java/net/onrc/onos/registry/controller/RegistryException.java
index fcc14a6..3b237c2 100644
--- a/src/main/java/net/floodlightcontroller/mastership/RegistryException.java
+++ b/src/main/java/net/onrc/onos/registry/controller/RegistryException.java
@@ -1,4 +1,4 @@
-package net.floodlightcontroller.mastership;
+package net.onrc.onos.registry.controller;
public class RegistryException extends Exception {
diff --git a/src/main/java/net/floodlightcontroller/mastership/MastershipManager.java b/src/main/java/net/onrc/onos/registry/controller/RegistryManager.java
similarity index 90%
rename from src/main/java/net/floodlightcontroller/mastership/MastershipManager.java
rename to src/main/java/net/onrc/onos/registry/controller/RegistryManager.java
index 2e50670..84f17c3 100644
--- a/src/main/java/net/floodlightcontroller/mastership/MastershipManager.java
+++ b/src/main/java/net/onrc/onos/registry/controller/RegistryManager.java
@@ -1,4 +1,4 @@
-package net.floodlightcontroller.mastership;
+package net.onrc.onos.registry.controller;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
@@ -25,7 +25,6 @@
import com.netflix.curator.framework.CuratorFramework;
import com.netflix.curator.framework.CuratorFrameworkFactory;
import com.netflix.curator.framework.api.CuratorWatcher;
-import com.netflix.curator.framework.imps.CuratorFrameworkState;
import com.netflix.curator.framework.recipes.cache.ChildData;
import com.netflix.curator.framework.recipes.cache.PathChildrenCache;
import com.netflix.curator.framework.recipes.cache.PathChildrenCache.StartMode;
@@ -33,9 +32,9 @@
import com.netflix.curator.framework.recipes.leader.Participant;
import com.netflix.curator.retry.RetryOneTime;
-public class MastershipManager implements IFloodlightModule, IMastershipService {
+public class RegistryManager implements IFloodlightModule, IControllerRegistryService {
- protected static Logger log = LoggerFactory.getLogger(MastershipManager.class);
+ protected static Logger log = LoggerFactory.getLogger(RegistryManager.class);
protected String mastershipId = null;
//TODO read this from configuration
@@ -49,7 +48,7 @@
protected PathChildrenCache controllerCache;
protected Map<String, LeaderLatch> switchLatches;
- protected Map<String, MastershipCallback> switchCallbacks;
+ protected Map<String, ControlChangeCallback> switchCallbacks;
protected boolean moduleEnabled = false;
@@ -74,7 +73,7 @@
log.debug("Disconnected while leader - lost leadership for {}", dpid);
isLeader = false;
- switchCallbacks.get(dpid).changeCallback(HexString.toLong(dpid), false);
+ switchCallbacks.get(dpid).controlChanged(HexString.toLong(dpid), false);
}
return;
}
@@ -87,13 +86,13 @@
log.debug("Became leader for {}", dpid);
isLeader = true;
- switchCallbacks.get(dpid).changeCallback(HexString.toLong(dpid), true);
+ switchCallbacks.get(dpid).controlChanged(HexString.toLong(dpid), true);
}
else if (!leader.getId().equals(mastershipId) && isLeader){
log.debug("Lost leadership for {}", dpid);
isLeader = false;
- switchCallbacks.get(dpid).changeCallback(HexString.toLong(dpid), false);
+ switchCallbacks.get(dpid).controlChanged(HexString.toLong(dpid), false);
}
} catch (Exception e){
if (isLeader){
@@ -101,7 +100,7 @@
dpid);
isLeader = false;
- switchCallbacks.get(dpid).changeCallback(HexString.toLong(dpid), false);
+ switchCallbacks.get(dpid).controlChanged(HexString.toLong(dpid), false);
}
}
@@ -112,7 +111,7 @@
@Override
- public void acquireMastership(long dpid, MastershipCallback cb) throws Exception {
+ public void requestControl(long dpid, ControlChangeCallback cb) throws Exception {
if (!moduleEnabled) return;
@@ -146,7 +145,7 @@
}
@Override
- public void releaseMastership(long dpid) {
+ public void releaseControl(long dpid) {
if (!moduleEnabled) return;
String dpidStr = HexString.toHexString(dpid);
@@ -169,7 +168,7 @@
}
@Override
- public boolean amMaster(long dpid) {
+ public boolean hasControl(long dpid) {
if (!moduleEnabled) return false;
LeaderLatch latch = switchLatches.get(HexString.toHexString(dpid));
@@ -274,6 +273,13 @@
return null;
}
+
+ @Override
+ public Collection<Map<String, String>> getAllSwitches() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
/*
* IFloodlightModule
*/
@@ -282,7 +288,7 @@
public Collection<Class<? extends IFloodlightService>> getModuleServices() {
Collection<Class<? extends IFloodlightService>> l =
new ArrayList<Class<? extends IFloodlightService>>();
- l.add(IMastershipService.class);
+ l.add(IControllerRegistryService.class);
return l;
}
@@ -290,7 +296,7 @@
public Map<Class<? extends IFloodlightService>, IFloodlightService> getServiceImpls() {
Map<Class<? extends IFloodlightService>, IFloodlightService> m =
new HashMap<Class<? extends IFloodlightService>, IFloodlightService>();
- m.put(IMastershipService.class, this);
+ m.put(IControllerRegistryService.class, this);
return m;
}
@@ -325,7 +331,7 @@
}
switchLatches = new HashMap<String, LeaderLatch>();
- switchCallbacks = new HashMap<String, MastershipCallback>();
+ switchCallbacks = new HashMap<String, ControlChangeCallback>();
//RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
RetryPolicy retryPolicy = new RetryOneTime(0);
@@ -349,4 +355,5 @@
public void startUp (FloodlightModuleContext context) {
// Nothing to be done on startup
}
+
}
diff --git a/src/main/java/net/floodlightcontroller/mastership/MastershipRouteResource.java b/src/main/java/net/onrc/onos/registry/controller/RegistryRouteResource.java
similarity index 68%
rename from src/main/java/net/floodlightcontroller/mastership/MastershipRouteResource.java
rename to src/main/java/net/onrc/onos/registry/controller/RegistryRouteResource.java
index f75c518..5dadafa 100644
--- a/src/main/java/net/floodlightcontroller/mastership/MastershipRouteResource.java
+++ b/src/main/java/net/onrc/onos/registry/controller/RegistryRouteResource.java
@@ -1,4 +1,4 @@
-package net.floodlightcontroller.mastership;
+package net.onrc.onos.registry.controller;
import org.restlet.resource.ServerResource;
import org.restlet.resource.Get;
@@ -8,9 +8,9 @@
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
-public class MastershipRouteResource extends ServerResource {
+public class RegistryRouteResource extends ServerResource {
- protected static Logger log = LoggerFactory.getLogger(MastershipRouteResource.class);
+ protected static Logger log = LoggerFactory.getLogger(RegistryRouteResource.class);
@Get
public String get(String fmJson) {
diff --git a/src/main/java/net/floodlightcontroller/mastership/MastershipRunner.java b/src/main/java/net/onrc/onos/registry/controller/RegistryRunner.java
similarity index 65%
rename from src/main/java/net/floodlightcontroller/mastership/MastershipRunner.java
rename to src/main/java/net/onrc/onos/registry/controller/RegistryRunner.java
index a28a9c5..8522893 100644
--- a/src/main/java/net/floodlightcontroller/mastership/MastershipRunner.java
+++ b/src/main/java/net/onrc/onos/registry/controller/RegistryRunner.java
@@ -1,8 +1,8 @@
-package net.floodlightcontroller.mastership;
+package net.onrc.onos.registry.controller;
import net.floodlightcontroller.core.module.FloodlightModuleContext;
import net.floodlightcontroller.core.module.FloodlightModuleException;
-import net.floodlightcontroller.mastership.IMastershipService.MastershipCallback;
+import net.onrc.onos.registry.controller.IControllerRegistryService.ControlChangeCallback;
import org.openflow.util.HexString;
import org.slf4j.Logger;
@@ -14,12 +14,14 @@
* @author jono
*
*/
-public class MastershipRunner {
- protected static Logger log = LoggerFactory.getLogger(MastershipRunner.class);
+public class RegistryRunner {
+ protected static Logger log = LoggerFactory.getLogger(RegistryRunner.class);
public static void main(String args[]){
FloodlightModuleContext fmc = new FloodlightModuleContext();
- MastershipManager mm = new MastershipManager();
+ RegistryManager rm = new RegistryManager();
+
+ fmc.addConfigParam(rm, "enableZookeeper", "true");
String id = null;
if (args.length > 0){
@@ -28,17 +30,17 @@
}
try {
- mm.init(fmc);
- mm.startUp(fmc);
+ rm.init(fmc);
+ rm.startUp(fmc);
if (id != null){
- mm.setMastershipId(id);
+ rm.setMastershipId(id);
}
- mm.acquireMastership(1L,
- new MastershipCallback(){
+ rm.requestControl(1L,
+ new ControlChangeCallback(){
@Override
- public void changeCallback(long dpid, boolean isMaster) {
+ public void controlChanged(long dpid, boolean isMaster) {
if (isMaster){
log.debug("Callback for becoming master for {}", HexString.toHexString(dpid));
}
@@ -48,7 +50,7 @@
}
});
- mm.registerController(id);
+ rm.registerController(id);
Thread.sleep(5000);
@@ -65,6 +67,6 @@
e.printStackTrace();
}
- log.debug("is master: {}", mm.amMaster(1L));
+ log.debug("is master: {}", rm.hasControl(1L));
}
}
diff --git a/src/main/java/net/floodlightcontroller/mastership/MastershipWebRoutable.java b/src/main/java/net/onrc/onos/registry/controller/RegistryWebRoutable.java
similarity index 61%
rename from src/main/java/net/floodlightcontroller/mastership/MastershipWebRoutable.java
rename to src/main/java/net/onrc/onos/registry/controller/RegistryWebRoutable.java
index 56d5d66..8b5123b 100644
--- a/src/main/java/net/floodlightcontroller/mastership/MastershipWebRoutable.java
+++ b/src/main/java/net/onrc/onos/registry/controller/RegistryWebRoutable.java
@@ -1,4 +1,4 @@
-package net.floodlightcontroller.mastership;
+package net.onrc.onos.registry.controller;
import org.restlet.Context;
import org.restlet.Restlet;
@@ -6,18 +6,18 @@
import net.floodlightcontroller.restserver.RestletRoutable;
-public class MastershipWebRoutable implements RestletRoutable {
+public class RegistryWebRoutable implements RestletRoutable {
@Override
public Restlet getRestlet(Context context) {
Router router = new Router(context);
- router.attach("/json", MastershipRouteResource.class);
+ router.attach("/json", RegistryRouteResource.class);
return router;
}
@Override
public String basePath() {
- return "/wm/mastership";
+ return "/wm/registry";
}
}
diff --git a/src/main/resources/META-INF/services/net.floodlightcontroller.core.module.IFloodlightModule b/src/main/resources/META-INF/services/net.floodlightcontroller.core.module.IFloodlightModule
index 44436f4..e784f56 100644
--- a/src/main/resources/META-INF/services/net.floodlightcontroller.core.module.IFloodlightModule
+++ b/src/main/resources/META-INF/services/net.floodlightcontroller.core.module.IFloodlightModule
@@ -23,6 +23,6 @@
net.floodlightcontroller.core.test.MockFloodlightProvider
net.floodlightcontroller.core.test.MockThreadPoolService
net.floodlightcontroller.firewall.Firewall
-net.floodlightcontroller.mastership.MastershipManager
+net.onrc.onos.registry.controller.RegistryManager