Showing posts with label application. Show all posts
Showing posts with label application. Show all posts

Tuesday, 22 October 2013

Creating a simple application in Open Daylight Controller

In this post I am going to make a simple application in ODL. Main aim of this application will be just to say "I have started" at the time of loading and "Over and out", when it stops.
To program for ODL you need to know java language and Maven, OSGi. Dont panic if you don't know about the last two its fairly easy and I will go step-by-step on that.
When you start developing your folder structure should be as below;

ubuntu@ubuntu:userinfo$ ls
META-INF pom.xml src target 


Here src is where you will have code; target is where you will have binaries META-INF has information related to OSGi (Explained later). You need not to worry about it right now Maven will take care of it.

To understand about OSGi and create a simple java code click here
To understand and create a simple pom file in ODL click here

Once you have build successfully go to your target directory. you will find samples.userinfo-0.4.0-SNAPSHOT.jar over there. Thats your bundle !

Now follow the steps at running a custom bundle and see your sample app running in controller.
If you have any queries feel free to post it :)


OSGi framework and Open DayLight

The newest SDN controller OpenDayLight is made on OSGi architecture. It gives you flexibility to load various plugins without stopping complete controller, which is cool actually as you can upgrade your existing plugin without any restart. So service is not affected. OSGi has three variations, OpenDayLight is made on equinox. (FYI eclipse is also made on equinox). OSGi bundles are essentially jar files. its the META-INF file which differentiates them. It has all information about the project. Whenever a project is loaded firstly an Activator class is called. (Note: That's why we give its address in tag bundle-activator in pom.xml). When bundle is loaded Activator first calls init method, and when you remove the bundle destroy method is called. the Now lets build a basic java code for ODL.


package org.opendaylight.controller.samples.userinfo.internal;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;


public class Activator extends ComponentActivatorAbstractBase {
    protected static final Logger logger = LoggerFactory
            .getLogger(Activator.class);

    /**
     * Function called when the activator starts just after some
     * initializations are done by the
     * ComponentActivatorAbstractBase.
     *
     */
    public void init() {
       logger.info("I have started !!");
    }

    /**
     * Function called when the activator stops just before the
     * cleanup done by ComponentActivatorAbstractBase
     *
     */
    public void destroy() {
              logger.info("Over and out !!");
    }

 }


For more info on pom file click here.
To create a sample application click here