Count Total number of Packets

Prev Next

One of the most basic tests is to count the total number of packets recorded in a capture. This can be done with or without BPF and Frame filters depending on the goal.

Using

fmadiocli "show capture list"

Find the full name of the capture for counting, we will use <full_capture_name> in the example below for this step


Basic Total Captured

Most basic is raw packet count

sudo stream_cat <full_capture_name> | capinfos2 -v

Example output is shown below

bfmadio@fmadio200v4-636:~$ sudo stream_cat wan0_20250501_1633  | capinfos2 -v
calibrating...
stream_cat ioqueue: 4
calibrating...
StartChunkID: 52289272
StartChunk: 52289272 Offset: 0 Stride: 1
StartChunk: 52289272
PCAP nano
0.00GB    0.000 Gbps    0.000 Mpps SeqError:0
1.83GB   14.635 Gbps    2.789 Mpps SeqError:0
packet stream end
20250506_183941 2.287s : Pkt:3334842 Byte:2187656352 SUCCESS
Total Packets: 3334842
TotalBytes     : 2134298880
TotalPackets   : 3334842
PayloadCRC     : 7946e8f8cd4c299
ErrorSeq       : 0
ErrorPktSize   : 0
LastByte       : 0x00000000
SeqStart       : 0x00000000 0x00000000 0x00000000 0x00000000 : 0x00000000
SeqEnd         : 0x00000000 0x00000000 0x00000000 0x00000000 : 0x00000000
PacketCnt      : 0 0 0 0
TimeOrder      : 0
CRCFail        : 0
CRCFailFNIC    : 0
Time First     : 20250501_163404 08:34:04.267.612.373 (1746088444.267612373)
Time Last      : 20250501_163934 08:39:34.448.225.332 (1746088774.448225332)
TotalPCAPTime  : 330180612959 ns (5.503min)
Bandwidth      : 0.052 Gbps
Packet Rate    : 0.010 Mpps

Complete
fmadio@fmadio200v4-636:~$

In this example there are total of 3334842 packets


Basic Total Capture in JSON

The same example using JSON formatting

Command is shown below

sudo stream_cat <full_capture_name> | capinfos2 -v --json | grep IsJSON | jq

Example output shown below

fmadio@fmadio200v4-636:~$ sudo stream_cat wan0_20250501_1633  | capinfos2 -v --json | grep IsJSON | jq
calibrating...
stream_cat ioqueue: 4
calibrating...
0 : 2749994583           2.7500 cycles/nsec offset:0.005 Mhz
Cycles/Sec 2749994583.0000 Std:       0 cycle std(  0.00000000) Target:2.75 Ghz
0 : 2749992300           2.7500 cycles/nsec offset:0.008 Mhz
Cycles/Sec 2749992300.0000 Std:       0 cycle std(  0.00000000) Target:2.75 Ghz
StartChunkID: 52289272
StartChunk: 52289272 Offset: 0 Stride: 1
StartChunk: 52289272
packet stream end
20250506_184108 2.276s : Pkt:3334842 Byte:2187656352 SUCCESS
{
  "IsJSON": true,
  "TotalByteCapture": 2187656352,
  "TotalByteWire": 2134298880,
  "TotalPacket": 3334842,
  "TimeStartStr": "20250501_163404",
  "TimeStart": 1746088444267612373,
  "TimeEndStr": "20250501_163934",
  "TimeEnd": 1746088774448225332,
  "TimeDurationNS": 330180612959,
  "BandwidthGbps": 0.051712,
  "PacketrateMpps": 0.010100,
  "SeqCheckError": 0,
  "SeqStart0": 0,
  "SeqStart1": 0,
  "SeqStart2": 0,
  "SeqStart3": 0,
  "SeqEnd0": 0,
  "SeqEnd1": 0,
  "SeqEnd2": 0,
  "SeqEnd3": 0
}
fmadio@fmadio200v4-636:~$

BPF Filtered Number of Packets

Using a BPF Filter to select specific packets and count them.

In the below example we want only TCP packets

sudo stream_cat <full_capture_name> --bpf "tcp" | capinfos2 -v

Example output shown below

fmadio@fmadio20v3-2U-364:~$ sudo stream_cat wan_20250506_1100 --bpf "tcp" | capinfos2 -v
calibrating...
BPF Filter [tcp] slen: 3 alen: 3
stream_cat ioqueue: 6
StartChunkID: 133883688
StartChunk: 133883688 Offset: 0 Stride: 1
StartChunk: 133883688
PCAP nano
0.00GB    0.000 Gbps    0.000 Mpps SeqError:0
1.18GB    9.450 Gbps    1.134 Mpps SeqError:0
2.57GB   11.065 Gbps    0.954 Mpps SeqError:0
3.50GB    7.494 Gbps    1.332 Mpps SeqError:0
4.26GB    6.066 Gbps    1.396 Mpps SeqError:0
5.02GB    6.043 Gbps    1.392 Mpps SeqError:0
5.77GB    6.025 Gbps    1.388 Mpps SeqError:0
6.53GB    6.044 Gbps    1.393 Mpps SeqError:0
packet stream end
20250506_184508 8.461s : Pkt:9595572 Byte:6850838524 SUCCESS
Total Packets: 9595572
TotalBytes     : 6697309372
TotalPackets   : 9595572
PayloadCRC     : 3040931de00fb314
ErrorSeq       : 0
ErrorPktSize   : 0
LastByte       : 0x00000000
SeqStart       : 0x00000000 0x00000000 0x00000000 0x00000000 : 0x00000000
SeqEnd         : 0x00000000 0x00000000 0x00000000 0x00000000 : 0x00000000
PacketCnt      : 0 0 0 0
TimeOrder      : 0
CRCFail        : 0
CRCFailFNIC    : 0
Time First     : 20250506_105959 02:59:59.943.698.539 (1746500399.943698539)
Time Last      : 20250506_115959 03:59:59.986.220.762 (1746503999.986220762)
TotalPCAPTime  : 3600042522223 ns (60.001min)
Bandwidth      : 0.015 Gbps
Packet Rate    : 0.003 Mpps

Complete
fmadio@fmadio20v3-2U-364:~$

In this example total number of packets is 9595572


Capture Port number of Packets

Using FrameFilters calculating the number of packets per physical capture port is useful operation

Command to count on caputre port 0 (cap0

sudo stream_cat <full_capture_name> --frame "capture.port==1" | capinfos2 -v

Example output shown below. Total number of packets on cap1 is 13620333

fmadio@fmadio20v3-2U-364:~$ sudo stream_cat wan_20250506_1100 --frame "capture.port==1" | capinfos2 -v
calibrating...
Frame Filter [capture.port==1]
stream_cat ioqueue: 6
capture port     [1] invert:0
   capture port enable:1 [1]
fmadio capture port map: [1]
fmadio a7130   port map: []
fmadio c3550   port map: []
StartChunkID: 133883688
StartChunk: 133883688 Offset: 0 Stride: 1
StartChunk: 133883688
PCAP nano
0.00GB    0.000 Gbps    0.000 Mpps SeqError:0
1.25GB    9.989 Gbps    1.453 Mpps SeqError:0
2.74GB   11.910 Gbps    1.091 Mpps SeqError:0
3.65GB    7.270 Gbps    2.099 Mpps SeqError:0
4.50GB    6.830 Gbps    2.131 Mpps SeqError:0
5.36GB    6.847 Gbps    2.156 Mpps SeqError:0
6.24GB    7.012 Gbps    2.189 Mpps SeqError:0
7.11GB    6.946 Gbps    2.170 Mpps SeqError:0
packet stream end
20250506_184750 8.185s : Pkt:13620333 Byte:7230944572 SUCCESS
Total Packets: 13620333
TotalBytes     : 7013019244
TotalPackets   : 13620333
PayloadCRC     : 3165b3a72bbfa7c8
ErrorSeq       : 0
ErrorPktSize   : 0
LastByte       : 0x00000000
SeqStart       : 0x00000000 0x00000000 0x00000000 0x00000000 : 0x00000000
SeqEnd         : 0x00000000 0x00000000 0x00000000 0x00000000 : 0x00000000
PacketCnt      : 0 0 0 0
TimeOrder      : 0
CRCFail        : 0
CRCFailFNIC    : 0
Time First     : 20250506_105959 02:59:59.943.692.382 (1746500399.943692382)
Time Last      : 20250506_115959 03:59:59.986.229.940 (1746503999.986229940)
TotalPCAPTime  : 3600042537558 ns (60.001min)
Bandwidth      : 0.016 Gbps
Packet Rate    : 0.004 Mpps

Complete
fmadio@fmadio20v3-2U-364:~$