*/
package org.opendaylight.openflowplugin.api.openflow.md;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
+import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
import org.opendaylight.openflowplugin.api.openflow.md.core.session.SessionContext;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.OpendaylightFlowStatisticsService;
Identifiable<InstanceIdentifier<Node>> {
/**
- * @param ctx
+ * @param rpcProviderRegistry
* @return wrapped list of {service provider + path} registration couples
*/
- CompositeObjectRegistration<ModelDrivenSwitch> register(ProviderContext ctx);
+ CompositeObjectRegistration<ModelDrivenSwitch> register(RpcProviderRegistry rpcProviderRegistry);
/**
* @return id of encapsulated node (served by this impl)
<name>openflow-switch-connection-provider-legacy</name>
</openflow-switch-connection-provider>
+ <data-broker>
+ <type xmlns:binding="urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding">binding:binding-async-data-broker</type>
+ <name>pingpong-binding-data-broker</name>
+ </data-broker>
+ <rpc-registry>
+ <type xmlns:binding="urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding">binding:binding-rpc-registry</type>
+ <name>binding-rpc-broker</name>
+ </rpc-registry>
+ <notification-service>
+ <type xmlns:binding="urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding">binding:binding-notification-service</type>
+ <name>binding-notification-broker</name>
+ </notification-service>
- <binding-aware-broker>
- <type xmlns:binding="urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding">binding:binding-broker-osgi-registry</type>
- <name>binding-osgi-broker</name>
- </binding-aware-broker>
</module>
</modules>
<name>openflow-switch-connection-provider-legacy</name>
</openflow-switch-connection-provider>
- <binding-aware-broker>
- <type xmlns:binding="urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding">binding:binding-broker-osgi-registry</type>
- <name>binding-osgi-broker</name>
- </binding-aware-broker>
+ <data-broker>
+ <type xmlns:binding="urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding">binding:binding-async-data-broker</type>
+ <name>pingpong-binding-data-broker</name>
+ </data-broker>
+ <rpc-registry>
+ <type xmlns:binding="urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding">binding:binding-rpc-registry</type>
+ <name>binding-rpc-broker</name>
+ </rpc-registry>
+ <notification-service>
+ <type xmlns:binding="urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding">binding:binding-notification-service</type>
+ <name>binding-notification-broker</name>
+ </notification-service>
</module>
*/
package org.opendaylight.openflowplugin.openflow.md.core.sal;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
+import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
import org.opendaylight.openflowplugin.api.openflow.md.ModelDrivenSwitch;
import org.opendaylight.openflowplugin.api.openflow.md.core.session.SessionContext;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
}
@Override
- public CompositeObjectRegistration<ModelDrivenSwitch> register(ProviderContext ctx) {
+ public CompositeObjectRegistration<ModelDrivenSwitch> register(RpcProviderRegistry rpcProviderRegistry) {
CompositeObjectRegistrationBuilder<ModelDrivenSwitch> builder = CompositeObjectRegistration
.<ModelDrivenSwitch> builderFor(this);
- final RoutedRpcRegistration<SalFlowService> flowRegistration = ctx.addRoutedRpcImplementation(SalFlowService.class, this);
+ final RoutedRpcRegistration<SalFlowService> flowRegistration = rpcProviderRegistry.addRoutedRpcImplementation(SalFlowService.class, this);
flowRegistration.registerPath(NodeContext.class, getIdentifier());
builder.add(flowRegistration);
- final RoutedRpcRegistration<SalPortService> portRegistration = ctx.addRoutedRpcImplementation(SalPortService.class, this);
+ final RoutedRpcRegistration<SalPortService> portRegistration = rpcProviderRegistry.addRoutedRpcImplementation(SalPortService.class, this);
portRegistration.registerPath(NodeContext.class, getIdentifier());
builder.add(portRegistration);
- final RoutedRpcRegistration<SalMeterService> meterRegistration = ctx.addRoutedRpcImplementation(SalMeterService.class, this);
+ final RoutedRpcRegistration<SalMeterService> meterRegistration = rpcProviderRegistry.addRoutedRpcImplementation(SalMeterService.class, this);
meterRegistration.registerPath(NodeContext.class, getIdentifier());
builder.add(meterRegistration);
- final RoutedRpcRegistration<SalGroupService> groupRegistration = ctx.addRoutedRpcImplementation(SalGroupService.class, this);
+ final RoutedRpcRegistration<SalGroupService> groupRegistration = rpcProviderRegistry.addRoutedRpcImplementation(SalGroupService.class, this);
groupRegistration.registerPath(NodeContext.class, getIdentifier());
builder.add(groupRegistration);
- final RoutedRpcRegistration<SalTableService> tableRegistration = ctx.addRoutedRpcImplementation(SalTableService.class, this);
+ final RoutedRpcRegistration<SalTableService> tableRegistration = rpcProviderRegistry.addRoutedRpcImplementation(SalTableService.class, this);
tableRegistration.registerPath(NodeContext.class, getIdentifier());
builder.add(tableRegistration);
- final RoutedRpcRegistration<PacketProcessingService> packetRegistration = ctx.addRoutedRpcImplementation(PacketProcessingService.class, this);
+ final RoutedRpcRegistration<PacketProcessingService> packetRegistration = rpcProviderRegistry.addRoutedRpcImplementation(PacketProcessingService.class, this);
packetRegistration.registerPath(NodeContext.class, getIdentifier());
builder.add(packetRegistration);
- final RoutedRpcRegistration<OpendaylightFlowStatisticsService> flowStatisticsRegistration = ctx.addRoutedRpcImplementation(OpendaylightFlowStatisticsService.class, this);
+ final RoutedRpcRegistration<OpendaylightFlowStatisticsService> flowStatisticsRegistration = rpcProviderRegistry.addRoutedRpcImplementation(OpendaylightFlowStatisticsService.class, this);
flowStatisticsRegistration.registerPath(NodeContext.class, getIdentifier());
builder.add(flowStatisticsRegistration);
- final RoutedRpcRegistration<OpendaylightGroupStatisticsService> groupStatisticsRegistration = ctx.addRoutedRpcImplementation(OpendaylightGroupStatisticsService.class, this);
+ final RoutedRpcRegistration<OpendaylightGroupStatisticsService> groupStatisticsRegistration = rpcProviderRegistry.addRoutedRpcImplementation(OpendaylightGroupStatisticsService.class, this);
groupStatisticsRegistration.registerPath(NodeContext.class, getIdentifier());
builder.add(groupStatisticsRegistration);
- final RoutedRpcRegistration<OpendaylightMeterStatisticsService> meterStatisticsRegistration = ctx.addRoutedRpcImplementation(OpendaylightMeterStatisticsService.class, this);
+ final RoutedRpcRegistration<OpendaylightMeterStatisticsService> meterStatisticsRegistration = rpcProviderRegistry.addRoutedRpcImplementation(OpendaylightMeterStatisticsService.class, this);
meterStatisticsRegistration.registerPath(NodeContext.class, getIdentifier());
builder.add(meterStatisticsRegistration);
- final RoutedRpcRegistration<OpendaylightPortStatisticsService> portStatisticsRegistration = ctx.addRoutedRpcImplementation(OpendaylightPortStatisticsService.class, this);
+ final RoutedRpcRegistration<OpendaylightPortStatisticsService> portStatisticsRegistration = rpcProviderRegistry.addRoutedRpcImplementation(OpendaylightPortStatisticsService.class, this);
portStatisticsRegistration.registerPath(NodeContext.class, getIdentifier());
builder.add(portStatisticsRegistration);
- final RoutedRpcRegistration<NodeConfigService> nodeConfigRegistration = ctx.addRoutedRpcImplementation(NodeConfigService.class, this);
+ final RoutedRpcRegistration<NodeConfigService> nodeConfigRegistration = rpcProviderRegistry.addRoutedRpcImplementation(NodeConfigService.class, this);
nodeConfigRegistration.registerPath(NodeContext.class, getIdentifier());
builder.add(nodeConfigRegistration);
- final RoutedRpcRegistration<OpendaylightFlowTableStatisticsService> flowTableStatisticsRegistration = ctx.addRoutedRpcImplementation(OpendaylightFlowTableStatisticsService.class, this);
+ final RoutedRpcRegistration<OpendaylightFlowTableStatisticsService> flowTableStatisticsRegistration = rpcProviderRegistry.addRoutedRpcImplementation(OpendaylightFlowTableStatisticsService.class, this);
flowTableStatisticsRegistration.registerPath(NodeContext.class, getIdentifier());
builder.add(flowTableStatisticsRegistration);
- final RoutedRpcRegistration<OpendaylightQueueStatisticsService> queueStatisticsRegistration = ctx.addRoutedRpcImplementation(OpendaylightQueueStatisticsService.class, this);
+ final RoutedRpcRegistration<OpendaylightQueueStatisticsService> queueStatisticsRegistration = rpcProviderRegistry.addRoutedRpcImplementation(OpendaylightQueueStatisticsService.class, this);
queueStatisticsRegistration.registerPath(NodeContext.class, getIdentifier());
builder.add(queueStatisticsRegistration);
}
/**
- * @return session context
+ * @return session context
*/
public SessionContext getSessionContext() {
return sessionContext;
*/
package org.opendaylight.openflowplugin.openflow.md.core.sal;
+import com.google.common.annotations.VisibleForTesting;
import java.util.Collection;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
-import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
+import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;
import org.opendaylight.openflowplugin.api.openflow.statistics.MessageCountDumper;
import org.opendaylight.openflowplugin.api.openflow.statistics.MessageObservatory;
import org.opendaylight.openflowplugin.statistics.MessageSpyCounterImpl;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.common.config.impl.rev140326.OfpRole;
import org.opendaylight.yangtools.yang.binding.DataContainer;
-import org.osgi.framework.BundleContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* OFPlugin provider implementation
*/
-public class OpenflowPluginProvider implements BindingAwareProvider, AutoCloseable, OpenFlowPluginExtensionRegistratorProvider {
+public class OpenflowPluginProvider implements AutoCloseable, OpenFlowPluginExtensionRegistratorProvider {
private static final Logger LOG = LoggerFactory.getLogger(OpenflowPluginProvider.class);
- private BindingAwareBroker broker;
-
- private BundleContext context;
-
private Collection<SwitchConnectionProvider> switchConnectionProviders;
private MDController mdController;
private OfpRole role;
private OFRoleManager roleManager;
+ private DataBroker dataBroker;
+ private NotificationProviderService notificationService;
+ private RpcProviderRegistry rpcRegistry;
/**
* Initialization of services and msgSpy counter
messageCountProvider = new MessageSpyCounterImpl();
extensionConverterManager = new ExtensionConverterManagerImpl();
roleManager = new OFRoleManager(OFSessionUtil.getSessionManager());
- this.registerProvider();
- }
-
- /**
- * @param switchConnectionProvider
- */
- public void setSwitchConnectionProviders(Collection<SwitchConnectionProvider> switchConnectionProvider) {
- this.switchConnectionProviders = switchConnectionProvider;
- }
-
- /**
- * @return osgi context
- */
- public BundleContext getContext() {
- return context;
- }
- @Override
- public void onSessionInitiated(ProviderContext session) {
- LOG.debug("onSessionInitiated");
+ LOG.debug("dependencies gathered..");
registrationManager = new SalRegistrationManager();
- registrationManager.onSessionInitiated(session);
+ registrationManager.setDataService(dataBroker);
+ registrationManager.setPublishService(notificationService);
+ registrationManager.setRpcProviderRegistry(rpcRegistry);
+ registrationManager.init();
+
mdController = new MDController();
mdController.setSwitchConnectionProviders(switchConnectionProviders);
mdController.setMessageSpyCounter(messageCountProvider);
mdController.start();
}
+ /**
+ * @param switchConnectionProvider
+ */
+ public void setSwitchConnectionProviders(Collection<SwitchConnectionProvider> switchConnectionProvider) {
+ this.switchConnectionProviders = switchConnectionProvider;
+ }
+
@Override
public void close() {
LOG.debug("close");
registrationManager = null;
}
- /**
- * @return BA default broker
- */
- public BindingAwareBroker getBroker() {
- return broker;
- }
-
- /**
- * dependencymanager requirement
- *
- * @param broker
- */
- public void setBroker(BindingAwareBroker broker) {
- this.broker = broker;
- }
-
- /**
- * dependencymanager requirement
- *
- * @param brokerArg
- */
- public void unsetBroker(BindingAwareBroker brokerArg) {
- this.broker = null;
- }
-
- private boolean hasAllDependencies() {
- if (this.broker != null && this.switchConnectionProviders != null) {
- return true;
- }
- return false;
- }
-
- /**
- * register providers for md-sal
- */
- private void registerProvider() {
- if (hasAllDependencies()) {
- this.broker.registerProvider(this, context);
- }
- }
-
public MessageCountDumper getMessageCountDumper() {
return messageCountProvider;
}
}
}
}
+
+ public void setDataBroker(DataBroker dataBroker) {
+ this.dataBroker = dataBroker;
+ }
+
+ public void setNotificationService(NotificationProviderService notificationService) {
+ this.notificationService = notificationService;
+ }
+
+ public void setRpcRegistry(RpcProviderRegistry rpcRegistry) {
+ this.rpcRegistry = rpcRegistry;
+ }
+
+ @VisibleForTesting
+ protected RpcProviderRegistry getRpcRegistry() {
+ return rpcRegistry;
+ }
+
+ @VisibleForTesting
+ protected NotificationProviderService getNotificationService() {
+ return notificationService;
+ }
+
+ @VisibleForTesting
+ protected DataBroker getDataBroker() {
+ return dataBroker;
+ }
}
import java.net.InetAddress;
import java.net.InetSocketAddress;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
+import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
import org.opendaylight.openflowplugin.api.openflow.md.ModelDrivenSwitch;
import org.opendaylight.openflowplugin.api.openflow.md.core.NotificationQueueWrapper;
-import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil;
import org.opendaylight.openflowplugin.api.openflow.md.core.session.SessionContext;
import org.opendaylight.openflowplugin.api.openflow.md.core.session.SessionListener;
import org.opendaylight.openflowplugin.api.openflow.md.core.session.SessionManager;
import org.opendaylight.openflowplugin.api.openflow.md.core.session.SwitchSessionKeyOF;
+import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address;
private static final Logger LOG = LoggerFactory.getLogger(SalRegistrationManager.class);
- private ProviderContext providerContext;
-
private NotificationProviderService publishService;
private DataBroker dataService;
+ private RpcProviderRegistry rpcProviderRegistry;
+
private SwitchFeaturesUtil swFeaturesUtil;
private ListenerRegistration<SessionListener> sessionListenerRegistration;
this.publishService = publishService;
}
- public ProviderContext getProviderContext() {
- return providerContext;
+ public void setDataService(DataBroker dataService) {
+ this.dataService = dataService;
}
- public void onSessionInitiated(ProviderContext session) {
- LOG.debug("onSessionInitiated");
- this.providerContext = session;
- this.publishService = session.getSALService(NotificationProviderService.class);
- this.dataService = session.getSALService(DataBroker.class);
- // We register as listener for Session Manager
+ public void setRpcProviderRegistry(RpcProviderRegistry rpcProviderRegistry) {
+ this.rpcProviderRegistry = rpcProviderRegistry;
+ }
+
+ public void init() {
+ LOG.debug("init..");
sessionListenerRegistration = getSessionManager().registerSessionListener(this);
getSessionManager().setNotificationProviderService(publishService);
getSessionManager().setDataBroker(dataService);
NodeRef nodeRef = new NodeRef(identifier);
NodeId nodeId = nodeIdFromDatapathId(datapathId);
ModelDrivenSwitchImpl ofSwitch = new ModelDrivenSwitchImpl(nodeId, identifier, context);
- CompositeObjectRegistration<ModelDrivenSwitch> registration = ofSwitch.register(providerContext);
+ CompositeObjectRegistration<ModelDrivenSwitch> registration =
+ ofSwitch.register(rpcProviderRegistry);
context.setProviderRegistration(registration);
- LOG.debug("ModelDrivenSwitch for {} registered to MD-SAL.", datapathId.toString());
+ LOG.debug("ModelDrivenSwitch for {} registered to MD-SAL.", datapathId);
NotificationQueueWrapper wrappedNotification = new NotificationQueueWrapper(
nodeAdded(ofSwitch, features, nodeRef),
registration.close();
context.setProviderRegistration(null);
}
- LOG.debug("ModelDrivenSwitch for {} unregistered from MD-SAL.", datapathId.toString());
+ LOG.debug("ModelDrivenSwitch for {} unregistered from MD-SAL.", datapathId);
NotificationQueueWrapper wrappedNotification = new NotificationQueueWrapper(
nodeRemoved, context.getFeatures().getVersion());
public static NodeId nodeIdFromDatapathId(BigInteger datapathId) {
// FIXME: Convert to textual representation of datapathID
- String current = datapathId.toString();
+ String current = String.valueOf(datapathId);
return new NodeId("openflow:" + current);
}
public void close() {
LOG.debug("close");
dataService = null;
- providerContext = null;
+ rpcProviderRegistry = null;
publishService = null;
if (sessionListenerRegistration != null) {
sessionListenerRegistration.close();
}
}
-
- /**
- * @param providerContext the providerContext to set
- */
- public void setProviderContext(ProviderContext providerContext) {
- this.providerContext = providerContext;
- }
}
*/
package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.common.config.impl.rev140326;
+import com.google.common.base.MoreObjects;
import javax.management.ObjectName;
-
import org.opendaylight.openflowplugin.openflow.md.core.sal.OpenflowPluginProvider;
-import com.google.common.base.MoreObjects;
-
/**
*
*/
@Override
public java.lang.AutoCloseable createInstance() {
pluginProvider = new OpenflowPluginProvider();
- pluginProvider.setBroker(getBindingAwareBrokerDependency());
+ pluginProvider.setDataBroker(getDataBrokerDependency());
+ pluginProvider.setNotificationService(getNotificationServiceDependency());
+ pluginProvider.setRpcRegistry(getRpcRegistryDependency());
pluginProvider.setSwitchConnectionProviders(getOpenflowSwitchConnectionProviderDependency());
pluginProvider.setRole(getRole());
pluginProvider.initialization();
// we can reuse if only the role field changed
boolean noChangeExceptRole = true;
noChangeExceptRole &= dependencyResolver.canReuseDependency(
- getBindingAwareBroker(), bindingAwareBrokerJmxAttribute);
+ getDataBroker(), dataBrokerJmxAttribute);
+ noChangeExceptRole &= dependencyResolver.canReuseDependency(
+ getNotificationService(), notificationServiceJmxAttribute);
+ noChangeExceptRole &= dependencyResolver.canReuseDependency(
+ getRpcRegistry(), rpcRegistryJmxAttribute);
+
for (ObjectName ofSwitchProvider : getOpenflowSwitchConnectionProvider()) {
noChangeExceptRole &= dependencyResolver.canReuseDependency(
- ofSwitchProvider, openflowSwitchConnectionProviderJmxAttribute);
+ ofSwitchProvider, openflowSwitchConnectionProviderJmxAttribute);
}
return noChangeExceptRole;
}
case openflow-provider-impl {
when "/config:modules/config:module/config:type = 'openflow-provider-impl'";
- container binding-aware-broker {
+ container data-broker {
uses config:service-ref {
refine type {
mandatory true;
- config:required-identity md-sal-binding:binding-broker-osgi-registry;
+ config:required-identity md-sal-binding:binding-async-data-broker;
}
}
}
+ container rpc-registry {
+ uses config:service-ref {
+ refine type {
+ mandatory true;
+ config:required-identity md-sal-binding:binding-rpc-registry;
+ }
+ }
+ }
+ container notification-service {
+ uses config:service-ref {
+ refine type {
+ mandatory true;
+ config:required-identity md-sal-binding:binding-notification-service;
+ }
+ }
+ }
+
list openflow-switch-connection-provider {
uses config:service-ref {
refine type {
package org.opendaylight.openflowplugin.openflow.md.core.sal;
+import com.google.common.util.concurrent.ListeningExecutorService;
import java.math.BigInteger;
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
-
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.stubbing.Answer;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
+import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
import org.opendaylight.openflowplugin.api.OFConstants;
import org.opendaylight.openflowplugin.api.openflow.md.core.ConnectionConductor;
import org.opendaylight.openflowplugin.api.openflow.md.core.NotificationEnqueuer;
-import org.opendaylight.openflowplugin.openflow.md.core.ThreadPoolLoggingExecutor;
-import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil;
import org.opendaylight.openflowplugin.api.openflow.md.core.session.SessionContext;
import org.opendaylight.openflowplugin.api.openflow.md.core.session.SwitchSessionKeyOF;
+import org.opendaylight.openflowplugin.openflow.md.core.ThreadPoolLoggingExecutor;
+import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Capabilities;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutputBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.util.concurrent.ListeningExecutorService;
-
/**
* Created by Martin Bobak mbobak@cisco.com on 9/22/14.
*/
@Mock
private ConnectionConductor connectionConductor;
@Mock
- private ListeningExecutorService rpcPool;
+ private ListeningExecutorService rpcPool;
+ @Mock
+ private NotificationProviderService notificationProviderService;
@Mock
- private NotificationProviderService notificationProviderService;
+ private RpcProviderRegistry rpcProviderRegistry;
@Mock
- private ProviderContext providerContext;
+ private DataBroker dataBroker;
@Mock
private NotificationEnqueuer notificationEnqueuer;
@Mock
@Before
public void setUp() {
SWITCH_SESSION_KEY_OF.setDatapathId(BigInteger.ONE);
- Mockito.when(providerContext.getSALService(NotificationProviderService.class)).thenReturn(notificationProviderService);
Mockito.when(context.getNotificationEnqueuer()).thenReturn(notificationEnqueuer);
-
+
// features mockery
features = new GetFeaturesOutputBuilder()
.setVersion(OFConstants.OFP_VERSION_1_3)
.setCapabilities(new Capabilities(true, true, true, true, true, true, true))
.build();
Mockito.when(context.getFeatures()).thenReturn(features);
-
+
Mockito.when(context.getPrimaryConductor()).thenReturn(connectionConductor);
Mockito.when(context.getSessionKey()).thenReturn(SWITCH_SESSION_KEY_OF);
Mockito.when(connectionConductor.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
-
+
// provider context - registration responder
- Mockito.when(providerContext.addRoutedRpcImplementation(Matchers.any(Class.class), Matchers.any(RpcService.class)))
+ Mockito.when(rpcProviderRegistry.addRoutedRpcImplementation(Matchers.any(Class.class), Matchers.any(RpcService.class)))
.then(new Answer<RoutedRpcRegistration<?>>() {
@Override
public RoutedRpcRegistration<?> answer(InvocationOnMock invocation) {
LOG.error("delaying of worker thread [{}] failed.", Thread.currentThread().getName(), e);
}
}
-
+
Object[] args = invocation.getArguments();
RoutedRpcRegistration<RpcService> registration = Mockito.mock(RoutedRpcRegistration.class);
Mockito.when(registration.getInstance()).thenReturn((RpcService) args[1]);
-
+
return registration;
}
});
-
+
Mockito.when(connectionConductor.getConnectionAdapter()).thenReturn(connectionAdapter);
Mockito.when(connectionAdapter.getRemoteAddress()).thenReturn(new InetSocketAddress("10.1.2.3", 4242));
-
+
taskExecutor = new ThreadPoolCollectingExecutor(
2, 2, 0, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(2), "junit");
-
- registrationManager.onSessionInitiated(providerContext);
+
+ registrationManager.setRpcProviderRegistry(rpcProviderRegistry);
+ registrationManager.setDataService(dataBroker);
+ registrationManager.setPublishService(notificationProviderService);
+ registrationManager.init();
OFSessionUtil.getSessionManager().setRpcPool(rpcPool);
}
-
+
/**
* clean up
- * @throws InterruptedException
+ * @throws InterruptedException
*/
@After
public void tearDown() throws InterruptedException {
taskExecutor.shutdown();
taskExecutor.awaitTermination(1, TimeUnit.SECONDS);
if (!taskExecutor.isTerminated()) {
- taskExecutor.shutdownNow();
+ taskExecutor.shutdownNow();
}
LOG.info("All tasks have finished.");
-
- LOG.info("amount of scheduled threads: {}, exited threads: {}, failed threads: {}",
+
+ LOG.info("amount of scheduled threads: {}, exited threads: {}, failed threads: {}",
taskExecutor.getTaskCount(), taskExecutor.getThreadExitCounter(), taskExecutor.getFailLogbook().size());
for (String exitStatus : taskExecutor.getFailLogbook()) {
LOG.debug(exitStatus);
}
-
+
OFSessionUtil.releaseSessionManager();
Assert.assertTrue("there should not be any failed threads in the pool", taskExecutor.getFailLogbook().isEmpty());
Assert.assertTrue("there should not be any living thread in the pool", taskExecutor.getActiveCount() == 0);
/**
* Test method which verifies that session could not be invalidated while in creation.
- * @throws InterruptedException
- * @throws TimeoutException
- * @throws ExecutionException
+ * @throws InterruptedException
+ * @throws TimeoutException
+ * @throws ExecutionException
*/
@Test
public void testConcurrentRemoveSessionContext() throws InterruptedException, ExecutionException, TimeoutException {
return null;
}
};
-
+
Future<Void> addSessionResult = taskExecutor.submit(delayedThread);
Future<Void> removeSessionResult = taskExecutor.submit(noDelayThread);
-
+
addSessionResult.get(REGISTRATION_ACTION_TIMEOUT, TimeUnit.SECONDS);
removeSessionResult.get(REGISTRATION_ACTION_TIMEOUT, TimeUnit.SECONDS);
}
private static class ThreadPoolCollectingExecutor extends ThreadPoolLoggingExecutor {
-
+
private List<String> failLogbook;
private int threadExitCounter = 0;
int maximumPoolSize, long keepAliveTime, TimeUnit unit,
BlockingQueue<Runnable> workQueue, String poolName) {
super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, poolName);
-
+
failLogbook = Collections.synchronizedList(new ArrayList<String>());
}
-
+
@Override
protected void afterExecute(Runnable r, Throwable t) {
super.afterExecute(r, t);
threadExitCounter ++;
-
+
if (t != null) {
failLogbook.add("job ["+r+"] exited with throwable:" + t.getMessage());
}
}
-
+
/**
* @return the chronicles
*/
public List<String> getFailLogbook() {
return failLogbook;
}
-
+
/**
* @return the threadExitCounter
*/
package org.opendaylight.openflowplugin.openflow.md.core.sal;\r
\r
\r
+import com.google.common.util.concurrent.Futures;
import java.util.ArrayList;\r
-\r
import org.junit.Assert;\r
import org.junit.Before;\r
import org.junit.Test;\r
import org.mockito.Mock;\r
+import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;\r
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;\r
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
+import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;\r
\r
/**\r
*/\r
public class OpenflowPluginProviderTest {\r
\r
- @Mock BindingAwareBroker baBroker;\r
- @Mock SwitchConnectionProvider switchProvider;\r
+ @Mock
+ DataBroker dataBroker;
+ @Mock
+ NotificationProviderService notificationProviderService;
+ @Mock
+ RpcProviderRegistry rpcProviderRegistry;
+ @Mock
+ SwitchConnectionProvider switchProvider;
\r
OpenflowPluginProvider provider = new OpenflowPluginProvider();\r
\r
*/\r
@Test\r
public void testInitialization() {\r
+ Mockito.when(switchProvider.startup()).thenReturn(Futures.immediateFuture(Boolean.TRUE));
ArrayList<SwitchConnectionProvider> switchProviders = new ArrayList<>();\r
switchProviders.add(switchProvider);\r
provider.setSwitchConnectionProviders(switchProviders);\r
- provider.setBroker(baBroker);\r
+ provider.setDataBroker(dataBroker);
+ provider.setNotificationService(notificationProviderService);
+ provider.setRpcRegistry(rpcProviderRegistry);
provider.initialization();\r
\r
Assert.assertNotNull("Wrong message count dumper", provider.getMessageCountDumper());\r
Assert.assertNotNull("Wrong extension converter registrator", provider.getExtensionConverterRegistrator());\r
- Assert.assertNull("Wrong context", provider.getContext());\r
- Assert.assertNotNull("Wrong broker", provider.getBroker());\r
+ Assert.assertNotNull("Wrong data broker", provider.getDataBroker());
+ Assert.assertNotNull("Wrong notification service", provider.getNotificationService());
+ Assert.assertNotNull("Wrong rpc registry", provider.getRpcRegistry());
}\r
}
\ No newline at end of file
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
+import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
import org.opendaylight.controller.sal.common.util.Rpcs;
import org.opendaylight.openflowplugin.api.OFConstants;
import org.opendaylight.openflowplugin.api.openflow.md.ModelDrivenSwitch;
private ListeningExecutorService rpcPool;
@Mock
private NotificationProviderService notificationProviderService;
+ @Mock
+ private RpcProviderRegistry rpcProviderRegistry;
+ @Mock
+ private DataBroker dataBroker;
private ModelDrivenSwitch mdSwitchOF13;
Matchers.any(SwitchConnectionDistinguisher.class))).thenReturn(Futures.immediateFuture(result));
salRegistrationManager = new SalRegistrationManager();
- salRegistrationManager.onSessionInitiated(providerContext);
salRegistrationManager.setPublishService(notificationProviderService);
+ salRegistrationManager.setDataService(dataBroker);
+ salRegistrationManager.setRpcProviderRegistry(rpcProviderRegistry);
+
+ salRegistrationManager.init();
}
*/
package org.opendaylight.openflowplugin.openflow.md.core.session;
+import com.google.common.util.concurrent.ListeningExecutorService;
import java.math.BigInteger;
import java.net.InetSocketAddress;
-
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.stubbing.Answer;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
+import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
import org.opendaylight.openflowplugin.api.openflow.md.core.ConnectionConductor;
import org.opendaylight.openflowplugin.api.openflow.md.core.NotificationEnqueuer;
import org.opendaylight.yangtools.yang.binding.Notification;
import org.opendaylight.yangtools.yang.binding.RpcService;
-import com.google.common.util.concurrent.ListeningExecutorService;
-
/**
* test of {@link SessionManagerOFImpl}
*/
@RunWith(MockitoJUnitRunner.class)
public class SessionManagerOFImplTest {
-
+
private SessionManager sm;
private SwitchSessionKeyOF sessionKey;
@Mock
@Mock
private ConnectionConductor primaryConductor;
@Mock
- private ListeningExecutorService rpcPool;
+ private ListeningExecutorService rpcPool;
@Mock
- private NotificationProviderService notificationProviderService;
+ private NotificationProviderService notificationProviderService;
@Mock
- private ProviderContext providerContext;
+ private RpcProviderRegistry rpcProviderRegistry;
@Mock
private NotificationEnqueuer notificationEnqueuer;
@Mock
private ConnectionAdapter connectionAdapter;
+ @Mock
+ private DataBroker dataService;
/**
* prepare session manager
// context
Mockito.when(context.getPrimaryConductor()).thenReturn(primaryConductor);
Mockito.when(context.getNotificationEnqueuer()).thenReturn(notificationEnqueuer);
-
+
// provider context - registration responder
- Mockito.when(providerContext.addRoutedRpcImplementation(Matchers.any(Class.class), Matchers.any(RpcService.class)))
+ Mockito.when(rpcProviderRegistry.addRoutedRpcImplementation(Matchers.any(Class.class), Matchers.any(RpcService.class)))
.then(new Answer<RoutedRpcRegistration<?>>() {
@Override
public RoutedRpcRegistration<?> answer(InvocationOnMock invocation) {
return registration;
}
});
-
+
// session listener - prepare registration and notification mockery
SalRegistrationManager sessionListener = new SalRegistrationManager();
sessionListener.setPublishService(notificationProviderService);
- sessionListener.setProviderContext(providerContext);
-
+ sessionListener.setRpcProviderRegistry(rpcProviderRegistry);
+ sessionListener.setDataService(dataService);
+
// session manager (mimic SalRegistrationManager.onSessionInitiated())
sm = SessionManagerOFImpl.getInstance();
sm.setRpcPool(rpcPool);
sm.registerSessionListener(sessionListener);
sm.setNotificationProviderService(notificationProviderService);
-
+
// session key - switch id
sessionKey = new SwitchSessionKeyOF();
sessionKey.setDatapathId(BigInteger.valueOf(42));
}
-
+
/**
* free session manager
*/
}
/**
- * Test method for {@link org.opendaylight.openflowplugin.openflow.md.core.session.SessionManagerOFImpl#addSessionContext(org.opendaylight.openflowplugin.openflow.md.core.session.SwitchSessionKeyOF, org.opendaylight.openflowplugin.openflow.md.core.session.SessionContext)}.
+ * Test method for {@link org.opendaylight.openflowplugin.openflow.md.core.session.SessionManagerOFImpl#addSessionContext(SwitchSessionKeyOF, SessionContext)}.
*/
@Test
public void testAddSessionContext() {
Mockito.when(context.getFeatures()).thenReturn(featuresBld.build());
Mockito.when(primaryConductor.getConnectionAdapter()).thenReturn(connectionAdapter);
Mockito.when(connectionAdapter.getRemoteAddress()).thenReturn(new InetSocketAddress("10.1.2.3", 4242));
-
+
//test target
sm.addSessionContext(sessionKey, context);
-
+
//capture
ArgumentCaptor<NotificationQueueWrapper> notifCaptor = ArgumentCaptor.forClass(NotificationQueueWrapper.class);
Mockito.verify(notificationEnqueuer).enqueueNotification(notifCaptor.capture());