This tutorial will show you how to create a CLI command to print the endpoints found by the reactive forwarding application from theĀ Application tutorial. After completing this tutorial, you will understand:
- How to extend applications with new services
- How to extend the Karaf-based ONOS CLI with new commands
Offering services to other modules
If you want your module to be able to provide services to other modules, you should define a service interface and have your module class implement it.
1. Define a service interface.
We start by defining a new interface for the service in the same location as our application (~/onos-next/apps/ifwd/src/main/java/org/onlab/onos/ifwd/):
2. Import the service interface.
Next, we implement our service in IntentReactiveForwarding
. We also indicate to Karaf that the application exports a service, using the the Felix SCR annotationĀ @Service
:
Although we won't be using it here in this manner, the @ServiceĀ
annotation enables another class to reference the service through the @Reference
annotation:
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) protected ForwardingMapService fwdMapService;
3. Implement the service.
We can now define the new method.