diff --git a/.gitignore b/.gitignore index b79ebe2942680058581bffac633a1294b5e282f4..aeb0dd73cfa475e0201e0be90a255c6240b0ba04 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ .DS_Store target thrift +logback.xml diff --git a/example/cli.py b/example/cli.py new file mode 100755 index 0000000000000000000000000000000000000000..f50788fca2311fb79662694412134d619a1e6b62 --- /dev/null +++ b/example/cli.py @@ -0,0 +1,109 @@ +#!/usr/bin/python + +import sys +import argparse +import json +import httplib +import urllib2 + +class RestApi(object): + + def __init__(self, server,port): + self.server = server + self.port = port + + def get(self, path): + #ret = self.rest_call(path, {}, 'GET') + #return ret[2] + f = urllib2.urlopen('http://'+self.server+':'+str(self.port)+path) + ret = f.read() + return json.loads(ret) + + def set(self, path, data): + ret = self.rest_call(path, data, 'POST') + return ret[0] == 200 + + def remove(self, objtype, data): + #ret = self.rest_call(data, 'DELETE') + return ret[0] == 200 + + def rest_call(self, path, data, action): + headers = { + 'Content-type': 'application/json', + 'Accept': 'application/json', + } + body = json.dumps(data) + conn = httplib.HTTPConnection(self.server, self.port) + conn.request(action, path, body, headers) + response = conn.getresponse() + ret = (response.status, response.reason, response.read()) + conn.close() + print str(ret[2]) + return ret + + + +usage_desc = """ +Command descriptions: + + host <MAC> + + link + + memory + + switch + + switch_stats [port, queue, flow, aggregate, desc, table, features, host] + + per_switch_stats [DPID] [port, queue, flow, aggregate, desc, table, features, host] + + """ + +def lookupPath(cmd): + path = '' + + numargs = len(args.otherargs) + + if args.cmd == 'switch_stats' and numargs == 1: + path = '/wm/core/switch/all/'+args.otherargs[0]+'/json' + elif args.cmd == 'per_switch_stats' and numargs == 2: + path = '/wm/core/switch/'+args.ortherargs[0]+'/'+args.otherargs[1]+'/json' + elif args.cmd == 'switch': + path = '/wm/core/controller/switches/json' + elif args.cmd == 'counter' and numargs == 1: + path = '/wm/core/counter/'+args.otherargs[0]+'/json' + elif args.cmd == 'switch_counter' and numargs == 2: + path = '/wm/core/counter/'+args.otherargs[0]+'/'+otherargs[1]+'/json' + elif args.cmd == 'memory': + path = '/wm/core/memory/json' + elif args.cmd == 'link': + path = '/wm/topology/links/json' + elif args.cmd == 'switchclusters': + path = '/wm/topology/switchclusters/json' + elif args.cmd == 'host': + if len(args.otherargs) == 0: + args.otherargs.append("all") + path = '/wm/devicemanager/device/'+args.otherargs[0]+'/json' + else: + print usage_desc + path = '' + exit(0) + return path + +parser = argparse.ArgumentParser(description='process args', usage=usage_desc, epilog='foo bar help') +parser.add_argument('--ip', default='localhost') +parser.add_argument('--port', default=8080) +parser.add_argument('cmd') +parser.add_argument('otherargs', nargs='*') +args = parser.parse_args() + +#print args + +rest = RestApi(args.ip, args.port) +path = lookupPath(args.cmd) + +out = rest.get(path) +print json.dumps(out,sort_keys=True, indent=4) +print "Number of items: " + str(len(out)) + diff --git a/floodlight.sh b/floodlight.sh index d0db5dd27f47edc0d51f61587b21b450225ae51c..04e9afb9218de6f38cd62f6d5eee14bade1f8037 100755 --- a/floodlight.sh +++ b/floodlight.sh @@ -26,10 +26,8 @@ JVM_OPTS="$JVM_OPTS -XX:CompileThreshold=1500 -XX:PreBlockSpin=8" </root> <logger name="org" level="WARN"/> <logger name="LogService" level="WARN"/> <!-- Restlet access logging --> - <logger name="net.floodlightcontroller" level="ERROR"/> + <logger name="net.floodlightcontroller" level="INFO"/> <logger name="net.floodlightcontroller.logging" level="ERROR"/> - <logger name="net.beaconcontroller" level="ERROR" /> - <logger name="net.beaconcontroller.logging" level="ERROR" /> </configuration> EOF_LOGBACK diff --git a/src/main/java/net/floodlightcontroller/core/internal/Controller.java b/src/main/java/net/floodlightcontroller/core/internal/Controller.java index f11bbf6fd59029c912a462013609f3486fd0f790..c087bf217c052cbdafcbce314947c2683c7a2685 100644 --- a/src/main/java/net/floodlightcontroller/core/internal/Controller.java +++ b/src/main/java/net/floodlightcontroller/core/internal/Controller.java @@ -1690,7 +1690,7 @@ public class Controller implements IFloodlightProviderService { if (threads != null) { this.workerThreads = Integer.parseInt(threads); } - log.info("Number of worker threads port set to {}", this.workerThreads); + log.info("Number of worker threads set to {}", this.workerThreads); String controllerId = configParams.get("controllerid"); if (controllerId != null) { this.controllerId = controllerId; diff --git a/src/main/java/net/floodlightcontroller/jython/JythonDebugInterface.java b/src/main/java/net/floodlightcontroller/jython/JythonDebugInterface.java index 0eb532963b8abe31b9d4c4dbba726f2070d3cc3e..19a97b5b93992b302e1557a758bd1f0324a3c6ca 100644 --- a/src/main/java/net/floodlightcontroller/jython/JythonDebugInterface.java +++ b/src/main/java/net/floodlightcontroller/jython/JythonDebugInterface.java @@ -14,7 +14,8 @@ import net.floodlightcontroller.core.module.IFloodlightService; public class JythonDebugInterface implements IFloodlightModule { protected static Logger log = LoggerFactory.getLogger(JythonDebugInterface.class); - JythonServer debug_server; + protected JythonServer debug_server; + protected static int JYTHON_PORT = 6655; @Override public Collection<Class<? extends IFloodlightService>> getModuleServices() { @@ -44,8 +45,7 @@ public class JythonDebugInterface implements IFloodlightModule { @Override public void startUp(FloodlightModuleContext context) { - Map<String, Object> locals = new HashMap<String, Object>(); - + Map<String, Object> locals = new HashMap<String, Object>(); // add all existing module references to the debug server for (Class<? extends IFloodlightService> s : context.getAllServices()) { // Put only the last part of the name @@ -54,7 +54,15 @@ public class JythonDebugInterface implements IFloodlightModule { locals.put(name, context.getServiceImpl(s)); } - JythonServer debug_server = new JythonServer(6655, locals); + // 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); + } + + JythonServer debug_server = new JythonServer(port, locals); debug_server.start(); } } diff --git a/src/main/resources/floodlightdefault.properties b/src/main/resources/floodlightdefault.properties index 687660194cf2dde6816c2fb94e3cf0388b2a4588..27b2795b3ed7443d3a32689dc2213708d0172505 100644 --- a/src/main/resources/floodlightdefault.properties +++ b/src/main/resources/floodlightdefault.properties @@ -7,3 +7,4 @@ net.floodlightcontroller.perfmon.PktInProcessingTime,\ net.floodlightcontroller.ui.web.StaticWebRoutable net.floodlightcontroller.restserver.RestApiServer.port = 8080 net.floodlightcontroller.core.FloodlightProvider.openflowport = 6633 +net.floodlightcontroller.jython.JythonDebugInterface.port = 6655 \ No newline at end of file