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.openflow.md.core.session.OFRoleManager;
20 import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil;
21 import org.opendaylight.openflowplugin.api.openflow.statistics.MessageCountDumper;
22 import org.opendaylight.openflowplugin.api.openflow.statistics.MessageObservatory;
23 import org.opendaylight.openflowplugin.statistics.MessageSpyCounterImpl;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.common.config.impl.rev140326.OfpRole;
25 import org.opendaylight.yangtools.yang.binding.DataContainer;
26 import org.osgi.framework.BundleContext;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
31 * OFPlugin provider implementation
33 public class OpenflowPluginProvider implements BindingAwareProvider, AutoCloseable {
35 private static final Logger LOG = LoggerFactory.getLogger(OpenflowPluginProvider.class);
37 private BindingAwareBroker broker;
39 private BundleContext context;
41 private Collection<SwitchConnectionProvider> switchConnectionProviders;
43 private MDController mdController;
45 private MessageObservatory<DataContainer> messageCountProvider;
47 private SalRegistrationManager registrationManager;
49 private ExtensionConverterManager extensionConverterManager;
53 private OFRoleManager roleManager;
56 * Initialization of services and msgSpy counter
58 public void initialization() {
59 messageCountProvider = new MessageSpyCounterImpl();
60 extensionConverterManager = new ExtensionConverterManagerImpl();
61 roleManager = new OFRoleManager(OFSessionUtil.getSessionManager());
62 this.registerProvider();
66 * @param switchConnectionProvider
68 public void setSwitchConnectionProviders(Collection<SwitchConnectionProvider> switchConnectionProvider) {
69 this.switchConnectionProviders = switchConnectionProvider;
73 * @return osgi context
75 public BundleContext getContext() {
80 public void onSessionInitiated(ProviderContext session) {
81 LOG.debug("onSessionInitiated");
82 registrationManager = new SalRegistrationManager();
83 registrationManager.onSessionInitiated(session);
84 mdController = new MDController();
85 mdController.setSwitchConnectionProviders(switchConnectionProviders);
86 mdController.setMessageSpyCounter(messageCountProvider);
87 mdController.setExtensionConverterProvider(extensionConverterManager);
97 registrationManager.close();
98 registrationManager = null;
102 * @return BA default broker
104 public BindingAwareBroker getBroker() {
109 * dependencymanager requirement
113 public void setBroker(BindingAwareBroker broker) {
114 this.broker = broker;
118 * dependencymanager requirement
122 public void unsetBroker(BindingAwareBroker brokerArg) {
126 private boolean hasAllDependencies() {
127 if (this.broker != null && this.switchConnectionProviders != null) {
134 * register providers for md-sal
136 private void registerProvider() {
137 if (hasAllDependencies()) {
138 this.broker.registerProvider(this, context);
142 public MessageCountDumper getMessageCountDumper() {
143 return messageCountProvider;
147 * @return the extensionConverterRegistry
149 public ExtensionConverterRegistrator getExtensionConverterRegistrator() {
150 return extensionConverterManager;
154 * @param role of instance
156 public void setRole(OfpRole role) {
163 public void fireRoleChange(OfpRole newRole) {
164 if (!role.equals(newRole)) {
165 LOG.debug("my role was chaged from {} to {}", role, newRole);
169 //TODO: implement appropriate action
170 roleManager.manageRoleChange(role);
173 //TODO: implement appropriate action
174 roleManager.manageRoleChange(role);
177 //TODO: implement appropriate action
178 roleManager.manageRoleChange(role);
181 LOG.warn("role not supported: {}", role);