pktgen.txt 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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 stop aborts injection. Also, ^C aborts generator.
  85. Example scripts
  86. ===============
  87. A collection of small tutorial scripts for pktgen is in expamples dir.
  88. pktgen.conf-1-1 # 1 CPU 1 dev
  89. pktgen.conf-1-2 # 1 CPU 2 dev
  90. pktgen.conf-2-1 # 2 CPU's 1 dev
  91. pktgen.conf-2-2 # 2 CPU's 2 dev
  92. pktgen.conf-1-1-rdos # 1 CPU 1 dev w. route DoS
  93. pktgen.conf-1-1-ip6 # 1 CPU 1 dev ipv6
  94. pktgen.conf-1-1-ip6-rdos # 1 CPU 1 dev ipv6 w. route DoS
  95. pktgen.conf-1-1-flows # 1 CPU 1 dev multiple flows.
  96. Run in shell: ./pktgen.conf-X-Y It does all the setup including sending.
  97. Interrupt affinity
  98. ===================
  99. Note when adding devices to a specific CPU there good idea to also assign
  100. /proc/irq/XX/smp_affinity so the TX-interrupts gets bound to the same CPU.
  101. as this reduces cache bouncing when freeing skb's.
  102. Current commands and configuration options
  103. ==========================================
  104. ** Pgcontrol commands:
  105. start
  106. stop
  107. ** Thread commands:
  108. add_device
  109. rem_device_all
  110. max_before_softirq
  111. ** Device commands:
  112. count
  113. clone_skb
  114. debug
  115. frags
  116. delay
  117. src_mac_count
  118. dst_mac_count
  119. pkt_size
  120. min_pkt_size
  121. max_pkt_size
  122. udp_src_min
  123. udp_src_max
  124. udp_dst_min
  125. udp_dst_max
  126. flag
  127. IPSRC_RND
  128. TXSIZE_RND
  129. IPDST_RND
  130. UDPSRC_RND
  131. UDPDST_RND
  132. MACSRC_RND
  133. MACDST_RND
  134. dst_min
  135. dst_max
  136. src_min
  137. src_max
  138. dst_mac
  139. src_mac
  140. clear_counters
  141. dst6
  142. src6
  143. flows
  144. flowlen
  145. References:
  146. ftp://robur.slu.se/pub/Linux/net-development/pktgen-testing/
  147. ftp://robur.slu.se/pub/Linux/net-development/pktgen-testing/examples/
  148. Paper from Linux-Kongress in Erlangen 2004.
  149. ftp://robur.slu.se/pub/Linux/net-development/pktgen-testing/pktgen_paper.pdf
  150. Thanks to:
  151. Grant Grundler for testing on IA-64 and parisc, Harald Welte, Lennert Buytenhek
  152. Stephen Hemminger, Andi Kleen, Dave Miller and many others.
  153. Good luck with the linux net-development.