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);
72 LOG.debug("dependencies gathered..");
73 registrationManager = new SalRegistrationManager();
74 registrationManager.setDataService(dataBroker);
75 registrationManager.setPublishService(notificationService);
76 registrationManager.setRpcProviderRegistry(rpcRegistry);
77 registrationManager.setOfEntityManager(entManager);
78 registrationManager.init();
80 mdController = new MDController();
81 mdController.setSwitchConnectionProviders(switchConnectionProviders);
82 mdController.setMessageSpyCounter(messageCountProvider);
83 mdController.setExtensionConverterProvider(extensionConverterManager);
89 * @param switchConnectionProvider switch connection provider
91 public void setSwitchConnectionProviders(Collection<SwitchConnectionProvider> switchConnectionProvider) {
92 this.switchConnectionProviders = switchConnectionProvider;
100 registrationManager.close();
101 registrationManager = null;
104 public MessageCountDumper getMessageCountDumper() {
105 return messageCountProvider;
109 * @return the extensionConverterRegistry
112 public ExtensionConverterRegistrator getExtensionConverterRegistrator() {
113 return extensionConverterManager;
117 * @param role of instance
119 public void setRole(OfpRole role) {
124 * @param newRole new controller role
126 public void fireRoleChange(OfpRole newRole) {
127 if (!role.equals(newRole)) {
128 LOG.debug("Controller role was changed from {} to {}", role, newRole);
132 //TODO: implement appropriate action
133 roleManager.manageRoleChange(role);
136 //TODO: implement appropriate action
137 roleManager.manageRoleChange(role);
140 //TODO: implement appropriate action
141 roleManager.manageRoleChange(role);
144 LOG.warn("role not supported: {}", role);
150 public void setDataBroker(DataBroker dataBroker) {
151 this.dataBroker = dataBroker;
154 public void setNotificationService(NotificationProviderService notificationService) {
155 this.notificationService = notificationService;
158 public void setRpcRegistry(RpcProviderRegistry rpcRegistry) {
159 this.rpcRegistry = rpcRegistry;
162 public void setEntityOwnershipService(EntityOwnershipService entityOwnershipService) {
163 this.entityOwnershipService = entityOwnershipService;
166 public void setOpenflowPluginConfig(OpenflowPluginConfig openflowPluginConfig) {
167 this.openflowPluginConfig = openflowPluginConfig;
171 public OpenflowPluginConfig getOpenflowPluginConfig() {
172 return openflowPluginConfig;
176 protected RpcProviderRegistry getRpcRegistry() {
181 protected NotificationProviderService getNotificationService() {
182 return notificationService;
186 protected DataBroker getDataBroker() {