Ben Hutchings | db72aba | 2015-02-24 02:32:59 +0000 | [diff] [blame] | 1 | #!/bin/bash |
Ben Hutchings | 7c95a9d | 2015-02-24 02:32:07 +0000 | [diff] [blame] | 2 | |
| 3 | #modprobe pktgen |
| 4 | |
| 5 | |
| 6 | function pgset() { |
| 7 | local result |
| 8 | |
| 9 | echo $1 > $PGDEV |
| 10 | |
| 11 | result=`cat $PGDEV | fgrep "Result: OK:"` |
| 12 | if [ "$result" = "" ]; then |
| 13 | cat $PGDEV | fgrep Result: |
| 14 | fi |
| 15 | } |
| 16 | |
Ben Hutchings | 7c95a9d | 2015-02-24 02:32:07 +0000 | [diff] [blame] | 17 | # Config Start Here ----------------------------------------------------------- |
| 18 | |
| 19 | |
| 20 | # thread config |
Ben Hutchings | 2ad1cdf | 2015-02-24 02:32:37 +0000 | [diff] [blame] | 21 | # Each CPU has its own thread. Two CPU example. We add eth1, eth2 respectively. |
Ben Hutchings | 7c95a9d | 2015-02-24 02:32:07 +0000 | [diff] [blame] | 22 | |
| 23 | PGDEV=/proc/net/pktgen/kpktgend_0 |
| 24 | echo "Removing all devices" |
| 25 | pgset "rem_device_all" |
| 26 | echo "Adding eth1" |
| 27 | pgset "add_device eth1" |
Ben Hutchings | 7c95a9d | 2015-02-24 02:32:07 +0000 | [diff] [blame] | 28 | |
| 29 | PGDEV=/proc/net/pktgen/kpktgend_1 |
| 30 | echo "Removing all devices" |
| 31 | pgset "rem_device_all" |
| 32 | echo "Adding eth2" |
| 33 | pgset "add_device eth2" |
Ben Hutchings | 7c95a9d | 2015-02-24 02:32:07 +0000 | [diff] [blame] | 34 | |
| 35 | |
| 36 | # device config |
| 37 | # delay 0 means maximum speed. |
| 38 | |
| 39 | CLONE_SKB="clone_skb 1000000" |
| 40 | # NIC adds 4 bytes CRC |
| 41 | PKT_SIZE="pkt_size 60" |
| 42 | |
| 43 | # COUNT 0 means forever |
| 44 | #COUNT="count 0" |
| 45 | COUNT="count 10000000" |
| 46 | DELAY="delay 0" |
| 47 | |
| 48 | PGDEV=/proc/net/pktgen/eth1 |
| 49 | echo "Configuring $PGDEV" |
| 50 | pgset "$COUNT" |
| 51 | pgset "$CLONE_SKB" |
| 52 | pgset "$PKT_SIZE" |
| 53 | pgset "$DELAY" |
| 54 | pgset "dst 10.10.11.2" |
| 55 | pgset "dst_mac 00:04:23:08:91:dc" |
| 56 | |
| 57 | PGDEV=/proc/net/pktgen/eth2 |
| 58 | echo "Configuring $PGDEV" |
| 59 | pgset "$COUNT" |
| 60 | pgset "$CLONE_SKB" |
| 61 | pgset "$PKT_SIZE" |
| 62 | pgset "$DELAY" |
| 63 | pgset "dst 192.168.2.2" |
| 64 | pgset "dst_mac 00:04:23:08:91:de" |
| 65 | |
| 66 | # Time to run |
| 67 | PGDEV=/proc/net/pktgen/pgctrl |
| 68 | |
| 69 | echo "Running... ctrl^C to stop" |
Ben Hutchings | 16b5d0c | 2015-02-24 02:33:08 +0000 | [diff] [blame] | 70 | trap true INT |
Ben Hutchings | 7c95a9d | 2015-02-24 02:32:07 +0000 | [diff] [blame] | 71 | pgset "start" |
| 72 | echo "Done" |
Ben Hutchings | 4062bd2 | 2015-02-24 02:33:20 +0000 | [diff] [blame] | 73 | cat /proc/net/pktgen/eth1 /proc/net/pktgen/eth2 |