OpenDaylight Maven and OSGI Dev Notes

OpenDaylight Maven and OSGI Dev Notes

OPENDAYLIGHT MAVEN AND OSGI DEV NOTES

Prior to OpenDaylight I had only used the ODGI framework with David Ericson’s Beacon contorller. I wanted to dump some of my notes from code hacking over the past couple of weeks. Most of the time has been spent getting used to OSGI and Maven. After the Maven and OSGI overviews, I list my dev notes for setting OSGI log levels, building an individual specific OpenDaylight bundle with Maven and making a creating a new module to hack on.

WHAT IS OSGI?

OSGI is adds a modular framework that allows for dynamic loading of Java modules. This means you can load and unload , start and stop applications without taking down the running JVM platform. This seems to fits the theme of OpenDaylight to allow applications and protocols to plug into the framework to fit different use cases and vendor strategies. The platform is merely a series of Java interfaces. The projects that plug into the framework are referred to as bundles. The bundles need a few things to get started.

WHAT IS MAVEN?

Here are some high points of the value Maven brings. Maven is awesome becuase it pulls dependencies automagically and lets you change version by merely changing the release number.

Making the build process easy

Providing a uniform build system

Providing quality project information

Providing guidelines for best practices development

Allowing transparent migration to new features

Change log document created directly from source control

Cross referenced sources

Mailing lists

Dependency list

Unit test reports including coverage

Keeping your test source code in a separate, but parallel source tree

Using test case naming conventions to locate and execute tests

Have test cases setup their environment and don’t rely on customizing the build for test preparation.

ENABLING LOGGING LEVELS AND TRACES IN THE OSGI CONSOLE

Lets say you want to see all log messages from the bundle. Change the logging level to arphandler to trace from the OSGI console.

BUILDING OPENDAYLIGHT MODULES INDIVIDUALLY AFTER CHANGING THE CODE

Once you edit code on an individual bundle, you need to rebuild the bundle for the code to take effect. It is way to slow to rebuild the entire platform, not to mention very un-agileish.

First, if the project is running, stop the module with the following from the OSGI console. In this case I am using the arphandler bundle as an example.

1

2

3

4

5

6

osgi ss|greparphandler

35ACTIVE org.opendaylight.controller.arphandler_0.4.0.SNAPSHOT

Stopabundle:

osgi stop35

Next, rebuild the bundle. When you build the project using mvn clean install, it will delete the existing jar file and create a new one. In order to get the new jar to load it needs to match the pom.xml loaded module. That is why I copy it in the second line in the following snippet.

Finally load the new jar into the framework. The cool thing is the JVM was never stopped in this process.

1

2

3

4

Startabundle:

osgi start35

You can also never stop the bundle and perform an upgrade using OSGI with:

1

2

3

4

Startabundle:

osgi upgrade35

OSGI will pull the current jar in the path and reload it.

HACKING BUNDLES : CREATE YOUR OWN MODULE

I am using bundles and projects (right or wrong) interchangeably. There are various ways to start bundles, but an easy starter could be to copy and paste an existing application. There are some example application bundles located in the “~/controller/opendaylight/samples/” directory. It can also be done using declarative services, but I have not explored that yet. This is just a total sample of how to hack and even better break things to learn the OSGI/Maven framework and the code order of operations. Keep in mind, there isn’t a main method with OSGI. It is more of blob projects/modules/bundles can plug into and dynamically loaded and unloaded without restarting the entire JVM.

Copy and application like samples.simpleforwarding and paste it into the project explorer.
Edit the project bundle pom.xml to match your new bundle: ~/controller/opendaylight/samples/simpleforwarding
Edit the parent pom.xml located in distribution.opendaylight and add the new bundle: ~/controller/opendaylight/distribution/opendaylight/pom.xml. The parent pom.xml denoted by is located in opendaylight/commons/opendaylight/pom.xml
The Activator.java can be used to start/stop/initialize/destroy bundles into the JVM. Simple examples are two methods starting a bundle, start/stop.

1

2

3

4

5

6

7

8

9

10

11

12

Amethod startingabundle:

public voidstart(BundleContext context){

Amethod tostop the bundle:

public voidstop(BundleContext context){

An arrayisrun togetall of the classobjects inside of OpenDaylight.Just copy andpastethe bundle:

public Object[]getImplementations(){

Object[]res={NewClass.class};

returnres;

}

Project Object Model or POM is the main piece of Maven that ties all of the projects in together. Each project has a pom.xml and the whole platform has a super pom.xml. The format is XML and fairly easy to discern what is going on. There is a patch in from David Erickson to bring the net-virt platform into the controller which will be awesome. The net-virt L2 forwarding module is very mature coupled with its host tracker. I hope to use it in production soon to proof reactive BUM traffic scale (may need a job:-).

UPDATE OPENDAYLIGHT USING GIT

Running git pull from anywhere south of the parent controller directory will update the code set. Then just rebuild it w/ mvn clean install. mvn clean will delete the existing built jars. Install will build and leave them in the target directory.

MORE OPENDAYLIGHT HOW-TOS

We are starting to have a good list of resources. Hack around and break it and fix it. I am great at the breaking part personally. Dont be overwhelmed, if you want to learn ODP or even programming you can if you put in the time. It is a unique time in networking to shape the future.

See more blogs from the ODP community and visit the OpenDaylight Wiki. If you do any how-tos feel free to shoot them to me and I will post them on the wiki.

Join the OpenDaylight IRC channel at irc.freenode.net at #opendaylight and colaborate with others from the community.

Regardless of any claims, no one really knows what the future of networking should or will be but open source is a safe bet based on history. Companies like Red Hat and IBM are well positioned in the Daylight project so keep that in mind when parsing through the FUD. Little if any of SDN is proofed beyond a few fixed scenarios. It is a great chance for both vendors and community to collaborate and evolve together for the future. The Linux Foundation is an appropriate organization for ODP to be under the auspices of. OpenDaylight has the makings of becoming the Linux kernel of networking.

To get there it will take community. The TSC’s role should be focused on community enablement. The broader OpenDaylight project goal should not only be bootstrapping code, but the equally important mission of bootstrapping a the fledgling network community. The vendors on the IRC channel everyday helping field dev questions are nothing short of phenomenal. Come grow with networking, I am happy to help, as are others in channel. No such thing as dumb questions.

Share this:

About the Author

Brent SalisburyI have over 15 years of experience wearing various hats from, network engineer, architect, devops and software engineer. I currently have the pleasure of working at the company that develops my favorite software I have ever used, Docker. My comments here are my personal thoughts and opinions. More at Brent's BioView all posts by Brent Salisbury →

Hi Brent, thanks for your really useful tutorials and notes on using OpenDayLight. I’ve created an OpenDayLight app developer tutorial: http://www.openflow.org/wk/index.php?title=OpenDayLight_Tutorial . Similar to the L2 Hub/Switch that folks developed for POX and NOX, I’ve created one for OpenDayLight. It was a fun exercise and I hope others benefit from it.
— Srini.

Elsie, the best place would be to jump on irc.freenode.net #opendaylight and ping the community in case someone else has run into the same issue. Or you can also email the controller-dev listserv for assist also.

I am swamped and have not had a chance to try out the tutorial myself. One of us should record it for folks having trouble with the steps. OSGI is tough at first.

0

| - Share

Guest

Elsie

1 year 8 months ago

Hi Brent,

How can I run a bundle in the opendaylight independently to check whether it can work or not?

Hi Elsie, a great place to start are the Junit’s in each bundle. You can’t right click in Eclipse or Intellij and run them as a Junit (Eclipse) or just run them standalone in Intellij and it will execute the integration or unit tests in the specified bundle/project. Not sure if that answers your question but it might help get started

Thanks,
-Brent

0

| - Share

Guest

Elsie

1 year 8 months ago

Hi Srini,

Thank you so much for your tutorial!

I followed the tutorial step by step. But I have no idea how to make it work…

after run the opendaylight-application.launch, and type
osgi> ss| grep tutorial
the response is false

Pickle The Coding Kittah

Pickle the cat is sleepy after rolling some code for me. If anything here was helpful consider supporting some homeless kitties and click the picture and help save some furry friends today! http://www.alleycat.org/ or head to The Petition Site www.thepetitionsite.com and sign a few petitions to help prevent animal cruelty. It only takes a few clicks to help out!

Podcast Roll

If you would like me to list your tech podcast here please don’t hesitate to ping me. I am short on time these days and its hard to keep up.

Start Blogging Today

Start blogging, coding, Tweeting, labbing, anything that contributes to the community while improving yourself at the same time. Either way, no one is going to learn for you and you sure as hell don’t want to wait on some poseur middle manager or peer talking a big game at the expense of your career. Take control of your own future. So few careers equate hard work to reward like IT. Enough pep talking, get to it and change the world!

Feel free to use anything you find on the site that is useful as long as no kitties are harmed in the process