2.2 Karaf and feature creation&2.3 Config subsystem
Karaf and feature creation
Now that we compiled our sample project, let's run the controller itself; preferably in a different terminal
ubuntu@sdnhubvm:~$ cd SDNHub_Opendaylight_Tutorial/distribution/opendaylight-karaf/target/assembly
ubuntu@sdnhubvm:~/SDNHub_Opendaylight_Tutorial/distribution/opendaylight-karaf/target/assembly$ ./bin/karaf
opendaylight-user@root> feature:list | grep sdnhub
sdnhub-tutorial-tapapp | 1.0.0-SNAPSHOT | x | tutorial-features-1.0.0-SNAPSHOT | SDN Hub Tutorial :: OpenDaylight :: Tap application
sdnhub-tutorial-learning-switch | 1.0.0-SNAPSHOT | | tutorial-features-1.0.0-SNAPSHOT | SDN Hub Tutorial :: OpenDaylight :: Learning switch
opendaylight-user@root> bundle:list -s | grep sdnhub
178 | Active | 80 | 1.0.0.SNAPSHOT | org.sdnhub.odl.tutorial.tapapp.impl
179 | Active | 80 | 1.0.0.SNAPSHOT | org.sdnhub.odl.tutorial.tapapp.model
opendaylight-user@root> log:set DEBUG org.sdnhub.odl.tutorial
opendaylight-user@root> log:tail
Here are some notes on the above process of starting the controller:
- Running karaf starts all the Java bundles installed as jar files in the OSGi environment. Once all bundles are started, the createInstance() method in each implementation class will be be called, and the controller moves to an event-driven operation state.
- The karaf shell is your main portal for managing all applications and the Java bundles. Press “Tab” to learn about all the CLI commands possible here
- “feature:list” and “bundle:list -s” are commands that will help with look at active features and bundles in the Karaf runtime environment. ‘x’ means the feature is loaded and active. Work “Active” means the module/bundle is running, while “Resolved” would mean that it has been stopped, and “Installed” means it is blocked on some missing dependency.
- There are also commands to install a feature (feature:install) or a specific bundle (bundle:install). By default karaf loads all the features listed in the distribution/opendaylight-karaf/target/assembly/etc/org.apache.karaf.features.cfg file. In our example, we autoload sdnhub-tutorial-tapapp feature.
- Karaf and OSGi do not provide a way to specify which modules get precedence over other modules. So we use the config subsystem of OpenDaylight to enforce the ordering. More on that in the next subsection.
To drive karaf, every application built must have a feature description for the karaf shell to load it. The feature.xml file is where we define it. For instance, the sdnhub-tutorial-tapapp feature that is autoloaded, has the following corresponding feature description in the feature.xml file:
ubuntu@sdnhubvm:~/SDNHub_Opendaylight_Tutorial$ cat features/src/main/resources/feature.xml
...
<feature name="sdnhub-tutorial-tapapp" description="SDN Hub Tutorial :: OpenDaylight :: Tap application" version='${project.version}'>
<feature version="${openflowplugin.version}">odl-openflowplugin-southbound</feature>
<feature version="${openflowplugin.version}">odl-openflowplugin-flow-services</feature>
<feature version="${mdsal.version}">odl-mdsal-broker</feature>
<bundle>mvn:org.sdnhub.odl.tutorial.tapapp/tapapp-impl/${tapapp.version}</bundle>
<bundle>mvn:org.sdnhub.odl.tutorial.tapapp/tapapp-model/${tapapp.version}</bundle>
<configfile finalname="etc/opendaylight/karaf/${tapapp.configfile}">mvn:org.sdnhub.odl.tutorial.tapapp/tapapp-config/${tapapp.version}/xml/config</configfile>
</feature>
...
The above feature description dictates that the installation of the sdnhub-tutorial-tapapp features requires us to load all the following. Even if one of them cannot be loaded, the feature hangs:
- OpenFlow plugin,
- MD-SAL data broker,
- TapApp model,
- TapApp implementation,
- TapApp configuration for the config subsystem
If you create a new application, do not forget to include its description in the feature file.
Config subsystem
OpenDaylight has a built-in feature called the config subsystem that instantiates bundles in the appropriate ordering with the MD-SAL right dependencies pre-loaded. This is achieved by having a configuration file, typically named with a number in the beginning to denote the order of loading.
For instance, the tap application has a 50-tapapp-config.xml that is added to the karaf feature. This xml file is read at run-time and appropriate dependencies are injected.
To get your new application to load correctly, this config.xml, and the config augmentation with the implementation YANG file (e.g., tap-impl.yang) needs to have the right namespace, package name, and artifact id.
评论
发表评论