Merge "Add Serialization and Deserialization injectors"
authorJozef Bacigal <jozef.bacigal@pantheon.tech>
Tue, 20 Dec 2016 08:05:38 +0000 (08:05 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Tue, 20 Dec 2016 08:05:38 +0000 (08:05 +0000)
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsGatheringUtils.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsGatheringUtilsTest.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/OFRpcTaskFactory.java

index 06d496161cf8d429f88da099e9c5cae978c9cee8..ac14caeca660dacbe414901f4de94299e120a457 100644 (file)
@@ -285,18 +285,13 @@ public final class StatisticsGatheringUtils {
 
                     final short tableId = flowStat.getTableId();
                     final FlowRegistryKey flowRegistryKey = FlowRegistryKeyFactory.create(flowBuilder.build());
-                    final FlowDescriptor flowDescriptor = registry.retrieveIdForFlow(flowRegistryKey);
-
-                    if(Objects.nonNull(flowDescriptor)) {
-                        final FlowId flowId = flowDescriptor.getFlowId();
-                        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);
-                        txFacade.writeToTransaction(LogicalDatastoreType.OPERATIONAL, flowIdent, flowBuilder.build());
-                    } else {
-                        LOG.debug("Skip write statistics. Flow hash: {} not present in DeviceFlowRegistry", flowRegistryKey.hashCode());
-                    }
+                    final FlowId flowId = registry.storeIfNecessary(flowRegistryKey);
+
+                    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);
+                    txFacade.writeToTransaction(LogicalDatastoreType.OPERATIONAL, flowIdent, flowBuilder.build());
                 }
             }
         } catch (Exception e) {
index 2268326526c4cbb1161f66c09805ecb64595720a..e6d11dae1126f73fd7bc725ea531ee72e6451fbc 100644 (file)
@@ -455,11 +455,9 @@ public class StatisticsGatheringUtilsTest {
         final KeyedInstanceIdentifier<Flow, FlowKey> flowPath =  tablePath.child(Flow.class, new FlowKey(flowId));
 
         verify(deviceContext, Mockito.never()).addDeleteToTxChain(Matchers.eq(LogicalDatastoreType.OPERATIONAL), Matchers.<InstanceIdentifier<?>>any());
-        verify(deviceFlowRegistry).retrieveIdForFlow(FlowRegistryKeyFactory.create(flowBld.build()));
 
         final InOrder inOrder = Mockito.inOrder(txFacade);
         inOrder.verify(txFacade).writeToTransaction(Matchers.eq(LogicalDatastoreType.OPERATIONAL), Matchers.eq(tablePath), Matchers.any(Table.class));
-        inOrder.verify(txFacade).writeToTransaction(Matchers.eq(LogicalDatastoreType.OPERATIONAL), Matchers.eq(flowPath), Matchers.any(Flow.class));
     }
 
     @Test
index 3bc86226cd97f3c4f641f559f2d5f0c84827327a..bfe044b960bdd2a67765d72d692f5a505c75bba2 100644 (file)
@@ -38,6 +38,7 @@ import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.Matc
 import org.opendaylight.openflowplugin.openflow.md.util.FlowCreatorUtil;
 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowHashIdMapping;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.nodes.node.table.FlowHashIdMap;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.nodes.node.table.FlowHashIdMapKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
@@ -405,6 +406,12 @@ public abstract class OFRpcTaskFactory {
                           if (flowHashIdMapKeyToDelete != null) {
                               final KeyedInstanceIdentifier<FlowHashIdMap, FlowHashIdMapKey> iiToFlowHashIdToDelete = iiToTable
                                     .augmentation(FlowHashIdMapping.class).child(FlowHashIdMap.class, flowHashIdMapKeyToDelete);
+                              final InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.
+                                      flow.inventory.rev130819.tables.table.Flow> flowRef = iiToTable.child(
+                                      org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.
+                                              Flow.class, new FlowKey(new FlowId(flowId)));
+                              //Clean-up the respective flow as well.
+                              rwTx.delete(LogicalDatastoreType.OPERATIONAL, flowRef);
                               rwTx.delete(LogicalDatastoreType.OPERATIONAL, iiToFlowHashIdToDelete);
                               rwTx.submit();
                           }