pktgen.txt 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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 affinty it's 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 montoring 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 assigend 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. Confguring 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 continious sends untill explicitl 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 "src_mac_count 1" Sets the number of MACs we'll range through.
  71. The 'minimum' MAC is what you set with srcmac.
  72. pgset "dst_mac_count 1" Sets the number of MACs we'll range through.
  73. The 'minimum' MAC is what you set with dstmac.
  74. pgset "flag [name]" Set a flag to determine behaviour. Current flags
  75. are: IPSRC_RND #IP Source is random (between min/max),
  76. IPDST_RND, UDPSRC_RND,
  77. UDPDST_RND, MACSRC_RND, MACDST_RND
  78. pgset "udp_src_min 9" set UDP source port min, If < udp_src_max, then
  79. cycle through the port range.
  80. pgset "udp_src_max 9" set UDP source port max.
  81. pgset "udp_dst_min 9" set UDP destination port min, If < udp_dst_max, then
  82. cycle through the port range.
  83. pgset "udp_dst_max 9" set UDP destination port max.
  84. pgset "mpls 0001000a,0002000a,0000000a" set MPLS labels (in this example
  85. outer label=16,middle label=32,
  86. inner label=0 (IPv4 NULL)) Note that
  87. there must be no spaces between the
  88. arguments. Leading zeros are required.
  89. Do not set the bottom of stack bit,
  90. thats done automatically. If you do
  91. set the bottom of stack bit, that
  92. indicates that you want to randomly
  93. generate that address and the flag
  94. MPLS_RND will be turned on. You
  95. can have any mix of random and fixed
  96. labels in the label stack.
  97. pgset "mpls 0" turn off mpls (or any invalid argument works too!)
  98. pgset stop aborts injection. Also, ^C aborts generator.
  99. Example scripts
  100. ===============
  101. A collection of small tutorial scripts for pktgen is in expamples dir.
  102. pktgen.conf-1-1 # 1 CPU 1 dev
  103. pktgen.conf-1-2 # 1 CPU 2 dev
  104. pktgen.conf-2-1 # 2 CPU's 1 dev
  105. pktgen.conf-2-2 # 2 CPU's 2 dev
  106. pktgen.conf-1-1-rdos # 1 CPU 1 dev w. route DoS
  107. pktgen.conf-1-1-ip6 # 1 CPU 1 dev ipv6
  108. pktgen.conf-1-1-ip6-rdos # 1 CPU 1 dev ipv6 w. route DoS
  109. pktgen.conf-1-1-flows # 1 CPU 1 dev multiple flows.
  110. Run in shell: ./pktgen.conf-X-Y It does all the setup including sending.
  111. Interrupt affinity
  112. ===================
  113. Note when adding devices to a specific CPU there good idea to also assign
  114. /proc/irq/XX/smp_affinity so the TX-interrupts gets bound to the same CPU.
  115. as this reduces cache bouncing when freeing skb's.
  116. Current commands and configuration options
  117. ==========================================
  118. ** Pgcontrol commands:
  119. start
  120. stop
  121. ** Thread commands:
  122. add_device
  123. rem_device_all
  124. max_before_softirq
  125. ** Device commands:
  126. count
  127. clone_skb
  128. debug
  129. frags
  130. delay
  131. src_mac_count
  132. dst_mac_count
  133. pkt_size
  134. min_pkt_size
  135. max_pkt_size
  136. mpls
  137. udp_src_min
  138. udp_src_max
  139. udp_dst_min
  140. udp_dst_max
  141. flag
  142. IPSRC_RND
  143. TXSIZE_RND
  144. IPDST_RND
  145. UDPSRC_RND
  146. UDPDST_RND
  147. MACSRC_RND
  148. MACDST_RND
  149. dst_min
  150. dst_max
  151. src_min
  152. src_max
  153. dst_mac
  154. src_mac
  155. clear_counters
  156. dst6
  157. src6
  158. flows
  159. flowlen
  160. References:
  161. ftp://robur.slu.se/pub/Linux/net-development/pktgen-testing/
  162. ftp://robur.slu.se/pub/Linux/net-development/pktgen-testing/examples/
  163. Paper from Linux-Kongress in Erlangen 2004.
  164. ftp://robur.slu.se/pub/Linux/net-development/pktgen-testing/pktgen_paper.pdf
  165. Thanks to:
  166. Grant Grundler for testing on IA-64 and parisc, Harald Welte, Lennert Buytenhek
  167. Stephen Hemminger, Andi Kleen, Dave Miller and many others.
  168. Good luck with the linux net-development.