OpenDaylight & OSGI

What Is OSGI

  • OSGI defines an architecture for modular application development.
  • It adds a modular framework that allows for dynamic loading/unloading/starting/stopping of Java modules without bringing down the entire running JVM platform.
  • These modules are called bundles which is nothing but jars with manifest files that defines what is exported to other bundles and what is imported from other bundles in addition to other details such as bundle name, activator, version etc.
  • A bundle alone can act as a service provider or a service consumer. Services are specified by Java interfaces. Bundles can implement this interface and register the service with the Service Registry.
  • Consumers of a particular service can look up for it in the service registry.
OSGI Bundle Life Cycle

osgi bundle life cycle

Example

Let’s take an example of how an OSGI bundle can be stopped and started without re-starting opendaylight controller.

Launch opendaylight controller by running run.bat or run.sh. This will load the OSGI environment & provide an osgi> prompt as shown in the figure below. In background, we have logged into opendaylight controller through web interface.

OSGI and opendaylight

Now, as you can see there are three tabs – Devices, Flows and Troubleshoot. Let’s dynamically add and remove Flows tab using OSGI prompt. By running command “ss flows”, we figured out the id of corresponding OSGI bundle is 152.

Now let’s stop this bundle by running command “stop 152″ and see what happens.

stop an osgi bundle

Notice that we are now left with only two tabs – Devices and Troubleshoot. Flows tab is not available now since we have stopped the corresponding OSGI bundle.

Now, let’s start this bundle again by running command “start 152″.

start an osgi bundle

Notice that Flows tab has appeared again.

So we stopped and started an individual OSGI bundle without bringing down the entire controller. Easy it was, wasn’t it? ;)

What Is Equinox

Equinox is an open-source OSGI Container that eclipse uses internally. It implements various optional OSGi services and other infrastructure for running OSGi-based system. In opendaylight controller project it is used as a launcher – bundles are executed atop the OSGi Framework Equinox.

What Is Felix

Apache Felix is another OSGI Container. In opendaylight controller project, it’s file install and dependency manager functionality are used. During the Maven build process,  the bundle plugin from Apache Felix is used to create the OSGI bundle.

Why We Use Both Equinox & Felix

Declarative Services in Equinox base framework were not sufficient to provide the needed flexibility in life-cycle management of OSGI bundles. Apache Felix Dependency Management provided that flexibility in addition to the replacement of xml files (used in equinox to to define the bundle dependency) by plain Java files. Refer to below mail thread for more clarification.

https://lists.opendaylight.org/pipermail/controller-dev/2013-July/000797.html

References

  • http://en.wikipedia.org/wiki/OSGi
  • http://www.eclipse.org/equinox/

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *