From 41acc3f4b03b00fe04cafb9851afa2d4db7a214c Mon Sep 17 00:00:00 2001 From: Tomas Slusny Date: Mon, 4 Apr 2016 16:43:14 +0200 Subject: [PATCH] Bug 5592 - NodeId+DatapathId in Services (remove dependency on DeviceContext) - Changed AbstractService.getVersion and AbstractService.getDatapathId to return data from DeviceState - Added AbstractService.getNodeId what returns nodeId from DeviceState - Updated all ocurences of getting above 3 values in subclasses to use these methods - Updated tests (in most of them, DeviceState was not mocked) Change-Id: Ie0b38788d66687c07d1a6265006d0026076f8dc9 Signed-off-by: Tomas Slusny --- .../impl/services/AbstractService.java | 23 ++++++++++++------- .../impl/services/RoleService.java | 11 ++++----- .../impl/services/SalRoleServiceImpl.java | 14 ++++------- .../impl/services/SalTableServiceImpl.java | 3 +-- .../services/MatchingFlowsInTableService.java | 3 +-- .../AbstractCompatibleStatService.java | 2 +- .../StatisticsGatheringOnTheFlyService.java | 2 +- .../dedicated/StatisticsGatheringService.java | 2 +- .../impl/role/RoleManagerImplTest.java | 10 ++++++++ .../impl/rpc/RpcManagerImplTest.java | 22 +++++++++++++++++- .../impl/services/SalFlowServiceImplTest.java | 13 +++++++---- .../impl/services/SalRoleServiceImplTest.java | 12 ++++++++++ .../impl/services/ServiceMocking.java | 8 ++++++- .../StatisticsContextImpMockInitiation.java | 22 +++++++++++------- .../statistics/StatisticsContextImplTest.java | 4 ++++ .../statistics/StatisticsManagerImplTest.java | 8 +++++++ .../services/AbstractStatsServiceTest.java | 3 ++- .../AbstractCompatibleStatServiceTest.java | 5 ++++ .../impl/util/MdSalRegistrationUtilsTest.java | 11 ++++++++- 19 files changed, 132 insertions(+), 46 deletions(-) diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/AbstractService.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/AbstractService.java index 5888d2b443..f1bdbf116d 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/AbstractService.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/AbstractService.java @@ -14,15 +14,16 @@ import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import java.math.BigInteger; import javax.annotation.Nonnull; -import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter; import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue; import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceState; import org.opendaylight.openflowplugin.api.openflow.device.RequestContext; import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; import org.opendaylight.openflowplugin.api.openflow.device.Xid; import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.EventIdentifier; import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; import org.opendaylight.yangtools.yang.binding.DataContainer; import org.opendaylight.yangtools.yang.common.RpcError; @@ -40,18 +41,20 @@ abstract class AbstractService { private final BigInteger datapathId; private final RequestContextStack requestContextStack; private final DeviceContext deviceContext; - private final ConnectionAdapter primaryConnectionAdapter; private final MessageSpy messageSpy; + private final NodeId nodeId; private EventIdentifier eventIdentifier; public AbstractService(final RequestContextStack requestContextStack, final DeviceContext deviceContext) { + final DeviceState deviceState = deviceContext.getDeviceState(); + final GetFeaturesOutput features = deviceState.getFeatures(); + this.requestContextStack = requestContextStack; this.deviceContext = deviceContext; - final FeaturesReply features = this.deviceContext.getPrimaryConnectionContext().getFeatures(); this.datapathId = features.getDatapathId(); this.version = features.getVersion(); - this.primaryConnectionAdapter = deviceContext.getPrimaryConnectionContext().getConnectionAdapter(); this.messageSpy = deviceContext.getMessageSpy(); + this.nodeId = deviceState.getNodeId(); } public EventIdentifier getEventIdentifier() { @@ -70,6 +73,10 @@ abstract class AbstractService { return datapathId; } + public NodeId getNodeId() { + return nodeId; + } + public RequestContextStack getRequestContextStack() { return requestContextStack; } @@ -101,16 +108,16 @@ abstract class AbstractService { final RequestContext requestContext = requestContextStack.createRequestContext(); if (requestContext == null) { LOG.trace("Request context refused."); - deviceContext.getMessageSpy().spyMessage(AbstractService.class, MessageSpy.STATISTIC_GROUP.TO_SWITCH_DISREGARDED); + getMessageSpy().spyMessage(AbstractService.class, MessageSpy.STATISTIC_GROUP.TO_SWITCH_DISREGARDED); return failedFuture(); } if (requestContext.getXid() == null) { - deviceContext.getMessageSpy().spyMessage(requestContext.getClass(), MessageSpy.STATISTIC_GROUP.TO_SWITCH_RESERVATION_REJECTED); + getMessageSpy().spyMessage(requestContext.getClass(), MessageSpy.STATISTIC_GROUP.TO_SWITCH_RESERVATION_REJECTED); return RequestContextUtil.closeRequestContextWithRpcError(requestContext, "Outbound queue wasn't able to reserve XID."); } - messageSpy.spyMessage(requestContext.getClass(), MessageSpy.STATISTIC_GROUP.TO_SWITCH_READY_FOR_SUBMIT); + getMessageSpy().spyMessage(requestContext.getClass(), MessageSpy.STATISTIC_GROUP.TO_SWITCH_READY_FOR_SUBMIT); final Xid xid = requestContext.getXid(); OfHeader request = null; diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/RoleService.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/RoleService.java index 0bf66fa960..c677c53a68 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/RoleService.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/RoleService.java @@ -54,8 +54,7 @@ public class RoleService extends AbstractSimpleService getGenerationIdFromDevice(final Short version) { - final NodeId nodeId = deviceContext.getPrimaryConnectionContext().getNodeId(); - LOG.info("getGenerationIdFromDevice called for device:{}", nodeId.getValue()); + LOG.info("getGenerationIdFromDevice called for device:{}", getNodeId().getValue()); // send a dummy no-change role request to get the generation-id of the switch final RoleRequestInputBuilder roleRequestInputBuilder = new RoleRequestInputBuilder(); @@ -75,7 +74,7 @@ public class RoleService extends AbstractSimpleService> submitRoleChange(final OfpRole ofpRole, final Short version, final BigInteger generationId) { LOG.info("submitRoleChange called for device:{}, role:{}", - deviceContext.getPrimaryConnectionContext().getNodeId(), ofpRole); + getNodeId(), ofpRole); final RoleRequestInputBuilder roleRequestInputBuilder = new RoleRequestInputBuilder(); roleRequestInputBuilder.setRole(toOFJavaRole(ofpRole)); roleRequestInputBuilder.setVersion(version); @@ -111,7 +110,7 @@ public class RoleService extends AbstractSimpleService roleRequestOutputRpcResult) { LOG.info("submitRoleChange onSuccess for device:{}, role:{}", - deviceContext.getPrimaryConnectionContext().getNodeId(), ofpRole); + getNodeId(), ofpRole); final RoleRequestOutput roleRequestOutput = roleRequestOutputRpcResult.getResult(); final Collection rpcErrors = roleRequestOutputRpcResult.getErrors(); if (roleRequestOutput != null) { @@ -133,7 +132,7 @@ public class RoleService extends AbstractSimpleService> tryToChangeRole(final OfpRole role) { - LOG.info("RoleChangeTask called on device:{} OFPRole:{}", nodeId.getValue(), role); + LOG.info("RoleChangeTask called on device:{} OFPRole:{}", getNodeId().getValue(), role); - final Future generationFuture = roleService.getGenerationIdFromDevice(version); + final Future generationFuture = roleService.getGenerationIdFromDevice(getVersion()); return Futures.transform(JdkFutureAdapters.listenInPoolThread(generationFuture), (AsyncFunction>) generationId -> { - LOG.debug("RoleChangeTask, GenerationIdFromDevice from device {} is {}", nodeId.getValue(), generationId); + LOG.debug("RoleChangeTask, GenerationIdFromDevice from device {} is {}", getNodeId().getValue(), generationId); final BigInteger nextGenerationId = getNextGenerationId(generationId); - LOG.debug("nextGenerationId received from device:{} is {}", nodeId.getValue(), nextGenerationId); - final Future> submitRoleFuture = roleService.submitRoleChange(role, version, nextGenerationId); + LOG.debug("nextGenerationId received from device:{} is {}", getNodeId().getValue(), nextGenerationId); + final Future> submitRoleFuture = roleService.submitRoleChange(role, getVersion(), nextGenerationId); return JdkFutureAdapters.listenInPoolThread(submitRoleFuture); }); } diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/SalTableServiceImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/SalTableServiceImpl.java index 1c218b37b2..644ea77de8 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/SalTableServiceImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/SalTableServiceImpl.java @@ -114,9 +114,8 @@ public final class SalTableServiceImpl extends AbstractMultipartService salTableFeatures = convertToSalTableFeatures(multipartReplies); final DeviceContext deviceContext = getDeviceContext(); - final NodeId nodeId = deviceContext.getPrimaryConnectionContext().getNodeId(); final InstanceIdentifier flowCapableNodeII = InstanceIdentifier.create(Nodes.class) - .child(Node.class, new NodeKey(nodeId)).augmentation(FlowCapableNode.class); + .child(Node.class, new NodeKey(getNodeId())).augmentation(FlowCapableNode.class); for (final org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures tableFeatureData : salTableFeatures) { final Short tableId = tableFeatureData.getTableId(); final KeyedInstanceIdentifier tableFeaturesII = flowCapableNodeII diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/MatchingFlowsInTableService.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/MatchingFlowsInTableService.java index e15c0166b8..3de2abdba1 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/MatchingFlowsInTableService.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/MatchingFlowsInTableService.java @@ -61,8 +61,7 @@ final class MatchingFlowsInTableService extends AbstractMultipartService>> getStatisticsOfType(final EventIdentifier eventIdentifier, final MultipartType type) { - LOG.debug("Getting statistics (onTheFly) for node {} of type {}", getDeviceContext().getDeviceState().getNodeId(), type); + LOG.debug("Getting statistics (onTheFly) for node {} of type {}", getNodeId(), type); EventsTimeCounter.markStart(eventIdentifier); setEventIdentifier(eventIdentifier); return handleServiceCall(type); diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/dedicated/StatisticsGatheringService.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/dedicated/StatisticsGatheringService.java index 9a2eb17de6..c43ae604fc 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/dedicated/StatisticsGatheringService.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/dedicated/StatisticsGatheringService.java @@ -38,7 +38,7 @@ public class StatisticsGatheringService extends AbstractMultipartService>> getStatisticsOfType(final EventIdentifier eventIdentifier, final MultipartType type) { - LOG.debug("Getting statistics for node {} of type {}", getDeviceContext().getDeviceState().getNodeId(), type); + LOG.debug("Getting statistics for node {} of type {}", getNodeId(), type); EventsTimeCounter.markStart(eventIdentifier); setEventIdentifier(eventIdentifier); return handleServiceCall(type); diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/role/RoleManagerImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/role/RoleManagerImplTest.java index bba0245d9a..f91eeafd07 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/role/RoleManagerImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/role/RoleManagerImplTest.java @@ -36,6 +36,7 @@ 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.DeviceManager; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceState; import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitializationPhaseHandler; import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceTerminationPhaseHandler; import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor; @@ -43,6 +44,7 @@ import org.opendaylight.openflowplugin.api.openflow.lifecycle.RoleChangeListener import org.opendaylight.openflowplugin.api.openflow.role.RoleContext; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.OfpRole; /** @@ -92,6 +94,12 @@ public class RoleManagerImplTest { @Mock LifecycleConductor conductor; + @Mock + DeviceState deviceState; + + @Mock + GetFeaturesOutput featuresOutput; + private RoleManagerImpl roleManager; private RoleManagerImpl roleManagerSpy; private RoleContext roleContextSpy; @@ -107,9 +115,11 @@ public class RoleManagerImplTest { @Before public void setUp() throws Exception { CheckedFuture 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(connectionContext.getFeatures()).thenReturn(featuresReply); Mockito.when(connectionContext.getNodeId()).thenReturn(nodeId); Mockito.when(connectionContext.getConnectionState()).thenReturn(ConnectionContext.CONNECTION_STATE.WORKING); diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/rpc/RpcManagerImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/rpc/RpcManagerImplTest.java index 3d4a67d8c5..723447c16b 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/rpc/RpcManagerImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/rpc/RpcManagerImplTest.java @@ -34,6 +34,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.OfpRole; import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; @@ -57,6 +58,12 @@ public class RpcManagerImplTest { private MessageSpy mockMsgSpy; @Mock private LifecycleConductor conductor; + @Mock + private ConnectionContext connectionContext; + @Mock + private ItemLifeCycleRegistry itemLifeCycleRegistry; + @Mock + private MessageSpy messageSpy; @Rule public ExpectedException expectedException = ExpectedException.none(); @@ -70,8 +77,21 @@ public class RpcManagerImplTest { final NodeKey nodeKey = new NodeKey(nodeId); rpcManager = new RpcManagerImpl(rpcProviderRegistry, QUOTA_VALUE, conductor); rpcManager.setDeviceInitializationPhaseHandler(deviceINitializationPhaseHandler); + + GetFeaturesOutput featuresOutput = new GetFeaturesOutputBuilder() + .setVersion(OFConstants.OFP_VERSION_1_3) + .build(); + + FeaturesReply features = featuresOutput; + + Mockito.when(connectionContext.getFeatures()).thenReturn(features); + Mockito.when(deviceContext.getPrimaryConnectionContext()).thenReturn(connectionContext); Mockito.when(deviceContext.getDeviceState()).thenReturn(deviceState); - Mockito.when(deviceContext.getMessageSpy()).thenReturn(mockMsgSpy); + Mockito.when(deviceContext.getDeviceState().getRole()).thenReturn(OfpRole.BECOMEMASTER); + Mockito.when(deviceContext.getItemLifeCycleSourceRegistry()).thenReturn(itemLifeCycleRegistry); + Mockito.when(deviceState.getNodeInstanceIdentifier()).thenReturn(nodePath); + Mockito.when(deviceState.getFeatures()).thenReturn(featuresOutput); + Mockito.when(deviceContext.getMessageSpy()).thenReturn(messageSpy); Mockito.when(deviceState.getNodeId()).thenReturn(nodeKey.getId()); Mockito.when(conductor.getDeviceContext(Mockito.any())).thenReturn(deviceContext); } diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/SalFlowServiceImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/SalFlowServiceImplTest.java index 76c7ac43ce..3cf72599f8 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/SalFlowServiceImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/SalFlowServiceImplTest.java @@ -50,6 +50,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; @@ -92,14 +93,18 @@ public class SalFlowServiceImplTest extends TestCase { private SalFlowServiceImpl salFlowService; @Mock - DeviceState mockedDeviceState; + private DeviceState mockedDeviceState; @Mock private DeviceFlowRegistry deviceFlowRegistry; + @Mock + private GetFeaturesOutput mockedFeaturesOutput; @Before public void initialization() { when(mockedFeatures.getDatapathId()).thenReturn(DUMMY_DATAPATH_ID); when(mockedFeatures.getVersion()).thenReturn(DUMMY_VERSION); + when(mockedFeaturesOutput.getDatapathId()).thenReturn(DUMMY_DATAPATH_ID); + when(mockedFeaturesOutput.getVersion()).thenReturn(DUMMY_VERSION); when(mockedPrimConnectionContext.getFeatures()).thenReturn(mockedFeatures); when(mockedPrimConnectionContext.getConnectionAdapter()).thenReturn(mockedConnectionAdapter); @@ -114,11 +119,11 @@ public class SalFlowServiceImplTest extends TestCase { when(requestContext.getXid()).thenReturn(new Xid(84L)); when(requestContext.getFuture()).thenReturn(RpcResultBuilder.success().buildFuture()); - salFlowService = new SalFlowServiceImpl(mockedRequestContextStack, mockedDeviceContext); - - when(mockedDeviceState.getNodeInstanceIdentifier()).thenReturn(NODE_II); + when(mockedDeviceState.getFeatures()).thenReturn(mockedFeaturesOutput); when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState); + + salFlowService = new SalFlowServiceImpl(mockedRequestContextStack, mockedDeviceContext); } @Test diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/SalRoleServiceImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/SalRoleServiceImplTest.java index 2de3711cf9..35c702a512 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/SalRoleServiceImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/SalRoleServiceImplTest.java @@ -23,6 +23,7 @@ import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter; 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.DeviceState; import org.opendaylight.openflowplugin.api.openflow.device.RequestContext; import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack; import org.opendaylight.openflowplugin.api.openflow.device.Xid; @@ -34,6 +35,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.OfpRole; @@ -71,6 +73,12 @@ public class SalRoleServiceImplTest { @Mock private RequestContext mockRequestContext; + @Mock + private DeviceState mockDeviceState; + + @Mock + private GetFeaturesOutput mockFeaturesOutput; + @Mock private OutboundQueue mockOutboundQueue; @@ -85,6 +93,10 @@ public class SalRoleServiceImplTest { @Before public void setup() { MockitoAnnotations.initMocks(this); + Mockito.when(mockDeviceState.getNodeId()).thenReturn(testNodeId); + Mockito.when(mockDeviceState.getFeatures()).thenReturn(mockFeaturesOutput); + Mockito.when(mockFeaturesOutput.getVersion()).thenReturn(testVersion); + Mockito.when(mockDeviceContext.getDeviceState()).thenReturn(mockDeviceState); Mockito.when(mockDeviceContext.getPrimaryConnectionContext()).thenReturn(mockConnectionContext); Mockito.when(mockConnectionContext.getFeatures()).thenReturn(mockFeaturesReply); Mockito.when(mockConnectionContext.getNodeId()).thenReturn(testNodeId); diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/ServiceMocking.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/ServiceMocking.java index 011387a6d0..d6edde7299 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/ServiceMocking.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/ServiceMocking.java @@ -31,6 +31,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; @@ -56,6 +57,8 @@ public abstract class ServiceMocking { @Mock protected FeaturesReply mockedFeatures; @Mock + protected GetFeaturesOutput mockedFeaturesOutput; + @Mock protected ConnectionAdapter mockedConnectionAdapter; @Mock protected MessageSpy mockedMessagSpy; @@ -80,13 +83,16 @@ public abstract class ServiceMocking { when(mockedFeatures.getDatapathId()).thenReturn(DUMMY_DATAPATH_ID); when(mockedFeatures.getVersion()).thenReturn(DUMMY_VERSION); + when(mockedFeaturesOutput.getDatapathId()).thenReturn(DUMMY_DATAPATH_ID); + when(mockedFeaturesOutput.getVersion()).thenReturn(DUMMY_VERSION); + when(mockedPrimConnectionContext.getFeatures()).thenReturn(mockedFeatures); when(mockedPrimConnectionContext.getConnectionAdapter()).thenReturn(mockedConnectionAdapter); 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(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedPrimConnectionContext); when(mockedDeviceContext.getMessageSpy()).thenReturn(mockedMessagSpy); diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsContextImpMockInitiation.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsContextImpMockInitiation.java index 7c50f076e4..bce92039e2 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsContextImpMockInitiation.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsContextImpMockInitiation.java @@ -30,6 +30,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; @@ -43,15 +44,15 @@ class StatisticsContextImpMockInitiation { Boolean isQueue = false; protected DeviceContext mockedDeviceContext; + protected DeviceState mockedDeviceState; + StatisticsGatheringService mockedStatisticsGatheringService; StatisticsGatheringOnTheFlyService mockedStatisticsOnFlyGatheringService; ConnectionContext mockedConnectionContext; - protected DeviceState mockedDeviceState; + static final KeyedInstanceIdentifier dummyNodeII = InstanceIdentifier.create(Nodes.class) .child(Node.class, new NodeKey(new NodeId("dummyNodeId"))); - protected MessageSpy mockedMessageSpy; - protected OutboundQueue mockedOutboundQueue; - protected DeviceManager mockedDeviceManager; + LifecycleConductor mockConductor; @Before @@ -60,16 +61,16 @@ class StatisticsContextImpMockInitiation { mockedStatisticsGatheringService = mock(StatisticsGatheringService.class); mockedStatisticsOnFlyGatheringService = mock(StatisticsGatheringOnTheFlyService.class); mockedConnectionContext = mock(ConnectionContext.class); - final FeaturesReply mockedFeatures = mock(FeaturesReply.class); mockedDeviceState = mock(DeviceState.class); + + final FeaturesReply mockedFeatures = mock(FeaturesReply.class); final MessageSpy mockedMessageSpy = mock(MessageSpy.class); final OutboundQueue mockedOutboundQueue = mock(OutboundQueue.class); final DeviceManager mockedDeviceManager = mock(DeviceManager.class); + final GetFeaturesOutput mockedFeaturesOutput = mock(GetFeaturesOutput.class); + mockConductor = mock(LifecycleConductor.class); - when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState); - when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedConnectionContext); - when(mockedDeviceContext.getMessageSpy()).thenReturn(mockedMessageSpy); when(mockedDeviceState.isTableStatisticsAvailable()).thenReturn(isTable); when(mockedDeviceState.isFlowStatisticsAvailable()).thenReturn(isFlow); when(mockedDeviceState.isGroupAvailable()).thenReturn(isGroup); @@ -77,6 +78,11 @@ class StatisticsContextImpMockInitiation { when(mockedDeviceState.isPortStatisticsAvailable()).thenReturn(isPort); when(mockedDeviceState.isQueueStatisticsAvailable()).thenReturn(isQueue); when(mockedDeviceState.getNodeInstanceIdentifier()).thenReturn(dummyNodeII); + when(mockedDeviceState.getFeatures()).thenReturn(mockedFeaturesOutput); + + when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState); + when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedConnectionContext); + when(mockedDeviceContext.getMessageSpy()).thenReturn(mockedMessageSpy); when(mockedConnectionContext.getNodeId()).thenReturn(dummyNodeII.getKey().getId()); when(mockedConnectionContext.getFeatures()).thenReturn(mockedFeatures); diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsContextImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsContextImplTest.java index 91533ae800..05cd073993 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsContextImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsContextImplTest.java @@ -13,9 +13,11 @@ package org.opendaylight.openflowplugin.impl.statistics; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; + import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import java.util.Collections; @@ -32,6 +34,7 @@ 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; import org.opendaylight.yangtools.yang.common.RpcResult; import org.opendaylight.yangtools.yang.common.RpcResultBuilder; @@ -97,6 +100,7 @@ public class StatisticsContextImplTest extends StatisticsContextImpMockInitiatio @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); diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsManagerImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsManagerImplTest.java index df14afe627..904cc7be57 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsManagerImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsManagerImplTest.java @@ -50,6 +50,7 @@ import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.Messa import org.opendaylight.openflowplugin.impl.registry.flow.DeviceFlowRegistryImpl; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; @@ -78,6 +79,8 @@ public class StatisticsManagerImplTest { @Mock FeaturesReply mockedFeatures; @Mock + GetFeaturesOutput mockedFeaturesOutput; + @Mock ConnectionAdapter mockedConnectionAdapter; @Mock MessageSpy mockedMessagSpy; @@ -107,6 +110,8 @@ public class StatisticsManagerImplTest { private DeviceManager deviceManager; @Mock private LifecycleConductor conductor; + @Mock + private GetFeaturesOutput featuresOutput; private RequestContext> currentRequestContext; private StatisticsManagerImpl statisticsManager; @@ -115,6 +120,8 @@ public class StatisticsManagerImplTest { public void initialization() { when(mockedFeatures.getDatapathId()).thenReturn(DUMMY_DATAPATH_ID); when(mockedFeatures.getVersion()).thenReturn(DUMMY_VERSION); + when(mockedFeaturesOutput.getDatapathId()).thenReturn(DUMMY_DATAPATH_ID); + when(mockedFeaturesOutput.getVersion()).thenReturn(DUMMY_VERSION); when(mockedPrimConnectionContext.getFeatures()).thenReturn(mockedFeatures); when(mockedPrimConnectionContext.getConnectionAdapter()).thenReturn(mockedConnectionAdapter); @@ -128,6 +135,7 @@ public class StatisticsManagerImplTest { 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.getNodeId()).thenReturn(new NodeId("ofp-unit-dummy-node-id")); diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/AbstractStatsServiceTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/AbstractStatsServiceTest.java index db225e3594..a3480ed9ad 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/AbstractStatsServiceTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/AbstractStatsServiceTest.java @@ -94,10 +94,11 @@ public abstract class AbstractStatsServiceTest { 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(getFeaturesOutput.getDatapathId()).thenReturn(BigInteger.valueOf(123L)); Mockito.when(connectionContext.getFeatures()).thenReturn(features); Mockito.when(connectionContext.getOutboundQueueProvider()).thenReturn(outboundQueueProvider); Mockito.when(features.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3); + Mockito.when(getFeaturesOutput.getDatapathId()).thenReturn(BigInteger.valueOf(123L)); + Mockito.when(getFeaturesOutput.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3); setUp(); diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/compatibility/AbstractCompatibleStatServiceTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/compatibility/AbstractCompatibleStatServiceTest.java index 501020b438..0d845ede07 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/compatibility/AbstractCompatibleStatServiceTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/compatibility/AbstractCompatibleStatServiceTest.java @@ -41,6 +41,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.g import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.get.aggregate.flow.statistics.from.flow.table._for.given.match.output.AggregatedFlowStatisticsBuilder; 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; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput; @@ -64,6 +65,8 @@ public class AbstractCompatibleStatServiceTest extends AbstractStatsServiceTest private DeviceState deviceState; @Mock private MessageTranslator translator; + @Mock + private GetFeaturesOutput featuresOutput; private AbstractRequestContext rqContext; @@ -89,10 +92,12 @@ public class AbstractCompatibleStatServiceTest extends AbstractStatsServiceTest } }; + Mockito.when(featuresOutput.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3); Mockito.when(rqContextStack.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.doAnswer(closeRequestFutureAnswer).when(multiMsgCollector).endCollecting(); Mockito.doAnswer(closeRequestFutureAnswer).when(multiMsgCollector).endCollecting(Matchers.any(EventIdentifier.class)); diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/util/MdSalRegistrationUtilsTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/util/MdSalRegistrationUtilsTest.java index bed59f638f..12842a3403 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/util/MdSalRegistrationUtilsTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/util/MdSalRegistrationUtilsTest.java @@ -22,8 +22,10 @@ import org.junit.Test; 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.DeviceState; import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.OfpRole; import org.opendaylight.yangtools.yang.binding.RpcService; @@ -42,14 +44,21 @@ public class MdSalRegistrationUtilsTest { final DeviceContext mockedDeviceContext = mock(DeviceContext.class); final ConnectionContext mockedConnectionContext = mock(ConnectionContext.class); + final DeviceState mockedDeviceState = mock(DeviceState.class); + when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState); + 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(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedConnectionContext); - MdSalRegistrationUtils.registerMasterServices(mockedRpcContext,mockedDeviceContext, OfpRole.BECOMEMASTER); + MdSalRegistrationUtils.registerMasterServices(mockedRpcContext, mockedDeviceContext, OfpRole.BECOMEMASTER); verify(mockedRpcContext, times(NUMBER_OF_RPC_SERVICE_REGISTRATION)).registerRpcServiceImplementation( Matchers.> any(), any(RpcService.class)); } -- 2.36.6