import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
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;
import org.opendaylight.openflowplugin.impl.registry.flow.FlowRegistryKeyFactory;
-import org.opendaylight.openflowplugin.impl.statistics.services.dedicated.StatisticsGatheringService;
+import org.opendaylight.openflowplugin.impl.statistics.ofpspecific.EventsTimeCounter;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
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.meter.statistics.rev131111.MeterConfigStatsUpdated;
import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterStatisticsUpdated;
import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterStatistics;
private static final Logger LOG = LoggerFactory.getLogger(StatisticsGatheringUtils.class);
private static final SinglePurposeMultipartReplyTranslator MULTIPART_REPLY_TRANSLATOR = new SinglePurposeMultipartReplyTranslator();
+ public static final String QUEUE2_REQCTX = "QUEUE2REQCTX-";
private StatisticsGatheringUtils() {
throw new IllegalStateException("This class should not be instantiated.");
}
-
- public static ListenableFuture<Boolean> gatherStatistics(final StatisticsGatheringService statisticsGatheringService,
+ public static ListenableFuture<Boolean> gatherStatistics(final StatisticsGatherer statisticsGatheringService,
final DeviceContext deviceContext,
final MultipartType type) {
//FIXME : anytype listener must not be send as parameter, it has to be extracted from device context inside service
+ final String deviceId = deviceContext.getPrimaryConnectionContext().getNodeId().toString();
+ EventIdentifier wholeProcessEventIdentifier = null;
+ if (MultipartType.OFPMPFLOW.equals(type)) {
+ wholeProcessEventIdentifier = new EventIdentifier(type.toString(), deviceId);
+ EventsTimeCounter.markStart(wholeProcessEventIdentifier);
+ }
+ EventIdentifier ofpQueuToRequestContextEventIdentifier = new EventIdentifier(QUEUE2_REQCTX + type.toString(), deviceId);
final ListenableFuture<RpcResult<List<MultipartReply>>> statisticsDataInFuture =
- JdkFutureAdapters.listenInPoolThread(statisticsGatheringService.getStatisticsOfType(type));
- return transformAndStoreStatisticsData(statisticsDataInFuture, deviceContext);
+ JdkFutureAdapters.listenInPoolThread(statisticsGatheringService.getStatisticsOfType(
+ ofpQueuToRequestContextEventIdentifier, type));
+ return transformAndStoreStatisticsData(statisticsDataInFuture, deviceContext, wholeProcessEventIdentifier);
}
private static ListenableFuture<Boolean> transformAndStoreStatisticsData(final ListenableFuture<RpcResult<List<MultipartReply>>> statisticsDataInFuture,
- final DeviceContext deviceContext) {
+ final DeviceContext deviceContext,
+ final EventIdentifier eventIdentifier) {
return Futures.transform(statisticsDataInFuture, new Function<RpcResult<List<MultipartReply>>, Boolean>() {
@Nullable
@Override
public Boolean apply(final RpcResult<List<MultipartReply>> rpcResult) {
if (rpcResult.isSuccessful()) {
boolean isMultipartProcessed = Boolean.TRUE;
- Iterable<? extends DataObject> allMultipartData = Collections.emptyList();
- DataObject multipartData = null;
- for (final MultipartReply singleReply : rpcResult.getResult()) {
- final List<? extends DataObject> multipartDataList = MULTIPART_REPLY_TRANSLATOR.translate(deviceContext, singleReply);
- multipartData = multipartDataList.get(0);
- allMultipartData = Iterables.concat(allMultipartData, multipartDataList);
- }
- if (multipartData instanceof GroupStatisticsUpdated) {
- processGroupStatistics((Iterable<GroupStatisticsUpdated>) allMultipartData, deviceContext);
- } else if (multipartData instanceof MeterStatisticsUpdated) {
- processMetersStatistics((Iterable<MeterStatisticsUpdated>) allMultipartData, deviceContext);
- } else if (multipartData instanceof NodeConnectorStatisticsUpdate) {
- processNodeConnectorStatistics((Iterable<NodeConnectorStatisticsUpdate>) allMultipartData, deviceContext);
- } else if (multipartData instanceof FlowTableStatisticsUpdate) {
- processFlowTableStatistics((Iterable<FlowTableStatisticsUpdate>) allMultipartData, deviceContext);
- } else if (multipartData instanceof QueueStatisticsUpdate) {
- processQueueStatistics((Iterable<QueueStatisticsUpdate>) allMultipartData, deviceContext);
- } else if (multipartData instanceof FlowsStatisticsUpdate) {
- processFlowStatistics((Iterable<FlowsStatisticsUpdate>) allMultipartData, deviceContext);
- } else if (multipartData instanceof GroupDescStatsUpdated) {
- processGroupDescStats((Iterable<GroupDescStatsUpdated>) allMultipartData, deviceContext);
- } else if (multipartData instanceof MeterConfigStatsUpdated) {
- processMeterConfigStatsUpdated((Iterable<MeterConfigStatsUpdated>) allMultipartData, deviceContext);
- } else {
- isMultipartProcessed = Boolean.FALSE;
+ // TODO: in case the result value is null then multipart data probably got processed on the fly -
+ // TODO: this contract should by clearly stated and enforced - now simple true value is returned
+ if (null != rpcResult.getResult()) {
+ Iterable<? extends DataObject> allMultipartData = Collections.emptyList();
+ DataObject multipartData = null;
+ for (final MultipartReply singleReply : rpcResult.getResult()) {
+ final List<? extends DataObject> multipartDataList = MULTIPART_REPLY_TRANSLATOR.translate(deviceContext, singleReply);
+ multipartData = multipartDataList.get(0);
+ allMultipartData = Iterables.concat(allMultipartData, multipartDataList);
+ }
+
+ if (multipartData instanceof GroupStatisticsUpdated) {
+ processGroupStatistics((Iterable<GroupStatisticsUpdated>) allMultipartData, deviceContext);
+ } else if (multipartData instanceof MeterStatisticsUpdated) {
+ processMetersStatistics((Iterable<MeterStatisticsUpdated>) allMultipartData, deviceContext);
+ } else if (multipartData instanceof NodeConnectorStatisticsUpdate) {
+ processNodeConnectorStatistics((Iterable<NodeConnectorStatisticsUpdate>) allMultipartData, deviceContext);
+ } else if (multipartData instanceof FlowTableStatisticsUpdate) {
+ processFlowTableStatistics((Iterable<FlowTableStatisticsUpdate>) allMultipartData, deviceContext);
+ } else if (multipartData instanceof QueueStatisticsUpdate) {
+ processQueueStatistics((Iterable<QueueStatisticsUpdate>) allMultipartData, deviceContext);
+ } else if (multipartData instanceof FlowsStatisticsUpdate) {
+ processFlowStatistics((Iterable<FlowsStatisticsUpdate>) allMultipartData, deviceContext);
+ EventsTimeCounter.markEnd(eventIdentifier);
+ } else if (multipartData instanceof GroupDescStatsUpdated) {
+ processGroupDescStats((Iterable<GroupDescStatsUpdated>) allMultipartData, deviceContext);
+ } else if (multipartData instanceof MeterConfigStatsUpdated) {
+ processMeterConfigStatsUpdated((Iterable<MeterConfigStatsUpdated>) allMultipartData, deviceContext);
+ } else {
+ isMultipartProcessed = Boolean.FALSE;
+ }
+ //TODO : implement experimenter
}
- //TODO : implement experimenter
return isMultipartProcessed;
}
}
private static void processMeterConfigStatsUpdated(final Iterable<MeterConfigStatsUpdated> data, final DeviceContext deviceContext) {
+ final InstanceIdentifier<FlowCapableNode> fNodeIdent = assembleFlowCapableNodeInstanceIdentifier(deviceContext);
+ deleteAllKnownMeters(deviceContext, fNodeIdent);
for (final MeterConfigStatsUpdated meterConfigStatsUpdated : data) {
- final NodeId nodeId = meterConfigStatsUpdated.getId();
- final InstanceIdentifier<FlowCapableNode> fNodeIdent = getFlowCapableNodeInstanceIdentifier(nodeId);
for (final MeterConfigStats meterConfigStats : meterConfigStatsUpdated.getMeterConfigStats()) {
final MeterId meterId = meterConfigStats.getMeterId();
final InstanceIdentifier<Meter> meterInstanceIdentifier = fNodeIdent.child(Meter.class, new MeterKey(meterId));
}
private static void processFlowStatistics(final Iterable<FlowsStatisticsUpdate> data, final DeviceContext deviceContext) {
- final NodeId nodeId = deviceContext.getDeviceState().getNodeId();
- final InstanceIdentifier<Node> nodeIdent = InstanceIdentifier.create(Nodes.class)
- .child(Node.class, new NodeKey(nodeId));
- deleteAllKnownFlows(deviceContext, nodeIdent);
+ deleteAllKnownFlows(deviceContext);
+ writeFlowStatistics(data, deviceContext);
+ deviceContext.submitTransaction();
+ }
+
+ public static void writeFlowStatistics(Iterable<FlowsStatisticsUpdate> data, DeviceContext deviceContext) {
+ final InstanceIdentifier<FlowCapableNode> fNodeIdent = assembleFlowCapableNodeInstanceIdentifier(deviceContext);
for (final FlowsStatisticsUpdate flowsStatistics : data) {
for (final FlowAndStatisticsMapList flowStat : flowsStatistics.getFlowAndStatisticsMapList()) {
final FlowBuilder flowBuilder = new FlowBuilder(flowStat);
final FlowKey flowKey = new FlowKey(flowId);
flowBuilder.setKey(flowKey);
final TableKey tableKey = new TableKey(tableId);
- final InstanceIdentifier<FlowCapableNode> fNodeIdent = getFlowCapableNodeInstanceIdentifier(flowsStatistics.getId());
final InstanceIdentifier<Flow> flowIdent = fNodeIdent.child(Table.class, tableKey).child(Flow.class, flowKey);
deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, flowIdent, flowBuilder.build());
}
}
- deviceContext.submitTransaction();
}
- private static void deleteAllKnownFlows(final DeviceContext deviceContext, final InstanceIdentifier<Node> nodeIdent) {
+ public static void deleteAllKnownFlows(final DeviceContext deviceContext) {
if (deviceContext.getDeviceState().deviceSynchronized()) {
+ InstanceIdentifier<FlowCapableNode> flowCapableNodePath = assembleFlowCapableNodeInstanceIdentifier(deviceContext);
final Short numOfTablesOnDevice = deviceContext.getDeviceState().getFeatures().getTables();
- for (short i=0; i<numOfTablesOnDevice; i++) {
- final KeyedInstanceIdentifier<Table, TableKey> iiToTable
- = nodeIdent.augmentation(FlowCapableNode.class).child( Table.class, new TableKey(i));
+ for (short i = 0; i < numOfTablesOnDevice; i++) {
+ final KeyedInstanceIdentifier<Table, TableKey> iiToTable = flowCapableNodePath.child(Table.class, new TableKey(i));
final ReadTransaction readTx = deviceContext.getReadTransaction();
final CheckedFuture<Optional<Table>, ReadFailedException> tableDataFuture = readTx.read(LogicalDatastoreType.OPERATIONAL, iiToTable);
try {
}
private static void processQueueStatistics(final Iterable<QueueStatisticsUpdate> data, final DeviceContext deviceContext) {
+ final InstanceIdentifier<Node> nodeIdent = deviceContext.getDeviceState().getNodeInstanceIdentifier();
for (final QueueStatisticsUpdate queueStatisticsUpdate : data) {
- final InstanceIdentifier<Node> nodeIdent = InstanceIdentifier.create(Nodes.class)
- .child(Node.class, new NodeKey(queueStatisticsUpdate.getId()));
for (final QueueIdAndStatisticsMap queueStat : queueStatisticsUpdate.getQueueIdAndStatisticsMap()) {
if (queueStat.getQueueId() != null) {
final FlowCapableNodeConnectorQueueStatistics statChild =
}
private static void processFlowTableStatistics(final Iterable<FlowTableStatisticsUpdate> data, final DeviceContext deviceContext) {
+ final InstanceIdentifier<FlowCapableNode> fNodeIdent = assembleFlowCapableNodeInstanceIdentifier(deviceContext);
for (final FlowTableStatisticsUpdate flowTableStatisticsUpdate : data) {
- final InstanceIdentifier<FlowCapableNode> fNodeIdent = getFlowCapableNodeInstanceIdentifier(flowTableStatisticsUpdate.getId());
for (final FlowTableAndStatisticsMap tableStat : flowTableStatisticsUpdate.getFlowTableAndStatisticsMap()) {
final InstanceIdentifier<FlowTableStatistics> tStatIdent = fNodeIdent.child(Table.class, new TableKey(tableStat.getTableId().getValue()))
}
private static void processNodeConnectorStatistics(final Iterable<NodeConnectorStatisticsUpdate> data, final DeviceContext deviceContext) {
+ final InstanceIdentifier<Node> nodeIdent = deviceContext.getDeviceState().getNodeInstanceIdentifier();
for (final NodeConnectorStatisticsUpdate nodeConnectorStatisticsUpdate : data) {
- final InstanceIdentifier<Node> nodeIdent = InstanceIdentifier.create(Nodes.class)
- .child(Node.class, new NodeKey(nodeConnectorStatisticsUpdate.getId()));
for (final NodeConnectorStatisticsAndPortNumberMap nConnectPort : nodeConnectorStatisticsUpdate.getNodeConnectorStatisticsAndPortNumberMap()) {
final FlowCapableNodeConnectorStatistics stats = new FlowCapableNodeConnectorStatisticsBuilder(nConnectPort).build();
final NodeConnectorKey key = new NodeConnectorKey(nConnectPort.getNodeConnectorId());
private static void processMetersStatistics(final Iterable<MeterStatisticsUpdated> data,
final DeviceContext deviceContext) {
- final NodeId nodeId = deviceContext.getDeviceState().getNodeId();
- final InstanceIdentifier<FlowCapableNode> fNodeIdent = getFlowCapableNodeInstanceIdentifier(nodeId);
- deleteAllKnownMeters(deviceContext, fNodeIdent);
+ final InstanceIdentifier<FlowCapableNode> fNodeIdent = assembleFlowCapableNodeInstanceIdentifier(deviceContext);
for (final MeterStatisticsUpdated meterStatisticsUpdated : data) {
for (final MeterStats mStat : meterStatisticsUpdated.getMeterStats()) {
final MeterStatistics stats = new MeterStatisticsBuilder(mStat).build();
}
private static void processGroupDescStats(final Iterable<GroupDescStatsUpdated> data, final DeviceContext deviceContext) {
- for (final GroupDescStatsUpdated groupDescStatsUpdated : data) {
- final NodeId nodeId = groupDescStatsUpdated.getId();
- final InstanceIdentifier<FlowCapableNode> fNodeIdent = getFlowCapableNodeInstanceIdentifier(nodeId);
+ final InstanceIdentifier<FlowCapableNode> fNodeIdent =
+ deviceContext.getDeviceState().getNodeInstanceIdentifier().augmentation(FlowCapableNode.class);
+ deleteAllKnownGroups(deviceContext, fNodeIdent);
+ for (final GroupDescStatsUpdated groupDescStatsUpdated : data) {
for (final GroupDescStats groupDescStats : groupDescStatsUpdated.getGroupDescStats()) {
final GroupId groupId = groupDescStats.getGroupId();
}
private static void processGroupStatistics(final Iterable<GroupStatisticsUpdated> data, final DeviceContext deviceContext) {
- final NodeId nodeId = deviceContext.getDeviceState().getNodeId();
- final InstanceIdentifier<FlowCapableNode> fNodeIdent = getFlowCapableNodeInstanceIdentifier(nodeId);
- deleteAllKnownGroups(deviceContext, fNodeIdent);
+ final InstanceIdentifier<FlowCapableNode> fNodeIdent = assembleFlowCapableNodeInstanceIdentifier(deviceContext);
for (final GroupStatisticsUpdated groupStatistics : data) {
for (final GroupStats groupStats : groupStatistics.getGroupStats()) {
deviceContext.submitTransaction();
}
- private static InstanceIdentifier<FlowCapableNode> getFlowCapableNodeInstanceIdentifier(final NodeId nodeId) {
- final InstanceIdentifier<Node> nodeIdent = InstanceIdentifier
- .create(Nodes.class).child(Node.class, new NodeKey(nodeId));
- return nodeIdent.augmentation(FlowCapableNode.class);
+ private static InstanceIdentifier<FlowCapableNode> assembleFlowCapableNodeInstanceIdentifier(final DeviceContext deviceContext) {
+ return deviceContext.getDeviceState().getNodeInstanceIdentifier().augmentation(FlowCapableNode.class);
}
}