pktgen.txt
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:3k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. How to use the Linux packet generator module.
  2. 1. Enable CONFIG_NET_PKTGEN to compile and build pktgen.o, install it
  3.    in the place where insmod may find it.
  4. 2. Cut script "ipg" (see below).
  5. 3. Edit script to set preferred device and destination IP address.
  6. 3a.  Create more scripts for different interfaces.  Up to thirty-two
  7.      pktgen processes can be configured and run at once by using the
  8.      32 /proc/net/pg* files.
  9. 4. Run in shell: ". ipg"
  10. 5. After this two commands are defined:
  11.    A. "pg" to start generator and to get results.
  12.    B. "pgset" to change generator parameters. F.e.
  13.       pgset "multiskb 1"      use multiple SKBs for packet generation
  14.       pgset "multiskb 0"      use single SKB for all transmits
  15.       pgset "pkt_size 9014"   sets packet size to 9014
  16.       pgset "frags 5"         packet will consist of 5 fragments
  17.       pgset "count 200000"    sets number of packets to send, set to zero
  18.                               for continious sends untill explicitly
  19.                               stopped.
  20.       pgset "ipg 5000"        sets artificial gap inserted between packets
  21.                               to 5000 nanoseconds
  22.       pgset "dst 10.0.0.1"    sets IP destination address
  23.                               (BEWARE! This generator is very aggressive!)
  24.       pgset "dst_min 10.0.0.1"            Same as dst
  25.       pgset "dst_max 10.0.0.254"          Set the maximum destination IP.
  26.       pgset "src_min 10.0.0.1"            Set the minimum (or only) source IP.
  27.       pgset "src_max 10.0.0.254"          Set the maximum source IP.
  28.       pgset "dstmac 00:00:00:00:00:00"    sets MAC destination address
  29.       pgset "srcmac 00:00:00:00:00:00"    sets MAC source address
  30.       pgset "src_mac_count 1" Sets the number of MACs we'll range through.  The
  31.                               'minimum' MAC is what you set with srcmac.
  32.       pgset "dst_mac_count 1" Sets the number of MACs we'll range through.  The
  33.                               'minimum' MAC is what you set with dstmac.
  34.       pgset "flag [name]"     Set a flag to determine behaviour.  Current flags
  35.                               are: IPSRC_RND #IP Source is random (between min/max),
  36.                                    IPDST_RND, UDPSRC_RND,
  37.                                    UDPDST_RND, MACSRC_RND, MACDST_RND 
  38.       pgset "udp_src_min 9"   set UDP source port min, If < udp_src_max, then
  39.                               cycle through the port range.
  40.       pgset "udp_src_max 9"   set UDP source port max.
  41.       pgset "udp_dst_min 9"   set UDP destination port min, If < udp_dst_max, then
  42.                               cycle through the port range.
  43.       pgset "udp_dst_max 9"   set UDP destination port max.
  44.       pgset stop           aborts injection
  45.       
  46.   Also, ^C aborts generator.
  47. ---- cut here
  48. #! /bin/sh
  49. modprobe pktgen
  50. PGDEV=/proc/net/pg/pg0
  51. function pgset() {
  52.     local result
  53.     echo $1 > $PGDEV
  54.     result=`cat $PGDEV | fgrep "Result: OK:"`
  55.     if [ "$result" = "" ]; then
  56.          cat $PGDEV | fgrep Result:
  57.     fi
  58. }
  59. function pg() {
  60.     echo inject > $PGDEV
  61.     cat $PGDEV
  62. }
  63. pgset "odev eth0"
  64. pgset "dst 0.0.0.0"
  65. ---- cut here