diff --git a/src/main/java/net/floodlightcontroller/core/internal/Controller.java b/src/main/java/net/floodlightcontroller/core/internal/Controller.java index 21e1244a3eadaf9fd6df4089b08d59c87b4e4719..38b26f481a58f5040c947652a31b5d3e9d60a8b9 100644 --- a/src/main/java/net/floodlightcontroller/core/internal/Controller.java +++ b/src/main/java/net/floodlightcontroller/core/internal/Controller.java @@ -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); diff --git a/src/main/java/net/floodlightcontroller/core/module/IFloodlightModuleContext.java b/src/main/java/net/floodlightcontroller/core/module/IFloodlightModuleContext.java index 6dce334f8cd15c529c9aa56e55f07418e0adb705..46dea092c2eaa20b180b2176ddd3babbb2d24b26 100644 --- a/src/main/java/net/floodlightcontroller/core/module/IFloodlightModuleContext.java +++ b/src/main/java/net/floodlightcontroller/core/module/IFloodlightModuleContext.java @@ -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 diff --git a/src/main/java/net/floodlightcontroller/jython/JythonDebugInterface.java b/src/main/java/net/floodlightcontroller/jython/JythonDebugInterface.java index 213921b03b415f2c88d0bca4ca1355579cdd89a3..49f1692d6bf5406643b64b9db3b9574baecf7f1c 100644 --- a/src/main/java/net/floodlightcontroller/jython/JythonDebugInterface.java +++ b/src/main/java/net/floodlightcontroller/jython/JythonDebugInterface.java @@ -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(); } } diff --git a/src/main/java/net/floodlightcontroller/jython/JythonServer.java b/src/main/java/net/floodlightcontroller/jython/JythonServer.java index 98ee956b3fd722b4611e09042567884e974250eb..2eb28e817c44de4e0d7a15b07375252e002c8c03 100644 --- a/src/main/java/net/floodlightcontroller/jython/JythonServer.java +++ b/src/main/java/net/floodlightcontroller/jython/JythonServer.java @@ -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())"); + } } - } diff --git a/src/main/java/net/floodlightcontroller/restserver/RestApiServer.java b/src/main/java/net/floodlightcontroller/restserver/RestApiServer.java index 80813a37c7e255c99f17abf54d81197a12bbb7b1..9b0b8f5909bfd3bdf6863546174e08350574a8d7 100644 --- a/src/main/java/net/floodlightcontroller/restserver/RestApiServer.java +++ b/src/main/java/net/floodlightcontroller/restserver/RestApiServer.java @@ -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); diff --git a/src/main/python/debugserver.py b/src/main/python/debugserver.py index d8c81f9d49c3ff1c1e77f3b04acefa9dbfbf93e5..5d9272d62007cbde6ba400618b8551148791d8b9 100644 --- a/src/main/python/debugserver.py +++ b/src/main/python/debugserver.py @@ -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: diff --git a/src/main/resources/floodlightdefault.properties b/src/main/resources/floodlightdefault.properties index 2d384d3a1b6e39accfcd56839588cbfc1fb9bdbe..522e5c39e73fe3fd30c528a51a2e0d125dd7df46 100644 --- a/src/main/resources/floodlightdefault.properties +++ b/src/main/resources/floodlightdefault.properties @@ -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