pktgen.txt 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. HOWTO for the linux packet generator
  2. ------------------------------------
  3. Date: 041221
  4. Enable CONFIG_NET_PKTGEN to compile and build pktgen.o either in kernel
  5. or as module. Module is preferred. insmod pktgen if needed. Once running
  6. pktgen creates a thread on each CPU where each thread has affinity to its CPU.
  7. Monitoring and controlling is done via /proc. Easiest to select a suitable
  8. a sample script and configure.
  9. On a dual CPU:
  10. ps aux | grep pkt
  11. root 129 0.3 0.0 0 0 ? SW 2003 523:20 [pktgen/0]
  12. root 130 0.3 0.0 0 0 ? SW 2003 509:50 [pktgen/1]
  13. For monitoring and control pktgen creates:
  14. /proc/net/pktgen/pgctrl
  15. /proc/net/pktgen/kpktgend_X
  16. /proc/net/pktgen/ethX
  17. Tuning NIC for max performance
  18. ==============================
  19. The default NIC setting are (likely) not tuned for pktgen's artificial
  20. overload type of benchmarking, as this could hurt the normal use-case.
  21. Specifically increasing the TX ring buffer in the NIC:
  22. # ethtool -G ethX tx 1024
  23. A larger TX ring can improve pktgen's performance, while it can hurt
  24. in the general case, 1) because the TX ring buffer might get larger
  25. than the CPUs L1/L2 cache, 2) because it allow more queueing in the
  26. NIC HW layer (which is bad for bufferbloat).
  27. One should be careful to conclude, that packets/descriptors in the HW
  28. TX ring cause delay. Drivers usually delay cleaning up the
  29. ring-buffers (for various performance reasons), thus packets stalling
  30. the TX ring, might just be waiting for cleanup.
  31. This cleanup issues is specifically the case, for the driver ixgbe
  32. (Intel 82599 chip). This driver (ixgbe) combine TX+RX ring cleanups,
  33. and the cleanup interval is affected by the ethtool --coalesce setting
  34. of parameter "rx-usecs".
  35. For ixgbe use e.g "30" resulting in approx 33K interrupts/sec (1/30*10^6):
  36. # ethtool -C ethX rx-usecs 30
  37. Viewing threads
  38. ===============
  39. /proc/net/pktgen/kpktgend_0
  40. Name: kpktgend_0 max_before_softirq: 10000
  41. Running:
  42. Stopped: eth1
  43. Result: OK: max_before_softirq=10000
  44. Most important the devices assigned to thread. Note! A device can only belong
  45. to one thread.
  46. Viewing devices
  47. ===============
  48. Parm section holds configured info. Current hold running stats.
  49. Result is printed after run or after interruption. Example:
  50. /proc/net/pktgen/eth1
  51. Params: count 10000000 min_pkt_size: 60 max_pkt_size: 60
  52. frags: 0 delay: 0 clone_skb: 1000000 ifname: eth1
  53. flows: 0 flowlen: 0
  54. dst_min: 10.10.11.2 dst_max:
  55. src_min: src_max:
  56. src_mac: 00:00:00:00:00:00 dst_mac: 00:04:23:AC:FD:82
  57. udp_src_min: 9 udp_src_max: 9 udp_dst_min: 9 udp_dst_max: 9
  58. src_mac_count: 0 dst_mac_count: 0
  59. Flags:
  60. Current:
  61. pkts-sofar: 10000000 errors: 39664
  62. started: 1103053986245187us stopped: 1103053999346329us idle: 880401us
  63. seq_num: 10000011 cur_dst_mac_offset: 0 cur_src_mac_offset: 0
  64. cur_saddr: 0x10a0a0a cur_daddr: 0x20b0a0a
  65. cur_udp_dst: 9 cur_udp_src: 9
  66. flows: 0
  67. Result: OK: 13101142(c12220741+d880401) usec, 10000000 (60byte,0frags)
  68. 763292pps 390Mb/sec (390805504bps) errors: 39664
  69. Configuring threads and devices
  70. ================================
  71. This is done via the /proc interface easiest done via pgset in the scripts
  72. Examples:
  73. pgset "clone_skb 1" sets the number of copies of the same packet
  74. pgset "clone_skb 0" use single SKB for all transmits
  75. pgset "burst 8" uses xmit_more API to queue 8 copies of the same
  76. packet and update HW tx queue tail pointer once.
  77. "burst 1" is the default
  78. pgset "pkt_size 9014" sets packet size to 9014
  79. pgset "frags 5" packet will consist of 5 fragments
  80. pgset "count 200000" sets number of packets to send, set to zero
  81. for continuous sends until explicitly stopped.
  82. pgset "delay 5000" adds delay to hard_start_xmit(). nanoseconds
  83. pgset "dst 10.0.0.1" sets IP destination address
  84. (BEWARE! This generator is very aggressive!)
  85. pgset "dst_min 10.0.0.1" Same as dst
  86. pgset "dst_max 10.0.0.254" Set the maximum destination IP.
  87. pgset "src_min 10.0.0.1" Set the minimum (or only) source IP.
  88. pgset "src_max 10.0.0.254" Set the maximum source IP.
  89. pgset "dst6 fec0::1" IPV6 destination address
  90. pgset "src6 fec0::2" IPV6 source address
  91. pgset "dstmac 00:00:00:00:00:00" sets MAC destination address
  92. pgset "srcmac 00:00:00:00:00:00" sets MAC source address
  93. pgset "queue_map_min 0" Sets the min value of tx queue interval
  94. pgset "queue_map_max 7" Sets the max value of tx queue interval, for multiqueue devices
  95. To select queue 1 of a given device,
  96. use queue_map_min=1 and queue_map_max=1
  97. pgset "src_mac_count 1" Sets the number of MACs we'll range through.
  98. The 'minimum' MAC is what you set with srcmac.
  99. pgset "dst_mac_count 1" Sets the number of MACs we'll range through.
  100. The 'minimum' MAC is what you set with dstmac.
  101. pgset "flag [name]" Set a flag to determine behaviour. Current flags
  102. are: IPSRC_RND # IP source is random (between min/max)
  103. IPDST_RND # IP destination is random
  104. UDPSRC_RND, UDPDST_RND,
  105. MACSRC_RND, MACDST_RND
  106. TXSIZE_RND, IPV6,
  107. MPLS_RND, VID_RND, SVID_RND
  108. FLOW_SEQ,
  109. QUEUE_MAP_RND # queue map random
  110. QUEUE_MAP_CPU # queue map mirrors smp_processor_id()
  111. UDPCSUM,
  112. IPSEC # IPsec encapsulation (needs CONFIG_XFRM)
  113. NODE_ALLOC # node specific memory allocation
  114. pgset spi SPI_VALUE Set specific SA used to transform packet.
  115. pgset "udp_src_min 9" set UDP source port min, If < udp_src_max, then
  116. cycle through the port range.
  117. pgset "udp_src_max 9" set UDP source port max.
  118. pgset "udp_dst_min 9" set UDP destination port min, If < udp_dst_max, then
  119. cycle through the port range.
  120. pgset "udp_dst_max 9" set UDP destination port max.
  121. pgset "mpls 0001000a,0002000a,0000000a" set MPLS labels (in this example
  122. outer label=16,middle label=32,
  123. inner label=0 (IPv4 NULL)) Note that
  124. there must be no spaces between the
  125. arguments. Leading zeros are required.
  126. Do not set the bottom of stack bit,
  127. that's done automatically. If you do
  128. set the bottom of stack bit, that
  129. indicates that you want to randomly
  130. generate that address and the flag
  131. MPLS_RND will be turned on. You
  132. can have any mix of random and fixed
  133. labels in the label stack.
  134. pgset "mpls 0" turn off mpls (or any invalid argument works too!)
  135. pgset "vlan_id 77" set VLAN ID 0-4095
  136. pgset "vlan_p 3" set priority bit 0-7 (default 0)
  137. pgset "vlan_cfi 0" set canonical format identifier 0-1 (default 0)
  138. pgset "svlan_id 22" set SVLAN ID 0-4095
  139. pgset "svlan_p 3" set priority bit 0-7 (default 0)
  140. pgset "svlan_cfi 0" set canonical format identifier 0-1 (default 0)
  141. pgset "vlan_id 9999" > 4095 remove vlan and svlan tags
  142. pgset "svlan 9999" > 4095 remove svlan tag
  143. pgset "tos XX" set former IPv4 TOS field (e.g. "tos 28" for AF11 no ECN, default 00)
  144. pgset "traffic_class XX" set former IPv6 TRAFFIC CLASS (e.g. "traffic_class B8" for EF no ECN, default 00)
  145. pgset stop aborts injection. Also, ^C aborts generator.
  146. pgset "rate 300M" set rate to 300 Mb/s
  147. pgset "ratep 1000000" set rate to 1Mpps
  148. Example scripts
  149. ===============
  150. A collection of small tutorial scripts for pktgen is in examples dir.
  151. pktgen.conf-1-1 # 1 CPU 1 dev
  152. pktgen.conf-1-2 # 1 CPU 2 dev
  153. pktgen.conf-2-1 # 2 CPU's 1 dev
  154. pktgen.conf-2-2 # 2 CPU's 2 dev
  155. pktgen.conf-1-1-rdos # 1 CPU 1 dev w. route DoS
  156. pktgen.conf-1-1-ip6 # 1 CPU 1 dev ipv6
  157. pktgen.conf-1-1-ip6-rdos # 1 CPU 1 dev ipv6 w. route DoS
  158. pktgen.conf-1-1-flows # 1 CPU 1 dev multiple flows.
  159. Run in shell: ./pktgen.conf-X-Y It does all the setup including sending.
  160. Interrupt affinity
  161. ===================
  162. Note when adding devices to a specific CPU there good idea to also assign
  163. /proc/irq/XX/smp_affinity so the TX-interrupts gets bound to the same CPU.
  164. as this reduces cache bouncing when freeing skb's.
  165. Enable IPsec
  166. ============
  167. Default IPsec transformation with ESP encapsulation plus Transport mode
  168. could be enabled by simply setting:
  169. pgset "flag IPSEC"
  170. pgset "flows 1"
  171. To avoid breaking existing testbed scripts for using AH type and tunnel mode,
  172. user could use "pgset spi SPI_VALUE" to specify which formal of transformation
  173. to employ.
  174. Current commands and configuration options
  175. ==========================================
  176. ** Pgcontrol commands:
  177. start
  178. stop
  179. ** Thread commands:
  180. add_device
  181. rem_device_all
  182. max_before_softirq
  183. ** Device commands:
  184. count
  185. clone_skb
  186. debug
  187. frags
  188. delay
  189. src_mac_count
  190. dst_mac_count
  191. pkt_size
  192. min_pkt_size
  193. max_pkt_size
  194. mpls
  195. udp_src_min
  196. udp_src_max
  197. udp_dst_min
  198. udp_dst_max
  199. flag
  200. IPSRC_RND
  201. IPDST_RND
  202. UDPSRC_RND
  203. UDPDST_RND
  204. MACSRC_RND
  205. MACDST_RND
  206. TXSIZE_RND
  207. IPV6
  208. MPLS_RND
  209. VID_RND
  210. SVID_RND
  211. FLOW_SEQ
  212. QUEUE_MAP_RND
  213. QUEUE_MAP_CPU
  214. UDPCSUM
  215. IPSEC
  216. NODE_ALLOC
  217. dst_min
  218. dst_max
  219. src_min
  220. src_max
  221. dst_mac
  222. src_mac
  223. clear_counters
  224. dst6
  225. src6
  226. flows
  227. flowlen
  228. rate
  229. ratep
  230. References:
  231. ftp://robur.slu.se/pub/Linux/net-development/pktgen-testing/
  232. ftp://robur.slu.se/pub/Linux/net-development/pktgen-testing/examples/
  233. Paper from Linux-Kongress in Erlangen 2004.
  234. ftp://robur.slu.se/pub/Linux/net-development/pktgen-testing/pktgen_paper.pdf
  235. Thanks to:
  236. Grant Grundler for testing on IA-64 and parisc, Harald Welte, Lennert Buytenhek
  237. Stephen Hemminger, Andi Kleen, Dave Miller and many others.
  238. Good luck with the linux net-development.