import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceivedBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.FlowCapableNodeConnectorStatisticsData;
import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.FlowCapableNodeConnectorStatisticsDataBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SalRoleService;
import org.opendaylight.yangtools.yang.binding.DataContainer;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
private final ItemLifeCycleKeeper flowLifeCycleKeeper;
private final MessageTranslator<PortGrouping, FlowCapableNodeConnector> portStatusTranslator;
private final MessageTranslator<PacketInMessage, PacketReceived> packetInTranslator;
- private final MessageTranslator<FlowRemoved, org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemoved> flowRemovedTranslator;
+ private final MessageTranslator<FlowRemoved, org.opendaylight.yang.gen.v1.urn.opendaylight
+ .flow.service.rev130819.FlowRemoved> flowRemovedTranslator;
private final TranslatorLibrary translatorLibrary;
private final ItemLifeCycleRegistry itemLifeCycleSourceRegistry;
private final ConvertorExecutor convertorExecutor;
private DeviceGroupRegistry deviceGroupRegistry;
private DeviceMeterRegistry deviceMeterRegistry;
private ExtensionConverterProvider extensionConverterProvider;
- private SalRoleService salRoleService;
private ContextChainMastershipWatcher contextChainMastershipWatcher;
DeviceContextImpl(@Nonnull final ConnectionContext primaryConnectionContext,
this.portStatusTranslator = translatorLibrary.lookupTranslator(
new TranslatorKey(deviceInfo.getVersion(), PortGrouping.class.getName()));
this.packetInTranslator = translatorLibrary.lookupTranslator(
- new TranslatorKey(deviceInfo.getVersion(), org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
+ new TranslatorKey(deviceInfo.getVersion(), org.opendaylight.yang.gen.v1.urn.opendaylight.openflow
+ .protocol.rev130731
.PacketIn.class.getName()));
this.flowRemovedTranslator = translatorLibrary.lookupTranslator(
new TranslatorKey(deviceInfo.getVersion(), FlowRemoved.class.getName()));
@Override
public <T extends DataObject> void writeToTransaction(final LogicalDatastoreType store,
final InstanceIdentifier<T> path,
- final T data){
+ final T data) {
if (initialized.get()) {
transactionChainManager.writeToTransaction(store, path, data, false);
}
@Override
public <T extends DataObject> void writeToTransactionWithParentsSlow(final LogicalDatastoreType store,
final InstanceIdentifier<T> path,
- final T data){
+ final T data) {
if (initialized.get()) {
transactionChainManager.writeToTransaction(store, path, data, true);
}
}
@Override
- public <T extends DataObject> void addDeleteToTxChain(final LogicalDatastoreType store, final InstanceIdentifier<T> path) {
+ public <T extends DataObject> void addDeleteToTxChain(final LogicalDatastoreType store,
+ final InstanceIdentifier<T> path) {
if (initialized.get()) {
transactionChainManager.addDeleteOperationTotTxChain(store, path);
}
final ItemLifecycleListener itemLifecycleListener = flowLifeCycleKeeper.getItemLifecycleListener();
if (itemLifecycleListener != null) {
//2. create registry key
- final FlowRegistryKey flowRegKey = FlowRegistryKeyFactory.create(getDeviceInfo().getVersion(), flowRemovedNotification);
+ final FlowRegistryKey flowRegKey = FlowRegistryKeyFactory.create(getDeviceInfo().getVersion(),
+ flowRemovedNotification);
//3. lookup flowId
final FlowDescriptor flowDescriptor = deviceFlowRegistry.retrieveDescriptor(flowRegKey);
//4. if flowId present:
}
@Override
+ @SuppressWarnings("checkstyle:IllegalCatch")
public void processPortStatusMessage(final PortStatusMessage portStatus) {
- messageSpy.spyMessage(portStatus.getImplementedInterface(), MessageSpy.StatisticsGroup.FROM_SWITCH_PUBLISHED_SUCCESS);
+ messageSpy.spyMessage(portStatus.getImplementedInterface(), MessageSpy.StatisticsGroup
+ .FROM_SWITCH_PUBLISHED_SUCCESS);
if (initialized.get()) {
try {
portStatusMessage.getPortNo(),
OpenflowVersion.get(deviceInfo.getVersion()))));
- if (PortReason.OFPPRADD.equals(portStatusMessage.getReason()) || PortReason.OFPPRMODIFY.equals(portStatusMessage.getReason())) {
+ if (PortReason.OFPPRADD.equals(portStatusMessage.getReason())
+ || PortReason.OFPPRMODIFY.equals(portStatusMessage.getReason())) {
// because of ADD status node connector has to be created
writeToTransaction(LogicalDatastoreType.OPERATIONAL, iiToNodeConnector, new NodeConnectorBuilder()
.setKey(iiToNodeConnector.getKey())
- .addAugmentation(FlowCapableNodeConnectorStatisticsData.class, new FlowCapableNodeConnectorStatisticsDataBuilder().build())
+ .addAugmentation(FlowCapableNodeConnectorStatisticsData.class, new
+ FlowCapableNodeConnectorStatisticsDataBuilder().build())
.addAugmentation(FlowCapableNodeConnector.class, flowCapableNodeConnector)
.build());
} else if (PortReason.OFPPRDELETE.equals(portStatusMessage.getReason())) {
if (!packetInLimiter.acquirePermit()) {
LOG.debug("Packet limited");
// TODO: save packet into emergency slot if possible
- messageSpy.spyMessage(implementedInterface, MessageSpy.StatisticsGroup.FROM_SWITCH_PACKET_IN_LIMIT_REACHED_AND_DROPPED);
+ messageSpy.spyMessage(implementedInterface, MessageSpy.StatisticsGroup
+ .FROM_SWITCH_PACKET_IN_LIMIT_REACHED_AND_DROPPED);
return;
}
}
@Override
- public void onFailure(final Throwable t) {
- messageSpy.spyMessage(implementedInterface, MessageSpy.StatisticsGroup.FROM_SWITCH_NOTIFICATION_REJECTED);
- LOG.debug("notification offer failed: {}", t.getMessage());
- LOG.trace("notification offer failed..", t);
+ public void onFailure(final Throwable throwable) {
+ messageSpy.spyMessage(implementedInterface, MessageSpy.StatisticsGroup
+ .FROM_SWITCH_NOTIFICATION_REJECTED);
+ LOG.debug("notification offer failed: {}", throwable.getMessage());
+ LOG.trace("notification offer failed..", throwable);
packetInLimiter.releasePermit();
}
});
final MessageTypeKey<? extends ExperimenterDataOfChoice> key = new MessageTypeKey<>(
getDeviceInfo().getVersion(),
(Class<? extends ExperimenterDataOfChoice>) vendorData.getImplementedInterface());
- final ConvertorMessageFromOFJava<ExperimenterDataOfChoice, MessagePath> messageConverter = extensionConverterProvider.getMessageConverter(key);
+ final ConvertorMessageFromOFJava<ExperimenterDataOfChoice, MessagePath> messageConverter =
+ extensionConverterProvider.getMessageConverter(key);
if (messageConverter == null) {
LOG.warn("custom converter for {}[OF:{}] not found",
notification.getExperimenterDataOfChoice().getImplementedInterface(),
final ExperimenterMessageOfChoice messageOfChoice;
try {
messageOfChoice = messageConverter.convert(vendorData, MessagePath.MESSAGE_NOTIFICATION);
- final ExperimenterMessageFromDevBuilder experimenterMessageFromDevBld = new ExperimenterMessageFromDevBuilder()
+ final ExperimenterMessageFromDevBuilder experimenterMessageFromDevBld = new
+ ExperimenterMessageFromDevBuilder()
.setNode(new NodeRef(getDeviceInfo().getNodeInstanceIdentifier()))
.setExperimenterMessageOfChoice(messageOfChoice);
// publish
}
@Override
- public <T extends OfHeader> MultiMsgCollector<T> getMultiMsgCollector(final RequestContext<List<T>> requestContext) {
+ public <T extends OfHeader> MultiMsgCollector<T> getMultiMsgCollector(final RequestContext<List<T>>
+ requestContext) {
return new MultiMsgCollectorImpl<>(this, requestContext);
}
@Override
public void updatePacketInRateLimit(final long upperBound) {
- packetInLimiter.changeWaterMarks((int) (LOW_WATERMARK_FACTOR * upperBound), (int) (HIGH_WATERMARK_FACTOR * upperBound));
+ packetInLimiter.changeWaterMarks((int) (LOW_WATERMARK_FACTOR * upperBound),
+ (int) (HIGH_WATERMARK_FACTOR * upperBound));
}
@Override
? transactionChainManager.deactivateTransactionManager()
: Futures.immediateFuture(null);
- hashedWheelTimer.newTimeout((t) -> {
+ hashedWheelTimer.newTimeout((timerTask) -> {
if (!listenableFuture.isDone() && !listenableFuture.isCancelled()) {
listenableFuture.cancel(true);
}
}
@Override
- public void onFailure(final Throwable t) {
+ public void onFailure(final Throwable throwable) {
transactionChainManager.close();
transactionChainManager = null;
}
}
@Override
+ @SuppressWarnings("checkstyle:IllegalCatch")
public void instantiateServiceInstance() {
lazyTransactionManagerInitialization();
deviceInfo.toString()));
}
- final ListenableFuture<List<com.google.common.base.Optional<FlowCapableNode>>> deviceFlowRegistryFill = getDeviceFlowRegistry().fill();
+ final ListenableFuture<List<com.google.common.base.Optional<FlowCapableNode>>> deviceFlowRegistryFill =
+ getDeviceFlowRegistry().fill();
Futures.addCallback(deviceFlowRegistryFill,
new DeviceFlowRegistryCallback(deviceFlowRegistryFill, contextChainMastershipWatcher));
}
LOG.debug("Transaction chain manager for node {} created", deviceInfo.getLOGValue());
}
this.transactionChainManager = new TransactionChainManager(dataBroker, deviceInfo);
- this.deviceFlowRegistry = new DeviceFlowRegistryImpl(deviceInfo.getVersion(), dataBroker, deviceInfo.getNodeInstanceIdentifier());
+ this.deviceFlowRegistry = new DeviceFlowRegistryImpl(deviceInfo.getVersion(), dataBroker, deviceInfo
+ .getNodeInstanceIdentifier());
this.deviceGroupRegistry = new DeviceGroupRegistryImpl();
this.deviceMeterRegistry = new DeviceMeterRegistryImpl();
}
hasState.set(true);
}
- private class DeviceFlowRegistryCallback implements FutureCallback<List<com.google.common.base.Optional<FlowCapableNode>>> {
+ private class DeviceFlowRegistryCallback implements FutureCallback<List<com.google.common.base
+ .Optional<FlowCapableNode>>> {
private final ListenableFuture<List<com.google.common.base.Optional<FlowCapableNode>>> deviceFlowRegistryFill;
private final ContextChainMastershipWatcher contextChainMastershipWatcher;
.filter(Objects::nonNull)
.count();
- LOG.debug("Finished filling flow registry with {} flows for node: {}", flowCount, deviceInfo.getLOGValue());
+ LOG.debug("Finished filling flow registry with {} flows for node: {}", flowCount, deviceInfo
+ .getLOGValue());
}
- this.contextChainMastershipWatcher.onMasterRoleAcquired(deviceInfo, ContextChainMastershipState.INITIAL_FLOW_REGISTRY_FILL);
+ this.contextChainMastershipWatcher.onMasterRoleAcquired(deviceInfo, ContextChainMastershipState
+ .INITIAL_FLOW_REGISTRY_FILL);
}
@Override
- public void onFailure(Throwable t) {
+ public void onFailure(Throwable throwable) {
if (deviceFlowRegistryFill.isCancelled()) {
if (LOG.isDebugEnabled()) {
LOG.debug("Cancelled filling flow registry with flows for node: {}", deviceInfo.getLOGValue());
}
} else {
- LOG.warn("Failed filling flow registry with flows for node: {} with exception: {}", deviceInfo.getLOGValue(), t);
+ LOG.warn("Failed filling flow registry with flows for node: {} with exception: {}", deviceInfo
+ .getLOGValue(), throwable);
}
contextChainMastershipWatcher.onNotAbleToStartMastership(
deviceInfo,
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-/**
- *
- */
public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProviderKeeper {
private static final Logger LOG = LoggerFactory.getLogger(DeviceManagerImpl.class);
package org.opendaylight.openflowplugin.impl.device;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
/**
- * Holder for device features
+ * Holder for device features.
*/
class DeviceStateImpl implements DeviceState {
import org.opendaylight.yangtools.concepts.Registration;
/**
- * default implementation
+ * Default implementation.
*/
public class ItemLifeCycleRegistryImpl implements ItemLifeCycleRegistry {
private final ConnectionAdapter connectionAdapter;
private final MessageSpy messageSpy;
- PacketInRateLimiter(final ConnectionAdapter connectionAdapter, final int lowWatermark, final int highWatermark, final MessageSpy messageSpy, float rejectedDrainFactor) {
+ PacketInRateLimiter(final ConnectionAdapter connectionAdapter,
+ final int lowWatermark,
+ final int highWatermark,
+ final MessageSpy messageSpy,
+ float rejectedDrainFactor) {
super(lowWatermark, highWatermark);
Preconditions.checkArgument(rejectedDrainFactor > 0 && rejectedDrainFactor < 1);
this.rejectedDrainFactor = rejectedDrainFactor;
}
protected abstract void disableFlow();
+
protected abstract void enableFlow();
boolean acquirePermit() {
import org.slf4j.LoggerFactory;
/**
- * openflowplugin-impl
- * org.opendaylight.openflowplugin.impl.device
- * <p/>
- * Package protected class for controlling {@link WriteTransaction} life cycle. It is
+ * The openflowplugin-impl.org.opendaylight.openflowplugin.impl.device
+ * package protected class for controlling {@link WriteTransaction} life cycle. It is
* a {@link TransactionChainListener} and provide package protected methods for writeToTransaction
* method (wrapped {@link WriteTransaction#put(LogicalDatastoreType, InstanceIdentifier, DataObject)})
- * and submitTransaction method (wrapped {@link WriteTransaction#submit()})
+ * and submitTransaction method (wrapped {@link WriteTransaction#submit()}).
*/
class TransactionChainManager implements TransactionChainListener, AutoCloseable {
private final String nodeId;
@GuardedBy("txLock")
- private WriteTransaction wTx;
+ private WriteTransaction writeTx;
@GuardedBy("txLock")
private BindingTransactionChain txChainFactory;
@GuardedBy("txLock")
if (TransactionChainManagerStatus.SLEEPING == transactionChainManagerStatus) {
Preconditions.checkState(txChainFactory == null,
"TxChainFactory survive last close.");
- Preconditions.checkState(wTx == null,
+ Preconditions.checkState(writeTx == null,
"We have some unexpected WriteTransaction.");
this.transactionChainManagerStatus = TransactionChainManagerStatus.WORKING;
this.submitIsEnabled = false;
if (TransactionChainManagerStatus.WORKING == transactionChainManagerStatus) {
transactionChainManagerStatus = TransactionChainManagerStatus.SLEEPING;
future = txChainShuttingDown();
- Preconditions.checkState(wTx == null,
+ Preconditions.checkState(writeTx == null,
"We have some unexpected WriteTransaction.");
Futures.addCallback(future, new FutureCallback<Void>() {
@Override
}
@Override
- public void onFailure(final Throwable t) {
+ public void onFailure(final Throwable throwable) {
removeTxChainFactory();
}
});
}
return false;
}
- if (Objects.isNull(wTx)) {
+ if (Objects.isNull(writeTx)) {
if (LOG.isTraceEnabled()) {
LOG.trace("nothing to commit - submit returns true");
}
Preconditions.checkState(TransactionChainManagerStatus.WORKING == transactionChainManagerStatus,
"we have here Uncompleted Transaction for node {} and we are not MASTER",
this.nodeId);
- final ListenableFuture<Void> submitFuture = wTx.submit();
+ final ListenableFuture<Void> submitFuture = writeTx.submit();
lastSubmittedFuture = submitFuture;
- wTx = null;
+ writeTx = null;
if (initCommit) {
try {
}
@Override
- public void onFailure(final Throwable t) {
- if (t instanceof TransactionCommitFailedException) {
- LOG.error("Transaction commit failed. ", t);
+ public void onFailure(final Throwable throwable) {
+ if (throwable instanceof TransactionCommitFailedException) {
+ LOG.error("Transaction commit failed. ", throwable);
} else {
- if (t instanceof CancellationException) {
+ if (throwable instanceof CancellationException) {
LOG.warn("Submit task was canceled");
- LOG.trace("Submit exception: ", t);
+ LOG.trace("Submit exception: ", throwable);
} else {
- LOG.error("Exception during transaction submitting. ", t);
+ LOG.error("Exception during transaction submitting. ", throwable);
}
}
}
}
<T extends DataObject> void addDeleteOperationTotTxChain(final LogicalDatastoreType store,
- final InstanceIdentifier<T> path){
+ final InstanceIdentifier<T> path) {
synchronized (txLock) {
ensureTransaction();
- if (wTx == null) {
+ if (writeTx == null) {
LOG.debug("WriteTx is null for node {}. Delete {} was not realized.", this.nodeId, path);
throw new TransactionChainClosedException(CANNOT_WRITE_INTO_TRANSACTION);
}
- wTx.delete(store, path);
+ writeTx.delete(store, path);
}
}
<T extends DataObject> void writeToTransaction(final LogicalDatastoreType store,
final InstanceIdentifier<T> path,
final T data,
- final boolean createParents){
+ final boolean createParents) {
synchronized (txLock) {
ensureTransaction();
- if (wTx == null) {
+ if (writeTx == null) {
LOG.debug("WriteTx is null for node {}. Write data for {} was not realized.", this.nodeId, path);
throw new TransactionChainClosedException(CANNOT_WRITE_INTO_TRANSACTION);
}
- wTx.put(store, path, data, createParents);
+ writeTx.put(store, path, data, createParents);
}
}
if (TransactionChainManagerStatus.WORKING == transactionChainManagerStatus) {
LOG.warn("Transaction chain failed, recreating chain due to ", cause);
createTxChain();
- wTx = null;
+ writeTx = null;
}
}
}
@GuardedBy("txLock")
private void ensureTransaction() {
- if (wTx == null && TransactionChainManagerStatus.WORKING == transactionChainManagerStatus
- && txChainFactory != null) {
- wTx = txChainFactory.newWriteOnlyTransaction();
+ if (writeTx == null && TransactionChainManagerStatus.WORKING == transactionChainManagerStatus
+ && txChainFactory != null) {
+ writeTx = txChainFactory.newWriteOnlyTransaction();
}
}
// stay with actual thread
future = Futures.immediateCheckedFuture(null);
- if (wTx != null) {
- wTx.cancel();
- wTx = null;
+ if (writeTx != null) {
+ writeTx.cancel();
+ writeTx = null;
}
- } else if (wTx == null) {
+ } else if (writeTx == null) {
// hijack md-sal thread
future = lastSubmittedFuture;
} else {
LOG.debug("Submitting all transactions for Node {}", this.nodeId);
}
// hijack md-sal thread
- future = wTx.submit();
- wTx = null;
+ future = writeTx.submit();
+ writeTx = null;
}
return future;
}
private enum TransactionChainManagerStatus {
- /** txChainManager is sleeping - is not active (SLAVE or default init value) */
+ /**
+ * txChainManager is working - is active (MASTER).
+ */
WORKING,
- /** txChainManager is working - is active (MASTER) */
+ /**
+ * txChainManager is sleeping - is not active (SLAVE or default init value).
+ */
SLEEPING,
- /** txChainManager is trying to be closed - device disconnecting */
+ /**
+ * txChainManager is trying to be closed - device disconnecting.
+ */
SHUTTING_DOWN;
}
}
private static final Logger LOG = LoggerFactory.getLogger(AbstractDeviceInitializer.class);
/**
- * Perform initial information gathering and store them to operational datastore
+ * Perform initial information gathering and store them to operational datastore.
+ *
* @param deviceContext device context
* @param switchFeaturesMandatory is switch features mandatory
* @param skipTableFeatures skip collecting of table features
* @param multipartWriterProvider multipart writer provider
* @param convertorExecutor convertor executor
*/
+ @SuppressWarnings("checkstyle:IllegalCatch")
public Future<Void> initialize(@Nonnull final DeviceContext deviceContext,
final boolean switchFeaturesMandatory,
final boolean skipTableFeatures,
multipartWriterProvider, convertorExecutor);
}
- protected abstract Future<Void> initializeNodeInformation(@Nonnull final DeviceContext deviceContext,
- final boolean switchFeaturesMandatory,
- final boolean skipTableFeatures,
- @Nullable final MultipartWriterProvider multipartWriterProvider,
- @Nullable final ConvertorExecutor convertorExecutor);
+ protected abstract Future<Void> initializeNodeInformation(@Nonnull DeviceContext deviceContext,
+ boolean switchFeaturesMandatory,
+ boolean skipTableFeatures,
+ @Nullable MultipartWriterProvider multipartWriterProvider,
+ @Nullable ConvertorExecutor convertorExecutor);
}
import org.opendaylight.openflowplugin.api.OFConstants;
/**
- * Multipart writer provider factory
+ * Multipart writer provider factory.
*/
public class DeviceInitializerProviderFactory {
/**
- * Create default #{@link org.opendaylight.openflowplugin.impl.device.initialization.DeviceInitializerProvider}
+ * Create default #{@link org.opendaylight.openflowplugin.impl.device.initialization.DeviceInitializerProvider}.
* @return the device initialization provider
*/
public static DeviceInitializerProvider createDefaultProvider() {
final boolean skipTableFeatures,
@Nullable final MultipartWriterProvider multipartWriterProvider,
@Nullable final ConvertorExecutor convertorExecutor) {
- final ConnectionContext connectionContext = Preconditions.checkNotNull(deviceContext.getPrimaryConnectionContext());
+ final ConnectionContext connectionContext =
+ Preconditions.checkNotNull(deviceContext.getPrimaryConnectionContext());
final DeviceState deviceState = Preconditions.checkNotNull(deviceContext.getDeviceState());
final DeviceInfo deviceInfo = Preconditions.checkNotNull(deviceContext.getDeviceInfo());
final CapabilitiesV10 capabilitiesV10 = connectionContext.getFeatures().getCapabilitiesV10();
}
@Override
- public void onFailure(@Nonnull final Throwable t) {
+ public void onFailure(@Nonnull final Throwable throwable) {
LOG.warn("Error occurred in preparation node {} for protocol 1.0", deviceInfo);
- LOG.trace("Error for node {} : ", deviceInfo, t);
+ LOG.trace("Error for node {} : ", deviceInfo, throwable);
}
});
});
}
+ @SuppressWarnings("checkstyle:IllegalCatch")
private static void writePhyPortInformation(final DeviceContext deviceContext) {
final DeviceInfo deviceInfo = deviceContext.getDeviceInfo();
final ConnectionContext connectionContext = deviceContext.getPrimaryConnectionContext();
});
}
+ @SuppressWarnings("checkstyle:IllegalCatch")
private static void makeEmptyFlowCapableNode(final TxFacade txFacade, final DeviceInfo deviceInfo) {
try {
txFacade.writeToTransaction(LogicalDatastoreType.OPERATIONAL,
final DeviceContext deviceContext) {
if (deviceContext.canUseSingleLayerSerialization()) {
final SingleLayerMultipartCollectorService service =
- new SingleLayerMultipartCollectorService(deviceContext, deviceContext);
-
- return Futures.transform(service.handleServiceCall(multipartType), new Function<RpcResult<List<MultipartReply>>, Boolean>() {
- @Nonnull
- @Override
- public Boolean apply(final RpcResult<List<MultipartReply>> input) {
- return input.isSuccessful();
- }
- });
+ new SingleLayerMultipartCollectorService(deviceContext, deviceContext);
+
+ return Futures.transform(service.handleServiceCall(multipartType),
+ new Function<RpcResult<List<MultipartReply>>, Boolean>() {
+ @Nonnull
+ @Override
+ public Boolean apply(final RpcResult<List<MultipartReply>> input) {
+ return input.isSuccessful();
+ }
+ });
}
final MultiLayerMultipartCollectorService service =
- new MultiLayerMultipartCollectorService(deviceContext, deviceContext);
-
- return Futures.transform(service.handleServiceCall(multipartType), new Function<RpcResult<List<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply>>, Boolean>() {
- @Nonnull
- @Override
- public Boolean apply(final RpcResult<List<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply>> input) {
- return input.isSuccessful();
- }
- });
+ new MultiLayerMultipartCollectorService(deviceContext, deviceContext);
+
+ return Futures.transform(service.handleServiceCall(multipartType),
+ new Function<RpcResult<List<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol
+ .rev130731.MultipartReply>>, Boolean>() {
+ @Nonnull
+ @Override
+ public Boolean apply(final RpcResult<List<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow
+ .protocol
+ .rev130731.MultipartReply>> input) {
+ return input.isSuccessful();
+ }
+ });
}
}
final boolean skipTableFeatures,
@Nullable final MultipartWriterProvider multipartWriterProvider,
@Nullable final ConvertorExecutor convertorExecutor) {
- final ConnectionContext connectionContext = Preconditions.checkNotNull(deviceContext.getPrimaryConnectionContext());
+ final ConnectionContext connectionContext =
+ Preconditions.checkNotNull(deviceContext.getPrimaryConnectionContext());
final DeviceState deviceState = Preconditions.checkNotNull(deviceContext.getDeviceState());
final DeviceInfo deviceInfo = Preconditions.checkNotNull(deviceContext.getDeviceInfo());
final Capabilities capabilities = connectionContext.getFeatures().getCapabilities();
convertorExecutor);
final List<ListenableFuture<RpcResult<List<OfHeader>>>> futures = new ArrayList<>();
- futures.add(requestAndProcessMultipart(MultipartType.OFPMPMETERFEATURES, deviceContext, skipTableFeatures, multipartWriterProvider, convertorExecutor));
- futures.add(requestAndProcessMultipart(MultipartType.OFPMPGROUPFEATURES, deviceContext, skipTableFeatures, multipartWriterProvider, convertorExecutor));
- futures.add(requestAndProcessMultipart(MultipartType.OFPMPTABLEFEATURES, deviceContext, skipTableFeatures, multipartWriterProvider, convertorExecutor));
- futures.add(requestAndProcessMultipart(MultipartType.OFPMPPORTDESC, deviceContext, skipTableFeatures, multipartWriterProvider, convertorExecutor));
+ futures.add(requestAndProcessMultipart(MultipartType.OFPMPMETERFEATURES, deviceContext,
+ skipTableFeatures, multipartWriterProvider, convertorExecutor));
+ futures.add(requestAndProcessMultipart(MultipartType.OFPMPGROUPFEATURES, deviceContext,
+ skipTableFeatures, multipartWriterProvider, convertorExecutor));
+ futures.add(requestAndProcessMultipart(MultipartType.OFPMPTABLEFEATURES, deviceContext,
+ skipTableFeatures, multipartWriterProvider, convertorExecutor));
+ futures.add(requestAndProcessMultipart(MultipartType.OFPMPPORTDESC, deviceContext, skipTableFeatures,
+ multipartWriterProvider, convertorExecutor));
return Futures.transform(
(switchFeaturesMandatory ? Futures.allAsList(futures) : Futures.successfulAsList(futures)),
@Nullable
@Override
public Void apply(@Nullable final List<RpcResult<List<OfHeader>>> input) {
- LOG.info("Static node {} successfully finished collecting", deviceContext.getDeviceInfo().getLOGValue());
+ LOG.info("Static node {} successfully finished collecting",
+ deviceContext.getDeviceInfo().getLOGValue());
return null;
}
});
}
/**
- * Request multipart of specified type and then run some processing on it
+ * Request multipart of specified type and then run some processing on it.
+ *
* @param type multipart type
* @param deviceContext device context
* @param skipTableFeatures skip collecting of table features
* @return list of multipart messages unified to parent interface
*/
private static ListenableFuture<RpcResult<List<OfHeader>>> requestAndProcessMultipart(final MultipartType type,
- final DeviceContext deviceContext,
- final boolean skipTableFeatures,
- final MultipartWriterProvider multipartWriterProvider,
- @Nullable final ConvertorExecutor convertorExecutor) {
+ final DeviceContext deviceContext,
+ final boolean skipTableFeatures,
+ final MultipartWriterProvider multipartWriterProvider,
+ @Nullable final ConvertorExecutor convertorExecutor) {
final ListenableFuture<RpcResult<List<OfHeader>>> rpcResultListenableFuture =
MultipartType.OFPMPTABLEFEATURES.equals(type) && skipTableFeatures
? RpcResultBuilder.<List<OfHeader>>success().buildFuture()
/**
* Inject callback ti future for specified multipart type. This callback will translate and write
- * result of multipart messages
+ * result of multipart messages.
+ *
* @param type multipart type
* @param future multipart collection future
* @param deviceContext device context
}
@Override
- public void onFailure(@Nonnull final Throwable t) {
- LOG.warn("Request of type {} for static info of node {} failed.", type, deviceContext.getDeviceInfo().getLOGValue());
+ public void onFailure(@Nonnull final Throwable throwable) {
+ LOG.warn("Request of type {} for static info of node {} failed.",
+ type, deviceContext.getDeviceInfo().getLOGValue());
}
});
}
/**
- * Translate and write multipart messages from OpenflowJava
+ * Translate and write multipart messages from OpenflowJava.
+ *
* @param type multipart type
* @param result multipart messages
* @param deviceContext device context
* @param multipartWriterProvider multipart writer provider
* @param convertorExecutor convertor executor
*/
+ @SuppressWarnings("checkstyle:IllegalCatch")
private static void translateAndWriteResult(final MultipartType type,
final List<OfHeader> result,
final DeviceContext deviceContext,
.ifPresent(translatedReply -> {
// If we collected meter features, check if we have support for meters
// and pass this information to device context
- if (MultipartType.OFPMPMETERFEATURES.equals(type) &&
- translatedReply instanceof MeterFeatures) {
+ if (MultipartType.OFPMPMETERFEATURES.equals(type)
+ && translatedReply instanceof MeterFeatures) {
final MeterFeatures meterFeatures = (MeterFeatures) translatedReply;
if (meterFeatures.getMaxMeter().getValue() > 0) {
}
/**
- * Send request to device and unify different possible reply types from OpenflowJava to common parent interface
+ * Send request to device and unify different possible reply types from OpenflowJava to common parent interface.
+ *
* @param multipartType multipart type
* @param deviceContext device context
* @return unified replies
final DeviceContext deviceContext) {
if (deviceContext.canUseSingleLayerSerialization()) {
final SingleLayerMultipartCollectorService service =
- new SingleLayerMultipartCollectorService(deviceContext, deviceContext);
+ new SingleLayerMultipartCollectorService(deviceContext, deviceContext);
- return Futures.transform(service.handleServiceCall(multipartType), new Function<RpcResult<List<MultipartReply>>, RpcResult<List<OfHeader>>>() {
- @Nonnull
- @Override
- public RpcResult<List<OfHeader>> apply(final RpcResult<List<MultipartReply>> input) {
- if (Objects.isNull(input.getResult()) && input.isSuccessful()) {
- final List<OfHeader> temp = null;
- return RpcResultBuilder.success(temp).build();
- }
+ return Futures.transform(service.handleServiceCall(multipartType),
+ new Function<RpcResult<List<MultipartReply>>, RpcResult<List<OfHeader>>>() {
+ @Nonnull
+ @Override
+ public RpcResult<List<OfHeader>> apply(final RpcResult<List<MultipartReply>> input) {
+ if (Objects.isNull(input.getResult()) && input.isSuccessful()) {
+ final List<OfHeader> temp = null;
+ return RpcResultBuilder.success(temp).build();
+ }
- return input.isSuccessful()
- ? RpcResultBuilder.success(input
- .getResult()
- .stream()
- .map(OfHeader.class::cast)
- .collect(Collectors.toList()))
- .build()
- : RpcResultBuilder.<List<OfHeader>>failed()
- .withRpcErrors(input.getErrors())
- .build();
- }
- });
+ return input.isSuccessful()
+ ? RpcResultBuilder.success(input
+ .getResult()
+ .stream()
+ .map(OfHeader.class::cast)
+ .collect(Collectors.toList()))
+ .build()
+ : RpcResultBuilder.<List<OfHeader>>failed()
+ .withRpcErrors(input.getErrors())
+ .build();
+ }
+ });
}
final MultiLayerMultipartCollectorService service =
new MultiLayerMultipartCollectorService(deviceContext, deviceContext);
- return Futures.transform(service.handleServiceCall(multipartType), new Function<RpcResult<List<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply>>, RpcResult<List<OfHeader>>>() {
+ return Futures.transform(service.handleServiceCall(multipartType), new Function<RpcResult<List<org
+ .opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply>>,
+ RpcResult<List<OfHeader>>>() {
@Nonnull
@Override
- public RpcResult<List<OfHeader>> apply(final RpcResult<List<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply>> input) {
+ public RpcResult<List<OfHeader>> apply(final RpcResult<List<org.opendaylight.yang.gen.v1.urn.opendaylight
+ .openflow.protocol.rev130731.MultipartReply>> input) {
if (Objects.isNull(input.getResult()) && input.isSuccessful()) {
final List<OfHeader> temp = null;
return RpcResultBuilder.success(temp).build();
}
return input.isSuccessful()
- ? RpcResultBuilder.success(input
- .getResult()
- .stream()
- .map(OfHeader.class::cast)
- .collect(Collectors.toList()))
- .build()
- : RpcResultBuilder.<List<OfHeader>>failed()
- .withRpcErrors(input.getErrors())
- .build();
+ ? RpcResultBuilder.success(input
+ .getResult()
+ .stream()
+ .map(OfHeader.class::cast)
+ .collect(Collectors.toList()))
+ .build()
+ : RpcResultBuilder.<List<OfHeader>>failed()
+ .withRpcErrors(input.getErrors())
+ .build();
}
});
}
/**
- * <p>
- * Implementation for {@link MultiMsgCollector} interface
+ * Implementation for {@link MultiMsgCollector} interface.
*
* @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
* @author <a href="mailto:tkubas@cisco.com">Timotej Kubas</a>
- * </p>
- * Created: Mar 23, 2015
*/
public class MultiMsgCollectorImpl<T extends OfHeader> implements MultiMsgCollector<T> {
private static final Logger LOG = LoggerFactory.getLogger(MultiMsgCollectorImpl.class);
private final RequestContext<List<T>> requestContext;
private final DeviceReplyProcessor deviceReplyProcessor;
- public MultiMsgCollectorImpl(final DeviceReplyProcessor deviceReplyProcessor, final RequestContext<List<T>> requestContext) {
+ public MultiMsgCollectorImpl(final DeviceReplyProcessor deviceReplyProcessor,
+ final RequestContext<List<T>> requestContext) {
this.deviceReplyProcessor = Preconditions.checkNotNull(deviceReplyProcessor);
this.requestContext = Preconditions.checkNotNull(requestContext);
}
@Override
- public void addMultipartMsg(@Nonnull final T reply, final boolean reqMore, @Nullable final EventIdentifier eventIdentifier) {
+ public void addMultipartMsg(@Nonnull final T reply, final boolean reqMore,
+ @Nullable final EventIdentifier eventIdentifier) {
Preconditions.checkNotNull(reply);
Preconditions.checkNotNull(requestContext.getXid());
Preconditions.checkArgument(requestContext.getXid().getValue().equals(reply.getXid()));
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-/**
- *
- */
public class OpenflowProtocolListenerFullImpl implements AlienMessageListener, OpenflowMessageListenerFacade {
private static final Logger LOG = LoggerFactory.getLogger(OpenflowProtocolListenerFullImpl.class);
private final DeviceReplyProcessor deviceReplyProcessor;
/**
- * @param connectionAdapter
- * @param deviceReplyProcessor
+ * Constructor.
+ *
+ * @param connectionAdapter - connection adapter
+ * @param deviceReplyProcessor - device replay processor
*/
- public OpenflowProtocolListenerFullImpl(final ConnectionAdapter connectionAdapter, final DeviceReplyProcessor deviceReplyProcessor) {
+ public OpenflowProtocolListenerFullImpl(final ConnectionAdapter connectionAdapter,
+ final DeviceReplyProcessor deviceReplyProcessor) {
this.connectionAdapter = connectionAdapter;
this.deviceReplyProcessor = deviceReplyProcessor;
}
@Override
public void onEchoRequestMessage(final EchoRequestMessage echoRequestMessage) {
- if(LOG.isDebugEnabled()) {
+ if (LOG.isDebugEnabled()) {
LOG.debug("echo request received: {}", echoRequestMessage.getXid());
}
final EchoReplyInputBuilder builder = new EchoReplyInputBuilder();
@Override
public void onHelloMessage(final HelloMessage hello) {
- LOG.warn("hello message received outside handshake phase -> dropping connection {}", connectionAdapter.getRemoteAddress());
+ LOG.warn("hello message received outside handshake phase -> dropping connection {}",
+ connectionAdapter.getRemoteAddress());
connectionAdapter.disconnect();
}
@Override
public void onMultipartReplyMessage(final MultipartReplyMessage notification) {
- if(LOG.isTraceEnabled()) {
+ if (LOG.isTraceEnabled()) {
LOG.trace("Multipart Reply with XID: {}", notification.getXid());
}
-// multiMsgCollector.addMultipartMsg(notification);
+ // multiMsgCollector.addMultipartMsg(notification);
}
@Override
@Mock
DataBroker dataBroker;
@Mock
- WriteTransaction wTx;
+ WriteTransaction writeTx;
@Mock
- ReadOnlyTransaction rTx;
+ ReadOnlyTransaction readTx;
@Mock
BindingTransactionChain txChainFactory;
@Mock
private DeviceContext deviceContextSpy;
@Before
- public void setUp() throws Exception{
- final CheckedFuture<Optional<Node>, ReadFailedException> noExistNodeFuture = Futures.immediateCheckedFuture(Optional.<Node>absent());
- Mockito.when(rTx.read(LogicalDatastoreType.OPERATIONAL, nodeKeyIdent)).thenReturn(noExistNodeFuture);
- Mockito.when(dataBroker.newReadOnlyTransaction()).thenReturn(rTx);
- Mockito.when(dataBroker.createTransactionChain(Mockito.any(TransactionChainManager.class))).thenReturn(txChainFactory);
+ public void setUp() throws Exception {
+ final CheckedFuture<Optional<Node>, ReadFailedException> noExistNodeFuture =
+ Futures.immediateCheckedFuture(Optional.<Node>absent());
+ Mockito.when(readTx.read(LogicalDatastoreType.OPERATIONAL, nodeKeyIdent)).thenReturn(noExistNodeFuture);
+ Mockito.when(dataBroker.newReadOnlyTransaction()).thenReturn(readTx);
+ Mockito.when(dataBroker.createTransactionChain(Mockito.any(TransactionChainManager.class)))
+ .thenReturn(txChainFactory);
Mockito.when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(nodeKeyIdent);
Mockito.when(deviceInfo.getNodeId()).thenReturn(nodeId);
Mockito.when(deviceInfo.getDatapathId()).thenReturn(BigInteger.ONE);
settableFutureMultiReply.set((RpcResult<MultipartReply>) invocation.getArguments()[0]);
return null;
}).when(requestContextMultiReply).setResult(any(RpcResult.class));
- Mockito.when(txChainFactory.newWriteOnlyTransaction()).thenReturn(wTx);
- Mockito.when(dataBroker.newReadOnlyTransaction()).thenReturn(rTx);
+ Mockito.when(txChainFactory.newWriteOnlyTransaction()).thenReturn(writeTx);
+ Mockito.when(dataBroker.newReadOnlyTransaction()).thenReturn(readTx);
Mockito.when(connectionContext.getOutboundQueueProvider()).thenReturn(outboundQueueProvider);
Mockito.when(connectionContext.getConnectionAdapter()).thenReturn(connectionAdapter);
Mockito.when(connectionContext.getDeviceInfo()).thenReturn(deviceInfo);
Mockito.when(featuresOutput.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
final PacketReceived packetReceived = new PacketReceivedBuilder()
- .setMatch(new org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.packet.received.MatchBuilder()
+ .setMatch(new org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.packet.received
+ .MatchBuilder()
.setInPort(new NodeConnectorId("openflow:1:LOCAL"))
.build())
.build();
- Mockito.when(messageTranslatorPacketReceived.translate(any(Object.class), any(DeviceInfo.class), any(Object.class))).thenReturn(packetReceived);
- Mockito.when(messageTranslatorFlowCapableNodeConnector.translate(any(Object.class), any(DeviceInfo.class), any(Object.class))).thenReturn(mock(FlowCapableNodeConnector.class));
- Mockito.when(translatorLibrary.lookupTranslator(eq(new TranslatorKey(OFConstants.OFP_VERSION_1_3, PacketIn.class.getName())))).thenReturn(messageTranslatorPacketReceived);
- Mockito.when(translatorLibrary.lookupTranslator(eq(new TranslatorKey(OFConstants.OFP_VERSION_1_3, PortGrouping.class.getName())))).thenReturn(messageTranslatorFlowCapableNodeConnector);
+ Mockito.when(messageTranslatorPacketReceived.translate(any(Object.class), any(DeviceInfo.class),
+ any(Object.class))).thenReturn(packetReceived);
+ Mockito.when(messageTranslatorFlowCapableNodeConnector.translate(any(Object.class), any(DeviceInfo.class),
+ any(Object.class))).thenReturn(mock(FlowCapableNodeConnector.class));
Mockito.when(translatorLibrary.lookupTranslator(eq(new TranslatorKey(OFConstants.OFP_VERSION_1_3,
- FlowRemoved.class.getName()))))
- .thenReturn(messageTranslatorFlowRemoved);
+ PacketIn.class.getName())))).thenReturn(messageTranslatorPacketReceived);
+ Mockito.when(translatorLibrary.lookupTranslator(eq(new TranslatorKey(OFConstants.OFP_VERSION_1_3,
+ PortGrouping.class.getName())))).thenReturn(messageTranslatorFlowCapableNodeConnector);
+ Mockito.when(translatorLibrary.lookupTranslator(eq(new TranslatorKey(OFConstants.OFP_VERSION_1_3,
+ FlowRemoved.class.getName())))).thenReturn(messageTranslatorFlowRemoved);
Mockito.when(abstractDeviceInitializer.initialize(any(), anyBoolean(), anyBoolean(), any(), any()))
.thenReturn(Futures.immediateFuture(null));
public void testGetReadTransaction() {
final ReadTransaction readTx = deviceContext.getReadTransaction();
assertNotNull(readTx);
- assertEquals(rTx, readTx);
+ assertEquals(this.readTx, readTx);
}
- /**
- * @throws Exception
- */
@Test
public void testInitialSubmitTransaction() throws Exception {
- Mockito.when(wTx.submit()).thenReturn(Futures.immediateCheckedFuture(null));
+ Mockito.when(writeTx.submit()).thenReturn(Futures.immediateCheckedFuture(null));
final InstanceIdentifier<Nodes> dummyII = InstanceIdentifier.create(Nodes.class);
((DeviceContextImpl) deviceContext).getTransactionChainManager().activateTransactionManager() ;
((DeviceContextImpl) deviceContext).getTransactionChainManager().enableSubmit();
deviceContext.addDeleteToTxChain(LogicalDatastoreType.CONFIGURATION, dummyII);
deviceContext.initialSubmitTransaction();
- verify(wTx).submit();
+ verify(writeTx).submit();
}
private ConnectionContext prepareConnectionContext() {
return mockedConnectionContext;
}
- /**
- * @throws Exception
- */
@Test
- public void testAddDeleteToTxChain() throws Exception{
+ public void testAddDeleteToTxChain() throws Exception {
final InstanceIdentifier<Nodes> dummyII = InstanceIdentifier.create(Nodes.class);
((DeviceContextImpl) deviceContext).getTransactionChainManager().activateTransactionManager() ;
((DeviceContextImpl) deviceContext).getTransactionChainManager().enableSubmit();
deviceContext.addDeleteToTxChain(LogicalDatastoreType.CONFIGURATION, dummyII);
- verify(wTx).delete(eq(LogicalDatastoreType.CONFIGURATION), eq(dummyII));
+ verify(writeTx).delete(eq(LogicalDatastoreType.CONFIGURATION), eq(dummyII));
}
- /**
- * @throws Exception
- */
@Test
public void testSubmitTransaction() throws Exception {
((DeviceContextImpl) deviceContext).getTransactionChainManager().activateTransactionManager() ;
final NotificationPublishService mockedNotificationPublishService = mock(NotificationPublishService.class);
final ListenableFuture stringListenableFuture = Futures.immediateFuture(new String("dummy value"));
- when(mockedNotificationPublishService.offerNotification(any(PacketReceived.class))).thenReturn(stringListenableFuture);
+ when(mockedNotificationPublishService.offerNotification(any(PacketReceived.class)))
+ .thenReturn(stringListenableFuture);
deviceContext.setNotificationPublishService(mockedNotificationPublishService);
deviceContext.processPacketInMessage(mockedPacketInMessage);
verify(messageSpy).spyMessage(any(Class.class), eq(MessageSpy.StatisticsGroup.FROM_SWITCH));
when(mockedNotificationPublishService.offerNotification(any(PacketReceived.class))).thenReturn(dummyFuture);
deviceContext.setNotificationPublishService(mockedNotificationPublishService);
deviceContext.processPacketInMessage(mockedPacketInMessage);
- verify(messageSpy).spyMessage(any(Class.class), eq(MessageSpy.StatisticsGroup.FROM_SWITCH_NOTIFICATION_REJECTED));
+ verify(messageSpy).spyMessage(any(Class.class),
+ eq(MessageSpy.StatisticsGroup.FROM_SWITCH_NOTIFICATION_REJECTED));
}
@Test
}
@Test
- public void testPortStatusMessage() throws Exception{
+ public void testPortStatusMessage() throws Exception {
final PortStatusMessage mockedPortStatusMessage = mock(PortStatusMessage.class);
final Class dummyClass = Class.class;
when(mockedPortStatusMessage.getImplementedInterface()).thenReturn(dummyClass);
.setMatch(new MatchBuilder().build());
final NotificationPublishService mockedNotificationPublishService = mock(NotificationPublishService.class);
- Mockito.when(messageTranslatorFlowRemoved.translate(any(Object.class), any(DeviceInfo.class), any(Object.class)))
+ Mockito.when(messageTranslatorFlowRemoved
+ .translate(any(Object.class), any(DeviceInfo.class), any(Object.class)))
.thenReturn(flowRemovedMdsalBld.build());
// insert flow+flowId into local registry
- final FlowRegistryKey flowRegKey = FlowRegistryKeyFactory.create(deviceInfo.getVersion(), flowRemovedMdsalBld.build());
+ final FlowRegistryKey flowRegKey =
+ FlowRegistryKeyFactory.create(deviceInfo.getVersion(), flowRemovedMdsalBld.build());
final FlowDescriptor flowDescriptor = FlowDescriptorFactory.create((short) 0, new FlowId("ut-ofp:f456"));
deviceContext.getDeviceFlowRegistry().storeDescriptor(flowRegKey, flowDescriptor);
// plug in lifecycleListener
final ItemLifecycleListener itemLifecycleListener = Mockito.mock(ItemLifecycleListener.class);
- for (final ItemLifeCycleSource lifeCycleSource : deviceContext.getItemLifeCycleSourceRegistry().getLifeCycleSources()) {
+ for (final ItemLifeCycleSource lifeCycleSource : deviceContext.getItemLifeCycleSourceRegistry()
+ .getLifeCycleSources()) {
lifeCycleSource.setItemLifecycleListener(itemLifecycleListener);
}
public void testProcessExperimenterMessage() {
final ConvertorMessageFromOFJava mockedMessageConverter = mock(ConvertorMessageFromOFJava.class);
final ExtensionConverterProvider mockedExtensionConverterProvider = mock(ExtensionConverterProvider.class);
- when(mockedExtensionConverterProvider.getMessageConverter(any(MessageTypeKey.class))).thenReturn(mockedMessageConverter);
+ when(mockedExtensionConverterProvider.getMessageConverter(any(MessageTypeKey.class)))
+ .thenReturn(mockedMessageConverter);
final ExperimenterDataOfChoice mockedExperimenterDataOfChoice = mock(ExperimenterDataOfChoice.class);
final ExperimenterMessage experimenterMessage = new ExperimenterMessageBuilder()
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.provider.config.rev160510.NonZeroUint32Type;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.provider.config.rev160510.OpenflowProviderConfigBuilder;
import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
-import org.opendaylight.yangtools.yang.common.RpcError;
@RunWith(MockitoJUnitRunner.class)
public class DeviceManagerImplTest {
private static final long TEST_VALUE_GLOBAL_NOTIFICATION_QUOTA = 2000L;
- private static final int barrierCountLimit = 25600;
- private static final long barrierIntervalNanos = 500;
+ private static final int BARRIER_COUNT_LIMIT = 25600;
+ private static final long BARRIER_INTERVAL_NANOS = 500;
private static final NodeId DUMMY_NODE_ID = new NodeId("dummyNodeId");
private static final KeyedInstanceIdentifier<Node, NodeKey> DUMMY_IDENTIFIER = DeviceStateUtil
.createNodeInstanceIdentifier(DUMMY_NODE_ID);
deviceManager = new DeviceManagerImpl(
new OpenflowProviderConfigBuilder()
- .setBarrierCountLimit(new NonZeroUint16Type(barrierCountLimit))
- .setBarrierIntervalTimeoutLimit(new NonZeroUint32Type(barrierIntervalNanos))
+ .setBarrierCountLimit(new NonZeroUint16Type(BARRIER_COUNT_LIMIT))
+ .setBarrierIntervalTimeoutLimit(new NonZeroUint32Type(BARRIER_INTERVAL_NANOS))
.setGlobalNotificationQuota(TEST_VALUE_GLOBAL_NOTIFICATION_QUOTA)
.setSwitchFeaturesMandatory(false)
.setEnableFlowRemovedNotification(true)
}
@SuppressWarnings("unchecked")
- private static ConcurrentHashMap<DeviceInfo, DeviceContext> getContextsCollection(final DeviceManagerImpl deviceManager) throws NoSuchFieldException, IllegalAccessException {
+ private static ConcurrentHashMap<DeviceInfo, DeviceContext> getContextsCollection(
+ final DeviceManagerImpl deviceManager) throws NoSuchFieldException, IllegalAccessException {
// HACK: contexts collection for testing shall be accessed in some more civilized way
final Field contextsField = DeviceManagerImpl.class.getDeclaredField("deviceContexts");
Assert.assertNotNull(contextsField);
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
/**
- * openflowplugin-impl
- * org.opendaylight.openflowplugin.impl.device
- *
- * test of {@link DeviceStateImpl} - lightweight version, using basic ways (TDD)
+ * openflowplugin-impl.org.opendaylight.openflowplugin.impl.device
+ * test of {@link DeviceStateImpl} - lightweight version, using basic ways (TDD).
*/
@RunWith(MockitoJUnitRunner.class)
public class DeviceStateImplTest {
-
- @Mock
- private DeviceInfo deviceInfo;
-
private DeviceStateImpl deviceState;
@Before
}
@Test
- public void testStatistics_initialValue(){
+ public void testStatistics_initialValue() {
Assert.assertFalse(deviceState.isFlowStatisticsAvailable());
Assert.assertFalse(deviceState.isPortStatisticsAvailable());
Assert.assertFalse(deviceState.isQueueStatisticsAvailable());
}
@Test
- public void testMeterAndGroupAvailable_initialValue(){
+ public void testMeterAndGroupAvailable_initialValue() {
Assert.assertFalse(deviceState.isGroupAvailable());
Assert.assertFalse(deviceState.isMetersAvailable());
}
import org.opendaylight.controller.md.sal.common.api.data.TransactionChain;
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.connection.ConnectionContext;
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.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
-/**
- * Created by mirehak on 4/5/15.
- */
@RunWith(MockitoJUnitRunner.class)
public class TransactionChainManagerTest {
@Mock
private DataBroker dataBroker;
@Mock
- private ConnectionContext connectionContext;
- @Mock
private BindingTransactionChain txChain;
@Mock
private WriteTransaction writeTx;
@Before
public void setUp() throws Exception {
final ReadOnlyTransaction readOnlyTx = Mockito.mock(ReadOnlyTransaction.class);
- final CheckedFuture<Optional<Node>, ReadFailedException> noExistNodeFuture = Futures.immediateCheckedFuture(Optional.<Node>absent());
+ final CheckedFuture<Optional<Node>, ReadFailedException> noExistNodeFuture =
+ Futures.immediateCheckedFuture(Optional.<Node>absent());
Mockito.when(readOnlyTx.read(LogicalDatastoreType.OPERATIONAL, nodeKeyIdent)).thenReturn(noExistNodeFuture);
Mockito.when(dataBroker.newReadOnlyTransaction()).thenReturn(readOnlyTx);
Mockito.when(dataBroker.createTransactionChain(Matchers.any(TransactionChainListener.class)))
Mockito.when(txChain.newWriteOnlyTransaction()).thenReturn(writeTx);
path = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(nodeId));
- Mockito.when(writeTx.submit()).thenReturn(Futures.<Void, TransactionCommitFailedException>immediateCheckedFuture(null));
+ Mockito.when(writeTx.submit())
+ .thenReturn(Futures.<Void, TransactionCommitFailedException>immediateCheckedFuture(null));
txChainManager.activateTransactionManager();
}
}
/**
- * test of {@link TransactionChainManager#submitWriteTransaction()}
- * @throws Exception
+ * Test of {@link TransactionChainManager#submitWriteTransaction()}.
*/
@Test
public void testSubmitTransaction() throws Exception {
}
/**
- * test of {@link TransactionChainManager#submitWriteTransaction()}: no submit, never enabled
- * @throws Exception
+ * Test of {@link TransactionChainManager#submitWriteTransaction()}: no submit, never enabled.
*/
@Test
public void testSubmitTransaction1() throws Exception {
Mockito.verify(writeTx, Mockito.never()).submit();
}
- /**
- * @throws Exception
- */
@Test
public void testSubmitTransactionFailed() throws Exception {
- Mockito.when(writeTx.submit()).thenReturn(Futures.immediateFailedCheckedFuture(new TransactionCommitFailedException("mock")));
+ Mockito.when(writeTx.submit())
+ .thenReturn(Futures.immediateFailedCheckedFuture(new TransactionCommitFailedException("mock")));
final Node data = new NodeBuilder().setId(nodeId).build();
txChainManager.initialSubmitWriteTransaction();
txChainManager.writeToTransaction(LogicalDatastoreType.CONFIGURATION, path, data, false);
txChainManager.writeToTransaction(LogicalDatastoreType.CONFIGURATION, path, data, false);
txChainManager.submitWriteTransaction();
- Mockito.when(writeTx.submit()).thenReturn(Futures.immediateFailedCheckedFuture(new TransactionCommitFailedException("mock")));
+ Mockito.when(writeTx.submit())
+ .thenReturn(Futures.immediateFailedCheckedFuture(new TransactionCommitFailedException("mock")));
txChainManager.writeToTransaction(LogicalDatastoreType.CONFIGURATION, path, data, false);
txChainManager.submitWriteTransaction();
}
/**
- * test of {@link TransactionChainManager#enableSubmit()}: no submit - counter is not active
- *
- * @throws Exception
+ * Test of {@link TransactionChainManager#enableSubmit()}: no submit - counter is not active.
*/
@Test
public void testEnableCounter1() throws Exception {
Mockito.verify(writeTx, Mockito.never()).submit();
}
- /**
- * @throws Exception
- */
@Test
public void testOnTransactionChainFailed() throws Exception {
- txChainManager.onTransactionChainFailed(transactionChain, Mockito.mock(AsyncTransaction.class), Mockito.mock(Throwable.class));
+ txChainManager.onTransactionChainFailed(transactionChain,
+ Mockito.mock(AsyncTransaction.class), Mockito.mock(Throwable.class));
Mockito.verify(txChain).close();
Mockito.verify(dataBroker, Mockito.times(2)).createTransactionChain(txChainManager);
}
Mockito.verify(txChain).close();
}
- /**
- * @throws Exception
- */
@Test
public void testDeactivateTransactionChainManagerFailed() throws Exception {
- Mockito.when(writeTx.submit()).thenReturn(Futures.<Void, TransactionCommitFailedException>immediateFailedCheckedFuture(new TransactionCommitFailedException("mock")));
+ Mockito.when(writeTx.submit())
+ .thenReturn(Futures.<Void, TransactionCommitFailedException>immediateFailedCheckedFuture(
+ new TransactionCommitFailedException("mock")));
final Node data = new NodeBuilder().setId(nodeId).build();
txChainManager.writeToTransaction(LogicalDatastoreType.CONFIGURATION, path, data, false);
}
@Test
- public void testShuttingDown() throws Exception{
+ public void testShuttingDown() throws Exception {
final Node data = new NodeBuilder().setId(nodeId).build();
txChainManager.writeToTransaction(LogicalDatastoreType.CONFIGURATION, path, data, false);
txChainManager.enableSubmit();
/**
* openflowplugin-api
* org.opendaylight.openflowplugin.impl.openflow.device
- * <p/>
- * Test class for testing basic method functionality for {@link MultiMsgCollector}
+ * Test class for testing basic method functionality for {@link MultiMsgCollector}.
*
* @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
* @author <a href="mailto:tkubas@cisco.com">Timotej Kubas</a>
- * <p/>
- * Created: Mar 23, 2015
+ *
*/
@RunWith(MockitoJUnitRunner.class)
public class MultiMsgCollectorImplTest {
}
/**
- * test of ${link MultiMsgCollector#addMultipartMsg} <br>
- * success with message consisting of 1 part
+ * Test of ${link MultiMsgCollector#addMultipartMsg}
+ * success with message consisting of 1 part.
*/
@Test
public void testAddMultipartMsgOne() {
- collector.addMultipartMsg(MsgGeneratorTestUtils.makeMultipartDescReply(xid, hwTestValue, false).build(), false, null);
+ collector.addMultipartMsg(MsgGeneratorTestUtils
+ .makeMultipartDescReply(xid, hwTestValue, false).build(), false, null);
Mockito.verify(deviceProcessor).processReply(xidCaptor.capture(), mmCaptor.capture());
Assert.assertEquals(xid, xidCaptor.getValue().getValue());
}
/**
- * test of ${link MultiMsgCollector#addMultipartMsg} <br>
- * success with message consisting of 2 parts
+ * Test of ${link MultiMsgCollector#addMultipartMsg}
+ * success with message consisting of 2 parts.
*/
@Test
public void testAddMultipartMsgTwo() {
- collector.addMultipartMsg(MsgGeneratorTestUtils.makeMultipartDescReply(xid, hwTestValue, true).build(), true, null);
- collector.addMultipartMsg(MsgGeneratorTestUtils.makeMultipartDescReply(xid, hwTestValue, false).build(), false, null);
+ collector.addMultipartMsg(MsgGeneratorTestUtils
+ .makeMultipartDescReply(xid, hwTestValue, true).build(), true, null);
+ collector.addMultipartMsg(MsgGeneratorTestUtils
+ .makeMultipartDescReply(xid, hwTestValue, false).build(), false, null);
Mockito.verify(deviceProcessor).processReply(xidCaptor.capture(), mmCaptor.capture());
Assert.assertEquals(xid, xidCaptor.getValue().getValue());
}
/**
- * test of ${link MultiMsgCollector#addMultipartMsg} <br>
- * xid not registered before message
+ * Test of ${link MultiMsgCollector#addMultipartMsg}
+ * xid not registered before message.
*/
- @Test(expected=IllegalArgumentException.class)
+ @Test(expected = IllegalArgumentException.class)
public void testAddMultipartMsgNotExpectedXid() {
final Long dif_xid = 5L;
- final MultipartReplyMessage mrMsg = MsgGeneratorTestUtils.makeMultipartDescReply(dif_xid, hwTestValue, true).build();
+ final MultipartReplyMessage mrMsg = MsgGeneratorTestUtils
+ .makeMultipartDescReply(dif_xid, hwTestValue, true).build();
collector.addMultipartMsg(mrMsg, true, null);
}
/**
- * test of ${link MultiMsgCollector#addMultipartMsg} <br>
- * message types are inconsistent - second message is final and should be rejected
+ * Test of ${link MultiMsgCollector#addMultipartMsg}
+ * message types are inconsistent - second message is final and should be rejected.
*/
@Test
public void testAddMultipartMsgWrongType1() {
- collector.addMultipartMsg(MsgGeneratorTestUtils.makeMultipartDescReply(xid, hwTestValue, true).build(), true, null);
+ collector.addMultipartMsg(MsgGeneratorTestUtils
+ .makeMultipartDescReply(xid, hwTestValue, true).build(), true, null);
collector.addMultipartMsg(MsgGeneratorTestUtils.makeMultipartDescReply(xid, hwTestValue, false)
.setType(MultipartType.OFPMPPORTDESC).build(), false, null);
}
/**
- * test of ${link MultiMsgCollector#addMultipartMsg} <br>
- * message types are inconsistent - second message is not final and should be rejected
+ * Test of ${link MultiMsgCollector#addMultipartMsg}
+ * message types are inconsistent - second message is not final and should be rejected.
*/
@Test
public void testAddMultipartMsgWrongType2() {
- collector.addMultipartMsg(MsgGeneratorTestUtils.makeMultipartDescReply(xid, hwTestValue, true).build(), true, null);
+ collector.addMultipartMsg(MsgGeneratorTestUtils
+ .makeMultipartDescReply(xid, hwTestValue, true).build(), true, null);
collector.addMultipartMsg(MsgGeneratorTestUtils.makeMultipartDescReply(xid, hwTestValue, true)
.setType(MultipartType.OFPMPPORTDESC).build(), true, null);
- collector.addMultipartMsg(MsgGeneratorTestUtils.makeMultipartDescReply(xid, hwTestValue, false).build(), false, null);
+ collector.addMultipartMsg(MsgGeneratorTestUtils
+ .makeMultipartDescReply(xid, hwTestValue, false).build(), false, null);
Mockito.verify(deviceProcessor).processReply(xidCaptor.capture(), mmCaptor.capture());
Mockito.verify(deviceProcessor).processReply(xidCaptor.capture(), mmCaptor.capture());
}
/**
- * test of ${link MultiMsgCollector#addMultipartMsg} <br>
- * message types are inconsistent - second message and third should be rejected
+ * Test of ${link MultiMsgCollector#addMultipartMsg}
+ * message types are inconsistent - second message and third should be rejected.
*/
@Test
public void testAddMultipartMsgWrongType3() {
- collector.addMultipartMsg(MsgGeneratorTestUtils.makeMultipartDescReply(xid, hwTestValue, true).build(), true, null);
+ collector.addMultipartMsg(MsgGeneratorTestUtils
+ .makeMultipartDescReply(xid, hwTestValue, true).build(), true, null);
collector.addMultipartMsg(MsgGeneratorTestUtils.makeMultipartDescReply(xid, hwTestValue, true)
.setType(MultipartType.OFPMPPORTDESC).build(), true, null);
- collector.addMultipartMsg(MsgGeneratorTestUtils.makeMultipartDescReply(xid, hwTestValue, false).build(), false, null);
+ collector.addMultipartMsg(MsgGeneratorTestUtils
+ .makeMultipartDescReply(xid, hwTestValue, false).build(), false, null);
Mockito.verify(deviceProcessor).processReply(xidCaptor.capture(), mmCaptor.capture());
Assert.assertEquals(xid, xidCaptor.getValue().getValue());
/**
* openflowplugin-impl
* org.opendaylight.openflowplugin.impl.connection.listener
- * <p/>
- * test of {@link OpenflowProtocolListenerFullImpl} - lightweight version, using basic ways (TDD)
+ * test of {@link OpenflowProtocolListenerFullImpl} - lightweight version, using basic ways (TDD).
*
* @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
- * <p/>
- * Created: Mar 26, 2015
+ *
*/
@RunWith(MockitoJUnitRunner.class)
public class OpenflowProtocolListenerFullImplTest {
// place for mocking method's general behavior for HandshakeContext and ConnectionContext
ofProtocolListener = new OpenflowProtocolListenerFullImpl(connectionAdapter, deviceReplyProcessor);
connectionAdapter.setMessageListener(ofProtocolListener);
- Mockito.when(connectionAdapter.getRemoteAddress()).thenReturn(InetSocketAddress.createUnresolved("ofp-junit.example.org", 6663));
+ Mockito.when(connectionAdapter.getRemoteAddress())
+ .thenReturn(InetSocketAddress.createUnresolved("ofp-junit.example.org", 6663));
Mockito.verify(connectionAdapter).setMessageListener(Matchers.any(OpenflowProtocolListener.class));
}
}
/**
- * Test method for {@link OpenflowProtocolListenerFullImpl#onEchoRequestMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessage)}.
+ * Test method for
+ * {@link OpenflowProtocolListenerFullImpl#onEchoRequestMessage(
+ * org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessage)}.
*/
@Test
public void testOnEchoRequestMessage() {
}
/**
- * Test method for {@link OpenflowProtocolListenerFullImpl#onErrorMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage)}.
+ * Test method for
+ * {@link OpenflowProtocolListenerFullImpl#onErrorMessage(
+ * org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage)}.
*/
@Test
public void testOnErrorMessage() {
}
/**
- * Test method for {@link OpenflowProtocolListenerFullImpl#onExperimenterMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage)}.
+ * Test method for
+ * {@link OpenflowProtocolListenerFullImpl#onExperimenterMessage(
+ * org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage)}.
*/
@Test
public void testOnExperimenterMessage() {
}
/**
- * Test method for {@link OpenflowProtocolListenerFullImpl#onFlowRemovedMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage)}.
+ * Test method for
+ * {@link OpenflowProtocolListenerFullImpl#onFlowRemovedMessage(
+ * org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage)}.
*/
@Test
public void testOnFlowRemovedMessage() {
}
/**
- * Test method for {@link OpenflowProtocolListenerFullImpl#onHelloMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessage)}.
+ * Test method for
+ * {@link OpenflowProtocolListenerFullImpl#onHelloMessage(
+ * org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessage)}.
*/
@Test
public void testOnHelloMessage() {
}
/**
- * Test method for {@link OpenflowProtocolListenerFullImpl#onPacketInMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage)}.
+ * Test method for
+ * {@link OpenflowProtocolListenerFullImpl#onPacketInMessage(
+ * org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage)}.
*/
@Test
public void testOnPacketInMessage() {
}
/**
- * Test method for {@link OpenflowProtocolListenerFullImpl#onPortStatusMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage)}.
+ * Test method for
+ * {@link OpenflowProtocolListenerFullImpl#onPortStatusMessage(
+ * org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage)}.
*/
@Test
public void testOnPortStatusMessage() {