This is an archive of the ONOS 1.1 wiki. For the current ONOS wiki, look here.

Work-in-progress. Completed page will be linked into the Tutorials and Walkthroughs page.

Overview

This tutorial shows you how to incorporate tunable parameters into your component by making the link-flapping behavior of the NullLinkProvider from the Provider Tutorial configurable.

By completing this tutorial, you will understand:

  • The usage of @Property and @Modified annotations to add and use tunable parameters
  • The usage of configuration files to apply user configurations

While we use a Provider in this tutorial, the procedure described here is also applicable to applications.

As in the case of other tutorials, ${ONOS_ROOT} refers to the project root directory of ONOS, and ${KARAF_ROOT} refers to the installation location of Apache Karaf.

Modifications

1. Modify the component POM file.

We use Component Contexts to pass configuration information to the component. The following should be added to the component's POM file, in this case, the Provider-specific pom.xml, in ${ONOS_ROOT}/providers/null/link :

Provider-specific pom.xml Expand source

2. Add support for configuration.

We make a few modifications to the NullLinkProvider:

NullLinkProvider.java Expand source

We note two features needed for configurability:

  • ComponentContext context : Used to pass around information read from a configuration file
  • @Modified : Annotation indicating that the modified() method should be called when configuration changes are made.

We call modified() from activate()so that the configuration file is read at module startup. Afterwards, the @modified annotation causes modified() to be called whenever the file is changed.

3. Annotate the tunable parameters.

The two tunable parameters for the NullLinkProvider are:

  • Enable/disable link flapping
  • Link flapping rate (in milliseconds)

Luckily, we had already defined the variables associated with these parameters, flicker and eventRate, so we annotate them (and change FLICKER to false):

NullLinkProvider.java Expand source

4. Add file-parsing code.

Next, we implement modified() to parse out the values set for these parameters.

NullLinkProvider.java - modified() Expand source

5. Create a configuration file.

The configurations associated with tunable components are named by the FQDN of the component. For example, the NullLinkProvider, this would be org.onosproject.provider.nil.link.impl.NullLinkProvider.cfg. The files are added to different locations, depending on where you want to run ONOS:

  • ${ONOS_ROOT}/tools/package/etc/ , if you wan to package and deploy ONOS instances on remote machines or VMs
  • ${KARAF_ROOT}/etc/ , if you wish to launch ONOS locally on your machine

The contents of the file are simple, a list of parameter names and their values:

# Sample configurations for the NullLinkProvider.
#
# If enabled, generates LinkDetected and LinkVanished events
# to make the link appear to be flapping.
#
# flicker = true
#
# If enabled, sets the time between LinkEvent generation,
# in milliseconds.
#
# eventRate = 2000

Verification

We can now rebuild the Null Providers to test the configurability of this Provider.

 

 

  • No labels