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 com.google.common.annotations.VisibleForTesting;
11 import java.util.Collection;
12 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
13 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
14 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
15 import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;
16 import org.opendaylight.openflowplugin.api.openflow.statistics.MessageCountDumper;
17 import org.opendaylight.openflowplugin.api.openflow.statistics.MessageObservatory;
18 import org.opendaylight.openflowplugin.extension.api.ExtensionConverterRegistrator;
19 import org.opendaylight.openflowplugin.extension.api.OpenFlowPluginExtensionRegistratorProvider;
20 import org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionConverterManager;
21 import org.opendaylight.openflowplugin.openflow.md.core.MDController;
22 import org.opendaylight.openflowplugin.openflow.md.core.extension.ExtensionConverterManagerImpl;
23 import org.opendaylight.openflowplugin.openflow.md.core.session.OFRoleManager;
24 import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil;
25 import org.opendaylight.openflowplugin.openflow.md.core.role.OfEntityManager;
26 import org.opendaylight.openflowplugin.statistics.MessageSpyCounterImpl;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.common.config.impl.rev140326.OfpRole;
28 import org.opendaylight.yangtools.yang.binding.DataContainer;
29 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
34 * OFPlugin provider implementation
36 public class OpenflowPluginProvider implements AutoCloseable, OpenFlowPluginExtensionRegistratorProvider {
38 private static final Logger LOG = LoggerFactory.getLogger(OpenflowPluginProvider.class);
40 private Collection<SwitchConnectionProvider> switchConnectionProviders;
42 private MDController mdController;
44 private MessageObservatory<DataContainer> messageCountProvider;
46 private SalRegistrationManager registrationManager;
48 private ExtensionConverterManager extensionConverterManager;
52 private OFRoleManager roleManager;
53 private OfEntityManager entManager;
54 private DataBroker dataBroker;
55 private NotificationProviderService notificationService;
56 private RpcProviderRegistry rpcRegistry;
57 private EntityOwnershipService entityOwnershipService;
59 private OpenflowPluginConfig openflowPluginConfig;
62 * Initialization of services and msgSpy counter
64 public void initialization() {
65 messageCountProvider = new MessageSpyCounterImpl();
66 extensionConverterManager = new ExtensionConverterManagerImpl();
67 roleManager = new OFRoleManager(OFSessionUtil.getSessionManager());
68 entManager = new OfEntityManager(entityOwnershipService,getOpenflowPluginConfig());
69 entManager.setDataBroker(dataBroker);
71 LOG.debug("dependencies gathered..");
72 registrationManager = new SalRegistrationManager();
73 registrationManager.setDataService(dataBroker);
74 registrationManager.setPublishService(notificationService);
75 registrationManager.setRpcProviderRegistry(rpcRegistry);
76 registrationManager.setOfEntityManager(entManager);
77 registrationManager.init();
79 mdController = new MDController();
80 mdController.setSwitchConnectionProviders(switchConnectionProviders);
81 mdController.setMessageSpyCounter(messageCountProvider);
82 mdController.setExtensionConverterProvider(extensionConverterManager);
88 * @param switchConnectionProvider switch connection provider
90 public void setSwitchConnectionProviders(Collection<SwitchConnectionProvider> switchConnectionProvider) {
91 this.switchConnectionProviders = switchConnectionProvider;
99 registrationManager.close();
100 registrationManager = null;
103 public MessageCountDumper getMessageCountDumper() {
104 return messageCountProvider;
108 * @return the extensionConverterRegistry
111 public ExtensionConverterRegistrator getExtensionConverterRegistrator() {
112 return extensionConverterManager;
116 * @param role of instance
118 public void setRole(OfpRole role) {
123 * @param newRole new controller role
125 public void fireRoleChange(OfpRole newRole) {
126 if (!role.equals(newRole)) {
127 LOG.debug("Controller role was changed from {} to {}", role, newRole);
131 //TODO: implement appropriate action
132 roleManager.manageRoleChange(role);
135 //TODO: implement appropriate action
136 roleManager.manageRoleChange(role);
139 //TODO: implement appropriate action
140 roleManager.manageRoleChange(role);
143 LOG.warn("role not supported: {}", role);
149 public void setDataBroker(DataBroker dataBroker) {
150 this.dataBroker = dataBroker;
153 public void setNotificationService(NotificationProviderService notificationService) {
154 this.notificationService = notificationService;
157 public void setRpcRegistry(RpcProviderRegistry rpcRegistry) {
158 this.rpcRegistry = rpcRegistry;
161 public void setEntityOwnershipService(EntityOwnershipService entityOwnershipService) {
162 this.entityOwnershipService = entityOwnershipService;
165 public void setOpenflowPluginConfig(OpenflowPluginConfig openflowPluginConfig) {
166 this.openflowPluginConfig = openflowPluginConfig;
170 public OpenflowPluginConfig getOpenflowPluginConfig() {
171 return openflowPluginConfig;
175 protected RpcProviderRegistry getRpcRegistry() {
180 protected NotificationProviderService getNotificationService() {
181 return notificationService;
185 protected DataBroker getDataBroker() {