* General API for all OFP Context
*/
public interface OFPContext {
+
+ /**
+ * distinguished device context states
+ */
+ enum CONTEXT_STATE {
+ /**
+ * initial phase
+ */
+ INITIALIZATION,
+ /**
+ * standard phase
+ */
+ WORKING,
+ /**
+ * termination phase
+ */
+ TERMINATION
+ }
+
+ CONTEXT_STATE getState();
+
}
OFPContext,
DeviceRegistry{
- /**
- * distinguished device context states
- */
- enum DEVICE_CONTEXT_STATE {
- /**
- * initial phase of talking to switch
- */
- INITIALIZATION,
- /**
- * standard phase - interacting with switch
- */
- WORKING,
- /**
- * termination phase of talking to switch
- */
- TERMINATION
- }
-
- /**
- * Method returns current device context state.
- *
- * @return {@link DeviceContext.DEVICE_CONTEXT_STATE}
- */
- DEVICE_CONTEXT_STATE getDeviceContextState();
-
/**
* Method close all auxiliary connections and primary connection.
*/
private final DeviceInfo deviceInfo;
- private volatile DEVICE_CONTEXT_STATE deviceCtxState;
+ private volatile CONTEXT_STATE contextState;
@VisibleForTesting
DeviceContextImpl(@Nonnull final ConnectionContext primaryConnectionContext,
itemLifeCycleSourceRegistry = new ItemLifeCycleRegistryImpl();
flowLifeCycleKeeper = new ItemLifeCycleSourceImpl();
itemLifeCycleSourceRegistry.registerLifeCycleSource(flowLifeCycleKeeper);
- deviceCtxState = DEVICE_CONTEXT_STATE.INITIALIZATION;
+ contextState = CONTEXT_STATE.INITIALIZATION;
}
/**
@Override
public void onPublished() {
- Verify.verify(DEVICE_CONTEXT_STATE.INITIALIZATION.equals(deviceCtxState));
- deviceCtxState = DEVICE_CONTEXT_STATE.WORKING;
+ Verify.verify(CONTEXT_STATE.INITIALIZATION.equals(contextState));
+ contextState = CONTEXT_STATE.WORKING;
primaryConnectionContext.getConnectionAdapter().setPacketInFiltering(false);
for (final ConnectionContext switchAuxConnectionContext : auxiliaryConnectionContexts.values()) {
switchAuxConnectionContext.getConnectionAdapter().setPacketInFiltering(false);
@Override
public synchronized void shutdownConnection() {
LOG.debug("Shutdown method for node {}", deviceInfo.getNodeId());
- if (DEVICE_CONTEXT_STATE.TERMINATION.equals(deviceCtxState)) {
+ if (CONTEXT_STATE.TERMINATION.equals(contextState)) {
LOG.debug("DeviceCtx for Node {} is in termination process.", deviceInfo.getNodeId());
return;
}
- deviceCtxState = DEVICE_CONTEXT_STATE.TERMINATION;
+ contextState = CONTEXT_STATE.TERMINATION;
if (ConnectionContext.CONNECTION_STATE.RIP.equals(getPrimaryConnectionContext().getConnectionState())) {
LOG.debug("ConnectionCtx for Node {} is in RIP state.", deviceInfo.getNodeId());
deviceMeterRegistry.close();
}
- @Override
- public DEVICE_CONTEXT_STATE getDeviceContextState() {
- return deviceCtxState;
- }
-
@Override
public ListenableFuture<Void> shuttingDownDataStoreTransactions() {
return transactionChainManager.shuttingDown();
TransactionChainManager getTransactionChainManager() {
return this.transactionChainManager;
}
+
+ @Override
+ public CONTEXT_STATE getState() {
+ return this.contextState;
+ }
}
@Override
public ListenableFuture<Boolean> apply(@Nonnull final Void input) throws Exception {
statisticsContext.statListForCollectingInitialization();
- return statisticsContext.gatherDynamicData();
+ return statisticsContext.initialGatherDynamicData();
}
});
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.OFPContext;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
private final Semaphore roleChangeGuard = new Semaphore(1, true);
private final LifecycleConductor conductor;
+ private volatile CONTEXT_STATE contextState;
RoleContextImpl(final DeviceInfo deviceInfo, final EntityOwnershipService entityOwnershipService, final Entity entity, final Entity txEntity, final LifecycleConductor lifecycleConductor) {
this.entityOwnershipService = entityOwnershipService;
this.txEntity = txEntity;
this.deviceInfo = deviceInfo;
this.conductor = lifecycleConductor;
+ contextState = CONTEXT_STATE.INITIALIZATION;
}
@Override
public boolean initialization() {
LOG.info("Initialization main candidate for node {}", deviceInfo.getNodeId());
+ contextState = CONTEXT_STATE.WORKING;
return registerCandidate(this.entity);
}
@Override
public void close() {
+ contextState = CONTEXT_STATE.TERMINATION;
unregisterAllCandidates();
}
public boolean isMaster(){
return (txEntityOwnershipCandidateRegistration != null && entityOwnershipCandidateRegistration != null);
}
+
+ @Override
+ public CONTEXT_STATE getState() {
+ return contextState;
+ }
}
import java.util.concurrent.Semaphore;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
+import org.opendaylight.openflowplugin.api.openflow.OFPContext;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
import org.opendaylight.openflowplugin.api.openflow.device.XidSequencer;
import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
private final XidSequencer xidSequencer;
private boolean isStatisticsRpcEnabled;
+ private volatile CONTEXT_STATE contextState;
+
// TODO: add private Sal salBroker
private final ConcurrentMap<Class<?>, RoutedRpcRegistration<?>> rpcRegistrations = new ConcurrentHashMap<>();
private final KeyedInstanceIdentifier<Node, NodeKey> nodeInstanceIdentifier;
this.nodeInstanceIdentifier = nodeInstanceIdentifier;
tracker = new Semaphore(maxRequests, true);
+ contextState = CONTEXT_STATE.WORKING;
}
/**
*/
@Override
public void close() {
- for (final Iterator<Entry<Class<?>, RoutedRpcRegistration<?>>> iterator = Iterators
- .consumingIterator(rpcRegistrations.entrySet().iterator()); iterator.hasNext();) {
- final RoutedRpcRegistration<?> rpcRegistration = iterator.next().getValue();
- rpcRegistration.unregisterPath(NodeContext.class, nodeInstanceIdentifier);
- rpcRegistration.close();
- LOG.debug("Closing RPC Registration of service {} for device {}.", rpcRegistration.getServiceType(),
- nodeInstanceIdentifier);
+ if (CONTEXT_STATE.TERMINATION.equals(contextState)){
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("RpcContext is already in TERMINATION state.");
+ }
+ } else {
+ contextState = CONTEXT_STATE.TERMINATION;
+ for (final Iterator<Entry<Class<?>, RoutedRpcRegistration<?>>> iterator = Iterators
+ .consumingIterator(rpcRegistrations.entrySet().iterator()); iterator.hasNext(); ) {
+ final RoutedRpcRegistration<?> rpcRegistration = iterator.next().getValue();
+ rpcRegistration.unregisterPath(NodeContext.class, nodeInstanceIdentifier);
+ rpcRegistration.close();
+ LOG.debug("Closing RPC Registration of service {} for device {}.", rpcRegistration.getServiceType(),
+ nodeInstanceIdentifier);
+ }
}
}
public boolean isStatisticsRpcEnabled() {
return isStatisticsRpcEnabled;
}
+
+ @Override
+ public CONTEXT_STATE getState() {
+ return contextState;
+ }
}
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.concurrent.GuardedBy;
+import org.opendaylight.openflowplugin.api.openflow.OFPContext;
import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
private Timeout pollTimeout;
private volatile boolean schedulingEnabled;
+ private volatile CONTEXT_STATE contextState;
StatisticsContextImpl(@CheckForNull final DeviceInfo deviceInfo, final boolean shuttingDownStatisticsPolling, final LifecycleConductor lifecycleConductor) {
this.deviceContext = Preconditions.checkNotNull(lifecycleConductor.getDeviceContext(deviceInfo));
statisticsGatheringOnTheFlyService = new StatisticsGatheringOnTheFlyService(this, deviceContext);
itemLifeCycleListener = new ItemLifecycleListenerImpl(deviceContext);
statListForCollectingInitialization();
+ contextState = CONTEXT_STATE.WORKING;
}
@Override
@Override
public void close() {
- schedulingEnabled = false;
- for (final Iterator<RequestContext<?>> iterator = Iterators.consumingIterator(requestContexts.iterator());
- iterator.hasNext();) {
- RequestContextUtil.closeRequestContextWithRpcError(iterator.next(), CONNECTION_CLOSED);
- }
- if (null != pollTimeout && !pollTimeout.isExpired()) {
- pollTimeout.cancel();
+ if (CONTEXT_STATE.TERMINATION.equals(contextState)) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Statistics context is already in state TERMINATION.");
+ }
+ } else {
+ contextState = CONTEXT_STATE.TERMINATION;
+ schedulingEnabled = false;
+ for (final Iterator<RequestContext<?>> iterator = Iterators.consumingIterator(requestContexts.iterator());
+ iterator.hasNext(); ) {
+ RequestContextUtil.closeRequestContextWithRpcError(iterator.next(), CONNECTION_CLOSED);
+ }
+ if (null != pollTimeout && !pollTimeout.isExpired()) {
+ pollTimeout.cancel();
+ }
}
}
return itemLifeCycleListener;
}
+ @Override
+ public CONTEXT_STATE getState() {
+ return contextState;
+ }
}