pktgen.txt 7.8 KB

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