1 .\" netsniff-ng - the packet sniffing beast
2 .\" Copyright 2013 Daniel Borkmann.
3 .\" Subject to the GPL, version 2.
5 .TH TRAFGEN 8 "03 March 2013" "Linux" "netsniff-ng toolkit"
7 trafgen \- a fast, multithreaded network packet generator
11 \fB trafgen\fR [\fIoptions\fR]
15 trafgen is a fast, zero-copy network traffic generator for debugging,
16 performance evaluation and fuzz-testing purposes. trafgen utilizes the packet(7)
17 socket interface of Linux which postpones complete control over packet data
18 and packet headers into the user space. It has a powerful packet configuration
19 language, which is rather low-level and not limited to particular protocols.
20 Thus, trafgen can be used for many purposes. Its only limitation is that it
21 cannot mimic full streams resp. sessions. However, it is very useful for
22 various kinds of load testing in order to analyze and subsequently improve
23 systems behaviour under DoS attack scenarios, for instance.
25 trafgen is Linux specific only, meaning there is no support for other operating
26 systems just as in netsniff-ng(8), thus we can keep the code footprint quite
27 minimal and to the point. trafgen makes use of packet(7) socket's TX_RING
28 interface of the Linux kernel, which is a mmap(2)'ed ring buffer shared between
29 user and kernel space.
31 On default, trafgen starts as many processes as CPUs that are online, pins each
32 of them to their respective CPU and sets up the ring buffer each in their own
33 process space after having compiled a list of packets to transmit. Thus, this is
34 likely the fastest one can get out of the box in terms of transmission performance
35 from user space, without having to load unsupported or non-mainline third-party
36 kernel modules. On Gigabit Ethernet, trafgen has a comparable performance to
37 pktgen, the built-in Linux kernel traffic generator, only that trafgen is more
38 flexible in terms of packet configuration possibilities. On 10-Gigabit-per-second
39 Ethernet, trafgen might be slower than pktgen due to the user/kernel space
40 overhead but still has a fairly high performance for out of the box kernels.
42 trafgen has a possibility to do fuzz testing, meaning a packet configuration can
43 be built with random numbers on all or certain packet offsets that are freshly
44 generated each time a packet is sent out. With a built-in IPv4 ping, trafgen can
45 send out an ICMP probe after each packet injection to the remote host in order
46 to test if it is still responsive/alive. Assuming there is no answer from the
47 remote host after a certain threshold of probes, the machine is considered dead
48 and the last sent packet is printed together with the random seed that was used
49 by trafgen. You might not really get lucky fuzz-testing the Linux kernel, but
50 presumably there are buggy closed-source embedded systems or network driver's
51 firmware files that are prone to bugs, where trafgen could help in finding them.
53 trafgen's configuration language is quite powerful, also due to the fact, that
54 it supports C preprocessor macros. A stddef.h is being shipped with trafgen for
55 this purpose, so that well known defines from Linux kernel or network programming
56 can be reused. After a configuration file has passed the C preprocessor stage,
57 it is processed by the trafgen packet compiler. The language itself supports a
58 couple of features that are useful when assembling packets, such as built-in
59 runtime checksum support for IP, UDP and TCP. Also it has an expression evaluator
60 where arithmetic (basic operations, bit operations, bit shifting, ...) on constant
61 expressions is being reduced to a single constant on compile time. Other features
62 are ``fill'' macros, where a packet can be filled with n bytes by a constant, a
63 compile-time random number or run-time random number (as mentioned with fuzz
64 testing). Also, netsniff-ng(8) is able to convert a pcap file into a trafgen
65 configuration file, thus such a configuration can then be further tweaked for a
70 .SS -i <cfg|->, -c <cfg|i>, --in <cfg|->, --conf <cfg|->
71 Defines the input configuration file that can either be passed as a normal plain
72 text file or via stdin (``-''). Note that currently in case a configuration is
73 passed through stdin, only 1 CPU will be used.
75 .SS -o <dev>, -d <dev>, --out <dev>, --dev <dev>
76 Defines the outgoing networking device such as eth0, wlan0 and others.
79 Pass the packet configuration to
81 .SS -J, --jumbo-support
82 On default trafgen's ring buffer frames are of a fixed size of 2048 bytes.
83 This means that if you're expecting jumbo frames or even super jumbo frames to
84 pass your line, then you need to enable support for that with the help of this
85 option. However, this has the disadvantage of a performance regression and a
86 bigger memory footprint for the ring buffer.
89 In case the output networking device is a wireless device, it is possible with
90 trafgen to turn this into monitor mode and create a mon<X> device that trafgen
91 will be transmitting on instead of wlan<X>, for instance. This enables trafgen
92 to inject raw 802.11 frames.
94 .SS -s <ipv4>, --smoke-test <ipv4>
95 In case this option is enabled, trafgen will perform a smoke test. In other
96 words, it will probe the remote end, specified by an <ipv4> address, that is
97 being ``attacked'' with trafgen network traffic, if it is still alive and
98 responsive. That means, after each transmitted packet that has been configured,
99 trafgen sends out ICMP echo requests and waits for an answer before it continues.
100 In case the remote end stays unresponsive, trafgen assumes that the machine
101 has crashed and will print out the content of the last packet as a trafgen
102 packet configuration and the random seed that has been used in order to
103 reproduce a possible bug. This might be useful when testing proprietary embedded
104 devices. It is recommended to have a direct link between the host running
105 trafgen and the host being attacked by trafgen.
107 .SS -n <0|uint>, --num <0|uint>
108 Process a number of packets and then exit. If the number of packets is 0, then
109 this is equivalent to infinite packets resp. processing until interrupted.
110 Otherwise, a number given as an unsigned integer will limit processing.
113 Randomize the packet selection of the configuration file. On default, if more
114 than one packet is defined in a packet configuration, packets are scheduled for
115 transmission in a round robin fashion. With this option, they are selected
118 .SS -P <uint>, --cpus <uint>
119 Specify the number of processes trafgen shall fork(2) off. On default trafgen
120 will start as many processes as CPUs that are online and pin them to each,
121 respectively. Allowed value must be within interval [1,CPUs].
123 .SS -t <uint>, --gap <uint>
124 Specify a static inter-packet timegap in micro-seconds. If this option is given,
125 then instead of packet(7)'s TX_RING interface, trafgen will use sendto(2) I/O
126 for network packets, even if the <uint> argument is 0. This option is useful for
127 a couple of reasons: i) comparison between sendto(2) and TX_RING performance,
128 ii) low-traffic packet probing for a given interval, iii) ping-like debugging
129 with specific payload patterns. Furthermore, the TX_RING interface does not cope
130 with interpacket gaps.
132 .SS -S <size>, --ring-size <size>
133 Manually define the RX_RING resp. TX_RING size in ``<num>KiB/MiB/GiB''. On
134 default the size is being determined based on the network connectivity rate.
136 .SS -k <uint>, --kernel-pull <uint>
137 Manually define the interval in micro-seconds where the kernel should be triggered
138 to batch process the ring buffer frames. On default, it is every 10us, but it can
139 manually be prolonged, for instance..
141 .SS -E <uint>, --seed <uint>
142 Manually set the seed for trafgen. On default, a random seed from /dev/urandom
143 is being used to feed glibc's pseudo random number generator. If that fails, it
144 falls back to the unix timestamp. It can be useful to set it up manually to be
145 able to reproduce a trafgen session, e.g. after fuzz testing.
147 .SS -u <uid>, --user <uid> resp. -g <gid>, --group <gid>
148 After ring setup drop privileges to a non-root user/group combination.
151 Let trafgen be more talkative and let it print the parsed configuration and
152 some ring buffer statistics.
155 Show a built-in packet configuration example. This might be a good starting
156 point for an initial packet configuration scenario.
159 Show versioning information.
174 trafgen can saturate a Gigabit Ethernet link without problems. As always,
175 of course, this depends on your hardware as well. Not everywhere where it
176 says Gigabit Ethernet on the box, you'll reach almost physical line rate!
177 Please also read the netsniff-ng(8) man page, section NOTE for further
178 details about tuning your system e.g. with tuned(8).
180 If you intend to use trafgen on a 10-Gbit/s Ethernet NIC, make sure you
181 are using a multiqueue tc(8) discipline, and make sure that the packets
182 you generate with trafgen will have a good distribution among tx_hashes
183 so that you'll actually make use of multiqueues.
185 For introducing bit errors, delays with random variation and more, there
186 is no built-in option in trafgen. Rather, one should reuse existing methods
187 for that which integrate nicely with trafgen, such as tc(8) with its
188 different disciplines, i.e. netem.
190 For more complex packet configurations, it is recommended to use high-level
191 scripting for generating trafgen packet configurations in a more automated
192 way, i.e. also to create different traffic distributions that are common for
193 industrial benchmarking:
195 Traffic model Distribution
197 IMIX 64:7, 570:4, 1518:1
198 Tolly 64:55, 78:5, 576:17, 1518:23
199 Cisco 64:7, 594:4, 1518:1
200 RPR Trimodal 64:60, 512:20, 1518:20
201 RPR Quadrimodal 64:50, 512:15, 1518:15, 9218:20
203 The low-level nature of trafgen makes trafgen rather protocol independant
204 and therefore useful in many scenarios when stress testing is needed, for
205 instance. However, if a traffic generator with higher level packet
206 descriptions is desired, netsniff-ng's mausezahn(8) can be of good use as
209 For smoke/fuzz testing with trafgen, it is recommended to have a direct
210 link between the host you want to analyze (``victim'' machine) and the host
211 you run trafgen on (``attacker'' machine). If the ICMP reply from the victim
212 fails, we assume that probably its kernel crashed, thus we print the last
213 sent packet togther with the seed and quit probing. It might be very unlikely
214 to find such a ping-of-death on modern Linux systems. However, there might
215 be a good chance to find it on some proprietary (e.g. embedded) systems or
216 buggy driver firmwares that are in the wild. Also, fuzz testing can be done
217 on raw 802.11 frames, of course. In case you find a ping-of-death, please
218 mention that you were using trafgen in your commit message of the fix!
221 When I start trafgen, my kernel crashes: we have fixed this bug in the
222 mainline and stable kernels under commit 7f5c3e3a8 (``af_packet: remove
223 BUG statement in tpacket_destruct_skb''). Either update your kernel to
224 the latest version, e.g. clone and build it from git.kernel.org, to a
225 stable kernel, or don't start multiple trafgen instances at once resp.
226 start trafgen with flag -A to disable temporary socket memory adaptation!
229 trafgen is licensed under the GNU GPL version 2.0.
233 was originally written for the netsniff-ng toolkit by Daniel Borkmann. It
234 is currently maintained by Tobias Klauser <tklauser@distanz.ch> and Daniel
235 Borkmann <dborkma@tik.ee.ethz.ch>.
243 .BR astraceroute (8),
247 Manpage was written by Daniel Borkmann.