pktgen.conf

    技术2022-08-01  73

    #! /bin/sh # FileName: pktgen-eth5-eth6.conf # modprobe pktgen function pgset() { local result echo $1 > $PGDEV result=`cat $PGDEV | fgrep "Result: OK:"` if [ "$result" = "" ]; then cat $PGDEV | fgrep Result: fi } function pg() { echo inject > $PGDEV cat $PGDEV } # Config Start Here ----------------------------------------------------------- # thread config # Each CPU has own thread. Two CPU exammple. We add eth1, eth2 respectivly. PGDEV=/proc/net/pktgen/kpktgend_2 echo "Removing all devices" pgset "rem_device_all" echo "Adding eth5" pgset "add_device eth5" PGDEV=/proc/net/pktgen/kpktgend_3 echo "Removing all devices" pgset "rem_device_all" echo "Adding eth6" pgset "add_device eth6" # device config # delay 0 means maximum speed. CLONE_SKB="clone_skb 1000000" # NIC adds 4 bytes CRC PKT_SIZE="pkt_size 60" # COUNT 0 means forever #COUNT="count 0" COUNT="count 0" DELAY="delay 0" PGDEV=/proc/net/pktgen/eth5 echo "Configuring $PGDEV" pgset "$COUNT" pgset "$CLONE_SKB" pgset "$PKT_SIZE" pgset "$DELAY" pgset "dst 192.168.1.96" pgset "dst_mac 00:0C:29:97:9B:BE" PGDEV=/proc/net/pktgen/eth6 echo "Configuring $PGDEV" pgset "$COUNT" pgset "$CLONE_SKB" pgset "$PKT_SIZE" pgset "$DELAY" pgset "dst 192.168.1.95" pgset "dst_mac 00:0C:29:97:9B:B4" # Time to run PGDEV=/proc/net/pktgen/pgctrl echo "Running... ctrl^C to stop" pgset "start" echo "Done" # Result can be vieved in /proc/net/pktgen/eth[5,6]

     

     

    pgset "clone_skb 1" sets the number of copies of the same packet pgset "clone_skb 0" use single SKB for all transmits pgset "pkt_size 9014" sets packet size to 9014 pgset "frags 5" packet will consist of 5 fragments pgset "count 200000" sets number of packets to send, set to zero for continious sends untill explicitl stopped. pgset "delay 5000" adds delay to hard_start_xmit(). nanoseconds pgset "dst 10.0.0.1" sets IP destination addres (BEWARE! This generator is very aggressive!) pgset "dst_min 10.0.0.1" Same as dst pgset "dst_max 10.0.0.254" Set the maximum destination IP. pgset "src_min 10.0.0.1" Set the minimum (or only) source IP. pgset "src_max 10.0.0.254" Set the maximum source IP. pgset "dst6 fec0::1" IPV6 destination address pgset "src6 fec0::2" IPV6 source address pgset "dstmac 00:00:00:00:00:00" sets MAC destination address pgset "srcmac 00:00:00:00:00:00" sets MAC source address pgset "src_mac_count 1" Sets the number of MACs we'll range through. The 'minimum' MAC is what you set with srcmac. pgset "dst_mac_count 1" Sets the number of MACs we'll range through. The 'minimum' MAC is what you set with dstmac. pgset "flag [name]" Set a flag to determine behaviour. Current flags are: IPSRC_RND #IP Source is random (between min/max), IPDST_RND, UDPSRC_RND, UDPDST_RND, MACSRC_RND, MACDST_RND pgset "udp_src_min 9" set UDP source port min, If < udp_src_max, then cycle through the port range. pgset "udp_src_max 9" set UDP source port max. pgset "udp_dst_min 9" set UDP destination port min, If < udp_dst_max, then cycle through the port range. pgset "udp_dst_max 9" set UDP destination port max. pgset stop aborts injection. Also, ^C aborts generator.

     

    #! /bin/sh #pktgen.conf-1-1 sample #modprobe pktgen # 写虚拟文件系统的函数, 每次操作之前, 设置好要操作的设备 $PGDEV 为 pgctl/kpktgend_X/ehtX function pgset() { local result echo $1 > $PGDEV result=`cat $PGDEV | fgrep "Result: OK:"` if [ "$result" = "" ]; then cat $PGDEV | fgrep Result: fi } function pg() { echo inject > $PGDEV cat $PGDEV } # Config Start Here ----------------------------------------------------------- # thread config # Each CPU has own thread. Two CPU exammple. We add eth1, eth2 respectivly. # 移除线程中对应的所有网口, 再添加 PGDEV=/proc/net/pktgen/kpktgend_0 echo "Removing all devices" pgset "rem_device_all" echo "Adding eth1" pgset "add_device eth1" echo "Setting max_before_softirq 10000" pgset "max_before_softirq 10000" # device config # ipg is inter packet gap. 0 means maximum speed. CLONE_SKB="clone_skb 1000000" # NIC adds 4 bytes CRC PKT_SIZE="pkt_size 60" # COUNT 0 means forever #COUNT="count 0" COUNT="count 10000000" # ipg 参数在我实验的时候无效, 我从2.6.32的源码中也没有看到相关的设置, 可以将 ipg 相关的配置删掉 #IPG="ipg 0" PGDEV=/proc/net/pktgen/eth1 echo "Configuring $PGDEV" pgset "$COUNT" pgset "$CLONE_SKB" pgset "$PKT_SIZE" #pgset "$IPG" # 配置目标IP pgset "dst 10.10.11.2" # 配置目标MAC pgset "dst_mac 00:04:23:08:91:dc" # Time to run PGDEV=/proc/net/pktgen/pgctrl # 发送 start 给 pgctl, 让 pktgen 开始发包 echo "Running... ctrl^C to stop" pgset "start" echo "Done" # Result can be vieved in /proc/net/pktgen/eth1

     

    Processed: 0.011, SQL: 9