Often times, when I have to prototype quickly an OpenFlow application or if I need to test a specific match condition on OpenFlow, I usually stick with Ryu, since it has support even for OpenFlow 1.5, it’s completely written in Python and it has some amazing test suites. However, if you’ve never run Ryu controller before, you’ll realize that sometimes you’ll have to dig into the code to figure out a way to accomplish whatever you want and also, most likely if you’re running multiple applications you’ll certainly want to have a proper logging configuration in place to trace which application (or Python module) sent which message and correlate the events, otherwise you’ll probably get lost in a storm of messages depending on what you’re testing or debugging. So, on this post I’ll briefly show to you how to set a simple logging.ini file in order to address these points.
First, if you just want to have an overall overview, starting with a root filter and setting up the logging level to
DEBUG will show you all the messages. So, from this point you can start narrowing down to the logging level or even to narrow down to just a single or multiple Python modules that you’re interested in. A simple logging.ini configuration file looks like this:
You can find more information about Python logging configuration file here.
Let’s run two Ryu applications, but before I do that let me first decrease the level of the root logger to INFO on logging.ini file, otherwise the output would be too lengthy for this post (you can proceed with level DEBUG as an exercise):
Starting both simple_switch_13 and ofctl_rest Ryu applications:
As you can see bellow, there are three threads as a result, MainThread, GreenThread-1 and GreenThread-2:
Assuming that you just want to see events of the SimpleSwitch13 and ryu.base.app_manager modules, let’s make these changes:
1 - Add two extra loggers,
logger_ryu.base.app_manager, and set their levels to INFO.
2 - Decrease the root logger logging level to ERROR, just so all the other modules only show errors and nothing else.
This is the final logging.ini file with after applying these changes:
This is the final result on the terminal, as you can see, there’s no
ryu.lib.hub being logged anymore, only ryu.base.app_manager (MainThread) and the other green thread of SimplesSwitch13 (which now is GreenThread-1):
Ryu is written in Python so, you can set the logging module whoever you feel is more convenient to help you to troubleshoot the problem. Usually, I’d recommend that you start with full DEBUG at the root level and narrow down accordingly.