Skip to content
Snippets Groups Projects
Commit 5e7ef76e authored by Kuang-Ching Wang's avatar Kuang-Ching Wang
Browse files

Merge pull request #379 from vy/hostparam

Provide parameters for configuring the host addresses that Controller/REST/Jython listens on.
parents 6c1e3330 ba0fa0ab
No related branches found
No related tags found
No related merge requests found
......@@ -180,6 +180,7 @@ public class Controller implements IFloodlightProviderService,
protected IThreadPoolService threadPool;
// Configuration options
protected String openFlowHost = null;
protected int openFlowPort = 6633;
protected int workerThreads = 0;
......@@ -1714,7 +1715,10 @@ public class Controller implements IFloodlightProviderService,
ChannelPipelineFactory pfact =
new OpenflowPipelineFactory(this, null);
bootstrap.setPipelineFactory(pfact);
InetSocketAddress sa = new InetSocketAddress(openFlowPort);
InetSocketAddress sa =
(openFlowHost == null)
? new InetSocketAddress(openFlowPort)
: new InetSocketAddress(openFlowHost, openFlowPort);
final ChannelGroup cg = new DefaultChannelGroup();
cg.add(bootstrap.bind(sa));
......@@ -1755,6 +1759,11 @@ public class Controller implements IFloodlightProviderService,
}
public void setConfigParams(Map<String, String> configParams) {
String ofHost = configParams.get("openflowhost");
if (ofHost != null) {
this.openFlowHost = ofHost;
log.debug("OpenFlow host set to {}", this.openFlowHost);
}
String ofPort = configParams.get("openflowport");
if (ofPort != null) {
this.openFlowPort = Integer.parseInt(ofPort);
......
......@@ -41,7 +41,7 @@ public interface IFloodlightModuleContext {
* @return All Floodlight modules that are going to be loaded
*/
public Collection<IFloodlightModule> getAllModules();
/**
* Gets module specific configuration parameters.
* @param module The module to get the configuration parameters for
......
......@@ -23,6 +23,7 @@ import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import net.floodlightcontroller.core.FloodlightProvider;
import net.floodlightcontroller.core.module.FloodlightModuleContext;
import net.floodlightcontroller.core.module.FloodlightModuleException;
import net.floodlightcontroller.core.module.IFloodlightModule;
......@@ -31,7 +32,8 @@ import net.floodlightcontroller.core.module.IFloodlightService;
public class JythonDebugInterface implements IFloodlightModule {
protected static Logger log = LoggerFactory.getLogger(JythonDebugInterface.class);
protected JythonServer debug_server;
protected static int JYTHON_PORT = 6655;
protected String jythonHost = null;
protected int jythonPort = 6655;
@Override
public Collection<Class<? extends IFloodlightService>> getModuleServices() {
......@@ -72,13 +74,22 @@ public class JythonDebugInterface implements IFloodlightModule {
// read our config options
Map<String, String> configOptions = context.getConfigParams(this);
int port = JYTHON_PORT;
String portNum = configOptions.get("port");
if (portNum != null) {
port = Integer.parseInt(portNum);
jythonHost = configOptions.get("host");
if (jythonHost == null) {
Map<String, String> providerConfigOptions = context.getConfigParams(
FloodlightProvider.class);
jythonHost = providerConfigOptions.get("openflowhost");
}
if (jythonHost != null) {
log.debug("Jython host set to {}", jythonHost);
}
String port = configOptions.get("port");
if (port != null) {
jythonPort = Integer.parseInt(port);
}
log.debug("Jython port set to {}", jythonPort);
JythonServer debug_server = new JythonServer(port, locals);
JythonServer debug_server = new JythonServer(jythonHost, jythonPort, locals);
debug_server.start();
}
}
......@@ -34,15 +34,18 @@ import org.slf4j.LoggerFactory;
public class JythonServer extends Thread {
protected static Logger log = LoggerFactory.getLogger(JythonServer.class);
String host;
int port;
Map<String, Object> locals;
/**
* @param host_ Host to use for jython server
* @param port_ Port to use for jython server
* @param locals_ Locals to add to the interpreters top level name space
*/
public JythonServer(int port_, Map<String, Object> locals_) {
this.port = port_ ;
public JythonServer(String host_, int port_, Map<String, Object> locals_) {
this.host = host_;
this.port = port_;
this.locals = locals_;
if (this.locals == null) {
this.locals = new HashMap<String, Object>();
......@@ -73,7 +76,10 @@ public class JythonServer extends Thread {
p.exec("import sys");
p.exec("sys.path.append('" + jarPath + "')");
p.exec("from debugserver import run_server");
p.exec("run_server(" + this.port + ", '0.0.0.0', locals())");
if (this.host == null) {
p.exec("run_server(port=" + this.port + ", locals=locals())");
} else {
p.exec("run_server(port=" + this.port + ", host='" + this.host + "', locals=locals())");
}
}
}
......@@ -40,6 +40,7 @@ import org.restlet.service.StatusService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import net.floodlightcontroller.core.FloodlightProvider;
import net.floodlightcontroller.core.module.FloodlightModuleContext;
import net.floodlightcontroller.core.module.FloodlightModuleException;
import net.floodlightcontroller.core.module.IFloodlightModule;
......@@ -50,6 +51,7 @@ public class RestApiServer
protected static Logger logger = LoggerFactory.getLogger(RestApiServer.class);
protected List<RestletRoutable> restlets;
protected FloodlightModuleContext fmlContext;
protected String restHost = null;
protected int restPort = 8080;
// ***********
......@@ -91,7 +93,7 @@ public class RestApiServer
return slashFilter;
}
public void run(FloodlightModuleContext fmlContext, int restPort) {
public void run(FloodlightModuleContext fmlContext, String restHost, int restPort) {
setStatusService(new StatusService() {
@Override
public Representation getRepresentation(Status status,
......@@ -114,7 +116,11 @@ public class RestApiServer
// Start listening for REST requests
try {
final Component component = new Component();
component.getServers().add(Protocol.HTTP, restPort);
if (restHost == null) {
component.getServers().add(Protocol.HTTP, restPort);
} else {
component.getServers().add(Protocol.HTTP, restHost, restPort);
}
component.getClients().add(Protocol.CLAP);
component.getDefaultHost().attach(this);
component.start();
......@@ -148,7 +154,7 @@ public class RestApiServer
}
RestApplication restApp = new RestApplication();
restApp.run(fmlContext, restPort);
restApp.run(fmlContext, restHost, restPort);
}
// *****************
......@@ -190,6 +196,15 @@ public class RestApiServer
// read our config options
Map<String, String> configOptions = context.getConfigParams(this);
restHost = configOptions.get("host");
if (restHost == null) {
Map<String, String> providerConfigOptions = context.getConfigParams(
FloodlightProvider.class);
restHost = providerConfigOptions.get("openflowhost");
}
if (restHost != null) {
logger.debug("REST host set to {}", restHost);
}
String port = configOptions.get("port");
if (port != null) {
restPort = Integer.parseInt(port);
......
......@@ -56,7 +56,7 @@ class DebugServer(TCPServer):
_log.debug('Closing connection to DebugServer from %s:%d' % client_address)
request.close()
def run_server(port=6655, host='0.0.0.0', locals=locals()):
def run_server(port=6655, host='', locals=locals()):
currentThread()._thread.setName("debugserver-main")
global _locals
......@@ -65,8 +65,8 @@ def run_server(port=6655, host='0.0.0.0', locals=locals()):
global _log
_log = locals["log"]
_log.info("Starting DebugServer on port %d" % port)
server = DebugServer(('', port), DebugServerHandler)
_log.info("Starting DebugServer on %s:%d" % (host, port))
server = DebugServer((host, port), DebugServerHandler)
try:
server.serve_forever()
except KeyboardInterrupt:
......
......@@ -16,7 +16,9 @@ net.floodlightcontroller.debugcounter.DebugCounter,\
net.floodlightcontroller.perfmon.PktInProcessingTime,\
net.floodlightcontroller.ui.web.StaticWebRoutable,\
net.floodlightcontroller.loadbalancer.LoadBalancer
net.floodlightcontroller.restserver.RestApiServer.host = 192.168.56.2
net.floodlightcontroller.restserver.RestApiServer.port = 8080
net.floodlightcontroller.core.FloodlightProvider.openflowhost = 192.168.56.1
net.floodlightcontroller.core.FloodlightProvider.openflowport = 6633
net.floodlightcontroller.jython.JythonDebugInterface.port = 6655
net.floodlightcontroller.forwarding.Forwarding.idletimeout = 5
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment