pktgen.txt 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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 "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. MPLS_RND, VID_RND, SVID_RND
  79. pgset "udp_src_min 9" set UDP source port min, If < udp_src_max, then
  80. cycle through the port range.
  81. pgset "udp_src_max 9" set UDP source port max.
  82. pgset "udp_dst_min 9" set UDP destination port min, If < udp_dst_max, then
  83. cycle through the port range.
  84. pgset "udp_dst_max 9" set UDP destination port max.
  85. pgset "mpls 0001000a,0002000a,0000000a" set MPLS labels (in this example
  86. outer label=16,middle label=32,
  87. inner label=0 (IPv4 NULL)) Note that
  88. there must be no spaces between the
  89. arguments. Leading zeros are required.
  90. Do not set the bottom of stack bit,
  91. that's done automatically. If you do
  92. set the bottom of stack bit, that
  93. indicates that you want to randomly
  94. generate that address and the flag
  95. MPLS_RND will be turned on. You
  96. can have any mix of random and fixed
  97. labels in the label stack.
  98. pgset "mpls 0" turn off mpls (or any invalid argument works too!)
  99. pgset "vlan_id 77" set VLAN ID 0-4095
  100. pgset "vlan_p 3" set priority bit 0-7 (default 0)
  101. pgset "vlan_cfi 0" set canonical format identifier 0-1 (default 0)
  102. pgset "svlan_id 22" set SVLAN ID 0-4095
  103. pgset "svlan_p 3" set priority bit 0-7 (default 0)
  104. pgset "svlan_cfi 0" set canonical format identifier 0-1 (default 0)
  105. pgset "vlan_id 9999" > 4095 remove vlan and svlan tags
  106. pgset "svlan 9999" > 4095 remove svlan tag
  107. pgset "tos XX" set former IPv4 TOS field (e.g. "tos 28" for AF11 no ECN, default 00)
  108. pgset "traffic_class XX" set former IPv6 TRAFFIC CLASS (e.g. "traffic_class B8" for EF no ECN, default 00)
  109. pgset stop aborts injection. Also, ^C aborts generator.
  110. Example scripts
  111. ===============
  112. A collection of small tutorial scripts for pktgen is in examples dir.
  113. pktgen.conf-1-1 # 1 CPU 1 dev
  114. pktgen.conf-1-2 # 1 CPU 2 dev
  115. pktgen.conf-2-1 # 2 CPU's 1 dev
  116. pktgen.conf-2-2 # 2 CPU's 2 dev
  117. pktgen.conf-1-1-rdos # 1 CPU 1 dev w. route DoS
  118. pktgen.conf-1-1-ip6 # 1 CPU 1 dev ipv6
  119. pktgen.conf-1-1-ip6-rdos # 1 CPU 1 dev ipv6 w. route DoS
  120. pktgen.conf-1-1-flows # 1 CPU 1 dev multiple flows.
  121. Run in shell: ./pktgen.conf-X-Y It does all the setup including sending.
  122. Interrupt affinity
  123. ===================
  124. Note when adding devices to a specific CPU there good idea to also assign
  125. /proc/irq/XX/smp_affinity so the TX-interrupts gets bound to the same CPU.
  126. as this reduces cache bouncing when freeing skb's.
  127. Current commands and configuration options
  128. ==========================================
  129. ** Pgcontrol commands:
  130. start
  131. stop
  132. ** Thread commands:
  133. add_device
  134. rem_device_all
  135. max_before_softirq
  136. ** Device commands:
  137. count
  138. clone_skb
  139. debug
  140. frags
  141. delay
  142. src_mac_count
  143. dst_mac_count
  144. pkt_size
  145. min_pkt_size
  146. max_pkt_size
  147. mpls
  148. udp_src_min
  149. udp_src_max
  150. udp_dst_min
  151. udp_dst_max
  152. flag
  153. IPSRC_RND
  154. TXSIZE_RND
  155. IPDST_RND
  156. UDPSRC_RND
  157. UDPDST_RND
  158. MACSRC_RND
  159. MACDST_RND
  160. dst_min
  161. dst_max
  162. src_min
  163. src_max
  164. dst_mac
  165. src_mac
  166. clear_counters
  167. dst6
  168. src6
  169. flows
  170. flowlen
  171. References:
  172. ftp://robur.slu.se/pub/Linux/net-development/pktgen-testing/
  173. ftp://robur.slu.se/pub/Linux/net-development/pktgen-testing/examples/
  174. Paper from Linux-Kongress in Erlangen 2004.
  175. ftp://robur.slu.se/pub/Linux/net-development/pktgen-testing/pktgen_paper.pdf
  176. Thanks to:
  177. Grant Grundler for testing on IA-64 and parisc, Harald Welte, Lennert Buytenhek
  178. Stephen Hemminger, Andi Kleen, Dave Miller and many others.
  179. Good luck with the linux net-development.