pktgen.txt 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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. Kernel threads
  18. ==============
  19. Pktgen creates a thread for each CPU with affinity to that CPU.
  20. Which is controlled through procfile /proc/net/pktgen/kpktgend_X.
  21. Example: /proc/net/pktgen/kpktgend_0
  22. Running:
  23. Stopped: eth4@0
  24. Result: OK: add_device=eth4@0
  25. Most important are the devices assigned to the thread.
  26. The two basic thread commands are:
  27. * add_device DEVICE@NAME -- adds a single device
  28. * rem_device_all -- remove all associated devices
  29. When adding a device to a thread, a corrosponding procfile is created
  30. which is used for configuring this device. Thus, device names need to
  31. be unique.
  32. To support adding the same device to multiple threads, which is useful
  33. with multi queue NICs, a the device naming scheme is extended with "@":
  34. device@something
  35. The part after "@" can be anything, but it is custom to use the thread
  36. number.
  37. Viewing devices
  38. ===============
  39. Parm section holds configured info. Current hold running stats.
  40. Result is printed after run or after interruption. Example:
  41. /proc/net/pktgen/eth4@0
  42. Params: count 100000 min_pkt_size: 60 max_pkt_size: 60
  43. frags: 0 delay: 0 clone_skb: 64 ifname: eth4@0
  44. flows: 0 flowlen: 0
  45. queue_map_min: 0 queue_map_max: 0
  46. dst_min: 192.168.81.2 dst_max:
  47. src_min: src_max:
  48. src_mac: 90:e2:ba:0a:56:b4 dst_mac: 00:1b:21:3c:9d:f8
  49. udp_src_min: 9 udp_src_max: 109 udp_dst_min: 9 udp_dst_max: 9
  50. src_mac_count: 0 dst_mac_count: 0
  51. Flags: UDPSRC_RND NO_TIMESTAMP QUEUE_MAP_CPU
  52. Current:
  53. pkts-sofar: 100000 errors: 0
  54. started: 623913381008us stopped: 623913396439us idle: 25us
  55. seq_num: 100001 cur_dst_mac_offset: 0 cur_src_mac_offset: 0
  56. cur_saddr: 192.168.8.3 cur_daddr: 192.168.81.2
  57. cur_udp_dst: 9 cur_udp_src: 42
  58. cur_queue_map:
  59. flows: 0
  60. Result: OK: 15430(c15405d25) usec, 100000 (60byte,0frags)
  61. 6480562pps 3110Mb/sec (3110669760bps) errors: 0
  62. Configuring devices
  63. ===================
  64. This is done via the /proc interface easiest done via pgset in the scripts
  65. Examples:
  66. pgset "clone_skb 1" sets the number of copies of the same packet
  67. pgset "clone_skb 0" use single SKB for all transmits
  68. pgset "pkt_size 9014" sets packet size to 9014
  69. pgset "frags 5" packet will consist of 5 fragments
  70. pgset "count 200000" sets number of packets to send, set to zero
  71. for continuous sends until explicitly stopped.
  72. pgset "delay 5000" adds delay to hard_start_xmit(). nanoseconds
  73. pgset "dst 10.0.0.1" sets IP destination address
  74. (BEWARE! This generator is very aggressive!)
  75. pgset "dst_min 10.0.0.1" Same as dst
  76. pgset "dst_max 10.0.0.254" Set the maximum destination IP.
  77. pgset "src_min 10.0.0.1" Set the minimum (or only) source IP.
  78. pgset "src_max 10.0.0.254" Set the maximum source IP.
  79. pgset "dst6 fec0::1" IPV6 destination address
  80. pgset "src6 fec0::2" IPV6 source address
  81. pgset "dstmac 00:00:00:00:00:00" sets MAC destination address
  82. pgset "srcmac 00:00:00:00:00:00" sets MAC source address
  83. pgset "queue_map_min 0" Sets the min value of tx queue interval
  84. pgset "queue_map_max 7" Sets the max value of tx queue interval, for multiqueue devices
  85. To select queue 1 of a given device,
  86. use queue_map_min=1 and queue_map_max=1
  87. pgset "src_mac_count 1" Sets the number of MACs we'll range through.
  88. The 'minimum' MAC is what you set with srcmac.
  89. pgset "dst_mac_count 1" Sets the number of MACs we'll range through.
  90. The 'minimum' MAC is what you set with dstmac.
  91. pgset "flag [name]" Set a flag to determine behaviour. Current flags
  92. are: IPSRC_RND #IP Source is random (between min/max),
  93. IPDST_RND, UDPSRC_RND,
  94. UDPDST_RND, MACSRC_RND, MACDST_RND
  95. MPLS_RND, VID_RND, SVID_RND
  96. QUEUE_MAP_RND # queue map random
  97. QUEUE_MAP_CPU # queue map mirrors smp_processor_id()
  98. pgset "udp_src_min 9" set UDP source port min, If < udp_src_max, then
  99. cycle through the port range.
  100. pgset "udp_src_max 9" set UDP source port max.
  101. pgset "udp_dst_min 9" set UDP destination port min, If < udp_dst_max, then
  102. cycle through the port range.
  103. pgset "udp_dst_max 9" set UDP destination port max.
  104. pgset "mpls 0001000a,0002000a,0000000a" set MPLS labels (in this example
  105. outer label=16,middle label=32,
  106. inner label=0 (IPv4 NULL)) Note that
  107. there must be no spaces between the
  108. arguments. Leading zeros are required.
  109. Do not set the bottom of stack bit,
  110. that's done automatically. If you do
  111. set the bottom of stack bit, that
  112. indicates that you want to randomly
  113. generate that address and the flag
  114. MPLS_RND will be turned on. You
  115. can have any mix of random and fixed
  116. labels in the label stack.
  117. pgset "mpls 0" turn off mpls (or any invalid argument works too!)
  118. pgset "vlan_id 77" set VLAN ID 0-4095
  119. pgset "vlan_p 3" set priority bit 0-7 (default 0)
  120. pgset "vlan_cfi 0" set canonical format identifier 0-1 (default 0)
  121. pgset "svlan_id 22" set SVLAN ID 0-4095
  122. pgset "svlan_p 3" set priority bit 0-7 (default 0)
  123. pgset "svlan_cfi 0" set canonical format identifier 0-1 (default 0)
  124. pgset "vlan_id 9999" > 4095 remove vlan and svlan tags
  125. pgset "svlan 9999" > 4095 remove svlan tag
  126. pgset "tos XX" set former IPv4 TOS field (e.g. "tos 28" for AF11 no ECN, default 00)
  127. pgset "traffic_class XX" set former IPv6 TRAFFIC CLASS (e.g. "traffic_class B8" for EF no ECN, default 00)
  128. pgset stop aborts injection. Also, ^C aborts generator.
  129. pgset "rate 300M" set rate to 300 Mb/s
  130. pgset "ratep 1000000" set rate to 1Mpps
  131. Example scripts
  132. ===============
  133. A collection of small tutorial scripts for pktgen is in examples dir.
  134. pktgen.conf-1-1 # 1 CPU 1 dev
  135. pktgen.conf-1-2 # 1 CPU 2 dev
  136. pktgen.conf-2-1 # 2 CPU's 1 dev
  137. pktgen.conf-2-2 # 2 CPU's 2 dev
  138. pktgen.conf-1-1-rdos # 1 CPU 1 dev w. route DoS
  139. pktgen.conf-1-1-ip6 # 1 CPU 1 dev ipv6
  140. pktgen.conf-1-1-ip6-rdos # 1 CPU 1 dev ipv6 w. route DoS
  141. pktgen.conf-1-1-flows # 1 CPU 1 dev multiple flows.
  142. Run in shell: ./pktgen.conf-X-Y It does all the setup including sending.
  143. Interrupt affinity
  144. ===================
  145. Note when adding devices to a specific CPU there good idea to also assign
  146. /proc/irq/XX/smp_affinity so the TX-interrupts gets bound to the same CPU.
  147. as this reduces cache bouncing when freeing skb's.
  148. Plus using the device flag QUEUE_MAP_CPU, which maps the SKBs TX queue
  149. to the running threads CPU (directly from smp_processor_id()).
  150. Current commands and configuration options
  151. ==========================================
  152. ** Pgcontrol commands:
  153. start
  154. stop
  155. ** Thread commands:
  156. add_device
  157. rem_device_all
  158. max_before_softirq
  159. ** Device commands:
  160. count
  161. clone_skb
  162. debug
  163. frags
  164. delay
  165. src_mac_count
  166. dst_mac_count
  167. pkt_size
  168. min_pkt_size
  169. max_pkt_size
  170. mpls
  171. udp_src_min
  172. udp_src_max
  173. udp_dst_min
  174. udp_dst_max
  175. flag
  176. IPSRC_RND
  177. TXSIZE_RND
  178. IPDST_RND
  179. UDPSRC_RND
  180. UDPDST_RND
  181. MACSRC_RND
  182. MACDST_RND
  183. dst_min
  184. dst_max
  185. src_min
  186. src_max
  187. dst_mac
  188. src_mac
  189. clear_counters
  190. dst6
  191. src6
  192. flows
  193. flowlen
  194. rate
  195. ratep
  196. References:
  197. ftp://robur.slu.se/pub/Linux/net-development/pktgen-testing/
  198. ftp://robur.slu.se/pub/Linux/net-development/pktgen-testing/examples/
  199. Paper from Linux-Kongress in Erlangen 2004.
  200. ftp://robur.slu.se/pub/Linux/net-development/pktgen-testing/pktgen_paper.pdf
  201. Thanks to:
  202. Grant Grundler for testing on IA-64 and parisc, Harald Welte, Lennert Buytenhek
  203. Stephen Hemminger, Andi Kleen, Dave Miller and many others.
  204. Good luck with the linux net-development.