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 to the first |
| 22 | # and leave the second idle. |
Ben Hutchings | 7c95a9d | 2015-02-24 02:32:07 +0000 | [diff] [blame] | 23 | |
| 24 | PGDEV=/proc/net/pktgen/kpktgend_0 |
| 25 | echo "Removing all devices" |
| 26 | pgset "rem_device_all" |
| 27 | echo "Adding eth1" |
| 28 | pgset "add_device eth1" |
Ben Hutchings | 7c95a9d | 2015-02-24 02:32:07 +0000 | [diff] [blame] | 29 | |
| 30 | # We need to remove old config since we dont use this thread. We can only |
| 31 | # one NIC on one CPU due to affinity reasons. |
| 32 | |
| 33 | PGDEV=/proc/net/pktgen/kpktgend_1 |
| 34 | echo "Removing all devices" |
| 35 | pgset "rem_device_all" |
| 36 | |
| 37 | # device config |
| 38 | # delay 0 means maximum speed. |
| 39 | |
| 40 | CLONE_SKB="clone_skb 1000000" |
| 41 | # NIC adds 4 bytes CRC |
| 42 | PKT_SIZE="pkt_size 60" |
| 43 | |
| 44 | # COUNT 0 means forever |
| 45 | #COUNT="count 0" |
| 46 | COUNT="count 10000000" |
| 47 | DELAY="delay 0" |
| 48 | |
| 49 | PGDEV=/proc/net/pktgen/eth1 |
| 50 | echo "Configuring $PGDEV" |
| 51 | pgset "$COUNT" |
| 52 | pgset "$CLONE_SKB" |
| 53 | pgset "$PKT_SIZE" |
| 54 | pgset "$DELAY" |
| 55 | pgset "dst 10.10.11.2" |
| 56 | pgset "dst_mac 00:04:23:08:91:dc" |
| 57 | |
| 58 | |
| 59 | # Time to run |
| 60 | PGDEV=/proc/net/pktgen/pgctrl |
| 61 | |
| 62 | echo "Running... ctrl^C to stop" |
Ben Hutchings | 16b5d0c | 2015-02-24 02:33:08 +0000 | [diff] [blame] | 63 | trap true INT |
Ben Hutchings | 7c95a9d | 2015-02-24 02:32:07 +0000 | [diff] [blame] | 64 | pgset "start" |
| 65 | echo "Done" |
Ben Hutchings | 4062bd2 | 2015-02-24 02:33:20 +0000 | [diff] [blame] | 66 | cat /proc/net/pktgen/eth1 |