• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..24-Aug-2021-

README.afpacket.mdH A D24-Aug-20213.9 KiB10877

daq_afpacket.cH A D24-Aug-202151 KiB1,5471,198

libdaq_static_afpacket.pc.inH A D24-Aug-2021335 1613

README.afpacket.md

1AFPacket Module
2===============
3
4A DAQ module built on top of the Linux memory-mapped packet socket interface
5(AF_PACKET).  This interface provides direct access to copies of raw packets
6received on Linux network devices in an adjuct ring buffer.  It supports both
7passive and inline modes.
8
9If you want to run AFPacket in inline mode, you must craft the device string as
10one or more interface pairs, where each member of a pair is separated by a
11single colon and each pair is separated by a double colon like this:
12
13    eth0:eth1
14
15or this:
16
17    eth0:eth1::eth2:eth3
18
19Passive mode can listen on multiple interfaces simultaneously with a similarly
20crafted input specification consisting of colon-separated interface names like
21this:
22
23    eth0:eth1:eth2:eth3
24
25The AFPacket DAQ module will always run the interfaces in promiscuous mode.
26
27Requirements
28------------
29* Linux kernel version 3.14 or higher
30* libpcap is optional (required for BPF support)
31
32Interface Preparation
33---------------------
34Before trying to use any interfaces with AFPacket, they must first be brought
35UP via something like ifconfig (ifconfig eth0 up) or ip (ip link set eth0 up).
36
37Additionally, it is a good idea disable receive-side offloading that results
38in frames larger than the configured snaplen.  Not doing so will result in the
39application seeing truncated packet data.  This is especially bad when operating
40in inline mode as it will then forward only the truncated portion of the packet
41that is available to it.  To disable LRO (Large Receive Offload) and GRO
42(Generic Receive Offload), use ethtool like this:
43
44    ethtool -K eth0 lro off gro off
45
46Ring Buffer Memory
47------------------
48By default, the afpacket DAQ allocates 128MB for packet memory divided evenly
49across all participating interfaces.  You can change this with the
50'buffer_size_mb' variable.
51
52Note that the total allocated is actually higher, here's why.  Assuming the
53default packet memory with a snaplen of 1518, the numbers break down like this:
54
55* The frame size is 1518 (snaplen) + the size of the AFPacket header (66 bytes)
56  = 1584 bytes.
57
58* The number of frames is 128 MB / 1518 = 84733.
59
60* The smallest block size that can fit at least one frame is  4 KB = 4096 bytes
61  @ 2 frames per block.
62
63* As a result, we need 84733 / 2 = 42366 blocks.
64
65* Actual memory allocated is 42366 * 4 KB = 165.5 MB.
66
67BPF Support
68-----------
69The AFPacket DAQ module will implement BPF filtering if the LibPCAP development
70headers and libraries are available at build time.  This results in a library
71dependency on libpcap at runtime for the AFPacket DAQ module.
72
73TX Ring Support
74---------------
75AFPacket TX ring support is currently implemented but disabled by default due to
76suboptimal performance results in testing.  There are plans to try to address
77this in future releases.  If you want to forcibly enable using the TX ring, you
78can override the default with the 'use_tx_ring' variable.
79
80NOTE: When TX rings are in use, the RX buffer memory given to each interface is
81halved to accomodate the TX ring buffer memory.
82
83Fanout (Kernel Loadbalancing)
84-----------------------------
85More recent Linux kernel versions (3.1+) support various kernel-space
86loadbalancing methods within AFPacket configured using the PACKET_FANOUT ioctl.
87This allows you to have multiple AFPacket DAQ module instances processing
88packets from the same interfaces in parallel for significantly improved
89throughput.
90
91To configure PACKET_FANOUT in the AFPacket DAQ module, two DAQ variables are
92used:
93
94    fanout_type=<hash|lb|cpu|rollover|rnd|qm>
95
96and (optionally):
97
98    fanout_flag=<rollover|defrag>
99
100In general, you're going to want to use the 'hash' fanout type, but the others
101have been included for completeness.  The 'defrag' fanout flag is probably a
102good idea to correctly handle loadbalancing of flows containing fragmented
103packets.
104
105Please read the man page for 'packet' or packet_mmap.txt in the Linux kernel
106source for more details on the different fanout types and modifier flags.
107
108