X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=openflowplugin-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowplugin%2Fimpl%2Fstatistics%2FStatisticsGatheringUtils.java;h=ec74cc43b8055ebfc59069425ed8877f886206ad;hb=52f69b2f96908053793d76807ee5e82b4dc21e4f;hp=97a9e7d319d25e71ec3c01ea03871b1001b0fe1c;hpb=b856e3c6051c1b9a8962fbcac1c3f34b0148f441;p=openflowplugin.git diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsGatheringUtils.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsGatheringUtils.java index 97a9e7d319..ec74cc43b8 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsGatheringUtils.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsGatheringUtils.java @@ -25,9 +25,9 @@ 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.ofpspecific.EventsTimeCounter; -import org.opendaylight.openflowplugin.impl.statistics.services.dedicated.StatisticsGatheringService; 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; @@ -40,14 +40,18 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.ta import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowStatisticsData; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowStatisticsDataBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowsStatisticsUpdate; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.statistics.FlowStatisticsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsData; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsUpdate; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMap; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.statistics.FlowTableStatistics; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.statistics.FlowTableStatisticsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.queues.Queue; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.queues.QueueBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.queues.QueueKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupDescStatsUpdated; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupStatisticsUpdated; @@ -61,12 +65,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group 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; @@ -110,7 +111,7 @@ public final class StatisticsGatheringUtils { } - public static ListenableFuture gatherStatistics(final StatisticsGatheringService statisticsGatheringService, + public static ListenableFuture 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 @@ -122,7 +123,8 @@ public final class StatisticsGatheringUtils { } EventIdentifier ofpQueuToRequestContextEventIdentifier = new EventIdentifier(QUEUE2_REQCTX + type.toString(), deviceId); final ListenableFuture>> statisticsDataInFuture = - JdkFutureAdapters.listenInPoolThread(statisticsGatheringService.getStatisticsOfType(ofpQueuToRequestContextEventIdentifier, type)); + JdkFutureAdapters.listenInPoolThread(statisticsGatheringService.getStatisticsOfType( + ofpQueuToRequestContextEventIdentifier, type)); return transformAndStoreStatisticsData(statisticsDataInFuture, deviceContext, wholeProcessEventIdentifier); } @@ -135,35 +137,40 @@ public final class StatisticsGatheringUtils { public Boolean apply(final RpcResult> rpcResult) { if (rpcResult.isSuccessful()) { boolean isMultipartProcessed = Boolean.TRUE; - Iterable allMultipartData = Collections.emptyList(); - DataObject multipartData = null; - for (final MultipartReply singleReply : rpcResult.getResult()) { - final List multipartDataList = MULTIPART_REPLY_TRANSLATOR.translate(deviceContext, singleReply); - multipartData = multipartDataList.get(0); - allMultipartData = Iterables.concat(allMultipartData, multipartDataList); - } - if (multipartData instanceof GroupStatisticsUpdated) { - processGroupStatistics((Iterable) allMultipartData, deviceContext); - } else if (multipartData instanceof MeterStatisticsUpdated) { - processMetersStatistics((Iterable) allMultipartData, deviceContext); - } else if (multipartData instanceof NodeConnectorStatisticsUpdate) { - processNodeConnectorStatistics((Iterable) allMultipartData, deviceContext); - } else if (multipartData instanceof FlowTableStatisticsUpdate) { - processFlowTableStatistics((Iterable) allMultipartData, deviceContext); - } else if (multipartData instanceof QueueStatisticsUpdate) { - processQueueStatistics((Iterable) allMultipartData, deviceContext); - } else if (multipartData instanceof FlowsStatisticsUpdate) { - processFlowStatistics((Iterable) allMultipartData, deviceContext); - EventsTimeCounter.markEnd(eventIdentifier); - } else if (multipartData instanceof GroupDescStatsUpdated) { - processGroupDescStats((Iterable) allMultipartData, deviceContext); - } else if (multipartData instanceof MeterConfigStatsUpdated) { - processMeterConfigStatsUpdated((Iterable) 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 allMultipartData = Collections.emptyList(); + DataObject multipartData = null; + for (final MultipartReply singleReply : rpcResult.getResult()) { + final List multipartDataList = MULTIPART_REPLY_TRANSLATOR.translate(deviceContext, singleReply); + multipartData = multipartDataList.get(0); + allMultipartData = Iterables.concat(allMultipartData, multipartDataList); + } + + if (multipartData instanceof GroupStatisticsUpdated) { + processGroupStatistics((Iterable) allMultipartData, deviceContext); + } else if (multipartData instanceof MeterStatisticsUpdated) { + processMetersStatistics((Iterable) allMultipartData, deviceContext); + } else if (multipartData instanceof NodeConnectorStatisticsUpdate) { + processNodeConnectorStatistics((Iterable) allMultipartData, deviceContext); + } else if (multipartData instanceof FlowTableStatisticsUpdate) { + processFlowTableStatistics((Iterable) allMultipartData, deviceContext); + } else if (multipartData instanceof QueueStatisticsUpdate) { + processQueueStatistics((Iterable) allMultipartData, deviceContext); + } else if (multipartData instanceof FlowsStatisticsUpdate) { + processFlowStatistics((Iterable) allMultipartData, deviceContext); + EventsTimeCounter.markEnd(eventIdentifier); + } else if (multipartData instanceof GroupDescStatsUpdated) { + processGroupDescStats((Iterable) allMultipartData, deviceContext); + } else if (multipartData instanceof MeterConfigStatsUpdated) { + processMeterConfigStatsUpdated((Iterable) allMultipartData, deviceContext); + } else { + isMultipartProcessed = Boolean.FALSE; + } + //TODO : implement experimenter } - //TODO : implement experimenter return isMultipartProcessed; } @@ -173,9 +180,9 @@ public final class StatisticsGatheringUtils { } private static void processMeterConfigStatsUpdated(final Iterable data, final DeviceContext deviceContext) { + final InstanceIdentifier fNodeIdent = assembleFlowCapableNodeInstanceIdentifier(deviceContext); + deleteAllKnownMeters(deviceContext, fNodeIdent); for (final MeterConfigStatsUpdated meterConfigStatsUpdated : data) { - final NodeId nodeId = meterConfigStatsUpdated.getId(); - final InstanceIdentifier fNodeIdent = getFlowCapableNodeInstanceIdentifier(nodeId); for (final MeterConfigStats meterConfigStats : meterConfigStatsUpdated.getMeterConfigStats()) { final MeterId meterId = meterConfigStats.getMeterId(); final InstanceIdentifier meterInstanceIdentifier = fNodeIdent.child(Meter.class, new MeterKey(meterId)); @@ -191,13 +198,18 @@ public final class StatisticsGatheringUtils { } private static void processFlowStatistics(final Iterable data, final DeviceContext deviceContext) { - final NodeId nodeId = deviceContext.getDeviceState().getNodeId(); - final InstanceIdentifier 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 data, DeviceContext deviceContext) { + final InstanceIdentifier fNodeIdent = assembleFlowCapableNodeInstanceIdentifier(deviceContext); for (final FlowsStatisticsUpdate flowsStatistics : data) { for (final FlowAndStatisticsMapList flowStat : flowsStatistics.getFlowAndStatisticsMapList()) { final FlowBuilder flowBuilder = new FlowBuilder(flowStat); + flowBuilder.addAugmentation(FlowStatisticsData.class, refineFlowStatisticsAugmentation(flowStat).build()); + final short tableId = flowStat.getTableId(); final FlowRegistryKey flowRegistryKey = FlowRegistryKeyFactory.create(flowBuilder.build()); final FlowId flowId = deviceContext.getDeviceFlowRegistry().storeIfNecessary(flowRegistryKey, tableId); @@ -205,20 +217,30 @@ public final class StatisticsGatheringUtils { final FlowKey flowKey = new FlowKey(flowId); flowBuilder.setKey(flowKey); final TableKey tableKey = new TableKey(tableId); - final InstanceIdentifier fNodeIdent = getFlowCapableNodeInstanceIdentifier(flowsStatistics.getId()); final InstanceIdentifier 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 nodeIdent) { + /** + * Method extracts flow statistics out of flowAndStatistics model + * + * @param flowAndStats + */ + private static FlowStatisticsDataBuilder refineFlowStatisticsAugmentation(final FlowAndStatisticsMapList flowAndStats) { + final FlowStatisticsBuilder flowStatisticsBuilder = new FlowStatisticsBuilder(flowAndStats); + final FlowStatisticsDataBuilder flowStatisticsDataBld = new FlowStatisticsDataBuilder(); + flowStatisticsDataBld.setFlowStatistics(flowStatisticsBuilder.build()); + return flowStatisticsDataBld; + } + + public static void deleteAllKnownFlows(final DeviceContext deviceContext) { if (deviceContext.getDeviceState().deviceSynchronized()) { + InstanceIdentifier flowCapableNodePath = assembleFlowCapableNodeInstanceIdentifier(deviceContext); final Short numOfTablesOnDevice = deviceContext.getDeviceState().getFeatures().getTables(); for (short i = 0; i < numOfTablesOnDevice; i++) { - final KeyedInstanceIdentifier iiToTable - = nodeIdent.augmentation(FlowCapableNode.class).child(Table.class, new TableKey(i)); + final KeyedInstanceIdentifier iiToTable = flowCapableNodePath.child(Table.class, new TableKey(i)); final ReadTransaction readTx = deviceContext.getReadTransaction(); final CheckedFuture, ReadFailedException> tableDataFuture = readTx.read(LogicalDatastoreType.OPERATIONAL, iiToTable); try { @@ -234,13 +256,14 @@ public final class StatisticsGatheringUtils { LOG.trace("Reading of table features for table wit ID {} encountered execution exception {}.", i, e); } } + deviceContext.getDeviceFlowRegistry().removeMarked(); } } private static void processQueueStatistics(final Iterable data, final DeviceContext deviceContext) { + // TODO: clean all queues of all node-connectors before writing up-to-date stats + final InstanceIdentifier nodeIdent = deviceContext.getDeviceState().getNodeInstanceIdentifier(); for (final QueueStatisticsUpdate queueStatisticsUpdate : data) { - final InstanceIdentifier 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 = @@ -253,8 +276,12 @@ public final class StatisticsGatheringUtils { .child(NodeConnector.class, new NodeConnectorKey(queueStat.getNodeConnectorId())) .augmentation(FlowCapableNodeConnector.class) .child(Queue.class, qKey); - final InstanceIdentifier queueStatIdent = queueIdent.augmentation(FlowCapableNodeConnectorQueueStatisticsData.class); - deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, queueStatIdent, statBuild.build()); + final QueueBuilder queueBuilder = new QueueBuilder() + .setKey(qKey) + .setQueueId(queueStat.getQueueId()) + // node-connector-id is already contained in parent node and the port-id here is of incompatible format + .addAugmentation(FlowCapableNodeConnectorQueueStatisticsData.class, statBuild.build()); + deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, queueIdent, queueBuilder.build()); } } } @@ -262,8 +289,8 @@ public final class StatisticsGatheringUtils { } private static void processFlowTableStatistics(final Iterable data, final DeviceContext deviceContext) { + final InstanceIdentifier fNodeIdent = assembleFlowCapableNodeInstanceIdentifier(deviceContext); for (final FlowTableStatisticsUpdate flowTableStatisticsUpdate : data) { - final InstanceIdentifier fNodeIdent = getFlowCapableNodeInstanceIdentifier(flowTableStatisticsUpdate.getId()); for (final FlowTableAndStatisticsMap tableStat : flowTableStatisticsUpdate.getFlowTableAndStatisticsMap()) { final InstanceIdentifier tStatIdent = fNodeIdent.child(Table.class, new TableKey(tableStat.getTableId().getValue())) @@ -276,9 +303,8 @@ public final class StatisticsGatheringUtils { } private static void processNodeConnectorStatistics(final Iterable data, final DeviceContext deviceContext) { + final InstanceIdentifier nodeIdent = deviceContext.getDeviceState().getNodeInstanceIdentifier(); for (final NodeConnectorStatisticsUpdate nodeConnectorStatisticsUpdate : data) { - final InstanceIdentifier 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()); @@ -295,9 +321,7 @@ public final class StatisticsGatheringUtils { private static void processMetersStatistics(final Iterable data, final DeviceContext deviceContext) { - final NodeId nodeId = deviceContext.getDeviceState().getNodeId(); - final InstanceIdentifier fNodeIdent = getFlowCapableNodeInstanceIdentifier(nodeId); - deleteAllKnownMeters(deviceContext, fNodeIdent); + final InstanceIdentifier fNodeIdent = assembleFlowCapableNodeInstanceIdentifier(deviceContext); for (final MeterStatisticsUpdated meterStatisticsUpdated : data) { for (final MeterStats mStat : meterStatisticsUpdated.getMeterStats()) { final MeterStatistics stats = new MeterStatisticsBuilder(mStat).build(); @@ -321,10 +345,11 @@ public final class StatisticsGatheringUtils { } private static void processGroupDescStats(final Iterable data, final DeviceContext deviceContext) { - for (final GroupDescStatsUpdated groupDescStatsUpdated : data) { - final NodeId nodeId = groupDescStatsUpdated.getId(); - final InstanceIdentifier fNodeIdent = getFlowCapableNodeInstanceIdentifier(nodeId); + final InstanceIdentifier 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(); @@ -350,9 +375,7 @@ public final class StatisticsGatheringUtils { } private static void processGroupStatistics(final Iterable data, final DeviceContext deviceContext) { - final NodeId nodeId = deviceContext.getDeviceState().getNodeId(); - final InstanceIdentifier fNodeIdent = getFlowCapableNodeInstanceIdentifier(nodeId); - deleteAllKnownGroups(deviceContext, fNodeIdent); + final InstanceIdentifier fNodeIdent = assembleFlowCapableNodeInstanceIdentifier(deviceContext); for (final GroupStatisticsUpdated groupStatistics : data) { for (final GroupStats groupStats : groupStatistics.getGroupStats()) { @@ -368,9 +391,7 @@ public final class StatisticsGatheringUtils { deviceContext.submitTransaction(); } - private static InstanceIdentifier getFlowCapableNodeInstanceIdentifier(final NodeId nodeId) { - final InstanceIdentifier nodeIdent = InstanceIdentifier - .create(Nodes.class).child(Node.class, new NodeKey(nodeId)); - return nodeIdent.augmentation(FlowCapableNode.class); + private static InstanceIdentifier assembleFlowCapableNodeInstanceIdentifier(final DeviceContext deviceContext) { + return deviceContext.getDeviceState().getNodeInstanceIdentifier().augmentation(FlowCapableNode.class); } }