DeviceContexts holds referrence to message spy counter 57/18757/4
authorMartin Bobak <mbobak@cisco.com>
Mon, 20 Apr 2015 08:35:12 +0000 (10:35 +0200)
committerMartin Bobak <mbobak@cisco.com>
Wed, 22 Apr 2015 07:38:46 +0000 (09:38 +0200)
Change-Id: Ia9a4c6c10859cd0c9c5c6cd56806afe282626933
Signed-off-by: Martin Bobak <mbobak@cisco.com>
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/device/DeviceContext.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceContextImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceManagerImpl.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/DeviceContextImplTest.java

index bbd535852ec990aaced7d17a6ff187fb2c5fdade..03a1b8a0909e5a9a9a92b341836c02b39e9e0819 100644 (file)
@@ -8,13 +8,12 @@
 
 package org.opendaylight.openflowplugin.api.openflow.device;
 
-import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
-
 import io.netty.util.Timeout;
 import java.math.BigInteger;
 import java.util.Map;
 import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
 import org.opendaylight.openflowplugin.api.openflow.OpenflowPluginTimer;
 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceReplyProcessor;
@@ -45,7 +44,7 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
  * <p>
  * Created by Martin Bobak &lt;mbobak@cisco.com&gt; on 25.2.2015.
  */
-public interface DeviceContext extends AutoCloseable,OpenflowPluginTimer, MessageHandler, TranslatorLibrarian, OutstandingMessageExtractor, DeviceReplyProcessor {
+public interface DeviceContext extends AutoCloseable, OpenflowPluginTimer, MessageHandler, TranslatorLibrarian, OutstandingMessageExtractor, DeviceReplyProcessor {
 
 
     /**
@@ -112,6 +111,7 @@ public interface DeviceContext extends AutoCloseable,OpenflowPluginTimer, Messag
 
     /**
      * Method generates unique XID value.
+     *
      * @return
      */
     Xid getNextXid();
@@ -139,28 +139,33 @@ public interface DeviceContext extends AutoCloseable,OpenflowPluginTimer, Messag
 
     /**
      * Method returns registered {@link org.opendaylight.openflowplugin.api.openflow.device.listener.OpenflowMessageListenerFacade}
+     *
      * @return
      */
     OpenflowMessageListenerFacade getOpenflowMessageListenerFacade();
 
     /**
      * Method exposes flow registry used for storing flow ids identified by calculated flow hash.
+     *
      * @return
      */
     DeviceFlowRegistry getDeviceFlowRegistry();
+
     /**
      * Method exposes device group registry used for storing group ids.
+     *
      * @return
      */
     DeviceGroupRegistry getDeviceGroupRegistry();
+
     /**
      * Method exposes device meter registry used for storing meter ids.
+     *
      * @return
      */
     DeviceMeterRegistry getDeviceMeterRegistry();
 
 
-
     /**
      * store cancellable timeout handler of currently running barrier task
      */
@@ -173,6 +178,7 @@ public interface DeviceContext extends AutoCloseable,OpenflowPluginTimer, Messag
 
     /**
      * Sets notification service
+     *
      * @param notificationService
      */
     void setNotificationService(NotificationProviderService notificationService);
index 5195d08af8afbfe751cea80a91e1477304ec4675..e6389ac342fe923e5494e03e143b5e7bc6367b3b 100644 (file)
@@ -38,6 +38,7 @@ import org.opendaylight.openflowplugin.api.openflow.md.core.TranslatorKey;
 import org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry;
 import org.opendaylight.openflowplugin.api.openflow.registry.group.DeviceGroupRegistry;
 import org.opendaylight.openflowplugin.api.openflow.registry.meter.DeviceMeterRegistry;
+import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
 import org.opendaylight.openflowplugin.impl.common.NodeStaticReplyTranslatorUtil;
 import org.opendaylight.openflowplugin.impl.registry.flow.DeviceFlowRegistryImpl;
 import org.opendaylight.openflowplugin.impl.registry.group.DeviceGroupRegistryImpl;
@@ -95,11 +96,15 @@ public class DeviceContextImpl implements DeviceContext {
     private final DeviceMeterRegistry deviceMeterRegistry;
     private Timeout barrierTaskTimeout;
     private NotificationProviderService notificationService;
+    private final MessageSpy messageSpy;
+
 
     @VisibleForTesting
     DeviceContextImpl(@Nonnull final ConnectionContext primaryConnectionContext,
-                      @Nonnull final DeviceState deviceState, @Nonnull final DataBroker dataBroker,
-                      @Nonnull final HashedWheelTimer hashedWheelTimer) {
+                      @Nonnull final DeviceState deviceState,
+                      @Nonnull final DataBroker dataBroker,
+                      @Nonnull final HashedWheelTimer hashedWheelTimer,
+                      @Nonnull final MessageSpy _messageSpy) {
         this.primaryConnectionContext = Preconditions.checkNotNull(primaryConnectionContext);
         this.deviceState = Preconditions.checkNotNull(deviceState);
         this.dataBroker = Preconditions.checkNotNull(dataBroker);
@@ -111,6 +116,7 @@ public class DeviceContextImpl implements DeviceContext {
         deviceFlowRegistry = new DeviceFlowRegistryImpl();
         deviceGroupRegistry = new DeviceGroupRegistryImpl();
         deviceMeterRegistry = new DeviceMeterRegistryImpl();
+        messageSpy = _messageSpy;
     }
 
     /**
index c43ebcaf98b420508c26b8bfb865080a789d872b..94554e5fcd6ed5ed393eff31ba3ce8cc4208ef92 100644 (file)
@@ -47,6 +47,7 @@ import org.opendaylight.openflowplugin.impl.common.NodeStaticReplyTranslatorUtil
 import org.opendaylight.openflowplugin.impl.device.listener.OpenflowProtocolListenerFullImpl;
 import org.opendaylight.openflowplugin.impl.rpc.RequestContextImpl;
 import org.opendaylight.openflowplugin.impl.services.OFJResult2RequestCtxFuture;
+import org.opendaylight.openflowplugin.impl.statistics.ofpspecific.MessageIntelligenceAgencyImpl;
 import org.opendaylight.openflowplugin.impl.util.DeviceStateUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeBuilder;
@@ -107,6 +108,7 @@ public class DeviceManagerImpl implements DeviceManager, AutoCloseable {
     private NotificationProviderService notificationService;
     private final List<DeviceContext> synchronizedDeviceContextsList = Collections
             .<DeviceContext>synchronizedList(new ArrayList<DeviceContext>());
+    private final MessageIntelligenceAgency messageIntelligenceAgency = new MessageIntelligenceAgencyImpl();
 
     public DeviceManagerImpl(@Nonnull final DataBroker dataBroker) {
         this.dataBroker = Preconditions.checkNotNull(dataBroker);
@@ -153,7 +155,7 @@ public class DeviceManagerImpl implements DeviceManager, AutoCloseable {
 
         final DeviceState deviceState = new DeviceStateImpl(connectionContext.getFeatures(), connectionContext.getNodeId());
 
-        final DeviceContextImpl deviceContext = new DeviceContextImpl(connectionContext, deviceState, dataBroker, hashedWheelTimer);
+        final DeviceContextImpl deviceContext = new DeviceContextImpl(connectionContext, deviceState, dataBroker, hashedWheelTimer, messageIntelligenceAgency);
 
         deviceContext.setNotificationService(notificationService);
         deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, deviceState.getNodeInstanceIdentifier(), new NodeBuilder().setId(deviceState.getNodeId()).build());
index ef87feccdf771d7c76e17864cdcf269b89767c88..1fa1a92a99d75a6af001784f2fca0ebbe8b6e338 100644 (file)
@@ -2,6 +2,7 @@ package org.opendaylight.openflowplugin.impl.device;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
+
 import com.google.common.util.concurrent.SettableFuture;
 import io.netty.util.HashedWheelTimer;
 import java.util.ArrayList;
@@ -28,6 +29,7 @@ import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
 import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
 import org.opendaylight.openflowplugin.api.openflow.device.exception.DeviceDataException;
+import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageIntelligenceAgency;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.Error;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessageBuilder;
@@ -76,6 +78,8 @@ public class DeviceContextImplTest {
     BindingTransactionChain txChainFactory;
     @Mock
     HashedWheelTimer timer;
+    @Mock
+    MessageIntelligenceAgency messageIntelligenceAgency;
 
     @Before
     public void setUp() {
@@ -88,29 +92,29 @@ public class DeviceContextImplTest {
         Mockito.when(txChainFactory.newWriteOnlyTransaction()).thenReturn(wTx);
         Mockito.when(dataBroker.newReadOnlyTransaction()).thenReturn(rTx);
 
-        deviceContext = new DeviceContextImpl(connectionContext, deviceState, dataBroker, timer);
+        deviceContext = new DeviceContextImpl(connectionContext, deviceState, dataBroker, timer, messageIntelligenceAgency);
         xid = deviceContext.getNextXid();
         xidMulti = deviceContext.getNextXid();
     }
 
     @Test(expected = NullPointerException.class)
     public void testDeviceContextImplConstructorNullConnectionContext() {
-        new DeviceContextImpl(null, deviceState, dataBroker, timer);
+        new DeviceContextImpl(null, deviceState, dataBroker, timer, messageIntelligenceAgency);
     }
 
     @Test(expected = NullPointerException.class)
     public void testDeviceContextImplConstructorNullDataBroker() {
-        new DeviceContextImpl(connectionContext, deviceState, null, timer);
+        new DeviceContextImpl(connectionContext, deviceState, null, timer, messageIntelligenceAgency);
     }
 
     @Test(expected = NullPointerException.class)
     public void testDeviceContextImplConstructorNullDeviceState() {
-        new DeviceContextImpl(connectionContext, null, dataBroker, timer);
+        new DeviceContextImpl(connectionContext, null, dataBroker, timer, messageIntelligenceAgency);
     }
 
     @Test(expected = NullPointerException.class)
     public void testDeviceContextImplConstructorNullTimer() {
-        new DeviceContextImpl(null, deviceState, dataBroker, null);
+        new DeviceContextImpl(null, deviceState, dataBroker, null, messageIntelligenceAgency);
     }
 
     @Test
@@ -129,9 +133,9 @@ public class DeviceContextImplTest {
 
     private static GetAsyncOutput createAsyncOutput(final Xid xid) {
         final GetAsyncOutputBuilder asyncOutputBuilder = new GetAsyncOutputBuilder();
-        asyncOutputBuilder.setFlowRemovedMask(Collections.<FlowRemovedMask> emptyList());
-        asyncOutputBuilder.setPacketInMask(Collections.<PacketInMask> emptyList());
-        asyncOutputBuilder.setPortStatusMask(Collections.<PortStatusMask> emptyList());
+        asyncOutputBuilder.setFlowRemovedMask(Collections.<FlowRemovedMask>emptyList());
+        asyncOutputBuilder.setPacketInMask(Collections.<PacketInMask>emptyList());
+        asyncOutputBuilder.setPortStatusMask(Collections.<PortStatusMask>emptyList());
         asyncOutputBuilder.setVersion(OFConstants.OFP_VERSION_1_3);
         asyncOutputBuilder.setXid(xid.getValue());
         return asyncOutputBuilder.build();
@@ -226,7 +230,7 @@ public class DeviceContextImplTest {
     private static List<MultipartReply> createMultipartReplyList(final Xid xid) {
         final MultipartReplyDesc descValue = new MultipartReplyDescBuilder().setHwDesc("hw-test-value").build();
         final MultipartReplyDescCase replyBody = new MultipartReplyDescCaseBuilder()
-                                                        .setMultipartReplyDesc(descValue).build();
+                .setMultipartReplyDesc(descValue).build();
         final List<MultipartReply> multipartReplies = new ArrayList<>();
         multipartReplies.add(new MultipartReplyMessageBuilder()
                 .setMultipartReplyBody(replyBody)
@@ -255,13 +259,13 @@ public class DeviceContextImplTest {
 
         LOG.info("Checking RequestContext.future");
         try {
-                final Object object = requestContext.getFuture().get(1L, TimeUnit.SECONDS);
-                final RpcResult<OfHeader> rpcResult = (RpcResult<OfHeader>) object;
-                Assert.assertFalse(rpcResult.isSuccessful());
-                final List<RpcError> errors = (List<RpcError>) rpcResult.getErrors();
-                Assert.assertTrue(errors.get(0).getCause() instanceof DeviceDataException);
-                final DeviceDataException cause = (DeviceDataException) errors.get(0).getCause();
-                Assert.assertTrue(cause.getCause() instanceof NullPointerException);
+            final Object object = requestContext.getFuture().get(1L, TimeUnit.SECONDS);
+            final RpcResult<OfHeader> rpcResult = (RpcResult<OfHeader>) object;
+            Assert.assertFalse(rpcResult.isSuccessful());
+            final List<RpcError> errors = (List<RpcError>) rpcResult.getErrors();
+            Assert.assertTrue(errors.get(0).getCause() instanceof DeviceDataException);
+            final DeviceDataException cause = (DeviceDataException) errors.get(0).getCause();
+            Assert.assertTrue(cause.getCause() instanceof NullPointerException);
         } catch (InterruptedException | ExecutionException | TimeoutException e) {
             LOG.error("Test failed when checking RequestContext.future", e);
             fail("fail");