void setIsStatisticsPollingOff(final boolean isStatisticsPollingOff);
- void setEntityOwnershipService(EntityOwnershipService entityOwnershipService);
-
-
/**
* Backward compatibility feature - exposing rpc for statistics polling (result is provided in form of async notification)
*
AutoCloseable,
DeviceReplyProcessor,
TxFacade,
- XidSequencer,
DeviceRegistry{
/**
/**
* API defining basic device information
*/
-public interface DeviceInfo {
+public interface DeviceInfo extends XidSequencer {
/**
* @return id of encapsulated node
import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitializationPhaseHandler;
import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceLifecycleSupervisor;
import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceTerminationPhaseHandler;
+import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
import org.opendaylight.openflowplugin.api.openflow.translator.TranslatorLibrarian;
/**
+++ /dev/null
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.openflowplugin.api.openflow.lifecycle;
-
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
-
-/**
- * This API is for all listeners who wish to know about device context in cluster
- */
-public interface DeviceContextChangeListener {
-
- /**
- * Notification about start phase in device context, right after successful handshake
- * @param deviceInfo
- * @param success or failure
- */
- void deviceStartInitializationDone(final DeviceInfo deviceInfo, final boolean success);
-
- /**
- * Notification about start phase in device context, after all other contexts initialized properly
- * @param deviceInfo
- * @param success
- */
- void deviceInitializationDone(final DeviceInfo deviceInfo, final boolean success);
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.openflowplugin.api.openflow.lifecycle;
-
-import io.netty.util.Timeout;
-import io.netty.util.TimerTask;
-import java.util.concurrent.TimeUnit;
-import javax.annotation.Nonnull;
-import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
-import org.opendaylight.openflowplugin.api.openflow.OFPManager;
-import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
-import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsContext;
-import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageIntelligenceAgency;
-
-/**
- * This class is a binder between all managers
- * Should be defined in OpenFlowPluginProviderImpl
- */
-public interface LifecycleConductor {
-
- /**
- * Returns device context from device manager device contexts maps
- *
- * @param deviceInfo@return null if context doesn't exists
- */
- DeviceContext getDeviceContext(DeviceInfo deviceInfo);
-
-
- /**
- * Setter for device manager once set it cant be unset or overwritten
- * @param manager
- */
- void setSafelyManager(OFPManager manager);
-
- /**
- * Set new timeout for {@link io.netty.util.HashedWheelTimer}
- * @param task timer task
- * @param delay delay
- * @param unit time unit
- * @return new timeout
- */
- Timeout newTimeout(@Nonnull TimerTask task, long delay, @Nonnull TimeUnit unit);
-
- /**
- * Returns message intelligence agency
- * @return MessageIntelligenceAgency set by constructor
- */
- MessageIntelligenceAgency getMessageIntelligenceAgency();
-
- /**
- * Interrupt connection for the node
- * @param deviceInfo node identification
- */
- void closeConnection(final DeviceInfo deviceInfo);
-
- ConnectionContext.CONNECTION_STATE gainConnectionStateSafely(DeviceInfo deviceInfo);
-
- /**
- * Xid from outboundqueue
- * @param deviceInfo
- * @return
- */
- Long reserveXidForDeviceMessage(final DeviceInfo deviceInfo);
-
- NotificationPublishService getNotificationPublishService();
-
- void setNotificationPublishService(NotificationPublishService notificationPublishService);
-}
void setRoleContext(RoleContext roleContext);
void setStatContext(StatisticsContext statContext);
+
+ /**
+ * Some services, contexts etc. still need to have access to device context,
+ * instead to push into them, here is the getter
+ * @return device context for this device
+ */
+ DeviceContext getDeviceContext();
+
+ /**
+ * if some services not started properly need to close connection
+ */
+ void closeConnection();
}
import org.opendaylight.openflowplugin.api.openflow.OFPManager;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
+import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
import org.opendaylight.openflowplugin.api.openflow.rpc.listener.ItemLifecycleListener;
/**
* @return true if scheduling is enabled
*/
boolean isSchedulingEnabled();
+
+ LifecycleService getLifecycleService();
}
+++ /dev/null
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.openflowplugin.impl;
-
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import com.google.common.util.concurrent.FutureCallback;
-import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.ListenableFuture;
-import io.netty.util.HashedWheelTimer;
-import io.netty.util.Timeout;
-import io.netty.util.TimerTask;
-import java.util.Collection;
-import java.util.List;
-import java.util.concurrent.TimeUnit;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
-import org.opendaylight.openflowplugin.api.openflow.OFPManager;
-import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceManager;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.DeviceContextChangeListener;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.RoleChangeListener;
-import org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry;
-import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
-import org.opendaylight.openflowplugin.api.openflow.rpc.RpcManager;
-import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsContext;
-import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsManager;
-import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageIntelligenceAgency;
-import org.opendaylight.openflowplugin.extension.api.ExtensionConverterProviderKeeper;
-import org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionConverterProvider;
-import org.opendaylight.openflowplugin.impl.util.MdSalRegistrationUtils;
-import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.OfpRole;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- */
-final class LifecycleConductorImpl implements LifecycleConductor, DeviceContextChangeListener, ExtensionConverterProviderKeeper {
-
- private static final Logger LOG = LoggerFactory.getLogger(LifecycleConductorImpl.class);
- private static final int TICKS_PER_WHEEL = 500;
- private static final long TICK_DURATION = 10; // 0.5 sec.
-
- private final HashedWheelTimer hashedWheelTimer = new HashedWheelTimer(TICK_DURATION, TimeUnit.MILLISECONDS, TICKS_PER_WHEEL);
- private ExtensionConverterProvider extensionConverterProvider;
- private DeviceManager deviceManager;
- private StatisticsManager statisticsManager;
- private RpcManager rpcManager;
- private final MessageIntelligenceAgency messageIntelligenceAgency;
- private final ConvertorExecutor convertorExecutor;
- private NotificationPublishService notificationPublishService;
-
- LifecycleConductorImpl(final MessageIntelligenceAgency messageIntelligenceAgency, ConvertorExecutor convertorExecutor) {
- this.messageIntelligenceAgency = Preconditions.checkNotNull(messageIntelligenceAgency);
- this.convertorExecutor = convertorExecutor;
- }
-
- @Override
- public ExtensionConverterProvider getExtensionConverterProvider() {
- return extensionConverterProvider;
- }
-
- @Override
- public void setExtensionConverterProvider(ExtensionConverterProvider extensionConverterProvider) {
- this.extensionConverterProvider = extensionConverterProvider;
- }
-
- @Override
- public void setSafelyManager(final OFPManager manager){
- if (manager instanceof RpcManager) {
- if (rpcManager != null) {
- LOG.info("RPC manager {} is already defined in conductor. ", manager);
- return;
- }
- this.rpcManager = (RpcManager) manager;
- } else {
- if (manager instanceof StatisticsManager) {
- if (statisticsManager != null) {
- LOG.info("Statistics manager {} is already defined in conductor. ", manager);
- return;
- }
- this.statisticsManager = (StatisticsManager) manager;
- } else {
- if (manager instanceof DeviceManager) {
- if (deviceManager != null) {
- LOG.info("Device manager {} is already defined in conductor. ", manager);
- return;
- }
- this.deviceManager = (DeviceManager) manager;
- }
- }
- }
- }
-
- public void closeConnection(final DeviceInfo deviceInfo) {
- LOG.debug("Close connection called for node {}", deviceInfo);
- final DeviceContext deviceContext = getDeviceContext(deviceInfo);
- if (null != deviceContext) {
- deviceContext.shutdownConnection();
- }
- }
-
- public MessageIntelligenceAgency getMessageIntelligenceAgency() {
- return messageIntelligenceAgency;
- }
-
- @Override
- public DeviceContext getDeviceContext(DeviceInfo deviceInfo){
- return deviceManager.gainContext(deviceInfo);
- }
-
- public Timeout newTimeout(@Nonnull TimerTask task, long delay, @Nonnull TimeUnit unit) {
- return hashedWheelTimer.newTimeout(task, delay, unit);
- }
-
- @Override
- public ConnectionContext.CONNECTION_STATE gainConnectionStateSafely(final DeviceInfo deviceInfo){
- return (null != getDeviceContext(deviceInfo)) ? getDeviceContext(deviceInfo).getPrimaryConnectionContext().getConnectionState() : null;
- }
-
- @Override
- public Long reserveXidForDeviceMessage(final DeviceInfo deviceInfo){
- return null != getDeviceContext(deviceInfo) ? getDeviceContext(deviceInfo).reserveXidForDeviceMessage() : null;
- }
-
- @Override
- public void deviceStartInitializationDone(final DeviceInfo deviceInfo, final boolean success) {
- if (!success) {
- LOG.warn("Initialization phase for node {} in device context was NOT successful, closing connection.", deviceInfo.getNodeId().getValue());
- closeConnection(deviceInfo);
- } else {
- LOG.info("initialization phase for node {} in device context was successful. Continuing to next context.", deviceInfo.getNodeId().getValue());
- }
- }
-
- @Override
- public void deviceInitializationDone(final DeviceInfo deviceInfo, final boolean success) {
- if (!success) {
- LOG.warn("Initialization phase for node {} in device context was NOT successful, closing connection.", deviceInfo.getNodeId().getValue());
- closeConnection(deviceInfo);
- } else {
- LOG.info("initialization phase for node {} in device context was successful. All phases initialized OK.", deviceInfo.getNodeId().getValue());
- }
- }
-
- @Override
- public NotificationPublishService getNotificationPublishService() {
- return notificationPublishService;
- }
-
- @Override
- public void setNotificationPublishService(NotificationPublishService notificationPublishService) {
- this.notificationPublishService = notificationPublishService;
- }
-}
openflowPluginProvider.setRpcProviderRegistry(rpcRegistry);
openflowPluginProvider.setNotificationProviderService(notificationService);
openflowPluginProvider.setNotificationPublishService(notificationPublishService);
- openflowPluginProvider.setEntityOwnershipService(entityOwnershipService);
openflowPluginProvider.setSwitchFeaturesMandatory(providerConfig.isSwitchFeaturesMandatory());
openflowPluginProvider.setIsStatisticsPollingOff(providerConfig.isIsStatisticsPollingOff());
openflowPluginProvider.setIsStatisticsRpcEnabled(providerConfig.isIsStatisticsRpcEnabled());
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
+import io.netty.util.HashedWheelTimer;
import java.lang.management.ManagementFactory;
import java.util.ArrayList;
import java.util.Collection;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
import org.opendaylight.controller.md.sal.binding.api.NotificationService;
-import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;
import org.opendaylight.openflowplugin.api.openflow.OpenFlowPluginProvider;
import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionManager;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceManager;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
import org.opendaylight.openflowplugin.api.openflow.role.RoleManager;
import org.opendaylight.openflowplugin.api.openflow.rpc.RpcManager;
import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsManager;
private static final Logger LOG = LoggerFactory.getLogger(OpenFlowPluginProviderImpl.class);
private static final MessageIntelligenceAgency messageIntelligenceAgency = new MessageIntelligenceAgencyImpl();
+ private static final int TICKS_PER_WHEEL = 500;
+ private static final long TICK_DURATION = 10; // 0.5 sec.
+
+ private final HashedWheelTimer hashedWheelTimer = new HashedWheelTimer(TICK_DURATION, TimeUnit.MILLISECONDS, TICKS_PER_WHEEL);
private final int rpcRequestsQuota;
private final long globalNotificationQuota;
private ConnectionManager connectionManager;
private NotificationService notificationProviderService;
private NotificationPublishService notificationPublishService;
- private EntityOwnershipService entityOwnershipService;
-
private ExtensionConverterManager extensionConverterManager;
-
private DataBroker dataBroker;
private Collection<SwitchConnectionProvider> switchConnectionProviders;
private boolean switchFeaturesMandatory = false;
private boolean isStatisticsPollingOff = false;
private boolean isStatisticsRpcEnabled;
private boolean isNotificationFlowRemovedOff = false;
-
- private final LifecycleConductor conductor;
private final ThreadPoolExecutor threadPool;
private ClusterSingletonServiceProvider singletonServicesProvider;
Preconditions.checkNotNull(threadPoolMaxThreads),
Preconditions.checkNotNull(threadPoolTimeout), TimeUnit.SECONDS,
new SynchronousQueue<>(), "ofppool");
-
convertorManager = ConvertorManagerFactory.createDefaultManager();
- conductor = new LifecycleConductorImpl(messageIntelligenceAgency, convertorManager);
}
@Override
return switchFeaturesMandatory;
}
- @Override
- public void setEntityOwnershipService(final EntityOwnershipService entityOwnershipService) {
- this.entityOwnershipService = entityOwnershipService;
- }
-
@Override
public void setBarrierCountLimit(final int barrierCountLimit) {
this.barrierCountLimit = barrierCountLimit;
this.singletonServicesProvider = singletonServicesProvider;
}
-
@Override
public void setSwitchFeaturesMandatory(final boolean switchFeaturesMandatory) {
this.switchFeaturesMandatory = switchFeaturesMandatory;
switchFeaturesMandatory,
barrierInterval,
barrierCountLimit,
- conductor,
+ getMessageIntelligenceAgency(),
isNotificationFlowRemovedOff,
- convertorManager,
- singletonServicesProvider);
- ((ExtensionConverterProviderKeeper) conductor).setExtensionConverterProvider(extensionConverterManager);
- ((ExtensionConverterProviderKeeper) deviceManager).setExtensionConverterProvider(extensionConverterManager);
- conductor.setSafelyManager(deviceManager);
- conductor.setNotificationPublishService(notificationPublishService);
+ singletonServicesProvider,
+ notificationPublishService,
+ hashedWheelTimer,
+ convertorManager);
- statisticsManager = new StatisticsManagerImpl(rpcProviderRegistry, isStatisticsPollingOff, conductor, convertorManager);
- roleManager = new RoleManagerImpl(dataBroker, conductor);
- conductor.setSafelyManager(statisticsManager);
+ ((ExtensionConverterProviderKeeper) deviceManager).setExtensionConverterProvider(extensionConverterManager);
- rpcManager = new RpcManagerImpl(rpcProviderRegistry, rpcRequestsQuota, conductor, extensionConverterManager, convertorManager, notificationPublishService);
- conductor.setSafelyManager(rpcManager);
+ rpcManager = new RpcManagerImpl(rpcProviderRegistry, rpcRequestsQuota, extensionConverterManager, convertorManager, notificationPublishService);
+ roleManager = new RoleManagerImpl(dataBroker, hashedWheelTimer);
+ statisticsManager = new StatisticsManagerImpl(rpcProviderRegistry, isStatisticsPollingOff, hashedWheelTimer, convertorManager);
/* Initialization Phase ordering - OFP Device Context suite */
// CM -> DM -> SM -> RPC -> Role -> DM
import com.google.common.base.Preconditions;
import java.math.BigInteger;
import java.net.InetSocketAddress;
+import java.util.Objects;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
nodeId,
DeviceStateUtil.createNodeInstanceIdentifier(nodeId),
featuresReply.getVersion(),
- featuresReply.getDatapathId());
+ featuresReply.getDatapathId(),
+ outboundQueueProvider);
}
@Override
private class DeviceInfoImpl implements DeviceInfo {
- final private NodeId nodeId;
- final private KeyedInstanceIdentifier<Node, NodeKey> nodeII;
- final private Short version;
- final private BigInteger datapathId;
- final private ServiceGroupIdentifier serviceGroupIdentifier;
+ private final NodeId nodeId;
+ private final KeyedInstanceIdentifier<Node, NodeKey> nodeII;
+ private final Short version;
+ private final BigInteger datapathId;
+ private final ServiceGroupIdentifier serviceGroupIdentifier;
+ private OutboundQueue outboundQueueProvider;
DeviceInfoImpl(
final NodeId nodeId,
final KeyedInstanceIdentifier<Node, NodeKey> nodeII,
final Short version,
- final BigInteger datapathId) {
+ final BigInteger datapathId,
+ final OutboundQueue outboundQueueProvider) {
this.nodeId = nodeId;
this.nodeII = nodeII;
this.version = version;
this.datapathId = datapathId;
+ this.outboundQueueProvider = outboundQueueProvider;
this.serviceGroupIdentifier = ServiceGroupIdentifier.create(this.nodeId.getValue());
}
result = 31 * result + datapathId.hashCode();
return result;
}
+
+ @Override
+ public Long reserveXidForDeviceMessage() {
+ return outboundQueueProvider.reserveEntry();
+ }
}
}
import org.opendaylight.controller.md.sal.common.api.data.TransactionChainClosedException;
import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
-import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey;
import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
-import org.opendaylight.openflowplugin.api.openflow.connection.OutboundQueueProvider;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceManager;
import org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary;
import org.opendaylight.openflowplugin.api.openflow.device.Xid;
import org.opendaylight.openflowplugin.api.openflow.device.handlers.MultiMsgCollector;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
import org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDistinguisher;
import org.opendaylight.openflowplugin.api.openflow.md.core.TranslatorKey;
import org.opendaylight.openflowplugin.api.openflow.registry.ItemLifeCycleRegistry;
private final MessageSpy messageSpy;
private final ItemLifeCycleKeeper flowLifeCycleKeeper;
private NotificationPublishService notificationPublishService;
- private final OutboundQueue outboundQueueProvider;
private Timeout barrierTaskTimeout;
private final MessageTranslator<PortGrouping, FlowCapableNodeConnector> portStatusTranslator;
private final MessageTranslator<PacketInMessage, PacketReceived> packetInTranslator;
public DeviceContextImpl(
@Nonnull final ConnectionContext primaryConnectionContext,
@Nonnull final DataBroker dataBroker,
- @Nonnull final LifecycleConductor conductor,
- @Nonnull final OutboundQueueProvider outboundQueueProvider,
+ @Nonnull final MessageSpy messageSpy,
@Nonnull final TranslatorLibrary translatorLibrary,
@Nonnull final DeviceManager manager,
final ConvertorExecutor convertorExecutor) {
this.deviceInfo = primaryConnectionContext.getDeviceInfo();
this.deviceState = new DeviceStateImpl();
this.dataBroker = Preconditions.checkNotNull(dataBroker);
- Preconditions.checkNotNull(conductor);
- this.outboundQueueProvider = Preconditions.checkNotNull(outboundQueueProvider);
- this.transactionChainManager = new TransactionChainManager(dataBroker, deviceInfo , conductor);
+ this.transactionChainManager = new TransactionChainManager(dataBroker, deviceInfo);
auxiliaryConnectionContexts = new HashMap<>();
deviceFlowRegistry = new DeviceFlowRegistryImpl(dataBroker, deviceInfo.getNodeInstanceIdentifier());
deviceGroupRegistry = new DeviceGroupRegistryImpl();
deviceMeterRegistry = new DeviceMeterRegistryImpl();
- messageSpy = conductor.getMessageIntelligenceAgency();
+ this.messageSpy = Preconditions.checkNotNull(messageSpy);
this.deviceManager = Preconditions.checkNotNull(manager);
packetInLimiter = new PacketInRateLimiter(primaryConnectionContext.getConnectionAdapter(),
- /*initial*/ 1000, /*initial*/2000, messageSpy, REJECTED_DRAIN_FACTOR);
+ /*initial*/ 1000, /*initial*/2000, this.messageSpy, REJECTED_DRAIN_FACTOR);
this.translatorLibrary = translatorLibrary;
portStatusTranslator = translatorLibrary.lookupTranslator(
transactionChainManager.initialSubmitWriteTransaction();
}
- @Override
- public Long reserveXidForDeviceMessage() {
- return outboundQueueProvider.reserveEntry();
- }
-
@Override
public void addAuxiliaryConnectionContext(final ConnectionContext connectionContext) {
final SwitchConnectionDistinguisher connectionDistinguisher = createConnectionDistinguisher(connectionContext);
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
+import io.netty.util.HashedWheelTimer;
import io.netty.util.TimerTask;
import java.util.Collections;
import java.util.Iterator;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
import org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary;
import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitializationPhaseHandler;
import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceTerminationPhaseHandler;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
+import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
import org.opendaylight.openflowplugin.extension.api.ExtensionConverterProviderKeeper;
import org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionConverterProvider;
import org.opendaylight.openflowplugin.impl.connection.OutboundQueueProviderImpl;
private ExtensionConverterProvider extensionConverterProvider;
private ScheduledThreadPoolExecutor spyPool;
private final ClusterSingletonServiceProvider singletonServiceProvider;
-
- private final LifecycleConductor conductor;
+ private final NotificationPublishService notificationPublishService;
+ private final MessageSpy messageSpy;
+ private final HashedWheelTimer hashedWheelTimer;
public DeviceManagerImpl(@Nonnull final DataBroker dataBroker,
final long globalNotificationQuota,
final boolean switchFeaturesMandatory,
final long barrierInterval,
final int barrierCountLimit,
- final LifecycleConductor lifecycleConductor,
- boolean isNotificationFlowRemovedOff,
- final ConvertorExecutor convertorExecutor,
- final ClusterSingletonServiceProvider singletonServiceProvider) {
+
+ final MessageSpy messageSpy,
+ final boolean isNotificationFlowRemovedOff,
+ final ClusterSingletonServiceProvider singletonServiceProvider,
+ final NotificationPublishService notificationPublishService,
+ final HashedWheelTimer hashedWheelTimer,
+ final ConvertorExecutor convertorExecutor) {
this.switchFeaturesMandatory = switchFeaturesMandatory;
this.globalNotificationQuota = globalNotificationQuota;
this.isNotificationFlowRemovedOff = isNotificationFlowRemovedOff;
this.dataBroker = Preconditions.checkNotNull(dataBroker);
this.convertorExecutor = convertorExecutor;
+ this.hashedWheelTimer = hashedWheelTimer;
/* merge empty nodes to oper DS to predict any problems with missing parent for Node */
final WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
this.barrierIntervalNanos = TimeUnit.MILLISECONDS.toNanos(barrierInterval);
this.barrierCountLimit = barrierCountLimit;
- this.conductor = lifecycleConductor;
spyPool = new ScheduledThreadPoolExecutor(1);
this.singletonServiceProvider = singletonServiceProvider;
+ this.notificationPublishService = notificationPublishService;
+ this.messageSpy = messageSpy;
}
connectionAdapter.registerOutboundQueueHandler(outboundQueueProvider, barrierCountLimit, barrierIntervalNanos);
connectionContext.setOutboundQueueHandleRegistration(outboundQueueHandlerRegistration);
- final DeviceContext deviceContext = new DeviceContextImpl(connectionContext,
+ final DeviceContext deviceContext = new DeviceContextImpl(
+ connectionContext,
dataBroker,
- conductor,
- outboundQueueProvider,
+ messageSpy,
translatorLibrary,
this,
convertorExecutor);
+ Verify.verify(deviceContexts.putIfAbsent(deviceInfo, deviceContext) == null, "DeviceCtx still not closed.");
+
final LifecycleService lifecycleService = new LifecycleServiceImpl();
lifecycleService.setDeviceContext(deviceContext);
- Verify.verify(deviceContexts.putIfAbsent(deviceInfo, deviceContext) == null, "DeviceCtx still not closed.");
lifecycleServices.putIfAbsent(deviceInfo, lifecycleService);
deviceContext.setSwitchFeaturesMandatory(switchFeaturesMandatory);
((ExtensionConverterProviderKeeper) deviceContext).setExtensionConverterProvider(extensionConverterProvider);
- deviceContext.setNotificationPublishService(conductor.getNotificationPublishService());
+ deviceContext.setNotificationPublishService(notificationPublishService);
updatePacketInRateLimiters();
@Override
public void initialize() {
- spyPool.scheduleAtFixedRate(conductor.getMessageIntelligenceAgency(), SPY_RATE, SPY_RATE, TimeUnit.SECONDS);
+ spyPool.scheduleAtFixedRate(messageSpy, SPY_RATE, SPY_RATE, TimeUnit.SECONDS);
}
@Override
future.cancel(false);
}
};
- conductor.newTimeout(timerTask, 10, TimeUnit.SECONDS);
+ hashedWheelTimer.newTimeout(timerTask, 10, TimeUnit.SECONDS);
}
}
deviceContexts.put(deviceInfo, deviceContext);
}
+ @VisibleForTesting
+ void removeDeviceContextFromMap(final DeviceInfo deviceInfo){
+ deviceContexts.remove(deviceInfo);
+ }
+
@Override
public <T extends OFPContext> T gainContext(final DeviceInfo deviceInfo) {
return (T) deviceContexts.get(deviceInfo);
import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
private final Object txLock = new Object();
private final KeyedInstanceIdentifier<Node, NodeKey> nodeII;
- private final DeviceInfo deviceInfo;
private final DataBroker dataBroker;
- private final LifecycleConductor conductor;
@GuardedBy("txLock")
private WriteTransaction wTx;
private boolean initCommit;
- public TransactionChainManagerStatus getTransactionChainManagerStatus() {
- return transactionChainManagerStatus;
- }
-
@GuardedBy("txLock")
private TransactionChainManagerStatus transactionChainManagerStatus = TransactionChainManagerStatus.SLEEPING;
TransactionChainManager(@Nonnull final DataBroker dataBroker,
- @Nonnull final DeviceInfo deviceInfo,
- @Nonnull final LifecycleConductor conductor) {
+ @Nonnull final DeviceInfo deviceInfo) {
this.dataBroker = Preconditions.checkNotNull(dataBroker);
- this.conductor = Preconditions.checkNotNull(conductor);
- this.deviceInfo = deviceInfo;
this.nodeII = deviceInfo.getNodeInstanceIdentifier();
this.transactionChainManagerStatus = TransactionChainManagerStatus.SLEEPING;
lastSubmittedFuture = Futures.immediateFuture(null);
}
if (initCommit) {
LOG.error("Initial commit failed. {}", t);
- conductor.closeConnection(deviceInfo);
}
}
});
this.statContext = statContext;
}
+ @Override
+ public DeviceContext getDeviceContext() {
+ return this.deviceContext;
+ }
+
+ @Override
+ public void closeConnection() {
+ this.deviceContext.shutdownConnection();
+ }
+
private void fillDeviceFlowRegistry() {
// Fill device flow registry with flows from datastore
final ListenableFuture<List<Optional<FlowCapableNode>>> deviceFlowRegistryFill = deviceContext.getDeviceFlowRegistry().fill();
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.JdkFutureAdapters;
import com.google.common.util.concurrent.ListenableFuture;
+import io.netty.util.HashedWheelTimer;
import io.netty.util.TimerTask;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import org.opendaylight.openflowplugin.api.OFConstants;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
import org.opendaylight.openflowplugin.api.openflow.role.RoleContext;
import org.opendaylight.openflowplugin.api.openflow.role.RoleManager;
import org.opendaylight.openflowplugin.impl.rpc.AbstractRequestContext;
private static final int MAX_CLEAN_DS_RETRIES = 3;
private SalRoleService salRoleService = null;
- private final LifecycleConductor conductor;
+ private final HashedWheelTimer hashedWheelTimer;
private final DeviceInfo deviceInfo;
private CONTEXT_STATE state;
private final RoleManager myManager;
RoleContextImpl(final DeviceInfo deviceInfo,
- final LifecycleConductor lifecycleConductor,
+ final HashedWheelTimer hashedWheelTimer,
final RoleManager myManager) {
- this.conductor = lifecycleConductor;
this.deviceInfo = deviceInfo;
state = CONTEXT_STATE.WORKING;
this.myManager = myManager;
+ this.hashedWheelTimer = hashedWheelTimer;
}
@Nullable
@Override
public <T> RequestContext<T> createRequestContext() {
- return new AbstractRequestContext<T>(conductor.reserveXidForDeviceMessage(getDeviceInfo())) {
+ return new AbstractRequestContext<T>(deviceInfo.reserveXidForDeviceMessage()) {
@Override
public void close() {
}
setRoleOutputFuture.cancel(true);
}
};
- conductor.newTimeout(timerTask, 10, TimeUnit.SECONDS);
+ hashedWheelTimer.newTimeout(timerTask, 10, TimeUnit.SECONDS);
}
return JdkFutureAdapters.listenInPoolThread(setRoleOutputFuture);
}
import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
-import java.util.ArrayList;
+import io.netty.util.HashedWheelTimer;
import java.util.Iterator;
-import java.util.List;
-import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import javax.annotation.CheckForNull;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitializationPhaseHandler;
import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceTerminationPhaseHandler;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.RoleChangeListener;
import org.opendaylight.openflowplugin.api.openflow.role.RoleContext;
import org.opendaylight.openflowplugin.api.openflow.role.RoleManager;
import org.opendaylight.openflowplugin.impl.services.SalRoleServiceImpl;
import org.opendaylight.openflowplugin.impl.util.DeviceStateUtil;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.OfpRole;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private DeviceTerminationPhaseHandler deviceTerminationPhaseHandler;
private final DataBroker dataBroker;
private final ConcurrentMap<DeviceInfo, RoleContext> contexts = new ConcurrentHashMap<>();
- private List<RoleChangeListener> listeners = new ArrayList<>();
+ private final HashedWheelTimer hashedWheelTimer;
- private final LifecycleConductor conductor;
-
- public RoleManagerImpl(final DataBroker dataBroker, final LifecycleConductor lifecycleConductor) {
+ public RoleManagerImpl(final DataBroker dataBroker, final HashedWheelTimer hashedWheelTimer) {
this.dataBroker = Preconditions.checkNotNull(dataBroker);
- this.conductor = lifecycleConductor;
+ this.hashedWheelTimer = hashedWheelTimer;
}
@Override
@Override
public void onDeviceContextLevelUp(@CheckForNull final DeviceInfo deviceInfo, final LifecycleService lifecycleService) throws Exception {
- final DeviceContext deviceContext = Preconditions.checkNotNull(conductor.getDeviceContext(deviceInfo));
- final RoleContext roleContext = new RoleContextImpl(deviceInfo, conductor, this);
+ final DeviceContext deviceContext = Preconditions.checkNotNull(lifecycleService.getDeviceContext());
+ final RoleContext roleContext = new RoleContextImpl(deviceInfo, hashedWheelTimer, this);
roleContext.setSalRoleService(new SalRoleServiceImpl(roleContext, deviceContext));
Verify.verify(contexts.putIfAbsent(deviceInfo, roleContext) == null, "Role context for master Node %s is still not closed.", deviceInfo.getNodeId());
lifecycleService.setRoleContext(roleContext);
private final RpcProviderRegistry rpcProviderRegistry;
private final MessageSpy messageSpy;
private final Semaphore tracker;
- private final XidSequencer xidSequencer;
private boolean isStatisticsRpcEnabled;
// TODO: add private Sal salBroker
RpcContextImpl(final DeviceInfo deviceInfo,
final RpcProviderRegistry rpcProviderRegistry,
- final XidSequencer xidSequencer,
final MessageSpy messageSpy,
final int maxRequests,
final KeyedInstanceIdentifier<Node, NodeKey> nodeInstanceIdentifier,
final ExtensionConverterProvider extensionConverterProvider,
final ConvertorExecutor convertorExecutor,
final NotificationPublishService notificationPublishService) {
- this.xidSequencer = Preconditions.checkNotNull(xidSequencer);
this.messageSpy = Preconditions.checkNotNull(messageSpy);
this.rpcProviderRegistry = Preconditions.checkNotNull(rpcProviderRegistry);
this.nodeInstanceIdentifier = nodeInstanceIdentifier;
LOG.trace("Acquired semaphore for {}, available permits:{} ", nodeInstanceIdentifier.getKey().getId(), tracker.availablePermits());
}
- final Long xid = xidSequencer.reserveXidForDeviceMessage();
+ final Long xid = deviceInfo.reserveXidForDeviceMessage();
if (xid == null) {
LOG.warn("Xid cannot be reserved for new RequestContext, node:{}", nodeInstanceIdentifier.getKey().getId());
tracker.release();
import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitializationPhaseHandler;
import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceTerminationPhaseHandler;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
import org.opendaylight.openflowplugin.api.openflow.rpc.RpcManager;
private final ConcurrentMap<DeviceInfo, RpcContext> contexts = new ConcurrentHashMap<>();
private boolean isStatisticsRpcEnabled;
private final ExtensionConverterProvider extensionConverterProvider;
+ private final ConvertorExecutor convertorExecutor;
private final NotificationPublishService notificationPublishService;
- private final LifecycleConductor conductor;
- private final ConvertorExecutor convertorExecutor;
public RpcManagerImpl(
final RpcProviderRegistry rpcProviderRegistry,
final int quotaValue,
-
- final LifecycleConductor lifecycleConductor,
final ExtensionConverterProvider extensionConverterProvider,
final ConvertorExecutor convertorExecutor,
final NotificationPublishService notificationPublishService) {
this.rpcProviderRegistry = rpcProviderRegistry;
maxRequestsQuota = quotaValue;
this.extensionConverterProvider = extensionConverterProvider;
- this.conductor = lifecycleConductor;
this.convertorExecutor = convertorExecutor;
this.notificationPublishService = notificationPublishService;
}
@Override
public void onDeviceContextLevelUp(final DeviceInfo deviceInfo, final LifecycleService lifecycleService) throws Exception {
- final DeviceContext deviceContext = Preconditions.checkNotNull(conductor.getDeviceContext(deviceInfo));
+ final DeviceContext deviceContext = Preconditions.checkNotNull(lifecycleService.getDeviceContext());
final RpcContext rpcContext = new RpcContextImpl(
deviceInfo,
rpcProviderRegistry,
- deviceContext,
deviceContext.getMessageSpy(),
maxRequestsQuota,
deviceInfo.getNodeInstanceIdentifier(),
import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
+import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
import org.opendaylight.openflowplugin.api.openflow.rpc.listener.ItemLifecycleListener;
import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsContext;
import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsManager;
private Timeout pollTimeout;
private final DeviceInfo deviceInfo;
private final StatisticsManager myManager;
+ private final LifecycleService lifecycleService;
private volatile boolean schedulingEnabled;
private volatile CONTEXT_STATE state;
StatisticsContextImpl(@Nonnull final DeviceInfo deviceInfo,
- @Nonnull final boolean shuttingDownStatisticsPolling,
- @Nonnull final LifecycleConductor lifecycleConductor,
+ final boolean shuttingDownStatisticsPolling,
+ @Nonnull final LifecycleService lifecycleService,
@Nonnull final ConvertorExecutor convertorExecutor,
- @Nonnull final StatisticsManager myManager) {
- this.deviceContext = Preconditions.checkNotNull(lifecycleConductor.getDeviceContext(deviceInfo));
+ @Nonnull final StatisticsManager myManager) {
+ this.lifecycleService = lifecycleService;
+ this.deviceContext = lifecycleService.getDeviceContext();
this.devState = Preconditions.checkNotNull(deviceContext.getDeviceState());
this.shuttingDownStatisticsPolling = shuttingDownStatisticsPolling;
multipartReplyTranslator = new SinglePurposeMultipartReplyTranslator(convertorExecutor);
@Override
public <T> RequestContext<T> createRequestContext() {
- final AbstractRequestContext<T> ret = new AbstractRequestContext<T>(deviceContext.reserveXidForDeviceMessage()) {
+ final AbstractRequestContext<T> ret = new AbstractRequestContext<T>(deviceInfo.reserveXidForDeviceMessage()) {
@Override
public void close() {
requestContexts.remove(this);
myManager.stopScheduling(deviceInfo);
return Futures.immediateFuture(null);
}
+
+ @Override
+ public LifecycleService getLifecycleService() {
+ return lifecycleService;
+ }
}
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
+import io.netty.util.HashedWheelTimer;
import io.netty.util.Timeout;
import io.netty.util.TimerTask;
import java.util.Iterator;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
import org.opendaylight.openflowplugin.api.openflow.OFPContext;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitializationPhaseHandler;
import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceTerminationPhaseHandler;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
import org.opendaylight.openflowplugin.api.openflow.rpc.ItemLifeCycleSource;
import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsContext;
private boolean isStatisticsPollingEnabled;
private BindingAwareBroker.RpcRegistration<StatisticsManagerControlService> controlServiceRegistration;
- private final LifecycleConductor conductor;
+ private final HashedWheelTimer hashedWheelTimer;
@Override
public void setDeviceInitializationPhaseHandler(final DeviceInitializationPhaseHandler handler) {
public StatisticsManagerImpl(final RpcProviderRegistry rpcProviderRegistry,
final boolean isStatisticsPollingEnabled,
- final LifecycleConductor lifecycleConductor,
- final ConvertorExecutor convertorExecutor) {
+ final HashedWheelTimer hashedWheelTimer,
+ final ConvertorExecutor convertorExecutor) {
Preconditions.checkArgument(rpcProviderRegistry != null);
this.convertorExecutor = convertorExecutor;
this.controlServiceRegistration = Preconditions.checkNotNull(rpcProviderRegistry.addRpcImplementation(
StatisticsManagerControlService.class, this));
this.isStatisticsPollingEnabled = isStatisticsPollingEnabled;
- this.conductor = lifecycleConductor;
+ this.hashedWheelTimer = hashedWheelTimer;
}
@Override
public void onDeviceContextLevelUp(final DeviceInfo deviceInfo, final LifecycleService lifecycleService) throws Exception {
- final StatisticsContext statisticsContext = new StatisticsContextImpl(deviceInfo, isStatisticsPollingEnabled, conductor, convertorExecutor, this);
+ final StatisticsContext statisticsContext = new StatisticsContextImpl(deviceInfo, isStatisticsPollingEnabled, lifecycleService, convertorExecutor, this);
Verify.verify(contexts.putIfAbsent(deviceInfo, statisticsContext) == null, "StatisticsCtx still not closed for Node {}", deviceInfo.getNodeId());
lifecycleService.setStatContext(statisticsContext);
deviceInitPhaseHandler.onDeviceContextLevelUp(deviceInfo, lifecycleService);
calculateTimerDelay(timeCounter);
if (throwable instanceof CancellationException) {
/* This often happens when something wrong with akka or DS, so closing connection will help to restart device **/
- conductor.closeConnection(deviceInfo);
+ contexts.get(deviceInfo).getLifecycleService().closeConnection();
} else {
scheduleNextPolling(deviceState, deviceInfo, statisticsContext, timeCounter);
}
}
};
- conductor.newTimeout(timerTask, STATS_TIMEOUT_SEC, TimeUnit.SECONDS);
+ hashedWheelTimer.newTimeout(timerTask, STATS_TIMEOUT_SEC, TimeUnit.SECONDS);
}
private void scheduleNextPolling(final DeviceState deviceState,
final TimeCounter timeCounter) {
LOG.debug("SCHEDULING NEXT STATISTICS POLLING for device: {}", deviceInfo.getNodeId());
if (!isStatisticsPollingEnabled) {
- final Timeout pollTimeout = conductor.newTimeout(timeout -> pollStatistics(deviceState, statisticsContext, timeCounter, deviceInfo), currentTimerDelay, TimeUnit.MILLISECONDS);
+ final Timeout pollTimeout = hashedWheelTimer.newTimeout(
+ timeout -> pollStatistics(
+ deviceState,
+ statisticsContext,
+ timeCounter,
+ deviceInfo),
+ currentTimerDelay,
+ TimeUnit.MILLISECONDS);
statisticsContext.setPollTimeout(pollTimeout);
}
}
isStatisticsPollingEnabled = StatisticsWorkMode.FULLYDISABLED.equals(targetWorkMode);
// iterate through stats-ctx: propagate mode
for (Map.Entry<DeviceInfo, StatisticsContext> entry : contexts.entrySet()) {
+ final DeviceInfo deviceInfo = entry.getKey();
+ final StatisticsContext statisticsContext = entry.getValue();
+ final DeviceContext deviceContext = statisticsContext.getLifecycleService().getDeviceContext();
switch (targetWorkMode) {
case COLLECTALL:
- scheduleNextPolling(conductor.getDeviceContext(entry.getKey()).getDeviceState(), entry.getKey(), entry.getValue(), new TimeCounter());
- for (final ItemLifeCycleSource lifeCycleSource : conductor.getDeviceContext(entry.getKey()).getItemLifeCycleSourceRegistry().getLifeCycleSources()) {
+ scheduleNextPolling(deviceContext.getDeviceState(), deviceInfo, statisticsContext, new TimeCounter());
+ for (final ItemLifeCycleSource lifeCycleSource : deviceContext.getItemLifeCycleSourceRegistry().getLifeCycleSources()) {
lifeCycleSource.setItemLifecycleListener(null);
}
break;
case FULLYDISABLED:
- final Optional<Timeout> pollTimeout = entry.getValue().getPollTimeout();
+ final Optional<Timeout> pollTimeout = statisticsContext.getPollTimeout();
if (pollTimeout.isPresent()) {
pollTimeout.get().cancel();
}
- for (final ItemLifeCycleSource lifeCycleSource : conductor.getDeviceContext(entry.getKey()).getItemLifeCycleSourceRegistry().getLifeCycleSources()) {
- lifeCycleSource.setItemLifecycleListener(entry.getValue().getItemLifeCycleListener());
+ for (final ItemLifeCycleSource lifeCycleSource : deviceContext.getItemLifeCycleSourceRegistry().getLifeCycleSources()) {
+ lifeCycleSource.setItemLifecycleListener(statisticsContext.getItemLifeCycleListener());
}
break;
default:
LOG.info("Scheduling statistics poll for device: {}", deviceInfo.getNodeId());
statisticsContext.setSchedulingEnabled(true);
- scheduleNextPolling(conductor.getDeviceContext(deviceInfo).getDeviceState(), deviceInfo, statisticsContext, new TimeCounter());
+ final DeviceState deviceState = contexts.get(deviceInfo).getLifecycleService().getDeviceContext().getDeviceState();
+ scheduleNextPolling(deviceState, deviceInfo, statisticsContext, new TimeCounter());
}
@Override
final OutboundQueue queue = deviceContext.getPrimaryConnectionContext().getOutboundQueueProvider();
- final Long reserved = deviceContext.reserveXidForDeviceMessage();
+ final Long reserved = deviceContext.getDeviceInfo().reserveXidForDeviceMessage();
final RequestContext<List<MultipartReply>> requestContext = new AbstractRequestContext<List<MultipartReply>>(
reserved) {
@Override
+++ /dev/null
-/**
- * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.openflowplugin.impl;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import com.google.common.util.concurrent.ListenableFuture;
-import io.netty.util.HashedWheelTimer;
-import io.netty.util.TimerTask;
-import java.math.BigInteger;
-import java.util.concurrent.TimeUnit;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-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.openflowplugin.api.openflow.connection.ConnectionContext;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceManager;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
-import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
-import org.opendaylight.openflowplugin.api.openflow.rpc.RpcManager;
-import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsManager;
-import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageIntelligenceAgency;
-import org.opendaylight.openflowplugin.impl.registry.flow.DeviceFlowRegistryImpl;
-import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager;
-import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManagerFactory;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.OfpRole;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
-
-@RunWith(MockitoJUnitRunner.class)
-public class LifecycleConductorImplTest {
-
- private LifecycleConductorImpl lifecycleConductor;
-
- @Mock
- private MessageIntelligenceAgency messageIntelligenceAgency;
- @Mock
- private DeviceContext deviceContext;
- @Mock
- private DeviceManager deviceManager;
- @Mock
- private DeviceState deviceState;
- @Mock
- private ConnectionContext connectionContext;
- @Mock
- private FeaturesReply featuresReply;
- @Mock
- private TimerTask timerTask;
- @Mock
- private TimeUnit timeUnit;
- @Mock
- private HashedWheelTimer hashedWheelTimer;
- @Mock
- private ListenableFuture<Void> listenableFuture;
- @Mock
- private StatisticsManager statisticsManager;
- @Mock
- private RpcManager rpcManager;
- @Mock
- private RpcContext rpcContext;
- @Mock
- private DeviceInfo deviceInfo;
-
- private NodeId nodeId = new NodeId("openflow-junit:1");
- private OfpRole ofpRole = OfpRole.NOCHANGE;
- private KeyedInstanceIdentifier<Node, NodeKey> nodeInstanceIdentifier = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(nodeId));
-
- @Before
- public void setUp() {
- nodeInstanceIdentifier = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(nodeId));
- final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager();
-
- lifecycleConductor = new LifecycleConductorImpl(messageIntelligenceAgency, convertorManager);
- lifecycleConductor.setSafelyManager(deviceManager);
- lifecycleConductor.setSafelyManager(statisticsManager);
- lifecycleConductor.setSafelyManager(rpcManager);
-
- when(deviceManager.gainContext(Mockito.any())).thenReturn(deviceContext);
- when(deviceContext.getPrimaryConnectionContext()).thenReturn(connectionContext);
- when(deviceContext.getDeviceInfo()).thenReturn(deviceInfo);
- when(rpcManager.gainContext(Mockito.any())).thenReturn(rpcContext);
- when(deviceInfo.getNodeId()).thenReturn(nodeId);
- when(deviceInfo.getDatapathId()).thenReturn(BigInteger.TEN);
- when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(nodeInstanceIdentifier);
- when(deviceContext.getDeviceInfo()).thenReturn(deviceInfo);
- }
-
- /**
- * If getDeviceContext return null then null should be returned
- */
- @Test
- public void gainConnectionStateSafelyTest1() {
- when(deviceManager.gainContext(deviceInfo)).thenReturn(null);
- assertNull(lifecycleConductor.gainConnectionStateSafely(deviceInfo));
- }
-
- /**
- * If getDeviceContext return deviceContext then getPrimaryConnectionContext should be called
- */
- @Test
- public void gainConnectionStateSafelyTest2() {
- lifecycleConductor.gainConnectionStateSafely(deviceInfo);
- verify(deviceContext,times(1)).getPrimaryConnectionContext();
- }
-
- /**
- * If getDeviceContext returns null then null should be returned
- */
- @Test
- public void reserveXidForDeviceMessageTest1() {
- when(deviceManager.gainContext(deviceInfo)).thenReturn(null);
- assertNull(lifecycleConductor.reserveXidForDeviceMessage(deviceInfo));
- }
-
- /**
- * If getDeviceContext returns deviceContext reserveXidForDeviceMessage() should be called
- */
- @Test
- public void reserveXidForDeviceMessageTest2() {
- lifecycleConductor.reserveXidForDeviceMessage(deviceInfo);
- verify(deviceContext,times(1)).reserveXidForDeviceMessage();
- }
-
- /**
- * When succes flag is set to FALSE connection should be closed
- */
- @Test
- public void deviceStartInitializationDoneTest() {
- lifecycleConductor.deviceStartInitializationDone(deviceInfo, false);
- verify(deviceContext,times(1)).shutdownConnection();
- }
-
- /**
- * When succes flag is set to FALSE connection should be closed
- */
- @Test
- public void deviceInitializationDoneTest() {
- lifecycleConductor.deviceInitializationDone(deviceInfo, false);
- verify(deviceContext,times(1)).shutdownConnection();
- }
-}
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
provider.setDataBroker(dataBroker);
provider.setRpcProviderRegistry(rpcProviderRegistry);
provider.setNotificationProviderService(notificationService);
- provider.setEntityOwnershipService(entityOwnershipService);
provider.setSwitchConnectionProviders(Lists.newArrayList(switchConnectionProvider));
provider.setClusteringSingletonServicesProvider(clusterSingletonServiceProvider);
}
import org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary;
import org.opendaylight.openflowplugin.api.openflow.device.Xid;
import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceTerminationPhaseHandler;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
+import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
import org.opendaylight.openflowplugin.api.openflow.md.core.TranslatorKey;
import org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry;
import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowDescriptor;
@Mock
HashedWheelTimer timer;
@Mock
- MessageIntelligenceAgency messageIntelligenceAgency;
- @Mock
OutboundQueueProvider outboundQueueProvider;
@Mock
ConnectionAdapter connectionAdapter;
@Mock
private MessageTranslator<Object, Object> messageTranslatorFlowRemoved;
@Mock
- private LifecycleConductor lifecycleConductor;
- @Mock
private DeviceInfo deviceInfo;
@Mock
private DeviceManager deviceManager;
@Mock
private ConvertorExecutor convertorExecutor;
+ private LifecycleService lifecycleService;
+ @Mock
+ private MessageSpy messageSpy;
private InOrder inOrderDevState;
Mockito.when(translatorLibrary.lookupTranslator(eq(new TranslatorKey(OFConstants.OFP_VERSION_1_3,
org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemoved.class.getName()))))
.thenReturn(messageTranslatorFlowRemoved);
- Mockito.when(lifecycleConductor.getMessageIntelligenceAgency()).thenReturn(messageIntelligenceAgency);
deviceContext = new DeviceContextImpl(
connectionContext,
dataBroker,
- lifecycleConductor,
- outboundQueueProvider,
+ messageSpy,
translatorLibrary,
deviceManager,
convertorExecutor);
@Test(expected = NullPointerException.class)
public void testDeviceContextImplConstructorNullDataBroker() throws Exception {
- new DeviceContextImpl(connectionContext, null, lifecycleConductor, outboundQueueProvider, translatorLibrary, deviceManager, convertorExecutor).close();
-
+ new DeviceContextImpl(connectionContext, null, null, translatorLibrary, deviceManager, convertorExecutor).close();
}
@Test(expected = NullPointerException.class)
public void testDeviceContextImplConstructorNullTimer() throws Exception {
-
- new DeviceContextImpl(null, dataBroker, lifecycleConductor, outboundQueueProvider, translatorLibrary, deviceManager, convertorExecutor).close();
+ new DeviceContextImpl(null, dataBroker, null, translatorLibrary, deviceManager,convertorExecutor).close();
}
@Test
((DeviceContextImpl) deviceContext).getTransactionChainManager().activateTransactionManager() ;
((DeviceContextImpl) deviceContext).getTransactionChainManager().enableSubmit();
deviceContext.addDeleteToTxChain(LogicalDatastoreType.CONFIGURATION, dummyII);
- ((DeviceContextImpl) deviceContext).initialSubmitTransaction();
+ deviceContext.initialSubmitTransaction();
verify(wTx).submit();
}
- @Test
- public void testGetReservedXid() {
- deviceContext.reserveXidForDeviceMessage();
- verify(outboundQueueProvider).reserveEntry();
- }
-
@Test
public void testAuxiliaryConnectionContext() {
final ConnectionContext mockedConnectionContext = addDummyAuxiliaryConnectionContext();
public void testProcessReply() {
final Error mockedError = mock(Error.class);
deviceContext.processReply(mockedError);
- verify(messageIntelligenceAgency).spyMessage(any(Class.class), eq(MessageSpy.STATISTIC_GROUP.FROM_SWITCH_PUBLISHED_FAILURE));
+ verify(messageSpy).spyMessage(any(Class.class), eq(MessageSpy.STATISTIC_GROUP.FROM_SWITCH_PUBLISHED_FAILURE));
final OfHeader mockedOfHeader = mock(OfHeader.class);
deviceContext.processReply(mockedOfHeader);
- verify(messageIntelligenceAgency).spyMessage(any(Class.class), eq(MessageSpy.STATISTIC_GROUP.FROM_SWITCH_PUBLISHED_SUCCESS));
+ verify(messageSpy).spyMessage(any(Class.class), eq(MessageSpy.STATISTIC_GROUP.FROM_SWITCH_PUBLISHED_SUCCESS));
}
@Test
final MultipartReply mockedMultipartReply = mock(MultipartReply.class);
final Xid dummyXid = new Xid(DUMMY_XID);
deviceContext.processReply(dummyXid, Lists.newArrayList(mockedMultipartReply));
- verify(messageIntelligenceAgency).spyMessage(any(Class.class), eq(MessageSpy.STATISTIC_GROUP.FROM_SWITCH_PUBLISHED_FAILURE));
+ verify(messageSpy).spyMessage(any(Class.class), eq(MessageSpy.STATISTIC_GROUP.FROM_SWITCH_PUBLISHED_FAILURE));
}
@Test
when(mockedNotificationPublishService.offerNotification(any(PacketReceived.class))).thenReturn(stringListenableFuture);
deviceContext.setNotificationPublishService(mockedNotificationPublishService);
deviceContext.processPacketInMessage(mockedPacketInMessage);
- verify(messageIntelligenceAgency).spyMessage(any(Class.class), eq(MessageSpy.STATISTIC_GROUP.FROM_SWITCH_PUBLISHED_SUCCESS));
+ verify(messageSpy).spyMessage(any(Class.class), eq(MessageSpy.STATISTIC_GROUP.FROM_SWITCH_PUBLISHED_SUCCESS));
}
@Test
when(mockedNotificationPublishService.offerNotification(any(PacketReceived.class))).thenReturn(dummyFuture);
deviceContext.setNotificationPublishService(mockedNotificationPublishService);
deviceContext.processPacketInMessage(mockedPacketInMessage);
- verify(messageIntelligenceAgency).spyMessage(any(Class.class), eq(MessageSpy.STATISTIC_GROUP.FROM_SWITCH_NOTIFICATION_REJECTED));
+ verify(messageSpy).spyMessage(any(Class.class), eq(MessageSpy.STATISTIC_GROUP.FROM_SWITCH_NOTIFICATION_REJECTED));
}
@Test
@Test
public void testGetMessageSpy() {
final MessageSpy pickedMessageSpy = deviceContext.getMessageSpy();
- assertEquals(messageIntelligenceAgency, pickedMessageSpy);
+ assertEquals(messageSpy, pickedMessageSpy);
}
@Test
import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
-import io.netty.util.TimerTask;
+import io.netty.util.HashedWheelTimer;
import java.lang.reflect.Field;
import java.math.BigInteger;
import java.util.Collections;
import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.TimeUnit;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
-import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
import org.opendaylight.openflowplugin.api.openflow.connection.OutboundQueueProvider;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceManager;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
import org.opendaylight.openflowplugin.api.openflow.device.MessageTranslator;
import org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary;
import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitializationPhaseHandler;
import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceTerminationPhaseHandler;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
import org.opendaylight.openflowplugin.api.openflow.md.core.TranslatorKey;
import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageIntelligenceAgency;
@Mock
private NodeId mockedNodeId;
@Mock
- private LifecycleConductor lifecycleConductor;
- @Mock
private MessageIntelligenceAgency messageIntelligenceAgency;
@Mock
private DeviceInfo deviceInfo;
when(mockFeatures.getCapabilities()).thenReturn(capabilitiesV13);
when(mockFeatures.getCapabilitiesV10()).thenReturn(capabilitiesV10);
when(mockFeatures.getDatapathId()).thenReturn(BigInteger.valueOf(21L));
-
- when(lifecycleConductor.getMessageIntelligenceAgency()).thenReturn(messageIntelligenceAgency);
}
@Test
}
private DeviceManagerImpl prepareDeviceManager() {
- return prepareDeviceManager(false);
- }
-
- private DeviceManagerImpl prepareDeviceManager(final boolean withException) {
final DataBroker mockedDataBroker = mock(DataBroker.class);
final WriteTransaction mockedWriteTransaction = mock(WriteTransaction.class);
false,
barrierIntervalNanos,
barrierCountLimit,
- lifecycleConductor,
+ messageIntelligenceAgency,
true,
- convertorExecutor,
- clusterSingletonServiceProvider);
+ clusterSingletonServiceProvider,
+ null,
+ new HashedWheelTimer(),
+ convertorExecutor);
deviceManager.setDeviceInitializationPhaseHandler(deviceInitPhaseHandler);
deviceManager.setDeviceTerminationPhaseHandler(deviceTerminationPhaseHandler);
}
public void onDeviceContextLevelUp(final boolean withException) throws Exception {
- final DeviceManagerImpl deviceManager = prepareDeviceManager(withException);
+ final DeviceManagerImpl deviceManager = prepareDeviceManager();
final DeviceState mockedDeviceState = mock(DeviceState.class);
when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
deviceContexts.put(deviceInfo, deviceContext);
deviceManager.onDeviceDisconnected(connectionContext);
-
- verify(lifecycleConductor).newTimeout(Mockito.<TimerTask>any(), Mockito.anyLong(), Mockito.<TimeUnit>any());
}
protected ConnectionContext buildMockConnectionContext(final short ofpVersion) {
import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
+import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
import org.opendaylight.openflowplugin.impl.util.DeviceStateUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
@Mock
DeviceInfo deviceInfo;
@Mock
- LifecycleConductor conductor;
+ LifecycleService lifecycleService;
@Mock
private KeyedInstanceIdentifier<Node, NodeKey> nodeKeyIdent;
nodeKeyIdent = DeviceStateUtil.createNodeInstanceIdentifier(nodeId);
Mockito.when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(nodeKeyIdent);
Mockito.when(deviceInfo.getNodeId()).thenReturn(nodeId);
- txChainManager = new TransactionChainManager(dataBroker, deviceInfo, conductor);
+ txChainManager = new TransactionChainManager(dataBroker, deviceInfo);
Mockito.when(txChain.newWriteOnlyTransaction()).thenReturn(writeTx);
path = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(nodeId));
package org.opendaylight.openflowplugin.impl.role;
+import io.netty.util.HashedWheelTimer;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.invocation.InvocationOnMock;
import org.mockito.runners.MockitoJUnitRunner;
-import org.mockito.stubbing.Answer;
import org.opendaylight.controller.md.sal.common.api.clustering.CandidateAlreadyRegisteredException;
-import org.opendaylight.controller.md.sal.common.api.clustering.Entity;
-import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipCandidateRegistration;
-import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
import org.opendaylight.openflowplugin.api.openflow.role.RoleContext;
import org.opendaylight.openflowplugin.api.openflow.role.RoleManager;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
private static final Logger LOG = LoggerFactory.getLogger(RoleContextImpl.class);
@Mock
- private LifecycleConductor conductor;
+ HashedWheelTimer hashedWheelTimer;
@Mock
private DeviceInfo deviceInfo;
@Mock
@Before
public void setup() throws CandidateAlreadyRegisteredException {
- roleContext = new RoleContextImpl(deviceInfo, conductor, roleManager);
+ roleContext = new RoleContextImpl(deviceInfo, hashedWheelTimer, roleManager);
Mockito.when(deviceInfo.getNodeId()).thenReturn(nodeId);
}
@Test
public void testCreateRequestContext() throws Exception {
roleContext.createRequestContext();
- Mockito.verify(conductor).reserveXidForDeviceMessage(deviceInfo);
+ Mockito.verify(deviceInfo).reserveXidForDeviceMessage();
}
@Test(expected = NullPointerException.class)
package org.opendaylight.openflowplugin.impl.role;
-import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import com.google.common.base.VerifyException;
import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.Futures;
+import io.netty.util.HashedWheelTimer;
import java.math.BigInteger;
import org.junit.After;
-import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.clustering.Entity;
-import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipCandidateRegistration;
-import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipChange;
-import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipListener;
-import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipListenerRegistration;
-import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
import org.opendaylight.openflowplugin.api.OFConstants;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitializationPhaseHandler;
import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceTerminationPhaseHandler;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.RoleChangeListener;
import org.opendaylight.openflowplugin.api.openflow.role.RoleContext;
import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.OfpRole;
@RunWith(MockitoJUnitRunner.class)
public class RoleManagerImplTest {
- @Mock
- EntityOwnershipService entityOwnershipService;
-
@Mock
DataBroker dataBroker;
-
@Mock
DeviceContext deviceContext;
-
@Mock
DeviceManager deviceManager;
-
- @Mock
- EntityOwnershipListener entityOwnershipListener;
-
- @Mock
- EntityOwnershipListenerRegistration entityOwnershipListenerRegistration;
-
- @Mock
- EntityOwnershipCandidateRegistration entityOwnershipCandidateRegistration;
-
@Mock
ConnectionContext connectionContext;
-
@Mock
FeaturesReply featuresReply;
-
@Mock
DeviceInitializationPhaseHandler deviceInitializationPhaseHandler;
-
@Mock
DeviceTerminationPhaseHandler deviceTerminationPhaseHandler;
-
@Mock
WriteTransaction writeTransaction;
-
- @Mock
- LifecycleConductor conductor;
-
@Mock
DeviceState deviceState;
-
@Mock
DeviceInfo deviceInfo;
-
@Mock
DeviceInfo deviceInfo2;
-
@Mock
MessageSpy messageSpy;
-
@Mock
OutboundQueue outboundQueue;
-
@Mock
GetFeaturesOutput featuresOutput;
-
@Mock
LifecycleService lifecycleService;
@Before
public void setUp() throws Exception {
CheckedFuture<Void, TransactionCommitFailedException> future = Futures.immediateCheckedFuture(null);
- Mockito.when(entityOwnershipService.registerListener(Mockito.anyString(), Mockito.any(EntityOwnershipListener.class))).thenReturn(entityOwnershipListenerRegistration);
- Mockito.when(entityOwnershipService.registerCandidate(Mockito.any(Entity.class))).thenReturn(entityOwnershipCandidateRegistration);
Mockito.when(deviceContext.getPrimaryConnectionContext()).thenReturn(connectionContext);
Mockito.when(deviceContext.getDeviceState()).thenReturn(deviceState);
Mockito.when(deviceContext.getDeviceInfo()).thenReturn(deviceInfo);
Mockito.when(deviceInfo.getNodeId()).thenReturn(nodeId);
Mockito.when(deviceInfo2.getNodeId()).thenReturn(nodeId2);
Mockito.when(deviceInfo.getDatapathId()).thenReturn(BigInteger.TEN);
- roleManager = new RoleManagerImpl(dataBroker, conductor);
+ Mockito.when(lifecycleService.getDeviceContext()).thenReturn(deviceContext);
+ roleManager = new RoleManagerImpl(dataBroker, new HashedWheelTimer());
roleManager.setDeviceInitializationPhaseHandler(deviceInitializationPhaseHandler);
roleManager.setDeviceTerminationPhaseHandler(deviceTerminationPhaseHandler);
- Mockito.when(conductor.getDeviceContext(deviceInfo)).thenReturn(deviceContext);
roleManagerSpy = Mockito.spy(roleManager);
roleManagerSpy.onDeviceContextLevelUp(deviceInfo, lifecycleService);
roleContextSpy = Mockito.spy(roleManager.getRoleContext(deviceInfo));
Mockito.when(roleContextSpy.getDeviceInfo()).thenReturn(deviceInfo);
Mockito.when(roleContextSpy.getDeviceInfo().getNodeId()).thenReturn(nodeId);
- inOrder = Mockito.inOrder(entityOwnershipListenerRegistration, roleManagerSpy, roleContextSpy);
+ inOrder = Mockito.inOrder(roleManagerSpy, roleContextSpy);
}
@After
rpcContext = new RpcContextImpl(
deviceInfo,
rpcProviderRegistry,
- deviceContext,
messageSpy,
MAX_REQUESTS,
nodeInstanceIdentifier,
try (final RpcContext rpcContext = new RpcContextImpl(
deviceInfo,
rpcProviderRegistry,
- xidSequencer,
messageSpy,
100,
nodeInstanceIdentifier,
try (final RpcContext rpcContext = new RpcContextImpl(
deviceInfo,
rpcProviderRegistry,
- xidSequencer,
messageSpy,
0,
nodeInstanceIdentifier,
try (final RpcContext rpcContext = new RpcContextImpl(
deviceInfo,
rpcProviderRegistry,
- deviceContext,
messageSpy,
100,
nodeInstanceIdentifier,
*/
@Test
public void testCreateRequestContext1() throws InterruptedException {
- when(deviceContext.reserveXidForDeviceMessage()).thenReturn(null);
+ when(deviceInfo.reserveXidForDeviceMessage()).thenReturn(null);
assertEquals(rpcContext.createRequestContext(),null);
}
import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitializationPhaseHandler;
import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceTerminationPhaseHandler;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
import org.opendaylight.openflowplugin.api.openflow.registry.ItemLifeCycleRegistry;
import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
@Mock
private MessageSpy mockMsgSpy;
@Mock
- private LifecycleConductor conductor;
- @Mock
private ConnectionContext connectionContext;
@Mock
private ItemLifeCycleRegistry itemLifeCycleRegistry;
@Before
public void setUp() {
final NodeKey nodeKey = new NodeKey(nodeId);
- rpcManager = new RpcManagerImpl(rpcProviderRegistry, QUOTA_VALUE, conductor, extensionConverterProvider, convertorExecutor, notificationPublishService);
+ rpcManager = new RpcManagerImpl(rpcProviderRegistry, QUOTA_VALUE, extensionConverterProvider, convertorExecutor, notificationPublishService);
rpcManager.setDeviceInitializationPhaseHandler(deviceINitializationPhaseHandler);
GetFeaturesOutput featuresOutput = new GetFeaturesOutputBuilder()
Mockito.when(rpcProviderRegistry.addRoutedRpcImplementation(
Matchers.<Class<RpcService>>any(), Matchers.any(RpcService.class)))
.thenReturn(routedRpcRegistration);
- Mockito.when(conductor.getDeviceContext(deviceInfo)).thenReturn(deviceContext);
Mockito.when(contexts.remove(deviceInfo)).thenReturn(removedContexts);
- }
-
- @Test
- public void onDeviceContextLevelUp() throws Exception {
- rpcManager.onDeviceContextLevelUp(deviceInfo, lifecycleService);
- verify(conductor).getDeviceContext(deviceInfo);
+ Mockito.when(lifecycleService.getDeviceContext()).thenReturn(deviceContext);
}
@Test
import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceManager;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
+import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsManager;
import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
import org.opendaylight.openflowplugin.impl.statistics.services.dedicated.StatisticsGatheringOnTheFlyService;
ConnectionContext mockedConnectionContext;
DeviceInfo mockedDeviceInfo;
StatisticsManager mockedStatisticsManager;
+ LifecycleService lifecycleService;
static final KeyedInstanceIdentifier<Node, NodeKey> dummyNodeII = InstanceIdentifier.create(Nodes.class)
.child(Node.class, new NodeKey(new NodeId("dummyNodeId")));
- LifecycleConductor mockConductor;
-
@Before
public void initialize() {
mockedDeviceContext = mock(DeviceContext.class);
mockedDeviceState = mock(DeviceState.class);
mockedDeviceInfo = mock(DeviceInfo.class);
mockedStatisticsManager = mock(StatisticsManager.class);
+ lifecycleService = mock(LifecycleService.class);
final FeaturesReply mockedFeatures = mock(FeaturesReply.class);
final MessageSpy mockedMessageSpy = mock(MessageSpy.class);
final OutboundQueue mockedOutboundQueue = mock(OutboundQueue.class);
final DeviceManager mockedDeviceManager = mock(DeviceManager.class);
- mockConductor = mock(LifecycleConductor.class);
-
when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
when(mockedDeviceContext.getDeviceInfo()).thenReturn(mockedDeviceInfo);
when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedConnectionContext);
when(mockedConnectionContext.getConnectionState()).thenReturn(ConnectionContext.CONNECTION_STATE.WORKING);
when(mockedConnectionContext.getOutboundQueueProvider()).thenReturn(mockedOutboundQueue);
- mockConductor.setSafelyManager(mockedDeviceManager);
- when(mockConductor.getDeviceContext(mockedDeviceInfo)).thenReturn(mockedDeviceContext);
}
}
@Test
public void gatherDynamicDataTest() {
- final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager();
- final StatisticsContextImpl statisticsContext = new StatisticsContextImpl(mockedDeviceInfo, false, mockConductor, convertorManager, mockedStatisticsManager);
+ when(lifecycleService.getDeviceContext()).thenReturn(mockedDeviceContext);
+ when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
+ final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager();
+ final StatisticsContextImpl statisticsContext = new StatisticsContextImpl(mockedDeviceInfo, false, lifecycleService ,convertorManager, mockedStatisticsManager);
final ListenableFuture<RpcResult<List<MultipartReply>>> rpcResult = immediateFuture(RpcResultBuilder.success(Collections.<MultipartReply>emptyList()).build());
when(mockedStatisticsGatheringService.getStatisticsOfType(any(EventIdentifier.class), any(MultipartType
@Before
public void setUp() throws Exception {
convertorManager = ConvertorManagerFactory.createDefaultManager();
- when(mockedDeviceContext.reserveXidForDeviceMessage()).thenReturn(TEST_XID);
- when(mockConductor.getDeviceContext(mockedDeviceInfo)).thenReturn(mockedDeviceContext);
+ when(mockedDeviceInfo.reserveXidForDeviceMessage()).thenReturn(TEST_XID);
+ Mockito.when(lifecycleService.getDeviceContext()).thenReturn(mockedDeviceContext);
+ Mockito.when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
initStatisticsContext();
}
private void initStatisticsContext() {
- statisticsContext = new StatisticsContextImpl(mockedDeviceInfo, false, mockConductor, convertorManager, mockedStatisticsManager);
+ statisticsContext = new StatisticsContextImpl(mockedDeviceInfo, false, lifecycleService, convertorManager, mockedStatisticsManager);
statisticsContext.setStatisticsGatheringService(mockedStatisticsGatheringService);
statisticsContext.setStatisticsGatheringOnTheFlyService(mockedStatisticsOnFlyGatheringService);
}
*/
@Test
public void testClose() throws Exception {
- final StatisticsContextImpl statisticsContext = new StatisticsContextImpl(mockedDeviceInfo, false, mockConductor, convertorManager, mockedStatisticsManager);
+ final StatisticsContextImpl statisticsContext = new StatisticsContextImpl(mockedDeviceInfo, false, lifecycleService, convertorManager, mockedStatisticsManager);
final RequestContext<Object> requestContext = statisticsContext.createRequestContext();
statisticsContext.close();
try {
import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitializationPhaseHandler;
import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceTerminationPhaseHandler;
import org.opendaylight.openflowplugin.api.openflow.device.handlers.MultiMsgCollector;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
import org.opendaylight.openflowplugin.api.openflow.registry.ItemLifeCycleRegistry;
import org.opendaylight.openflowplugin.api.openflow.rpc.ItemLifeCycleSource;
@Mock
private DeviceManager deviceManager;
@Mock
- private LifecycleConductor conductor;
- @Mock
private GetFeaturesOutput featuresOutput;
@Mock
private DeviceInitializationPhaseHandler deviceInitializationPhaseHandler;
Matchers.<StatisticsManagerControlService>any())).thenReturn(serviceControlRegistration);
final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager();
- statisticsManager = new StatisticsManagerImpl(rpcProviderRegistry, false, conductor, convertorManager);
+ statisticsManager = new StatisticsManagerImpl(rpcProviderRegistry, false, new HashedWheelTimer(), convertorManager);
statisticsManager.setDeviceInitializationPhaseHandler(deviceInitializationPhaseHandler);
- when(conductor.getDeviceContext(deviceInfo)).thenReturn(mockedDeviceContext);
}
@Test
}).when(outboundQueue)
.commitEntry(Matchers.anyLong(), Matchers.<OfHeader>any(), Matchers.<FutureCallback<OfHeader>>any());
+ Mockito.when(lifecycleService.getDeviceContext()).thenReturn(mockedDeviceContext);
+ Mockito.when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
+
statisticsManager.setDeviceInitializationPhaseHandler(mockedDevicePhaseHandler);
statisticsManager.onDeviceContextLevelUp(deviceInfo, lifecycleService);
verify(mockedDevicePhaseHandler).onDeviceContextLevelUp(deviceInfo, lifecycleService);
when(itemLifeCycleRegistry.getLifeCycleSources()).thenReturn(
Collections.<ItemLifeCycleSource>emptyList());
+ when(statisticContext.getLifecycleService()).thenReturn(lifecycleService);
+ when(lifecycleService.getDeviceContext()).thenReturn(mockedDeviceContext);
+
getContextsMap(statisticsManager).put(deviceInfo, statisticContext);
final ChangeStatisticsWorkModeInputBuilder changeStatisticsWorkModeInputBld =
getContextsMap(statisticsManager).put(deviceInfo, statisticContext);
+ when(statisticContext.getLifecycleService()).thenReturn(lifecycleService);
+ when(lifecycleService.getDeviceContext()).thenReturn(mockedDeviceContext);
+
final ChangeStatisticsWorkModeInputBuilder changeStatisticsWorkModeInputBld =
new ChangeStatisticsWorkModeInputBuilder()
.setMode(StatisticsWorkMode.FULLYDISABLED);
getContextsMap(statisticsManager).put(deviceInfo, statisticContext);
+ when(statisticContext.getLifecycleService()).thenReturn(lifecycleService);
+ when(lifecycleService.getDeviceContext()).thenReturn(mockedDeviceContext);
+
final ChangeStatisticsWorkModeInputBuilder changeStatisticsWorkModeInputBld =
new ChangeStatisticsWorkModeInputBuilder()
.setMode(StatisticsWorkMode.FULLYDISABLED);