BUG-4283 experimenter msg support - provider part
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / sal / OpenflowPluginProvider.java
index 33b65a4bc26cb28f6ab156f627ac8c54119854c5..149f6c4610c7466124fe32f1cefc379e74b36112 100644 (file)
@@ -7,37 +7,34 @@
  */
 package org.opendaylight.openflowplugin.openflow.md.core.sal;
 
+import com.google.common.annotations.VisibleForTesting;
 import java.util.Collection;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
-import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
+import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
 import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;
+import org.opendaylight.openflowplugin.api.openflow.statistics.MessageCountDumper;
+import org.opendaylight.openflowplugin.api.openflow.statistics.MessageObservatory;
 import org.opendaylight.openflowplugin.extension.api.ExtensionConverterRegistrator;
+import org.opendaylight.openflowplugin.extension.api.OpenFlowPluginExtensionRegistratorProvider;
+import org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionConverterManager;
 import org.opendaylight.openflowplugin.openflow.md.core.MDController;
-import org.opendaylight.openflowplugin.openflow.md.core.extension.ExtensionConverterManager;
 import org.opendaylight.openflowplugin.openflow.md.core.extension.ExtensionConverterManagerImpl;
 import org.opendaylight.openflowplugin.openflow.md.core.session.OFRoleManager;
 import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil;
-import org.opendaylight.openflowplugin.api.statistics.MessageCountDumper;
-import org.opendaylight.openflowplugin.api.statistics.MessageObservatory;
 import org.opendaylight.openflowplugin.statistics.MessageSpyCounterImpl;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.common.config.impl.rev140326.OfpRole;
 import org.opendaylight.yangtools.yang.binding.DataContainer;
-import org.osgi.framework.BundleContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
  * OFPlugin provider implementation
  */
-public class OpenflowPluginProvider implements BindingAwareProvider, AutoCloseable {
+public class OpenflowPluginProvider implements AutoCloseable, OpenFlowPluginExtensionRegistratorProvider {
 
     private static final Logger LOG = LoggerFactory.getLogger(OpenflowPluginProvider.class);
 
-    private BindingAwareBroker broker;
-
-    private BundleContext context;
-
     private Collection<SwitchConnectionProvider> switchConnectionProviders;
 
     private MDController mdController;
@@ -51,6 +48,9 @@ public class OpenflowPluginProvider implements BindingAwareProvider, AutoCloseab
     private OfpRole role;
 
     private OFRoleManager roleManager;
+    private DataBroker dataBroker;
+    private NotificationProviderService notificationService;
+    private RpcProviderRegistry rpcRegistry;
 
     /**
      * Initialization of services and msgSpy counter
@@ -59,28 +59,14 @@ public class OpenflowPluginProvider implements BindingAwareProvider, AutoCloseab
         messageCountProvider = new MessageSpyCounterImpl();
         extensionConverterManager = new ExtensionConverterManagerImpl();
         roleManager = new OFRoleManager(OFSessionUtil.getSessionManager());
-        this.registerProvider();
-    }
-
-    /**
-     * @param switchConnectionProvider
-     */
-    public void setSwitchConnectionProviders(Collection<SwitchConnectionProvider> switchConnectionProvider) {
-        this.switchConnectionProviders = switchConnectionProvider;
-    }
-
-    /**
-     * @return osgi context
-     */
-    public BundleContext getContext() {
-        return context;
-    }
 
-    @Override
-    public void onSessionInitiated(ProviderContext session) {
-        LOG.debug("onSessionInitiated");
+        LOG.debug("dependencies gathered..");
         registrationManager = new SalRegistrationManager();
-        registrationManager.onSessionInitiated(session);
+        registrationManager.setDataService(dataBroker);
+        registrationManager.setPublishService(notificationService);
+        registrationManager.setRpcProviderRegistry(rpcRegistry);
+        registrationManager.init();
+
         mdController = new MDController();
         mdController.setSwitchConnectionProviders(switchConnectionProviders);
         mdController.setMessageSpyCounter(messageCountProvider);
@@ -89,6 +75,13 @@ public class OpenflowPluginProvider implements BindingAwareProvider, AutoCloseab
         mdController.start();
     }
 
+    /**
+     * @param switchConnectionProvider
+     */
+    public void setSwitchConnectionProviders(Collection<SwitchConnectionProvider> switchConnectionProvider) {
+        this.switchConnectionProviders = switchConnectionProvider;
+    }
+
     @Override
     public void close() {
         LOG.debug("close");
@@ -98,47 +91,6 @@ public class OpenflowPluginProvider implements BindingAwareProvider, AutoCloseab
         registrationManager = null;
     }
 
-    /**
-     * @return BA default broker
-     */
-    public BindingAwareBroker getBroker() {
-        return broker;
-    }
-
-    /**
-     * dependencymanager requirement
-     *
-     * @param broker
-     */
-    public void setBroker(BindingAwareBroker broker) {
-        this.broker = broker;
-    }
-
-    /**
-     * dependencymanager requirement
-     *
-     * @param brokerArg
-     */
-    public void unsetBroker(BindingAwareBroker brokerArg) {
-        this.broker = null;
-    }
-
-    private boolean hasAllDependencies() {
-        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;
     }
@@ -146,6 +98,7 @@ public class OpenflowPluginProvider implements BindingAwareProvider, AutoCloseab
     /**
      * @return the extensionConverterRegistry
      */
+    @Override
     public ExtensionConverterRegistrator getExtensionConverterRegistrator() {
         return extensionConverterManager;
     }
@@ -165,22 +118,49 @@ public class OpenflowPluginProvider implements BindingAwareProvider, AutoCloseab
             LOG.debug("my role was chaged from {} to {}", role, newRole);
             role = newRole;
             switch (role) {
-            case BECOMEMASTER:
-                //TODO: implement appropriate action
-                roleManager.manageRoleChange(role);
-                break;
-            case BECOMESLAVE:
-                //TODO: implement appropriate action
-                roleManager.manageRoleChange(role);
-                break;
-            case NOCHANGE:
-                //TODO: implement appropriate action
-                roleManager.manageRoleChange(role);
-                break;
-            default:
-                LOG.warn("role not supported: {}", role);
-                break;
+                case BECOMEMASTER:
+                    //TODO: implement appropriate action
+                    roleManager.manageRoleChange(role);
+                    break;
+                case BECOMESLAVE:
+                    //TODO: implement appropriate action
+                    roleManager.manageRoleChange(role);
+                    break;
+                case NOCHANGE:
+                    //TODO: implement appropriate action
+                    roleManager.manageRoleChange(role);
+                    break;
+                default:
+                    LOG.warn("role not supported: {}", role);
+                    break;
             }
         }
     }
+
+    public void setDataBroker(DataBroker dataBroker) {
+        this.dataBroker = dataBroker;
+    }
+
+    public void setNotificationService(NotificationProviderService notificationService) {
+        this.notificationService = notificationService;
+    }
+
+    public void setRpcRegistry(RpcProviderRegistry rpcRegistry) {
+        this.rpcRegistry = rpcRegistry;
+    }
+
+    @VisibleForTesting
+    protected RpcProviderRegistry getRpcRegistry() {
+        return rpcRegistry;
+    }
+
+    @VisibleForTesting
+    protected NotificationProviderService getNotificationService() {
+        return notificationService;
+    }
+
+    @VisibleForTesting
+    protected DataBroker getDataBroker() {
+        return dataBroker;
+    }
 }