From: Jesper Dangaard Brouer <brouer@redhat.com>
To: Cong Wang <cwang@twopensource.com>
Cc: netdev <netdev@vger.kernel.org>,
Daniel Borkmann <borkmann@iogearbox.net>,
Alexei Starovoitov <ast@plumgrid.com>,
Robert Olsson <robert@herjulf.se>,
Ben Greear <greearb@candelatech.com>,
brouer@redhat.com
Subject: Re: [net-next PATCH 06/10] pktgen: new pktgen helper functions for samples scripts
Date: Thu, 21 May 2015 11:18:49 +0200 [thread overview]
Message-ID: <20150521111849.283d230b@redhat.com> (raw)
In-Reply-To: <CAHA+R7NzKMLLZ954F+moZ7wFEFWPTBzo0Js9rGnU02kkPTPB0A@mail.gmail.com>
On Wed, 20 May 2015 14:23:17 -0700
Cong Wang <cwang@twopensource.com> wrote:
> On Tue, May 19, 2015 at 2:36 PM, Jesper Dangaard Brouer
> <brouer@redhat.com> wrote:
> > +
> > +# 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
> > + 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)
> > +
> > + 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)
>
> > + 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
> > + 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().
--
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
next prev parent reply other threads:[~2015-05-21 9:19 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-19 21:35 [net-next PATCH 00/10] pktgen: cleanups and introducing new samples/pktgen scripts Jesper Dangaard Brouer
2015-05-19 21:35 ` [net-next PATCH 01/10] pktgen: remove obsolete "max_before_softirq" from pktgen doc Jesper Dangaard Brouer
2015-05-19 21:35 ` [net-next PATCH 02/10] pktgen: adjust spacing in proc file interface output Jesper Dangaard Brouer
2015-05-19 21:35 ` [net-next PATCH 03/10] pktgen: doc were missing several config options Jesper Dangaard Brouer
2015-05-19 21:35 ` [net-next PATCH 04/10] pktgen: document ability to add same device to several threads Jesper Dangaard Brouer
2015-05-19 21:54 ` Alexei Starovoitov
2015-05-19 21:35 ` [net-next PATCH 05/10] pktgen: make /proc/net/pktgen/pgctrl report fail on invalid input Jesper Dangaard Brouer
2015-05-19 21:36 ` [net-next PATCH 06/10] pktgen: new pktgen helper functions for samples scripts Jesper Dangaard Brouer
2015-05-20 21:23 ` Cong Wang
2015-05-21 9:18 ` Jesper Dangaard Brouer [this message]
2015-05-19 21:36 ` [net-next PATCH 07/10] pktgen: add sample script pktgen_sample01_simple.sh Jesper Dangaard Brouer
2015-05-19 21:36 ` [net-next PATCH 08/10] pktgen: add sample script pktgen_sample02_multiqueue.sh Jesper Dangaard Brouer
2015-05-19 21:36 ` [net-next PATCH 09/10] pktgen: add sample script pktgen_sample03_burst_single_flow.sh Jesper Dangaard Brouer
2015-05-20 21:33 ` Cong Wang
2015-05-21 9:47 ` Jesper Dangaard Brouer
2015-05-19 21:36 ` [net-next PATCH 10/10] pktgen: add benchmark script pktgen_bench_xmit_mode_netif_receive.sh Jesper Dangaard Brouer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150521111849.283d230b@redhat.com \
--to=brouer@redhat.com \
--cc=ast@plumgrid.com \
--cc=borkmann@iogearbox.net \
--cc=cwang@twopensource.com \
--cc=greearb@candelatech.com \
--cc=netdev@vger.kernel.org \
--cc=robert@herjulf.se \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).