Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6e32a74a authored by Daniel T. Lee's avatar Daniel T. Lee Committed by David S. Miller
Browse files

samples: pktgen: allow to specify destination port



Currently, kernel pktgen has the feature to specify udp destination port
for sending packet. (e.g. pgset "udp_dst_min 9")

But on samples, each of the scripts doesn't have any option to achieve this.

This commit adds the DST_PORT option to specify the target port(s) in the script.

    -p : ($DST_PORT)  destination PORT range (e.g. 433-444) is also allowed

Signed-off-by: default avatarDaniel T. Lee <danieltimlee@gmail.com>
Acked-by: default avatarJesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 226b96c2
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ across the sample scripts. Usage example is printed on errors::
  -s : ($PKT_SIZE)  packet size
  -d : ($DEST_IP)   destination IP
  -m : ($DST_MAC)   destination MAC-addr
  -p : ($DST_PORT)  destination PORT range (e.g. 433-444) is also allowed
  -t : ($THREADS)   threads to start
  -f : ($F_THREAD)  index of first thread (zero indexed CPU number)
  -c : ($SKB_CLONE) SKB clones send before alloc new SKB
+6 −1
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ function usage() {
    echo "  -s : (\$PKT_SIZE)  packet size"
    echo "  -d : (\$DEST_IP)   destination IP"
    echo "  -m : (\$DST_MAC)   destination MAC-addr"
    echo "  -p : (\$DST_PORT)  destination PORT range (e.g. 433-444) is also allowed"
    echo "  -t : (\$THREADS)   threads to start"
    echo "  -f : (\$F_THREAD)  index of first thread (zero indexed CPU number)"
    echo "  -c : (\$SKB_CLONE) SKB clones send before alloc new SKB"
@@ -23,7 +24,7 @@ function usage() {

##  --- Parse command line arguments / parameters ---
## echo "Commandline options:"
while getopts "s:i:d:m:f:t:c:n:b:vxh6" option; do
while getopts "s:i:d:m:p:f:t:c:n:b:vxh6" option; do
    case $option in
        i) # interface
          export DEV=$OPTARG
@@ -41,6 +42,10 @@ while getopts "s:i:d:m:f:t:c:n:b:vxh6" option; do
          export DST_MAC=$OPTARG
	  info "Destination MAC set to: DST_MAC=$DST_MAC"
          ;;
        p) # PORT
          export DST_PORT=$OPTARG
	  info "Destination PORT set to: DST_PORT=$DST_PORT"
          ;;
        f)
	  export F_THREAD=$OPTARG
	  info "Index of first thread (zero indexed CPU number): $F_THREAD"
+11 −0
Original line number Diff line number Diff line
@@ -41,6 +41,10 @@ fi
[ -z "$DST_MAC" ] && DST_MAC="90:e2:ba:ff:ff:ff"
[ -z "$BURST" ] && BURST=1024
[ -z "$COUNT" ] && COUNT="10000000" # Zero means indefinitely
if [ -n "$DST_PORT" ]; then
    read -r DST_MIN DST_MAX <<< $(parse_ports $DST_PORT)
    validate_ports $DST_MIN $DST_MAX
fi

# Base Config
DELAY="0"        # Zero means max speed
@@ -69,6 +73,13 @@ for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
    pg_set $dev "dst_mac $DST_MAC"
    pg_set $dev "dst$IP6 $DEST_IP"

    if [ -n "$DST_PORT" ]; then
	# Single destination port or random port range
	pg_set $dev "flag UDPDST_RND"
	pg_set $dev "udp_dst_min $DST_MIN"
	pg_set $dev "udp_dst_max $DST_MAX"
    fi

    # Inject packet into RX path of stack
    pg_set $dev "xmit_mode netif_receive"

+11 −0
Original line number Diff line number Diff line
@@ -24,6 +24,10 @@ if [[ -n "$BURST" ]]; then
    err 1 "Bursting not supported for this mode"
fi
[ -z "$COUNT" ] && COUNT="10000000" # Zero means indefinitely
if [ -n "$DST_PORT" ]; then
    read -r DST_MIN DST_MAX <<< $(parse_ports $DST_PORT)
    validate_ports $DST_MIN $DST_MAX
fi

# Base Config
DELAY="0"        # Zero means max speed
@@ -52,6 +56,13 @@ for ((thread = $F_THREAD; thread <= $L_THREAD; thread++)); do
    pg_set $dev "dst_mac $DST_MAC"
    pg_set $dev "dst$IP6 $DEST_IP"

    if [ -n "$DST_PORT" ]; then
	# Single destination port or random port range
	pg_set $dev "flag UDPDST_RND"
	pg_set $dev "udp_dst_min $DST_MIN"
	pg_set $dev "udp_dst_max $DST_MAX"
    fi

    # Inject packet into TX qdisc egress path of stack
    pg_set $dev "xmit_mode queue_xmit"
done
+11 −0
Original line number Diff line number Diff line
@@ -22,6 +22,10 @@ fi
# Example enforce param "-m" for dst_mac
[ -z "$DST_MAC" ] && usage && err 2 "Must specify -m dst_mac"
[ -z "$COUNT" ]   && COUNT="100000" # Zero means indefinitely
if [ -n "$DST_PORT" ]; then
    read -r DST_MIN DST_MAX <<< $(parse_ports $DST_PORT)
    validate_ports $DST_MIN $DST_MAX
fi

# Base Config
DELAY="0"        # Zero means max speed
@@ -59,6 +63,13 @@ pg_set $DEV "flag NO_TIMESTAMP"
pg_set $DEV "dst_mac $DST_MAC"
pg_set $DEV "dst$IP6 $DEST_IP"

if [ -n "$DST_PORT" ]; then
    # Single destination port or random port range
    pg_set $DEV "flag UDPDST_RND"
    pg_set $DEV "udp_dst_min $DST_MIN"
    pg_set $DEV "udp_dst_max $DST_MAX"
fi

# Setup random UDP port src range
pg_set $DEV "flag UDPSRC_RND"
pg_set $DEV "udp_src_min $UDP_MIN"
Loading