*/
DeviceState getDeviceState();
+ DeviceInfo getDeviceInfo();
+
/**
* Method has to activate (MASTER) or deactivate (SLAVE) TransactionChainManager.
* TransactionChainManager represents possibility to write or delete Node subtree data
import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceLifecycleSupervisor;
import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceTerminationPhaseHandler;
import org.opendaylight.openflowplugin.api.openflow.translator.TranslatorLibrarian;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
/**
* This interface is responsible for instantiating DeviceContext and
* Returning device context from map maintained in device manager
* This prevent to send whole device context to another context
* If device context not exists for nodeId it will return null
- * @param nodeId
- * @return device context or null
+ *
+ * @param deviceInfo@return device context or null
*/
- DeviceContext getDeviceContextFromNodeId(NodeId nodeId);
+ DeviceContext getDeviceContextFromNodeId(DeviceInfo deviceInfo);
void setStatisticsRpcEnabled(boolean isStatisticsRpcEnabled);
}
import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
/**
- * Created by Martin Bobak <mbobak@cisco.com> on 25.2.2015.
+ * Holder of device's structure
*/
public interface DeviceState {
- /**
- * @return id of encapsulated node
- */
- NodeId getNodeId();
-
- /**
- * @return {@link Node} instance identifier
- */
- KeyedInstanceIdentifier<Node, NodeKey> getNodeInstanceIdentifier();
-
- /**
- * @return the features of corresponding switch
- */
- GetFeaturesOutput getFeatures();
-
/**
* @return true if this session is valid
*/
*/
void setValid(boolean valid);
- /**
- * Return node current OF protocol version
- *
- * @return
- */
- short getVersion();
-
/**
* Return true if we have relevant meter information
* from device
/**
* Translates from input to output
* @param input
- * @param deviceState
+ * @param deviceInfo
* @param connectionDistinguisher
* @return message of output type
*/
- O translate(I input, DeviceState deviceState, Object connectionDistinguisher);
+ O translate(I input, DeviceInfo deviceInfo, Object connectionDistinguisher);
}
package org.opendaylight.openflowplugin.api.openflow.lifecycle;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
/**
* This API is for all listeners who wish to know about device context in cluster
/**
* Notification about start phase in device context, right after successful handshake
- * @param nodeId
+ * @param deviceInfo
* @param success or failure
*/
- void deviceStartInitializationDone(final NodeId nodeId, final boolean success);
+ void deviceStartInitializationDone(final DeviceInfo deviceInfo, final boolean success);
/**
* Notification about start phase in device context, after all other contexts initialized properly
- * @param nodeId
+ * @param deviceInfo
* @param success
*/
- void deviceInitializationDone(final NodeId nodeId, final boolean success);
+ void deviceInitializationDone(final DeviceInfo deviceInfo, final boolean success);
}
import io.netty.util.Timeout;
import io.netty.util.TimerTask;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceManager;
import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsManager;
import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageIntelligenceAgency;
/**
* Returns device context from device manager device contexts maps
- * @param nodeId node identification
- * @return null if context doesn't exists
+ *
+ * @param deviceInfo@return null if context doesn't exists
*/
- DeviceContext getDeviceContext(final NodeId nodeId);
+ DeviceContext getDeviceContext(DeviceInfo deviceInfo);
/**
* Registers ont time listener for notify when services rpc, statistics are done stop or start
* @param manager service change listener
- * @param nodeId node identification
+ * @param deviceInfo node identification
*/
- void addOneTimeListenerWhenServicesChangesDone(final ServiceChangeListener manager, final NodeId nodeId);
+ void addOneTimeListenerWhenServicesChangesDone(final ServiceChangeListener manager, final DeviceInfo deviceInfo);
/**
* Returns device of version
- * @param nodeId node identification
+ * @param deviceInfo node identification
* @return null if device context doesn't exists
*/
- Short gainVersionSafely(final NodeId nodeId);
+ Short gainVersionSafely(final DeviceInfo deviceInfo);
/**
* Set new timeout for {@link io.netty.util.HashedWheelTimer}
/**
* Interrupt connection for the node
- * @param nodeId node identification
+ * @param deviceInfo node identification
*/
- void closeConnection(final NodeId nodeId);
+ void closeConnection(final DeviceInfo deviceInfo);
/**
* Setter for device manager once set it cant be unset or overwritten
/**
* Xid from outboundqueue
- * @param nodeId
+ * @param deviceInfo
* @return
*/
- Long reserveXidForDeviceMessage(final NodeId nodeId);
+ Long reserveXidForDeviceMessage(final DeviceInfo deviceInfo);
}
package org.opendaylight.openflowplugin.api.openflow.lifecycle;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.OfpRole;
/**
/**
* Notification when initialization for role context is done
- * @param nodeId
+ * @param deviceInfo
* @param success or failure
*/
- void roleInitializationDone(final NodeId nodeId, final boolean success);
+ void roleInitializationDone(final DeviceInfo deviceInfo, final boolean success);
/**
* Notification when the role change on device is done
- * @param nodeId
+ * @param deviceInfo
* @param success
* @param newRole
* @param initializationPhase
*/
- void roleChangeOnDevice(final NodeId nodeId, final boolean success, final OfpRole newRole, final boolean initializationPhase);
+ void roleChangeOnDevice(final DeviceInfo deviceInfo, final boolean success, final OfpRole newRole, final boolean initializationPhase);
}
package org.opendaylight.openflowplugin.api.openflow.lifecycle;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
/**
* This API is defined for listening when services (Statistics and RPCs) are fully stopped
/**
* Notification when services (rpc, statistics) are started or stopped working
- * @param nodeId
+ * @param deviceInfo
* @param success
*/
- void servicesChangeDone(NodeId nodeId, boolean success);
+ void servicesChangeDone(DeviceInfo deviceInfo, boolean success);
}
import javax.annotation.Nullable;
import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceManager;
import org.opendaylight.openflowplugin.api.openflow.lifecycle.DeviceContextChangeListener;
import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
private final HashedWheelTimer hashedWheelTimer = new HashedWheelTimer(TICK_DURATION, TimeUnit.MILLISECONDS, TICKS_PER_WHEEL);
private DeviceManager deviceManager;
private final MessageIntelligenceAgency messageIntelligenceAgency;
- private ConcurrentHashMap<NodeId, ServiceChangeListener> serviceChangeListeners = new ConcurrentHashMap<>();
+ private ConcurrentHashMap<DeviceInfo, ServiceChangeListener> serviceChangeListeners = new ConcurrentHashMap<>();
private StatisticsManager statisticsManager;
public LifecycleConductorImpl(final MessageIntelligenceAgency messageIntelligenceAgency) {
}
}
- public void addOneTimeListenerWhenServicesChangesDone(final ServiceChangeListener manager, final NodeId nodeId){
- LOG.debug("Listener {} for service change for node {} registered.", manager, nodeId);
- serviceChangeListeners.put(nodeId, manager);
+ public void addOneTimeListenerWhenServicesChangesDone(final ServiceChangeListener manager, final DeviceInfo deviceInfo){
+ LOG.debug("Listener {} for service change for node {} registered.", manager, deviceInfo.getNodeId());
+ serviceChangeListeners.put(deviceInfo, manager);
}
@VisibleForTesting
- void notifyServiceChangeListeners(final NodeId nodeId, final boolean success){
+ void notifyServiceChangeListeners(final DeviceInfo deviceInfo, final boolean success){
if (serviceChangeListeners.size() == 0) {
return;
}
LOG.debug("Notifying registered listeners for service change, no. of listeners {}", serviceChangeListeners.size());
- for (final Map.Entry<NodeId, ServiceChangeListener> nodeIdServiceChangeListenerEntry : serviceChangeListeners.entrySet()) {
- if (nodeIdServiceChangeListenerEntry.getKey().equals(nodeId)) {
- LOG.debug("Listener {} for service change for node {} was notified. Success was set on {}", nodeIdServiceChangeListenerEntry.getValue(), nodeId, success);
- nodeIdServiceChangeListenerEntry.getValue().servicesChangeDone(nodeId, success);
- serviceChangeListeners.remove(nodeId);
+ for (final Map.Entry<DeviceInfo, ServiceChangeListener> nodeIdServiceChangeListenerEntry : serviceChangeListeners.entrySet()) {
+ if (nodeIdServiceChangeListenerEntry.getKey().equals(deviceInfo)) {
+ LOG.debug("Listener {} for service change for node {} was notified. Success was set on {}", nodeIdServiceChangeListenerEntry.getValue(), deviceInfo, success);
+ nodeIdServiceChangeListenerEntry.getValue().servicesChangeDone(deviceInfo, success);
+ serviceChangeListeners.remove(deviceInfo);
}
}
}
@Override
- public void roleInitializationDone(final NodeId nodeId, final boolean success) {
+ public void roleInitializationDone(final DeviceInfo deviceInfo, final boolean success) {
if (!success) {
- LOG.warn("Initialization phase for node {} in role context was NOT successful, closing connection.", nodeId);
- closeConnection(nodeId);
+ LOG.warn("Initialization phase for node {} in role context was NOT successful, closing connection.", deviceInfo);
+ closeConnection(deviceInfo);
} else {
- LOG.info("initialization phase for node {} in role context was successful, continuing to next context.", nodeId);
+ LOG.info("initialization phase for node {} in role context was successful, continuing to next context.", deviceInfo);
}
}
- public void closeConnection(final NodeId nodeId) {
- LOG.debug("Close connection called for node {}", nodeId);
- final DeviceContext deviceContext = getDeviceContext(nodeId);
+ public void closeConnection(final DeviceInfo deviceInfo) {
+ LOG.debug("Close connection called for node {}", deviceInfo);
+ final DeviceContext deviceContext = getDeviceContext(deviceInfo);
if (null != deviceContext) {
deviceContext.shutdownConnection();
}
}
@Override
- public void roleChangeOnDevice(final NodeId nodeId, final boolean success, final OfpRole newRole, final boolean initializationPhase) {
+ public void roleChangeOnDevice(final DeviceInfo deviceInfo, final boolean success, final OfpRole newRole, final boolean initializationPhase) {
- final DeviceContext deviceContext = getDeviceContext(nodeId);
+ final DeviceContext deviceContext = getDeviceContext(deviceInfo);
if (null == deviceContext) {
LOG.warn("Something went wrong, device context for nodeId: {} doesn't exists");
return;
}
if (!success) {
- LOG.warn("Role change to {} in role context for node {} was NOT successful, closing connection", newRole, nodeId);
- closeConnection(nodeId);
+ LOG.warn("Role change to {} in role context for node {} was NOT successful, closing connection", newRole, deviceInfo);
+ closeConnection(deviceInfo);
} else {
if (initializationPhase) {
LOG.debug("Initialization phase skipping starting services.");
return;
}
- LOG.info("Role change to {} in role context for node {} was successful, starting/stopping services.", newRole, nodeId);
+ LOG.info("Role change to {} in role context for node {} was successful, starting/stopping services.", newRole, deviceInfo);
if (OfpRole.BECOMEMASTER.equals(newRole)) {
statisticsManager.startScheduling(deviceContext.getPrimaryConnectionContext().getDeviceInfo());
Futures.addCallback(onClusterRoleChange, new FutureCallback<Void>() {
@Override
public void onSuccess(@Nullable final Void aVoid) {
- LOG.info("Starting/Stopping services for node {} was successful", nodeId);
- if (newRole.equals(OfpRole.BECOMESLAVE)) notifyServiceChangeListeners(nodeId, true);
+ LOG.info("Starting/Stopping services for node {} was successful", deviceInfo);
+ if (newRole.equals(OfpRole.BECOMESLAVE)) notifyServiceChangeListeners(deviceInfo, true);
}
@Override
public void onFailure(final Throwable throwable) {
- LOG.warn("Starting/Stopping services for node {} was NOT successful, closing connection", nodeId);
- closeConnection(nodeId);
+ LOG.warn("Starting/Stopping services for node {} was NOT successful, closing connection", deviceInfo);
+ closeConnection(deviceInfo);
}
});
}
}
@Override
- public DeviceContext getDeviceContext(final NodeId nodeId){
- return deviceManager.getDeviceContextFromNodeId(nodeId);
+ public DeviceContext getDeviceContext(DeviceInfo deviceInfo){
+ return deviceManager.getDeviceContextFromNodeId(deviceInfo);
}
- public Short gainVersionSafely(final NodeId nodeId) {
- return (null != getDeviceContext(nodeId)) ? getDeviceContext(nodeId).getPrimaryConnectionContext().getFeatures().getVersion() : null;
+ @Override
+ public Short gainVersionSafely(final DeviceInfo deviceInfo) {
+ return (null != getDeviceContext(deviceInfo)) ? getDeviceContext(deviceInfo).getPrimaryConnectionContext().getFeatures().getVersion() : null;
}
public Timeout newTimeout(@Nonnull TimerTask task, long delay, @Nonnull TimeUnit unit) {
return hashedWheelTimer.newTimeout(task, delay, unit);
}
- public ConnectionContext.CONNECTION_STATE gainConnectionStateSafely(final NodeId nodeId){
- return (null != getDeviceContext(nodeId)) ? getDeviceContext(nodeId).getPrimaryConnectionContext().getConnectionState() : null;
+ ConnectionContext.CONNECTION_STATE gainConnectionStateSafely(final DeviceInfo deviceInfo){
+ return (null != getDeviceContext(deviceInfo)) ? getDeviceContext(deviceInfo).getPrimaryConnectionContext().getConnectionState() : null;
}
- public Long reserveXidForDeviceMessage(final NodeId nodeId){
- return null != getDeviceContext(nodeId) ? getDeviceContext(nodeId).reserveXidForDeviceMessage() : null;
+ @Override
+ public Long reserveXidForDeviceMessage(final DeviceInfo deviceInfo){
+ return null != getDeviceContext(deviceInfo) ? getDeviceContext(deviceInfo).reserveXidForDeviceMessage() : null;
}
@Override
- public void deviceStartInitializationDone(final NodeId nodeId, final boolean success) {
+ public void deviceStartInitializationDone(final DeviceInfo deviceInfo, final boolean success) {
if (!success) {
- LOG.warn("Initialization phase for node {} in device context was NOT successful, closing connection.", nodeId);
- closeConnection(nodeId);
+ LOG.warn("Initialization phase for node {} in device context was NOT successful, closing connection.", deviceInfo);
+ closeConnection(deviceInfo);
} else {
- LOG.info("initialization phase for node {} in device context was successful. Continuing to next context.", nodeId);
+ LOG.info("initialization phase for node {} in device context was successful. Continuing to next context.", deviceInfo);
}
}
@Override
- public void deviceInitializationDone(final NodeId nodeId, final boolean success) {
+ public void deviceInitializationDone(final DeviceInfo deviceInfo, final boolean success) {
if (!success) {
- LOG.warn("Initialization phase for node {} in device context was NOT successful, closing connection.", nodeId);
- closeConnection(nodeId);
+ LOG.warn("Initialization phase for node {} in device context was NOT successful, closing connection.", deviceInfo);
+ closeConnection(deviceInfo);
} else {
- LOG.info("initialization phase for node {} in device context was successful. All phases initialized OK.", nodeId);
+ LOG.info("initialization phase for node {} in device context was successful. All phases initialized OK.", deviceInfo);
}
}
this.dataBroker = Preconditions.checkNotNull(dataBroker);
Preconditions.checkNotNull(conductor);
this.outboundQueueProvider = Preconditions.checkNotNull(outboundQueueProvider);
- this.transactionChainManager = new TransactionChainManager(dataBroker, deviceState, conductor);
+ deviceInfo = primaryConnectionContext.getDeviceInfo();
+ this.transactionChainManager = new TransactionChainManager(dataBroker, deviceInfo, conductor);
auxiliaryConnectionContexts = new HashMap<>();
deviceFlowRegistry = new DeviceFlowRegistryImpl();
deviceGroupRegistry = new DeviceGroupRegistryImpl();
deviceMeterRegistry = new DeviceMeterRegistryImpl();
messageSpy = conductor.getMessageIntelligenceAgency();
+
packetInLimiter = new PacketInRateLimiter(primaryConnectionContext.getConnectionAdapter(),
/*initial*/ 1000, /*initial*/2000, messageSpy, REJECTED_DRAIN_FACTOR);
this.translatorLibrary = translatorLibrary;
portStatusTranslator = translatorLibrary.lookupTranslator(
- new TranslatorKey(deviceState.getVersion(), PortGrouping.class.getName()));
+ new TranslatorKey(deviceInfo.getVersion(), PortGrouping.class.getName()));
packetInTranslator = translatorLibrary.lookupTranslator(
- new TranslatorKey(deviceState.getVersion(), PacketIn.class.getName()));
+ new TranslatorKey(deviceInfo.getVersion(), PacketIn.class.getName()));
flowRemovedTranslator = translatorLibrary.lookupTranslator(
- new TranslatorKey(deviceState.getVersion(), FlowRemoved.class.getName()));
+ new TranslatorKey(deviceInfo.getVersion(), FlowRemoved.class.getName()));
nodeConnectorCache = new ConcurrentHashMap<>();
flowLifeCycleKeeper = new ItemLifeCycleSourceImpl();
itemLifeCycleSourceRegistry.registerLifeCycleSource(flowLifeCycleKeeper);
deviceCtxState = DEVICE_CONTEXT_STATE.INITIALIZATION;
- deviceInfo = primaryConnectionContext.getDeviceInfo();
}
/**
return deviceState;
}
+ @Override
+ public DeviceInfo getDeviceInfo() {
+ return this.deviceInfo;
+ }
+
@Override
public ReadOnlyTransaction getReadTransaction() {
return dataBroker.newReadOnlyTransaction();
public Void apply(final Boolean input) {
if (ConnectionContext.CONNECTION_STATE.RIP.equals(getPrimaryConnectionContext().getConnectionState())) {
final String errMsg = String.format("We lost connection for Device %s, context has to be closed.",
- getDeviceState().getNodeId());
+ getDeviceInfo().getNodeId());
LOG.warn(errMsg);
throw new IllegalStateException(errMsg);
}
if (!input) {
final String errMsg = String.format("Get Initial Device %s information fails",
- getDeviceState().getNodeId());
+ getDeviceInfo().getNodeId());
LOG.warn(errMsg);
throw new IllegalStateException(errMsg);
}
if (itemLifecycleListener != null) {
//1. translate to general flow (table, priority, match, cookie)
final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemoved flowRemovedNotification =
- flowRemovedTranslator.translate(flowRemoved, this.getDeviceState(), null);
+ flowRemovedTranslator.translate(flowRemoved, deviceInfo, null);
//2. create registry key
final FlowRegistryKey flowRegKey = FlowRegistryKeyFactory.create(flowRemovedNotification);
//3. lookup flowId
//4. if flowId present:
if (flowDescriptor != null) {
// a) construct flow path
- final KeyedInstanceIdentifier<Flow, FlowKey> flowPath = getDeviceState().getNodeInstanceIdentifier()
+ final KeyedInstanceIdentifier<Flow, FlowKey> flowPath = getDeviceInfo().getNodeInstanceIdentifier()
.augmentation(FlowCapableNode.class)
.child(Table.class, flowDescriptor.getTableKey())
.child(Flow.class, new FlowKey(flowDescriptor.getFlowId()));
notificationPublishService.offerNotification(flowRemovedNotification);
} else {
LOG.debug("flow id not found: nodeId={} tableId={}, priority={}",
- getDeviceState().getNodeId(), flowRegKey.getTableId(), flowRemovedNotification.getPriority());
+ getDeviceInfo().getNodeId(), flowRegKey.getTableId(), flowRemovedNotification.getPriority());
}
}
}
@Override
public void processPortStatusMessage(final PortStatusMessage portStatus) {
messageSpy.spyMessage(portStatus.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.FROM_SWITCH_PUBLISHED_SUCCESS);
- final FlowCapableNodeConnector flowCapableNodeConnector = portStatusTranslator.translate(portStatus, this.getDeviceState(), null);
+ final FlowCapableNodeConnector flowCapableNodeConnector = portStatusTranslator.translate(portStatus, deviceInfo, null);
final KeyedInstanceIdentifier<NodeConnector, NodeConnectorKey> iiToNodeConnector = provideIIToNodeConnector(portStatus.getPortNo(), portStatus.getVersion());
try {
}
private KeyedInstanceIdentifier<NodeConnector, NodeConnectorKey> provideIIToNodeConnector(final long portNo, final short version) {
- final InstanceIdentifier<Node> iiToNodes = deviceState.getNodeInstanceIdentifier();
- final BigInteger dataPathId = deviceState.getFeatures().getDatapathId();
+ final InstanceIdentifier<Node> iiToNodes = deviceInfo.getNodeInstanceIdentifier();
+ final BigInteger dataPathId = deviceInfo.getDatapathId();
final NodeConnectorId nodeConnectorId = NodeStaticReplyTranslatorUtil.nodeConnectorId(dataPathId.toString(), portNo, version);
return iiToNodes.child(NodeConnector.class, new NodeConnectorKey(nodeConnectorId));
}
public void processPacketInMessage(final PacketInMessage packetInMessage) {
messageSpy.spyMessage(packetInMessage.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.FROM_SWITCH);
final ConnectionAdapter connectionAdapter = getPrimaryConnectionContext().getConnectionAdapter();
- final PacketReceived packetReceived = packetInTranslator.translate(packetInMessage, this.getDeviceState(), null);
+ final PacketReceived packetReceived = packetInTranslator.translate(packetInMessage, deviceInfo, null);
if (packetReceived == null) {
LOG.debug("Received a null packet from switch {}", connectionAdapter.getRemoteAddress());
// lookup converter
final ExperimenterDataOfChoice vendorData = notification.getExperimenterDataOfChoice();
final MessageTypeKey<? extends ExperimenterDataOfChoice> key = new MessageTypeKey<>(
- deviceState.getVersion(),
+ deviceInfo.getVersion(),
(Class<? extends ExperimenterDataOfChoice>) vendorData.getImplementedInterface());
final ConvertorMessageFromOFJava<ExperimenterDataOfChoice, MessagePath> messageConverter = extensionConverterProvider.getMessageConverter(key);
if (messageConverter == null) {
LOG.warn("custom converter for {}[OF:{}] not found",
notification.getExperimenterDataOfChoice().getImplementedInterface(),
- deviceState.getVersion());
+ deviceInfo.getVersion());
return;
}
// build notification
try {
messageOfChoice = messageConverter.convert(vendorData, MessagePath.MESSAGE_NOTIFICATION);
final ExperimenterMessageFromDevBuilder experimenterMessageFromDevBld = new ExperimenterMessageFromDevBuilder()
- .setNode(new NodeRef(deviceState.getNodeInstanceIdentifier()))
+ .setNode(new NodeRef(deviceInfo.getNodeInstanceIdentifier()))
.setExperimenterMessageOfChoice(messageOfChoice);
// publish
notificationPublishService.offerNotification(experimenterMessageFromDevBld.build());
public synchronized void close() {
LOG.debug("closing deviceContext: {}, nodeId:{}",
getPrimaryConnectionContext().getConnectionAdapter().getRemoteAddress(),
- getDeviceState().getNodeId());
+ getDeviceInfo().getNodeId());
// NOOP
throw new UnsupportedOperationException("Autocloseble.close will be removed soon");
}
deviceCtxState = DEVICE_CONTEXT_STATE.TERMINATION;
if (ConnectionContext.CONNECTION_STATE.RIP.equals(getPrimaryConnectionContext().getConnectionState())) {
- LOG.debug("ConnectionCtx for Node {} is in RIP state.", deviceState.getNodeId());
+ LOG.debug("ConnectionCtx for Node {} is in RIP state.", deviceInfo.getNodeId());
return;
}
/* Terminate Auxiliary Connection */
import org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionConverterProvider;
import org.opendaylight.openflowplugin.impl.connection.OutboundQueueProviderImpl;
import org.opendaylight.openflowplugin.impl.device.listener.OpenflowProtocolListenerFullImpl;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
connectionAdapter.registerOutboundQueueHandler(outboundQueueProvider, barrierCountLimit, barrierIntervalNanos);
connectionContext.setOutboundQueueHandleRegistration(outboundQueueHandlerRegistration);
- final DeviceState deviceState = createDeviceState(connectionContext);
+ final DeviceState deviceState = new DeviceStateImpl();
final DeviceContext deviceContext = new DeviceContextImpl(connectionContext,
deviceState,
dataBroker,
return true;
}
- private static DeviceStateImpl createDeviceState(final @Nonnull ConnectionContext connectionContext) {
- return new DeviceStateImpl(connectionContext.getFeatures(), connectionContext.getNodeId());
- }
-
private void updatePacketInRateLimiters() {
synchronized (deviceContexts) {
final int deviceContextsSize = deviceContexts.size();
@Override
public void onDeviceContextLevelDown(final DeviceInfo deviceInfo) {
LOG.debug("onDeviceContextClosed for Node {}", deviceInfo.getNodeId());
- deviceContexts.remove(deviceInfo.getNodeId());
+ deviceContexts.remove(deviceInfo);
updatePacketInRateLimiters();
}
}
@Override
- public DeviceContext getDeviceContextFromNodeId(final NodeId nodeId) {
- return deviceContexts.get(nodeId);
+ public DeviceContext getDeviceContextFromNodeId(DeviceInfo deviceInfo) {
+ return deviceContexts.get(deviceInfo);
}
@Override
* DeviceState is builded from {@link FeaturesReply} and {@link NodeId}. Both values are inside
* {@link org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext}
*
- * @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
- * <p/>
- * Created: Mar 29, 2015
*/
class DeviceStateImpl implements DeviceState {
- private final GetFeaturesOutput featuresOutput;
- private final NodeId nodeId;
- private final KeyedInstanceIdentifier<Node, NodeKey> nodeII;
- private final short version;
private boolean valid;
private boolean meterIsAvailable;
private boolean groupIsAvailable;
private boolean statPollEnabled;
private boolean queueStatisticsAvailable;
- public DeviceStateImpl(@CheckForNull final FeaturesReply featuresReply, @Nonnull final NodeId nodeId) {
- Preconditions.checkArgument(featuresReply != null);
- featuresOutput = new GetFeaturesOutputBuilder(featuresReply).build();
- this.nodeId = Preconditions.checkNotNull(nodeId);
- nodeII = DeviceStateUtil.createNodeInstanceIdentifier(nodeId);
- version = featuresReply.getVersion();
+ DeviceStateImpl() {
statPollEnabled = false;
deviceSynchronized = false;
}
- @Override
- public NodeId getNodeId() {
- return nodeId;
- }
-
- @Override
- public KeyedInstanceIdentifier<Node, NodeKey> getNodeInstanceIdentifier() {
- return nodeII;
- }
-
- @Override
- public GetFeaturesOutput getFeatures() {
- return featuresOutput;
- }
-
@Override
public boolean isValid() {
return valid;
this.valid = valid;
}
- @Override
- public short getVersion() {
- return version;
- }
-
@Override
public boolean isMetersAvailable() {
return meterIsAvailable;
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.device.DeviceState;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
private final Object txLock = new Object();
private final KeyedInstanceIdentifier<Node, NodeKey> nodeII;
+ private final DeviceInfo deviceInfo;
private final DataBroker dataBroker;
private final LifecycleConductor conductor;
private TransactionChainManagerStatus transactionChainManagerStatus = TransactionChainManagerStatus.SLEEPING;
TransactionChainManager(@Nonnull final DataBroker dataBroker,
- @Nonnull final DeviceState deviceState,
+ @Nonnull final DeviceInfo deviceInfo,
@Nonnull final LifecycleConductor conductor) {
this.dataBroker = Preconditions.checkNotNull(dataBroker);
this.conductor = Preconditions.checkNotNull(conductor);
- this.nodeII = Preconditions.checkNotNull(deviceState.getNodeInstanceIdentifier());
+ this.deviceInfo = deviceInfo;
+ this.nodeII = deviceInfo.getNodeInstanceIdentifier();
this.transactionChainManagerStatus = TransactionChainManagerStatus.SLEEPING;
lastSubmittedFuture = Futures.immediateFuture(null);
- LOG.debug("created txChainManager for {}", nodeII);
+ LOG.debug("created txChainManager for {}", this.nodeII);
}
private NodeId nodeId() {
}
if (initCommit) {
LOG.error("Initial commit failed. {}", t);
- conductor.closeConnection(nodeId());
+ conductor.closeConnection(deviceInfo);
}
}
});
@Nullable
@Override
public <T> RequestContext<T> createRequestContext() {
- return new AbstractRequestContext<T>(conductor.reserveXidForDeviceMessage(deviceInfo.getNodeId())) {
+ return new AbstractRequestContext<T>(conductor.reserveXidForDeviceMessage(deviceInfo)) {
@Override
public void close() {
}
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.JdkFutureAdapters;
import com.google.common.util.concurrent.ListenableFuture;
-import io.netty.util.Timeout;
import io.netty.util.TimerTask;
import java.util.ArrayList;
@Override
public void onDeviceContextLevelUp(@CheckForNull final DeviceInfo deviceInfo) throws Exception {
- final DeviceContext deviceContext = Preconditions.checkNotNull(conductor.getDeviceContext(deviceInfo.getNodeId()));
+ final DeviceContext deviceContext = Preconditions.checkNotNull(conductor.getDeviceContext(deviceInfo));
final RoleContext roleContext = new RoleContextImpl(deviceInfo, entityOwnershipService, makeEntity(deviceInfo.getNodeId()), makeTxEntity(deviceInfo.getNodeId()), conductor);
roleContext.setSalRoleService(new SalRoleServiceImpl(roleContext, deviceContext));
Verify.verify(contexts.putIfAbsent(deviceInfo.getNodeId(), roleContext) == null, "Role context for master Node %s is still not closed.", deviceInfo.getNodeId());
makeDeviceRoleChange(OfpRole.BECOMESLAVE, roleContext, true);
/* First start to watch entity so we don't miss any notification, and then try to register in EOS */
- notifyListenersRoleInitializationDone(roleContext.getDeviceInfo().getNodeId(), roleContext.initialization());
+ notifyListenersRoleInitializationDone(roleContext.getDeviceInfo(), roleContext.initialization());
watchingEntities.put(roleContext.getEntity(), roleContext);
deviceInitializationPhaseHandler.onDeviceContextLevelUp(deviceInfo);
}
} else if ((ownershipChange.wasOwner() && !ownershipChange.isOwner()) || (ownershipChange.inJeopardy())) {
// MASTER -> SLAVE
LOG.debug("MASTER to SLAVE for node {}", roleContext.getDeviceInfo().getNodeId());
- conductor.addOneTimeListenerWhenServicesChangesDone(this, roleContext.getDeviceInfo().getNodeId());
+ conductor.addOneTimeListenerWhenServicesChangesDone(this, roleContext.getDeviceInfo());
makeDeviceRoleChange(OfpRole.BECOMESLAVE, roleContext, false);
}
} else {
final NodeId nodeId = roleContext.getDeviceInfo().getNodeId();
contexts.remove(nodeId, roleContext);
roleContext.close();
- conductor.closeConnection(nodeId);
+ conductor.closeConnection(roleContext.getDeviceInfo());
}
}
}
final NodeId nodeId = roleContext.getDeviceInfo().getNodeId();
contexts.remove(nodeId, roleContext);
roleContext.close();
- conductor.closeConnection(nodeId);
+ conductor.closeConnection(roleContext.getDeviceInfo());
}
}
}
final NodeId nodeId = roleContext.getDeviceInfo().getNodeId();
contexts.remove(nodeId, roleContext);
roleContext.close();
- conductor.closeConnection(nodeId);
+ conductor.closeConnection(roleContext.getDeviceInfo());
}
}
@Override
public void onSuccess(@Nullable final RpcResult<SetRoleOutput> setRoleOutputRpcResult) {
LOG.info("Role {} successfully set on device {}", role, roleContext.getDeviceInfo().getNodeId());
- notifyListenersRoleChangeOnDevice(roleContext.getDeviceInfo().getNodeId(), true, role, init);
+ notifyListenersRoleChangeOnDevice(roleContext.getDeviceInfo(), true, role, init);
}
@Override
public void onFailure(@Nonnull final Throwable throwable) {
LOG.warn("Unable to set role {} on device {}", role, roleContext.getDeviceInfo().getNodeId());
- notifyListenersRoleChangeOnDevice(roleContext.getDeviceInfo().getNodeId(), false, role, init);
+ notifyListenersRoleChangeOnDevice(roleContext.getDeviceInfo(), false, role, init);
}
});
}
ListenableFuture<RpcResult<SetRoleOutput>> sendRoleChangeToDevice(final OfpRole newRole, final RoleContext roleContext) {
LOG.debug("Sending new role {} to device {}", newRole, roleContext.getDeviceInfo().getNodeId());
final Future<RpcResult<SetRoleOutput>> setRoleOutputFuture;
- final Short version = conductor.gainVersionSafely(roleContext.getDeviceInfo().getNodeId());
+ final Short version = conductor.gainVersionSafely(roleContext.getDeviceInfo());
if (null == version) {
LOG.debug("Device version is null");
return Futures.immediateFuture(null);
final SetRoleInput setRoleInput = (new SetRoleInputBuilder()).setControllerRole(newRole)
.setNode(new NodeRef(DeviceStateUtil.createNodeInstanceIdentifier(roleContext.getDeviceInfo().getNodeId()))).build();
setRoleOutputFuture = roleContext.getSalRoleService().setRole(setRoleInput);
- final TimerTask timerTask = new TimerTask() {
-
- @Override
- public void run(final Timeout timeout) throws Exception {
- if (!setRoleOutputFuture.isDone()) {
- LOG.warn("New role {} was not propagated to device {} during 10 sec", newRole, roleContext.getDeviceInfo().getNodeId());
- setRoleOutputFuture.cancel(true);
- }
+ final TimerTask timerTask = timeout -> {
+ if (!setRoleOutputFuture.isDone()) {
+ LOG.warn("New role {} was not propagated to device {} during 10 sec", newRole, roleContext.getDeviceInfo().getNodeId());
+ setRoleOutputFuture.cancel(true);
}
};
conductor.newTimeout(timerTask, 10, TimeUnit.SECONDS);
}
@Override
- public void servicesChangeDone(final NodeId nodeId, final boolean success) {
- LOG.debug("Services stopping done for node {} as " + (success ? "successful" : "unsuccessful"), nodeId);
- final RoleContext roleContext = contexts.get(nodeId);
+ public void servicesChangeDone(final DeviceInfo deviceInfo, final boolean success) {
+ LOG.debug("Services stopping done for node {} as " + (success ? "successful" : "unsuccessful"), deviceInfo);
+ final RoleContext roleContext = contexts.get(deviceInfo.getNodeId());
if (null != roleContext) {
/* Services stopped or failure */
roleContext.unregisterCandidate(roleContext.getTxEntity());
/**
* Invoked when initialization phase is done
- * @param nodeId node identification
+ * @param deviceInfo node identification
* @param success true if initialization done ok, false otherwise
*/
@VisibleForTesting
- void notifyListenersRoleInitializationDone(final NodeId nodeId, final boolean success){
+ void notifyListenersRoleInitializationDone(final DeviceInfo deviceInfo, final boolean success){
LOG.debug("Notifying registered listeners for role initialization done, no. of listeners {}", listeners.size());
for (final RoleChangeListener listener : listeners) {
- listener.roleInitializationDone(nodeId, success);
+ listener.roleInitializationDone(deviceInfo, success);
}
}
/**
* Notifies registered listener on role change. Role is the new role on device
* If initialization phase is true, we may skip service starting
+ * @param deviceInfo
* @param success true if role change on device done ok, false otherwise
* @param role new role meant to be set on device
* @param initializationPhase if true, then skipp services start
*/
@VisibleForTesting
- void notifyListenersRoleChangeOnDevice(final NodeId nodeId, final boolean success, final OfpRole role, final boolean initializationPhase){
+ void notifyListenersRoleChangeOnDevice(final DeviceInfo deviceInfo, final boolean success, final OfpRole role, final boolean initializationPhase){
LOG.debug("Notifying registered listeners for role change, no. of listeners {}", listeners.size());
for (final RoleChangeListener listener : listeners) {
- listener.roleChangeOnDevice(nodeId, success, role, initializationPhase);
+ listener.roleChangeOnDevice(deviceInfo, success, role, initializationPhase);
}
}
@Override
public void onDeviceContextLevelUp(final DeviceInfo deviceInfo) throws Exception {
- final DeviceContext deviceContext = Preconditions.checkNotNull(conductor.getDeviceContext(deviceInfo.getNodeId()));
+ final DeviceContext deviceContext = Preconditions.checkNotNull(conductor.getDeviceContext(deviceInfo));
final RpcContext rpcContext = new RpcContextImpl(
rpcProviderRegistry,
deviceContext,
deviceContext.getMessageSpy(),
maxRequestsQuota,
- deviceContext.getDeviceState().getNodeInstanceIdentifier());
+ deviceInfo.getNodeInstanceIdentifier());
deviceContext.setRpcContext(rpcContext);
@Override
protected final FutureCallback<OfHeader> createCallback(final RequestContext<List<MultipartReply>> context, final Class<?> requestType) {
return new MultipartRequestOnTheFlyCallback(context, requestType,
- getDeviceContext().getMessageSpy(), getEventIdentifier(), getDeviceContext().getDeviceState(),
- getDeviceContext().getDeviceFlowRegistry(), getDeviceContext());
+ getDeviceContext().getMessageSpy(), getEventIdentifier(), getDeviceContext().getDeviceInfo(),
+ getDeviceContext().getDeviceFlowRegistry(), getDeviceContext(), getDeviceContext().getDeviceState());
}
import javax.annotation.Nonnull;
import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
private EventIdentifier eventIdentifier;
public AbstractService(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
- final DeviceState deviceState = deviceContext.getDeviceState();
- final GetFeaturesOutput features = deviceState.getFeatures();
+ final DeviceInfo deviceInfo = deviceContext.getDeviceInfo();
this.requestContextStack = requestContextStack;
this.deviceContext = deviceContext;
- this.datapathId = features.getDatapathId();
- this.version = features.getVersion();
+ this.datapathId = deviceInfo.getDatapathId();
+ this.version = deviceInfo.getVersion();
this.messageSpy = deviceContext.getMessageSpy();
- this.nodeId = deviceState.getNodeId();
+ this.nodeId = deviceInfo.getNodeId();
}
public EventIdentifier getEventIdentifier() {
import java.util.Collections;
import java.util.List;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
import org.opendaylight.openflowplugin.api.openflow.device.TxFacade;
final class MultipartRequestOnTheFlyCallback extends AbstractRequestCallback<List<MultipartReply>> {
private static final Logger LOG = LoggerFactory.getLogger(MultipartRequestOnTheFlyCallback.class);
private static final SinglePurposeMultipartReplyTranslator MULTIPART_REPLY_TRANSLATOR = new SinglePurposeMultipartReplyTranslator();
- private final DeviceState deviceState;
+ private final DeviceInfo deviceInfo;
private final DeviceFlowRegistry registry;
private boolean virgin = true;
private boolean finished = false;
private final EventIdentifier doneEventIdentifier;
private final TxFacade txFacade;
+ private final DeviceState deviceState;
public MultipartRequestOnTheFlyCallback(final RequestContext<List<MultipartReply>> context,
final Class<?> requestType,
final MessageSpy messageSpy,
final EventIdentifier eventIdentifier,
- final DeviceState deviceState,
+ final DeviceInfo deviceInfo,
final DeviceFlowRegistry registry,
- final TxFacade txFacade) {
+ final TxFacade txFacade,
+ final DeviceState deviceState) {
super(context, requestType, messageSpy, eventIdentifier);
- this.deviceState = deviceState;
+ 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(), deviceState.getNodeId().toString());
+ doneEventIdentifier = new EventIdentifier(MultipartType.OFPMPFLOW.name(), deviceInfo.getNodeId().toString());
}
public EventIdentifier getDoneEventIdentifier() {
final MultipartReply singleReply = multipartReply;
final List<? extends DataObject> multipartDataList = MULTIPART_REPLY_TRANSLATOR.translate(
- deviceState.getFeatures().getDatapathId(), deviceState.getFeatures().getVersion(), singleReply);
+ deviceInfo.getDatapathId(), deviceInfo.getVersion(), singleReply);
final Iterable<? extends DataObject> allMultipartData = multipartDataList;
//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(deviceState, registry, txFacade);
+ future = StatisticsGatheringUtils.deleteAllKnownFlows(deviceInfo, registry, txFacade, deviceState);
virgin = false;
} else {
future = Futures.immediateFuture(null);
@Override
public Void apply(final Void input) {
StatisticsGatheringUtils.writeFlowStatistics((Iterable<FlowsStatisticsUpdate>) allMultipartData,
- deviceState, registry, txFacade);
+ deviceInfo, registry, txFacade);
if (!multipartReply.getFlags().isOFPMPFREQMORE()) {
endCollecting();
}
if (itemLifecycleListener != null) {
KeyedInstanceIdentifier<Flow, FlowKey> flowPath = createFlowPath(flowDescriptor,
- deviceContext.getDeviceState().getNodeInstanceIdentifier());
+ deviceContext.getDeviceInfo().getNodeInstanceIdentifier());
final FlowBuilder flowBuilder = new FlowBuilder(input).setId(flowDescriptor.getFlowId());
itemLifecycleListener.onAdded(flowPath, flowBuilder.build());
}
deviceContext.getDeviceFlowRegistry().retrieveIdForFlow(flowRegistryKey);
if (flowDescriptor != null) {
KeyedInstanceIdentifier<Flow, FlowKey> flowPath = createFlowPath(flowDescriptor,
- deviceContext.getDeviceState().getNodeInstanceIdentifier());
+ deviceContext.getDeviceInfo().getNodeInstanceIdentifier());
itemLifecycleListener.onRemoved(flowPath);
}
}
final FlowDescriptor flowDescriptor = deviceContext.getDeviceFlowRegistry().retrieveIdForFlow(flowRegistryKey);
if (flowDescriptor != null) {
KeyedInstanceIdentifier<Flow, FlowKey> flowPath = createFlowPath(flowDescriptor,
- deviceContext.getDeviceState().getNodeInstanceIdentifier());
+ deviceContext.getDeviceInfo().getNodeInstanceIdentifier());
itemLifecycleListener.onRemoved(flowPath);
}
}
if (itemLifecycleListener != null) {
KeyedInstanceIdentifier<Flow, FlowKey> flowPath = createFlowPath(flowDescriptor,
- deviceContext.getDeviceState().getNodeInstanceIdentifier());
+ deviceContext.getDeviceInfo().getNodeInstanceIdentifier());
final FlowBuilder flowBuilder = new FlowBuilder(input.getUpdatedFlow()).setId(flowDescriptor.getFlowId());
itemLifecycleListener.onAdded(flowPath, flowBuilder.build());
}
if (itemLifecycleListener != null) {
KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group, GroupKey> groupPath
= createGroupPath(groupId,
- deviceContext.getDeviceState().getNodeInstanceIdentifier());
+ deviceContext.getDeviceInfo().getNodeInstanceIdentifier());
itemLifecycleListener.onRemoved(groupPath);
}
}
if (itemLifecycleListener != null) {
KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group, GroupKey> groupPath
= createGroupPath(groupId,
- deviceContext.getDeviceState().getNodeInstanceIdentifier());
+ deviceContext.getDeviceInfo().getNodeInstanceIdentifier());
itemLifecycleListener.onAdded(groupPath, new GroupBuilder(data).build());
}
}
if (itemLifecycleListener != null) {
KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter, MeterKey> meterPath
= createMeterPath(meterId,
- deviceContext.getDeviceState().getNodeInstanceIdentifier());
+ deviceContext.getDeviceInfo().getNodeInstanceIdentifier());
itemLifecycleListener.onRemoved(meterPath);
}
}
if (itemLifecycleListener != null) {
KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter, MeterKey> groupPath
= createMeterPath(meterId,
- deviceContext.getDeviceState().getNodeInstanceIdentifier());
+ deviceContext.getDeviceInfo().getNodeInstanceIdentifier());
itemLifecycleListener.onAdded(groupPath, new MeterBuilder(data).build());
}
}
private volatile boolean schedulingEnabled;
StatisticsContextImpl(@CheckForNull final DeviceInfo deviceInfo, final boolean shuttingDownStatisticsPolling, final LifecycleConductor lifecycleConductor) {
- this.deviceContext = Preconditions.checkNotNull(lifecycleConductor.getDeviceContext(deviceInfo.getNodeId()));
+ this.deviceContext = Preconditions.checkNotNull(lifecycleConductor.getDeviceContext(deviceInfo));
this.devState = Preconditions.checkNotNull(deviceContext.getDeviceState());
this.shuttingDownStatisticsPolling = shuttingDownStatisticsPolling;
emptyFuture = Futures.immediateFuture(false);
@Override
public ListenableFuture<Boolean> gatherDynamicData() {
if (shuttingDownStatisticsPolling) {
- LOG.debug("Statistics for device {} is not enabled.", deviceContext.getDeviceState().getNodeId());
+ LOG.debug("Statistics for device {} is not enabled.", deviceContext.getDeviceInfo().getNodeId());
return Futures.immediateFuture(Boolean.TRUE);
}
final ListenableFuture<Boolean> errorResultFuture = deviceConnectionCheck();
private void statChainFuture(final Iterator<MultipartType> iterator, final SettableFuture<Boolean> resultFuture) {
if (ConnectionContext.CONNECTION_STATE.RIP.equals(deviceContext.getPrimaryConnectionContext().getConnectionState())) {
final String errMsg = String.format("Device connection is closed for Node : %s.",
- deviceContext.getDeviceState().getNodeId());
+ deviceContext.getDeviceInfo().getNodeId());
LOG.debug(errMsg);
resultFuture.setException(new IllegalStateException(errMsg));
return;
}
if ( ! iterator.hasNext()) {
resultFuture.set(Boolean.TRUE);
- LOG.debug("Stats collection successfully finished for node {}", deviceContext.getDeviceState().getNodeId());
+ LOG.debug("Stats collection successfully finished for node {}", deviceContext.getDeviceInfo().getNodeId());
return;
}
final MultipartType nextType = iterator.next();
- LOG.debug("Stats iterating to next type for node {} of type {}", deviceContext.getDeviceState().getNodeId(), nextType);
+ LOG.debug("Stats iterating to next type for node {} of type {}", deviceContext.getDeviceInfo().getNodeId(), nextType);
final ListenableFuture<Boolean> deviceStatisticsCollectionFuture = chooseStat(nextType);
Futures.addCallback(deviceStatisticsCollectionFuture, new FutureCallback<Boolean>() {
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
import org.opendaylight.openflowplugin.api.openflow.device.TxFacade;
import org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry;
public ListenableFuture<Boolean> apply(final RpcResult<List<MultipartReply>> rpcResult) {
boolean isMultipartProcessed = Boolean.TRUE;
if (rpcResult.isSuccessful()) {
- LOG.debug("Stats reply successfully received for node {} of type {}", deviceContext.getDeviceState().getNodeId(), type);
+ LOG.debug("Stats reply successfully received for node {} of type {}", deviceContext.getDeviceInfo().getNodeId(), type);
// TODO: in case the result value is null then multipart data probably got processed on the fly -
// TODO: this contract should by clearly stated and enforced - now simple true value is returned
}
} catch (final Exception e) {
LOG.warn("stats processing of type {} for node {} failed during transfomation step",
- type, deviceContext.getDeviceState().getNodeId(), e);
+ type, deviceContext.getDeviceInfo().getNodeId(), e);
return Futures.immediateFailedFuture(e);
}
}
} catch (final Exception e) {
LOG.warn("stats processing of type {} for node {} failed during write-to-tx step",
- type, deviceContext.getDeviceState().getNodeId(), e);
+ type, deviceContext.getDeviceInfo().getNodeId(), e);
return Futures.immediateFailedFuture(e);
}
- LOG.debug("Stats reply added to transaction for node {} of type {}", deviceContext.getDeviceState().getNodeId(), type);
+ LOG.debug("Stats reply added to transaction for node {} of type {}", deviceContext.getDeviceInfo().getNodeId(), type);
//TODO : implement experimenter
} else {
- LOG.debug("Stats reply was empty for node {} of type {}", deviceContext.getDeviceState().getNodeId(), type);
+ LOG.debug("Stats reply was empty for node {} of type {}", deviceContext.getDeviceInfo().getNodeId(), type);
}
} else {
- LOG.debug("Stats reply FAILED for node {} of type {}: {}", deviceContext.getDeviceState().getNodeId(), type, rpcResult.getErrors());
+ LOG.debug("Stats reply FAILED for node {} of type {}: {}", deviceContext.getDeviceInfo().getNodeId(), type, rpcResult.getErrors());
isMultipartProcessed = Boolean.FALSE;
}
return Futures.immediateFuture(isMultipartProcessed);
}
private static void processMeterConfigStatsUpdated(final Iterable<MeterConfigStatsUpdated> data, final DeviceContext deviceContext) throws Exception {
- final InstanceIdentifier<FlowCapableNode> fNodeIdent = assembleFlowCapableNodeInstanceIdentifier(deviceContext.getDeviceState());
+ final InstanceIdentifier<FlowCapableNode> fNodeIdent = assembleFlowCapableNodeInstanceIdentifier(deviceContext.getDeviceInfo());
deleteAllKnownMeters(deviceContext, fNodeIdent);
for (final MeterConfigStatsUpdated meterConfigStatsUpdated : data) {
for (final MeterConfigStats meterConfigStats : meterConfigStatsUpdated.getMeterConfigStats()) {
private static ListenableFuture<Boolean> processFlowStatistics(final Iterable<FlowsStatisticsUpdate> data,
final DeviceContext deviceContext, final EventIdentifier eventIdentifier) {
- final ListenableFuture<Void> deleFuture = deleteAllKnownFlows(deviceContext.getDeviceState(),
- deviceContext.getDeviceFlowRegistry(), deviceContext);
+ final ListenableFuture<Void> deleFuture = deleteAllKnownFlows(deviceContext.getDeviceInfo(),
+ deviceContext.getDeviceFlowRegistry(), deviceContext, deviceContext.getDeviceState());
return Futures.transform(deleFuture, new Function<Void, Boolean>() {
@Override
public Boolean apply(final Void input) {
- writeFlowStatistics(data, deviceContext.getDeviceState(), deviceContext.getDeviceFlowRegistry(),
+ writeFlowStatistics(data, deviceContext.getDeviceInfo(), deviceContext.getDeviceFlowRegistry(),
deviceContext);
deviceContext.submitTransaction();
EventsTimeCounter.markEnd(eventIdentifier);
}
public static void writeFlowStatistics(final Iterable<FlowsStatisticsUpdate> data,
- final DeviceState deviceState,
+ final DeviceInfo deviceInfo,
final DeviceFlowRegistry registry,
final TxFacade txFacade) {
- final InstanceIdentifier<FlowCapableNode> fNodeIdent = assembleFlowCapableNodeInstanceIdentifier(deviceState);
+ final InstanceIdentifier<FlowCapableNode> fNodeIdent = assembleFlowCapableNodeInstanceIdentifier(deviceInfo);
try {
for (final FlowsStatisticsUpdate flowsStatistics : data) {
for (final FlowAndStatisticsMapList flowStat : flowsStatistics.getFlowAndStatisticsMapList()) {
return flowStatisticsDataBld;
}
- public static ListenableFuture<Void> deleteAllKnownFlows(final DeviceState deviceState,
+ public static ListenableFuture<Void> deleteAllKnownFlows(final DeviceInfo deviceInfo,
final DeviceFlowRegistry registry,
- final TxFacade txFacade) {
+ 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(deviceState);
+ final InstanceIdentifier<FlowCapableNode> flowCapableNodePath = assembleFlowCapableNodeInstanceIdentifier(deviceInfo);
final ReadOnlyTransaction readTx = txFacade.getReadTransaction();
final CheckedFuture<Optional<FlowCapableNode>, ReadFailedException> flowCapableNodeFuture = readTx.read(
LogicalDatastoreType.OPERATIONAL, flowCapableNodePath);
private static void processQueueStatistics(final Iterable<QueueStatisticsUpdate> data, final DeviceContext deviceContext) throws Exception {
// TODO: clean all queues of all node-connectors before writing up-to-date stats
- final InstanceIdentifier<Node> nodeIdent = deviceContext.getDeviceState().getNodeInstanceIdentifier();
+ final InstanceIdentifier<Node> nodeIdent = deviceContext.getDeviceInfo().getNodeInstanceIdentifier();
for (final QueueStatisticsUpdate queueStatisticsUpdate : data) {
for (final QueueIdAndStatisticsMap queueStat : queueStatisticsUpdate.getQueueIdAndStatisticsMap()) {
if (queueStat.getQueueId() != null) {
}
private static void processFlowTableStatistics(final Iterable<FlowTableStatisticsUpdate> data, final DeviceContext deviceContext) throws Exception {
- final InstanceIdentifier<FlowCapableNode> fNodeIdent = assembleFlowCapableNodeInstanceIdentifier(deviceContext.getDeviceState());
+ final InstanceIdentifier<FlowCapableNode> fNodeIdent = assembleFlowCapableNodeInstanceIdentifier(deviceContext.getDeviceInfo());
for (final FlowTableStatisticsUpdate flowTableStatisticsUpdate : data) {
for (final FlowTableAndStatisticsMap tableStat : flowTableStatisticsUpdate.getFlowTableAndStatisticsMap()) {
}
private static void processNodeConnectorStatistics(final Iterable<NodeConnectorStatisticsUpdate> data, final DeviceContext deviceContext) throws Exception {
- final InstanceIdentifier<Node> nodeIdent = deviceContext.getDeviceState().getNodeInstanceIdentifier();
+ final InstanceIdentifier<Node> nodeIdent = deviceContext.getDeviceInfo().getNodeInstanceIdentifier();
for (final NodeConnectorStatisticsUpdate nodeConnectorStatisticsUpdate : data) {
for (final NodeConnectorStatisticsAndPortNumberMap nConnectPort : nodeConnectorStatisticsUpdate.getNodeConnectorStatisticsAndPortNumberMap()) {
final FlowCapableNodeConnectorStatistics stats = new FlowCapableNodeConnectorStatisticsBuilder(nConnectPort).build();
private static void processMetersStatistics(final Iterable<MeterStatisticsUpdated> data,
final DeviceContext deviceContext) throws Exception {
- final InstanceIdentifier<FlowCapableNode> fNodeIdent = assembleFlowCapableNodeInstanceIdentifier(deviceContext.getDeviceState());
+ final InstanceIdentifier<FlowCapableNode> fNodeIdent = assembleFlowCapableNodeInstanceIdentifier(deviceContext.getDeviceInfo());
for (final MeterStatisticsUpdated meterStatisticsUpdated : data) {
for (final MeterStats mStat : meterStatisticsUpdated.getMeterStats()) {
final MeterStatistics stats = new MeterStatisticsBuilder(mStat).build();
private static void processGroupDescStats(final Iterable<GroupDescStatsUpdated> data, final DeviceContext deviceContext) throws Exception {
final InstanceIdentifier<FlowCapableNode> fNodeIdent =
- deviceContext.getDeviceState().getNodeInstanceIdentifier().augmentation(FlowCapableNode.class);
+ deviceContext.getDeviceInfo().getNodeInstanceIdentifier().augmentation(FlowCapableNode.class);
deleteAllKnownGroups(deviceContext, fNodeIdent);
for (final GroupDescStatsUpdated groupDescStatsUpdated : data) {
}
private static void processGroupStatistics(final Iterable<GroupStatisticsUpdated> data, final DeviceContext deviceContext) throws Exception {
- final InstanceIdentifier<FlowCapableNode> fNodeIdent = assembleFlowCapableNodeInstanceIdentifier(deviceContext.getDeviceState());
+ final InstanceIdentifier<FlowCapableNode> fNodeIdent = assembleFlowCapableNodeInstanceIdentifier(deviceContext.getDeviceInfo());
for (final GroupStatisticsUpdated groupStatistics : data) {
for (final GroupStats groupStats : groupStatistics.getGroupStats()) {
deviceContext.submitTransaction();
}
- private static InstanceIdentifier<FlowCapableNode> assembleFlowCapableNodeInstanceIdentifier(final DeviceState deviceState) {
- return deviceState.getNodeInstanceIdentifier().augmentation(FlowCapableNode.class);
+ private static InstanceIdentifier<FlowCapableNode> assembleFlowCapableNodeInstanceIdentifier(final DeviceInfo deviceInfo) {
+ return deviceInfo.getNodeInstanceIdentifier().augmentation(FlowCapableNode.class);
}
/**
* @param deviceContext txManager + node path keeper
*/
static void markDeviceStateSnapshotStart(final DeviceContext deviceContext) {
- final InstanceIdentifier<FlowCapableStatisticsGatheringStatus> statusPath = deviceContext.getDeviceState()
+ final InstanceIdentifier<FlowCapableStatisticsGatheringStatus> statusPath = deviceContext.getDeviceInfo()
.getNodeInstanceIdentifier().augmentation(FlowCapableStatisticsGatheringStatus.class);
final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_AND_TIME_FORMAT);
* @param succeeded outcome of currently finished gathering
*/
static void markDeviceStateSnapshotEnd(final DeviceContext deviceContext, final boolean succeeded) {
- final InstanceIdentifier<SnapshotGatheringStatusEnd> statusEndPath = deviceContext.getDeviceState()
+ final InstanceIdentifier<SnapshotGatheringStatusEnd> statusEndPath = deviceContext.getDeviceInfo()
.getNodeInstanceIdentifier().augmentation(FlowCapableStatisticsGatheringStatus.class)
.child(SnapshotGatheringStatusEnd.class);
@Override
public void onDeviceContextLevelUp(final DeviceInfo deviceInfo) throws Exception {
- final DeviceContext deviceContext = Preconditions.checkNotNull(conductor.getDeviceContext(deviceInfo.getNodeId()));
+ final DeviceContext deviceContext = Preconditions.checkNotNull(conductor.getDeviceContext(deviceInfo));
final StatisticsContext statisticsContext = new StatisticsContextImpl(deviceInfo, shuttingDownStatisticsPolling, conductor);
Verify.verify(contexts.putIfAbsent(deviceInfo, statisticsContext) == null, "StatisticsCtx still not closed for Node {}", deviceInfo.getNodeId());
final StatisticsContext statisticsContext,
final TimeCounter timeCounter) {
- final NodeId nodeId = deviceContext.getDeviceState().getNodeId();
+ final NodeId nodeId = deviceContext.getDeviceInfo().getNodeId();
if (!statisticsContext.isSchedulingEnabled()) {
LOG.debug("Disabling statistics scheduling for device: {}", nodeId);
calculateTimerDelay(timeCounter);
if (throwable instanceof CancellationException) {
/** This often happens when something wrong with akka or DS, so closing connection will help to restart device **/
- conductor.closeConnection(deviceContext.getDeviceState().getNodeId());
+ conductor.closeConnection(deviceContext.getDeviceInfo());
} else {
scheduleNextPolling(deviceContext, statisticsContext, timeCounter);
}
private void scheduleNextPolling(final DeviceContext deviceContext,
final StatisticsContext statisticsContext,
final TimeCounter timeCounter) {
- LOG.debug("SCHEDULING NEXT STATISTICS POLLING for device: {}", deviceContext.getDeviceState().getNodeId());
+ LOG.debug("SCHEDULING NEXT STATISTICS POLLING for device: {}", deviceContext.getDeviceInfo().getNodeId());
if (!shuttingDownStatisticsPolling) {
final Timeout pollTimeout = conductor.newTimeout(timeout -> pollStatistics(deviceContext, statisticsContext, timeCounter), currentTimerDelay, TimeUnit.MILLISECONDS);
statisticsContext.setPollTimeout(pollTimeout);
}
LOG.info("Scheduling statistics poll for device: {}", deviceInfo.getNodeId());
- final DeviceContext deviceContext = conductor.getDeviceContext(deviceInfo.getNodeId());
+ final DeviceContext deviceContext = conductor.getDeviceContext(deviceInfo);
if (deviceContext == null) {
LOG.warn("Device context not found for device: {}", deviceInfo.getNodeId());
final TranslatorKey translatorKey = new TranslatorKey(mpReply.getVersion(), MultipartReplyAggregateCase.class.getName());
final MessageTranslator<MultipartReply, AggregatedFlowStatistics> messageTranslator = translatorLibrary.lookupTranslator(translatorKey);
- final AggregatedFlowStatistics flowStatistics = messageTranslator.translate(mpReply, getDeviceContext().getDeviceState(), null);
+ final AggregatedFlowStatistics flowStatistics = messageTranslator.translate(mpReply, getDeviceContext().getDeviceInfo(), null);
final AggregateFlowStatisticsUpdateBuilder notification = new AggregateFlowStatisticsUpdateBuilder(flowStatistics)
- .setId(getDeviceContext().getDeviceState().getNodeId())
+ .setId(getDeviceContext().getDeviceInfo().getNodeId())
.setMoreReplies(Boolean.FALSE)
.setTransactionId(emulatedTxId);
@Override
public FlowsStatisticsUpdate transformToNotification(List<MultipartReply> result, TransactionId emulatedTxId) {
- return FlowStatisticsToNotificationTransformer.transformToNotification(result, getDeviceContext().getDeviceState(), getOfVersion(), emulatedTxId);
+ return FlowStatisticsToNotificationTransformer.transformToNotification(result, getDeviceContext().getDeviceInfo(), getOfVersion(), emulatedTxId);
}
}
@Override
public FlowsStatisticsUpdate transformToNotification(List<MultipartReply> mpResult, TransactionId emulatedTxId) {
- return FlowStatisticsToNotificationTransformer.transformToNotification(mpResult, getDeviceContext().getDeviceState(), getOfVersion(), emulatedTxId);
+ return FlowStatisticsToNotificationTransformer.transformToNotification(mpResult, getDeviceContext().getDeviceInfo(), getOfVersion(), emulatedTxId);
}
}
@Override
public GroupStatisticsUpdated transformToNotification(List<MultipartReply> result, TransactionId emulatedTxId) {
- return GroupStatisticsToNotificationTransformer.transformToNotification(result, getDeviceContext().getDeviceState(), getOfVersion(), emulatedTxId);
+ return GroupStatisticsToNotificationTransformer.transformToNotification(result, getDeviceContext().getDeviceInfo(), emulatedTxId);
}
}
@Override
public MeterConfigStatsUpdated transformToNotification(List<MultipartReply> result, TransactionId emulatedTxId) {
MeterConfigStatsUpdatedBuilder message = new MeterConfigStatsUpdatedBuilder();
- message.setId(getDeviceContext().getDeviceState().getNodeId());
+ message.setId(getDeviceContext().getDeviceInfo().getNodeId());
message.setMoreReplies(Boolean.FALSE);
message.setTransactionId(emulatedTxId);
@Override
public MeterStatisticsUpdated transformToNotification(List<MultipartReply> result, TransactionId emulatedTxId) {
- return MeterStatisticsToNotificationTransformer.transformToNotification(result, getDeviceContext().getDeviceState(), getOfVersion(), emulatedTxId);
+ return MeterStatisticsToNotificationTransformer.transformToNotification(result, getDeviceContext().getDeviceInfo(), getOfVersion(), emulatedTxId);
}
}
@Override
public QueueStatisticsUpdate transformToNotification(List<MultipartReply> result, TransactionId emulatedTxId) {
- return QueueStatisticsToNotificationTransformer.transformToNotification(result, getDeviceContext().getDeviceState(), getOfVersion(), emulatedTxId);
+ return QueueStatisticsToNotificationTransformer.transformToNotification(result, getDeviceContext().getDeviceInfo(), getOfVersion(), emulatedTxId);
}
}
@Override
public QueueStatisticsUpdate transformToNotification(List<MultipartReply> result, TransactionId emulatedTxId) {
- return QueueStatisticsToNotificationTransformer.transformToNotification(result, getDeviceContext().getDeviceState(), getOfVersion(), emulatedTxId);
+ return QueueStatisticsToNotificationTransformer.transformToNotification(result, getDeviceContext().getDeviceInfo(), getOfVersion(), emulatedTxId);
}
}
@Override
public FlowsStatisticsUpdate transformToNotification(List<MultipartReply> result, TransactionId emulatedTxId) {
- return FlowStatisticsToNotificationTransformer.transformToNotification(result, getDeviceContext().getDeviceState(), getOfVersion(), emulatedTxId);
+ return FlowStatisticsToNotificationTransformer.transformToNotification(result, getDeviceContext().getDeviceInfo(), getOfVersion(), emulatedTxId);
}
}
@Override
public GroupDescStatsUpdated transformToNotification(List<MultipartReply> result, TransactionId emulatedTxId) {
GroupDescStatsUpdatedBuilder notification = new GroupDescStatsUpdatedBuilder();
- notification.setId(getDeviceContext().getDeviceState().getNodeId());
+ notification.setId(getDeviceContext().getDeviceInfo().getNodeId());
notification.setMoreReplies(Boolean.FALSE);
notification.setTransactionId(emulatedTxId);
Preconditions.checkArgument(mpSize == 1, "unexpected (!=1) mp-reply size received: {}", mpSize);
GroupFeaturesUpdatedBuilder notification = new GroupFeaturesUpdatedBuilder();
- notification.setId(getDeviceContext().getDeviceState().getNodeId());
+ notification.setId(getDeviceContext().getDeviceInfo().getNodeId());
notification.setMoreReplies(Boolean.FALSE);
notification.setTransactionId(emulatedTxId);
@Override
public GroupStatisticsUpdated transformToNotification(List<MultipartReply> result, TransactionId emulatedTxId) {
- return GroupStatisticsToNotificationTransformer.transformToNotification(result, getDeviceContext().getDeviceState(), getOfVersion(), emulatedTxId);
+ return GroupStatisticsToNotificationTransformer.transformToNotification(result, getDeviceContext().getDeviceInfo(), emulatedTxId);
}
}
Preconditions.checkArgument(mpSize == 1, "unexpected (!=1) mp-reply size received: {}", mpSize);
MeterFeaturesUpdatedBuilder notification = new MeterFeaturesUpdatedBuilder();
- notification.setId(getDeviceContext().getDeviceState().getNodeId());
+ notification.setId(getDeviceContext().getDeviceInfo().getNodeId());
notification.setMoreReplies(Boolean.FALSE);
notification.setTransactionId(emulatedTxId);
@Override
public MeterStatisticsUpdated transformToNotification(List<MultipartReply> result, TransactionId emulatedTxId) {
- return MeterStatisticsToNotificationTransformer.transformToNotification(result, getDeviceContext().getDeviceState(), getOfVersion(), emulatedTxId);
+ return MeterStatisticsToNotificationTransformer.transformToNotification(result, getDeviceContext().getDeviceInfo(), getOfVersion(), emulatedTxId);
}
}
@Override
public QueueStatisticsUpdate transformToNotification(List<MultipartReply> result, TransactionId emulatedTxId) {
- return QueueStatisticsToNotificationTransformer.transformToNotification(result, getDeviceContext().getDeviceState(), getOfVersion(), emulatedTxId);
+ return QueueStatisticsToNotificationTransformer.transformToNotification(result, getDeviceContext().getDeviceInfo(), getOfVersion(), emulatedTxId);
}
}
List<AggregatedFlowStatistics> aggregStats = new ArrayList<AggregatedFlowStatistics>();
for (MultipartReply multipartReply : input.getResult()) {
- aggregStats.add(messageTranslator.translate(multipartReply, deviceContext.getDeviceState(), null));
+ aggregStats.add(messageTranslator.translate(multipartReply, deviceContext.getDeviceInfo(), null));
}
GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder getAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder =
@Override
public FlowTableStatisticsUpdate transformToNotification(List<MultipartReply> mpReplyList, TransactionId emulatedTxId) {
FlowTableStatisticsUpdateBuilder notification = new FlowTableStatisticsUpdateBuilder();
- notification.setId(getDeviceContext().getDeviceState().getNodeId());
+ notification.setId(getDeviceContext().getDeviceInfo().getNodeId());
notification.setMoreReplies(Boolean.FALSE);
notification.setTransactionId(emulatedTxId);
import com.google.common.base.Preconditions;
import java.util.ArrayList;
import java.util.List;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
+
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.FlowStatsResponseConvertor;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowsStatisticsUpdate;
/**
* @param mpResult raw multipart response from device
- * @param deviceState device state
+ * @param deviceInfo device state
* @param ofVersion device version
* @param emulatedTxId
* @return notification containing flow stats
*/
public static FlowsStatisticsUpdate transformToNotification(final List<MultipartReply> mpResult,
- final DeviceState deviceState,
+ final DeviceInfo deviceInfo,
final OpenflowVersion ofVersion,
final TransactionId emulatedTxId) {
final FlowsStatisticsUpdateBuilder notification = new FlowsStatisticsUpdateBuilder();
final List<FlowAndStatisticsMapList> statsList = new ArrayList<>();
- notification.setId(deviceState.getNodeId());
+ notification.setId(deviceInfo.getNodeId());
notification.setFlowAndStatisticsMapList(statsList);
notification.setMoreReplies(Boolean.FALSE);
notification.setTransactionId(emulatedTxId);
MultipartReplyFlow replyBody = caseBody.getMultipartReplyFlow();
List<FlowAndStatisticsMapList> outStatsItem = flowStatsConvertor.toSALFlowStatsList(
replyBody.getFlowStats(),
- deviceState.getFeatures().getDatapathId(),
+ deviceInfo.getDatapathId(),
ofVersion);
statsList.addAll(outStatsItem);
}
import java.util.ArrayList;
import java.util.List;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
-import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
+
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.GroupStatsResponseConvertor;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupStatisticsUpdated;
/**
* @param mpReplyList raw multipart response from device
- * @param deviceState device state
- * @param ofVersion device version
+ * @param deviceInfo device state
* @param emulatedTxId
* @return notification containing flow stats
*/
public static GroupStatisticsUpdated transformToNotification(final List<MultipartReply> mpReplyList,
- final DeviceState deviceState,
- final OpenflowVersion ofVersion,
+ final DeviceInfo deviceInfo,
final TransactionId emulatedTxId) {
GroupStatisticsUpdatedBuilder notification = new GroupStatisticsUpdatedBuilder();
- notification.setId(deviceState.getNodeId());
+ notification.setId(deviceInfo.getNodeId());
notification.setMoreReplies(Boolean.FALSE);
notification.setTransactionId(emulatedTxId);
import java.util.ArrayList;
import java.util.List;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
+
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.MeterStatsResponseConvertor;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionId;
/**
* @param mpReplyList raw multipart response from device
- * @param deviceState device state
+ * @param deviceInfo device state
* @param ofVersion device version
* @param emulatedTxId
* @return notification containing flow stats
*/
public static MeterStatisticsUpdated transformToNotification(final List<MultipartReply> mpReplyList,
- final DeviceState deviceState,
+ final DeviceInfo deviceInfo,
final OpenflowVersion ofVersion,
final TransactionId emulatedTxId) {
MeterStatisticsUpdatedBuilder notification = new MeterStatisticsUpdatedBuilder();
- notification.setId(deviceState.getNodeId());
+ notification.setId(deviceInfo.getNodeId());
notification.setMoreReplies(Boolean.FALSE);
notification.setTransactionId(emulatedTxId);
final TransactionId emulatedTxId) {
NodeConnectorStatisticsUpdateBuilder notification = new NodeConnectorStatisticsUpdateBuilder();
- notification.setId(deviceContext.getDeviceState().getNodeId());
+ notification.setId(deviceContext.getDeviceInfo().getNodeId());
notification.setMoreReplies(Boolean.FALSE);
notification.setTransactionId(emulatedTxId);
new NodeConnectorStatisticsAndPortNumberMapBuilder();
statsBuilder.setNodeConnectorId(
InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(
- deviceContext.getDeviceState().getFeatures().getDatapathId(),
+ deviceContext.getDeviceInfo().getDatapathId(),
portStats.getPortNo(), ofVersion));
BytesBuilder bytesBuilder = new BytesBuilder();
import java.util.ArrayList;
import java.util.List;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
+
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.Counter32;
/**
* @param mpReplyList raw multipart response from device
- * @param deviceState device state
+ * @param deviceInfo device state
* @param ofVersion device version
* @param emulatedTxId
* @return notification containing flow stats
*/
public static QueueStatisticsUpdate transformToNotification(final List<MultipartReply> mpReplyList,
- final DeviceState deviceState,
+ final DeviceInfo deviceInfo,
final OpenflowVersion ofVersion,
final TransactionId emulatedTxId) {
QueueStatisticsUpdateBuilder notification = new QueueStatisticsUpdateBuilder();
- notification.setId(deviceState.getNodeId());
+ notification.setId(deviceInfo.getNodeId());
notification.setMoreReplies(Boolean.FALSE);
notification.setTransactionId(emulatedTxId);
new QueueIdAndStatisticsMapBuilder();
statsBuilder.setNodeConnectorId(
InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(
- deviceState.getFeatures().getDatapathId(),
+ deviceInfo.getDatapathId(),
queueStats.getPortNo(), ofVersion));
statsBuilder.setTransmissionErrors(new Counter64(queueStats.getTxErrors()));
statsBuilder.setTransmittedBytes(new Counter64(queueStats.getTxBytes()));
@Override
protected void storeStatistics(GetFlowStatisticsOutput output) throws Exception {
final InstanceIdentifier<FlowCapableNode> nodePath = getDeviceContext()
- .getDeviceState().getNodeInstanceIdentifier().augmentation(FlowCapableNode.class);
+ .getDeviceInfo().getNodeInstanceIdentifier().augmentation(FlowCapableNode.class);
for (final FlowAndStatisticsMapList flowStatistics : output.getFlowAndStatisticsMapList()) {
final FlowId flowId = generateFlowId(flowStatistics);
@Override
protected void storeStatistics(GetGroupStatisticsOutput output) throws Exception {
final InstanceIdentifier<FlowCapableNode> nodePath = getDeviceContext()
- .getDeviceState().getNodeInstanceIdentifier().augmentation(FlowCapableNode.class);
+ .getDeviceInfo().getNodeInstanceIdentifier().augmentation(FlowCapableNode.class);
for (final GroupStats groupStatistics : output.getGroupStats()) {
final InstanceIdentifier<GroupStatistics> groupStatisticsPath = nodePath
@Override
protected void storeStatistics(GetMeterStatisticsOutput output) throws Exception {
final InstanceIdentifier<FlowCapableNode> nodePath = getDeviceContext()
- .getDeviceState().getNodeInstanceIdentifier().augmentation(FlowCapableNode.class);
+ .getDeviceInfo().getNodeInstanceIdentifier().augmentation(FlowCapableNode.class);
for (final MeterStats meterStatistics : output.getMeterStats()) {
final InstanceIdentifier<MeterStatistics> meterPath = nodePath
@Override
protected void storeStatistics(GetNodeConnectorStatisticsOutput output) throws Exception {
- final InstanceIdentifier<Node> nodePath = getDeviceContext().getDeviceState().getNodeInstanceIdentifier();
+ final InstanceIdentifier<Node> nodePath = getDeviceContext().getDeviceInfo().getNodeInstanceIdentifier();
for (final NodeConnectorStatisticsAndPortNumberMap nodeConnectorStatistics : output.getNodeConnectorStatisticsAndPortNumberMap()) {
final InstanceIdentifier<FlowCapableNodeConnectorStatistics> nodeConnectorPath = nodePath
@Override
protected void storeStatistics(GetQueueStatisticsOutput output) throws Exception {
- final InstanceIdentifier<Node> nodePath = getDeviceContext().getDeviceState().getNodeInstanceIdentifier();
+ final InstanceIdentifier<Node> nodePath = getDeviceContext().getDeviceInfo().getNodeInstanceIdentifier();
for (final QueueIdAndStatisticsMap queueStatistics : output.getQueueIdAndStatisticsMap()) {
if (queueStatistics.getQueueId() != null) {
package org.opendaylight.openflowplugin.impl.translator;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.device.MessageTranslator;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.Counter32;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.Counter64;
*/
public class AggregatedFlowStatisticsTranslator implements MessageTranslator<MultipartReply, AggregatedFlowStatistics> {
@Override
- public AggregatedFlowStatistics translate(final MultipartReply input, final DeviceState deviceState, final Object connectionDistinguisher) {
+ public AggregatedFlowStatistics translate(final MultipartReply input, final DeviceInfo deviceInfo, final Object connectionDistinguisher) {
AggregatedFlowStatisticsBuilder aggregatedFlowStatisticsBuilder = new AggregatedFlowStatisticsBuilder();
MultipartReplyAggregateCase caseBody = (MultipartReplyAggregateCase)input.getMultipartReplyBody();
*/
package org.opendaylight.openflowplugin.impl.translator;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.device.MessageTranslator;
import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchConvertorImpl;
public class FlowRemovedTranslator implements MessageTranslator<FlowRemoved, org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemoved> {
@Override
- public org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemoved translate(FlowRemoved input, DeviceState deviceState, Object connectionDistinguisher) {
+ public org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowRemoved translate(FlowRemoved input, DeviceInfo deviceInfo, Object connectionDistinguisher) {
FlowRemovedBuilder flowRemovedBld = new FlowRemovedBuilder()
- .setMatch(translateMatch(input, deviceState).build())
+ .setMatch(translateMatch(input, deviceInfo).build())
.setCookie(new FlowCookie(input.getCookie()))
- .setNode(new NodeRef(deviceState.getNodeInstanceIdentifier()))
+ .setNode(new NodeRef(deviceInfo.getNodeInstanceIdentifier()))
.setPriority(input.getPriority())
.setTableId(translateTableId(input));
return flowRemovedBld.build();
}
- protected MatchBuilder translateMatch(FlowRemoved flowRemoved, DeviceState deviceState) {
+ protected MatchBuilder translateMatch(FlowRemoved flowRemoved, DeviceInfo deviceInfo) {
return MatchConvertorImpl.fromOFMatchToSALMatch(flowRemoved.getMatch(),
- deviceState.getFeatures().getDatapathId(), OpenflowVersion.OF13);
+ deviceInfo.getDatapathId(), OpenflowVersion.OF13);
}
/**
package org.opendaylight.openflowplugin.impl.translator;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchConvertorImpl;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
public class FlowRemovedV10Translator extends FlowRemovedTranslator {
@Override
- protected MatchBuilder translateMatch(FlowRemoved flowRemoved, DeviceState deviceState) {
+ protected MatchBuilder translateMatch(FlowRemoved flowRemoved, DeviceInfo deviceInfo) {
return MatchConvertorImpl.fromOFMatchV10ToSALMatch(flowRemoved.getMatchV10(),
- deviceState.getFeatures().getDatapathId(), OpenflowVersion.OF10);
+ deviceInfo.getDatapathId(), OpenflowVersion.OF10);
}
/**
import com.google.common.annotations.VisibleForTesting;
import java.math.BigInteger;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
+
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.device.MessageTranslator;
import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
import org.opendaylight.openflowplugin.extension.api.AugmentTuple;
*/
public class PacketReceivedTranslator implements MessageTranslator<PacketInMessage, PacketReceived> {
@Override
- public PacketReceived translate(final PacketInMessage input, final DeviceState deviceState, final Object connectionDistinguisher) {
+ public PacketReceived translate(final PacketInMessage input, final DeviceInfo deviceInfo, final Object connectionDistinguisher) {
PacketReceivedBuilder packetReceivedBuilder = new PacketReceivedBuilder();
- BigInteger datapathId = deviceState.getFeatures().getDatapathId();
+ BigInteger datapathId = deviceInfo.getDatapathId();
// TODO: connection cookie from connection distinguisher
// packetReceivedBuilder.setConnectionCookie(new ConnectionCookie(input.getCookie().longValue()));
}
// Try to create the NodeConnectorRef
- BigInteger dataPathId = deviceState.getFeatures().getDatapathId();
+ BigInteger dataPathId = deviceInfo.getDatapathId();
NodeConnectorRef nodeConnectorRef = NodeConnectorRefToPortTranslator.toNodeConnectorRef(input, dataPathId);
// If we was able to create NodeConnectorRef, use it
import java.util.Collections;
import org.opendaylight.openflowplugin.api.OFConstants;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.device.MessageTranslator;
import org.opendaylight.openflowplugin.openflow.md.util.PortTranslatorUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
@Override
public FlowCapableNodeConnector translate(final PortGrouping input,
- final DeviceState deviceState, final Object connectionDistinguisher) {
+ final DeviceInfo deviceInfo, final Object connectionDistinguisher) {
final FlowCapableNodeConnectorBuilder builder = new FlowCapableNodeConnectorBuilder();
//OF1.0
- if (deviceState.getVersion() == OFConstants.OFP_VERSION_1_0) {
+ if (deviceInfo.getVersion() == OFConstants.OFP_VERSION_1_0) {
builder.setAdvertisedFeatures(PortTranslatorUtil.translatePortFeatures(input.getAdvertisedFeaturesV10()));
builder.setConfiguration(PortTranslatorUtil.translatePortConfig(input.getConfigV10()));
builder.setCurrentFeature(PortTranslatorUtil.translatePortFeatures(input.getCurrentFeaturesV10()));
builder.setPeerFeatures(PortTranslatorUtil.translatePortFeatures(input.getPeerFeaturesV10()));
builder.setState(PortTranslatorUtil.translatePortState(input.getStateV10()));
builder.setSupported(PortTranslatorUtil.translatePortFeatures(input.getSupportedFeaturesV10()));
- } else if (deviceState.getVersion() == OFConstants.OFP_VERSION_1_3) {
+ } else if (deviceInfo.getVersion() == OFConstants.OFP_VERSION_1_3) {
builder.setAdvertisedFeatures(PortTranslatorUtil.translatePortFeatures(input.getAdvertisedFeatures()));
builder.setConfiguration(PortTranslatorUtil.translatePortConfig(input.getConfig()));
builder.setCurrentFeature(PortTranslatorUtil.translatePortFeatures(input.getCurrentFeatures()));
import org.opendaylight.openflowplugin.api.OFConstants;
import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
import org.opendaylight.openflowplugin.api.openflow.device.MessageTranslator;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
public static ListenableFuture<Void> initializeNodeInformation(final DeviceContext deviceContext, final boolean switchFeaturesMandatory) {
Preconditions.checkArgument(deviceContext != null);
final DeviceState deviceState = Preconditions.checkNotNull(deviceContext.getDeviceState());
+ final DeviceInfo deviceInfo = deviceContext.getDeviceInfo();
final ConnectionContext connectionContext = Preconditions.checkNotNull(deviceContext.getPrimaryConnectionContext());
- final short version = deviceState.getVersion();
- LOG.trace("initalizeNodeInformation for node {}", deviceState.getNodeId());
+ final short version = deviceInfo.getVersion();
+ LOG.trace("initalizeNodeInformation for node {}", deviceInfo.getNodeId());
final SettableFuture<Void> returnFuture = SettableFuture.<Void>create();
addNodeToOperDS(deviceContext, returnFuture);
final ListenableFuture<List<RpcResult<List<MultipartReply>>>> deviceFeaturesFuture;
// create empty tables after device description is processed
chainTableTrunkWriteOF10(deviceContext, deviceFeaturesFuture);
- final short ofVersion = deviceContext.getDeviceState().getVersion();
+ final short ofVersion = deviceInfo.getVersion();
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();
for (final PortGrouping port : connectionContext.getFeatures().getPhyPort()) {
- final FlowCapableNodeConnector fcNodeConnector = translator.translate(port, deviceContext.getDeviceState(), null);
+ final FlowCapableNodeConnector fcNodeConnector = translator.translate(port, deviceContext.getDeviceInfo(), null);
final NodeConnectorId nodeConnectorId = NodeStaticReplyTranslatorUtil.nodeConnectorId(
dataPathId.toString(), port.getPortNo(), ofVersion);
ncBuilder.addAugmentation(FlowCapableNodeConnectorStatisticsData.class,
new FlowCapableNodeConnectorStatisticsDataBuilder().build());
final NodeConnector connector = ncBuilder.build();
- final InstanceIdentifier<NodeConnector> connectorII = deviceState.getNodeInstanceIdentifier().child(
+ final InstanceIdentifier<NodeConnector> connectorII = deviceInfo.getNodeInstanceIdentifier().child(
NodeConnector.class, connector.getKey());
try {
deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, connectorII, connector);
} catch (final Exception e) {
- LOG.debug("Failed to write node {} to DS ", deviceContext.getDeviceState().getNodeId().toString(),
+ LOG.debug("Failed to write node {} to DS ", deviceInfo.getNodeId().toString(),
e);
}
}
} else if (OFConstants.OFP_VERSION_1_3 == version) {
final Capabilities capabilities = connectionContext.getFeatures().getCapabilities();
- LOG.debug("Setting capabilities for device {}", deviceContext.getDeviceState().getNodeId());
+ LOG.debug("Setting capabilities for device {}", deviceInfo.getNodeId());
DeviceStateUtil.setDeviceStateBasedOnV13Capabilities(deviceState, capabilities);
deviceFeaturesFuture = createDeviceFeaturesForOF13(deviceContext, deviceState, switchFeaturesMandatory);
} else {
Futures.addCallback(deviceFeaturesFuture, new FutureCallback<List<RpcResult<List<MultipartReply>>>>() {
@Override
public void onSuccess(final List<RpcResult<List<MultipartReply>>> result) {
- LOG.debug("All init data for node {} is in submited.", deviceState.getNodeId());
+ LOG.debug("All init data for node {} is in submited.", deviceInfo.getNodeId());
returnFuture.set(null);
}
// FIXME : remove session
LOG.trace("Device capabilities gathering future failed.");
LOG.trace("more info in exploration failure..", t);
- LOG.debug("All init data for node {} was not submited correctly - connection has to go down.", deviceState.getNodeId());
+ LOG.debug("All init data for node {} was not submited correctly - connection has to go down.", deviceInfo.getNodeId());
returnFuture.setException(t);
}
});
private static void addNodeToOperDS(final DeviceContext deviceContext, final SettableFuture<Void> future) {
Preconditions.checkArgument(deviceContext != null);
final DeviceState deviceState = deviceContext.getDeviceState();
- final NodeBuilder nodeBuilder = new NodeBuilder().setId(deviceState.getNodeId()).setNodeConnector(
+ final NodeBuilder nodeBuilder = new NodeBuilder().setId(deviceContext.getDeviceInfo().getNodeId()).setNodeConnector(
Collections.<NodeConnector>emptyList());
try {
- deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, deviceState.getNodeInstanceIdentifier(),
+ deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, deviceContext.getDeviceInfo().getNodeInstanceIdentifier(),
nodeBuilder.build());
} catch (final Exception e) {
- LOG.warn("Failed to write node {} to DS ", deviceState.getNodeId(), e);
+ LOG.warn("Failed to write node {} to DS ", deviceContext.getDeviceInfo().getNodeId(), e);
future.cancel(true);
}
}
private static ListenableFuture<List<RpcResult<List<MultipartReply>>>> createDeviceFeaturesForOF10(
final DeviceContext deviceContext, final DeviceState deviceState) {
final ListenableFuture<RpcResult<List<MultipartReply>>> replyDesc = getNodeStaticInfo(MultipartType.OFPMPDESC,
- deviceContext, deviceState.getNodeInstanceIdentifier(), deviceState.getVersion());
+ deviceContext, deviceContext.getDeviceInfo().getNodeInstanceIdentifier(), deviceContext.getDeviceInfo().getVersion());
return Futures.allAsList(Arrays.asList(replyDesc));
}
final DeviceContext deviceContext, final DeviceState deviceState, final boolean switchFeaturesMandatory) {
final ListenableFuture<RpcResult<List<MultipartReply>>> replyDesc = getNodeStaticInfo(MultipartType.OFPMPDESC,
- deviceContext, deviceState.getNodeInstanceIdentifier(), deviceState.getVersion());
+ deviceContext, deviceContext.getDeviceInfo().getNodeInstanceIdentifier(), deviceContext.getDeviceInfo().getVersion());
//first process description reply, write data to DS and write consequent data if successful
return Futures.transform(replyDesc,
final RpcResult<List<MultipartReply>> rpcResult) throws Exception {
translateAndWriteReply(MultipartType.OFPMPDESC, deviceContext,
- deviceState.getNodeInstanceIdentifier(), rpcResult.getResult());
+ deviceContext.getDeviceInfo().getNodeInstanceIdentifier(), rpcResult.getResult());
final ListenableFuture<RpcResult<List<MultipartReply>>> replyMeterFeature = getNodeStaticInfo(
MultipartType.OFPMPMETERFEATURES, deviceContext,
- deviceState.getNodeInstanceIdentifier(), deviceState.getVersion());
+ deviceContext.getDeviceInfo().getNodeInstanceIdentifier(), deviceContext.getDeviceInfo().getVersion());
createSuccessProcessingCallback(MultipartType.OFPMPMETERFEATURES, deviceContext,
- deviceState.getNodeInstanceIdentifier(), replyMeterFeature);
+ deviceContext.getDeviceInfo().getNodeInstanceIdentifier(), replyMeterFeature);
final ListenableFuture<RpcResult<List<MultipartReply>>> replyGroupFeatures = getNodeStaticInfo(
MultipartType.OFPMPGROUPFEATURES, deviceContext,
- deviceState.getNodeInstanceIdentifier(), deviceState.getVersion());
+ deviceContext.getDeviceInfo().getNodeInstanceIdentifier(), deviceContext.getDeviceInfo().getVersion());
createSuccessProcessingCallback(MultipartType.OFPMPGROUPFEATURES, deviceContext,
- deviceState.getNodeInstanceIdentifier(), replyGroupFeatures);
+ deviceContext.getDeviceInfo().getNodeInstanceIdentifier(), replyGroupFeatures);
final ListenableFuture<RpcResult<List<MultipartReply>>> replyTableFeatures = getNodeStaticInfo(
MultipartType.OFPMPTABLEFEATURES, deviceContext,
- deviceState.getNodeInstanceIdentifier(), deviceState.getVersion());
+ deviceContext.getDeviceInfo().getNodeInstanceIdentifier(), deviceContext.getDeviceInfo().getVersion());
createSuccessProcessingCallback(MultipartType.OFPMPTABLEFEATURES, deviceContext,
- deviceState.getNodeInstanceIdentifier(), replyTableFeatures);
+ deviceContext.getDeviceInfo().getNodeInstanceIdentifier(), replyTableFeatures);
final ListenableFuture<RpcResult<List<MultipartReply>>> replyPortDescription = getNodeStaticInfo(
- MultipartType.OFPMPPORTDESC, deviceContext, deviceState.getNodeInstanceIdentifier(),
- deviceState.getVersion());
+ MultipartType.OFPMPPORTDESC, deviceContext, deviceContext.getDeviceInfo().getNodeInstanceIdentifier(),
+ deviceContext.getDeviceInfo().getVersion());
createSuccessProcessingCallback(MultipartType.OFPMPPORTDESC, deviceContext,
- deviceState.getNodeInstanceIdentifier(), replyPortDescription);
+ deviceContext.getDeviceInfo().getNodeInstanceIdentifier(), replyPortDescription);
if (switchFeaturesMandatory) {
return Futures.allAsList(Arrays.asList(replyMeterFeature, replyGroupFeatures,
replyTableFeatures, replyPortDescription));
final MultipartReplyPortDesc portDesc = ((MultipartReplyPortDescCase) body)
.getMultipartReplyPortDesc();
for (final PortGrouping port : portDesc.getPorts()) {
- final short ofVersion = dContext.getDeviceState().getVersion();
+ final short ofVersion = dContext.getDeviceInfo().getVersion();
final TranslatorKey translatorKey = new TranslatorKey(ofVersion, PortGrouping.class.getName());
final MessageTranslator<PortGrouping, FlowCapableNodeConnector> translator = dContext.oook()
.lookupTranslator(translatorKey);
- final FlowCapableNodeConnector fcNodeConnector = translator.translate(port, dContext.getDeviceState(), null);
+ final FlowCapableNodeConnector fcNodeConnector = translator.translate(port, dContext.getDeviceInfo(), null);
final BigInteger dataPathId = dContext.getPrimaryConnectionContext().getFeatures()
.getDatapathId();
}
}
} catch (final Exception e) {
- LOG.debug("Failed to write node {} to DS ", dContext.getDeviceState().getNodeId().toString(), e);
+ LOG.debug("Failed to write node {} to DS ", dContext.getDeviceInfo().getNodeId().toString(), e);
}
}
private static void createEmptyFlowCapableNodeInDs(final DeviceContext deviceContext) {
final FlowCapableNodeBuilder flowCapableNodeBuilder = new FlowCapableNodeBuilder();
- final InstanceIdentifier<FlowCapableNode> fNodeII = deviceContext.getDeviceState().getNodeInstanceIdentifier()
+ final InstanceIdentifier<FlowCapableNode> fNodeII = deviceContext.getDeviceInfo().getNodeInstanceIdentifier()
.augmentation(FlowCapableNode.class);
try {
deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, fNodeII, flowCapableNodeBuilder.build());
} catch (final Exception e) {
- LOG.debug("Failed to write node {} to DS ", deviceContext.getDeviceState().getNodeId().toString(), e);
+ LOG.debug("Failed to write node {} to DS ", deviceContext.getDeviceInfo().getNodeId().toString(), e);
}
}
if (remoteAddress == null) {
LOG.warn("IP address of the node {} cannot be obtained. No connection with switch.", deviceContext
- .getDeviceState().getNodeId());
+ .getDeviceInfo().getNodeId());
return null;
}
LOG.info("IP address of switch is: {}", remoteAddress);
try {
dContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, tableII, tableBuilder.build());
} catch (final Exception e) {
- LOG.debug("Failed to write node {} to DS ", dContext.getDeviceState().getNodeId().toString(), e);
+ LOG.debug("Failed to write node {} to DS ", dContext.getDeviceInfo().getNodeId().toString(), e);
}
}
public void onSuccess(final RpcResult<List<MultipartReply>> rpcResult) {
final List<MultipartReply> result = rpcResult.getResult();
if (result != null) {
- LOG.info("Static node {} info: {} collected", deviceContext.getDeviceState().getNodeId(), type);
+ LOG.info("Static node {} info: {} collected", deviceContext.getDeviceInfo().getNodeId(), type);
translateAndWriteReply(type, deviceContext, nodeII, result);
} else {
final Iterator<RpcError> rpcErrorIterator = rpcResult.getErrors().iterator();
}
if (allSucceeded) {
createEmptyFlowCapableNodeInDs(deviceContext);
- makeEmptyTables(deviceContext, deviceContext.getDeviceState().getNodeInstanceIdentifier(),
- deviceContext.getDeviceState().getFeatures().getTables());
+ makeEmptyTables(deviceContext, deviceContext.getDeviceInfo().getNodeInstanceIdentifier(),
+ deviceContext.getPrimaryConnectionContext().getFeatures().getTables());
}
}
@Mock
private ServiceChangeListener serviceChangeListener;
@Mock
- private ConcurrentHashMap<NodeId, ServiceChangeListener> serviceChangeListeners;
+ private ConcurrentHashMap<DeviceInfo, ServiceChangeListener> serviceChangeListeners;
@Mock
private DeviceContext deviceContext;
@Mock
@Before
public void setUp() {
- when(deviceManager.getDeviceContextFromNodeId(nodeId)).thenReturn(deviceContext);
+ when(deviceManager.getDeviceContextFromNodeId(deviceInfo)).thenReturn(deviceContext);
when(deviceContext.getPrimaryConnectionContext()).thenReturn(connectionContext);
lifecycleConductor = new LifecycleConductorImpl(messageIntelligenceAgency);
@Test
public void addOneTimeListenerWhenServicesChangesDoneTest() {
- lifecycleConductor.addOneTimeListenerWhenServicesChangesDone(serviceChangeListener, nodeId);
+ lifecycleConductor.addOneTimeListenerWhenServicesChangesDone(serviceChangeListener, deviceInfo);
assertEquals(false,lifecycleConductor.isServiceChangeListenersEmpty());
}
*/
@Test
public void notifyServiceChangeListenersTest1() {
- lifecycleConductor.notifyServiceChangeListeners(nodeId,true);
+ lifecycleConductor.notifyServiceChangeListeners(deviceInfo,true);
when(serviceChangeListeners.size()).thenReturn(0);
- verify(serviceChangeListeners,times(0)).remove(nodeId);
+ verify(serviceChangeListeners,times(0)).remove(deviceInfo);
}
/**
*/
@Test
public void notifyServiceChangeListenersTest2() {
- lifecycleConductor.addOneTimeListenerWhenServicesChangesDone(serviceChangeListener, nodeId);
+ lifecycleConductor.addOneTimeListenerWhenServicesChangesDone(serviceChangeListener, deviceInfo);
assertEquals(false,lifecycleConductor.isServiceChangeListenersEmpty());
- lifecycleConductor.notifyServiceChangeListeners(nodeId,true);
+ lifecycleConductor.notifyServiceChangeListeners(deviceInfo,true);
assertEquals(true,lifecycleConductor.isServiceChangeListenersEmpty());
}
*/
@Test
public void roleInitializationDoneTest1() {
- lifecycleConductor.addOneTimeListenerWhenServicesChangesDone(serviceChangeListener, nodeId);
- lifecycleConductor.roleInitializationDone(nodeId,false);
+ lifecycleConductor.addOneTimeListenerWhenServicesChangesDone(serviceChangeListener, deviceInfo);
+ lifecycleConductor.roleInitializationDone(deviceInfo,false);
verify(deviceContext,times(1)).shutdownConnection();
}
*/
@Test
public void roleInitializationDoneTest2() {
- lifecycleConductor.addOneTimeListenerWhenServicesChangesDone(serviceChangeListener, nodeId);
- lifecycleConductor.roleInitializationDone(nodeId,true);
+ lifecycleConductor.addOneTimeListenerWhenServicesChangesDone(serviceChangeListener, deviceInfo);
+ lifecycleConductor.roleInitializationDone(deviceInfo,true);
verify(deviceContext,times(0)).shutdownConnection();
}
*/
@Test
public void roleChangeOnDeviceTest1() {
- when(deviceManager.getDeviceContextFromNodeId(nodeId)).thenReturn(null);
- lifecycleConductor.roleChangeOnDevice(nodeId,true,ofpRole,false);
+ when(deviceManager.getDeviceContextFromNodeId(deviceInfo)).thenReturn(null);
+ lifecycleConductor.roleChangeOnDevice(deviceInfo,true,ofpRole,false);
verify(deviceContext,times(0)).shutdownConnection();
- lifecycleConductor.roleChangeOnDevice(nodeId,false,ofpRole,false);
+ lifecycleConductor.roleChangeOnDevice(deviceInfo,false,ofpRole,false);
verify(deviceContext,times(0)).shutdownConnection();
}
*/
@Test
public void roleChangeOnDeviceTest2() {
- when(deviceManager.getDeviceContextFromNodeId(nodeId)).thenReturn(deviceContext);
- lifecycleConductor.roleChangeOnDevice(nodeId,false,ofpRole,false);
+ when(deviceManager.getDeviceContextFromNodeId(deviceInfo)).thenReturn(deviceContext);
+ lifecycleConductor.roleChangeOnDevice(deviceInfo,false,ofpRole,false);
verify(deviceContext,times(1)).shutdownConnection();
}
*/
@Test
public void roleChangeOnDeviceTest3() {
- when(deviceManager.getDeviceContextFromNodeId(nodeId)).thenReturn(deviceContext);
- lifecycleConductor.roleChangeOnDevice(nodeId,true,ofpRole,true);
+ when(deviceManager.getDeviceContextFromNodeId(deviceInfo)).thenReturn(deviceContext);
+ lifecycleConductor.roleChangeOnDevice(deviceInfo,true,ofpRole,true);
verify(deviceContext,times(0)).shutdownConnection();
}
@Test
public void roleChangeOnDeviceTest4() {
when(deviceContext.getDeviceState()).thenReturn(deviceState);
- when(deviceManager.getDeviceContextFromNodeId(nodeId)).thenReturn(deviceContext);
+ when(deviceManager.getDeviceContextFromNodeId(deviceInfo)).thenReturn(deviceContext);
when(deviceContext.onClusterRoleChange(null, OfpRole.BECOMEMASTER)).thenReturn(listenableFuture);
- lifecycleConductor.roleChangeOnDevice(nodeId,true,OfpRole.BECOMEMASTER,false);
+ lifecycleConductor.roleChangeOnDevice(deviceInfo,true,OfpRole.BECOMEMASTER,false);
verify(statisticsManager).startScheduling(Mockito.<DeviceInfo>any());
}
@Test
public void roleChangeOnDeviceTest5() {
when(deviceContext.getDeviceState()).thenReturn(deviceState);
- when(deviceManager.getDeviceContextFromNodeId(nodeId)).thenReturn(deviceContext);
+ when(deviceManager.getDeviceContextFromNodeId(deviceInfo)).thenReturn(deviceContext);
when(deviceContext.onClusterRoleChange(null, OfpRole.BECOMESLAVE)).thenReturn(listenableFuture);
- lifecycleConductor.roleChangeOnDevice(nodeId,true,OfpRole.BECOMESLAVE,false);
+ lifecycleConductor.roleChangeOnDevice(deviceInfo,true,OfpRole.BECOMESLAVE,false);
verify(statisticsManager).stopScheduling(Mockito.<DeviceInfo>any());
}
*/
@Test
public void gainVersionSafelyTest1() {
- when(deviceManager.getDeviceContextFromNodeId(nodeId)).thenReturn(null);
- assertNull(lifecycleConductor.gainVersionSafely(nodeId));
+ when(deviceManager.getDeviceContextFromNodeId(deviceInfo)).thenReturn(null);
+ assertNull(lifecycleConductor.gainVersionSafely(deviceInfo));
}
/**
*/
@Test
public void gainVersionSafelyTest2() {
- when(deviceManager.getDeviceContextFromNodeId(nodeId)).thenReturn(deviceContext);
- lifecycleConductor.gainVersionSafely(nodeId);
+ when(deviceManager.getDeviceContextFromNodeId(deviceInfo)).thenReturn(deviceContext);
+ lifecycleConductor.gainVersionSafely(deviceInfo);
verify(deviceContext,times(1)).getPrimaryConnectionContext();
}
*/
@Test
public void gainConnectionStateSafelyTest1() {
- when(deviceManager.getDeviceContextFromNodeId(nodeId)).thenReturn(null);
- assertNull(lifecycleConductor.gainConnectionStateSafely(nodeId));
+ when(deviceManager.getDeviceContextFromNodeId(deviceInfo)).thenReturn(null);
+ assertNull(lifecycleConductor.gainConnectionStateSafely(deviceInfo));
}
/**
*/
@Test
public void gainConnectionStateSafelyTest2() {
- when(deviceManager.getDeviceContextFromNodeId(nodeId)).thenReturn(deviceContext);
- lifecycleConductor.gainConnectionStateSafely(nodeId);
+ when(deviceManager.getDeviceContextFromNodeId(deviceInfo)).thenReturn(deviceContext);
+ lifecycleConductor.gainConnectionStateSafely(deviceInfo);
verify(deviceContext,times(1)).getPrimaryConnectionContext();
}
*/
@Test
public void reserveXidForDeviceMessageTest1() {
- when(deviceManager.getDeviceContextFromNodeId(nodeId)).thenReturn(null);
- assertNull(lifecycleConductor.reserveXidForDeviceMessage(nodeId));
+ when(deviceManager.getDeviceContextFromNodeId(deviceInfo)).thenReturn(null);
+ assertNull(lifecycleConductor.reserveXidForDeviceMessage(deviceInfo));
}
/**
*/
@Test
public void reserveXidForDeviceMessageTest2() {
- when(deviceManager.getDeviceContextFromNodeId(nodeId)).thenReturn(deviceContext);
- lifecycleConductor.reserveXidForDeviceMessage(nodeId);
+ when(deviceManager.getDeviceContextFromNodeId(deviceInfo)).thenReturn(deviceContext);
+ lifecycleConductor.reserveXidForDeviceMessage(deviceInfo);
verify(deviceContext,times(1)).reserveXidForDeviceMessage();
}
*/
@Test
public void deviceStartInitializationDoneTest() {
- lifecycleConductor.deviceStartInitializationDone(nodeId, false);
+ lifecycleConductor.deviceStartInitializationDone(deviceInfo, false);
verify(deviceContext,times(1)).shutdownConnection();
}
*/
@Test
public void deviceInitializationDoneTest() {
- lifecycleConductor.deviceInitializationDone(nodeId, false);
+ lifecycleConductor.deviceInitializationDone(deviceInfo, false);
verify(deviceContext,times(1)).shutdownConnection();
}
}
import org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived;
import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.OfpRole;
import org.opendaylight.yangtools.concepts.Registration;
+import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
import org.opendaylight.yangtools.yang.common.RpcResult;
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);
- Mockito.when(deviceState.getNodeInstanceIdentifier()).thenReturn(nodeKeyIdent);
- Mockito.when(deviceState.getNodeId()).thenReturn(nodeId);
+ Mockito.when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(nodeKeyIdent);
+ Mockito.when(deviceInfo.getNodeId()).thenReturn(nodeId);
+ Mockito.when(deviceInfo.getDatapathId()).thenReturn(BigInteger.TEN);
final SettableFuture<RpcResult<GetAsyncReply>> settableFuture = SettableFuture.create();
final SettableFuture<RpcResult<MultipartReply>> settableFutureMultiReply = SettableFuture.create();
Mockito.when(requestContext.getFuture()).thenReturn(settableFuture);
when(connectionContext.getFeatures()).thenReturn(mockedFeaturesReply);
when(connectionContext.getFeatures().getCapabilities()).thenReturn(mock(Capabilities.class));
- Mockito.when(deviceState.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
+ Mockito.when(deviceInfo.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
Mockito.when(featuresOutput.getDatapathId()).thenReturn(DUMMY_DATAPATH_ID);
Mockito.when(featuresOutput.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
- Mockito.when(deviceState.getFeatures()).thenReturn(featuresOutput);
- Mockito.when(messageTranslatorPacketReceived.translate(any(Object.class), any(DeviceState.class), any(Object.class))).thenReturn(mock(PacketReceived.class));
- Mockito.when(messageTranslatorFlowCapableNodeConnector.translate(any(Object.class), any(DeviceState.class), any(Object.class))).thenReturn(mock(FlowCapableNodeConnector.class));
+ Mockito.when(messageTranslatorPacketReceived.translate(any(Object.class), any(DeviceInfo.class), any(Object.class))).thenReturn(mock(PacketReceived.class));
+ 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(translatorLibrary.lookupTranslator(eq(new TranslatorKey(OFConstants.OFP_VERSION_1_3,
when(connectionContext.getConnectionAdapter()).thenReturn(mockedConnectionAdapter);
final NodeId dummyNodeId = new NodeId("dummyNodeId");
- when(deviceState.getNodeId()).thenReturn(dummyNodeId);
+ when(deviceInfo.getNodeId()).thenReturn(dummyNodeId);
final ConnectionContext mockedAuxiliaryConnectionContext = prepareConnectionContext();
deviceContext.addAuxiliaryConnectionContext(mockedAuxiliaryConnectionContext);
}
@Test
- public void testPortStatusMessage() {
+ public void testPortStatusMessage() throws Exception{
final PortStatusMessage mockedPortStatusMessage = mock(PortStatusMessage.class);
final Class dummyClass = Class.class;
when(mockedPortStatusMessage.getImplementedInterface()).thenReturn(dummyClass);
final GetFeaturesOutput mockedFeature = mock(GetFeaturesOutput.class);
when(mockedFeature.getDatapathId()).thenReturn(DUMMY_DATAPATH_ID);
- when(deviceState.getFeatures()).thenReturn(mockedFeature);
when(mockedPortStatusMessage.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
when(mockedPortStatusMessage.getReason()).thenReturn(PortReason.OFPPRADD);
+ when(mockedPortStatusMessage.getPortNo()).thenReturn(42L);
OpenflowPortsUtil.init();
deviceContext.processPortStatusMessage(mockedPortStatusMessage);
.setMatch(new MatchBuilder().build());
final NotificationPublishService mockedNotificationPublishService = mock(NotificationPublishService.class);
- Mockito.when(messageTranslatorFlowRemoved.translate(any(Object.class), any(DeviceState.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
order.verify(mockConnectionContext).setOutboundQueueProvider(any(OutboundQueueProvider.class));
order.verify(mockConnectionContext).setOutboundQueueHandleRegistration(
Mockito.<OutboundQueueHandlerRegistration<OutboundQueueProvider>>any());
- order.verify(mockConnectionContext).getNodeId();
verify(deviceInitPhaseHandler).onDeviceContextLevelUp(Matchers.<DeviceInfo>any());
}
.setPortNo(41L);
when(mockFeatures.getPhyPort()).thenReturn(Collections.singletonList(phyPort.build()));
final MessageTranslator<Object, Object> mockedTranslator = mock(MessageTranslator.class);
- when(mockedTranslator.translate(Matchers.<Object>any(), Matchers.<DeviceState>any(), Matchers.any()))
+ when(mockedTranslator.translate(Matchers.<Object>any(), Matchers.<DeviceInfo>any(), Matchers.any()))
.thenReturn(null);
when(translatorLibrary.lookupTranslator(Matchers.<TranslatorKey>any())).thenReturn(mockedTranslator);
order.verify(mockConnectionContext).setOutboundQueueProvider(any(OutboundQueueProvider.class));
order.verify(mockConnectionContext).setOutboundQueueHandleRegistration(
Mockito.<OutboundQueueHandlerRegistration<OutboundQueueProvider>>any());
- order.verify(mockConnectionContext).getNodeId();
verify(deviceInitPhaseHandler).onDeviceContextLevelUp(Matchers.<DeviceInfo>any());
}
* org.opendaylight.openflowplugin.impl.device
*
* test of {@link DeviceStateImpl} - lightweight version, using basic ways (TDD)
- *
- * @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
- *
- * Created: Mar 29, 2015
*/
@RunWith(MockitoJUnitRunner.class)
public class DeviceStateImplTest {
- private NodeId nodeId;
@Mock
private FeaturesReply featuresReply;
private DeviceStateImpl deviceState;
@Before
public void initialization() {
- nodeId = new NodeId("test-node-id");
Mockito.when(featuresReply.getVersion()).thenReturn(version);
Mockito.when(featuresReply.getPhyPort()).thenReturn(pPort);
- deviceState = new DeviceStateImpl(featuresReply, nodeId);
- }
-
- /**
- * Test method for {@link DeviceStateImpl#DeviceStateImpl(FeaturesReply, NodeId)}.
- */
- @Test(expected=NullPointerException.class)
- public void testDeviceStateImplNullNodeId(){
- new DeviceStateImpl(featuresReply, null);
- }
-
- /**
- * Test method for {@link DeviceStateImpl#DeviceStateImpl(FeaturesReply, NodeId)}.
- */
- @Test(expected=IllegalArgumentException.class)
- public void testDeviceStateImplNullFeaturesReply(){
- new DeviceStateImpl(null, nodeId);
- }
-
- /**
- * Test method for {@link DeviceStateImpl#getNodeId()}.
- */
- @Test
- public void testGetNodeId(){
- final NodeId getNodeId = deviceState.getNodeId();
- Assert.assertNotNull(getNodeId);
- Assert.assertEquals(nodeId, getNodeId);
- }
-
- /**
- * Test method for {@link DeviceStateImpl#getFeatures()}.
- */
- @Test
- public void testGetFeatures(){
- final GetFeaturesOutputBuilder expetedResult = new GetFeaturesOutputBuilder(featuresReply);
- final GetFeaturesOutput getFeatures = deviceState.getFeatures();
- Assert.assertNotNull(getFeatures);
- Assert.assertEquals(expetedResult.getVersion(), getFeatures.getVersion());
- Assert.assertEquals(expetedResult.getPhyPort(), getFeatures.getPhyPort());
+ deviceState = new DeviceStateImpl();
}
@Test
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.api.openflow.lifecycle.LifecycleConductor;
import org.opendaylight.openflowplugin.impl.util.DeviceStateUtil;
@Mock
DeviceState deviceState;
@Mock
+ DeviceInfo deviceInfo;
+ @Mock
LifecycleConductor conductor;
@Mock
.thenReturn(txChain);
nodeId = new NodeId("h2g2:42");
nodeKeyIdent = DeviceStateUtil.createNodeInstanceIdentifier(nodeId);
- Mockito.when(deviceState.getNodeInstanceIdentifier()).thenReturn(nodeKeyIdent);
- Mockito.when(deviceState.getNodeId()).thenReturn(nodeId);
- txChainManager = new TransactionChainManager(dataBroker, deviceState, conductor);
+ Mockito.when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(nodeKeyIdent);
+ Mockito.when(deviceInfo.getNodeId()).thenReturn(nodeId);
+ txChainManager = new TransactionChainManager(dataBroker, deviceInfo, conductor);
Mockito.when(txChain.newWriteOnlyTransaction()).thenReturn(writeTx);
path = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(nodeId));
import org.mockito.runners.MockitoJUnitRunner;
import org.opendaylight.openflowplugin.api.OFConstants;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
private DeviceContext deviceContext;
@Mock
private DeviceState deviceState;
+ @Mock
+ private DeviceInfo deviceInfo;
@Before
}
FLOWS_STATISTICS_UPDATE_BUILDER.setFlowAndStatisticsMapList(flowAndStatisticsMapListList);
Mockito.when(deviceContext.getDeviceState()).thenReturn(deviceState);
- Mockito.when(deviceState.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
+ Mockito.when(deviceInfo.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
}
@Test
@Test
public void testCreateRequestContext() throws Exception {
roleContext.createRequestContext();
- Mockito.verify(conductor).reserveXidForDeviceMessage(nodeId);
+ Mockito.verify(conductor).reserveXidForDeviceMessage(deviceInfo);
}
@Test(expected = NullPointerException.class)
private final NodeId nodeId2 = NodeId.getDefaultInstance("openflow:2");
- private final EntityOwnershipChange masterEntity = new EntityOwnershipChange(RoleManagerImpl.makeEntity(nodeId), false, true, true);
- private final EntityOwnershipChange masterTxEntity = new EntityOwnershipChange(RoleManagerImpl.makeTxEntity(nodeId), false, true, true);
- private final EntityOwnershipChange slaveEntity = new EntityOwnershipChange(RoleManagerImpl.makeEntity(nodeId), true, false, true);
- private final EntityOwnershipChange slaveTxEntityLast = new EntityOwnershipChange(RoleManagerImpl.makeTxEntity(nodeId), true, false, false);
- private final EntityOwnershipChange masterEntityNotOwner = new EntityOwnershipChange(RoleManagerImpl.makeEntity(nodeId), true, false, true);
+ private final EntityOwnershipChange masterEntity = new EntityOwnershipChange(RoleManagerImpl.makeEntity(nodeId), false, true, true, false);
+ private final EntityOwnershipChange masterTxEntity = new EntityOwnershipChange(RoleManagerImpl.makeTxEntity(nodeId), false, true, true, false);
+ private final EntityOwnershipChange slaveEntity = new EntityOwnershipChange(RoleManagerImpl.makeEntity(nodeId), true, false, true, false);
+ private final EntityOwnershipChange slaveTxEntityLast = new EntityOwnershipChange(RoleManagerImpl.makeTxEntity(nodeId), true, false, false, false);
+ private final EntityOwnershipChange masterEntityNotOwner = new EntityOwnershipChange(RoleManagerImpl.makeEntity(nodeId), true, false, true, false);
private InOrder inOrder;
@Before
public void setUp() throws Exception {
CheckedFuture<Void, TransactionCommitFailedException> future = Futures.immediateCheckedFuture(null);
- Mockito.when(deviceState.getFeatures()).thenReturn(featuresOutput);
Mockito.when(entityOwnershipService.registerListener(Mockito.anyString(), Mockito.any(EntityOwnershipListener.class))).thenReturn(entityOwnershipListenerRegistration);
Mockito.when(entityOwnershipService.registerCandidate(Mockito.any(Entity.class))).thenReturn(entityOwnershipCandidateRegistration);
Mockito.when(deviceContext.getPrimaryConnectionContext()).thenReturn(connectionContext);
Mockito.when(deviceContext.getDeviceState()).thenReturn(deviceState);
- Mockito.when(deviceInfo.getNodeId()).thenReturn(nodeId);
+ Mockito.when(deviceContext.getDeviceInfo()).thenReturn(deviceInfo);
Mockito.when(connectionContext.getFeatures()).thenReturn(featuresReply);
Mockito.when(connectionContext.getNodeId()).thenReturn(nodeId);
Mockito.when(connectionContext.getConnectionState()).thenReturn(ConnectionContext.CONNECTION_STATE.WORKING);
Mockito.doNothing().when(deviceTerminationPhaseHandler).onDeviceContextLevelDown(Mockito.<DeviceInfo>any());
Mockito.when(dataBroker.newWriteOnlyTransaction()).thenReturn(writeTransaction);
Mockito.when(writeTransaction.submit()).thenReturn(future);
- Mockito.when(deviceManager.getDeviceContextFromNodeId(Mockito.<NodeId>any())).thenReturn(deviceContext);
+ Mockito.when(deviceManager.getDeviceContextFromNodeId(deviceInfo)).thenReturn(deviceContext);
Mockito.when(deviceInfo.getNodeId()).thenReturn(nodeId);
Mockito.when(deviceInfo2.getNodeId()).thenReturn(nodeId2);
+ Mockito.when(deviceInfo.getDatapathId()).thenReturn(BigInteger.TEN);
roleManager = new RoleManagerImpl(entityOwnershipService, dataBroker, conductor);
roleManager.setDeviceInitializationPhaseHandler(deviceInitializationPhaseHandler);
roleManager.setDeviceTerminationPhaseHandler(deviceTerminationPhaseHandler);
- Mockito.when(conductor.getDeviceContext(Mockito.<NodeId>any())).thenReturn(deviceContext);
+ Mockito.when(conductor.getDeviceContext(deviceInfo)).thenReturn(deviceContext);
roleManagerSpy = Mockito.spy(roleManager);
roleManagerSpy.onDeviceContextLevelUp(deviceInfo);
roleContextSpy = Mockito.spy(roleManager.getRoleContext(nodeId));
Mockito.when(roleContextSpy.isTxCandidateRegistered()).thenReturn(false);
roleManagerSpy.changeOwnershipForTxEntity(slaveTxEntityLast, roleContextSpy);
verify(roleContextSpy).close();
- verify(conductor).closeConnection(nodeId);
+ verify(conductor).closeConnection(deviceInfo);
}
@Test
Mockito.when(roleContextSpy.isTxCandidateRegistered()).thenReturn(true);
roleManagerSpy.changeOwnershipForTxEntity(masterEntityNotOwner, roleContextSpy);
verify(roleContextSpy).close();
- verify(conductor).closeConnection(nodeId);
+ verify(conductor).closeConnection(deviceInfo);
}
@Test
public void testAddListener() throws Exception {
roleManager.addRoleChangeListener((new RoleChangeListener() {
@Override
- public void roleInitializationDone(final NodeId nodeId, final boolean success) {
- Assert.assertTrue(nodeId.equals(nodeId));
+ public void roleInitializationDone(final DeviceInfo deviceInfo_, final boolean success) {
+ Assert.assertTrue(deviceInfo.equals(deviceInfo_));
Assert.assertTrue(success);
}
@Override
- public void roleChangeOnDevice(final NodeId nodeId_, final boolean success, final OfpRole newRole, final boolean initializationPhase) {
- Assert.assertTrue(nodeId.equals(nodeId_));
+ public void roleChangeOnDevice(final DeviceInfo deviceInfo_, final boolean success, final OfpRole newRole, final boolean initializationPhase) {
+ Assert.assertTrue(deviceInfo.equals(deviceInfo_));
Assert.assertTrue(success);
Assert.assertFalse(initializationPhase);
Assert.assertTrue(newRole.equals(OfpRole.BECOMEMASTER));
}
}));
- roleManager.notifyListenersRoleInitializationDone(nodeId, true);
- roleManager.notifyListenersRoleChangeOnDevice(nodeId, true, OfpRole.BECOMEMASTER, false);
+ roleManager.notifyListenersRoleInitializationDone(deviceInfo, true);
+ roleManager.notifyListenersRoleChangeOnDevice(deviceInfo, true, OfpRole.BECOMEMASTER, false);
}
@Test
public void testMakeDeviceRoleChange() throws Exception{
roleManagerSpy.makeDeviceRoleChange(OfpRole.BECOMEMASTER, roleContextSpy, true);
verify(roleManagerSpy, atLeastOnce()).sendRoleChangeToDevice(Mockito.<OfpRole>any(), Mockito.<RoleContext>any());
- verify(roleManagerSpy, atLeastOnce()).notifyListenersRoleChangeOnDevice(Mockito.<NodeId>any(), eq(true), Mockito.<OfpRole>any(), eq(true));
+ verify(roleManagerSpy, atLeastOnce()).notifyListenersRoleChangeOnDevice(Mockito.<DeviceInfo>any(), eq(true), Mockito.<OfpRole>any(), eq(true));
}
@Test
public void testServicesChangeDone() throws Exception {
roleManagerSpy.setRoleContext(nodeId2, roleContextSpy);
- roleManagerSpy.servicesChangeDone(nodeId2, true);
+ roleManagerSpy.servicesChangeDone(deviceInfo2, true);
verify(roleContextSpy).unregisterCandidate(Mockito.<Entity>any());
}
@Test
public void testServicesChangeDoneContextIsNull() throws Exception {
roleManagerSpy.setRoleContext(nodeId, roleContextSpy);
- roleManagerSpy.servicesChangeDone(nodeId2, true);
+ roleManagerSpy.servicesChangeDone(deviceInfo2, true);
verify(roleContextSpy, never()).unregisterCandidate(Mockito.<Entity>any());
}
}
\ No newline at end of file
import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
import org.opendaylight.openflowplugin.api.openflow.device.XidSequencer;
@Mock
private DeviceState deviceState;
@Mock
+ private DeviceInfo deviceInfo;
+ @Mock
private XidSequencer xidSequencer;
@Mock
private MessageSpy messageSpy;
nodeInstanceIdentifier = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(nodeId));
when(deviceContext.getDeviceState()).thenReturn(deviceState);
- when(deviceState.getNodeInstanceIdentifier()).thenReturn(nodeInstanceIdentifier);
+ when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(nodeInstanceIdentifier);
when(deviceContext.getMessageSpy()).thenReturn(messageSpy);
rpcContext = new RpcContextImpl(rpcProviderRegistry,deviceContext, messageSpy, MAX_REQUESTS,nodeInstanceIdentifier);
Mockito.when(deviceContext.getPrimaryConnectionContext()).thenReturn(connectionContext);
Mockito.when(deviceContext.getDeviceState()).thenReturn(deviceState);
Mockito.when(deviceContext.getItemLifeCycleSourceRegistry()).thenReturn(itemLifeCycleRegistry);
- Mockito.when(deviceState.getNodeInstanceIdentifier()).thenReturn(nodePath);
- Mockito.when(deviceState.getFeatures()).thenReturn(featuresOutput);
+ Mockito.when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(nodePath);
rpcManager.setDeviceTerminationPhaseHandler(deviceTerminationPhaseHandler);
Mockito.when(connectionContext.getFeatures()).thenReturn(features);
Mockito.when(deviceContext.getPrimaryConnectionContext()).thenReturn(connectionContext);
Mockito.when(deviceContext.getDeviceState()).thenReturn(deviceState);
Mockito.when(deviceContext.getItemLifeCycleSourceRegistry()).thenReturn(itemLifeCycleRegistry);
- Mockito.when(deviceState.getNodeInstanceIdentifier()).thenReturn(nodePath);
+ Mockito.when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(nodePath);
Mockito.when(deviceContext.getMessageSpy()).thenReturn(messageSpy);
Mockito.when(deviceInfo.getNodeId()).thenReturn(nodeKey.getId());
- Mockito.when(deviceState.getNodeId()).thenReturn(nodeKey.getId());
Mockito.when(rpcProviderRegistry.addRoutedRpcImplementation(
Matchers.<Class<RpcService>>any(), Matchers.any(RpcService.class)))
.thenReturn(routedRpcRegistration);
- Mockito.when(conductor.getDeviceContext(Mockito.<NodeId>any())).thenReturn(deviceContext);
+ Mockito.when(conductor.getDeviceContext(deviceInfo)).thenReturn(deviceContext);
Mockito.when(contexts.remove(deviceInfo)).thenReturn(removedContexts);
}
@Test
public void onDeviceContextLevelUp() throws Exception {
rpcManager.onDeviceContextLevelUp(deviceInfo);
- verify(conductor).getDeviceContext(Mockito.<NodeId>any());
+ verify(conductor).getDeviceContext(deviceInfo);
}
@Test
private SendBarrierInput buildSendBarrierInput() {
return new SendBarrierInputBuilder()
- .setNode(new NodeRef(mockedDeviceState.getNodeInstanceIdentifier())).build();
+ .setNode(new NodeRef(mockedDeviceInfo.getNodeInstanceIdentifier())).build();
}
}
\ No newline at end of file
import org.opendaylight.openflowplugin.api.OFConstants;
import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
import org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry;
@Mock
private DeviceState mockedDeviceState;
@Mock
+ private DeviceInfo mockedDeviceInfo;
+ @Mock
private GetFeaturesOutput mocketGetFeaturesOutput;
@Mock
private DeviceFlowRegistry mockedFlowRegistry;
when(mocketGetFeaturesOutput.getDatapathId()).thenReturn(BigInteger.valueOf(123L));
when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedPrimaryConnection);
- when(mockedDeviceState.getNodeInstanceIdentifier()).thenReturn(NODE_PATH);
- when(mockedDeviceState.getFeatures()).thenReturn(mocketGetFeaturesOutput);
+ when(mockedDeviceInfo.getNodeInstanceIdentifier()).thenReturn(NODE_PATH);
when(mockedDeviceState.deviceSynchronized()).thenReturn(true);
- when(mockedDeviceState.getNodeId()).thenReturn(mockedNodeId);
+ when(mockedDeviceInfo.getNodeId()).thenReturn(mockedNodeId);
+ when(mockedDeviceInfo.getDatapathId()).thenReturn(BigInteger.TEN);
when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
+ when(mockedDeviceContext.getDeviceInfo()).thenReturn(mockedDeviceInfo);
when(mockedDeviceContext.getDeviceFlowRegistry()).thenReturn(mockedFlowRegistry);
- final InstanceIdentifier<FlowCapableNode> nodePath = mockedDeviceState.getNodeInstanceIdentifier().augmentation(FlowCapableNode.class);
+ final InstanceIdentifier<FlowCapableNode> nodePath = mockedDeviceInfo.getNodeInstanceIdentifier().augmentation(FlowCapableNode.class);
final FlowCapableNodeBuilder flowNodeBuilder = new FlowCapableNodeBuilder();
flowNodeBuilder.setTable(Collections.<Table> emptyList());
final Optional<FlowCapableNode> flowNodeOpt = Optional.of(flowNodeBuilder.build());
}
};
multipartRequestOnTheFlyCallback = new MultipartRequestOnTheFlyCallback(dummyRequestContext, String.class,
- mockedDeviceContext.getMessageSpy(),dummyEventIdentifier, mockedDeviceContext.getDeviceState(),
- mockedDeviceContext.getDeviceFlowRegistry(), mockedDeviceContext);
+ mockedDeviceContext.getMessageSpy(),dummyEventIdentifier, mockedDeviceInfo,
+ mockedDeviceContext.getDeviceFlowRegistry(), mockedDeviceContext, mockedDeviceState);
}
.setMultipartReplyBody(multipartReplyFlowCaseBuilder.build())
.setXid(21L);
- final InstanceIdentifier<FlowCapableNode> nodePath = mockedDeviceState.getNodeInstanceIdentifier()
+ final InstanceIdentifier<FlowCapableNode> nodePath = mockedDeviceInfo.getNodeInstanceIdentifier()
.augmentation(FlowCapableNode.class);
final FlowCapableNodeBuilder flowNodeBuilder = new FlowCapableNodeBuilder();
final TableBuilder tableDataBld = new TableBuilder();
private TransmitPacketInput buildTransmitPacketInput() {
TransmitPacketInputBuilder transmitPacketInputBld = new TransmitPacketInputBuilder()
.setBufferId(OFConstants.OFP_NO_BUFFER)
- .setNode(new NodeRef(mockedDeviceState.getNodeInstanceIdentifier()))
+ .setNode(new NodeRef(mockedDeviceInfo.getNodeInstanceIdentifier()))
.setPayload(ULTIMATE_PAYLOAD.getBytes())
.setEgress(new NodeConnectorRef(pathToNodeconnector));
return transmitPacketInputBld.build();
private SendExperimenterInput buildSendExperimenterInput() {
SendExperimenterInputBuilder sendExperimenterInputBld = new SendExperimenterInputBuilder()
- .setNode(new NodeRef(mockedDeviceState.getNodeInstanceIdentifier()))
+ .setNode(new NodeRef(mockedDeviceInfo.getNodeInstanceIdentifier()))
.setExperimenterMessageOfChoice(new DummyExperimenter());
return sendExperimenterInputBld.build();
}
import org.opendaylight.openflowplugin.api.OFConstants;
import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
@Mock
private DeviceState mockedDeviceState;
@Mock
+ private DeviceInfo mockedDeviceInfo;
+ @Mock
private DeviceFlowRegistry deviceFlowRegistry;
@Mock
private GetFeaturesOutput mockedFeaturesOutput;
when(requestContext.getXid()).thenReturn(new Xid(84L));
when(requestContext.getFuture()).thenReturn(RpcResultBuilder.success().buildFuture());
- when(mockedDeviceState.getNodeInstanceIdentifier()).thenReturn(NODE_II);
- when(mockedDeviceState.getFeatures()).thenReturn(mockedFeaturesOutput);
+ when(mockedDeviceInfo.getNodeInstanceIdentifier()).thenReturn(NODE_II);
+ when(mockedDeviceInfo.getDatapathId()).thenReturn(DUMMY_DATAPATH_ID);
+ when(mockedDeviceInfo.getVersion()).thenReturn(DUMMY_VERSION);
when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
+ when(mockedDeviceContext.getDeviceInfo()).thenReturn(mockedDeviceInfo);
salFlowService = new SalFlowServiceImpl(mockedRequestContextStack, mockedDeviceContext);
}
import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
@Mock
private DeviceState mockDeviceState;
+ @Mock
+ private DeviceInfo mockDeviceInfo;
+
@Mock
private GetFeaturesOutput mockFeaturesOutput;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
- Mockito.when(mockDeviceState.getNodeId()).thenReturn(testNodeId);
- Mockito.when(mockDeviceState.getFeatures()).thenReturn(mockFeaturesOutput);
+ Mockito.when(mockDeviceInfo.getNodeId()).thenReturn(testNodeId);
+ Mockito.when(mockDeviceInfo.getDatapathId()).thenReturn(BigInteger.TEN);
Mockito.when(mockFeaturesOutput.getVersion()).thenReturn(testVersion);
Mockito.when(mockDeviceContext.getDeviceState()).thenReturn(mockDeviceState);
+ Mockito.when(mockDeviceContext.getDeviceInfo()).thenReturn(mockDeviceInfo);
Mockito.when(mockDeviceContext.getPrimaryConnectionContext()).thenReturn(mockConnectionContext);
Mockito.when(mockConnectionContext.getFeatures()).thenReturn(mockFeaturesReply);
Mockito.when(mockConnectionContext.getNodeId()).thenReturn(testNodeId);
import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
import org.opendaylight.openflowplugin.api.OFConstants;
import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
@Mock
protected DeviceState mockedDeviceState;
@Mock
+ protected DeviceInfo mockedDeviceInfo;
+ @Mock
protected DeviceInitializationPhaseHandler mockedDevicePhaseHandler;
@Mock
protected RequestContext mockedRequestContext;
when(mockedPrimConnectionContext.getConnectionState()).thenReturn(ConnectionContext.CONNECTION_STATE.WORKING);
when(mockedPrimConnectionContext.getOutboundQueueProvider()).thenReturn(mockedOutboundQueue);
- when(mockedDeviceState.getNodeInstanceIdentifier()).thenReturn(NODE_II);
- when(mockedDeviceState.getFeatures()).thenReturn(mockedFeaturesOutput);
+ when(mockedDeviceInfo.getNodeInstanceIdentifier()).thenReturn(NODE_II);
+ when(mockedDeviceInfo.getDatapathId()).thenReturn(DUMMY_DATAPATH_ID);
+ when(mockedDeviceInfo.getVersion()).thenReturn(DUMMY_VERSION);
when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedPrimConnectionContext);
when(mockedDeviceContext.getMessageSpy()).thenReturn(mockedMessagSpy);
when(mockedDeviceContext.getDeviceFlowRegistry()).thenReturn(new DeviceFlowRegistryImpl());
when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
+ when(mockedDeviceContext.getDeviceInfo()).thenReturn(mockedDeviceInfo);
when(mockedDeviceContext.getMultiMsgCollector(Matchers.<RequestContext<List<MultipartReply>>>any())).thenReturn(multiMessageCollector);
setup();
import static org.mockito.Mockito.when;
import org.junit.Before;
-import org.mockito.Mockito;
import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
+import java.math.BigInteger;
+
class StatisticsContextImpMockInitiation {
Boolean isTable = false;
when(mockedDeviceState.isMetersAvailable()).thenReturn(isMeter);
when(mockedDeviceState.isPortStatisticsAvailable()).thenReturn(isPort);
when(mockedDeviceState.isQueueStatisticsAvailable()).thenReturn(isQueue);
- when(mockedDeviceState.getNodeInstanceIdentifier()).thenReturn(dummyNodeII);
- when(mockedDeviceState.getFeatures()).thenReturn(mockedFeaturesOutput);
+ when(mockedDeviceInfo.getNodeInstanceIdentifier()).thenReturn(dummyNodeII);
+ when(mockedDeviceInfo.getDatapathId()).thenReturn(BigInteger.TEN);
when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
+ when(mockedDeviceContext.getDeviceInfo()).thenReturn(mockedDeviceInfo);
when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedConnectionContext);
when(mockedDeviceContext.getMessageSpy()).thenReturn(mockedMessageSpy);
when(mockedConnectionContext.getConnectionState()).thenReturn(ConnectionContext.CONNECTION_STATE.WORKING);
when(mockedConnectionContext.getOutboundQueueProvider()).thenReturn(mockedOutboundQueue);
- when(mockedDeviceManager.getDeviceContextFromNodeId(Mockito.<NodeId>any())).thenReturn(mockedDeviceContext);
+ when(mockedDeviceManager.getDeviceContextFromNodeId(mockedDeviceInfo)).thenReturn(mockedDeviceContext);
mockConductor.setSafelyDeviceManager(mockedDeviceManager);
- when(mockConductor.getDeviceContext(Mockito.<NodeId>any())).thenReturn(mockedDeviceContext);
+ when(mockConductor.getDeviceContext(mockedDeviceInfo)).thenReturn(mockedDeviceContext);
}
}
import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.EventIdentifier;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
@Before
public void setUp() throws Exception {
when(mockedDeviceContext.reserveXidForDeviceMessage()).thenReturn(TEST_XID);
- when(mockConductor.getDeviceContext(Mockito.<NodeId>any())).thenReturn(mockedDeviceContext);
+ when(mockConductor.getDeviceContext(mockedDeviceInfo)).thenReturn(mockedDeviceContext);
initStatisticsContext();
}
@Test
public void testGatherDynamicData_all() throws Exception {
Mockito.reset(mockedDeviceState);
- when(mockedDeviceState.getFeatures()).thenReturn(mock(GetFeaturesOutput.class));
when(mockedDeviceState.isTableStatisticsAvailable()).thenReturn(Boolean.TRUE);
when(mockedDeviceState.isFlowStatisticsAvailable()).thenReturn(Boolean.TRUE);
when(mockedDeviceState.isGroupAvailable()).thenReturn(Boolean.TRUE);
when(mockedDeviceState.isMetersAvailable()).thenReturn(Boolean.TRUE);
when(mockedDeviceState.isPortStatisticsAvailable()).thenReturn(Boolean.TRUE);
when(mockedDeviceState.isQueueStatisticsAvailable()).thenReturn(Boolean.TRUE);
- when(mockedDeviceState.getNodeInstanceIdentifier()).thenReturn(dummyNodeII);
+ when(mockedDeviceInfo.getNodeInstanceIdentifier()).thenReturn(dummyNodeII);
initStatisticsContext();
when(mockedStatisticsGatheringService.getStatisticsOfType(Matchers.any(EventIdentifier.class), Matchers.any(MultipartType.class)))
import org.opendaylight.openflowplugin.api.OFConstants;
import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
import org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry;
import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey;
private ConnectionContext connectionAdapter;
@Mock
private StatisticsGatherer statisticsService;
+ @Mock
+ private DeviceInfo deviceInfo;
public StatisticsGatheringUtilsTest() {
OpenflowPortsUtil.init();
@Before
public void setUp() throws Exception {
when(deviceContext.getDeviceState()).thenReturn(deviceState);
+ when(deviceContext.getDeviceInfo()).thenReturn(deviceInfo);
when(deviceContext.getDeviceFlowRegistry()).thenReturn(deviceFlowRegistry);
when(deviceContext.getDeviceGroupRegistry()).thenReturn(deviceGroupRegistry);
when(deviceContext.getDeviceMeterRegistry()).thenReturn(deviceMeterRegistry);
when(deviceContext.getReadTransaction()).thenReturn(readTx);
when(deviceContext.getPrimaryConnectionContext()).thenReturn(connectionAdapter);
when(connectionAdapter.getNodeId()).thenReturn(DUMMY_NODE_ID);
- when(deviceState.getFeatures()).thenReturn(features);
when(connectionAdapter.getFeatures()).thenReturn(features);
-
- when(features.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
when(features.getDatapathId()).thenReturn(BigInteger.ONE);
+ when(features.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
+
+ when(deviceInfo.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
+ when(deviceInfo.getDatapathId()).thenReturn(BigInteger.ONE);
- when(deviceState.getNodeInstanceIdentifier()).thenReturn(dummyNodePath);
+ when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(dummyNodePath);
}
@After
final ArgumentCaptor<Flow> flow = ArgumentCaptor.forClass(Flow.class);
StatisticsGatheringUtils.writeFlowStatistics(prepareFlowStatisticsData(),
- deviceContext.getDeviceState(), deviceContext.getDeviceFlowRegistry(), deviceContext);
+ deviceInfo, deviceContext.getDeviceFlowRegistry(), deviceContext);
Mockito.verify(deviceContext).writeToTransaction(
dataStoreType.capture(), flowPath.capture(), flow.capture());
@Test
public void testDeleteAllKnownFlowsNotSync() throws Exception {
when(deviceState.deviceSynchronized()).thenReturn(false);
- StatisticsGatheringUtils.deleteAllKnownFlows(deviceContext.getDeviceState(),
- deviceContext.getDeviceFlowRegistry(), deviceContext);
+ StatisticsGatheringUtils.deleteAllKnownFlows(deviceInfo,
+ deviceContext.getDeviceFlowRegistry(), deviceContext, deviceState);
Mockito.verifyNoMoreInteractions(deviceFlowRegistry);
}
public void testDeleteAllKnownFlows() throws Exception {
final short tableId = 0;
when(deviceState.deviceSynchronized()).thenReturn(true);
- final InstanceIdentifier<FlowCapableNode> nodePath = deviceState.getNodeInstanceIdentifier().augmentation(FlowCapableNode.class);
+ final InstanceIdentifier<FlowCapableNode> nodePath = deviceInfo.getNodeInstanceIdentifier().augmentation(FlowCapableNode.class);
final TableBuilder tableDataBld = new TableBuilder();
tableDataBld.setId(tableId);
final FlowCapableNodeBuilder flowNodeBuilder = new FlowCapableNodeBuilder();
final Optional<FlowCapableNode> flowNodeOpt = Optional.of(flowNodeBuilder.build());
final CheckedFuture<Optional<FlowCapableNode>, ReadFailedException> flowNodeFuture = Futures.immediateCheckedFuture(flowNodeOpt);
when(readTx.read(LogicalDatastoreType.OPERATIONAL, nodePath)).thenReturn(flowNodeFuture);
- final KeyedInstanceIdentifier<Table, TableKey> tablePath = deviceState.getNodeInstanceIdentifier()
+ final KeyedInstanceIdentifier<Table, TableKey> tablePath = deviceInfo.getNodeInstanceIdentifier()
.augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tableId));
- StatisticsGatheringUtils.deleteAllKnownFlows(deviceContext.getDeviceState(),
- deviceContext.getDeviceFlowRegistry(), deviceContext);
+ StatisticsGatheringUtils.deleteAllKnownFlows(deviceInfo,
+ deviceContext.getDeviceFlowRegistry(), deviceContext, deviceState);
verify(deviceContext).writeToTransaction(
LogicalDatastoreType.OPERATIONAL,
when(mockedDeviceState.isPortStatisticsAvailable()).thenReturn(Boolean.TRUE);
when(mockedDeviceState.isQueueStatisticsAvailable()).thenReturn(Boolean.TRUE);
when(mockedDeviceState.isTableStatisticsAvailable()).thenReturn(Boolean.TRUE);
- when(mockedDeviceState.getFeatures()).thenReturn(featuresOutput);
- when(mockedDeviceState.getNodeInstanceIdentifier()).thenReturn(nodePath);
+ when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(nodePath);
when(deviceInfo.getNodeId()).thenReturn(NODE_ID);
- when(mockedDeviceState.getNodeId()).thenReturn(NODE_ID);
+ when(mockedDeviceContext.getDeviceInfo()).thenReturn(deviceInfo);
when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedPrimConnectionContext);
when(mockedDeviceContext.getMessageSpy()).thenReturn(mockedMessagSpy);
when(mockedDeviceContext.getDeviceFlowRegistry()).thenReturn(new DeviceFlowRegistryImpl());
statisticsManager = new StatisticsManagerImpl(rpcProviderRegistry, false, conductor);
statisticsManager.setDeviceInitializationPhaseHandler(deviceInitializationPhaseHandler);
- when(deviceManager.getDeviceContextFromNodeId(Mockito.<NodeId>any())).thenReturn(mockedDeviceContext);
- when(conductor.getDeviceContext(Mockito.<NodeId>any())).thenReturn(mockedDeviceContext);
+ when(deviceManager.getDeviceContextFromNodeId(deviceInfo)).thenReturn(mockedDeviceContext);
+ when(conductor.getDeviceContext(deviceInfo)).thenReturn(mockedDeviceContext);
}
@Test
final TimeCounter mockTimerCounter = Mockito.mock(TimeCounter.class);
statisticsManager.pollStatistics(mockedDeviceContext, statisticsContext, mockTimerCounter);
- verify(mockedDeviceContext).getDeviceState();
+ verify(mockedDeviceContext).getDeviceInfo();
when(mockedDeviceContext.getDeviceState().isValid()).thenReturn(true);
statisticsManager.pollStatistics(mockedDeviceContext, statisticsContext, mockTimerCounter);
import org.opendaylight.openflowplugin.api.OFConstants;
import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
protected TranslatorLibrary translatorLibrary;
@Mock
protected DeviceState deviceState;
+ @Mock
+ protected DeviceInfo deviceInfo;
public static final NodeId NODE_ID = new NodeId("unit-test-node:123");
Mockito.when(deviceContext.getMultiMsgCollector(Matchers.any(RequestContext.class))).thenReturn(multiMsgCollector);
Mockito.when(deviceContext.oook()).thenReturn(translatorLibrary);
Mockito.when(deviceContext.getDeviceState()).thenReturn(deviceState);
- Mockito.when(deviceState.getNodeId()).thenReturn(NODE_ID);
- Mockito.when(deviceState.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
- Mockito.when(deviceState.getFeatures()).thenReturn(getFeaturesOutput);
+ Mockito.when(deviceContext.getDeviceInfo()).thenReturn(deviceInfo);
+ Mockito.when(deviceInfo.getNodeId()).thenReturn(NODE_ID);
+ Mockito.when(deviceInfo.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
+ Mockito.when(deviceInfo.getDatapathId()).thenReturn(BigInteger.TEN);
Mockito.when(connectionContext.getFeatures()).thenReturn(features);
Mockito.when(connectionContext.getOutboundQueueProvider()).thenReturn(outboundQueueProvider);
Mockito.when(features.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
}
).when(multiMsgCollector).endCollecting(Matchers.any(EventIdentifier.class));
Mockito.when(translator.translate(
- Matchers.any(MultipartReply.class), Matchers.same(deviceState), Matchers.isNull())
+ Matchers.any(MultipartReply.class), Matchers.same(deviceInfo), Matchers.isNull())
).thenReturn(new AggregatedFlowStatisticsBuilder().build());
import org.mockito.stubbing.Answer;
import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
import org.opendaylight.openflowplugin.api.OFConstants;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
import org.opendaylight.openflowplugin.api.openflow.device.MessageTranslator;
import org.opendaylight.openflowplugin.api.openflow.md.core.TranslatorKey;
@Mock
private DeviceState deviceState;
@Mock
+ private DeviceInfo deviceInfo;
+ @Mock
private MessageTranslator<Object, Object> translator;
@Mock
private GetFeaturesOutput featuresOutput;
Mockito.when(featuresOutput.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
Mockito.when(rqContextStack.<Object>createRequestContext()).thenReturn(rqContext);
Mockito.when(deviceContext.getDeviceState()).thenReturn(deviceState);
- Mockito.when(deviceState.getNodeId()).thenReturn(NODE_ID);
- Mockito.when(deviceState.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
- Mockito.when(deviceState.getFeatures()).thenReturn(featuresOutput);
+ Mockito.when(deviceContext.getDeviceInfo()).thenReturn(deviceInfo);
+ Mockito.when(deviceInfo.getNodeId()).thenReturn(NODE_ID);
+ Mockito.when(deviceInfo.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
Mockito.doAnswer(closeRequestFutureAnswer).when(multiMsgCollector).endCollecting();
Mockito.doAnswer(closeRequestFutureAnswer).when(multiMsgCollector).endCollecting(Matchers.any(EventIdentifier.class));
.setFlowCount(new Counter32(12L))
.setPacketCount(new Counter64(BigInteger.valueOf(13L)))
.build();
- Mockito.when(translator.translate(Matchers.any(MultipartReply.class), Matchers.eq(deviceState), Matchers.any()))
+ Mockito.when(translator.translate(Matchers.any(MultipartReply.class), Matchers.eq(deviceInfo), Matchers.any()))
.thenReturn(aggregatedStats);
.setNode(createNodeRef("unitProt:123"))
.setTableId(new TableId((short) 1));
- Mockito.when(translator.translate(Matchers.any(MultipartReply.class), Matchers.eq(deviceState), Matchers.any()))
+ Mockito.when(translator.translate(Matchers.any(MultipartReply.class), Matchers.eq(deviceInfo), Matchers.any()))
.thenReturn(new AggregatedFlowStatisticsBuilder()
.setByteCount(new Counter64(BigInteger.valueOf(50L)))
.setPacketCount(new Counter64(BigInteger.valueOf(51L)))
protected void setup() {
statisticsGatheringService = new StatisticsGatheringOnTheFlyService(mockedRequestContextStack, mockedDeviceContext);
Mockito.doReturn(NODE_ID).when(mockedPrimConnectionContext).getNodeId();
- Mockito.when(mockedDeviceContext.getDeviceState().getNodeId()).thenReturn(NODE_ID);
+ Mockito.when(mockedDeviceInfo.getNodeId()).thenReturn(NODE_ID);
}
@Test
import org.opendaylight.openflowplugin.api.OFConstants;
import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
import org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary;
@Mock
protected DeviceState deviceState;
@Mock
- protected GetFeaturesOutput getFeaturesOutput;
+ protected DeviceInfo deviceInfo;
protected NodeConnectorId nodeConnectorId;
protected KeyedInstanceIdentifier<Node, NodeKey> nodeInstanceIdentifier;
when(deviceContext.getMultiMsgCollector(any())).thenReturn(multiMsgCollector);
when(deviceContext.oook()).thenReturn(translatorLibrary);
when(deviceContext.getDeviceState()).thenReturn(deviceState);
- when(deviceContext.getDeviceState()).thenReturn(deviceState);
- when(deviceState.getNodeInstanceIdentifier()).thenReturn(nodeInstanceIdentifier);
- when(deviceState.getNodeId()).thenReturn(new NodeId(NODE_ID));
- when(deviceState.getVersion()).thenReturn(OF_VERSION);
- when(deviceState.getFeatures()).thenReturn(getFeaturesOutput);
- when(getFeaturesOutput.getVersion()).thenReturn(OF_VERSION);
- when(getFeaturesOutput.getDatapathId()).thenReturn(DATAPATH_ID);
+ when(deviceContext.getDeviceInfo()).thenReturn(deviceInfo);
+ when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(nodeInstanceIdentifier);
+ when(deviceInfo.getNodeId()).thenReturn(new NodeId(NODE_ID));
+ when(deviceInfo.getVersion()).thenReturn(OF_VERSION);
+ when(deviceInfo.getDatapathId()).thenReturn(DATAPATH_ID);
when(connectionContext.getFeatures()).thenReturn(features);
when(connectionContext.getOutboundQueueProvider()).thenReturn(outboundQueueProvider);
when(features.getVersion()).thenReturn(OF_VERSION);
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.get.aggregate.flow.statistics.from.flow.table._for.given.match.output.AggregatedFlowStatistics;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder;
private AggregatedFlowStatisticsTranslator translator;
@Mock
private DeviceState deviceState;
+ @Mock
+ private DeviceInfo deviceInfo;
@Before
public void setUp() throws Exception {
MultipartReplyMessageBuilder mpInputBld = new MultipartReplyMessageBuilder()
.setMultipartReplyBody(inputBld.build());
- final AggregatedFlowStatistics statistics = translator.translate(mpInputBld.build(), deviceState, null);
+ final AggregatedFlowStatistics statistics = translator.translate(mpInputBld.build(), deviceInfo, null);
Assert.assertEquals(aggregateStatsValueBld.getByteCount(), statistics.getByteCount().getValue());
Assert.assertEquals(aggregateStatsValueBld.getFlowCount(), statistics.getFlowCount().getValue());
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
@Mock
private DeviceState deviceState;
+ @Mock
+ private DeviceInfo deviceInfo;
+
@Mock
private GetFeaturesOutput features;
translatorV10 = new FlowRemovedV10Translator();
when(deviceContext.getDeviceState()).thenReturn(deviceState);
- when(deviceState.getNodeInstanceIdentifier()).thenReturn(nodeId);
- when(deviceState.getFeatures()).thenReturn(features);
+ when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(nodeId);
when(features.getDatapathId()).thenReturn(BigInteger.TEN);
}
@Test
public void testTranslate() throws Exception {
org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemoved flowRemovedMessage = buildMessage(false);
- final FlowRemoved flowRemoved = translator.translate(flowRemovedMessage, deviceState, null);
+ final FlowRemoved flowRemoved = translator.translate(flowRemovedMessage, deviceInfo, null);
assertEquals(flowRemovedMessage.getCookie(), flowRemoved.getCookie().getValue());
assertEquals(flowRemovedMessage.getPriority(), flowRemoved.getPriority());
@Test
public void testTranslateV10() throws Exception {
org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemoved flowRemovedMessage = buildMessage(true);
- final FlowRemoved flowRemoved = translatorV10.translate(flowRemovedMessage, deviceState, null);
+ final FlowRemoved flowRemoved = translatorV10.translate(flowRemovedMessage, deviceInfo, null);
assertEquals(flowRemovedMessage.getCookie(), flowRemoved.getCookie().getValue());
assertEquals(flowRemovedMessage.getPriority(), flowRemoved.getPriority());
import org.opendaylight.openflowplugin.api.OFConstants;
import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
@Mock
DeviceContext deviceContext;
@Mock
+ DeviceInfo deviceInfo;
+ @Mock
List<PhyPort> phyPorts;
@Mock
PhyPort phyPort;
Mockito.when(connectionContext.getFeatures()).thenReturn(featuresReply);
Mockito.when(featuresReply.getDatapathId()).thenReturn(BigInteger.TEN);
Mockito.when(deviceContext.getDeviceState()).thenReturn(deviceState);
- Mockito.when(deviceState.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
- Mockito.when(deviceState.getFeatures()).thenReturn(getFeaturesOutput);
+ Mockito.when(deviceInfo.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
+ Mockito.when(deviceInfo.getDatapathId()).thenReturn(BigInteger.TEN);
Mockito.when(getFeaturesOutput.getDatapathId()).thenReturn(BigInteger.TEN);
Mockito.when(getFeaturesOutput.getPhyPort()).thenReturn(phyPorts);
Mockito.when(phyPort.getPortNo()).thenReturn(PORT_NO_DS);
.child(Node.class, new NodeKey(new NodeId("openflow:10")));
final PacketReceivedTranslator packetReceivedTranslator = new PacketReceivedTranslator();
final PacketInMessage packetInMessage = createPacketInMessage(DATA.getBytes(), PORT_NO);
- Mockito.when(deviceState.getNodeInstanceIdentifier()).thenReturn(nodePath);
+ Mockito.when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(nodePath);
- final PacketReceived packetReceived = packetReceivedTranslator.translate(packetInMessage, deviceState, null);
+ final PacketReceived packetReceived = packetReceivedTranslator.translate(packetInMessage, deviceInfo, null);
Assert.assertArrayEquals(packetInMessage.getData(), packetReceived.getPayload());
Assert.assertEquals("org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.SendToController",
import org.mockito.runners.MockitoJUnitRunner;
import org.opendaylight.openflowplugin.api.OFConstants;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
private DeviceContext deviceContext;
@Mock
private DeviceState deviceState;
+ @Mock
+ private DeviceInfo deviceInfo;
private org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortConfig portConfig;
private StateBuilder portStateBld;
@Before
public void setUp() throws Exception {
- Mockito.when(deviceContext.getDeviceState()).thenReturn(deviceState);
+ Mockito.when(deviceContext.getDeviceInfo()).thenReturn(deviceInfo);
portUpdateTranslator = new PortUpdateTranslator();
portStateBld = new StateBuilder().setLive(true);
@Test
public void testTranslate_13() throws Exception {
- Mockito.when(deviceState.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
+ Mockito.when(deviceInfo.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortFeatures portFeatures =
org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortFeatures
.getDefaultInstance("hundredGbFd");
- final FlowCapableNodeConnector nodeConnector = portUpdateTranslator.translate(portBld.build(), deviceState, null);
+ final FlowCapableNodeConnector nodeConnector = portUpdateTranslator.translate(portBld.build(), deviceInfo, null);
commonCheck(nodeConnector);
@Test
public void testTranslate_10() throws Exception {
- Mockito.when(deviceState.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_0);
+ Mockito.when(deviceInfo.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_0);
final org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortFeatures portFeatures =
new org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortFeatures(
null, null, null, false, false, true, null, null,
null, false, false, null, null, null, null, null
);
- final FlowCapableNodeConnector nodeConnector = portUpdateTranslator.translate(portBld.build(), deviceState, null);
+ final FlowCapableNodeConnector nodeConnector = portUpdateTranslator.translate(portBld.build(), deviceInfo, null);
commonCheck(nodeConnector);
import org.opendaylight.openflowplugin.api.OFConstants;
import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
import org.opendaylight.openflowplugin.api.openflow.device.MessageTranslator;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
@Mock
private DeviceContextImpl mockedDeviceContext;
@Mock
+ private DeviceInfo mockedDeviceInfo;
+ @Mock
private DeviceInitializationUtils deviceInitializationUtils;
@Before
when(mockConnectionContext.getFeatures()).thenReturn(mockFeatures);
when(mockConnectionContext.getConnectionAdapter()).thenReturn(mockedConnectionAdapter);
when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockConnectionContext);
+ when(mockedDeviceContext.getDeviceInfo()).thenReturn(mockedDeviceInfo);
final Capabilities capabilitiesV13 = mock(Capabilities.class);
final CapabilitiesV10 capabilitiesV10 = mock(CapabilitiesV10.class);
GetFeaturesOutput mockedFeatures = mock(GetFeaturesOutput.class);
when(mockedFeatures.getTables()).thenReturn((short) 2);
- when(mockedDeviceState.getFeatures()).thenReturn(mockedFeatures);
- when(mockedDeviceState.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_0);
+ when(mockedDeviceInfo.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_0);
- when(mockedDeviceState.getNodeInstanceIdentifier()).thenReturn(DUMMY_NODE_II);
+ when(mockedDeviceInfo.getNodeInstanceIdentifier()).thenReturn(DUMMY_NODE_II);
when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
when(mockedDeviceContext.getMultiMsgCollector(Mockito.any(RequestContext.class))).thenReturn(msgCollector);
when(mockedDeviceContext.oook()).thenReturn(tLibrary);
final GetFeaturesOutput mockedFeatures = mock(GetFeaturesOutput.class);
when(mockedFeatures.getTables()).thenReturn((short) 2);
- when(mockedDeviceState.getFeatures()).thenReturn(mockedFeatures);
+ when(mockConnectionContext.getFeatures()).thenReturn(mockedFeatures);
- when(mockedDeviceState.getNodeInstanceIdentifier()).thenReturn(DUMMY_NODE_II);
+ when(mockedDeviceInfo.getNodeInstanceIdentifier()).thenReturn(DUMMY_NODE_II);
when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
final RpcResult<List<MultipartReply>> mockedRpcResult = mock(RpcResult.class);
when(mockedPrimaryConnectionContext.getFeatures()).thenReturn(mockedFeatures);
when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedPrimaryConnectionContext);
final DeviceState mockedDeviceState = mock(DeviceState.class);
- when(mockedDeviceState.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_0);
+ when(mockedDeviceInfo.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_0);
when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
final MessageTranslator mockedTranslator = mock(MessageTranslator.class);
when(translatorLibrary.lookupTranslator(any(TranslatorKey.class))).thenReturn(mockedTranslator);
import org.mockito.Matchers;
import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
final DeviceState mockedDeviceState = mock(DeviceState.class);
when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
+ final DeviceInfo mockedDeviceInfo = mock(DeviceInfo.class);
+ when(mockedDeviceContext.getDeviceInfo()).thenReturn(mockedDeviceInfo);
+
final FeaturesReply mockedFeatures = mock(FeaturesReply.class);
when(mockedConnectionContext.getFeatures()).thenReturn(mockedFeatures);
final GetFeaturesOutput mockedFeaturesOutput = mock(GetFeaturesOutput.class);
- when(mockedDeviceState.getFeatures()).thenReturn(mockedFeaturesOutput);
final BigInteger mockedDataPathId = mock(BigInteger.class);
when(mockedFeatures.getDatapathId()).thenReturn(mockedDataPathId);
when(mockedFeaturesOutput.getDatapathId()).thenReturn(mockedDataPathId);
+ when(mockedDeviceInfo.getDatapathId()).thenReturn(mockedDataPathId);
when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedConnectionContext);
MdSalRegistrationUtils.registerMasterServices(mockedRpcContext, mockedDeviceContext, OfpRole.BECOMEMASTER);