2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.openflowplugin.openflow.md.core.sal;
10 import java.util.Collection;
11 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
12 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
13 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
14 import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;
15 import org.opendaylight.openflowplugin.extension.api.ExtensionConverterRegistrator;
16 import org.opendaylight.openflowplugin.openflow.md.core.MDController;
17 import org.opendaylight.openflowplugin.openflow.md.core.extension.ExtensionConverterManager;
18 import org.opendaylight.openflowplugin.openflow.md.core.extension.ExtensionConverterManagerImpl;
19 import org.opendaylight.openflowplugin.api.statistics.MessageCountDumper;
20 import org.opendaylight.openflowplugin.api.statistics.MessageObservatory;
21 import org.opendaylight.openflowplugin.statistics.MessageSpyCounterImpl;
22 import org.opendaylight.yangtools.yang.binding.DataContainer;
23 import org.osgi.framework.BundleContext;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
28 * OFPlugin provider implementation
30 public class OpenflowPluginProvider implements BindingAwareProvider, AutoCloseable {
32 private static final Logger LOG = LoggerFactory.getLogger(OpenflowPluginProvider.class);
34 private BindingAwareBroker broker;
36 private BundleContext context;
38 private Collection<SwitchConnectionProvider> switchConnectionProviders;
40 private MDController mdController;
42 private MessageObservatory<DataContainer> messageCountProvider;
44 private SalRegistrationManager registrationManager;
46 private ExtensionConverterManager extensionConverterManager;
49 * Initialization of services and msgSpy counter
51 public void initialization() {
52 messageCountProvider = new MessageSpyCounterImpl();
53 extensionConverterManager = new ExtensionConverterManagerImpl();
54 this.registerProvider();
58 * @param switchConnectionProvider
60 public void setSwitchConnectionProviders(Collection<SwitchConnectionProvider> switchConnectionProvider) {
61 this.switchConnectionProviders = switchConnectionProvider;
65 * @return osgi context
67 public BundleContext getContext() {
72 public void onSessionInitiated(ProviderContext session) {
73 LOG.debug("onSessionInitiated");
74 registrationManager = new SalRegistrationManager();
75 registrationManager.onSessionInitiated(session);
76 mdController = new MDController();
77 mdController.setSwitchConnectionProviders(switchConnectionProviders);
78 mdController.setMessageSpyCounter(messageCountProvider);
79 mdController.setExtensionConverterProvider(extensionConverterManager);
89 registrationManager.close();
90 registrationManager = null;
94 * @return BA default broker
96 public BindingAwareBroker getBroker() {
101 * dependencymanager requirement
105 public void setBroker(BindingAwareBroker broker) {
106 this.broker = broker;
110 * dependencymanager requirement
114 public void unsetBroker(BindingAwareBroker brokerArg) {
118 private boolean hasAllDependencies() {
119 if (this.broker != null && this.switchConnectionProviders != null) {
126 * register providers for md-sal
128 private void registerProvider() {
129 if (hasAllDependencies()) {
130 this.broker.registerProvider(this, context);
134 public MessageCountDumper getMessageCountDumper() {
135 return messageCountProvider;
139 * @return the extensionConverterRegistry
141 public ExtensionConverterRegistrator getExtensionConverterRegistrator() {
142 return extensionConverterManager;