Have questions? Stuck? Please check our FAQ for some common questions and answers.

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

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/):

ForwardingMapService.java
package org.onlab.onos.ifwd;

import java.util.Map;
import org.onlab.onos.net.HostId;

/**
 * A demonstrative service for the intent reactive forwarding application to
 * export
 */
public interface ForwardingMapService {

    /**
     * Get the endpoints of the host-to-host intents that were installed
     *
     * @return maps of source to destination
     */
    public Map<HostId, HostId> getEndPoints();

}

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:

IntentReactiveForwarding.java
@Component(immediate = true)
@Service
public class IntentReactiveForwarding implements ForwardingMapService {

// ...<snip>...
 
    // the new service method, to be filled out
    @Override
    public Map<HostId, HostId> getEndPoints() {
        // TODO Auto-generated method stub
        return null;
    }
}


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:

Felix annotation reference
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected ForwardingMapService fwdMapService;

3. Implement the service.

We can now define the new method.

IntentReactiveForwarding.java - service
 
  • No labels