pktgen.txt 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  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 [pktgen/0]
  11. root 130 0.3 0.0 0 0 ? SW 2003 509:50 [pktgen/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 corrosponding 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, a 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. Examples:
  87. pgset "clone_skb 1" sets the number of copies of the same packet
  88. pgset "clone_skb 0" use single SKB for all transmits
  89. pgset "burst 8" uses xmit_more API to queue 8 copies of the same
  90. packet and update HW tx queue tail pointer once.
  91. "burst 1" is the default
  92. pgset "pkt_size 9014" sets packet size to 9014
  93. pgset "frags 5" packet will consist of 5 fragments
  94. pgset "count 200000" sets number of packets to send, set to zero
  95. for continuous sends until explicitly stopped.
  96. pgset "delay 5000" adds delay to hard_start_xmit(). nanoseconds
  97. pgset "dst 10.0.0.1" sets IP destination address
  98. (BEWARE! This generator is very aggressive!)
  99. pgset "dst_min 10.0.0.1" Same as dst
  100. pgset "dst_max 10.0.0.254" Set the maximum destination IP.
  101. pgset "src_min 10.0.0.1" Set the minimum (or only) source IP.
  102. pgset "src_max 10.0.0.254" Set the maximum source IP.
  103. pgset "dst6 fec0::1" IPV6 destination address
  104. pgset "src6 fec0::2" IPV6 source address
  105. pgset "dstmac 00:00:00:00:00:00" sets MAC destination address
  106. pgset "srcmac 00:00:00:00:00:00" sets MAC source address
  107. pgset "queue_map_min 0" Sets the min value of tx queue interval
  108. pgset "queue_map_max 7" Sets the max value of tx queue interval, for multiqueue devices
  109. To select queue 1 of a given device,
  110. use queue_map_min=1 and queue_map_max=1
  111. pgset "src_mac_count 1" Sets the number of MACs we'll range through.
  112. The 'minimum' MAC is what you set with srcmac.
  113. pgset "dst_mac_count 1" Sets the number of MACs we'll range through.
  114. The 'minimum' MAC is what you set with dstmac.
  115. pgset "flag [name]" Set a flag to determine behaviour. Current flags
  116. are: IPSRC_RND # IP source is random (between min/max)
  117. IPDST_RND # IP destination is random
  118. UDPSRC_RND, UDPDST_RND,
  119. MACSRC_RND, MACDST_RND
  120. TXSIZE_RND, IPV6,
  121. MPLS_RND, VID_RND, SVID_RND
  122. FLOW_SEQ,
  123. QUEUE_MAP_RND # queue map random
  124. QUEUE_MAP_CPU # queue map mirrors smp_processor_id()
  125. UDPCSUM,
  126. IPSEC # IPsec encapsulation (needs CONFIG_XFRM)
  127. NODE_ALLOC # node specific memory allocation
  128. NO_TIMESTAMP # disable timestamping
  129. pgset spi SPI_VALUE Set specific SA used to transform packet.
  130. pgset "udp_src_min 9" set UDP source port min, If < udp_src_max, then
  131. cycle through the port range.
  132. pgset "udp_src_max 9" set UDP source port max.
  133. pgset "udp_dst_min 9" set UDP destination port min, If < udp_dst_max, then
  134. cycle through the port range.
  135. pgset "udp_dst_max 9" set UDP destination port max.
  136. pgset "mpls 0001000a,0002000a,0000000a" set MPLS labels (in this example
  137. outer label=16,middle label=32,
  138. inner label=0 (IPv4 NULL)) Note that
  139. there must be no spaces between the
  140. arguments. Leading zeros are required.
  141. Do not set the bottom of stack bit,
  142. that's done automatically. If you do
  143. set the bottom of stack bit, that
  144. indicates that you want to randomly
  145. generate that address and the flag
  146. MPLS_RND will be turned on. You
  147. can have any mix of random and fixed
  148. labels in the label stack.
  149. pgset "mpls 0" turn off mpls (or any invalid argument works too!)
  150. pgset "vlan_id 77" set VLAN ID 0-4095
  151. pgset "vlan_p 3" set priority bit 0-7 (default 0)
  152. pgset "vlan_cfi 0" set canonical format identifier 0-1 (default 0)
  153. pgset "svlan_id 22" set SVLAN ID 0-4095
  154. pgset "svlan_p 3" set priority bit 0-7 (default 0)
  155. pgset "svlan_cfi 0" set canonical format identifier 0-1 (default 0)
  156. pgset "vlan_id 9999" > 4095 remove vlan and svlan tags
  157. pgset "svlan 9999" > 4095 remove svlan tag
  158. pgset "tos XX" set former IPv4 TOS field (e.g. "tos 28" for AF11 no ECN, default 00)
  159. pgset "traffic_class XX" set former IPv6 TRAFFIC CLASS (e.g. "traffic_class B8" for EF no ECN, default 00)
  160. pgset stop aborts injection. Also, ^C aborts generator.
  161. pgset "rate 300M" set rate to 300 Mb/s
  162. pgset "ratep 1000000" set rate to 1Mpps
  163. pgset "xmit_mode netif_receive" RX inject into stack netif_receive_skb()
  164. Works with "burst" but not with "clone_skb".
  165. Default xmit_mode is "start_xmit".
  166. Sample scripts
  167. ==============
  168. A collection of tutorial scripts and helpers for pktgen is in the
  169. samples/pktgen directory. The helper parameters.sh file support easy
  170. and consistant parameter parsing across the sample scripts.
  171. Usage example and help:
  172. ./pktgen_sample01_simple.sh -i eth4 -m 00:1B:21:3C:9D:F8 -d 192.168.8.2
  173. Usage: ./pktgen_sample01_simple.sh [-vx] -i ethX
  174. -i : ($DEV) output interface/device (required)
  175. -s : ($PKT_SIZE) packet size
  176. -d : ($DEST_IP) destination IP
  177. -m : ($DST_MAC) destination MAC-addr
  178. -t : ($THREADS) threads to start
  179. -c : ($SKB_CLONE) SKB clones send before alloc new SKB
  180. -b : ($BURST) HW level bursting of SKBs
  181. -v : ($VERBOSE) verbose
  182. -x : ($DEBUG) debug
  183. The global variables being set are also listed. E.g. the required
  184. interface/device parameter "-i" sets variable $DEV. Copy the
  185. pktgen_sampleXX scripts and modify them to fit your own needs.
  186. The old scripts:
  187. pktgen.conf-1-2 # 1 CPU 2 dev
  188. pktgen.conf-1-1-rdos # 1 CPU 1 dev w. route DoS
  189. pktgen.conf-1-1-ip6 # 1 CPU 1 dev ipv6
  190. pktgen.conf-1-1-ip6-rdos # 1 CPU 1 dev ipv6 w. route DoS
  191. pktgen.conf-1-1-flows # 1 CPU 1 dev multiple flows.
  192. Interrupt affinity
  193. ===================
  194. Note that when adding devices to a specific CPU it is a good idea to
  195. also assign /proc/irq/XX/smp_affinity so that the TX interrupts are bound
  196. to the same CPU. This reduces cache bouncing when freeing skbs.
  197. Plus using the device flag QUEUE_MAP_CPU, which maps the SKBs TX queue
  198. to the running threads CPU (directly from smp_processor_id()).
  199. Enable IPsec
  200. ============
  201. Default IPsec transformation with ESP encapsulation plus transport mode
  202. can be enabled by simply setting:
  203. pgset "flag IPSEC"
  204. pgset "flows 1"
  205. To avoid breaking existing testbed scripts for using AH type and tunnel mode,
  206. you can use "pgset spi SPI_VALUE" to specify which transformation mode
  207. to employ.
  208. Current commands and configuration options
  209. ==========================================
  210. ** Pgcontrol commands:
  211. start
  212. stop
  213. reset
  214. ** Thread commands:
  215. add_device
  216. rem_device_all
  217. ** Device commands:
  218. count
  219. clone_skb
  220. burst
  221. debug
  222. frags
  223. delay
  224. src_mac_count
  225. dst_mac_count
  226. pkt_size
  227. min_pkt_size
  228. max_pkt_size
  229. queue_map_min
  230. queue_map_max
  231. skb_priority
  232. tos (ipv4)
  233. traffic_class (ipv6)
  234. mpls
  235. udp_src_min
  236. udp_src_max
  237. udp_dst_min
  238. udp_dst_max
  239. node
  240. flag
  241. IPSRC_RND
  242. IPDST_RND
  243. UDPSRC_RND
  244. UDPDST_RND
  245. MACSRC_RND
  246. MACDST_RND
  247. TXSIZE_RND
  248. IPV6
  249. MPLS_RND
  250. VID_RND
  251. SVID_RND
  252. FLOW_SEQ
  253. QUEUE_MAP_RND
  254. QUEUE_MAP_CPU
  255. UDPCSUM
  256. IPSEC
  257. NODE_ALLOC
  258. NO_TIMESTAMP
  259. spi (ipsec)
  260. dst_min
  261. dst_max
  262. src_min
  263. src_max
  264. dst_mac
  265. src_mac
  266. clear_counters
  267. src6
  268. dst6
  269. dst6_max
  270. dst6_min
  271. flows
  272. flowlen
  273. rate
  274. ratep
  275. xmit_mode <start_xmit|netif_receive>
  276. vlan_cfi
  277. vlan_id
  278. vlan_p
  279. svlan_cfi
  280. svlan_id
  281. svlan_p
  282. References:
  283. ftp://robur.slu.se/pub/Linux/net-development/pktgen-testing/
  284. ftp://robur.slu.se/pub/Linux/net-development/pktgen-testing/examples/
  285. Paper from Linux-Kongress in Erlangen 2004.
  286. ftp://robur.slu.se/pub/Linux/net-development/pktgen-testing/pktgen_paper.pdf
  287. Thanks to:
  288. Grant Grundler for testing on IA-64 and parisc, Harald Welte, Lennert Buytenhek
  289. Stephen Hemminger, Andi Kleen, Dave Miller and many others.
  290. Good luck with the linux net-development.