#! /bin/sh

modprobe pktgen


function pgset() {
    local result

    echo $1 > $PGDEV
    echo 1

    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 eth0, eth2 respectivly.

PGDEV=/proc/net/pktgen/kpktgend_0
  echo "Removing all devices"
 pgset "rem_device_all" 
  echo "Adding eth0"
 pgset "add_device eth0" 
  echo "Setting max_before_softirq 10000"
 pgset "max_before_softirq 10000"


# device config
# delay 0
# We need to do alloc for every skb since we cannot clone here.

CLONE_SKB="clone_skb 0"
# NIC adds 4 bytes CRC
PKT_SIZE="pkt_size 600"

# COUNT 0 means forever
#COUNT="count 0"
COUNT="count 100000000"
#COUNT="count 1000"
DELAY="delay 3000"

PGDEV=/proc/net/pktgen/eth0
  echo "Configuring $PGDEV"
 pgset "$COUNT"
 pgset "$CLONE_SKB"
 pgset "$PKT_SIZE"
 pgset "$DELAY"
 # Random address with in the min-max range
 pgset "flag IPDST_RND" 
 pgset "dst_min 10.0.0.0" 
 pgset "dst_max 10.0.255.255" 

 # 8k Concurrent flows at 4 pkts
 #pgset "flows 8192" 
 pgset "flows 2048" 
 pgset "flowlen 4" 

 pgset "dst_mac  00:1b:24:bd:e9:cc"

# 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/eth0

