When a new developer set-out to write a SDN app in ODL, the learning curve is way too steep. Even though ONOS also follows maven archetypes , ONOS developers had made things simpler by providing a wrapper called onos-create-app.
I will let you glean-through the Template Application Tutorial to setup the skeleton app. Once you are done, continue reading through.
Scope of our application
Let us now create a simple application to get the Port Statistics of all the ports from all the devices ( possibly openflow devices ) that are attached to the controller.
So what exactly we mean about port statistics?? Well, it is basically the amount of packet, bytes that are sent to / recieved from a given port from a given device.
ONOS also maintain another special version of statistics known as Port Delta Statistics which actually provides the delta between 2 given probe intervals.
How to get our data from controller ?
ONOS exposes different services to poke into and get data. One such service is DeviceService. This particular service abstracts the south bound device irrespective of the south bound interface that is connected with.
So let us use this service to get the list of devices first. But before that, we need to get a reference of the interface class.
While this rudimentary, why not let us monitor every port of every device in autonomous way? Sounds good right??
All we need now is a worker for us to work in independant fashion. Well the solution is
TimerTask. So let us create a new class
TimerTask and fire an independant task operation as follows.
But before that, let us look how our
portStatsReaderTask might look.
Hope you get the implementation.
portStatsReaderTask contains an inner class named
TimerTask. This is necessary if we want to use
portStatsReaderTask as a self contained component ( you will get more clarity in the place where we really use this class ).
schedule() are really the heart & nerve of this whole logic. For the sake of this blog, I didn’t make the full source available. I shall provide a link to github source at the end of this post.
Having defined our worker, let us give some work to the worker.
deactivate function :
AppComponent class provides
deactivate() functions which marks the start & end of every ONOS app’s lifecycle. So we are going to place our logic in
First every device, we get
List<PortStatistics> objects. And for every element in list, we prepare a map of
port number and spawn a new
portStatsReaderTaskfor every element in list. Now you can understand the reason for create a wrapper as explained above.
As per ONOS's openflow driver (provider/of/device/impl/OpenFlowDeviceProvider.java), the polling frequency is set to 5 seconds. Hence you might need to understand that the B/W measurement depends on this 5 seconds polling intervals.
If incase you are trying to match the B/W data with external observer data ( like iperf for example ),
you might need to fix the probing interval of that observer as well to 5 seconds.
Just before saying Cya…
I hope this post would have provided you enough inputs on getting started with your ONOS app development. The idea is to provide a complete walk-through of a simple app and I hope I did justice to that intent. Feel free to fire in any questions / comments / clarifications and I would be happy to help.