Bug 5592 - NodeId+DatapathId in Services (remove dependency on DeviceContext) 83/37083/5
authorTomas Slusny <tomas.slusny@pantheon.sk>
Mon, 4 Apr 2016 14:43:14 +0000 (16:43 +0200)
committerTomas Slusny <tomas.slusny@pantheon.sk>
Fri, 13 May 2016 07:29:47 +0000 (09:29 +0200)
- 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 <tomas.slusny@pantheon.sk>
19 files changed:
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/AbstractService.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/RoleService.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/SalRoleServiceImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/SalTableServiceImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/MatchingFlowsInTableService.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/compatibility/AbstractCompatibleStatService.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/dedicated/StatisticsGatheringOnTheFlyService.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/services/dedicated/StatisticsGatheringService.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/role/RoleManagerImplTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/rpc/RpcManagerImplTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/SalFlowServiceImplTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/SalRoleServiceImplTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/ServiceMocking.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsContextImpMockInitiation.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsContextImplTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsManagerImplTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/AbstractStatsServiceTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/compatibility/AbstractCompatibleStatServiceTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/util/MdSalRegistrationUtilsTest.java

index 5888d2b443ac3da370303f9619842874221aea05..f1bdbf116da899234e9f5a02b5c49e90875194a6 100644 (file)
@@ -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<I, O> {
     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<I, O> {
         return datapathId;
     }
 
+    public NodeId getNodeId() {
+        return nodeId;
+    }
+
     public RequestContextStack getRequestContextStack() {
         return requestContextStack;
     }
@@ -101,16 +108,16 @@ abstract class AbstractService<I, O> {
         final RequestContext<O> 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;
index 0bf66fa960a12eaaf04c6279edf3097d677412cb..c677c53a68247079504cb9a8664125eb798020f6 100644 (file)
@@ -54,8 +54,7 @@ public class RoleService extends AbstractSimpleService<RoleRequestInputBuilder,
     }
 
     public Future<BigInteger> 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<RoleRequestInputBuilder,
                         finalFuture.set(roleRequestOutput.getGenerationId());
                     } else {
                         LOG.info("roleRequestOutput is null in getGenerationIdFromDevice");
-                        finalFuture.setException(new RoleChangeException("Exception in getting generationId for device:" + nodeId.getValue()));
+                        finalFuture.setException(new RoleChangeException("Exception in getting generationId for device:" + getNodeId().getValue()));
                     }
 
                 } else {
@@ -98,7 +97,7 @@ public class RoleService extends AbstractSimpleService<RoleRequestInputBuilder,
 
     public Future<RpcResult<SetRoleOutput>> 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<RoleRequestInputBuilder,
             @Override
             public void onSuccess(final RpcResult<RoleRequestOutput> roleRequestOutputRpcResult) {
                 LOG.info("submitRoleChange onSuccess for device:{}, role:{}",
-                        deviceContext.getPrimaryConnectionContext().getNodeId(), ofpRole);
+                        getNodeId(), ofpRole);
                 final RoleRequestOutput roleRequestOutput = roleRequestOutputRpcResult.getResult();
                 final Collection<RpcError> rpcErrors = roleRequestOutputRpcResult.getErrors();
                 if (roleRequestOutput != null) {
@@ -133,7 +132,7 @@ public class RoleService extends AbstractSimpleService<RoleRequestInputBuilder,
             @Override
             public void onFailure(final Throwable throwable) {
                 LOG.error("submitRoleChange onFailure for device:{}, role:{}",
-                        deviceContext.getPrimaryConnectionContext().getNodeId(), ofpRole, throwable);
+                        getNodeId(), ofpRole, throwable);
                 finalFuture.setException(throwable);
             }
         });
index cb2227769fb5b5e415a6f8395e2a6c66f04c236d..a8b4eb8107553851ad4264fe29b2d0c893de064a 100644 (file)
@@ -46,8 +46,6 @@ public final class SalRoleServiceImpl extends AbstractSimpleService<SetRoleInput
 
     private final DeviceContext deviceContext;
     private final RoleService roleService;
-    private final NodeId nodeId;
-    private final Short version;
 
     private final Semaphore currentRoleGuard = new Semaphore(1, true);
 
@@ -58,8 +56,6 @@ public final class SalRoleServiceImpl extends AbstractSimpleService<SetRoleInput
         super(requestContextStack, deviceContext, SetRoleOutput.class);
         this.deviceContext = Preconditions.checkNotNull(deviceContext);
         this.roleService =  new RoleService(requestContextStack, deviceContext, RoleRequestOutput.class);
-        nodeId = deviceContext.getPrimaryConnectionContext().getNodeId();
-        version = deviceContext.getPrimaryConnectionContext().getFeatures().getVersion();
     }
 
     @Override
@@ -161,15 +157,15 @@ public final class SalRoleServiceImpl extends AbstractSimpleService<SetRoleInput
     }
 
     private ListenableFuture<RpcResult<SetRoleOutput>> 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<BigInteger> generationFuture = roleService.getGenerationIdFromDevice(version);
+        final Future<BigInteger> generationFuture = roleService.getGenerationIdFromDevice(getVersion());
 
         return Futures.transform(JdkFutureAdapters.listenInPoolThread(generationFuture), (AsyncFunction<BigInteger, RpcResult<SetRoleOutput>>) 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<RpcResult<SetRoleOutput>> submitRoleFuture = roleService.submitRoleChange(role, version, nextGenerationId);
+            LOG.debug("nextGenerationId received from device:{} is {}", getNodeId().getValue(), nextGenerationId);
+            final Future<RpcResult<SetRoleOutput>> submitRoleFuture = roleService.submitRoleChange(role, getVersion(), nextGenerationId);
             return JdkFutureAdapters.listenInPoolThread(submitRoleFuture);
         });
     }
index 1c218b37b2c4a56eec0b2c1ae91fc2ec9449c117..644ea77de8dd05cfe70856e2951d871d25bafa72 100644 (file)
@@ -114,9 +114,8 @@ public final class SalTableServiceImpl extends AbstractMultipartService<UpdateTa
         final List<org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures> salTableFeatures = convertToSalTableFeatures(multipartReplies);
 
         final DeviceContext deviceContext = getDeviceContext();
-        final NodeId nodeId = deviceContext.getPrimaryConnectionContext().getNodeId();
         final InstanceIdentifier<FlowCapableNode> 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<org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures, TableFeaturesKey> tableFeaturesII = flowCapableNodeII
index e15c0166b8373699f03ccbc28c23ad560521d1af..3de2abdba19144abd0289e9ca620cd206f7191d5 100644 (file)
@@ -61,8 +61,7 @@ final class MatchingFlowsInTableService extends AbstractMultipartService<GetAggr
             mprAggregateRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
         }
 
-        MatchReactor.getInstance().convert(input.getMatch(), version, mprAggregateRequestBuilder,
-                deviceContext.getPrimaryConnectionContext().getFeatures().getDatapathId());
+        MatchReactor.getInstance().convert(input.getMatch(), version, mprAggregateRequestBuilder, getDatapathId());
 
         FlowCreatorUtil.setWildcardedFlowMatch(version, mprAggregateRequestBuilder);
 
index 47eb56819a2c58edf5beee18953b67483c2e8e3f..1a5c5a1d5f3473d87f372a5c50b55885e46c2c4b 100644 (file)
@@ -42,7 +42,7 @@ public abstract class AbstractCompatibleStatService<I, O, N extends Notification
     public AbstractCompatibleStatService(RequestContextStack requestContextStack, DeviceContext deviceContext, AtomicLong compatibilityXidSeed) {
         super(requestContextStack, deviceContext);
         this.compatibilityXidSeed = compatibilityXidSeed;
-        ofVersion = OpenflowVersion.get(getDeviceContext().getDeviceState().getVersion());
+        ofVersion = OpenflowVersion.get(getVersion());
     }
 
     public OpenflowVersion getOfVersion() {
index a38c4b480a44d13a687fd933e7638a3ec358c7c4..6dfcfa05405cccad2982993b662de6a5a6777185 100644 (file)
@@ -38,7 +38,7 @@ public class StatisticsGatheringOnTheFlyService extends AbstractMultipartOnTheFl
 
     @Override
     public Future<RpcResult<List<MultipartReply>>> 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);
index 9a2eb17de6d38b62b479bea658d4923b969b3af6..c43ae604fc8af3fee422d8b2e9ef5d61055285ba 100644 (file)
@@ -38,7 +38,7 @@ public class StatisticsGatheringService extends AbstractMultipartService<Multipa
 
     @Override
     public Future<RpcResult<List<MultipartReply>>> 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);
index bba0245d9a75e345d8aba960745ea93dc9c3ed42..f91eeafd070cc01ba4493ae071df6a83c7aed4b4 100644 (file)
@@ -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<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(connectionContext.getFeatures()).thenReturn(featuresReply);
         Mockito.when(connectionContext.getNodeId()).thenReturn(nodeId);
         Mockito.when(connectionContext.getConnectionState()).thenReturn(ConnectionContext.CONNECTION_STATE.WORKING);
index 3d4a67d8c575141c5224b848e06b9d7b2a79e24c..723447c16b4d1482daa20a229cee7a4222155d2f 100644 (file)
@@ -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.<NodeId>any())).thenReturn(deviceContext);
     }
index 76c7ac43ceb44ad5b5aab777153120f88417c09d..3cf72599f8d30a8a62c97fbb72f70289e10788f5 100644 (file)
@@ -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
index 2de3711cf94d194dbaaa7a96134b3b5b3803fd76..35c702a5126ee290bd3d5c40c46c890fc29ed9a3 100644 (file)
@@ -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<RoleRequestOutput> 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);
index 011387a6d01e7f6f8ad733987805267d6512eb7b..d6edde72994d8f0a5e04ff2bc29c229e9926b131 100644 (file)
@@ -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);
index 7c50f076e4b105381913c866473dff89468cf6df..bce92039e282e2d7942734dcb955d89693989bd7 100644 (file)
@@ -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<Node, NodeKey> 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);
index 91533ae80099edb90feb4e5172852ebbe2cbf0f6..05cd073993a75c3e41d917ab122b48574183a81c 100644 (file)
@@ -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);
index df14afe627374f37d6911f95074618a0d51e5e0b..904cc7be57763e6984baaa9ec08270b913493a0a 100644 (file)
@@ -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<List<MultipartReply>> 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"));
 
index db225e3594c32833e24007d57819def8a5315bee..a3480ed9ad9775bdc4890d643e19b9a7b4c59bb3 100644 (file)
@@ -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();
index 501020b4389d5b7f20edde01d001ff5a7cb7710d..0d845ede0725aba0c8835df61df2106dcc9aa2a8 100644 (file)
@@ -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<Object, Object> translator;
+    @Mock
+    private GetFeaturesOutput featuresOutput;
 
     private AbstractRequestContext<Object> rqContext;
 
@@ -89,10 +92,12 @@ public class AbstractCompatibleStatServiceTest extends AbstractStatsServiceTest
             }
         };
 
+        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.doAnswer(closeRequestFutureAnswer).when(multiMsgCollector).endCollecting();
         Mockito.doAnswer(closeRequestFutureAnswer).when(multiMsgCollector).endCollecting(Matchers.any(EventIdentifier.class));
 
index bed59f638f7993788ab745e4c17b411019f62035..12842a34036ac96733d1484c81e46e9790123717 100644 (file)
@@ -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.<Class<RpcService>> any(), any(RpcService.class));
     }