Table of Contents

SAL Binding

<WRAP center round info 100%> How SAL manages providers, consumers services? or How to register Services with SAL? </WRAP>

BindingAwareConsumer

BindingAwareProvider

BindingAwareBroker

Binding-aware core of the SAL layer responsible for wiring the SAL consumers. The responsibility of the broker is to maintain registration of SAL functionality Consumers and Providers, store provider and consumer specific context and functionality registration via BindingAwareBroker.ConsumerContext and provide access to infrastructure services, which removes direct dependencies between providers and consumers. The Binding-aware broker is also responsible for translation from Java classes modeling the functionality and data to binding-independent form which is used in SAL Core. Infrastructure services Some examples of infrastructure services:

YANG Module service - see RpcConsumerRegistry.getRpcService(Class), BindingAwareBroker.ProviderContext
Notification Service - see NotificationService and NotificationProviderService
Functionality and Data model
Data Store access and modification - see DataBrokerService and DataProviderService 

The services are exposed via session.

Session-based access

The providers and consumers needs to register in order to use the binding-independent SAL layer and to expose functionality via SAL layer. For more information about session-based access see BindingAwareBroker.ConsumerContext and BindingAwareBroker.ProviderContext

Activator

org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase implements org.osgi.framework.BundleActivator

ComponentActivatorAbstractBase

SDN-Hub plugin-exerciese code demonstrates how MD-SAL BindingAwareBroker can be injected into the a service (MdsalConsumerImpl). See this code:

18 public class Activator extends ComponentActivatorAbstractBase {
 19     /**
 20      * Function called when the activator starts just after some
 21      * initializations are done by the
 22      * ComponentActivatorAbstractBase.
 23      */
 24     @Override
 25     public void init() {
 26     }
 27 
 28     /**
 29      * Function called when the activator stops just before the
 30      * cleanup done by ComponentActivatorAbstractBase.
 31      *
 32      */
 33     @Override
 34     public void destroy() {
 35     }
 36 
 37     /**
 38      * Function that is used to communicate to dependency manager the
 39      * list of known implementations for services inside a container.
 40      *
 41      * @return An array containing all the CLASS objects that will be
 42      * instantiated in order to get an fully working implementation
 43      * Object
 44      */
 45     @Override
 46     public Object[] getImplementations() {
 47         Object[] res = {MdsalConsumerImpl.class,
 48                         TutorialFlowProgrammer.class,
 49                         TutorialOvsBridgeManager.class};
 50         return res;
 51     }
 52 
 53     /**
 54      * Function that is called when configuration of the dependencies
 55      * is required.
 56      *
 57      * @param c dependency manager Component object, used for
 58      * configuring the dependencies exported and imported
 59      * @param imp Implementation class that is being configured,
 60      * needed as long as the same routine can configure multiple
 61      * implementations
 62      * @param containerName The containerName being configured, this allow
 63      * also optional per-container different behavior if needed, usually
 64      * should not be the case though.
 65      */
 66     @Override
 67     public void configureInstance(Component c, Object imp,
 68                                   String containerName) {
 69 
 70         if (imp.equals(MdsalConsumerImpl.class)) {
 71             c.setInterface(MdsalConsumer.class.getName(), null);
 72             c.add(createServiceDependency().setService(BindingAwareBroker.class).setRequired(true)); <--------- BindingAwareBroker!
 73         }
 74 
 75         if (imp.equals(TutorialFlowProgrammer.class)) {
 76             c.add(createServiceDependency().setService(MdsalConsumer.class).setRequired(true));
 77         }
 78 
 79         if (imp.equals(TutorialOvsBridgeManager.class)) {
 80             c.setInterface(OvsdbInventoryListener.class.getName(), null);
 81             c.add(createServiceDependency().setService(OvsdbInventoryService.class).setRequired(true));
 82             c.add(createServiceDependency().setService(OvsdbConfigurationService.class).setRequired(true));
 83             c.add(createServiceDependency().setService(OvsdbConnectionService.class).setRequired(true));
 84         }
 85     }
 86 }
20 public class MdsalConsumerImpl implements BindingAwareConsumer, MdsalConsumer {                      
 21                                                                                                      
 22     private BundleContext ctx = null;                                                                
 23     private volatile BindingAwareBroker broker;                                                      
 24     private ConsumerContext consumerContext = null;                                                  
 25     private DataBroker dataBroker;                                                                   
 26     private NotificationService notificationService;                                                 
 27                                                                                                      
 28     static final Logger logger = LoggerFactory.getLogger(MdsalConsumerImpl.class);                   
 29                                                                                                      
 30     void init(Component c) {                                                                         
 31         this.ctx = c.getDependencyManager().getBundleContext();                                      
 32         logger.info("Registered consumer with MD-SAL");                                              
 33         broker.registerConsumer(this, this.ctx);                                                     
 34     }                                                                                                
 35                                                                                                      
 36     void destroy() {                                                                                 
 37         // Now lets close MDSAL session                                                              
 38         if (this.consumerContext != null) {                                                          
 39             //this.consumerContext.close();                                                          
 40             this.dataBroker = null;                                                                  
 41             this.consumerContext = null;                                                             
 42         }                                                                                            
 43     }                                                                                                
 44                                                                                                      
 45     void start() {                                                                                   
 46     }                                                                                                
 47                                                                                                      
 48     void stop() {                                                                                    
 49     }                                                                                                
 50                                                                                                      
 51     @Override                                                                                        
 52     public void onSessionInitialized(ConsumerContext session) {                                      
 53         this.consumerContext = session;                                                              
 54         dataBroker = session.getSALService(DataBroker.class);                                        
 55         notificationService = session.getSALService(NotificationService.class);                      
 56         logger.info("Initialized consumer context {}", session.toString());                          
 57     }                                                                                                
 58                                                                                                      
 59     @Override                                                              
 60     public ConsumerContext getConsumerContext() {                                                    
 61         return consumerContext;                                                                      
 62     }
 63     @Override
 64     public DataBroker getDataBroker() {
 65         return dataBroker;
 66     }
 67     @Override
 68     public NotificationService getNotificationService() {
 69         return notificationService;
 70     }
 71 }

AbstractBindingAwareConsumer

MD-SAL plugin is activated using AbstractBindingAwareConsumer/Provider, which extends AbstractBrokerAwareActiviator, which implements org.osgi.framework.BundleActivator

Headline

OVSDB services are registered using org.apache.felix.dm.DependencyActivatorBase.