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) {
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
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;
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();
}