* Parameters are used as marker to be sure it is change to SLAVE from MASTER or from
* MASTER to SLAVE and the last parameter "cleanDataStore" is used for validation only.
*
- * @param deviceInfo
+ * @param deviceInfo which device
* @param role - NewRole expect to be {@link OfpRole#BECOMESLAVE} or {@link OfpRole#BECOMEMASTER}
* @return RoleChangeTxChainManager future for activation/deactivation
*/
ListenableFuture<Void> onClusterRoleChange(final DeviceInfo deviceInfo, final OfpRole role);
+ /**
+ * Register device synchronize listeners
+ * @param deviceSynchronizeListener are notified if device is synchronized or not
+ */
+ void registerDeviceSynchronizeListeners(final DeviceSynchronizeListener deviceSynchronizeListener);
+
+ /**
+ * Notify all registered listeners about synchronized status
+ * @param deviceInfo which device
+ * @param deviceSynchronized true if device is synchronized
+ */
+ void notifyDeviceSynchronizeListeners(final DeviceInfo deviceInfo, final boolean deviceSynchronized);
+
+ /**
+ * Register device valid listeners
+ * @param deviceValidListener are notified if device is valid or not
+ */
+ void registerDeviceValidListeners(final DeviceValidListener deviceValidListener);
+
+ /**
+ * Notify all registered listeners about valid status
+ * @param deviceInfo which device
+ * @param deviceValid true if device is valid
+ */
+ void notifyDeviceValidListeners(final DeviceInfo deviceInfo, final boolean deviceValid);
}
package org.opendaylight.openflowplugin.api.openflow.device;
-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;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
-import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
-
/**
* Holder of device's structure
*/
-public interface DeviceState {
+public interface DeviceState extends DeviceSynchronizeListener, DeviceValidListener {
/**
* @return true if this session is valid
*/
boolean isValid();
- /**
- * @param valid the valid to set
- */
- void setValid(boolean valid);
-
/**
* Return true if we have relevant meter information
* from device
void setQueueStatisticsAvailable(boolean available);
- void setDeviceSynchronized(boolean deviceSynchronized);
-
boolean isStatisticsPollingEnabled();
void setStatisticsPollingEnabledProp(boolean statPollEnabled);
--- /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.api.openflow.device;
+
+/**
+ * API for device synchronized listeners
+ */
+public interface DeviceSynchronizeListener {
+
+ void deviceIsSynchronized(final DeviceInfo deviceInfo, final boolean isSynchronized);
+
+}
--- /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.api.openflow.device;
+
+/**
+ * API for device synchronized listeners
+ */
+public interface DeviceValidListener {
+
+ void deviceIsValid(final DeviceInfo deviceInfo, final boolean isValid);
+
+}
*/
public interface StatisticsContext extends RequestContextStack, AutoCloseable, OFPContext {
+ /**
+ * Gather data from device
+ * @return true if gathering was successful
+ */
ListenableFuture<Boolean> gatherDynamicData();
+ /**
+ * Initial data gathering
+ * @return true if gathering was successful
+ */
+ ListenableFuture<Boolean> initialGatherDynamicData();
+
/**
* Method has to be called from DeviceInitialization Method, otherwise
* we are not able to poll anything. Statistics Context normally initialize
LOG.debug("Close connection called for node {}", deviceInfo);
final DeviceContext deviceContext = getDeviceContext(deviceInfo);
if (null != deviceContext) {
+ deviceManager.notifyDeviceValidListeners(deviceInfo, false);
deviceContext.shutdownConnection();
}
}
@Override
public synchronized void shutdownConnection() {
LOG.debug("Shutdown method for node {}", deviceInfo.getNodeId());
- deviceState.setValid(false);
if (DEVICE_CONTEXT_STATE.TERMINATION.equals(deviceCtxState)) {
LOG.debug("DeviceCtx for Node {} is in termination process.", deviceInfo.getNodeId());
return;
@Override
public ListenableFuture<Void> shuttingDownDataStoreTransactions() {
- deviceState.setValid(false);
return transactionChainManager.shuttingDown();
}
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import io.netty.util.TimerTask;
+
+import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
+import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutionException;
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.DeviceSynchronizeListener;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceValidListener;
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;
private final int barrierCountLimit;
private ExtensionConverterProvider extensionConverterProvider;
private ScheduledThreadPoolExecutor spyPool;
+ private List<DeviceSynchronizeListener> deviceSynchronizedListeners;
+ private List<DeviceValidListener> deviceValidListeners;
private final LifecycleConductor conductor;
this.conductor = lifecycleConductor;
spyPool = new ScheduledThreadPoolExecutor(1);
+ this.deviceSynchronizedListeners = new ArrayList<>();
+ this.deviceValidListeners = new ArrayList<>();
}
connectionAdapter.registerOutboundQueueHandler(outboundQueueProvider, barrierCountLimit, barrierIntervalNanos);
connectionContext.setOutboundQueueHandleRegistration(outboundQueueHandlerRegistration);
- final DeviceState deviceState = new DeviceStateImpl();
+ final DeviceState deviceState = new DeviceStateImpl(deviceInfo);
+ this.registerDeviceSynchronizeListeners(deviceState);
+ this.registerDeviceValidListeners(deviceState);
+
final DeviceContext deviceContext = new DeviceContextImpl(connectionContext,
deviceState,
dataBroker,
final OpenflowProtocolListenerFullImpl messageListener = new OpenflowProtocolListenerFullImpl(
connectionAdapter, deviceContext);
connectionAdapter.setMessageListener(messageListener);
- deviceState.setValid(true);
+ notifyDeviceValidListeners(deviceInfo, true);
deviceInitPhaseHandler.onDeviceContextLevelUp(connectionContext.getDeviceInfo());
+ notifyDeviceSynchronizeListeners(deviceInfo, true);
+
return true;
}
for (final Iterator<DeviceContext> iterator = Iterators.consumingIterator(deviceContexts.values().iterator());
iterator.hasNext();) {
final DeviceContext deviceCtx = iterator.next();
+ notifyDeviceValidListeners(deviceCtx.getDeviceInfo(), false);
deviceCtx.shutdownConnection();
deviceCtx.shuttingDownDataStoreTransactions();
}
/* Connection is not PrimaryConnection so try to remove from Auxiliary Connections */
deviceCtx.removeAuxiliaryConnectionContext(connectionContext);
} else {
+ notifyDeviceValidListeners(deviceInfo, false);
/* Device is disconnected and so we need to close TxManager */
final ListenableFuture<Void> future = deviceCtx.shuttingDownDataStoreTransactions();
Futures.addCallback(future, new FutureCallback<Void>() {
return ((DeviceContextImpl)deviceContext).getTransactionChainManager().deactivateTransactionManager();
}
+ @Override
+ public void registerDeviceSynchronizeListeners(final DeviceSynchronizeListener deviceSynchronizeListener) {
+ this.deviceSynchronizedListeners.add(deviceSynchronizeListener);
+ }
+
+ @Override
+ public void notifyDeviceSynchronizeListeners(final DeviceInfo deviceInfo, final boolean deviceSynchronized) {
+ for (DeviceSynchronizeListener listener : deviceSynchronizedListeners) {
+ listener.deviceIsSynchronized(deviceInfo, deviceSynchronized);
+ }
+ }
+
+ @Override
+ public void registerDeviceValidListeners(final DeviceValidListener deviceValidListener) {
+ this.deviceValidListeners.add(deviceValidListener);
+ }
+
+ @Override
+ public void notifyDeviceValidListeners(final DeviceInfo deviceInfo, final boolean deviceValid) {
+ for (DeviceValidListener listener : deviceValidListeners) {
+ listener.deviceIsValid(deviceInfo, deviceValid);
+ }
+ }
+
private ListenableFuture<Void> onDeviceTakeClusterLeadership(final DeviceInfo deviceInfo) {
LOG.trace("onDeviceTakeClusterLeadership for node: {}", deviceInfo.getNodeId());
/* validation */
}
DeviceContext deviceContext = conductor.getDeviceContext(deviceInfo);
/* Prepare init info collecting */
- deviceContext.getDeviceState().setDeviceSynchronized(false);
+ notifyDeviceSynchronizeListeners(deviceInfo, false);
((DeviceContextImpl)deviceContext).getTransactionChainManager().activateTransactionManager();
/* Init Collecting NodeInfo */
final ListenableFuture<Void> initCollectingDeviceInfo = DeviceInitializationUtils.initializeNodeInformation(
throw new IllegalStateException(errMsg);
}
LOG.debug("Get Initial Device {} information is successful", deviceInfo.getNodeId());
- deviceContext.getDeviceState().setDeviceSynchronized(true);
+ notifyDeviceSynchronizeListeners(deviceInfo, true);
((DeviceContextImpl)deviceContext).getTransactionChainManager().initialSubmitWriteTransaction();
deviceContext.getDeviceState().setStatisticsPollingEnabledProp(true);
return null;
package org.opendaylight.openflowplugin.impl.device;
-import com.google.common.base.Preconditions;
-import javax.annotation.CheckForNull;
-import javax.annotation.Nonnull;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
-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.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.openflow.protocol.rev130731.GetFeaturesOutput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutputBuilder;
-import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
/**
* openflowplugin-impl
*/
class DeviceStateImpl implements DeviceState {
+ private final DeviceInfo deviceInfo;
private boolean valid;
private boolean meterIsAvailable;
private boolean groupIsAvailable;
private boolean statPollEnabled;
private boolean queueStatisticsAvailable;
- DeviceStateImpl() {
+ public DeviceStateImpl(final DeviceInfo deviceInfo) {
+ this.deviceInfo = deviceInfo;
statPollEnabled = false;
deviceSynchronized = false;
}
return valid;
}
- @Override
- public void setValid(final boolean valid) {
- this.valid = valid;
- }
-
@Override
public boolean isMetersAvailable() {
return meterIsAvailable;
}
- @Override
- public void setDeviceSynchronized(final boolean _deviceSynchronized) {
- deviceSynchronized = _deviceSynchronized;
- }
-
@Override
public boolean isStatisticsPollingEnabled() {
return statPollEnabled;
public void setStatisticsPollingEnabledProp(final boolean statPollEnabled) {
this.statPollEnabled = statPollEnabled;
}
+
+ @Override
+ public void deviceIsSynchronized(final DeviceInfo deviceInfo, final boolean isSynchronized) {
+ if (this.deviceInfo.equals(deviceInfo)) {
+ this.deviceSynchronized = isSynchronized;
+ }
+ }
+
+ @Override
+ public void deviceIsValid(final DeviceInfo deviceInfo, final boolean isValid) {
+ if (this.deviceInfo.equals(deviceInfo)) {
+ this.valid = isValid;
+ }
+ }
}
@Override
protected final FutureCallback<OfHeader> createCallback(final RequestContext<List<MultipartReply>> context, final Class<?> requestType) {
return new MultipartRequestOnTheFlyCallback(context, requestType,
- getDeviceContext().getMessageSpy(), getEventIdentifier(), getDeviceContext().getDeviceInfo(),
- getDeviceContext().getDeviceFlowRegistry(), getDeviceContext(), getDeviceContext().getDeviceState());
+ getMessageSpy(), getEventIdentifier(), getDeviceInfo(),
+ getDeviceContext().getDeviceFlowRegistry(), getTxFacade());
}
private boolean finished = false;
private final EventIdentifier doneEventIdentifier;
private final TxFacade txFacade;
- private final DeviceState deviceState;
public MultipartRequestOnTheFlyCallback(final RequestContext<List<MultipartReply>> context,
final EventIdentifier eventIdentifier,
final DeviceInfo deviceInfo,
final DeviceFlowRegistry registry,
- final TxFacade txFacade,
- final DeviceState deviceState) {
+ final TxFacade txFacade) {
super(context, requestType, messageSpy, eventIdentifier);
this.deviceInfo = deviceInfo;
this.registry = registry;
this.txFacade = txFacade;
- this.deviceState = deviceState;
//TODO: this is focused on flow stats only - need more general approach if used for more than flow stats
doneEventIdentifier = new EventIdentifier(MultipartType.OFPMPFLOW.name(), deviceInfo.getNodeId().toString());
//TODO: following part is focused on flow stats only - need more general approach if used for more than flow stats
ListenableFuture<Void> future;
if (virgin) {
- future = StatisticsGatheringUtils.deleteAllKnownFlows(deviceInfo, registry, txFacade, deviceState);
+ future = StatisticsGatheringUtils.deleteAllKnownFlows(deviceInfo, registry, txFacade);
virgin = false;
} else {
future = Futures.immediateFuture(null);
}
}
+
+ @Override
+ public ListenableFuture<Boolean> initialGatherDynamicData() {
+ return gatherDynamicData(true);
+ }
+
@Override
- public ListenableFuture<Boolean> gatherDynamicData() {
+ public ListenableFuture<Boolean> gatherDynamicData(){
+ return gatherDynamicData(false);
+ }
+
+ private ListenableFuture<Boolean> gatherDynamicData(final boolean initial) {
if (shuttingDownStatisticsPolling) {
LOG.debug("Statistics for device {} is not enabled.", deviceContext.getDeviceInfo().getNodeId());
return Futures.immediateFuture(Boolean.TRUE);
// write start timestamp to state snapshot container
StatisticsGatheringUtils.markDeviceStateSnapshotStart(deviceContext);
- statChainFuture(statIterator, settableStatResultFuture);
+ statChainFuture(statIterator, settableStatResultFuture, initial);
// write end timestamp to state snapshot container
Futures.addCallback(settableStatResultFuture, new FutureCallback<Boolean>() {
}
}
- private ListenableFuture<Boolean> chooseStat(final MultipartType multipartType){
+ private ListenableFuture<Boolean> chooseStat(final MultipartType multipartType, final boolean initial){
switch (multipartType) {
case OFPMPFLOW:
- return collectFlowStatistics(multipartType);
+ return collectFlowStatistics(multipartType, initial);
case OFPMPTABLE:
return collectTableStatistics(multipartType);
case OFPMPPORTSTATS:
return Optional.ofNullable(pollTimeout);
}
- private void statChainFuture(final Iterator<MultipartType> iterator, final SettableFuture<Boolean> resultFuture) {
+ private void statChainFuture(final Iterator<MultipartType> iterator, final SettableFuture<Boolean> resultFuture, final boolean initial) {
if (ConnectionContext.CONNECTION_STATE.RIP.equals(deviceContext.getPrimaryConnectionContext().getConnectionState())) {
final String errMsg = String.format("Device connection is closed for Node : %s.",
deviceContext.getDeviceInfo().getNodeId());
final MultipartType nextType = iterator.next();
LOG.debug("Stats iterating to next type for node {} of type {}", deviceContext.getDeviceInfo().getNodeId(), nextType);
- final ListenableFuture<Boolean> deviceStatisticsCollectionFuture = chooseStat(nextType);
+ final ListenableFuture<Boolean> deviceStatisticsCollectionFuture = chooseStat(nextType, initial);
Futures.addCallback(deviceStatisticsCollectionFuture, new FutureCallback<Boolean>() {
@Override
public void onSuccess(final Boolean result) {
- statChainFuture(iterator, resultFuture);
+ statChainFuture(iterator, resultFuture, initial);
}
@Override
public void onFailure(@Nonnull final Throwable t) {
@VisibleForTesting
ListenableFuture<Boolean> deviceConnectionCheck() {
if (!ConnectionContext.CONNECTION_STATE.WORKING.equals(deviceContext.getPrimaryConnectionContext().getConnectionState())) {
- ListenableFuture<Boolean> resultingFuture = SettableFuture.create();
+ ListenableFuture<Boolean> resultingFuture;
switch (deviceContext.getPrimaryConnectionContext().getConnectionState()) {
case RIP:
final String errMsg = String.format("Device connection doesn't exist anymore. Primary connection status : %s",
}
//TODO: Refactor twice sending deviceContext into gatheringStatistics
- private ListenableFuture<Boolean> collectFlowStatistics(final MultipartType multipartType) {
+ private ListenableFuture<Boolean> collectFlowStatistics(final MultipartType multipartType, final boolean initial) {
return devState.isFlowStatisticsAvailable() ? StatisticsGatheringUtils.gatherStatistics(
statisticsGatheringOnTheFlyService,
deviceContext.getDeviceInfo(),
/*MultipartType.OFPMPFLOW*/ multipartType,
deviceContext,
deviceContext,
- devState) : emptyFuture;
+ initial) : emptyFuture;
}
private ListenableFuture<Boolean> collectTableStatistics(final MultipartType multipartType) {
/*MultipartType.OFPMPTABLE*/ multipartType,
deviceContext,
deviceContext,
- devState) : emptyFuture;
+ false) : emptyFuture;
}
private ListenableFuture<Boolean> collectPortStatistics(final MultipartType multipartType) {
/*MultipartType.OFPMPPORTSTATS*/ multipartType,
deviceContext,
deviceContext,
- devState) : emptyFuture;
+ false) : emptyFuture;
}
private ListenableFuture<Boolean> collectQueueStatistics(final MultipartType multipartType) {
/*MultipartType.OFPMPQUEUE*/ multipartType,
deviceContext,
deviceContext,
- devState);
+ false);
}
private ListenableFuture<Boolean> collectGroupDescStatistics(final MultipartType multipartType) {
/*MultipartType.OFPMPGROUPDESC*/ multipartType,
deviceContext,
deviceContext,
- devState) : emptyFuture;
+ false) : emptyFuture;
}
private ListenableFuture<Boolean> collectGroupStatistics(final MultipartType multipartType) {
/*MultipartType.OFPMPGROUP*/ multipartType,
deviceContext,
deviceContext,
- devState) : emptyFuture;
+ false) : emptyFuture;
}
private ListenableFuture<Boolean> collectMeterConfigStatistics(final MultipartType multipartType) {
/*MultipartType.OFPMPMETERCONFIG*/ multipartType,
deviceContext,
deviceContext,
- devState) : emptyFuture;
+ false) : emptyFuture;
}
private ListenableFuture<Boolean> collectMeterStatistics(final MultipartType multipartType) {
/*MultipartType.OFPMPMETER*/ multipartType,
deviceContext,
deviceContext,
- devState) : emptyFuture;
+ false) : emptyFuture;
}
@VisibleForTesting
final MultipartType type,
final TxFacade txFacade,
final DeviceRegistry registry,
- final DeviceState deviceState) {
+ final Boolean initial) {
EventIdentifier wholeProcessEventIdentifier = null;
if (MultipartType.OFPMPFLOW.equals(type)) {
wholeProcessEventIdentifier = new EventIdentifier(type.toString(), deviceInfo.getNodeId().getValue());
final ListenableFuture<RpcResult<List<MultipartReply>>> statisticsDataInFuture =
JdkFutureAdapters.listenInPoolThread(statisticsGatheringService.getStatisticsOfType(
ofpQueuToRequestContextEventIdentifier, type));
- return transformAndStoreStatisticsData(statisticsDataInFuture, deviceInfo, wholeProcessEventIdentifier, type, txFacade, registry, deviceState);
+ return transformAndStoreStatisticsData(statisticsDataInFuture, deviceInfo, wholeProcessEventIdentifier, type, txFacade, registry, initial);
}
private static ListenableFuture<Boolean> transformAndStoreStatisticsData(final ListenableFuture<RpcResult<List<MultipartReply>>> statisticsDataInFuture,
final MultipartType type,
final TxFacade txFacade,
final DeviceRegistry registry,
- final DeviceState deviceState) {
+ final boolean initial) {
return Futures.transform(statisticsDataInFuture, new AsyncFunction<RpcResult<List<MultipartReply>>, Boolean>() {
@Nullable
@Override
} else if (multipartData instanceof FlowsStatisticsUpdate) {
/* FlowStat Processing is realized by NettyThread only by initPhase, otherwise it is realized
* by MD-SAL thread */
- return processFlowStatistics((Iterable<FlowsStatisticsUpdate>) allMultipartData, deviceInfo, txFacade, registry.getDeviceFlowRegistry(), deviceState, eventIdentifier);
+ return processFlowStatistics((Iterable<FlowsStatisticsUpdate>) allMultipartData, deviceInfo, txFacade, registry.getDeviceFlowRegistry(), initial, eventIdentifier);
} else if (multipartData instanceof GroupDescStatsUpdated) {
processGroupDescStats((Iterable<GroupDescStatsUpdated>) allMultipartData, deviceInfo, txFacade, registry.getDeviceGroupRegistry());
final DeviceInfo deviceInfo,
final TxFacade txFacade,
final DeviceFlowRegistry flowRegistry,
- final DeviceState deviceState,
+ final boolean initial,
final EventIdentifier eventIdentifier) {
- final ListenableFuture<Void> deleFuture = deleteAllKnownFlows(deviceInfo,
- flowRegistry, txFacade, deviceState);
- return Futures.transform(deleFuture, new Function<Void, Boolean>() {
+ final ListenableFuture<Void> deleteFuture = initial ? Futures.immediateFuture(null) : deleteAllKnownFlows(deviceInfo,
+ flowRegistry, txFacade);
+ return Futures.transform(deleteFuture, new Function<Void, Boolean>() {
@Override
public Boolean apply(final Void input) {
public static ListenableFuture<Void> deleteAllKnownFlows(final DeviceInfo deviceInfo,
final DeviceFlowRegistry registry,
- final TxFacade txFacade,
- final DeviceState deviceState) {
- //TODO:Make check for phase from enum
- /* DeviceState.deviceSynchronized is a marker for actual phase - false means initPhase, true means noInitPhase */
- if (deviceState.deviceSynchronized()) {
- final InstanceIdentifier<FlowCapableNode> flowCapableNodePath = assembleFlowCapableNodeInstanceIdentifier(deviceInfo);
- final ReadOnlyTransaction readTx = txFacade.getReadTransaction();
- final CheckedFuture<Optional<FlowCapableNode>, ReadFailedException> flowCapableNodeFuture = readTx.read(
- LogicalDatastoreType.OPERATIONAL, flowCapableNodePath);
-
- /* we wish to close readTx for fallBack */
- Futures.withFallback(flowCapableNodeFuture, new FutureFallback<Optional<FlowCapableNode>>() {
-
- @Override
- public ListenableFuture<Optional<FlowCapableNode>> create(final Throwable t) throws Exception {
- readTx.close();
- return Futures.immediateFailedFuture(t);
- }
- });
- /*
- * we have to read actual tables with all information before we set empty Flow list, merge is expensive and
- * not applicable for lists
- */
- return Futures.transform(flowCapableNodeFuture, new AsyncFunction<Optional<FlowCapableNode>, Void>() {
-
- @Override
- public ListenableFuture<Void> apply(final Optional<FlowCapableNode> flowCapNodeOpt) throws Exception {
- if (flowCapNodeOpt.isPresent()) {
- for (final Table tableData : flowCapNodeOpt.get().getTable()) {
- final Table table = new TableBuilder(tableData).setFlow(Collections.<Flow>emptyList()).build();
- final InstanceIdentifier<Table> iiToTable = flowCapableNodePath.child(Table.class, tableData.getKey());
- txFacade.writeToTransaction(LogicalDatastoreType.OPERATIONAL, iiToTable, table);
- }
+ final TxFacade txFacade) {
+ final InstanceIdentifier<FlowCapableNode> flowCapableNodePath = assembleFlowCapableNodeInstanceIdentifier(deviceInfo);
+ final ReadOnlyTransaction readTx = txFacade.getReadTransaction();
+ final CheckedFuture<Optional<FlowCapableNode>, ReadFailedException> flowCapableNodeFuture = readTx.read(
+ LogicalDatastoreType.OPERATIONAL, flowCapableNodePath);
+
+ /* we wish to close readTx for fallBack */
+ Futures.withFallback(flowCapableNodeFuture, new FutureFallback<Optional<FlowCapableNode>>() {
+
+ @Override
+ public ListenableFuture<Optional<FlowCapableNode>> create(final Throwable t) throws Exception {
+ readTx.close();
+ return Futures.immediateFailedFuture(t);
+ }
+ });
+ /*
+ * we have to read actual tables with all information before we set empty Flow list, merge is expensive and
+ * not applicable for lists
+ */
+ return Futures.transform(flowCapableNodeFuture, new AsyncFunction<Optional<FlowCapableNode>, Void>() {
+
+ @Override
+ public ListenableFuture<Void> apply(final Optional<FlowCapableNode> flowCapNodeOpt) throws Exception {
+ if (flowCapNodeOpt.isPresent()) {
+ for (final Table tableData : flowCapNodeOpt.get().getTable()) {
+ final Table table = new TableBuilder(tableData).setFlow(Collections.<Flow>emptyList()).build();
+ final InstanceIdentifier<Table> iiToTable = flowCapableNodePath.child(Table.class, tableData.getKey());
+ txFacade.writeToTransaction(LogicalDatastoreType.OPERATIONAL, iiToTable, table);
}
- registry.removeMarked();
- readTx.close();
- return Futures.immediateFuture(null);
}
+ registry.removeMarked();
+ readTx.close();
+ return Futures.immediateFuture(null);
+ }
- });
- }
- return Futures.immediateFuture(null);
+ });
}
private static void processQueueStatistics(final Iterable<QueueStatisticsUpdate> data, final DeviceInfo deviceInfo, final TxFacade txFacade) throws Exception {
final StatisticsContext statisticsContext = new StatisticsContextImpl(deviceInfo, shuttingDownStatisticsPolling, conductor);
Verify.verify(contexts.putIfAbsent(deviceInfo, statisticsContext) == null, "StatisticsCtx still not closed for Node {}", deviceInfo.getNodeId());
- deviceContext.getDeviceState().setDeviceSynchronized(true);
deviceInitPhaseHandler.onDeviceContextLevelUp(deviceInfo);
}
final TranslatorKey translatorKey = new TranslatorKey(ofVersion, PortGrouping.class.getName());
final MessageTranslator<PortGrouping, FlowCapableNodeConnector> translator = deviceContext.oook()
.lookupTranslator(translatorKey);
- final BigInteger dataPathId = deviceContext.getPrimaryConnectionContext().getFeatures().getDatapathId();
+ final BigInteger dataPathId = deviceContext.getDeviceInfo().getDatapathId();
for (final PortGrouping port : connectionContext.getFeatures().getPhyPort()) {
final FlowCapableNodeConnector fcNodeConnector = translator.translate(port, deviceContext.getDeviceInfo(), null);
package org.opendaylight.openflowplugin.impl.device;
-import java.util.Arrays;
-import java.util.List;
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.runners.MockitoJUnitRunner;
-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.openflow.protocol.rev130731.GetFeaturesOutputBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.features.reply.PhyPort;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.features.reply.PhyPortBuilder;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
/**
* openflowplugin-impl
@RunWith(MockitoJUnitRunner.class)
public class DeviceStateImplTest {
+ @Mock
+ private DeviceInfo deviceInfo;
+
private DeviceStateImpl deviceState;
@Before
public void initialization() {
- deviceState = new DeviceStateImpl();
+ deviceState = new DeviceStateImpl(deviceInfo);
}
@Test
};
multipartRequestOnTheFlyCallback = new MultipartRequestOnTheFlyCallback(dummyRequestContext, String.class,
mockedDeviceContext.getMessageSpy(),dummyEventIdentifier, mockedDeviceInfo,
- mockedDeviceContext.getDeviceFlowRegistry(), mockedDeviceContext, mockedDeviceState);
+ mockedDeviceContext.getDeviceFlowRegistry(), mockedDeviceContext);
}
type,
txFacade,
deviceContext,
- deviceState);
+ false);
Assert.assertTrue(gatherStatisticsResult.get(1, TimeUnit.SECONDS).booleanValue());
verify(txFacade).submitTransaction();
}
return new BucketStatsBuilder().setByteCount(BigInteger.valueOf(byteCount)).setPacketCount(BigInteger.valueOf(packetCount)).build();
}
- @Test
- public void testDeleteAllKnownFlowsNotSync() throws Exception {
- when(deviceState.deviceSynchronized()).thenReturn(false);
- StatisticsGatheringUtils.deleteAllKnownFlows(deviceInfo,
- deviceContext.getDeviceFlowRegistry(), deviceContext, deviceState);
- Mockito.verifyNoMoreInteractions(deviceFlowRegistry);
- }
-
@Test
public void testDeleteAllKnownFlows() throws Exception {
final short tableId = 0;
.augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tableId));
StatisticsGatheringUtils.deleteAllKnownFlows(deviceInfo,
- deviceContext.getDeviceFlowRegistry(), txFacade, deviceState);
+ deviceContext.getDeviceFlowRegistry(), txFacade);
verify(txFacade).writeToTransaction(
LogicalDatastoreType.OPERATIONAL,