Introduction

In this tutorial we will show you how to generate an ONOS bundle template. This makes it easy for you to add either an ONOS service or application. We will be using maven archetypes to generate our template, therefore this link could be handy if you would like to know more about this process.

Publish the artifacts to local repository

ONOS project started using BUCK from 1.7.0 hummingbird release. If you want to build ONOS application with maven archetype, you should publish the artifacts to local repository in ~/.m2:

onos-buck-publish-local

Generate your ONOS application project

Let's now generate an ONOS project which will be fully compilable and ready to be deployed. Although, you will still have to code up your application, we haven't yet figured out how to generate code that does exactly what you would like it to do . So let's start by running the following in a directory outside of $ONOS_ROOT:

Notably, this command will download the newest RELEASE version of onos-archetypes plugin and generate an ONOS application.

Alternatively, if you have the ONOS code checked out and available, you can use the onos-create-app tool to accomplish the same thing. It's important to note that if your ONOS is a SNAPSHOT version and is built with Buck, you should change directory to $ONOS_ROOT/tools/package/archetypes and generate the onos-archetypes firstly:

cd $ONOS_ROOT/tools/package/archetypes
mvn clean install

Then run in a directory outside of $ONOS_ROOT where you want to have your application:

onos-create-app

You will now be asked for several pieces of specific information about the bundle you would like to generate as you can see below. Make sure to enter parameters that are appropriate for you.

This will instruct the onos-maven-plugin to package the bundle as an ONOS application by producing an .oar (ONOS Application aRchive). After saving the changes, build the project as follows:

$ mvn clean install

When the build is complete, both the OSGi bundle and the application archive have been installed in your local maven repository. To install the application into running ONOS instance (or cluster), you can use the onos-app tool, which uses ONOS REST API within, to upload the .oar file as shown in the following example. If you need help running ONOS please refer to this page.

$ onos-app localhost install target/foo-app-1.0-SNAPSHOT.oar

Now, from the ONOS console, you should be able to see the application has been installed,

You can now use the generated code for this test app as a framework for adding your own custom code. If you edit the file src/main/java/org/foo/app/AppComponent.java, you can see how the application is created, and add your own code to the application.

Overlays

ONOS applications can hook into the ONOS CLI and GUI. When generating your application, you can use overlays to generate the classes needed to give your application access to these services.

Command Line Overlay

To allow your application to add commands to the ONOS CLI, overlay the CLI interface like this:

Creating a CLI Overlay

onos-create-app cli org.foo.app foo-app 1.0.0

Now, as before, we need to build and install our application. Since we installed it once already, we will use the reinstall command to deploy it:

Using the ONOS command line, restart the application (or use reinstall! in the command above):

onos> app activate org.foo.app

Using the ONOS command line, we now have access to the 'sample' command, which was defined by our overlay:

onos> sample
Hello World

You can use the CLI overlay to add your own commands to the CLI for your app. Edit the file src/main/java/org/foo/app/AppCommand.java to see how the sample command is implemented and the file src/main/resources/OSGI-INF/blueprint/shell-config.xml to see how new commands are integrated into the existing CLI.

User Interface Overlays

To allow your application to add to the ONOS web UI, overlay one of the UI interfaces. Navigate in the shell to the directory in which you have already created your app.

Choose to use either the "Custom View" overlay, like this:

Creating a UI Overlay – Custom View

onos-create-app ui org.foo.app foo-app 1.0.0

... or the "Tabular View" overlay, like this:

Creating a UI Overlay – Tabular View

onos-create-app uitab org.foo.app foo-app 1.0.0

... or you can even create a REST interface for your application, like this:

Creating a REST interface

onos-create-app rest org.foo.app foo-app 1.0.0

Now, as before, we need to build and install our application. Since we installed it once already, we will use the reinstall command to deploy it:

Using the ONOS command line, restart the application (or use reinstall! in the command above):

onos> app activate org.foo.app

The web UI overlay is now active. To view the new application page that was just created, point your browser to the ONOS GUI at http://localhost:8181/onos/ui/. In the upper left corner of the home page, click the navigation button to activate the drop down navigation menu. At the bottom of the list, you will see an entry for "Sample Custom" or "Sample Table", depending on which overlay you used. If you select it, you will navigate to the page that was installed by your test application.

ONOS can automatically generate SwaggerUI documentation for the URIs exposed in your RESTful application. After activating the application, you can visit the SwaggerUI at http://localhost:8181/v1/docs/ . You need to select Sample app REST API to test the URIs of your application.

Happy coding

Finally your application is loaded and running withing ONOS. Also, the generation process has generated an entire project which can be loaded into your favourite JAVA editor.