Showing results for 
Search instead for 
Did you mean: 
Cisco Employee
Cisco Employee

This is a short introduction to the opendaylight-startup-archetype which is the easiest way to get started writing an OpenDaylight MD-SAL application. An archetype creates a maven project from a template, giving you a working project to start from.

mvn archetype:generate \
-DarchetypeGroupId=org.opendaylight.controller \
-DarchetypeArtifactId=opendaylight-startup-archetype \
-DarchetypeVersion=1.0.3-Lithium-SR3 \

Follow the prompts to set the project parameters. When I ran the archetype I called my project demoproject so the snippets I use will always reference demoproject. Let me explain the structure of the generated project and the purpose of each part.

Note that the default value for the 'version' property is 1.0-SNAPSHOT. This causes problems when you want to install the project into an OpenDaylight release such as Lithium-SR3 because it is configured to ignore snapshots. If you set the 'version' property to 1.0 then the generated artifacts will work.

This is the structure of the generated project:

api  # contains the YANG model for your project
  |-- src/main/yang/demoproject.yang
  `-- pom.xml
impl # contains the project implementation
  |-- src/main/java
  | |-- com/cisco/impl/
  | `-- org/.../demoproject/impl/rev141210/ # Your module init class
  |-- src/main/yang/demoproject-impl.yang # YANG definition for your module config
  |-- src/main/config/default-config.xml  # Your module config file
  `-- pom.xml
features # contains the feature definition for Karaf
  |-- src/main/features/features.xml # defines features that can be installed in karaf
  `-- pom.xml
artifacts # maven project that includes all artifacts required by project
  `-- pom.xml # references demoproject-api, demoproject-impl, demoproject-features
karaf # maven project that builds an OpenDaylight karaf distribution
  `-- pom.xml # includes odl-demoproject-ui in the list of karaf local features

Without changing anything in the generated project, you can build the project and then run the generated Karaf distribution:

% cd demoproject
% mvn install
% ./karaf/target/assembly/bin/karaf

    ________                      ________                .__  .__      .__    __     
    \_____  \ ______  ____  ____ \______ \ _____  ___.__.|  | |__| ____ |  |___/  |_   
    /  |  \\____ \_/ __ \ /    \ |    |  \\__  \<  |  ||  | |  |/ ___\|  |  \  __\   
    /    |    \  |_> >  ___/|  |  \|    `  \/ __ \\___  ||  |_|  / /_/  >  Y  \  |     
    \_______  /  __/ \___  >___|  /_______  (____  / ____||____/__\___  /|___|  /__|     
            \/|__|        \/    \/        \/    \/\/            /_____/      \/         

Hit '<tab>' for a list of available commands
and '[cmd] --help' for help on a specific command.
Hit '<ctrl-d>' or type 'system:shutdown' or 'logout' to shutdown OpenDaylight.

opendaylight-user@root>feature:list | grep demoproject
odl-demoproject-api  | 1.0-SNAPSHOT | x  | odl-demoproject-1.0-SNAPSHOT | OpenDaylight :: demoproject :: api
odl-demoproject      | 1.0-SNAPSHOT | x  | odl-demoproject-1.0-SNAPSHOT | OpenDaylight :: demoproject
odl-demoproject-rest | 1.0-SNAPSHOT | x  | odl-demoproject-1.0-SNAPSHOT | OpenDaylight :: demoproject :: REST
odl-demoproject-ui  | 1.0-SNAPSHOT | x  | odl-demoproject-1.0-SNAPSHOT | OpenDaylight :: demoproject :: UI

As you can see, there are 4 features instlalled in karaf from my project. These features are define in the features.xml file. Features are a karaf concept that make it easier to install multiple OSGi bundles and their dependencies. A features.xml file is a "Feature Repository" which can contain multiple feature definitions. Here is the features.xml file with inline comments:

<?xml version="1.0" encoding="UTF-8"?>
<features name="odl-demoproject-${project.version}" xmlns=""
    Karaf features are defined in repositories. In order to reference a feature, you first need to
    declare its repository location. Repositories are just feature definition files that are stored
    in a Maven repo.
    The odl-demoproject-api feature references the odl-yangtools-models as a dependency and
    adds the demoproject-api bundle. This feature just installs the model into karaf.
  <feature name='odl-demoproject-api' version='${project.version}' description='OpenDaylight :: demoproject :: api'>
    <feature version='${yangtools.version}'>odl-yangtools-models</feature>
    The odl-demoproject feature references mdsal and the odl-demoproject-api features.
    It adds the demoproject-impl bundle. It also adds a configfile that tells OpenDaylight how
    to start this feature.
  <feature name='odl-demoproject' version='${project.version}' description='OpenDaylight :: demoproject'>
    <feature version='${mdsal.version}'>odl-mdsal-broker</feature>
    <feature version='${project.version}'>odl-demoproject-api</feature>
    <configfile finalname="${}/demoproject.xml">${project.version}/xml/config</configfile>
    This feature references the odl-demoproject and odl-restconf features.
    It ensures that the necessary features get installed to allow you to call your application via RESTCONF
  <feature name='odl-demoproject-rest' version='${project.version}' description='OpenDaylight :: demoproject :: REST'>
    <feature version="${project.version}">odl-demoproject</feature>
    <feature version="${mdsal.version}">odl-restconf</feature>
    This feature references the odl-demoproject-rest feature and also MD-SAL apidocs and xsql features.
    It ensures that the necessary features get installed to allow API doc UI to work for your project.
  <feature name='odl-demoproject-ui' version='${project.version}' description='OpenDaylight :: demoproject :: UI'>
    <feature version="${project.version}">odl-demoproject-rest</feature>
    <feature version="${mdsal.version}">odl-mdsal-apidocs</feature>
    <feature version="${mdsal.version}">odl-mdsal-xsql</feature>

You can install your application into a separate OpenDaylight runtime such as the Lithium-SR3 distribution. The maven project builds a Karaf "kar" file in features/target/demoproject-features-1.0.kar which can be copied into the karaf deploy directory:

% cp demoproject/features/target/demoproject-features-1.0.kar distribution-karaf-0.3.3-Lithium-SR3/deploy

Note that the OpenDaylight Lithium-SR3 distribution is configured to ignore snapshots so it is important that your project does not have a version like 1.0-SNAPSHOT.

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community:

Recognize Your Peers