lost and found ( for me ? )

pktgen : packet generator

In short , pktgen is a packet generator tool.
With pktgen , you can send small packets , such as 64bytes packets , and you can also assign a CPU core to a specific NIC for generating traffic.

I just referred to http://www.linuxfoundation.org/collaborate/workgroups/networking/pktgen. many thanks !

# uname –ri
3.2.0-34-virtual x86_64

# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 12.04.1 LTS
Release:        12.04
Codename:       precise


confirm pktgen module has been installed.
# modinfo pktgen
filename:       /lib/modules/3.2.0-34-virtual/kernel/net/core/pktgen.ko
version:        2.74
license:        GPL
description:    Packet Generator tool
author:         Robert Olsson <robert.olsson@its.uu.se>
srcversion:     B34DE3D9C4CC746E0B50842
depends:
intree:         Y
vermagic:       3.2.0-34-virtual SMP mod_unload modversions
parm:           pg_count_d:Default number of packets to inject (int)
parm:           pg_delay_d:Default delay between packets (nanoseconds) (int)
parm:           pg_clone_skb_d:Default number of copies of the same packet (int)
parm:           debug:Enable debugging of pktgen module (int)


Network topology
-- eth1 ubuntu eth2 --
|                             |
----------- vSW ---------


eth1 : 192.168.30.100 , MAC 52:54:00:14:d3:f1
eth2 : 192.168.30.101 , MAC 52:54:00:cd:fb:85

eth1 and eth2 are in the same VLAN.

download sample script from ftp://robur.slu.se/pub/Linux/net-development/pktgen-testing/examples/
# wget ftp://robur.slu.se/pub/Linux/net-development/pktgen-testing/examples/pktgen.conf-2-2


pktgen.conf-2-2 is a sample script for 2 CPUs , 2 NICs.
My Ubuntu VM has 2 vCPUs and 2 vNICs , so I’ll use this script.
# mv pktgen.conf-2-2 pktgen.conf-2-2.sh
# chmod u+x pktgen.conf-2-2.sh


edit pktgen.conf-2-2.sh
I edited red line.
#!/bin/sh

#modprobe pktgen
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_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"

PGDEV=/proc/net/pktgen/kpktgend_1
 echo "Removing all devices"
pgset "rem_device_all"
 echo "Adding eth2"
pgset "add_device eth2"
 echo "Setting max_before_softirq 10000"
pgset "max_before_softirq 10000"


# 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 10000000"
DELAY="delay 0"

PGDEV=/proc/net/pktgen/eth1
 echo "Configuring $PGDEV"
pgset "$COUNT"
pgset "$CLONE_SKB"
pgset "$PKT_SIZE"
pgset "$DELAY"
pgset "dst 192.168.30.101"
pgset "dst_mac  52:54:00:cd:fb:85"

PGDEV=/proc/net/pktgen/eth2
 echo "Configuring $PGDEV"
pgset "$COUNT"
pgset "$CLONE_SKB"
pgset "$PKT_SIZE"
pgset "$DELAY"
pgset "dst 192.168.30.100"
pgset "dst_mac  52:54:00:14:d3:f1"

# 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[1,2]


run the script
error
# ./pktgen.conf-2-2.sh
./pktgen.conf-2-2.sh: 6: ./pktgen.conf-2-2.sh: Syntax error: "(" unexpected


edit the script

from
1 #!/bin/sh


to
1 #!/bin/bash


run the script again.
# ./pktgen.conf-2-2.sh
Removing all devices
Adding eth1
Setting max_before_softirq 10000
Removing all devices
Adding eth2
Setting max_before_softirq 10000
Configuring /proc/net/pktgen/eth1
Configuring /proc/net/pktgen/eth2
Running... ctrl^C to stop


- stats

eth1
# cat /proc/net/pktgen/eth1
Params: count 10000000  min_pkt_size: 60  max_pkt_size: 60
    frags: 0  delay: 0  clone_skb: 1000000  ifname: eth1
    flows: 0 flowlen: 0
    queue_map_min: 0  queue_map_max: 0
    dst_min: 192.168.30.101  dst_max:
       src_min:   src_max:
    src_mac: 52:54:00:14:d3:f1 dst_mac: 52:54:00:cd:fb:85
    udp_src_min: 9  udp_src_max: 9  udp_dst_min: 9  udp_dst_max: 9
    src_mac_count: 0  dst_mac_count: 0
    Flags:
Current:
    pkts-sofar: 612783  errors: 0
    started: 4718340134us  stopped: 4736156921us idle: 232438us
    seq_num: 612784  cur_dst_mac_offset: 0  cur_src_mac_offset: 0
    cur_saddr: 0x641ea8c0  cur_daddr: 0x651ea8c0
    cur_udp_dst: 9  cur_udp_src: 9
    cur_queue_map: 0
    flows: 0


eth2
# cat /proc/net/pktgen/eth2
Params: count 10000000  min_pkt_size: 60  max_pkt_size: 60
    frags: 0  delay: 0  clone_skb: 1000000  ifname: eth2
    flows: 0 flowlen: 0
    queue_map_min: 0  queue_map_max: 0
    dst_min: 192.168.30.100  dst_max:
       src_min:   src_max:
    src_mac: 52:54:00:cd:fb:85 dst_mac: 52:54:00:14:d3:f1
    udp_src_min: 9  udp_src_max: 9  udp_dst_min: 9  udp_dst_max: 9
    src_mac_count: 0  dst_mac_count: 0
    Flags:
Current:
    pkts-sofar: 878218  errors: 0
    started: 4718340133us  stopped: 4775020348us idle: 5393504us
    seq_num: 878219  cur_dst_mac_offset: 0  cur_src_mac_offset: 0
    cur_saddr: 0x651ea8c0  cur_daddr: 0x641ea8c0
    cur_udp_dst: 9  cur_udp_src: 9
    cur_queue_map: 0
    flows: 0
Result: Starting


packet cap data
# tshark -V -r aaa.pcap -R '(frame.number == 1)'
Frame 1: 60 bytes on wire (480 bits), 60 bytes captured (480 bits)
   Arrival Time: Dec  1, , 2012 07:03:25.510239000 UTC
   Epoch Time: 1354518205.510239000 seconds
   [Time delta from previous captured frame: 0.000000000 seconds]
   [Time delta from previous displayed frame: 0.000000000 seconds]
   [Time since reference or first frame: 0.000000000 seconds]
   Frame Number: 1
   Frame Length: 60 bytes (480 bits)
   Capture Length: 60 bytes (480 bits)
   [Frame is marked: False]
   [Frame is ignored: False]
   [Protocols in frame: eth:ip:udp:pktgen:data]
Ethernet II, Src: RealtekU_cd:fb:85 (52:54:00:cd:fb:85), Dst: RealtekU_14:d3:f1 (52:54:00:14:d3:f1)
   Destination: RealtekU_14:d3:f1 (52:54:00:14:d3:f1)
       Address: RealtekU_14:d3:f1 (52:54:00:14:d3:f1)
       .... ...0 .... .... .... .... = IG bit: Individual address (unicast)
       .... ..1. .... .... .... .... = LG bit: Locally administered address (this is NOT the factory default)
   Source: RealtekU_cd:fb:85 (52:54:00:cd:fb:85)
       Address: RealtekU_cd:fb:85 (52:54:00:cd:fb:85)
       .... ...0 .... .... .... .... = IG bit: Individual address (unicast)
       .... ..1. .... .... .... .... = LG bit: Locally administered address (this is NOT the factory default)
   Type: IP (0x0800)
Internet Protocol Version 4, Src: 192.168.30.101 (192.168.30.101), Dst: 192.168.30.100 (192.168.30.100)
   Version: 4
   Header length: 20 bytes
   Differentiated Services Field: 0x00 (DSCP 0x00: Default; ECN: 0x00: Not-ECT (Not ECN-Capable Transport))
       0000 00.. = Differentiated Services Codepoint: Default (0x00)
       .... ..00 = Explicit Congestion Notification: Not-ECT (Not ECN-Capable Transport) (0x00)
   Total Length: 46
   Identification: 0x0000 (0)
   Flags: 0x00
       0... .... = Reserved bit: Not set
       .0.. .... = Don't fragment: Not set
       ..0. .... = More fragments: Not set
   Fragment offset: 0
   Time to live: 32
   Protocol: UDP (17)
   Header checksum: 0xdca5 [correct]
       [Good: True]
       [Bad: False]
   Source: 192.168.30.101 (192.168.30.101)
   Destination: 192.168.30.100 (192.168.30.100)
User Datagram Protocol, Src Port: discard (9), Dst Port: discard (9)
   Source port: discard (9)
   Destination port: discard (9)
   Length: 26
   Checksum: 0x0000 (none)
       [Good Checksum: False]
       [Bad Checksum: False]
Linux Kernel Packet Generator
   Magic number: 0xbe9be955
   Sequence number: 1
   [Timestamp tvsec: 1354518173]
   [Timestamp tvusec: 956631]
   Timestamp: Dec  1, , 2012 07:02:53.956631000 UTC
   Data (2 bytes)

0000  00 00                                             ..
       Data: 0000
       [Length: 2]


when changing packet size from 64 to 1518
# NIC adds 4 bytes CRC
#PKT_SIZE="pkt_size 60"
PKT_SIZE="pkt_size 1514"


packet cap data
# tshark -V -r zz.pcap -R '(frame.number == 1)'
Frame 1: 1514 bytes on wire (12112 bits), 1514 bytes captured (12112 bits)
   Arrival Time: Dec  1, , 2012 07:23:48.510236000 UTC
   Epoch Time: 1354519428.510236000 seconds
   [Time delta from previous captured frame: 0.000000000 seconds]
   [Time delta from previous displayed frame: 0.000000000 seconds]
   [Time since reference or first frame: 0.000000000 seconds]
   Frame Number: 1
   Frame Length: 1514 bytes (12112 bits)
   Capture Length: 1514 bytes (12112 bits)
   [Frame is marked: False]
   [Frame is ignored: False]
   [Protocols in frame: eth:ip:udp:pktgen:data]
Ethernet II, Src: RealtekU_cd:fb:85 (52:54:00:cd:fb:85), Dst: RealtekU_14:d3:f1 (52:54:00:14:d3:f1)
   Destination: RealtekU_14:d3:f1 (52:54:00:14:d3:f1)
       Address: RealtekU_14:d3:f1 (52:54:00:14:d3:f1)
       .... ...0 .... .... .... .... = IG bit: Individual address (unicast)
       .... ..1. .... .... .... .... = LG bit: Locally administered address (this is NOT the factory default)
   Source: RealtekU_cd:fb:85 (52:54:00:cd:fb:85)
       Address: RealtekU_cd:fb:85 (52:54:00:cd:fb:85)
       .... ...0 .... .... .... .... = IG bit: Individual address (unicast)
       .... ..1. .... .... .... .... = LG bit: Locally administered address (this is NOT the factory default)
   Type: IP (0x0800)
Internet Protocol Version 4, Src: 192.168.30.101 (192.168.30.101), Dst: 192.168.30.100 (192.168.30.100)
   Version: 4
   Header length: 20 bytes
   Differentiated Services Field: 0x00 (DSCP 0x00: Default; ECN: 0x00: Not-ECT (Not ECN-Capable Transport))
       0000 00.. = Differentiated Services Codepoint: Default (0x00)
       .... ..00 = Explicit Congestion Notification: Not-ECT (Not ECN-Capable Transport) (0x00)
   Total Length: 1500
   Identification: 0x0000 (0)
   Flags: 0x00
       0... .... = Reserved bit: Not set
       .0.. .... = Don't fragment: Not set
       ..0. .... = More fragments: Not set
   Fragment offset: 0
   Time to live: 32
   Protocol: UDP (17)
   Header checksum: 0xd6f7 [correct]
       [Good: True]
       [Bad: False]
   Source: 192.168.30.101 (192.168.30.101)
   Destination: 192.168.30.100 (192.168.30.100)
User Datagram Protocol, Src Port: discard (9), Dst Port: discard (9)
   Source port: discard (9)
   Destination port: discard (9)
   Length: 1480
   Checksum: 0x0000 (none)
       [Good Checksum: False]
       [Bad Checksum: False]
Linux Kernel Packet Generator
   Magic number: 0xbe9be955
   Sequence number: 1
   [Timestamp tvsec: 1354519422]
   [Timestamp tvusec: 424679]
   Timestamp: Dec  1, , 2012 07:23:42.424679000 UTC
   Data (1456 bytes)

0000  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
0010  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
0020  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
<snip>
       [Length: 1456]

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.