In this blog, I will cover internals of programming with Opendaylight.
Opendaylight is mainly written in Java. OSGI framework is used that allows for bundles to be dynamically loaded and unloaded.
Following are the different layers of software from the lowest layer
- Plugins – Like openflow, ovsdb.
- SAL layer – Abstracts core modules from plugins
- Core modules – like Topology manager, switchmanager, hosttracker, statistics manager etc.
- Northbound interfaces – These expose REST api for applications to hook on.
- Web front-end uses Spring MVC framework and java script.
Programming Language choice:
- Developing core modules would mean coding in Java.
- For Opendaylight Web interface, need to have Spring MVC and Java script knowledge.
- For writing SDN applications on top of the controller, either Python or Java can be used. Python can use the REST apis to talk to the controller. With Java, the application can be written as OSGI bundle. Writing application in Java has the advantage of asynchronous event handling and packet handling mechanisms which Python cannot provide.
- For me, both Python and Java were new. I have done some Java programming many years back. I still found programming in Python a lot easier than Java because its very easy to try out new things and see the results immediately.
Similar to Makefile. Specifies modules that are part of a bundle and also specifies inter-bundle dependencies.
There is a pom.xml at 3 levels.
- pom.xml at base controller directory specifies which modules are part of the controller.
- pom.xml at distribution/opendaylight directory that specifies modules that are part of the distribution.
- pom.xml at individual module level specifies packages that are to be imported as well as inter-module dependencies.
Following is relevant section from arphandler pom.xml.
<artifactId>arphandler</artifactId> <version>0.5.1-SNAPSHOT</version> <packaging>bundle</packaging> <Import-Package> org.opendaylight.controller.sal.packet.address, org.opendaylight.controller.connectionmanager, org.opendaylight.controller.sal.connection, org.opendaylight.controller.sal.core, org.opendaylight.controller.sal.utils, org.opendaylight.controller.sal.packet, org.opendaylight.controller.sal.routing, org.opendaylight.controller.switchmanager, org.opendaylight.controller.topologymanager, org.opendaylight.controller.clustering.services, org.opendaylight.controller.hosttracker, org.opendaylight.controller.hosttracker.hostAware, org.apache.felix.dm, org.osgi.service.component, org.slf4j </Import-Package> <dependency> <groupId>org.opendaylight.controller</groupId> <artifactId>switchmanager</artifactId> </dependency> <dependency> <groupId>org.opendaylight.controller</groupId> <artifactId>connectionmanager</artifactId> <version>0.1.1-SNAPSHOT</version> </dependency>
ArtifactId is arphandler module and it has a version associated with it.
<import-package> specifies modules that are to be imported some of which are part of opendaylight and some of which are external dependencies. For example, switchmanager is an internal dependency and slf4j is external dependency.
Maven is used for build automation and it relies on pom.xml. Maven automatically downloads the latest jar files when the build is triggered. Jar files gets stored in <home>/.m2
Common maven commands:
mvn compile - to compile individual modules mvn install - copy jar files to target mvn clean mvn package - creates package mvn clean install -DskipTests - To skip tests(Tests are automatically built as part of each module)
mvn clean install -U (or)
rm -rf .m2 (in home directory)
Build specific module:
mvn clean install -DskipTests -pl :<module> -amd
Common OSGI commands:
pns - print nodes ss - lists bundles start - start bundle stop - stop bundle getLogLevel <bundle> setLogLevel org.opendaylight.controller.helloworld DEBUG (sets level to DEBUG for helloworld module) dm - dependencies for a module
Logs are stored in:
Logs also show up in OSGI console
Git is the source code control system used in Opendaylight.
Get new repository:
git clone ssh://<username>@git.opendaylight.org:29418/controller.git
git clone https://git.opendaylight.org/gerrit/p/controller.git
In case changes are made to repository and we need to update workspace:
git pull https://git.opendaylight.org/gerrit/p/controller.git
git stash pop
Apply specific patch:
git pull https://firstname.lastname@example.org/gerrit/controller <patch>