pktgen.rst 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. .. SPDX-License-Identifier: GPL-2.0
  2. ====================================
  3. HOWTO for the linux packet generator
  4. ====================================
  5. Enable CONFIG_NET_PKTGEN to compile and build pktgen either in-kernel
  6. or as a module. A module is preferred; modprobe pktgen if needed. Once
  7. running, pktgen creates a thread for each CPU with affinity to that CPU.
  8. Monitoring and controlling is done via /proc. It is easiest to select a
  9. suitable sample script and configure that.
  10. On a dual CPU::
  11. ps aux | grep pkt
  12. root 129 0.3 0.0 0 0 ? SW 2003 523:20 [kpktgend_0]
  13. root 130 0.3 0.0 0 0 ? SW 2003 509:50 [kpktgend_1]
  14. For monitoring and control pktgen creates::
  15. /proc/net/pktgen/pgctrl
  16. /proc/net/pktgen/kpktgend_X
  17. /proc/net/pktgen/ethX
  18. Tuning NIC for max performance
  19. ==============================
  20. The default NIC settings are (likely) not tuned for pktgen's artificial
  21. overload type of benchmarking, as this could hurt the normal use-case.
  22. Specifically increasing the TX ring buffer in the NIC::
  23. # ethtool -G ethX tx 1024
  24. A larger TX ring can improve pktgen's performance, while it can hurt
  25. in the general case, 1) because the TX ring buffer might get larger
  26. than the CPU's L1/L2 cache, 2) because it allows more queueing in the
  27. NIC HW layer (which is bad for bufferbloat).
  28. One should hesitate to conclude that packets/descriptors in the HW
  29. TX ring cause delay. Drivers usually delay cleaning up the
  30. ring-buffers for various performance reasons, and packets stalling
  31. the TX ring might just be waiting for cleanup.
  32. This cleanup issue is specifically the case for the driver ixgbe
  33. (Intel 82599 chip). This driver (ixgbe) combines TX+RX ring cleanups,
  34. and the cleanup interval is affected by the ethtool --coalesce setting
  35. of parameter "rx-usecs".
  36. For ixgbe use e.g. "30" resulting in approx 33K interrupts/sec (1/30*10^6)::
  37. # ethtool -C ethX rx-usecs 30
  38. Kernel threads
  39. ==============
  40. Pktgen creates a thread for each CPU with affinity to that CPU.
  41. Which is controlled through procfile /proc/net/pktgen/kpktgend_X.
  42. Example: /proc/net/pktgen/kpktgend_0::
  43. Running:
  44. Stopped: eth4@0
  45. Result: OK: add_device=eth4@0
  46. Most important are the devices assigned to the thread.
  47. The two basic thread commands are:
  48. * add_device DEVICE@NAME -- adds a single device
  49. * rem_device_all -- remove all associated devices
  50. When adding a device to a thread, a corresponding procfile is created
  51. which is used for configuring this device. Thus, device names need to
  52. be unique.
  53. To support adding the same device to multiple threads, which is useful
  54. with multi queue NICs, the device naming scheme is extended with "@":
  55. device@something
  56. The part after "@" can be anything, but it is custom to use the thread
  57. number.
  58. Viewing devices
  59. ===============
  60. The Params section holds configured information. The Current section
  61. holds running statistics. The Result is printed after a run or after
  62. interruption. Example::
  63. /proc/net/pktgen/eth4@0
  64. Params: count 100000 min_pkt_size: 60 max_pkt_size: 60
  65. frags: 0 delay: 0 clone_skb: 64 ifname: eth4@0
  66. flows: 0 flowlen: 0
  67. queue_map_min: 0 queue_map_max: 0
  68. dst_min: 192.168.81.2 dst_max:
  69. src_min: src_max:
  70. src_mac: 90:e2:ba:0a:56:b4 dst_mac: 00:1b:21:3c:9d:f8
  71. udp_src_min: 9 udp_src_max: 109 udp_dst_min: 9 udp_dst_max: 9
  72. src_mac_count: 0 dst_mac_count: 0
  73. Flags: UDPSRC_RND NO_TIMESTAMP QUEUE_MAP_CPU
  74. Current:
  75. pkts-sofar: 100000 errors: 0
  76. started: 623913381008us stopped: 623913396439us idle: 25us
  77. seq_num: 100001 cur_dst_mac_offset: 0 cur_src_mac_offset: 0
  78. cur_saddr: 192.168.8.3 cur_daddr: 192.168.81.2
  79. cur_udp_dst: 9 cur_udp_src: 42
  80. cur_queue_map: 0
  81. flows: 0
  82. Result: OK: 15430(c15405+d25) usec, 100000 (60byte,0frags)
  83. 6480562pps 3110Mb/sec (3110669760bps) errors: 0
  84. Configuring devices
  85. ===================
  86. This is done via the /proc interface, and most easily done via pgset
  87. as defined in the sample scripts.
  88. You need to specify PGDEV environment variable to use functions from sample
  89. scripts, i.e.::
  90. export PGDEV=/proc/net/pktgen/eth4@0
  91. source samples/pktgen/functions.sh
  92. Examples::
  93. pg_ctrl start starts injection.
  94. pg_ctrl stop aborts injection. Also, ^C aborts generator.
  95. pgset "clone_skb 1" sets the number of copies of the same packet
  96. pgset "clone_skb 0" use single SKB for all transmits
  97. pgset "burst 8" uses xmit_more API to queue 8 copies of the same
  98. packet and update HW tx queue tail pointer once.
  99. "burst 1" is the default
  100. pgset "pkt_size 9014" sets packet size to 9014
  101. pgset "frags 5" packet will consist of 5 fragments
  102. pgset "count 200000" sets number of packets to send, set to zero
  103. for continuous sends until explicitly stopped.
  104. pgset "delay 5000" adds delay to hard_start_xmit(). nanoseconds
  105. pgset "dst 10.0.0.1" sets IP destination address
  106. (BEWARE! This generator is very aggressive!)
  107. pgset "dst_min 10.0.0.1" Same as dst
  108. pgset "dst_max 10.0.0.254" Set the maximum destination IP.
  109. pgset "src_min 10.0.0.1" Set the minimum (or only) source IP.
  110. pgset "src_max 10.0.0.254" Set the maximum source IP.
  111. pgset "dst6 fec0::1" IPV6 destination address
  112. pgset "src6 fec0::2" IPV6 source address
  113. pgset "dstmac 00:00:00:00:00:00" sets MAC destination address
  114. pgset "srcmac 00:00:00:00:00:00" sets MAC source address
  115. pgset "queue_map_min 0" Sets the min value of tx queue interval
  116. pgset "queue_map_max 7" Sets the max value of tx queue interval, for multiqueue devices
  117. To select queue 1 of a given device,
  118. use queue_map_min=1 and queue_map_max=1
  119. pgset "src_mac_count 1" Sets the number of MACs we'll range through.
  120. The 'minimum' MAC is what you set with srcmac.
  121. pgset "dst_mac_count 1" Sets the number of MACs we'll range through.
  122. The 'minimum' MAC is what you set with dstmac.
  123. pgset "flag [name]" Set a flag to determine behaviour. Current flags
  124. are: IPSRC_RND # IP source is random (between min/max)
  125. IPDST_RND # IP destination is random
  126. UDPSRC_RND, UDPDST_RND,
  127. MACSRC_RND, MACDST_RND
  128. TXSIZE_RND, IPV6,
  129. MPLS_RND, VID_RND, SVID_RND
  130. FLOW_SEQ,
  131. QUEUE_MAP_RND # queue map random
  132. QUEUE_MAP_CPU # queue map mirrors smp_processor_id()
  133. UDPCSUM,
  134. IPSEC # IPsec encapsulation (needs CONFIG_XFRM)
  135. NODE_ALLOC # node specific memory allocation
  136. NO_TIMESTAMP # disable timestamping
  137. pgset 'flag ![name]' Clear a flag to determine behaviour.
  138. Note that you might need to use single quote in
  139. interactive mode, so that your shell wouldn't expand
  140. the specified flag as a history command.
  141. pgset "spi [SPI_VALUE]" Set specific SA used to transform packet.
  142. pgset "udp_src_min 9" set UDP source port min, If < udp_src_max, then
  143. cycle through the port range.
  144. pgset "udp_src_max 9" set UDP source port max.
  145. pgset "udp_dst_min 9" set UDP destination port min, If < udp_dst_max, then
  146. cycle through the port range.
  147. pgset "udp_dst_max 9" set UDP destination port max.
  148. pgset "mpls 0001000a,0002000a,0000000a" set MPLS labels (in this example
  149. outer label=16,middle label=32,
  150. inner label=0 (IPv4 NULL)) Note that
  151. there must be no spaces between the
  152. arguments. Leading zeros are required.
  153. Do not set the bottom of stack bit,
  154. that's done automatically. If you do
  155. set the bottom of stack bit, that
  156. indicates that you want to randomly
  157. generate that address and the flag
  158. MPLS_RND will be turned on. You
  159. can have any mix of random and fixed
  160. labels in the label stack.
  161. pgset "mpls 0" turn off mpls (or any invalid argument works too!)
  162. pgset "vlan_id 77" set VLAN ID 0-4095
  163. pgset "vlan_p 3" set priority bit 0-7 (default 0)
  164. pgset "vlan_cfi 0" set canonical format identifier 0-1 (default 0)
  165. pgset "svlan_id 22" set SVLAN ID 0-4095
  166. pgset "svlan_p 3" set priority bit 0-7 (default 0)
  167. pgset "svlan_cfi 0" set canonical format identifier 0-1 (default 0)
  168. pgset "vlan_id 9999" > 4095 remove vlan and svlan tags
  169. pgset "svlan 9999" > 4095 remove svlan tag
  170. pgset "tos XX" set former IPv4 TOS field (e.g. "tos 28" for AF11 no ECN, default 00)
  171. pgset "traffic_class XX" set former IPv6 TRAFFIC CLASS (e.g. "traffic_class B8" for EF no ECN, default 00)
  172. pgset "rate 300M" set rate to 300 Mb/s
  173. pgset "ratep 1000000" set rate to 1Mpps
  174. pgset "xmit_mode netif_receive" RX inject into stack netif_receive_skb()
  175. Works with "burst" but not with "clone_skb".
  176. Default xmit_mode is "start_xmit".
  177. Sample scripts
  178. ==============
  179. A collection of tutorial scripts and helpers for pktgen is in the
  180. samples/pktgen directory. The helper parameters.sh file support easy
  181. and consistent parameter parsing across the sample scripts.
  182. Usage example and help::
  183. ./pktgen_sample01_simple.sh -i eth4 -m 00:1B:21:3C:9D:F8 -d 192.168.8.2
  184. Usage:::
  185. ./pktgen_sample01_simple.sh [-vx] -i ethX
  186. -i : ($DEV) output interface/device (required)
  187. -s : ($PKT_SIZE) packet size
  188. -d : ($DEST_IP) destination IP
  189. -m : ($DST_MAC) destination MAC-addr
  190. -t : ($THREADS) threads to start
  191. -c : ($SKB_CLONE) SKB clones send before alloc new SKB
  192. -b : ($BURST) HW level bursting of SKBs
  193. -v : ($VERBOSE) verbose
  194. -x : ($DEBUG) debug
  195. The global variables being set are also listed. E.g. the required
  196. interface/device parameter "-i" sets variable $DEV. Copy the
  197. pktgen_sampleXX scripts and modify them to fit your own needs.
  198. The old scripts::
  199. pktgen.conf-1-2 # 1 CPU 2 dev
  200. pktgen.conf-1-1-rdos # 1 CPU 1 dev w. route DoS
  201. pktgen.conf-1-1-ip6 # 1 CPU 1 dev ipv6
  202. pktgen.conf-1-1-ip6-rdos # 1 CPU 1 dev ipv6 w. route DoS
  203. pktgen.conf-1-1-flows # 1 CPU 1 dev multiple flows.
  204. Interrupt affinity
  205. ===================
  206. Note that when adding devices to a specific CPU it is a good idea to
  207. also assign /proc/irq/XX/smp_affinity so that the TX interrupts are bound
  208. to the same CPU. This reduces cache bouncing when freeing skbs.
  209. Plus using the device flag QUEUE_MAP_CPU, which maps the SKBs TX queue
  210. to the running threads CPU (directly from smp_processor_id()).
  211. Enable IPsec
  212. ============
  213. Default IPsec transformation with ESP encapsulation plus transport mode
  214. can be enabled by simply setting::
  215. pgset "flag IPSEC"
  216. pgset "flows 1"
  217. To avoid breaking existing testbed scripts for using AH type and tunnel mode,
  218. you can use "pgset spi SPI_VALUE" to specify which transformation mode
  219. to employ.
  220. Current commands and configuration options
  221. ==========================================
  222. **Pgcontrol commands**::
  223. start
  224. stop
  225. reset
  226. **Thread commands**::
  227. add_device
  228. rem_device_all
  229. **Device commands**::
  230. count
  231. clone_skb
  232. burst
  233. debug
  234. frags
  235. delay
  236. src_mac_count
  237. dst_mac_count
  238. pkt_size
  239. min_pkt_size
  240. max_pkt_size
  241. queue_map_min
  242. queue_map_max
  243. skb_priority
  244. tos (ipv4)
  245. traffic_class (ipv6)
  246. mpls
  247. udp_src_min
  248. udp_src_max
  249. udp_dst_min
  250. udp_dst_max
  251. node
  252. flag
  253. IPSRC_RND
  254. IPDST_RND
  255. UDPSRC_RND
  256. UDPDST_RND
  257. MACSRC_RND
  258. MACDST_RND
  259. TXSIZE_RND
  260. IPV6
  261. MPLS_RND
  262. VID_RND
  263. SVID_RND
  264. FLOW_SEQ
  265. QUEUE_MAP_RND
  266. QUEUE_MAP_CPU
  267. UDPCSUM
  268. IPSEC
  269. NODE_ALLOC
  270. NO_TIMESTAMP
  271. spi (ipsec)
  272. dst_min
  273. dst_max
  274. src_min
  275. src_max
  276. dst_mac
  277. src_mac
  278. clear_counters
  279. src6
  280. dst6
  281. dst6_max
  282. dst6_min
  283. flows
  284. flowlen
  285. rate
  286. ratep
  287. xmit_mode <start_xmit|netif_receive>
  288. vlan_cfi
  289. vlan_id
  290. vlan_p
  291. svlan_cfi
  292. svlan_id
  293. svlan_p
  294. References:
  295. - ftp://robur.slu.se/pub/Linux/net-development/pktgen-testing/
  296. - tp://robur.slu.se/pub/Linux/net-development/pktgen-testing/examples/
  297. Paper from Linux-Kongress in Erlangen 2004.
  298. - ftp://robur.slu.se/pub/Linux/net-development/pktgen-testing/pktgen_paper.pdf
  299. Thanks to:
  300. Grant Grundler for testing on IA-64 and parisc, Harald Welte, Lennert Buytenhek
  301. Stephen Hemminger, Andi Kleen, Dave Miller and many others.
  302. Good luck with the linux net-development.