Search in sources :

Example 6 with GetFlowStatisticsOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsOutput in project netvirt by opendaylight.

the class CounterRetriever method createSwitchFlowResultMapDirect.

private CounterResultDataStructure createSwitchFlowResultMapDirect(GetFlowStatisticsOutput flowStatsOutput) {
    List<FlowAndStatisticsMapList> flowUpdates = flowStatsOutput.getFlowAndStatisticsMapList();
    if (flowUpdates == null || flowUpdates.isEmpty()) {
        LOG.warn("Unable to retrieve flows statistics info");
        return null;
    }
    CounterResultDataStructure crds = new CounterResultDataStructure();
    for (FlowAndStatisticsMapList flowUpdate : flowUpdates) {
        String resultId = flowUpdate.getTableId().toString() + CountersUtils.OF_DELIMITER + UUID.randomUUID();
        crds.addCounterResult(resultId);
        if (flowUpdate.getByteCount() != null) {
            crds.addCounterToGroup(resultId, CountersUtils.BYTES_GROUP_NAME, CountersUtils.BYTE_COUNTER_NAME, flowUpdate.getByteCount().getValue());
        }
        if (flowUpdate.getPacketCount() != null) {
            crds.addCounterToGroup(resultId, CountersUtils.PACKETS_GROUP_NAME, CountersUtils.PACKET_COUNTER_NAME, flowUpdate.getPacketCount().getValue());
        }
        if (flowUpdate.getDuration() != null) {
            crds.addCounterToGroup(resultId, CountersUtils.DURATION_GROUP_NAME, CountersUtils.DURATION_SECOND_COUNTER_NAME, big(flowUpdate.getDuration().getSecond().getValue()));
            crds.addCounterToGroup(resultId, CountersUtils.DURATION_GROUP_NAME, CountersUtils.DURATION_NANO_SECOND_COUNTER_NAME, big(flowUpdate.getDuration().getNanosecond().getValue()));
        }
    }
    return crds;
}
Also used : FlowAndStatisticsMapList(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList)

Example 7 with GetFlowStatisticsOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsOutput in project netvirt by opendaylight.

the class TestOdlDirectStatisticsService method getFlowStatistics.

@Override
public Future<RpcResult<GetFlowStatisticsOutput>> getFlowStatistics(GetFlowStatisticsInput input) {
    LOG.info("getFlowStatistics rpc input = {}", input);
    List<FlowAndStatisticsMapList> flowStatsList = new ArrayList<>();
    FlowAndStatisticsMapList portIngressFlowStats1 = buildFlowStats(NwConstants.EGRESS_ACL_FILTER_CUM_DISPATCHER_TABLE, AclConstants.ACL_PORT_SPECIFIC_DROP_PRIORITY, 1, 5, 5);
    FlowAndStatisticsMapList portIngressFlowStats2 = buildFlowStats(NwConstants.EGRESS_ACL_FILTER_CUM_DISPATCHER_TABLE, AclConstants.CT_STATE_TRACKED_INVALID_PRIORITY, 1, 10, 10);
    FlowAndStatisticsMapList portEgressFlowStats1 = buildFlowStats(NwConstants.INGRESS_ACL_FILTER_CUM_DISPATCHER_TABLE, AclConstants.ACL_PORT_SPECIFIC_DROP_PRIORITY, 1, 15, 15);
    FlowAndStatisticsMapList portEgressFlowStats2 = buildFlowStats(NwConstants.INGRESS_ACL_FILTER_CUM_DISPATCHER_TABLE, AclConstants.CT_STATE_TRACKED_INVALID_PRIORITY, 1, 20, 20);
    if (input.getTableId() == null || input.getTableId() == NwConstants.EGRESS_ACL_FILTER_CUM_DISPATCHER_TABLE) {
        flowStatsList.add(portIngressFlowStats1);
        flowStatsList.add(portIngressFlowStats2);
    }
    if (input.getTableId() == null || input.getTableId() == NwConstants.INGRESS_ACL_FILTER_CUM_DISPATCHER_TABLE) {
        flowStatsList.add(portEgressFlowStats1);
        flowStatsList.add(portEgressFlowStats2);
    }
    GetFlowStatisticsOutput output = new GetFlowStatisticsOutputBuilder().setFlowAndStatisticsMapList(flowStatsList).build();
    RpcResultBuilder<GetFlowStatisticsOutput> rpcResultBuilder = RpcResultBuilder.success();
    rpcResultBuilder.withResult(output);
    return Futures.immediateFuture(rpcResultBuilder.build());
}
Also used : ArrayList(java.util.ArrayList) FlowAndStatisticsMapList(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList) GetFlowStatisticsOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsOutput) GetFlowStatisticsOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsOutputBuilder)

Example 8 with GetFlowStatisticsOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsOutput in project netvirt by opendaylight.

the class AclLiveStatisticsHelper method getAclDropStats.

/**
 * Gets the acl drop stats.
 *
 * @param direction the direction
 * @param aclStatsBuilder the acl stats builder
 * @param flowStatsOutput the flow stats output
 */
private static void getAclDropStats(Direction direction, AclPortStatsBuilder aclStatsBuilder, GetFlowStatisticsOutput flowStatsOutput) {
    List<FlowAndStatisticsMapList> flowAndStatisticsMapList = flowStatsOutput.getFlowAndStatisticsMapList();
    if (flowAndStatisticsMapList == null || flowAndStatisticsMapList.isEmpty()) {
        String errMsg = "Unable to retrieve drop counts as interface is not configured for statistics collection.";
        aclStatsBuilder.setError(new ErrorBuilder().setErrorMessage(errMsg).build());
        return;
    }
    BytesBuilder portEgressBytesBuilder = new BytesBuilder();
    BytesBuilder portIngressBytesBuilder = new BytesBuilder();
    PacketsBuilder portEgressPacketsBuilder = new PacketsBuilder();
    PacketsBuilder portIngressPacketsBuilder = new PacketsBuilder();
    for (FlowAndStatisticsMapList flowStats : flowAndStatisticsMapList) {
        BigInteger portEgressBytesBuilderDropCount = BigInteger.valueOf(0);
        BigInteger portEgressPacketsBuilderDropCount = BigInteger.valueOf(0);
        BigInteger portIngressBytesBuilderDropCount = BigInteger.valueOf(0);
        BigInteger portIngressPacketsBuilderDropCount = BigInteger.valueOf(0);
        switch(flowStats.getTableId()) {
            case NwConstants.INGRESS_ACL_FILTER_CUM_DISPATCHER_TABLE:
                if (flowStats.getPriority().equals(AclConstants.CT_STATE_TRACKED_INVALID_PRIORITY)) {
                    portEgressBytesBuilder.setInvalidDropCount(flowStats.getByteCount().getValue());
                    portEgressPacketsBuilder.setInvalidDropCount(flowStats.getPacketCount().getValue());
                } else if (flowStats.getPriority().equals(AclConstants.ACL_PORT_SPECIFIC_DROP_PRIORITY)) {
                    if (portEgressBytesBuilder.getDropCount() != null) {
                        portEgressBytesBuilderDropCount = portEgressBytesBuilder.getDropCount().add(flowStats.getByteCount().getValue());
                        portEgressPacketsBuilderDropCount = portEgressPacketsBuilder.getDropCount().add(flowStats.getPacketCount().getValue());
                    } else {
                        portEgressBytesBuilderDropCount = flowStats.getByteCount().getValue();
                        portEgressPacketsBuilderDropCount = flowStats.getPacketCount().getValue();
                    }
                } else if (flowStats.getPriority().equals(AclConstants.ACE_LAST_REMOTE_ACL_PRIORITY)) {
                    if (portEgressBytesBuilder.getDropCount() != null) {
                        portEgressBytesBuilderDropCount = portEgressBytesBuilder.getDropCount().add(flowStats.getByteCount().getValue());
                        portEgressPacketsBuilderDropCount = portEgressPacketsBuilder.getDropCount().add(flowStats.getPacketCount().getValue());
                    } else {
                        portEgressBytesBuilderDropCount = flowStats.getByteCount().getValue();
                        portEgressPacketsBuilderDropCount = flowStats.getPacketCount().getValue();
                    }
                }
                // TODO: Update stats for other drops
                break;
            case NwConstants.EGRESS_ACL_FILTER_CUM_DISPATCHER_TABLE:
                if (flowStats.getPriority().equals(AclConstants.CT_STATE_TRACKED_INVALID_PRIORITY)) {
                    portIngressBytesBuilder.setInvalidDropCount(flowStats.getByteCount().getValue());
                    portIngressPacketsBuilder.setInvalidDropCount(flowStats.getPacketCount().getValue());
                } else if (flowStats.getPriority().equals(AclConstants.ACL_PORT_SPECIFIC_DROP_PRIORITY)) {
                    if (portIngressBytesBuilder.getDropCount() != null) {
                        portIngressBytesBuilderDropCount = portIngressBytesBuilder.getDropCount().add(flowStats.getByteCount().getValue());
                        portIngressPacketsBuilderDropCount = portIngressPacketsBuilder.getDropCount().add(flowStats.getPacketCount().getValue());
                    } else {
                        portIngressBytesBuilderDropCount = flowStats.getByteCount().getValue();
                        portIngressPacketsBuilderDropCount = flowStats.getPacketCount().getValue();
                    }
                } else if (flowStats.getPriority().equals(AclConstants.ACE_LAST_REMOTE_ACL_PRIORITY)) {
                    if (portIngressBytesBuilder.getDropCount() != null) {
                        portIngressBytesBuilderDropCount = portIngressBytesBuilder.getDropCount().add(flowStats.getByteCount().getValue());
                        portIngressPacketsBuilderDropCount = portIngressPacketsBuilder.getDropCount().add(flowStats.getPacketCount().getValue());
                    } else {
                        portIngressBytesBuilderDropCount = flowStats.getByteCount().getValue();
                        portIngressPacketsBuilderDropCount = flowStats.getPacketCount().getValue();
                    }
                }
                // TODO: Update stats for other drops
                break;
            default:
                LOG.warn("Invalid table ID filtered for Acl flow stats: {}", flowStats);
                break;
        }
        portEgressBytesBuilder.setDropCount(portEgressBytesBuilderDropCount);
        portEgressPacketsBuilder.setDropCount(portEgressPacketsBuilderDropCount);
        portIngressBytesBuilder.setDropCount(portIngressBytesBuilderDropCount);
        portIngressPacketsBuilder.setDropCount(portIngressPacketsBuilderDropCount);
    }
    List<AclDropStats> lstAclDropStats = new ArrayList<>();
    if (direction == Direction.Egress || direction == Direction.Both) {
        AclDropStats aclEgressDropStats = new AclDropStatsBuilder().setDirection(Direction.Egress).setBytes(portEgressBytesBuilder.build()).setPackets(portEgressPacketsBuilder.build()).build();
        lstAclDropStats.add(aclEgressDropStats);
    }
    if (direction == Direction.Ingress || direction == Direction.Both) {
        AclDropStats aclIngressDropStats = new AclDropStatsBuilder().setDirection(Direction.Ingress).setBytes(portIngressBytesBuilder.build()).setPackets(portIngressPacketsBuilder.build()).build();
        lstAclDropStats.add(aclIngressDropStats);
    }
    aclStatsBuilder.setAclDropStats(lstAclDropStats);
}
Also used : AclDropStats(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.acl.stats.output.acl.port.stats.AclDropStats) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) FlowAndStatisticsMapList(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList) PacketsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.acl.stats.output.acl.port.stats.acl.drop.stats.PacketsBuilder) AclDropStatsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.acl.stats.output.acl.port.stats.AclDropStatsBuilder) ErrorBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.acl.stats.output.acl.port.stats.ErrorBuilder) BytesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.acl.stats.output.acl.port.stats.acl.drop.stats.BytesBuilder)

Example 9 with GetFlowStatisticsOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsOutput in project openflowplugin by opendaylight.

the class FlowDirectStatisticsServiceTest method testStoreStatistics.

@Override
public void testStoreStatistics() throws Exception {
    final FlowAndStatisticsMapList stat = mock(FlowAndStatisticsMapList.class);
    when(stat.getTableId()).thenReturn(TABLE_NO);
    when(stat.getMatch()).thenReturn(new MatchBuilder().build());
    final List<FlowAndStatisticsMapList> stats = Collections.singletonList(stat);
    final GetFlowStatisticsOutput output = mock(GetFlowStatisticsOutput.class);
    when(output.getFlowAndStatisticsMapList()).thenReturn(stats);
    multipartWriterProvider.lookup(MultipartType.OFPMPFLOW).get().write(output, true);
    verify(deviceContext).writeToTransactionWithParentsSlow(eq(LogicalDatastoreType.OPERATIONAL), any(), any());
}
Also used : FlowAndStatisticsMapList(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList) GetFlowStatisticsOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsOutput) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder)

Example 10 with GetFlowStatisticsOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsOutput in project openflowplugin by opendaylight.

the class FlowDirectStatisticsServiceTest method testStoreStatistics.

@Override
public void testStoreStatistics() throws Exception {
    final FlowAndStatisticsMapList stat = mock(FlowAndStatisticsMapList.class);
    when(stat.getTableId()).thenReturn(TABLE_NO);
    when(stat.getMatch()).thenReturn(new MatchBuilder().build());
    final List<FlowAndStatisticsMapList> stats = Collections.singletonList(stat);
    final GetFlowStatisticsOutput output = mock(GetFlowStatisticsOutput.class);
    when(output.getFlowAndStatisticsMapList()).thenReturn(stats);
    multipartWriterProvider.lookup(MultipartType.OFPMPFLOW).get().write(output, true);
    verify(deviceContext).writeToTransactionWithParentsSlow(eq(LogicalDatastoreType.OPERATIONAL), any(), any());
}
Also used : FlowAndStatisticsMapList(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList) GetFlowStatisticsOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsOutput) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder)

Aggregations

GetFlowStatisticsOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsOutput)9 FlowAndStatisticsMapList (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList)8 ArrayList (java.util.ArrayList)4 MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder)4 BigInteger (java.math.BigInteger)3 GetFlowStatisticsInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsInputBuilder)3 NodeRef (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef)3 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)3 List (java.util.List)2 ExecutionException (java.util.concurrent.ExecutionException)2 GetFlowStatisticsOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsOutputBuilder)2 FlowAndStatisticsMap (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowAndStatisticsMap)2 NodeId (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId)2 Nodes (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes)2 NodeKey (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey)2 Optional (com.google.common.base.Optional)1 FutureCallback (com.google.common.util.concurrent.FutureCallback)1 Futures (com.google.common.util.concurrent.Futures)1 JdkFutureAdapters (com.google.common.util.concurrent.JdkFutureAdapters)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1