man-pages/man8/tc-sample.8.html
2021-03-31 01:06:50 +01:00

206 lines
4.7 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of Packet sample action in tc</TITLE>
</HEAD><BODY>
<H1>Packet sample action in tc</H1>
Section: Linux (8)<BR>Updated: 31 Jan 2017<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<P>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
sample - packet sampling tc action
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<BR>
<P>
<B>tc</B> ... <B>action sample rate</B>
<I>RATE</I>
<B>group</B>
<I>GROUP</I>
[ <B>trunc</B>
<I>SIZE</I> ]
[ <B>index</B>
<I>INDEX</I> ]
<BR>
<P>
<B>tc</B> ... <B>action sample index </B>
<I>INDEX</I>
<BR>
<P>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
The
<B>sample</B>
action allows sampling packets matching classifier.
<P>
The packets are chosen randomly according to the
<B>rate</B>
parameter, and are sampled using the
<B>psample</B>
generic netlink channel. The user can also specify packet truncation to save
user-kernel traffic. Each sample includes some informative metadata about the
original packet, which is sent using netlink attributes, alongside the original
packet data.
<P>
The user can either specify the sample action parameters as presented in the
first form above, or use an existing sample action using its index, as presented
in the second form.
<P>
<A NAME="lbAE">&nbsp;</A>
<H2>SAMPLED PACKETS METADATA FIELDS</H2>
The metadata are delivered to userspace applications using the
<B>psample</B>
generic netlink channel, where each sample includes the following netlink
attributes:
<DL COMPACT>
<DT id="1"><B>PSAMPLE_ATTR_IIFINDEX</B>
<DD>
The input interface index of the packet, if there is one.
<DT id="2"><B>PSAMPLE_ATTR_OIFINDEX</B>
<DD>
The output interface index of the packet. This field is not relevant on ingress
sampling
<DT id="3"><B>PSAMPLE_ATTR_ORIGSIZE</B>
<DD>
The size of the original packet (before truncation)
<DT id="4"><B>PSAMPLE_ATTR_SAMPLE_GROUP</B>
<DD>
The
<B>psample</B>
group the packet was sent to
<DT id="5"><B>PSAMPLE_ATTR_GROUP_SEQ</B>
<DD>
A sequence number of the sampled packet. This number is incremented with each
sampled packet of the current
<B>psample</B>
group
<DT id="6"><B>PSAMPLE_ATTR_SAMPLE_RATE</B>
<DD>
The rate the packet was sampled with
<P>
</DL>
<A NAME="lbAF">&nbsp;</A>
<H2>OPTIONS</H2>
<DL COMPACT>
<DT id="7"><B>rate</B><I> RATE</I>
<DD>
The packet sample rate.
<I>RATE</I>
is the expected ratio between observed packets and sampled packets. For example,
<I>RATE</I>
of 100 will lead to an average of one sampled packet out of every 100 observed.
<DT id="8"><B>trunc</B><I> SIZE</I>
<DD>
Upon set, defines the maximum size of the sampled packets, and causes truncation
if needed
<DT id="9"><B>group</B><I> GROUP</I>
<DD>
The
<B>psample</B>
group the packet will be sent to. The
<B>psample</B>
module defines the concept of groups, which allows the user to match specific
sampled packets in the case of multiple sampling rules, thus identify only the
packets that came from a specific rule.
<DT id="10"><B>index</B><I> INDEX</I>
<DD>
Is a unique ID for an action. When creating new action instance, this parameter
allows to set the new action index. When using existing action, this parameter
allows to specify the existing action index. The index must 32bit unsigned
integer greater than zero.
</DL>
<A NAME="lbAG">&nbsp;</A>
<H2>EXAMPLES</H2>
Sample one of every 100 packets flowing into interface eth0 to psample group 12:
<P>
<DL COMPACT><DT id="11"><DD>
tc qdisc add dev eth0 handle ffff: ingress
tc filter add dev eth0 parent ffff: matchall \
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;action&nbsp;sample&nbsp;rate&nbsp;100&nbsp;group&nbsp;12&nbsp;index&nbsp;19
</DL>
<P>
Use the same action instance to sample eth1 too:
<P>
<DL COMPACT><DT id="12"><DD>
tc qdisc add dev eth1 handle ffff: ingress
tc filter add dev eth1 parent ffff: matchall \
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;action&nbsp;sample&nbsp;index&nbsp;19
</DL>
<P>
<A NAME="lbAH">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?8+tc">tc</A></B>(8),
<B><A HREF="/cgi-bin/man/man2html?8+tc-matchall">tc-matchall</A></B>(8)
<B><A HREF="/cgi-bin/man/man2html?1+psample">psample</A></B>(1)
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="13"><A HREF="#lbAB">NAME</A><DD>
<DT id="14"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="15"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="16"><A HREF="#lbAE">SAMPLED PACKETS METADATA FIELDS</A><DD>
<DT id="17"><A HREF="#lbAF">OPTIONS</A><DD>
<DT id="18"><A HREF="#lbAG">EXAMPLES</A><DD>
<DT id="19"><A HREF="#lbAH">SEE ALSO</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:06:17 GMT, March 31, 2021
</BODY>
</HTML>