Bug 1544 - Explicit LLDP flow to punt whole LLDP packets to the controller
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / sal / OpenflowPluginProvider.java
index a7a3ca13dde9ad83a5eccb2d98b40f605dc38608..2ec7fb1458656a1d0d4bf3315371cd6a9d1f57cb 100644 (file)
@@ -10,74 +10,121 @@ package org.opendaylight.openflowplugin.openflow.md.core.sal;
 import java.util.Collection;
 import java.util.Collections;
 
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
 import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;
+import org.opendaylight.openflowplugin.extension.api.ExtensionConverterRegistrator;
 import org.opendaylight.openflowplugin.openflow.md.core.MDController;
-import org.opendaylight.openflowplugin.openflow.md.core.cmd.MessageCountCommandProvider;
-import org.opendaylight.openflowplugin.openflow.md.queue.MessageObservatory;
-import org.opendaylight.openflowplugin.openflow.md.queue.MessageSpyCounterImpl;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
-import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.openflowplugin.openflow.md.core.extension.ExtensionConverterManagerImpl;
+import org.opendaylight.openflowplugin.openflow.md.core.extension.ExtensionConverterManager;
+import org.opendaylight.openflowplugin.openflow.md.lldp.LLDPPAcketPuntEnforcer;
+import org.opendaylight.openflowplugin.statistics.MessageCountCommandProvider;
+import org.opendaylight.openflowplugin.statistics.MessageCountDumper;
+import org.opendaylight.openflowplugin.statistics.MessageObservatory;
+import org.opendaylight.openflowplugin.statistics.MessageSpyCounterImpl;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+import org.opendaylight.yangtools.yang.binding.DataContainer;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.RpcService;
 import org.osgi.framework.BundleContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * OFPlugin provider implementation
  */
 public class OpenflowPluginProvider implements BindingAwareProvider, AutoCloseable {
 
+    private static Logger LOG = LoggerFactory.getLogger(OpenflowPluginProvider.class);
+
     private BindingAwareBroker broker;
 
     private BundleContext context;
 
-    private SwitchConnectionProvider switchConnectionProvider;
+    private Collection<SwitchConnectionProvider> switchConnectionProviders;
 
     private MDController mdController;
-    
+
     private MessageCountCommandProvider messageCountCommandProvider;
 
-    private MessageObservatory<OfHeader, DataObject> messageCountProvider;
+    private MessageObservatory<DataContainer> messageCountProvider;
+
+    private SalRegistrationManager registrationManager;
     
-    public void unsetSwitchConnectionProvider() {
-        switchConnectionProvider = null;
+    private ExtensionConverterManager extensionConverterManager;  
+
+    /**
+     * Initialization of services and msgSpy counter
+     */
+    public void initialization() {
+        messageCountProvider = new MessageSpyCounterImpl();
+        extensionConverterManager = new ExtensionConverterManagerImpl();
+        this.registerProvider();
     }
 
-    public void setSwitchConnectionProvider(
-            SwitchConnectionProvider switchConnectionProvider) {
-        this.switchConnectionProvider = switchConnectionProvider;
-        registerProvider();
+    /**
+     * @param switchConnectionProvider
+     */
+    public void setSwitchConnectionProviders(Collection<SwitchConnectionProvider> switchConnectionProvider) {
+        this.switchConnectionProviders = switchConnectionProvider;
     }
 
+    /**
+     * @return osgi context
+     */
     public BundleContext getContext() {
         return context;
     }
 
+    /**
+     * dependencymanager requirement
+     * @param context
+     *
+     * @deprecated we should stop relying on osgi to provide cli interface for messageCounter
+     */
+    @Deprecated
     public void setContext(BundleContext context) {
         this.context = context;
     }
 
-    SalRegistrationManager registrationManager = new SalRegistrationManager();
-
-
     @Override
     public void onSessionInitiated(ProviderContext session) {
-        messageCountProvider = new MessageSpyCounterImpl();
+        LOG.debug("onSessionInitiated");
+        registrationManager = new SalRegistrationManager();
         registrationManager.onSessionInitiated(session);
+        //TODO : LLDPPAcketPuntEnforcer should be instantiated and registered in separate module driven by config subsystem
+        InstanceIdentifier path = InstanceIdentifier.create(Nodes.class).child(Node.class);
+        registrationManager.getSessionManager().getDataBroker().registerDataChangeListener(
+                LogicalDatastoreType.OPERATIONAL,
+                path,
+                new LLDPPAcketPuntEnforcer(
+                        session.<SalFlowService>getRpcService(SalFlowService.class)),
+                AsyncDataBroker.DataChangeScope.BASE);
         mdController = new MDController();
-        mdController.setSwitchConnectionProvider(switchConnectionProvider);
+        mdController.setSwitchConnectionProviders(switchConnectionProviders);
         mdController.setMessageSpyCounter(messageCountProvider);
+        mdController.setExtensionConverterProvider(extensionConverterManager);
         mdController.init();
         mdController.start();
         messageCountCommandProvider = new MessageCountCommandProvider(context, messageCountProvider);
         messageCountCommandProvider.onSessionInitiated(session);
     }
-    
+
     @Override
     public void close() {
+        LOG.debug("close");
         mdController.stop();
+        mdController = null;
+        registrationManager.close();
+        registrationManager = null;
+        messageCountCommandProvider.close();
+        messageCountCommandProvider = null;
     }
 
     @Override
@@ -95,28 +142,53 @@ public class OpenflowPluginProvider implements BindingAwareProvider, AutoCloseab
         return Collections.emptySet();
     }
 
+    /**
+     * @return BA default broker
+     */
     public BindingAwareBroker getBroker() {
         return broker;
     }
 
+    /**
+     * dependencymanager requirement
+     * @param broker
+     */
     public void setBroker(BindingAwareBroker broker) {
         this.broker = broker;
-        registerProvider();
     }
 
-    public void unsetBroker(BindingAwareBroker broker) {
+    /**
+     * dependencymanager requirement
+     * @param brokerArg
+     */
+    public void unsetBroker(BindingAwareBroker brokerArg) {
         this.broker = null;
     }
 
     private boolean hasAllDependencies(){
-        if(this.broker != null && this.switchConnectionProvider != null) {
+        if(this.broker != null && this.switchConnectionProviders != null) {
             return true;
         }
         return false;
     }
+
+    /**
+     * register providers for md-sal
+     */
     private void registerProvider() {
         if(hasAllDependencies()) {
             this.broker.registerProvider(this,context);
         }
     }
+
+    public MessageCountDumper getMessageCountDumper() {
+        return messageCountProvider;
+    }
+    
+    /**
+     * @return the extensionConverterRegistry
+     */
+    public ExtensionConverterRegistrator getExtensionConverterRegistrator() {
+        return extensionConverterManager;
+    }
  }