stream_statistics.h Source File

Reference Documentation

Platform
Intel® PAC
Napatech SmartNIC
Content Type
Reference Information
Capture Software Version
Link™ Capture Software 12.10
Napatech Software Suite: include/ntapi/stream_statistics.h Source File
stream_statistics.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (C) 2023 Napatech A/S.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Napatech A/S nor the
14  * names of its contributors may be used to endorse or promote products
15  * derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL NAPATECH A/S BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  *
29 
30  */
31 
32 /**
33  * @file
34  *
35  * This is the header file of the statistics stream interface
36  */
37 #ifndef __STREAM_STATISTICS_H__
38 #define __STREAM_STATISTICS_H__
39 
40 #if !defined(__NT_H__)
41  #error: My interface file is 'nt.h'. Please include that via #include "nt.h" directly.
42 #endif
43 
44 /** @addtogroup StatStream
45  * @{
46  *
47  * The statistics stream is used to access statistics from the
48  * system. The statistics stream is read only.
49  *
50  * Statistical information is retrieved using the @ref
51  * NtStatisticsCmd_e::NT_STATISTICS_READ_CMD_QUERY_V3
52  * "NT_STATISTICS_READ_CMD_QUERY_V3" command in a call to @ref NT_StatRead
53  * on an open statistics stream. This command will fill out the
54  * supplied @ref NtStatistics_t structure with port and color based
55  * statistics for all adapters in the system. The @ref
56  * NtPortStatistics_v1_s::NtPortStatisticsValid_v1_s "NtPortStatisticsValid_v1_s" structure can
57  * be used to check which returned part of the @ref NtPortStatistics_v1_s
58  * structure is valid. This is useful since not all adapters support
59  * all types of statistical information.
60  *
61  * @par
62  * @note
63  * Be aware that statistics from multiple adapters are only
64  * synchronized if the time is synchronized.
65  *
66  * For an example on how to use the statistics stream see @ref
67  * stat/stat_example.c "stat/stat_example.c".
68  *
69  * @section ColorStatistics Color Statistics
70  * The color statistics for each color are found by counting the number of
71  * packets getting that specific color.\n
72  * The colors are specified in some assign commands using either the 'Color' or
73  * 'ColorMask' options. By default all packets will get color 0. It is totally
74  * up to the application what meaning that should be put into a given color.
75  * The color statistics work probably best with the prioritized 'Color' option
76  * where the packet gets its color from one unique source. If you use the 'ColorMask'
77  * option, you can easily have a situation where one packet increments more than
78  * one color counter.
79  *
80  * Color counters are never reset. It is the responsibility of the application to
81  * handle this.
82  *
83  * It can be achieved by remembering the counter values for a given color
84  * when it was first configured and then subsequently only showing the
85  * delta compared to this initial value.
86  * Another option is to set the clear flag in @ref NtStatisticsQuery_v2_s::clear
87  * on the first call to @ref NT_StatRead. This will make the subsequent calls
88  * to @ref NT_StatRead return only the delta compared to the first call.
89  *
90  * Be aware that setting this clear flag will clear all statistics counters.
91  * If this is not desirable the application will have to handle it by itself.
92  *
93  * @par
94  * @note
95  * The color statistics only supports counters for colors 0-63 which could give rise
96  * to confusion as you can use 32 bits in the 'ColorMask' option. Only the lower 6 bits
97  * in the color field are considered when updating the color counters.
98  *
99  * @par
100  * @note
101  * Color statistics are only updated by packets that are assigned to a stream (including
102  * StreamId=drop). Packets that are not matched by any NTPL filter, or are matched by a
103  * filter that does not assign a StreamId (or inherit a StreamId from a previous filter),
104  * will not contribute to color statistics.
105  *
106  * @par
107  * @note The statistic stream is not thread-safe. If the same stream handle is to be used by multiple threads,
108  * it must be mutex protected in the application.
109  *
110  */
111 #include "ntapi/commontypes.h"
112 
113 /**
114  * Possible statistics read commands
115  */
117  NT_STATISTICS_READ_CMD_UNKNOWN=0, //!< Unknown read command
118  NT_STATISTICS_READ_CMD_COMPAT_0, //!< Command for backward compatibility - defined in stream_statistics_compat.h
119  NT_STATISTICS_READ_CMD_COMPAT_1, //!< Command for backward compatibility - defined in stream_statistics_compat.h
120  NT_STATISTICS_READ_CMD_COMPAT_2, //!< Command for backward compatibility - defined in stream_statistics_compat.h
121  NT_STATISTICS_READ_CMD_QUERY_V3, //!< Reads all the statistical information version 3
122  NT_STATISTICS_READ_CMD_USAGE_DATA_V0, //!< Reads hostbuffer, streamid and SDRAM usage data
123  NT_STATISTICS_READ_CMD_FLOW_V0, //!< Reads flow matcher statistics
124  NT_STATISTICS_READ_CMD_FLOW_V1, //!< Reads flow matcher statistics
125 };
126 
127 /**
128  * RMON1 counters as defined in RFC 2819
129  */
131  uint64_t dropEvents; //!< Number of events where packet(s) are dropped by the MAC because they are too small or the MAC has bandwidth issues
132  uint64_t octets; //!< Number of octets received by the port (good and bad)
133  uint64_t pkts; //!< Number of packets received by the port (good and bad)
134  uint64_t broadcastPkts; //!< Number of broadcast packets including MAC control packets
135  uint64_t multicastPkts; //!< Number of multicast packets including MAC pause and MAC control packets
136  uint64_t crcAlignErrors; //!< Number of packets with CRC/Align errors
137  uint64_t undersizePkts; //!< Number of packets < 64 octets.\n<b>Note:</b> 100G products with Xilinx FPGA drop packets smaller than 64 bytes. Packets < 64 octets are instead counted as dropEvents. The counter undersizePkts is always 0 on these products.\n <b>Note:</b> When packets with a size in the range [17..63] are transmitted on the following 1G adapters: NT4E2-4-PTP, NT4E2-4T-BP, NT4E and NT4E-STD using the segment interface, the packets will silently be padded to a size of 64 bytes, which is the size reported by @ref NtLinkCapabilities_s::minTxPktSize. For this reason they will be registered as 64 octet packets and not as an undersize packets.
138  uint64_t oversizePkts; //!< Number of packets > 1518 octets (and for NT adapters, packets > MAX and packets < 10000) If packets count here they do not count in the packet and octet counters.\n<b>Note:</b> This counter doesn't count in the TX direction for the following products: NT4E CAPTURE, NT4E-STD CAPTURE, NT20E CAPTURE.
139  uint64_t fragments; //!< Number of packets < 64 octets with errors.\n<b>Note:</b> 100G products with Xilinx FPGA drop packets smaller than 64 bytes. Packets < 64 octets are instead counted as dropEvents. The counter fragments is always 0 on these products.\n
140  uint64_t jabbers; //!< Number of packets > MAX with errors - if packets count here they do not count in the packets and octets counters
141  uint64_t collisions; //!< Number of collisions detected
142  uint64_t pkts64Octets; //!< Number of packets = 64 octets
143  uint64_t pkts65to127Octets; //!< Number of packets in the range 65 to 127 octets
144  uint64_t pkts128to255Octets; //!< Number of packets in the range 128 to 255 octets
145  uint64_t pkts256to511Octets; //!< Number of packets in the range 256 to 511 octets
146  uint64_t pkts512to1023Octets; //!< Number of packets in the range 512 to 1023 octets
147  uint64_t pkts1024to1518Octets; //!< Number of packets in the range 1024 to 1518 octets
148 };
149 
150 /**
151  * Extended RMON - these counters are used to categorize packets not handled by RMON1
152  */
154  uint64_t pkts1519to2047Octets; //!< Number of packets in the range 1519 to 2047 octets
155  uint64_t pkts2048to4095Octets; //!< Number of packets in the range 2048 to 4095 octets
156  uint64_t pkts4096to8191Octets; //!< Number of packets in the range 4096 to 8191 octets
157  uint64_t pkts8192toMaxOctets; //!< Number of packets in the range 8192 to MAX octets
158  uint64_t pktsHardSlice; //!< Number of packets in the range 10001 to 16383 octets
159  uint64_t pktsHardSliceJabber; //!< Number of bad packets in the range 10001 to 16383 octets and packets > 16383 octets
160  uint64_t unicastPkts; //!< Number of Unicast packets including MAC control packets
161  // The following counters are also counted as a sum in @ref NtRMON1Counters_s::crcAlignErrors.
162  uint64_t pktsCrc; //!< Number of packets with CRC errors
163  uint64_t pktsAlignment; //!< Number of packets with alignment errors
164  uint64_t pktsCodeViolation; //!< Number of packets with code violation errors
165  uint64_t pktsRetransmit;
166 };
167 
168 /**
169  * Checksum counters - these counters count packets with IP/TCP/UDP errors
170  */
172  uint64_t pktsIpChkSumError; //!< Number of packets with IP checksum errors
173  uint64_t pktsUdpChkSumError; //!< Number of packets with UDP checksum errors
174  uint64_t pktsTcpChkSumError; //!< Number of packets with TCP checksum errors
175 } ;
176 
177 /**
178  * Packet decoding counters - these counters are available on adapters with a packet decoder
179  */
181  uint64_t pktsGiantUndersize; //!< Number of packets > 63 bytes including tags and =< 63 excluding tags
182  uint64_t pktsBabyGiant; //!< Number of packets > MAX including tags and =< MAX excluding tags
183  uint64_t pktsNotIslVlanMpls; //!< Number of packets without ISL, VLAN and MPLS
184  uint64_t pktsIsl; //!< Number of packets with ISL
185  uint64_t pktsVlan; //!< Number of packets with VLAN
186  uint64_t pktsIslVlan; //!< Number of packets with ISL and VLAN
187  uint64_t pktsMpls; //!< Number of packets with MPLS
188  uint64_t pktsIslMpls; //!< Number of packets with ISL and MPLS
189  uint64_t pktsVlanMpls; //!< Number of packets with VLAN and MPLS
190  uint64_t pktsIslVlanMpls; //!< Number of packets with ISL, VLAN and MPLS
191  uint64_t pktsDuplicate; //!< Number of packets marked as duplicates
192 };
193 
194 /**
195  * Extended drop counters - these counters will count the packets
196  * dropped for various reasons
197  */
199  uint64_t pktsMacBandwidth; //!< Number of packets dropped by the MAC because of bandwidth issues and number of packets < 17 octets. This counter is also available in @ref NtRMON1Counters_s::dropEvents.
200 
201  uint64_t pktsOverflow; //!< Number of packets dropped because the port buffer is full
202  uint64_t octetsOverflow; //!< Number of octets dropped because the port buffer is full
203 
204  uint64_t pktsDedup; //!< Number of packets dropped because of deduplication
205  uint64_t octetsDedup; //!< Number of octets dropped because of deduplication
206 
207  uint64_t pktsNoFilter; //!< Number of packets dropped because they do not match a filter
208  uint64_t octetsNoFilter; //!< Number of octets dropped because they do not match a filter
209 
210  uint64_t pktsFilterDrop; //!< Number of packets dropped because they are explicitly dropped
211  uint64_t octetsFilterDrop; //!< Number of octets dropped because they are explicitly dropped
212 };
213 
214 
215 /**
216  * Color counters
217  */
219  uint64_t pkts; //!< Number of packets
220  uint64_t octets; //!< Number of octets
221 //
222 
223 };
224 
225 /**
226  * Statistics info group for color statistics
227  */
229  int supported; //!< Set if color statistics is supported
230 //
231 
232  struct NtColorStatistics_s aColor[64]; //!< The color statistics
233 //
234 
235  uint64_t ts; //!< Color counter sample time stamp. The format of the timestamp is specified by @ref tsType.
236  enum NtTimestampType_e tsType; //!< Time stamp type - For a description of the time stamp type see "DN-0384 3GD Time-Stamping and Time Synchronization User Guide"
237 };
238 
239 /**
240  * Statistics info group for adapter statistics
241  */
243  struct NtStatGroupColor_s color;
244 };
245 
246 /**
247  * Statistics info for IPF (IP Fragment matching table)
248  */
250  uint64_t ipFragTableFirstHit; //!< Counts all IPv4/IPv6 first-fragment hits in FPGA IPF-table
251  uint64_t ipFragTableFirstNoHit; //!< Counts all IPv4/IPv6 first-fragment misses in FPGA IPF-table (first fragment not received)
252  uint64_t ipFragTableMidHit; //!< Counts all IPv4/IPv6 mid-fragment hits in FPGA IPF-table
253  uint64_t ipFragTableMidNoHit; //!< Counts all IPv4/IPv6 mid-fragment misses in FPGA IPF-table (middle fragment not received)
254  uint64_t ipFragTableLastHit; //!< Counts all IPv4/IPv6 last-fragment hits in FPGA IPF-table
255  uint64_t ipFragTableLastNoHit; //!< Counts all IPv4/IPv6 last-fragment misses in FPGA IPF-table (last fragment not received - e.g. before timeout)
256 };
257 
258 /**
259  * Statistics for each port
260  */
262  /**
263  * Valid indicators - these indicate which counters are supported by the port
264  */
266  int RMON1; //!< Is set if RMON1 counters are supported
267  int extRMON; //!< Is set if extended RMON counters are supported
268  int chksum; //!< Is set if IP/TCP/UDP checksum counters are supported
269  int decode; //!< Is set if packet decode counters are supported
270  int extDrop; //!< Is set if extended drop counters are supported
271  int ipf; //!< Is set if IP fragment table counters are supported
272  } valid;
273 
274  struct NtRMON1Counters_s RMON1; //!< RMON1 counters
275  struct NtExtendedRMONCounters_v1_s extRMON; //!< Extended RMON counters
276  struct NtCheckSumCounters_s chksum; //!< Checksum error counters
277  struct NtDecodeCounters_v1_s decode; //!< Packets decoded by onboard packet decoder
278  struct NtExtendedDropCounters_v1_s extDrop; //!< Extended drop counters
279  struct NtIpFragTableCounters_s ipf; //!< IP fragment table counters (when using IPFMode)
280 };
281 
282 /**
283  * Statistics info group for port statistics
284  */
286  struct NtPortStatistics_v2_s rx; //!< Counters based on RX ports
287  struct NtPortStatistics_v2_s tx; //!< Counters based on TX ports
288  uint64_t linkDownCounter; //!< Counts number of link downs
289  uint64_t ts; //!< Port counter sample time stamp. The format of the timestamp is specified by @ref tsType.
290  enum NtTimestampType_e tsType; //!< Time stamp type - For a description of the time stamp type see "DN-0384 3GD Time-Stamping and Time Synchronization User Guide"
291 };
292 
293 /**
294  * Statistics info group for stream statistics
295  */
297  struct {
298  struct NtColorStatistics_s forward; //!< Number of forwarded packets/bytes
299  struct NtColorStatistics_s flush; //!< Number of flushed packets/bytes. Received while the stream-id is inactive
300  struct NtColorStatistics_s drop; //!< Number of dropped packets/bytes
301  } streamid[256]; //!< Statistic for an assigned stream-id.
302  struct {
303  struct NtColorStatistics_s forward; //!< Number of forwarded packets/bytes
304  struct NtColorStatistics_s flush; //!< Number of flushed packets/bytes. Received while the stream-id is inactive
305  struct NtColorStatistics_s drop; //!< Number of dropped packets/bytes
306  } Unassigned; //!< Statistic for traffic received in a host buffer before it has been assigned to a stream-id.
307  uint64_t ts; //!< Stream statistic sample time stamp. The format of the timestamp is specified by the timestamp setting @ref TimestampFormat in the ini-file.
308 };
309 
311  int poll; //!< Gets the current statistical information or waits for a new update
312  int clear; //!< Clears the statistical information after it has been read. All statistics counters for the current stream will be cleared. Other statistics streams will remain untouched.
313  /**
314  * Data section holding the statistic counters
315  */
317  /**
318  * Port specific statistics
319  */
321  uint8_t numPorts; //!< Number of ports in @ref aPorts
322  uint8_t Reserved1[3];
323 //
324 
325  struct NtStatGroupport_v2_s aPorts[64]; //!< Array of port statistic structures in the system
326 //
327 
328  } port;
329  /**
330  * Adapter specific statistics
331  */
333  uint8_t numAdapters; //!< Number of adapters in @ref aAdapters
334  uint8_t Reserved1[3];
335  struct NtStatGroupAdapter_s aAdapters[10]; //!< Array of adapter statistic structures
336  } adapter;
337  /**
338  * Stream specific statistics
339  */
340  struct NtStatGroupStream_s stream;
341  } data; //!< Structure for statistic results
342 };
343 
345  uint8_t streamid; //!< The streamid to get the usage data for.
346 
348  uint32_t numHostBufferUsed; //!< Number of hostbuffers used by this stream ID
350  uint64_t deQueued; //!< Bytes available or in use by the streams
351  uint64_t enQueued; //!< Bytes available to the host buffer handler
352  uint64_t enQueuedAdapter; //!< Bytes currently in the adapter
353  //!
354  uint8_t adapterNo; //!< The adapter owning the host buffer
355  uint8_t numaNode; //!< The numanode on which the hostbuffer is located
356  uint64_t hostBufferSize; //!< The host buffer size.
357  uint32_t numStreams; //!< Number of streams using the host buffers
358 
360  uint64_t used; //!< Onboard adapter buffering
361  uint64_t size; //!< Onboard adapter buffering size
362  uint32_t crcErrors; //!< The number of CRC errors detected in the onboard buffer
363  } onboardBuffering;
364 
365  struct NtStatUsage_s {
367  uint64_t bytes; //!< Bytes received
368  uint64_t frames; //!< Frames received
369  } rx;
371  uint64_t bytes; //!< Bytes dropped
372  uint64_t frames; //!< Frames dropped
373  } drop;
374  uint64_t ts; //!< Time stamp of gathered statistics
375  } stat;
376  } hb[256];
377  } data;
378 };
379 
380 /**
381  * Flow matcher statistics version 0
382  */
384  int clear; //!< Clears the statistical information after it has been read.
385  uint8_t adapterNo; //!< Adapter to receive the flow statistics from
386  uint8_t reserved[3];
387  uint64_t learnDone; //!< Total number of flows programmed
388  uint64_t learnFail; //!< Number of flows that couldn't be programmed
389  uint64_t learnIgnore;
390  uint64_t unlearnDone;
391  uint64_t unlearnIgnore;
396  uint64_t dmaWriteRecords;
401 };
402 
403 /**
404  * Flow matcher statistics version 1
405  */
407  int clear; //!< Clears the statistical information after it has been read.
408  uint8_t adapterNo; //!< Adapter to receive the flow statistics from
409  uint8_t reserved[3];
410  uint64_t learnDone; //!< Total number of flows programmed
411  uint64_t learnFail; //!< Number of flows that couldn't be programmed
412  uint64_t learnIgnore;
413  uint64_t unlearnDone;
414  uint64_t unlearnIgnore;
420  uint64_t dmaWriteRecords;
425 };
426 
427 /* Include commands for backwards compatibility */
428 #if !defined(_NT_NTAPI_NO_COMPAT)
430 #endif
431 
432 /**
433  * Statistics
434  */
435 typedef struct NtStatistics_s {
436  enum NtStatisticsCmd_e cmd; //!< Statistics command
437  /**
438  * Statistics data
439  */
441  struct NtStatisticsQuery_v3_s query_v3; //!< The structure to use for @ref NtStatistics_s::cmd==NT_STATISTICS_READ_CMD_QUERY_V3
442  struct NtStatisticsUsageData_v0_s usageData_v0; //!< The structure to use for @ref NtStatistics_s::cmd==NT_STATISTICS_READ_CMD_USAGE_DATA
443  struct NtStatisticsFlowData_v0_s flowData_v0; //!< The structure to use for @ref NtStatistics_s::cmd==NT_STATISTICS_READ_CMD_FLOW_V0
444  struct NtStatisticsFlowData_v1_s flowData_v1; //!< The structure to use for @ref NtStatistics_s::cmd==NT_STATISTICS_READ_CMD_FLOW_V1
445 #if !defined(_NT_NTAPI_NO_COMPAT)
446  /* Commands for backwards compatibility */
447  struct NtStatisticsQuery_v2_s query_v2; //!< The structure to use for @ref NtStatistics_s::cmd==NT_STATISTICS_READ_CMD_QUERY_V2
448  struct NtStatisticsQuery_v1_s query_v1; //!< The structure to use for @ref NtStatistics_s::cmd==NT_STATISTICS_READ_CMD_QUERY_V1
449  struct NtStatisticsQuery_s query; //!< The structure to use for @ref NtStatistics_s::cmd==NT_STATISTICS_READ_CMD_QUERY
450 #endif
451  }u; //!< Union for statistic structures
453 
454 /**
455  * Statistics stream handle
456  */
457 typedef struct NtStatStream_s* NtStatStream_t;
458 
459 /**
460  * @brief Opens a statistics stream
461  *
462  * This function is called to retrieve a handle to a statistics stream
463  *
464  * @param[out] hStatStream Reference to a NtStatStream_t stream pointer
465  * @param[in] name Stream friendly name - used in, for example, logging statements
466  *
467  * @retval 0 Success
468  * @retval !=0 Error
469  */
470 int NT_StatOpen(NtStatStream_t *hStatStream, const char *name);
471 
472 /**
473  * @brief Reads statistics
474  *
475  * Returns statistical information from the system
476  *
477  * @param[in] hStatStream NtStatStream_t handle
478  * @param[in] stat Return buffer for statistics
479  *
480  * @retval 0 Success
481  * @retval NT_STATUS_TIMEOUT No data has been returned and a timeout has occured
482  * @retval NT_STATUS_TRYAGAIN The resource is temporarily unavailable because of reconfiguration - call NT_StatRead() again
483  * @retval !=0 Error
484  */
485 int NT_StatRead(NtStatStream_t hStatStream, NtStatistics_t *stat);
486 
487 /**
488  * @brief Closes a statistics stream
489  *
490  * This function is called to close a statistics stream
491  *
492  * @param[in] hStatStream Reference to a NtStatStream_t stream pointer
493  *
494  * @retval 0 Success
495  * @retval !=0 Error
496  */
497 int NT_StatClose(NtStatStream_t hStatStream);
498 
499 /** @} */
500 
501 #endif // __STREAM_STATISTICS_H__