Merge "Bug 5591 - Changed DeviceContext to DeviceState in translate methods of Messag...
authorJozef Bacigal <jbacigal@cisco.com>
Tue, 17 May 2016 07:04:16 +0000 (07:04 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Tue, 17 May 2016 07:04:16 +0000 (07:04 +0000)
13 files changed:
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/device/DeviceContext.java
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/device/TxFacade.java [new file with mode: 0644]
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/AbstractMultipartOnTheFlyService.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/MultipartRequestOnTheFlyCallback.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/SalTableServiceImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/SinglePurposeMultipartReplyTranslator.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsGatheringUtils.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/util/MdSalRegistrationUtils.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/MultipartRequestOnTheFlyCallbackTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/SalTableServiceImplTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/SinglePurposeMultipartReplyTranslatorTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsGatheringUtilsTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/services/dedicated/StatisticsGatheringOnTheFlyServiceTest.java

index 62188f8fdf66c988d62f4d5b3530e5fc417e4c01..35125b54214b35279ede89e928717b82adc9fb9c 100644 (file)
@@ -15,10 +15,6 @@ import java.util.List;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
-import org.opendaylight.controller.md.sal.binding.api.NotificationService;
-import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.openflowplugin.api.openflow.OpenFlowPluginTimer;
 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceReplyProcessor;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.MultiMsgCollector;
@@ -31,8 +27,6 @@ import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsContext
 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.OfpRole;
-import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
 /**
  * <p>
@@ -54,6 +48,7 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 public interface DeviceContext extends AutoCloseable,
         DeviceReplyProcessor,
         PortNumberCache,
+        TxFacade,
         XidSequencer {
 
     void setStatisticsRpcEnabled(boolean isStatisticsRpcEnabled);
@@ -138,38 +133,11 @@ public interface DeviceContext extends AutoCloseable,
      */
     ListenableFuture<Void> onDeviceLostClusterLeadership();
 
-    /**
-     * Method creates put operation using provided data in underlying transaction chain.
-     */
-    <T extends DataObject> void writeToTransaction(final LogicalDatastoreType store, final InstanceIdentifier<T> path, final T data) throws Exception;
-
-    /**
-     * Method creates delete operation for provided path in underlying transaction chain.
-     */
-    <T extends DataObject> void addDeleteToTxChain(final LogicalDatastoreType store, final InstanceIdentifier<T> path) throws Exception;
-
-    /**
-     * Method submits Transaction to DataStore.
-     * @return transaction is submitted successfully
-     */
-    boolean submitTransaction();
-
     /**
      * Method has to close TxManager ASAP we are notified about Closed Connection
      * @return sync. future for Slave and MD-SAL completition for Master
      */
     ListenableFuture<Void> shuttingDownDataStoreTransactions();
-
-    /**
-     * Method exposes transaction created for device
-     * represented by this context. This read only transaction has a fresh dataStore snapshot.
-     * There is a possibility to get different data set from  DataStore
-     * as write transaction in this context.
-     * @return readOnlyTransaction - Don't forget to close it after finish reading
-     */
-    ReadOnlyTransaction getReadTransaction();
-
-
     /**
      * Method provides current devices connection context.
      *
diff --git a/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/device/TxFacade.java b/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/device/TxFacade.java
new file mode 100644 (file)
index 0000000..6a982b1
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.openflowplugin.api.openflow.device;
+
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+/**
+ * Handles operations with transactions
+ */
+public interface TxFacade {
+
+    /**
+     * Method creates put operation using provided data in underlying transaction chain.
+     */
+    <T extends DataObject> void writeToTransaction(final LogicalDatastoreType store, final InstanceIdentifier<T> path,
+                                                   final T data) throws Exception;
+
+    /**
+     * Method creates delete operation for provided path in underlying transaction chain.
+     */
+    <T extends DataObject> void addDeleteToTxChain(final LogicalDatastoreType store, final InstanceIdentifier<T> path) throws Exception;
+
+    /**
+     * Method submits Transaction to DataStore.
+     * @return transaction is submitted successfully
+     */
+    boolean submitTransaction();
+
+    /**
+     * Method exposes transaction created for device
+     * represented by this context. This read only transaction has a fresh dataStore snapshot.
+     * There is a possibility to get different data set from  DataStore
+     * as write transaction in this context.
+     * @return readOnlyTransaction - Don't forget to close it after finish reading
+     */
+    ReadOnlyTransaction getReadTransaction();
+}
index b665258ebcb6a66c8ca957b082bfbb6058e6c839..0d7020030500355cfdb59ed37a07cae73f2b83b7 100644 (file)
@@ -23,7 +23,9 @@ public abstract class AbstractMultipartOnTheFlyService<I> extends AbstractServic
 
     @Override
     protected final FutureCallback<OfHeader> createCallback(final RequestContext<List<MultipartReply>> context, final Class<?> requestType) {
-        return new MultipartRequestOnTheFlyCallback(context, requestType, getDeviceContext(), getEventIdentifier());
+        return new MultipartRequestOnTheFlyCallback(context, requestType,
+                getDeviceContext().getMessageSpy(), getEventIdentifier(), getDeviceContext().getDeviceState(),
+                getDeviceContext().getDeviceFlowRegistry(), getDeviceContext());
     }
 
 
index aacfa703c5744cec709595871d1e90d65deb577e..c00d092f96273335af1233e70141f3213a3a2ce5 100644 (file)
@@ -12,8 +12,11 @@ import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
 import java.util.Collections;
 import java.util.List;
-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.TxFacade;
+import org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry;
 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.EventIdentifier;
 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
 import org.opendaylight.openflowplugin.impl.statistics.SinglePurposeMultipartReplyTranslator;
@@ -32,21 +35,30 @@ import org.slf4j.LoggerFactory;
 
 final class MultipartRequestOnTheFlyCallback extends AbstractRequestCallback<List<MultipartReply>> {
     private static final Logger LOG = LoggerFactory.getLogger(MultipartRequestOnTheFlyCallback.class);
-    private final DeviceContext deviceContext;
     private static final SinglePurposeMultipartReplyTranslator MULTIPART_REPLY_TRANSLATOR = new SinglePurposeMultipartReplyTranslator();
+    private final DeviceState deviceState;
+    private final DeviceFlowRegistry registry;
     private boolean virgin = true;
     private boolean finished = false;
     private final EventIdentifier doneEventIdentifier;
+    private final TxFacade txFacade;
 
 
     public MultipartRequestOnTheFlyCallback(final RequestContext<List<MultipartReply>> context,
                                             final Class<?> requestType,
-                                            final DeviceContext deviceContext,
-                                            final EventIdentifier eventIdentifier) {
-        super(context, requestType, deviceContext.getMessageSpy(), eventIdentifier);
-        this.deviceContext = deviceContext;
+                                            final MessageSpy messageSpy,
+                                            final EventIdentifier eventIdentifier,
+                                            final DeviceState deviceState,
+                                            final DeviceFlowRegistry registry,
+                                            final TxFacade txFacade) {
+        super(context, requestType, messageSpy, eventIdentifier);
+
+        this.deviceState = deviceState;
+        this.registry = registry;
+        this.txFacade = txFacade;
+
         //TODO: this is focused on flow stats only - need more general approach if used for more than flow stats
-        doneEventIdentifier = new EventIdentifier(MultipartType.OFPMPFLOW.name(), deviceContext.getPrimaryConnectionContext().getNodeId().toString());
+        doneEventIdentifier = new EventIdentifier(MultipartType.OFPMPFLOW.name(), deviceState.getNodeId().toString());
     }
 
     public EventIdentifier getDoneEventIdentifier() {
@@ -77,13 +89,14 @@ final class MultipartRequestOnTheFlyCallback extends AbstractRequestCallback<Lis
             final MultipartReply multipartReply = (MultipartReply) result;
 
             final MultipartReply singleReply = multipartReply;
-            final List<? extends DataObject> multipartDataList = MULTIPART_REPLY_TRANSLATOR.translate(deviceContext, singleReply);
+            final List<? extends DataObject> multipartDataList = MULTIPART_REPLY_TRANSLATOR.translate(
+                    deviceState.getFeatures().getDatapathId(), deviceState.getFeatures().getVersion(), singleReply);
             final Iterable<? extends DataObject> allMultipartData = multipartDataList;
 
             //TODO: following part is focused on flow stats only - need more general approach if used for more than flow stats
             ListenableFuture<Void> future;
             if (virgin) {
-                future = StatisticsGatheringUtils.deleteAllKnownFlows(deviceContext);
+                future = StatisticsGatheringUtils.deleteAllKnownFlows(deviceState, registry, txFacade);
                 virgin = false;
             } else {
                 future = Futures.immediateFuture(null);
@@ -93,7 +106,8 @@ final class MultipartRequestOnTheFlyCallback extends AbstractRequestCallback<Lis
 
                 @Override
                 public Void apply(final Void input) {
-                    StatisticsGatheringUtils.writeFlowStatistics((Iterable<FlowsStatisticsUpdate>) allMultipartData,deviceContext);
+                    StatisticsGatheringUtils.writeFlowStatistics((Iterable<FlowsStatisticsUpdate>) allMultipartData,
+                            deviceState, registry, txFacade);
 
                     if (!multipartReply.getFlags().isOFPMPFREQMORE()) {
                         endCollecting();
@@ -110,7 +124,7 @@ final class MultipartRequestOnTheFlyCallback extends AbstractRequestCallback<Lis
         final RpcResult<List<MultipartReply>> rpcResult = RpcResultBuilder.success(Collections.<MultipartReply>emptyList()).build();
         spyMessage(MessageSpy.STATISTIC_GROUP.FROM_SWITCH_TRANSLATE_OUT_SUCCESS);
         setResult(rpcResult);
-        deviceContext.submitTransaction();
+        txFacade.submitTransaction();
         finished = true;
     }
 }
index f16594289eaa1c47ee4ab43450ab93885b00aaab..90d5dc62cf24ad8573559705d5f579023a6355b2 100644 (file)
@@ -18,6 +18,7 @@ import java.util.concurrent.Future;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
+import org.opendaylight.openflowplugin.api.openflow.device.TxFacade;
 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.TableFeaturesConvertor;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.TableFeaturesReplyConvertor;
@@ -52,9 +53,14 @@ import org.slf4j.Logger;
 
 public final class SalTableServiceImpl extends AbstractMultipartService<UpdateTableInput> implements SalTableService {
     private static final Logger LOG = org.slf4j.LoggerFactory.getLogger(SalTableServiceImpl.class);
+    private final TxFacade txFacade;
+    private final NodeId nodeId;
 
-    public SalTableServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext) {
+    public SalTableServiceImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext,
+                               final NodeId nodeId) {
         super(requestContextStack, deviceContext);
+        this.txFacade = deviceContext;
+        this.nodeId = nodeId;
     }
 
     @Override
@@ -113,7 +119,6 @@ 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 InstanceIdentifier<FlowCapableNode> flowCapableNodeII = InstanceIdentifier.create(Nodes.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) {
@@ -121,10 +126,11 @@ public final class SalTableServiceImpl extends AbstractMultipartService<UpdateTa
             final KeyedInstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures, TableFeaturesKey> tableFeaturesII = flowCapableNodeII
                     .child(org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures.class,
                             new TableFeaturesKey(tableId));
-            deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, tableFeaturesII,
+            txFacade.writeToTransaction(LogicalDatastoreType.OPERATIONAL, tableFeaturesII,
                     tableFeatureData);
         }
-        deviceContext.submitTransaction();
+
+        txFacade.submitTransaction();
     }
 
     protected static List<org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures> convertToSalTableFeatures(
index ad111387be91dcc2e326b044ec456ff8557af0bd..6c8d587854bb42d827dccaa50427e3a449201445 100644 (file)
@@ -111,16 +111,15 @@ public class SinglePurposeMultipartReplyTranslator {
     private static MeterStatsResponseConvertor meterStatsConvertor = new MeterStatsResponseConvertor();
 
 
-    public List<DataObject> translate(final DeviceContext deviceContext, final OfHeader msg) {
+    public List<DataObject> translate(final BigInteger datapathId, final short version, final OfHeader msg) {
 
         List<DataObject> listDataObject = new ArrayList<>();
 
-        OpenflowVersion ofVersion = OpenflowVersion.get(deviceContext.getPrimaryConnectionContext().getFeatures().getVersion());
+        OpenflowVersion ofVersion = OpenflowVersion.get(version);
 
-        final FeaturesReply features = deviceContext.getPrimaryConnectionContext().getFeatures();
         if (msg instanceof MultipartReplyMessage) {
             MultipartReplyMessage mpReply = (MultipartReplyMessage) msg;
-            NodeId node = SinglePurposeMultipartReplyTranslator.nodeIdFromDatapathId(features.getDatapathId());
+            NodeId node = SinglePurposeMultipartReplyTranslator.nodeIdFromDatapathId(datapathId);
             switch (mpReply.getType()) {
                 case OFPMPFLOW: {
                     FlowsStatisticsUpdateBuilder message = new FlowsStatisticsUpdateBuilder();
@@ -129,7 +128,7 @@ public class SinglePurposeMultipartReplyTranslator {
                     message.setTransactionId(generateTransactionId(mpReply.getXid()));
                     MultipartReplyFlowCase caseBody = (MultipartReplyFlowCase) mpReply.getMultipartReplyBody();
                     MultipartReplyFlow replyBody = caseBody.getMultipartReplyFlow();
-                    message.setFlowAndStatisticsMapList(flowStatsConvertor.toSALFlowStatsList(replyBody.getFlowStats(), features.getDatapathId(), ofVersion));
+                    message.setFlowAndStatisticsMapList(flowStatsConvertor.toSALFlowStatsList(replyBody.getFlowStats(), datapathId, ofVersion));
 
                     listDataObject.add(message.build());
                     return listDataObject;
@@ -167,7 +166,7 @@ public class SinglePurposeMultipartReplyTranslator {
                         NodeConnectorStatisticsAndPortNumberMapBuilder statsBuilder =
                                 new NodeConnectorStatisticsAndPortNumberMapBuilder();
                         statsBuilder.setNodeConnectorId(
-                                InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(features.getDatapathId(),
+                                InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(datapathId,
                                         portStats.getPortNo(), ofVersion));
 
                         BytesBuilder bytesBuilder = new BytesBuilder();
@@ -396,7 +395,7 @@ public class SinglePurposeMultipartReplyTranslator {
                         QueueIdAndStatisticsMapBuilder statsBuilder =
                                 new QueueIdAndStatisticsMapBuilder();
                         statsBuilder.setNodeConnectorId(
-                                InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(features.getDatapathId(),
+                                InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(datapathId,
                                         queueStats.getPortNo(), ofVersion));
                         statsBuilder.setTransmissionErrors(new Counter64(queueStats.getTxErrors()));
                         statsBuilder.setTransmittedBytes(new Counter64(queueStats.getTxBytes()));
@@ -408,7 +407,7 @@ public class SinglePurposeMultipartReplyTranslator {
                         statsBuilder.setDuration(durationBuilder.build());
 
                         statsBuilder.setQueueId(new QueueId(queueStats.getQueueId()));
-                        statsBuilder.setNodeConnectorId(InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(features.getDatapathId(),
+                        statsBuilder.setNodeConnectorId(InventoryDataServiceUtil.nodeConnectorIdfromDatapathPortNo(datapathId,
                                 queueStats.getPortNo(), ofVersion));
 
                         statsMap.add(statsBuilder.build());
index cc97c8fcc6bab1c55863c43ce6ab049126d1344b..4933f28374008e089049c67978ba84ae55fe0756 100644 (file)
@@ -26,6 +26,9 @@ import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
+import org.opendaylight.openflowplugin.api.openflow.device.TxFacade;
+import org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry;
 import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey;
 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.EventIdentifier;
 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.StatisticsGatherer;
@@ -157,7 +160,9 @@ public final class StatisticsGatheringUtils {
 
                         try {
                             for (final MultipartReply singleReply : rpcResult.getResult()) {
-                                final List<? extends DataObject> multipartDataList = MULTIPART_REPLY_TRANSLATOR.translate(deviceContext, singleReply);
+                                final List<? extends DataObject> multipartDataList = MULTIPART_REPLY_TRANSLATOR.translate(
+                                        deviceContext.getPrimaryConnectionContext().getFeatures().getDatapathId(),
+                                        deviceContext.getPrimaryConnectionContext().getFeatures().getVersion(), singleReply);
                                 multipartData = multipartDataList.get(0);
                                 allMultipartData = Iterables.concat(allMultipartData, multipartDataList);
                             }
@@ -214,7 +219,7 @@ public final class StatisticsGatheringUtils {
     }
 
     private static void processMeterConfigStatsUpdated(final Iterable<MeterConfigStatsUpdated> data, final DeviceContext deviceContext) throws Exception {
-        final InstanceIdentifier<FlowCapableNode> fNodeIdent = assembleFlowCapableNodeInstanceIdentifier(deviceContext);
+        final InstanceIdentifier<FlowCapableNode> fNodeIdent = assembleFlowCapableNodeInstanceIdentifier(deviceContext.getDeviceState());
         deleteAllKnownMeters(deviceContext, fNodeIdent);
         for (final MeterConfigStatsUpdated meterConfigStatsUpdated : data) {
             for (final MeterConfigStats meterConfigStats : meterConfigStatsUpdated.getMeterConfigStats()) {
@@ -233,12 +238,14 @@ public final class StatisticsGatheringUtils {
 
     private static ListenableFuture<Boolean> processFlowStatistics(final Iterable<FlowsStatisticsUpdate> data,
                                                                    final DeviceContext deviceContext, final EventIdentifier eventIdentifier) {
-        final ListenableFuture<Void> deleFuture = deleteAllKnownFlows(deviceContext);
+        final ListenableFuture<Void> deleFuture = deleteAllKnownFlows(deviceContext.getDeviceState(),
+                deviceContext.getDeviceFlowRegistry(), deviceContext);
         return Futures.transform(deleFuture, new Function<Void, Boolean>() {
 
             @Override
             public Boolean apply(final Void input) {
-                writeFlowStatistics(data, deviceContext);
+                writeFlowStatistics(data, deviceContext.getDeviceState(), deviceContext.getDeviceFlowRegistry(),
+                        deviceContext);
                 deviceContext.submitTransaction();
                 EventsTimeCounter.markEnd(eventIdentifier);
                 return Boolean.TRUE;
@@ -246,8 +253,11 @@ public final class StatisticsGatheringUtils {
         });
     }
 
-    public static void writeFlowStatistics(final Iterable<FlowsStatisticsUpdate> data, final DeviceContext deviceContext) {
-        final InstanceIdentifier<FlowCapableNode> fNodeIdent = assembleFlowCapableNodeInstanceIdentifier(deviceContext);
+    public static void writeFlowStatistics(final Iterable<FlowsStatisticsUpdate> data,
+                                           final DeviceState deviceState,
+                                           final DeviceFlowRegistry registry,
+                                           final TxFacade txFacade) {
+        final InstanceIdentifier<FlowCapableNode> fNodeIdent = assembleFlowCapableNodeInstanceIdentifier(deviceState);
         try {
             for (final FlowsStatisticsUpdate flowsStatistics : data) {
                 for (final FlowAndStatisticsMapList flowStat : flowsStatistics.getFlowAndStatisticsMapList()) {
@@ -256,13 +266,13 @@ public final class StatisticsGatheringUtils {
 
                     final short tableId = flowStat.getTableId();
                     final FlowRegistryKey flowRegistryKey = FlowRegistryKeyFactory.create(flowBuilder.build());
-                    final FlowId flowId = deviceContext.getDeviceFlowRegistry().storeIfNecessary(flowRegistryKey, tableId);
+                    final FlowId flowId = registry.storeIfNecessary(flowRegistryKey, tableId);
 
                     final FlowKey flowKey = new FlowKey(flowId);
                     flowBuilder.setKey(flowKey);
                     final TableKey tableKey = new TableKey(tableId);
                     final InstanceIdentifier<Flow> flowIdent = fNodeIdent.child(Table.class, tableKey).child(Flow.class, flowKey);
-                    deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, flowIdent, flowBuilder.build());
+                    txFacade.writeToTransaction(LogicalDatastoreType.OPERATIONAL, flowIdent, flowBuilder.build());
                 }
             }
         } catch (Exception e) {
@@ -282,11 +292,13 @@ public final class StatisticsGatheringUtils {
         return flowStatisticsDataBld;
     }
 
-    public static ListenableFuture<Void> deleteAllKnownFlows(final DeviceContext deviceContext) {
+    public static ListenableFuture<Void> deleteAllKnownFlows(final DeviceState deviceState,
+                                                             final DeviceFlowRegistry registry,
+                                                             final TxFacade txFacade) {
         /* DeviceState.deviceSynchronized is a marker for actual phase - false means initPhase, true means noInitPhase */
-        if (deviceContext.getDeviceState().deviceSynchronized()) {
-            final InstanceIdentifier<FlowCapableNode> flowCapableNodePath = assembleFlowCapableNodeInstanceIdentifier(deviceContext);
-            final ReadOnlyTransaction readTx = deviceContext.getReadTransaction();
+        if (deviceState.deviceSynchronized()) {
+            final InstanceIdentifier<FlowCapableNode> flowCapableNodePath = assembleFlowCapableNodeInstanceIdentifier(deviceState);
+            final ReadOnlyTransaction readTx = txFacade.getReadTransaction();
             final CheckedFuture<Optional<FlowCapableNode>, ReadFailedException> flowCapableNodeFuture = readTx.read(
                     LogicalDatastoreType.OPERATIONAL, flowCapableNodePath);
 
@@ -311,10 +323,10 @@ public final class StatisticsGatheringUtils {
                         for (final Table tableData : flowCapNodeOpt.get().getTable()) {
                             final Table table = new TableBuilder(tableData).setFlow(Collections.<Flow>emptyList()).build();
                             final InstanceIdentifier<Table> iiToTable = flowCapableNodePath.child(Table.class, tableData.getKey());
-                            deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, iiToTable, table);
+                            txFacade.writeToTransaction(LogicalDatastoreType.OPERATIONAL, iiToTable, table);
                         }
                     }
-                    deviceContext.getDeviceFlowRegistry().removeMarked();
+                    registry.removeMarked();
                     readTx.close();
                     return Futures.immediateFuture(null);
                 }
@@ -353,7 +365,7 @@ public final class StatisticsGatheringUtils {
     }
 
     private static void processFlowTableStatistics(final Iterable<FlowTableStatisticsUpdate> data, final DeviceContext deviceContext) throws Exception {
-        final InstanceIdentifier<FlowCapableNode> fNodeIdent = assembleFlowCapableNodeInstanceIdentifier(deviceContext);
+        final InstanceIdentifier<FlowCapableNode> fNodeIdent = assembleFlowCapableNodeInstanceIdentifier(deviceContext.getDeviceState());
         for (final FlowTableStatisticsUpdate flowTableStatisticsUpdate : data) {
 
             for (final FlowTableAndStatisticsMap tableStat : flowTableStatisticsUpdate.getFlowTableAndStatisticsMap()) {
@@ -385,7 +397,7 @@ public final class StatisticsGatheringUtils {
 
     private static void processMetersStatistics(final Iterable<MeterStatisticsUpdated> data,
                                                 final DeviceContext deviceContext) throws Exception {
-        final InstanceIdentifier<FlowCapableNode> fNodeIdent = assembleFlowCapableNodeInstanceIdentifier(deviceContext);
+        final InstanceIdentifier<FlowCapableNode> fNodeIdent = assembleFlowCapableNodeInstanceIdentifier(deviceContext.getDeviceState());
         for (final MeterStatisticsUpdated meterStatisticsUpdated : data) {
             for (final MeterStats mStat : meterStatisticsUpdated.getMeterStats()) {
                 final MeterStatistics stats = new MeterStatisticsBuilder(mStat).build();
@@ -439,7 +451,7 @@ public final class StatisticsGatheringUtils {
     }
 
     private static void processGroupStatistics(final Iterable<GroupStatisticsUpdated> data, final DeviceContext deviceContext) throws Exception {
-        final InstanceIdentifier<FlowCapableNode> fNodeIdent = assembleFlowCapableNodeInstanceIdentifier(deviceContext);
+        final InstanceIdentifier<FlowCapableNode> fNodeIdent = assembleFlowCapableNodeInstanceIdentifier(deviceContext.getDeviceState());
         for (final GroupStatisticsUpdated groupStatistics : data) {
             for (final GroupStats groupStats : groupStatistics.getGroupStats()) {
 
@@ -455,8 +467,8 @@ public final class StatisticsGatheringUtils {
         deviceContext.submitTransaction();
     }
 
-    private static InstanceIdentifier<FlowCapableNode> assembleFlowCapableNodeInstanceIdentifier(final DeviceContext deviceContext) {
-        return deviceContext.getDeviceState().getNodeInstanceIdentifier().augmentation(FlowCapableNode.class);
+    private static InstanceIdentifier<FlowCapableNode> assembleFlowCapableNodeInstanceIdentifier(final DeviceState deviceState) {
+        return deviceState.getNodeInstanceIdentifier().augmentation(FlowCapableNode.class);
     }
 
     /**
index 44f412be7a0389723a4a96ad741c16a00f23c8ff..708410e69cc14cb198332e5d2da154f38a3ca261 100644 (file)
@@ -96,7 +96,7 @@ public class MdSalRegistrationUtils {
         rpcContext.registerRpcServiceImplementation(FlowCapableTransactionService.class, flowCapableTransactionService);
         rpcContext.registerRpcServiceImplementation(SalMeterService.class, salMeterService);
         rpcContext.registerRpcServiceImplementation(SalGroupService.class, salGroupService);
-        rpcContext.registerRpcServiceImplementation(SalTableService.class, new SalTableServiceImpl(rpcContext, deviceContext));
+        rpcContext.registerRpcServiceImplementation(SalTableService.class, new SalTableServiceImpl(rpcContext, deviceContext, deviceContext.getPrimaryConnectionContext().getNodeId()));
         rpcContext.registerRpcServiceImplementation(SalPortService.class, new SalPortServiceImpl(rpcContext, deviceContext));
         rpcContext.registerRpcServiceImplementation(PacketProcessingService.class, new PacketProcessingServiceImpl(rpcContext, deviceContext));
         rpcContext.registerRpcServiceImplementation(NodeConfigService.class, new NodeConfigServiceImpl(rpcContext, deviceContext));
index 8d41070cbddac264106e1c63822d298ffd5cbd83..756b1ee4371b6cb5a0a85521d5b9823f6100199a 100644 (file)
@@ -109,11 +109,15 @@ public class MultipartRequestOnTheFlyCallbackTest {
         when(mockedFeaturesReply.getDatapathId()).thenReturn(BigInteger.valueOf(123L));
 
         when(mocketGetFeaturesOutput.getTables()).thenReturn(tableId);
+        when(mocketGetFeaturesOutput.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3);
+        when(mocketGetFeaturesOutput.getDatapathId()).thenReturn(BigInteger.valueOf(123L));
 
         when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedPrimaryConnection);
         when(mockedDeviceState.getNodeInstanceIdentifier()).thenReturn(NODE_PATH);
         when(mockedDeviceState.getFeatures()).thenReturn(mocketGetFeaturesOutput);
         when(mockedDeviceState.deviceSynchronized()).thenReturn(true);
+        when(mockedDeviceState.getNodeId()).thenReturn(mockedNodeId);
+
         when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
         when(mockedDeviceContext.getDeviceFlowRegistry()).thenReturn(mockedFlowRegistry);
 
@@ -132,7 +136,9 @@ public class MultipartRequestOnTheFlyCallbackTest {
                 //NOOP
             }
         };
-        multipartRequestOnTheFlyCallback = new MultipartRequestOnTheFlyCallback(dummyRequestContext, String.class, mockedDeviceContext, dummyEventIdentifier);
+        multipartRequestOnTheFlyCallback = new MultipartRequestOnTheFlyCallback(dummyRequestContext, String.class,
+                mockedDeviceContext.getMessageSpy(),dummyEventIdentifier, mockedDeviceContext.getDeviceState(),
+                mockedDeviceContext.getDeviceFlowRegistry(), mockedDeviceContext);
     }
 
 
index 188cb7816dfe532ffa697e034b6d8377f7ad5879..0e821d484ccc9450776108c137206b7435742c2e 100644 (file)
@@ -63,7 +63,8 @@ public class SalTableServiceImplTest extends ServiceMocking {
                 .when(mockedOutboundQueue).commitEntry(
                 Matchers.anyLong(), Matchers.<OfHeader>any(), Matchers.<FutureCallback<OfHeader>>any());
 
-        salTableService = new SalTableServiceImpl(mockedRequestContextStack, mockedDeviceContext);
+        salTableService = new SalTableServiceImpl(mockedRequestContextStack, mockedDeviceContext,
+                mockedDeviceContext.getPrimaryConnectionContext().getNodeId());
     }
 
     @Test
index 370af566666534b94e1df80a8ba11716c1c4b29c..46414d6c822c6315dee8f751c6a87a207e890bf5 100644 (file)
@@ -94,7 +94,10 @@ public class SinglePurposeMultipartReplyTranslatorTest {
 
         MultipartReplyMessage multipartReplyMessage = prepareMocks(mockedDeviceContext, prepareMultipartReplyFlow(), MultipartType.OFPMPFLOW);
 
-        List<DataObject> result = singlePurposeMultipartReplyTranslator.translate(mockedDeviceContext, multipartReplyMessage);
+        List<DataObject> result = singlePurposeMultipartReplyTranslator.translate(
+                mockedDeviceContext.getPrimaryConnectionContext().getFeatures().getDatapathId(),
+                mockedDeviceContext.getPrimaryConnectionContext().getFeatures().getVersion(),
+                multipartReplyMessage);
 
         DataObject dataObject = validateOutput(result);
         assertTrue(dataObject instanceof FlowsStatisticsUpdate);
@@ -106,7 +109,10 @@ public class SinglePurposeMultipartReplyTranslatorTest {
 
         MultipartReplyMessage multipartReplyMessage = prepareMocks(mockedDeviceContext, prepareMultipartReplyAggregate(), MultipartType.OFPMPAGGREGATE);
 
-        List<DataObject> result = singlePurposeMultipartReplyTranslator.translate(mockedDeviceContext, multipartReplyMessage);
+        List<DataObject> result = singlePurposeMultipartReplyTranslator.translate(
+                mockedDeviceContext.getPrimaryConnectionContext().getFeatures().getDatapathId(),
+                mockedDeviceContext.getPrimaryConnectionContext().getFeatures().getVersion(),
+                multipartReplyMessage);
 
         DataObject dataObject = validateOutput(result);
         assertTrue(dataObject instanceof AggregateFlowStatisticsUpdate);
@@ -123,7 +129,10 @@ public class SinglePurposeMultipartReplyTranslatorTest {
         MultipartReplyMessage multipartReplyMessage = prepareMocks(mockedDeviceContext, prepareMultipartReplyPortStats(), MultipartType.OFPMPPORTSTATS);
 
         OpenflowPortsUtil.init();
-        List<DataObject> result = singlePurposeMultipartReplyTranslator.translate(mockedDeviceContext, multipartReplyMessage);
+        List<DataObject> result = singlePurposeMultipartReplyTranslator.translate(
+                mockedDeviceContext.getPrimaryConnectionContext().getFeatures().getDatapathId(),
+                mockedDeviceContext.getPrimaryConnectionContext().getFeatures().getVersion(),
+                multipartReplyMessage);
 
         DataObject dataObject = validateOutput(result);
         assertTrue(dataObject instanceof NodeConnectorStatisticsUpdate);
@@ -152,7 +161,10 @@ public class SinglePurposeMultipartReplyTranslatorTest {
 
         MultipartReplyMessage multipartReplyMessage = prepareMocks(mockedDeviceContext, prepareMultipartReplyGroup(), MultipartType.OFPMPGROUP);
 
-        List<DataObject> result = singlePurposeMultipartReplyTranslator.translate(mockedDeviceContext, multipartReplyMessage);
+        List<DataObject> result = singlePurposeMultipartReplyTranslator.translate(
+                mockedDeviceContext.getPrimaryConnectionContext().getFeatures().getDatapathId(),
+                mockedDeviceContext.getPrimaryConnectionContext().getFeatures().getVersion(),
+                multipartReplyMessage);
 
         DataObject dataObject = validateOutput(result);
         assertTrue(dataObject instanceof GroupStatisticsUpdated);
@@ -175,7 +187,10 @@ public class SinglePurposeMultipartReplyTranslatorTest {
 
         MultipartReplyMessage multipartReplyMessage = prepareMocks(mockedDeviceContext, prepareMultipartReplyGroupDesc(), MultipartType.OFPMPGROUPDESC);
 
-        List<DataObject> result = singlePurposeMultipartReplyTranslator.translate(mockedDeviceContext, multipartReplyMessage);
+        List<DataObject> result = singlePurposeMultipartReplyTranslator.translate(
+                mockedDeviceContext.getPrimaryConnectionContext().getFeatures().getDatapathId(),
+                mockedDeviceContext.getPrimaryConnectionContext().getFeatures().getVersion(),
+                multipartReplyMessage);
 
         DataObject dataObject = validateOutput(result);
         assertTrue(dataObject instanceof GroupDescStatsUpdated);
index 283d0d0b87038c5dbfa448ec5857e7d96654556a..b1c389eca913baf3743cfd57f16c42968dfcbf64 100644 (file)
@@ -193,7 +193,8 @@ public class StatisticsGatheringUtilsTest {
         final ArgumentCaptor<InstanceIdentifier> flowPath = ArgumentCaptor.forClass(InstanceIdentifier.class);
         final ArgumentCaptor<Flow> flow = ArgumentCaptor.forClass(Flow.class);
 
-        StatisticsGatheringUtils.writeFlowStatistics(prepareFlowStatisticsData(), deviceContext);
+        StatisticsGatheringUtils.writeFlowStatistics(prepareFlowStatisticsData(),
+                deviceContext.getDeviceState(), deviceContext.getDeviceFlowRegistry(), deviceContext);
 
         Mockito.verify(deviceContext).writeToTransaction(
                 dataStoreType.capture(), flowPath.capture(), flow.capture());
@@ -493,7 +494,8 @@ public class StatisticsGatheringUtilsTest {
     @Test
     public void testDeleteAllKnownFlowsNotSync() throws Exception {
         when(deviceState.deviceSynchronized()).thenReturn(false);
-        StatisticsGatheringUtils.deleteAllKnownFlows(deviceContext);
+        StatisticsGatheringUtils.deleteAllKnownFlows(deviceContext.getDeviceState(),
+                deviceContext.getDeviceFlowRegistry(), deviceContext);
         Mockito.verifyNoMoreInteractions(deviceFlowRegistry);
     }
 
@@ -512,7 +514,8 @@ public class StatisticsGatheringUtilsTest {
         final KeyedInstanceIdentifier<Table, TableKey> tablePath = deviceState.getNodeInstanceIdentifier()
                 .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tableId));
 
-        StatisticsGatheringUtils.deleteAllKnownFlows(deviceContext);
+        StatisticsGatheringUtils.deleteAllKnownFlows(deviceContext.getDeviceState(),
+                deviceContext.getDeviceFlowRegistry(), deviceContext);
 
         verify(deviceContext).writeToTransaction(
                 LogicalDatastoreType.OPERATIONAL,
index 29626cf4e4e452e22c2c8df0944f31e13d56d95f..ab611e216afbb57f0e163a8732e748d2acccd267 100644 (file)
@@ -31,6 +31,7 @@ public class StatisticsGatheringOnTheFlyServiceTest extends ServiceMocking {
     protected void setup() {
         statisticsGatheringService = new StatisticsGatheringOnTheFlyService(mockedRequestContextStack, mockedDeviceContext);
         Mockito.doReturn(NODE_ID).when(mockedPrimConnectionContext).getNodeId();
+        Mockito.when(mockedDeviceContext.getDeviceState().getNodeId()).thenReturn(NODE_ID);
     }
 
     @Test