Skip to contentSkip to conversation

pktgen: cleanups and introducing new samples/pktgen scripts

PATCH Superseded Jesper Dangaard Brouer 3 participants 16 messages May 19, 2015 – May 21, 2015

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover pktgen: cleanups and introducing new samples/pktgen scripts

This patchset is focused on making pktgen easier to use and better documented. It contains a number of documentation updates and minor changes to pktgen. The major contribution is introduction of common helper function for sample scripts.

Instead of the old pgset() function, three new shell functions for configuring the different components of pktgen are introduced:
pg_ctrl(), pg_thread() and pg_set().

The new functions correspond to pktgens different components.
* pg_ctrl() control "pgctrl" (/proc/net/pktgen/pgctrl)
* pg_thread() control the kernel threads and binding to devices
* pg_set() control setup of individual devices

Helpers also provide consistent parameter parsing across the sample scripts.

Usage example:
./pktgen_sample01_simple.sh -i eth41 -m 00:12:C0:02:AC:5A -d 192.168.41.2

Usage: ./pktgen_sample01_simple.sh [-vx] -i ethX

  -i : ($DEV)       output interface/device (required)
  -s : ($PKT_SIZE)  packet size
  -d : ($DEST_IP)   destination IP
  -m : ($DST_MAC)   destination MAC-addr
  -t : ($THREADS)   threads to start
  -c : ($SKB_CLONE) SKB clones send before alloc new SKB
  -b : ($BURST)     HW level bursting of SKBs
  -v : ($VERBOSE)   verbose
  -x : ($DEBUG)     debug

These scripts and helpers are borrowed from:
https://github.com/netoptimizer/network-testing/tree/master/pktgen

---

Jesper Dangaard Brouer (10):
pktgen: add benchmark script pktgen_bench_xmit_mode_netif_receive.sh
pktgen: add sample script pktgen_sample03_burst_single_flow.sh
pktgen: add sample script pktgen_sample02_multiqueue.sh
pktgen: add sample script pktgen_sample01_simple.sh
pktgen: new pktgen helper functions for samples scripts
pktgen: make /proc/net/pktgen/pgctrl report fail on invalid input
pktgen: document ability to add same device to several threads
pktgen: doc were missing several config options
pktgen: adjust spacing in proc file interface output
pktgen: remove obsolete "max_before_softirq" from pktgen doc

 Documentation/networking/pktgen.txt                |  141 ++++++++++++++------
 net/core/pktgen.c                                  |    6 -
 samples/pktgen/README.rst                          |   43 ++++++
 samples/pktgen/functions.sh                        |  120 +++++++++++++++++
 samples/pktgen/parameters.sh                       |   97 ++++++++++++++
 samples/pktgen/pktgen.conf-1-1                     |   59 --------
 samples/pktgen/pktgen.conf-2-1                     |   66 ---------
 samples/pktgen/pktgen.conf-2-2                     |   73 ----------
 .../pktgen/pktgen_bench_xmit_mode_netif_receive.sh |   86 ++++++++++++
 samples/pktgen/pktgen_sample01_simple.sh           |   71 ++++++++++
 samples/pktgen/pktgen_sample02_multiqueue.sh       |   75 +++++++++++
 .../pktgen/pktgen_sample03_burst_single_flow.sh    |   82 ++++++++++++
 12 files changed, 677 insertions(+), 242 deletions(-)
 create mode 100644 samples/pktgen/README.rst
 create mode 100644 samples/pktgen/functions.sh
 create mode 100644 samples/pktgen/parameters.sh
 delete mode 100755 samples/pktgen/pktgen.conf-1-1
 delete mode 100755 samples/pktgen/pktgen.conf-2-1
 delete mode 100755 samples/pktgen/pktgen.conf-2-2
 create mode 100755 samples/pktgen/pktgen_bench_xmit_mode_netif_receive.sh
 create mode 100755 samples/pktgen/pktgen_sample01_simple.sh
 create mode 100755 samples/pktgen/pktgen_sample02_multiqueue.sh
 create mode 100755 samples/pktgen/pktgen_sample03_burst_single_flow.sh
#1 lore raw

PATCH 1/10 pktgen: remove obsolete "max_before_softirq" from pktgen doc

And cleanup some whitespaces in pktgen.txt.

---

 Documentation/networking/pktgen.txt |   18 ++++++++----------
 1 files changed, 8 insertions(+), 10 deletions(-)
Documentation/networking/pktgen.txt +8 -10
index 747facc..62f5ebb 100644
@@ -1,6 +1,6 @@
 
 
-                  HOWTO for the linux packet generator 
+                  HOWTO for the linux packet generator
                   ------------------------------------
 
 Enable CONFIG_NET_PKTGEN to compile and build pktgen either in-kernel
@@ -52,11 +52,10 @@ For ixgbe use e.g. "30" resulting in approx 33K interrupts/sec (1/30*10^6):
 
 Viewing threads
 ===============
-/proc/net/pktgen/kpktgend_0 
-Name: kpktgend_0  max_before_softirq: 10000
-Running: 
-Stopped: eth1 
-Result: OK: max_before_softirq=10000
+/proc/net/pktgen/kpktgend_0
+Running:
+Stopped: eth1
+Result: OK: add_device=eth1
 
 Most important are the devices assigned to the thread.  Note that a
 device can only belong to one thread.
@@ -69,7 +68,7 @@ The Params section holds configured information.  The Current section
 holds running statistics.  The Result is printed after a run or after
 interruption.  Example:
 
-/proc/net/pktgen/eth1       
+/proc/net/pktgen/eth1
 
 Params: count 10000000  min_pkt_size: 60  max_pkt_size: 60
      frags: 0  delay: 0  clone_skb: 1000000  ifname: eth1
@@ -126,7 +125,7 @@ Examples:
                          To select queue 1 of a given device,
                          use queue_map_min=1 and queue_map_max=1
 
- pgset "src_mac_count 1" Sets the number of MACs we'll range through.  
+ pgset "src_mac_count 1" Sets the number of MACs we'll range through.
                          The 'minimum' MAC is what you set with srcmac.
 
  pgset "dst_mac_count 1" Sets the number of MACs we'll range through.
@@ -247,7 +246,6 @@ stop
 
 add_device
 rem_device_all
-max_before_softirq
 
 
 ** Device commands:
@@ -262,7 +260,7 @@ delay
 src_mac_count
 dst_mac_count
 
-pkt_size 
+pkt_size
 min_pkt_size
 max_pkt_size
 
#2 lore raw

PATCH 2/10 pktgen: adjust spacing in proc file interface output

In reply to Jesper Dangaard Brouer

Too many spaces were introduced in commit 63adc6fb8ac0 ("pktgen: cleanup checkpatch warnings"), thus misaligning "src_min:" to other columns.

Fixes 63adc6fb8ac0 ("pktgen: cleanup checkpatch warnings")

---

 net/core/pktgen.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
net/core/pktgen.c +1 -1
index 62f9799..167e592 100644
@@ -572,7 +572,7 @@ static int pktgen_if_show(struct seq_file *seq, void *v)
 			   "     dst_min: %s  dst_max: %s\n",
 			   pkt_dev->dst_min, pkt_dev->dst_max);
 		seq_printf(seq,
-			   "        src_min: %s  src_max: %s\n",
+			   "     src_min: %s  src_max: %s\n",
 			   pkt_dev->src_min, pkt_dev->src_max);
 	}
 
#3 lore raw

PATCH 3/10 pktgen: doc were missing several config options

In reply to Jesper Dangaard Brouer

The pktgen.txt documentation over available config options were not complete. Making the list complete by adding the following.

Pgcontrol commands:
reset

Device commands:
burst
queue_map_min
queue_map_max
skb_priority
tos
traffic_class
node
spi
dst6_max
dst6_min
vlan_cfi
vlan_id
vlan_p
svlan_cfi
svlan_id
svlan_p

---

 Documentation/networking/pktgen.txt |   25 ++++++++++++++++++++++++-
 1 files changed, 24 insertions(+), 1 deletions(-)
Documentation/networking/pktgen.txt +24 -1
index 62f5ebb..d255434 100644
@@ -241,6 +241,7 @@ Current commands and configuration options
 
 start
 stop
+reset
 
 ** Thread commands:
 
@@ -252,6 +253,7 @@ rem_device_all
 
 count
 clone_skb
+burst
 debug
 
 frags
@@ -264,6 +266,13 @@ pkt_size
 min_pkt_size
 max_pkt_size
 
+queue_map_min
+queue_map_max
+skb_priority
+
+tos           (ipv4)
+traffic_class (ipv6)
+
 mpls
 
 udp_src_min
@@ -272,6 +281,8 @@ udp_src_max
 udp_dst_min
 udp_dst_max
 
+node
+
 flag
   IPSRC_RND
   IPDST_RND
@@ -292,6 +303,8 @@ flag
   NODE_ALLOC
   NO_TIMESTAMP
 
+spi (ipsec)
+
 dst_min
 dst_max
 
@@ -303,8 +316,10 @@ src_mac
 
 clear_counters
 
-dst6
 src6
+dst6
+dst6_max
+dst6_min
 
 flows
 flowlen
@@ -314,6 +329,14 @@ ratep
 
 xmit_mode <start_xmit|netif_receive>
 
+vlan_cfi
+vlan_id
+vlan_p
+
+svlan_cfi
+svlan_id
+svlan_p
+
 
 References:
 ftp://robur.slu.se/pub/Linux/net-development/pktgen-testing/
#4 lore raw

PATCH 4/10 pktgen: document ability to add same device to several threads

In reply to Jesper Dangaard Brouer

The pktgen.txt documentation still claimed that adding same device to multiple threads were not supported, but it have been since 2008 via commit e6fce5b916cd7 ("pktgen: multiqueue etc.").

Document this and describe the naming scheme dev@X, as the procfile name still need to be unique.

Fixes e6fce5b916cd7 ("pktgen: multiqueue etc.")

---

 Documentation/networking/pktgen.txt |   77 +++++++++++++++++++++++------------
 1 files changed, 50 insertions(+), 27 deletions(-)
Documentation/networking/pktgen.txt +50 -27
index d255434..e7ae8b2 100644
@@ -50,16 +50,33 @@ For ixgbe use e.g. "30" resulting in approx 33K interrupts/sec (1/30*10^6):
  # ethtool -C ethX rx-usecs 30
 
 
-Viewing threads
-===============
-/proc/net/pktgen/kpktgend_0
-Running:
-Stopped: eth1
-Result: OK: add_device=eth1
+Kernel threads
+==============
+Pktgen creates a thread for each CPU with affinity to that CPU.
+Which is controlled through procfile /proc/net/pktgen/kpktgend_X.
+
+Example: /proc/net/pktgen/kpktgend_0
+
+ Running:
+ Stopped: eth4@0
+ Result: OK: add_device=eth4@0
+
+Most important are the devices assigned to the thread.
 
-Most important are the devices assigned to the thread.  Note that a
-device can only belong to one thread.
+The two basic thread commands are:
+ * add_device DEVICE@NAME -- adds a single device
+ * rem_device_all         -- remove all associated devices
 
+When adding a device to a thread, a corrosponding procfile is created
+which is used for configuring this device. Thus, device names need to
+be unique.
+
+To support adding the same device to multiple threads, which is useful
+with multi queue NICs, a the device naming scheme is extended with "@":
+ device@something
+
+The part after "@" can be anything, but it is custom to use the thread
+number.
 
 Viewing devices
 ===============
@@ -68,29 +85,32 @@ The Params section holds configured information.  The Current section
 holds running statistics.  The Result is printed after a run or after
 interruption.  Example:
 
-/proc/net/pktgen/eth1
+/proc/net/pktgen/eth4@0
 
-Params: count 10000000  min_pkt_size: 60  max_pkt_size: 60
-     frags: 0  delay: 0  clone_skb: 1000000  ifname: eth1
+ Params: count 100000  min_pkt_size: 60  max_pkt_size: 60
+     frags: 0  delay: 0  clone_skb: 64  ifname: eth4@0
      flows: 0 flowlen: 0
-     dst_min: 10.10.11.2  dst_max: 
-     src_min:   src_max: 
-     src_mac: 00:00:00:00:00:00  dst_mac: 00:04:23:AC:FD:82
-     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: 10000000  errors: 39664
-     started: 1103053986245187us  stopped: 1103053999346329us idle: 880401us
-     seq_num: 10000011  cur_dst_mac_offset: 0  cur_src_mac_offset: 0
-     cur_saddr: 0x10a0a0a  cur_daddr: 0x20b0a0a
-     cur_udp_dst: 9  cur_udp_src: 9
+     queue_map_min: 0  queue_map_max: 0
+     dst_min: 192.168.81.2  dst_max:
+     src_min:   src_max:
+     src_mac: 90:e2:ba:0a:56:b4 dst_mac: 00:1b:21:3c:9d:f8
+     udp_src_min: 9  udp_src_max: 109  udp_dst_min: 9  udp_dst_max: 9
+     src_mac_count: 0  dst_mac_count: 0
+     Flags: UDPSRC_RND  NO_TIMESTAMP  QUEUE_MAP_CPU
+ Current:
+     pkts-sofar: 100000  errors: 0
+     started: 623913381008us  stopped: 623913396439us idle: 25us
+     seq_num: 100001  cur_dst_mac_offset: 0  cur_src_mac_offset: 0
+     cur_saddr: 192.168.8.3  cur_daddr: 192.168.81.2
+     cur_udp_dst: 9  cur_udp_src: 42
+     cur_queue_map: 0
      flows: 0
-Result: OK: 13101142(c12220741+d880401) usec, 10000000 (60byte,0frags)
-  763292pps 390Mb/sec (390805504bps) errors: 39664
+ Result: OK: 15430(c15405+d25) usec, 100000 (60byte,0frags)
+  6480562pps 3110Mb/sec (3110669760bps) errors: 0
+
 
-Configuring threads and devices
-================================
+Configuring devices
+===================
 This is done via the /proc interface, and most easily done via pgset
 as defined in the sample scripts.
 
@@ -221,6 +241,9 @@ Note that when adding devices to a specific CPU it is a good idea to
 also assign /proc/irq/XX/smp_affinity so that the TX interrupts are bound
 to the same CPU.  This reduces cache bouncing when freeing skbs.
 
+Plus using the device flag QUEUE_MAP_CPU, which maps the SKBs TX queue
+to the running threads CPU (directly from smp_processor_id()).
+
 Enable IPsec
 ============
 Default IPsec transformation with ESP encapsulation plus transport mode
Acked-by on v1 4/10
#5 lore raw

Re: [net-next PATCH 04/10] pktgen: document ability to add same device to several threads

Quoted 9 lines · Jesper Dangaard Brouer

The pktgen.txt documentation still claimed that adding same device to multiple threads were not supported, but it have been since 2008 via commit e6fce5b916cd7 ("pktgen: multiqueue etc.").

Document this and describe the naming scheme dev@X, as the procfile name still need to be unique.

Fixes e6fce5b916cd7 ("pktgen: multiqueue etc.")

...

Documentation/networking/pktgen.txt For ixgbe use e.g. "30" resulting in approx 33K interrupts/sec (1/30*10^6): · line 67

Quoted 4 lines
Documentation/networking/pktgen.txt +2 -2
-Most important are the devices assigned to the thread.  Note that a
-device can only belong to one thread.
+The two basic thread commands are:
+ * add_device DEVICE@NAME -- adds a single device

Great work for the whole series!
Wanted to specifically

this patch, since it could have saved me days of pointlessly reimplementing existing feature and likely will help others in the future. People do read docs :)

#6 lore raw

PATCH 5/10 pktgen: make /proc/net/pktgen/pgctrl report fail on invalid input

In reply to Jesper Dangaard Brouer

Giving /proc/net/pktgen/pgctrl an invalid command just returns shell success and prints a warning in dmesg. This is not very useful for shell scripting, as it can only detect the error by parsing dmesg.

Instead return -EINVAL when the command is unknown, as this provides userspace shell scripting a way of detecting this.

Also bump version tag to 2.75, because (1) reading /proc/net/pktgen/pgctrl output this version number which would allow to detect this small semantic change, and (2) because the pktgen version tag have not been updated since 2010.

---

 net/core/pktgen.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
net/core/pktgen.c +2 -2
index 167e592..676550f 100644
@@ -177,7 +177,7 @@
 #include <asm/dma.h>
 #include <asm/div64.h>		/* do_div */
 
-#define VERSION	"2.74"
+#define VERSION	"2.75"
 #define IP_NAME_SZ 32
 #define MAX_MPLS_LABELS 16 /* This is the max label stack depth */
 #define MPLS_STACK_BOTTOM htonl(0x00000100)
@@ -512,7 +512,7 @@ static ssize_t pgctrl_write(struct file *file, const char __user *buf,
 		pktgen_reset_all_threads(pn);
 
 	else
-		pr_warn("Unknown command: %s\n", data);
+		return -EINVAL;
 
 	return count;
 }
#7 lore raw

PATCH 6/10 pktgen: new pktgen helper functions for samples scripts

In reply to Jesper Dangaard Brouer

Preparing for removing existing samples/pktgen/ scripts, and replacing these with easier to use samples.

This commit provides two helper shell files, that can be "included" by shell source'ing. Namely "functions.sh" and "parameters.sh".

The parameters.sh file support easy and consistant parameter parsing across the sample scripts. Usage example is printed on errors.

The functions.sh file provides, three new shell functions for configuring the different components of pktgen: pg_ctrl(), pg_thread() and pg_set(). A slightly improved version of the old pgset() function is also provided for backwards compat.

The new functions correspond to pktgens different components.
* pg_ctrl() control "pgctrl" (/proc/net/pktgen/pgctrl)
* pg_thread() control the kernel threads and binding to devices
* pg_set() control setup of individual devices

These changes are borrowed from:
https://github.com/netoptimizer/network-testing/tree/master/pktgen

---

 samples/pktgen/README.rst    |   43 +++++++++++++++
 samples/pktgen/functions.sh  |  120 ++++++++++++++++++++++++++++++++++++++++++
 samples/pktgen/parameters.sh |   97 ++++++++++++++++++++++++++++++++++
 3 files changed, 260 insertions(+), 0 deletions(-)
 create mode 100644 samples/pktgen/README.rst
 create mode 100644 samples/pktgen/functions.sh
 create mode 100644 samples/pktgen/parameters.sh
samples/pktgen/README.rst new file +43 -0
new file mode 100644
index 0000000..8365c4e
@@ -0,0 +1,43 @@
+Sample and benchmark scripts for pktgen (packet generator)
+==========================================================
+This directory contains some pktgen sample and benchmark scripts, that
+can easily be copied and adjusted for your own use-case.
+
+General doc is located in kernel: Documentation/networking/pktgen.txt
+
+Helper include files
+====================
+This directory contains two helper shell files, that can be "included"
+by shell source'ing.  Namely "functions.sh" and "parameters.sh".
+
+Common parameters
+-----------------
+The parameters.sh file support easy and consistant parameter parsing
+across the sample scripts.  Usage example is printed on errors::
+
+ Usage: ./pktgen_sample01_simple.sh [-vx] -i ethX
+  -i : ($DEV)       output interface/device (required)
+  -s : ($PKT_SIZE)  packet size
+  -d : ($DEST_IP)   destination IP
+  -m : ($DST_MAC)   destination MAC-addr
+  -t : ($THREADS)   threads to start
+  -c : ($SKB_CLONE) SKB clones send before alloc new SKB
+  -b : ($BURST)     HW level bursting of SKBs
+  -v : ($VERBOSE)   verbose
+  -x : ($DEBUG)     debug
+
+The global variable being set is also listed.  E.g. the required
+interface/device parameter "-i" sets variable $DEV.
+
+Common functions
+----------------
+The functions.sh file provides; Three different shell functions for
+configuring the different components of pktgen: pg_ctrl(), pg_thread()
+and pg_set().
+
+These functions correspond to pktgens different components.
+ * pg_ctrl()   control "pgctrl" (/proc/net/pktgen/pgctrl)
+ * pg_thread() control the kernel threads and binding to devices
+ * pg_set()    control setup of individual devices
+
+See sample scripts for usage examples.
samples/pktgen/functions.sh new file +120 -0

120 lines not on this page · raw message

samples/pktgen/parameters.sh new file +97 -0

97 lines not on this page · raw message

#8 lore raw

Re: [net-next PATCH 06/10] pktgen: new pktgen helper functions for samples scripts

Quoted 15 lines · Jesper Dangaard Brouer
samples/pktgen/functions.sh new file +15 -0
+
+# More generic replacement for pgset(), that does not depend on global
+# variable for proc file.
+function proc_cmd() {
+    local result
+    local proc_file=$1
+    # after shift, the remaining args are contained in $@
+    shift
+    local proc_ctrl=${PROC_DIR}/$proc_file
+    if [[ ! -e "$proc_ctrl" ]]; then
+       err 3 "proc file:$proc_ctrl does not exists (dev added to thread?)"
+    else
+       if [[ ! -w "$proc_ctrl" ]]; then
+           err 4 "proc file:$proc_ctrl not writable, not root?!"
+       fi

samples/pktgen/functions.sh line 79

Quoted 10 lines
samples/pktgen/functions.sh new file +10 -0
+    fi
+
+    if [[ "$DEBUG" == "yes" ]]; then
+       echo "cmd: $@ > $proc_ctrl"
+    fi
+    # Quoting of "$@" is important for space expansion
+    echo "$@" > "$proc_ctrl"
+    local status=$?
+
+    result=`cat $proc_ctrl | fgrep "Result: OK:"`

Nit: useless usage of cat, grep/fgrep accepts a file name.

Quoted 1 line

+ if [[ "$result" == "" ]]; then

You can test $?

samples/pktgen/functions.sh line 84

Quoted 4 lines
samples/pktgen/functions.sh new file +4 -0
+       cat $proc_ctrl | fgrep Result: >&2
+    fi
+    if (( $status != 0 )); then
+       err 5 "Write error($status) occured cmd: \"$@ > $proc_ctrl\""

Typo: occurred

Quoted 3 lines
samples/pktgen/functions.sh new file +3 -0
+    fi
+}
+
#9 lore raw

Re: [net-next PATCH 06/10] pktgen: new pktgen helper functions for samples scripts

Quoted 17 lines · On Wed, 20 May 2015 14:23:17 -0700 Cong Wang <[email protected]> wrote:
Quoted 15 lines · Jesper Dangaard Brouer
samples/pktgen/functions.sh new file +15 -0
+
+# More generic replacement for pgset(), that does not depend on global
+# variable for proc file.
+function proc_cmd() {
+    local result
+    local proc_file=$1
+    # after shift, the remaining args are contained in $@
+    shift
+    local proc_ctrl=${PROC_DIR}/$proc_file
+    if [[ ! -e "$proc_ctrl" ]]; then
+       err 3 "proc file:$proc_ctrl does not exists (dev added to thread?)"
+    else
+       if [[ ! -w "$proc_ctrl" ]]; then
+           err 4 "proc file:$proc_ctrl not writable, not root?!"
+       fi
Quoted 8 lines

samples/pktgen/functions.sh line 77

Quoted 8 lines
samples/pktgen/functions.sh new file +8 -0
+    fi
+
+    if [[ "$DEBUG" == "yes" ]]; then
+       echo "cmd: $@ > $proc_ctrl"
+    fi
+    # Quoting of "$@" is important for space expansion
+    echo "$@" > "$proc_ctrl"
+    local status=$?

(For later, notice, extraction of $? here)

Quoted 4 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+    result=`cat $proc_ctrl | fgrep "Result: OK:"`

Nit: useless usage of cat, grep/fgrep accepts a file name.

True, I just copied it from the old pgset(). I also don't think "fgrep" is really needed.

Replacing with:
result=$(grep "Result: OK:" $proc_ctrl)

Quoted 4 lines
Quoted 2 lines

+ if [[ "$result" == "" ]]; then

You can test $?

No, unfortunately not... this is because I'm also using the function for /proc/net/pktgen/pgctrl which does not contain a "Result:" line.

Thus, I can reuse this function for pgctrl, by letting it pass this test. And pgctrl didn't even return errors on false input (fixed in this patchset), which made any feedback from pgctrl futile.

(RANT)
Do notice pktgen proc API of reading "Result: OK:" is broken in more ways ... which I'm trying to handle here.

On some proc-input pktgen does not return an error, but writes the error message in the proc file. Thus, we MUST parse/grep "Result".

On some proc-input pktgen only returns and error, and does NOT update the "result" output. Thus, the result can contain a "Result: OK:" from a previous command. This was not detected by old pgset().

This is why I'm extracting status=$? earlier.

This new proc write function catches a very common configuration sequence of input correct dst IP but wrong MAC addr.

See:

 # echo -e "dst 1.2.3.4.5.6" > eth4@0 ; cat eth4@0 | grep Result
 Result: OK: dst_min=1.2.3.4.5.6
 # echo -e "dst_mac in:va:id " > eth4@0 ; cat eth4@0 | grep Result
 -bash: echo: write error: Invalid argument
 Result: OK: dst_min=1.2.3.4.5.6
Quoted 6 lines

samples/pktgen/functions.sh line 84

Quoted 4 lines
samples/pktgen/functions.sh new file +4 -0
+       cat $proc_ctrl | fgrep Result: >&2
+    fi
+    if (( $status != 0 )); then
+       err 5 "Write error($status) occured cmd: \"$@ > $proc_ctrl\""

Typo: occurred

True, annoyingly I already fixed it in the backward compat pgset().

Signature · 5 lines
Best regards,
  Jesper Dangaard Brouer
  MSc.CS, Sr. Network Kernel Developer at Red Hat
  Author of http://www.iptv-analyzer.org
  LinkedIn: http://www.linkedin.com/in/brouer
#10 lore raw

PATCH 7/10 pktgen: add sample script pktgen_sample01_simple.sh

In reply to Jesper Dangaard Brouer

Add the first basic pktgen samples script pktgen_sample01_simple.sh, which demonstrates the a simple use of the helper functions. Removing pktgen.conf-1-1 as that example should be covered now.

The naming scheme pktgen_sampleNN, where NN is a number, should encourage reading the samples in a specific order.

Script cause pktgen sending with a single thread and single interface, and introduce flow variation via random UDP source port.

Usage example and help:
./pktgen_sample01_simple.sh -i eth4 -m 00:1B:21:3C:9D:F8 -d 192.168.8.2

Usage: ./pktgen_sample01_simple.sh [-vx] -i ethX

  -i : ($DEV)       output interface/device (required)
  -s : ($PKT_SIZE)  packet size
  -d : ($DEST_IP)   destination IP
  -m : ($DST_MAC)   destination MAC-addr

-c : ($SKB_CLONE) SKB clones send before alloc new SKB
-v : ($VERBOSE) verbose
-x : ($DEBUG) debug

---

 Documentation/networking/pktgen.txt      |   29 ++++++++++--
 samples/pktgen/pktgen.conf-1-1           |   59 -------------------------
 samples/pktgen/pktgen_sample01_simple.sh |   71 ++++++++++++++++++++++++++++++
 3 files changed, 94 insertions(+), 65 deletions(-)
 delete mode 100755 samples/pktgen/pktgen.conf-1-1
 create mode 100755 samples/pktgen/pktgen_sample01_simple.sh
Documentation/networking/pktgen.txt +23 -6
index e7ae8b2..f2f1033 100644
@@ -219,10 +219,30 @@ Examples:
 Sample scripts
 ==============
 
-A collection of small tutorial scripts for pktgen is in the
-samples/pktgen directory:
+A collection of tutorial scripts and helpers for pktgen is in the
+samples/pktgen directory. The helper parameters.sh file support easy
+and consistant parameter parsing across the sample scripts.
+
+Usage example and help:
+ ./pktgen_sample01_simple.sh -i eth4 -m 00:1B:21:3C:9D:F8 -d 192.168.8.2
+
+Usage: ./pktgen_sample01_simple.sh [-vx] -i ethX
+  -i : ($DEV)       output interface/device (required)
+  -s : ($PKT_SIZE)  packet size
+  -d : ($DEST_IP)   destination IP
+  -m : ($DST_MAC)   destination MAC-addr
+  -t : ($THREADS)   threads to start
+  -c : ($SKB_CLONE) SKB clones send before alloc new SKB
+  -b : ($BURST)     HW level bursting of SKBs
+  -v : ($VERBOSE)   verbose
+  -x : ($DEBUG)     debug
+
+The global variables being set are also listed.  E.g. the required
+interface/device parameter "-i" sets variable $DEV.  Copy the
+pktgen_sampleXX scripts and modify them to fit your own needs.
+
+The old scripts:
 
-pktgen.conf-1-1                  # 1 CPU 1 dev 
 pktgen.conf-1-2                  # 1 CPU 2 dev
 pktgen.conf-2-1                  # 2 CPU's 1 dev 
 pktgen.conf-2-2                  # 2 CPU's 2 dev
@@ -231,9 +251,6 @@ pktgen.conf-1-1-ip6              # 1 CPU 1 dev ipv6
 pktgen.conf-1-1-ip6-rdos         # 1 CPU 1 dev ipv6  w. route DoS
 pktgen.conf-1-1-flows            # 1 CPU 1 dev multiple flows.
 
-Run in shell: ./pktgen.conf-X-Y
-This does all the setup including sending.
-
 
 Interrupt affinity
 ===================
samples/pktgen/pktgen.conf-1-1 deleted +0 -59

59 lines not on this page · raw message

samples/pktgen/pktgen_sample01_simple.sh new file +71 -0

71 lines not on this page · raw message

#11 lore raw

PATCH 8/10 pktgen: add sample script pktgen_sample02_multiqueue.sh

In reply to Jesper Dangaard Brouer

Add the pktgen samples script pktgen_sample02_multiqueue.sh that demonstrates generating packets on multiqueue NICs.

Specifically notice the options "-t" that specifies how many kernel threads to activate. Also notice the flag QUEUE_MAP_CPU, which cause the SKB TX queue to be mapped to the CPU running the kernel thread. For best scalability people are also encourage to map NIC IRQ /proc/irq/*/smp_affinity to CPU number.

Usage example with "-t" 4 threads and help:
./pktgen_sample02_multiqueue.sh -i eth4 -m 00:1B:21:3C:9D:F8 -t 4

Usage: ./pktgen_sample02_multiqueue.sh [-vx] -i ethX

  -i : ($DEV)       output interface/device (required)
  -s : ($PKT_SIZE)  packet size
  -d : ($DEST_IP)   destination IP
  -m : ($DST_MAC)   destination MAC-addr
  -t : ($THREADS)   threads to start
  -c : ($SKB_CLONE) SKB clones send before alloc new SKB
  -b : ($BURST)     HW level bursting of SKBs
  -v : ($VERBOSE)   verbose
  -x : ($DEBUG)     debug

Removing pktgen.conf-2-1 and pktgen.conf-2-2 as these examples should be covered now.

---

 Documentation/networking/pktgen.txt          |    2 -
 samples/pktgen/pktgen.conf-2-1               |   66 -----------------------
 samples/pktgen/pktgen.conf-2-2               |   73 -------------------------
 samples/pktgen/pktgen_sample02_multiqueue.sh |   75 ++++++++++++++++++++++++++
 4 files changed, 75 insertions(+), 141 deletions(-)
 delete mode 100755 samples/pktgen/pktgen.conf-2-1
 delete mode 100755 samples/pktgen/pktgen.conf-2-2
 create mode 100755 samples/pktgen/pktgen_sample02_multiqueue.sh
Documentation/networking/pktgen.txt +0 -2
index f2f1033..f4be85e 100644
@@ -244,8 +244,6 @@ pktgen_sampleXX scripts and modify them to fit your own needs.
 The old scripts:
 
 pktgen.conf-1-2                  # 1 CPU 2 dev
-pktgen.conf-2-1                  # 2 CPU's 1 dev 
-pktgen.conf-2-2                  # 2 CPU's 2 dev
 pktgen.conf-1-1-rdos             # 1 CPU 1 dev w. route DoS 
 pktgen.conf-1-1-ip6              # 1 CPU 1 dev ipv6
 pktgen.conf-1-1-ip6-rdos         # 1 CPU 1 dev ipv6  w. route DoS
samples/pktgen/pktgen.conf-2-1 deleted +0 -66

66 lines not on this page · raw message

samples/pktgen/pktgen.conf-2-2 deleted +0 -73

73 lines not on this page · raw message

samples/pktgen/pktgen_sample02_multiqueue.sh new file +75 -0

75 lines not on this page · raw message

#12 lore raw

PATCH 9/10 pktgen: add sample script pktgen_sample03_burst_single_flow.sh

In reply to Jesper Dangaard Brouer

Add the pktgen samples script pktgen_sample03_burst_single_flow.sh that demonstrates how to acheive maximum performance.

If correctly tuned[1] single CPU 10Gbit/s wirespeed small pkts is possible[2] which is 14.88Mpps. The trick is to take advantage of the "burst" feature introduced in commit 38b2cf2982dc73 ("net: pktgen:
packet bursting via skb->xmit_more").

[1] http://netoptimizer.blogspot.dk/2014/06/pktgen-for-network-overload-testing.html
[2] http://netoptimizer.blogspot.dk/2014/10/unlocked-10gbps-tx-wirespeed-smallest.html

---

 .../pktgen/pktgen_sample03_burst_single_flow.sh    |   82 ++++++++++++++++++++
 1 files changed, 82 insertions(+), 0 deletions(-)
 create mode 100755 samples/pktgen/pktgen_sample03_burst_single_flow.sh
samples/pktgen/pktgen_sample03_burst_single_flow.sh new file +82 -0
new file mode 100755
index 0000000..f60d579
@@ -0,0 +1,82 @@
+#!/bin/bash
+#
+# Script for max single flow performance
+#  - If correctly tuned[1], single CPU 10G wirespeed small pkts is possible[2]
+#
+# Using pktgen "burst" option (use -b $N)
+#  - To boost max performance
+#  - Avail since: kernel v3.18
+#   * commit 38b2cf2982dc73 ("net: pktgen: packet bursting via skb->xmit_more")
+#  - This avoids writing the HW tailptr on every driver xmit
+#  - The performance boost is impressive, see commit and blog [2]
+#
+# Notice: On purpose generates a single (UDP) flow towards target,
+#   reason behind this is to only overload/activate a single CPU on
+#   target host.  And no randomness for pktgen also makes it faster.
+#
+# Tuning see:
+#  [1] http://netoptimizer.blogspot.dk/2014/06/pktgen-for-network-overload-testing.html
+#  [2] http://netoptimizer.blogspot.dk/2014/10/unlocked-10gbps-tx-wirespeed-smallest.html
+#
+basedir=`dirname $0`
+source ${basedir}/functions.sh
+root_check_run_with_sudo "$@"
+
+# Parameter parsing via include
+source ${basedir}/parameters.sh
+# Set some default params, if they didn't get set
+[ -z "$DEST_IP" ]   && DEST_IP="198.18.0.42"
+[ -z "$DST_MAC" ]   && DST_MAC="90:e2:ba:ff:ff:ff"
+[ -z "$BURST" ]     && BURST=32
+[ -z "$CLONE_SKB" ] && CLONE_SKB="100000"
+
+# Base Config
+DELAY="0"  # Zero means max speed
+COUNT="0"  # Zero means indefinitely
+
+# General cleanup everything since last run
+pg_ctrl "reset"
+
+# Threads are specified with parameter -t value in $THREADS
+for ((thread = 0; thread < $THREADS; thread++)); do
+    dev=${DEV}@${thread}
+
+    # Add remove all other devices and add_device $dev to thread
+    pg_thread $thread "rem_device_all"
+    pg_thread $thread "add_device" $dev
+
+    # Base config
+    pg_set $dev "flag QUEUE_MAP_CPU"
+    pg_set $dev "count $COUNT"
+    pg_set $dev "clone_skb $CLONE_SKB"
+    pg_set $dev "pkt_size $PKT_SIZE"
+    pg_set $dev "delay $DELAY"
+    pg_set $dev "flag NO_TIMESTAMP"
+
+    # Destination
+    pg_set $dev "dst_mac $DST_MAC"
+    pg_set $dev "dst $DEST_IP"
+
+    # Setup burst, for easy testing -b 0 disable bursting
+    # (internally in pktgen default and minimum burst=1)
+    if [[ ${BURST} != 0 ]]; then
+	pg_set $dev "burst $BURST"
+    else
+	info "$dev: Not using burst"
+    fi
+done
+
+# Run if user hits control-c
+function control_c() {
+    # Print results
+    for ((thread = 0; thread < $THREADS; thread++)); do
+	dev=${DEV}@${thread}
+	echo "Device: $dev"
+	cat /proc/net/pktgen/$dev | grep -A2 "Result:"
+    done
+}
+# trap keyboard interrupt (Ctrl-C)
+trap control_c SIGINT
+
+echo "Running... ctrl^C to stop" >&2
+pg_ctrl "start"
#13 lore raw

Re: [net-next PATCH 09/10] pktgen: add sample script pktgen_sample03_burst_single_flow.sh

Quoted 13 lines · Jesper Dangaard Brouer
samples/pktgen/pktgen_sample03_burst_single_flow.sh new file +13 -0
+# Threads are specified with parameter -t value in $THREADS
+for ((thread = 0; thread < $THREADS; thread++)); do
+    dev=${DEV}@${thread}
+
+    # Add remove all other devices and add_device $dev to thread
+    pg_thread $thread "rem_device_all"
+    pg_thread $thread "add_device" $dev
+
+    # Base config
+    pg_set $dev "flag QUEUE_MAP_CPU"
+    pg_set $dev "count $COUNT"
+    pg_set $dev "clone_skb $CLONE_SKB"
+    pg_set $dev "pkt_size $PKT_SIZE"

samples/pktgen/pktgen_sample03_burst_single_flow.sh line 62

Quoted 10 lines
samples/pktgen/pktgen_sample03_burst_single_flow.sh new file +10 -0
+    pg_set $dev "delay $DELAY"
+    pg_set $dev "flag NO_TIMESTAMP"
+
+    # Destination
+    pg_set $dev "dst_mac $DST_MAC"
+    pg_set $dev "dst $DEST_IP"
+
+    # Setup burst, for easy testing -b 0 disable bursting
+    # (internally in pktgen default and minimum burst=1)
+    if [[ ${BURST} != 0 ]]; then

Nit: probably you mean: [[ ${BURST} -ne 0 ]]

Quoted 5 lines
samples/pktgen/pktgen_sample03_burst_single_flow.sh new file +5 -0
+       pg_set $dev "burst $BURST"
+    else
+       info "$dev: Not using burst"
+    fi
+done
#14 lore raw

Re: [net-next PATCH 09/10] pktgen: add sample script pktgen_sample03_burst_single_flow.sh

Quoted 20 lines · On Wed, 20 May 2015 14:33:42 -0700 Cong Wang <[email protected]> wrote:
Quoted 18 lines · Jesper Dangaard Brouer
samples/pktgen/pktgen_sample03_burst_single_flow.sh new file +18 -0
+# Threads are specified with parameter -t value in $THREADS
+for ((thread = 0; thread < $THREADS; thread++)); do
+    dev=${DEV}@${thread}
+
+    # Add remove all other devices and add_device $dev to thread
+    pg_thread $thread "rem_device_all"
+    pg_thread $thread "add_device" $dev
+
+    # Base config
+    pg_set $dev "flag QUEUE_MAP_CPU"
+    pg_set $dev "count $COUNT"
+    pg_set $dev "clone_skb $CLONE_SKB"
+    pg_set $dev "pkt_size $PKT_SIZE"
+    pg_set $dev "delay $DELAY"
+    pg_set $dev "flag NO_TIMESTAMP"
+
+    # Destination
+    pg_set $dev "dst_mac $DST_MAC"
Quoted 8 lines

samples/pktgen/pktgen_sample03_burst_single_flow.sh line 62

Quoted 5 lines
samples/pktgen/pktgen_sample03_burst_single_flow.sh new file +5 -0
+    pg_set $dev "dst $DEST_IP"
+
+    # Setup burst, for easy testing -b 0 disable bursting
+    # (internally in pktgen default and minimum burst=1)
+    if [[ ${BURST} != 0 ]]; then

Nit: probably you mean: [[ ${BURST} -ne 0 ]]

With bash this still works (comparing it as a string), but I guess it is more correct as you propose to compare it as a number.

You do realize that this cause $BURST to be evaluated as an arithmetic expression, thus input like "10-10" will also disable bursting.

In bash it's also possible to write as: (( $BURST != 0 )) to be more explicit that this is an arithmetic expression, and then we don't use the -eq, -ne etc.

I'm fine with taking your proposal, as it also works with single "[" (although it does not fall for the arithmetic expansion).

Quoted 5 lines
Quoted 5 lines
samples/pktgen/pktgen_sample03_burst_single_flow.sh new file +5 -0
+       pg_set $dev "burst $BURST"
+    else
+       info "$dev: Not using burst"
+    fi
+done
Signature · 5 lines
Best regards,
  Jesper Dangaard Brouer
  MSc.CS, Sr. Network Kernel Developer at Red Hat
  Author of http://www.iptv-analyzer.org
  LinkedIn: http://www.linkedin.com/in/brouer
#15 lore raw

PATCH 10/10 pktgen: add benchmark script pktgen_bench_xmit_mode_netif_receive.sh

In reply to Jesper Dangaard Brouer

This script pktgen_bench_xmit_mode_netif_receive.sh is a benchmark script, which can be used for benchmarking part of the network stack. This can be used for performance improving or catching regression in that area.

The script is developed for benchmarking ingress qdisc path, original idea by Alexei Starovoitov. This script don't really need any hardware. This is achieved via the recently introduced stack inject feature "xmit_mode netif_receive". See commit 62f64aed622b6 ("pktgen:
introduce xmit_mode '<start_xmit|netif_receive>'").

---

 .../pktgen/pktgen_bench_xmit_mode_netif_receive.sh |   86 ++++++++++++++++++++
 1 files changed, 86 insertions(+), 0 deletions(-)
 create mode 100755 samples/pktgen/pktgen_bench_xmit_mode_netif_receive.sh
samples/pktgen/pktgen_bench_xmit_mode_netif_receive.sh new file +86 -0
new file mode 100755
index 0000000..cb15903
@@ -0,0 +1,86 @@
+#!/bin/bash
+#
+# Benchmark script:
+#  - developed for benchmarking ingress qdisc path
+#
+# Script for injecting packets into RX path of the stack with pktgen
+# "xmit_mode netif_receive".  With an invalid dst_mac this will only
+# measure the ingress code path as packets gets dropped in ip_rcv().
+#
+# This script don't really need any hardware.  It benchmarks software
+# RX path just after NIC driver level.  With bursting is also
+# "removes" the SKB alloc/free overhead.
+#
+# Setup scenarios for measuring ingress qdisc (with invalid dst_mac):
+# ------------------------------------------------------------------
+# (1) no ingress (uses static_key_false(&ingress_needed))
+#
+# (2) ingress on other dev (change ingress_needed and calls
+#     handle_ing() but exit early)
+#
+#  config:  tc qdisc add dev $SOMEDEV handle ffff: ingress
+#
+# (3) ingress on this dev, handle_ing() -> tc_classify()
+#
+#  config:  tc qdisc add dev $DEV handle ffff: ingress
+#
+# (4) ingress on this dev + drop at u32 classifier/action.
+#
+basedir=`dirname $0`
+source ${basedir}/functions.sh
+root_check_run_with_sudo "$@"
+
+# Parameter parsing via include
+source ${basedir}/parameters.sh
+# Using invalid DST_MAC will cause the packets to get dropped in
+# ip_rcv() which is part of the test
+[ -z "$DEST_IP" ] && DEST_IP="198.18.0.42"
+[ -z "$DST_MAC" ] && DST_MAC="90:e2:ba:ff:ff:ff"
+[ -z "$BURST" ] && BURST=1024
+
+# Base Config
+DELAY="0"        # Zero means max speed
+COUNT="10000000" # Zero means indefinitely
+
+# General cleanup everything since last run
+pg_ctrl "reset"
+
+# Threads are specified with parameter -t value in $THREADS
+for ((thread = 0; thread < $THREADS; thread++)); do
+    # The device name is extended with @name, using thread number to
+    # make then unique, but any name will do.
+    dev=${DEV}@${thread}
+
+    # Add remove all other devices and add_device $dev to thread
+    pg_thread $thread "rem_device_all"
+    pg_thread $thread "add_device" $dev
+
+    # Base config of dev
+    pg_set $dev "flag QUEUE_MAP_CPU"
+    pg_set $dev "count $COUNT"
+    pg_set $dev "pkt_size $PKT_SIZE"
+    pg_set $dev "delay $DELAY"
+    pg_set $dev "flag NO_TIMESTAMP"
+
+    # Destination
+    pg_set $dev "dst_mac $DST_MAC"
+    pg_set $dev "dst $DEST_IP"
+
+    # Inject packet into RX path of stack
+    pg_set $dev "xmit_mode netif_receive"
+
+    # Burst allow us to avoid measuring SKB alloc/free overhead
+    pg_set $dev "burst $BURST"
+done
+
+# start_run
+echo "Running... ctrl^C to stop" >&2
+pg_ctrl "start"
+echo "Done" >&2
+
+# Print results
+for ((thread = 0; thread < $THREADS; thread++)); do
+    dev=${DEV}@${thread}
+    echo "Device: $dev"
+    cat /proc/net/pktgen/$dev | grep -A2 "Result:"
+done