Creating your own application in OpenDaylight

 In Opendaylight


Introduction to Opendaylight

OpenDaylight Project is a collaborative open source project hosted by The Linux Foundation. The goal of the project is to accelerate the adoption of software-defined networking (SDN) and create a solid foundation for Network Functions Virtualization (NFV). The microservices architecture allows users to control applications, protocols and plugins, as well as to provide connections between external consumers and providers. Refer OpendayLight Beryllium solution architecture here

Opendaylight Technology stack

  • Maven – To build automation and its archetype is been used for setting up initial project structure to develop applications
  • Java – Framework is built in Java
  • Apache Karaf – Lightweight OSGi container for loading modules dynamically at runtime
  • YANG – For data modelling language, RPC & notification between different modules.


Application Development Process Flow

The diagram below outlines the application development process flowOpenDaylight-img

Development Environment Prerequisites

1.Maven 3.1.1 or above
2.Java 7 or above
3.Eclipse IDE & Yang plugin [Optional]

Step by step procedure for developing OpenDaylight Controller Application

The steps outlined are intended to build OpenDaylight Controller application in Beryllium release.

Step-1: Configure Maven settings.xml

Execute below command to setup your maven settings.xml under ~/.m2 directory.
cp -n ~/.m2/settings.xml{,.orig} ; \wget -q -O - settings.xml > ~/.m2/settings.xml

Make sure MAVEN_OPTS, JAVA_HOME environment variables are set. If not configure them as part of ~/.bashrc in linux

export MAVEN_OPTS='-Xmx1048m -XX:MaxPermSize=512m'
export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-amd64
export PATH=$JAVA_HOME/bin:$PATH

Project setup using Maven Archetype:

This is to create a project using Maven build tool in which archetype of ‘opendaylight-startup-archetype’ is used.

mvn archetype:generate -DarchetypeGroupId=org.opendaylight.controller

This will prompt you for below inputs,

Define value for property 'groupId': : <com.cloudenablers.networkoptimizer>
Define value for property 'artifactId': : <networkoptimizer>
[INFO] Using property: version = 1.0.0-SNAPSHOT
Define value for property 'package': com.cloudenablers.networkoptimizer: :
Define value for property 'classPrefix': Networkoptimizer: :
Define value for property 'copyright': : Copyright (c) 2016 Cloudenablers


Once this is completed, it should have generated networkoptimizer directory with its sub-folders in below hierarchy
├── api
├── artifacts
├── features
├── impl
├── it
├── karaf
└── pom.xml


Step-2: Build, Start & Verify the Application

Execute the below command to build the project
mvn clean install
Start the OSGi karaf runtime container

Verify the network optimizer module is built and installed as part of Karaf

[email protected]>feature:list | grep networkoptimizer

[email protected]>feature:list | grep networkoptimizer
odl-networkoptimizer-api | 1.0.0-SNAPSHOT | x | odl-networkoptimizer-1.0.0-SNAPSHOT | OpenDaylight ::
networkoptimizer :: api
odl-networkoptimizer | 1.0.0-SNAPSHOT | x | odl-networkoptimizer-1.0.0-SNAPSHOT | OpenDaylight ::
odl-networkoptimizer-rest | 1.0.0-SNAPSHOT | x | odl-networkoptimizer-1.0.0-SNAPSHOT | OpenDaylight ::
networkoptimizer :: REST
odl-networkoptimizer-ui | 1.0.0-SNAPSHOT | x | odl-networkoptimizer-1.0.0-SNAPSHOT | OpenDaylight ::
networkoptimizer :: UI
[email protected]>

Shutdown the karaf container
[email protected]>shutdown -f

Step-3: YANG definition for RPC

Below YANG defines a RPC named as service-account with inputs & outputs.

module networkoptimizer {
yang-version 1;
namespace "urn:opendaylight:params:xml:ns:yang:networkoptimizer";
prefix "networkoptimizer";
revision "2015-01-05" {
description "Initial revision of networkoptimizer model";
rpc service-account{
input {
leaf name {
type string;
leaf description {
type string;
output {
leaf service_name {
type string;

On re-building the application with this YANG, it would generate Java Objects & interfaces corresponding to the attributes defined in YANG. Please refer the below files which are auto generated under the api subdirectories.

├── $
└── $


Step-4: Eclipse setup

In Eclipse, import the networkoptimizer directory genearted as the Maven project. This would create different projects in eclipse for different top folder. In which add ‘api’ project as dependency to ‘impl’.

Step-5: Implement RPC:

Provide an implementation for the service interface generated by yangtools from the yang definition of serviceaccount. You can create the file which provides that implementation under impl/src/main/java/com/cloudenablers/networkoptimizer/impl/ and paste the below content in it.

package com.cloudenablers.networkoptimizer.impl;

import java.util.concurrent.Future;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.networkoptimizer.rev150105.NetworkoptimizerService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.networkoptimizer.rev150105.ServiceAccountInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.networkoptimizer.rev150105.ServiceAccountOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.networkoptimizer.rev150105.ServiceAccountOutputBuilder;

import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;

public class NetworkoptimizerImpl implements NetworkoptimizerService

public Future<RpcResult>
serviceAccount(ServiceAccountInput input) {
ServiceAccountOutputBuilder serviceAccBuilder = new ServiceAccountOutputBuilder();
serviceAccBuilder.setServiceName(“RPC request successful for Service Name: ” + input.getName());


Step-6: Register RPC

Add RPC registeration in the file under impl/src/main/java/com/cloudenablers/networkoptimizer/impl/ with the below content

package com.cloudenablers.networkoptimizer.impl;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration;
import com.cloudenablers.networkoptimizer.impl.NetworkoptimizerImpl;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.networkoptimizer.rev150105.NetworkoptimizerService;
import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class NetworkoptimizerProvider implements BindingAwareProvider, AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(NetworkoptimizerProvider.class);
private RpcRegistration<NetworkoptimizerService> optimizerService;
public void onSessionInitiated(ProviderContext session) {“NetworkoptimizerProvider Session Initiated”);
optimizerService = session.addRpcImplementation(NetworkoptimizerService.class, new NetworkoptimizerImpl());
public void close() throws Exception {“NetworkoptimizerProvider Closed”);


Step-7: Rebuild & start the Karaf

mvn clean install


Step-8: Verify the networkoptimizer module RPC

Launch the Opendaylight apidoc explorer with the below url and select the networkoptimizer module
Note: Default credentials for authentication in Apache Karaf is admin/admin

POST /operations/networkoptimizer:service-account
"name": "Demo_App",
"description": "Simple ODL App"

“output”: {
“service_name”: “RPC request successful for Service Name:

Application Source Code:

Anybody wants to try out the application, then please refer this github url to get the application source code


1.[Refer developer’s guide which is an updated one compared to wiki] 2.
5.” target=”_blank” >

Recent Posts

Leave a Comment

Start typing and press Enter to search