API: Handle Statistics Record

Stateful Flow Management

product_line_custom
Napatech SmartNIC
category
User Guide

Use this example to handle a statistics record.

To access general information on flows, the statistics stream can be used. The API to the statistics stream has not been changed for the flow manager, but command NT_STATISTICS_READ_CMD_FLOW_V0 has been added. The returned data from NT_StatRead is SmartNIC-specific, so before the function is called, the SmartNIC number must be specified.

The snippet below shows how to open a statistics stream, extract flow manager information, and includes an example on how to display the information.

Example:
uint8_t        adapterNo = 0;
  NtStatistics_t hStat;
  NtStatStream_t hStatStream;

  // Open the stat stream.
  status = NT_StatOpen(&hStatStream, "Read_flowstats_example");
  if(status != NT_SUCCESS) { /* Handle error */ }

  // Read the statistics counters
  hStat.cmd = NT_STATISTICS_READ_CMD_FLOW_V0;
  hStat.u.flowData_v0.clear = 0;  // Don't clear statistics
  hStat.u.flowData_v0.adapterNo = adapterNo;
  status = NT_StatRead(hStatStream, &hStat);
  if(status != NT_SUCCESS) { /* Handle error */ }

  std::cout << "Statistic from stat stream:" << std::endl
    << "  Learn:" << std::endl
    << "    Done:      " << hStat.u.flowData_v0.learnDone << std::endl
    << "    Ignore:    " << hStat.u.flowData_v0.learnIgnore << std::endl
    << "    Fail:      " << hStat.u.flowData_v0.learnFail << std::endl
    << "  Unlearn:" << std::endl
    << "    Done:      " << hStat.u.flowData_v0.unlearnDone << std::endl
    << "    Ignore:    " << hStat.u.flowData_v0.unlearnIgnore << std::endl
    << "  Automatic Unlearn:" << std::endl
    << "    Done:      " << hStat.u.flowData_v0.automaticUnlearnDone << std::endl
    << "    Ignore:    " << hStat.u.flowData_v0.automaticUnlearnIgnore << std::endl
    << "    Fail:      " << hStat.u.flowData_v0.automaticUnlearnFail << std::endl
    << "  Timeout Unlearn:" << std::endl
    << "    Done:      " << hStat.u.flowData_v0.timeoutUnlearnDone << std::endl
    << "  DMA:" << std::endl
    << "    Write:     " << hStat.u.flowData_v0.dmaWriteRecords << std::endl
    << "    Info Read: " << hStat.u.flowData_v0.dmaReadInfoRecords << std::endl
    << "    Stat Read: " << hStat.u.flowData_v0.dmaReadStatRecords << std::endl;