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.md.sal.common.api.clustering.EntityOwnershipService;
14 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
15 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
16 import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;
17 import org.opendaylight.openflowplugin.api.openflow.statistics.MessageCountDumper;
18 import org.opendaylight.openflowplugin.api.openflow.statistics.MessageObservatory;
19 import org.opendaylight.openflowplugin.extension.api.ExtensionConverterRegistrator;
20 import org.opendaylight.openflowplugin.extension.api.OpenFlowPluginExtensionRegistratorProvider;
21 import org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionConverterManager;
22 import org.opendaylight.openflowplugin.openflow.md.core.MDController;
23 import org.opendaylight.openflowplugin.openflow.md.core.extension.ExtensionConverterManagerImpl;
24 import org.opendaylight.openflowplugin.openflow.md.core.role.OfEntityManager;
25 import org.opendaylight.openflowplugin.openflow.md.core.session.OFRoleManager;
26 import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil;
27 import org.opendaylight.openflowplugin.statistics.MessageSpyCounterImpl;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.common.config.impl.rev140326.OfpRole;
29 import org.opendaylight.yangtools.yang.binding.DataContainer;
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 static final boolean SKIP_TABLE_FEATURES = false;
42 private Collection<SwitchConnectionProvider> switchConnectionProviders;
44 private MDController mdController;
46 private MessageObservatory<DataContainer> messageCountProvider;
48 private SalRegistrationManager registrationManager;
50 private ExtensionConverterManager extensionConverterManager;
53 private Boolean skipTableFeatures;
55 private OFRoleManager roleManager;
56 private OfEntityManager entManager;
57 private DataBroker dataBroker;
58 private NotificationProviderService notificationService;
59 private RpcProviderRegistry rpcRegistry;
60 private EntityOwnershipService entityOwnershipService;
62 private OpenflowPluginConfig openflowPluginConfig;
67 * Initialization of services and msgSpy counter
69 public void initialization() {
70 messageCountProvider = new MessageSpyCounterImpl();
71 extensionConverterManager = new ExtensionConverterManagerImpl();
72 roleManager = new OFRoleManager(OFSessionUtil.getSessionManager());
73 openflowPluginConfig = readConfig(skipTableFeatures);
74 entManager = new OfEntityManager(entityOwnershipService,getOpenflowPluginConfig());
75 entManager.setDataBroker(dataBroker);
78 LOG.debug("dependencies gathered..");
79 registrationManager = new SalRegistrationManager();
80 registrationManager.setDataService(dataBroker);
81 registrationManager.setPublishService(notificationService);
82 registrationManager.setRpcProviderRegistry(rpcRegistry);
83 registrationManager.setOfEntityManager(entManager);
84 registrationManager.init();
86 mdController = new MDController();
87 mdController.setSwitchConnectionProviders(switchConnectionProviders);
88 mdController.setMessageSpyCounter(messageCountProvider);
89 mdController.setExtensionConverterProvider(extensionConverterManager);
95 * @param switchConnectionProvider switch connection provider
97 public void setSwitchConnectionProviders(Collection<SwitchConnectionProvider> switchConnectionProvider) {
98 this.switchConnectionProviders = switchConnectionProvider;
102 public void close() {
105 if(mdController != null) {
110 if(registrationManager != null) {
111 registrationManager.close();
112 registrationManager = null;
116 public MessageCountDumper getMessageCountDumper() {
117 return messageCountProvider;
121 * @return the extensionConverterRegistry
124 public ExtensionConverterRegistrator getExtensionConverterRegistrator() {
125 return extensionConverterManager;
129 * @param role of instance
131 public void setRole(OfpRole role) {
136 * @param newRole new controller role
138 public void fireRoleChange(OfpRole newRole) {
139 if (!role.equals(newRole)) {
140 LOG.debug("Controller role was changed from {} to {}", role, newRole);
144 //TODO: implement appropriate action
145 roleManager.manageRoleChange(role);
148 //TODO: implement appropriate action
149 roleManager.manageRoleChange(role);
152 //TODO: implement appropriate action
153 roleManager.manageRoleChange(role);
156 LOG.warn("role not supported: {}", role);
162 private OpenflowPluginConfig readConfig(Boolean skipTableFeatures){
164 final OpenflowPluginConfig.OpenflowPluginConfigBuilder openflowCfgBuilder = OpenflowPluginConfig.builder();
166 if(skipTableFeatures !=null){
167 openflowCfgBuilder.setSkipTableFeatures(skipTableFeatures.booleanValue());
169 LOG.warn("Could not load XML configuration file via ConfigSubsystem! Fallback to default config value(s)");
170 openflowCfgBuilder.setSkipTableFeatures(SKIP_TABLE_FEATURES);
173 return openflowCfgBuilder.build();
176 public void setDataBroker(DataBroker dataBroker) {
177 this.dataBroker = dataBroker;
180 public void setNotificationService(NotificationProviderService notificationService) {
181 this.notificationService = notificationService;
184 public void setRpcRegistry(RpcProviderRegistry rpcRegistry) {
185 this.rpcRegistry = rpcRegistry;
188 public void setEntityOwnershipService(EntityOwnershipService entityOwnershipService) {
189 this.entityOwnershipService = entityOwnershipService;
192 public void setSkipTableFeatures(Boolean skipTableFeatures) {
193 this.skipTableFeatures = skipTableFeatures;
197 public OpenflowPluginConfig getOpenflowPluginConfig() {
198 return openflowPluginConfig;
202 protected RpcProviderRegistry getRpcRegistry() {
207 protected NotificationProviderService getNotificationService() {
208 return notificationService;
212 protected DataBroker getDataBroker() {