pktgen.txt 12 KB

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