OpenDaylight and OSGI basics

I am starting to learn about OSGI as it pertains to ODL.  OSGI allows for modules to be dynamically loaded and unloaded from a system, and provides encapsulation between those modules.  The modules are called bundles, and they provide services to one another via the execution environment.  The bundles are basically JAR files with a manifest file that indicates what is to be exported to other bundles, and what needs to be imported from other bundles. Here’s a diagram of how I currently think of it:
After executing the script in ODL, you will load the OSGI environment, and get an osgi> prompt which allows you to interact with the system.  We can use the command ss to get a list of all the bundles currently running:

osgi> ss
"Framework is launched."

id	State       Bundle
0	ACTIVE      org.eclipse.osgi_3.8.1.v20120830-144521
1	ACTIVE      org.apache.felix.fileinstall_3.1.6
2	ACTIVE      org.eclipse.jdt.core.compiler.batch_3.8.0.I20120518-2145
3	ACTIVE      org.eclipse.equinox.ds_1.4.0.v20120522-1841
4	ACTIVE      org.eclipse.equinox.util_1.0.400.v20120522-2049
5	ACTIVE      org.eclipse.osgi.services_3.3.100.v20120522-1822
6	ACTIVE      org.eclipse.equinox.console_1.0.0.v20120522-1841
7	ACTIVE      slf4j.api_1.7.2
8	ACTIVE      ch.qos.logback.classic_1.0.9
9	ACTIVE      ch.qos.logback.core_1.0.9
10	ACTIVE      org.opendaylight.controller.logging.bridge_0.4.0.SNAPSHOT
11	ACTIVE      com.sun.jersey.core_1.17.0
12	ACTIVE      com.sun.jersey.json_1.17.0
13	ACTIVE      com.sun.jersey.jersey-server_1.17.0
14	ACTIVE      org.opendaylight.controller.clustering.test_0.4.0.SNAPSHOT
15	ACTIVE      org.apache.felix.gogo.shell_0.8.0.v201110170705
... snip ...100	ACTIVE      org.opendaylight.controller.flowprogrammer.northbound_0.4.0.SNAPSHOT
101	RESOLVED    org.opendaylight.controller.troubleshoot.web_0.4.0.SNAPSHOT
102	ACTIVE      javax.servlet.jsp.jstl_1.2.0.v201105211821
103	ACTIVE      org.springframework.beans_3.1.3.RELEASE
104	ACTIVE      org.opendaylight.controller.configuration.implementation_0.4.0.SNAPSHOT
105	ACTIVE      org.apache.felix.gogo.command_0.8.0.v201108120515
106	ACTIVE      org.springframework.transaction_3.1.3.RELEASE
107	ACTIVE      org.opendaylight.controller.forwarding.staticrouting_0.4.0.SNAPSHOT
108	ACTIVE      org.opendaylight.controller.forwardingrulesmanager_0.4.0.SNAPSHOT
109	ACTIVE      org.eclipse.gemini.web.core_2.2.0.RELEASE
110	RESOLVED    org.apache.catalina.ha_7.0.32.v201211201952
111	ACTIVE      jackson-jaxrs_1.9.8
112	ACTIVE      javax.annotation_1.1.0.v201209060031
113	ACTIVE      org.opendaylight.controller.statisticsmanager_0.4.0.SNAPSHOT
114	ACTIVE      javax.activation_1.1.0.v201211130549

An example I was shown on bundle lifecycle is to stop the troubleshooting bundle, and see the results on the ODL page. Here’s how the page looks initially:
Now lets stop the troubleshooting bundle:

osgi> ss | grep troubleshoot
101	ACTIVE      org.opendaylight.controller.troubleshoot.web_0.4.0.SNAPSHOT
osgi> stop 101
May 03, 2013 10:58:25 AM org.apache.catalina.core.ApplicationContext log
INFO: Destroying Spring FrameworkServlet 'Troubleshoot'

Now if we reload the page, notice the troubleshooting tab is gone:
So OSGI let us unload this piece of the controller without stopping anything. We can just as easily start it back up again:

osgi> start 101
May 03, 2013 11:01:19 AM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
May 03, 2013 11:01:19 AM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'Troubleshoot'

And now we get our troubleshooting tab back. I’ve just started learning about OSGI, but hopefully this is a good start. Please let me know if I’m misunderstanding anything.


3 thoughts on “OpenDaylight and OSGI basics

  1. vikram says:

    This is a wonderful post.

    I am new to ODL and using Helium controller and I see features and bundles.
    how they are different?

    • A feature = list of features (on which it is depending) + bundles (bundles on which it is depending)

      A bundle is nothing but a jar file with some special OSGI entries in its manifestation file

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s