xref: /freebsd/share/man/man4/ng_pipe.4 (revision fa9896e082a1046ff4fbc75fcba4d18d1f2efc19)
117019bffSChristian Brueffer.\" Copyright (c) 2019 Lutz Donnerhacke
217019bffSChristian Brueffer.\" Copyright (c) 2004-2008 University of Zagreb
317019bffSChristian Brueffer.\" Copyright (c) 2007-2008 FreeBSD Foundation
417019bffSChristian Brueffer.\" All rights reserved.
517019bffSChristian Brueffer.\"
617019bffSChristian Brueffer.\" Redistribution and use in source and binary forms, with or without
717019bffSChristian Brueffer.\" modification, are permitted provided that the following conditions
817019bffSChristian Brueffer.\" are met:
917019bffSChristian Brueffer.\" 1. Redistributions of source code must retain the above copyright
1017019bffSChristian Brueffer.\"    notice, this list of conditions and the following disclaimer.
1117019bffSChristian Brueffer.\" 2. Redistributions in binary form must reproduce the above copyright
1217019bffSChristian Brueffer.\"    notice, this list of conditions and the following disclaimer in the
1317019bffSChristian Brueffer.\"    documentation and/or other materials provided with the distribution.
1417019bffSChristian Brueffer.\"
1517019bffSChristian Brueffer.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1617019bffSChristian Brueffer.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1717019bffSChristian Brueffer.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1817019bffSChristian Brueffer.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1917019bffSChristian Brueffer.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2017019bffSChristian Brueffer.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2117019bffSChristian Brueffer.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2217019bffSChristian Brueffer.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2317019bffSChristian Brueffer.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2417019bffSChristian Brueffer.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2517019bffSChristian Brueffer.\" SUCH DAMAGE.
2617019bffSChristian Brueffer.\"
2717019bffSChristian Brueffer.Dd October 17, 2019
2817019bffSChristian Brueffer.Dt NG_PIPE 4
2917019bffSChristian Brueffer.Os
3017019bffSChristian Brueffer.Sh NAME
3117019bffSChristian Brueffer.Nm ng_pipe
3217019bffSChristian Brueffer.Nd Traffic manipulating netgraph node type
3317019bffSChristian Brueffer.Sh SYNOPSIS
3417019bffSChristian Brueffer.In netgraph/ng_pipe.h
3517019bffSChristian Brueffer.Sh DESCRIPTION
3617019bffSChristian BruefferThe
3717019bffSChristian Brueffer.Nm pipe
3817019bffSChristian Brueffernode type manipulates traffic by emulating bandwidth and delay, as well as
3917019bffSChristian Bruefferrandom packet losses.
4017019bffSChristian Brueffer.Sh HOOKS
4117019bffSChristian BruefferThis node type supports the following hooks:
4217019bffSChristian Brueffer.Bl -tag -width ".Va upper"
4317019bffSChristian Brueffer.It Va upper
4417019bffSChristian BruefferHook leading to upper layer protocols.
4517019bffSChristian Brueffer.It Va lower
4617019bffSChristian BruefferHook leading to lower layer protocols.
4717019bffSChristian Brueffer.El
4817019bffSChristian Brueffer.Pp
4917019bffSChristian BruefferTraffic flowing from
5017019bffSChristian Brueffer.Va upper
5117019bffSChristian Bruefferto
5217019bffSChristian Brueffer.Va lower
5317019bffSChristian Bruefferis considered
5417019bffSChristian Brueffer.Sy downstream
5517019bffSChristian Brueffertraffic.
5617019bffSChristian BruefferTraffic flowing from
5717019bffSChristian Brueffer.Va lower
5817019bffSChristian Bruefferto
5917019bffSChristian Brueffer.Va upper
6017019bffSChristian Bruefferis considered
6117019bffSChristian Brueffer.Sy upstream
6217019bffSChristian Brueffertraffic.
6317019bffSChristian Brueffer.Sh MODE OF OPERATION
6417019bffSChristian BruefferData received on a hook - both in upstream and downstream direction -
6517019bffSChristian Bruefferis put into an inbound queue.
6617019bffSChristian BruefferIf inbound queue is full, discard one frame
6717019bffSChristian Bruefferdepending on dropping policy (from the head or from the tail of the
6817019bffSChristian Bruefferqueue).
6917019bffSChristian Brueffer.Pp
7017019bffSChristian BruefferThere are three mutually exclusive modes for the input queue:
7117019bffSChristian Brueffer.Bl -tag -width foo
7217019bffSChristian Brueffer.It Dv "First In First Out (FIFO)"
7317019bffSChristian BruefferA single queue holds packets in chronological order.
7417019bffSChristian Brueffer.It Dv Weighted fair queuing (WFQ)
7517019bffSChristian BruefferThere are multiple queues for different traffic flows (based on IPv4
7617019bffSChristian BruefferIPs).
7717019bffSChristian BruefferThe longest queue is truncated if necessary.
7817019bffSChristian BruefferThis approach
7917019bffSChristian Bruefferassumes that the stalling flow is the flow with the most packets currently
8017019bffSChristian Bruefferon hold.
8117019bffSChristian Brueffer.It Dv Deficit Round Robin (DRR)
8217019bffSChristian BruefferThis mode is similar to WFQ, but packets are not taken out in
8317019bffSChristian Bruefferstrict chronological order.
8417019bffSChristian BruefferIn principle oldest packets come first,
8517019bffSChristian Bruefferbut not too many packets from the same flow.
8617019bffSChristian Brueffer.El
8717019bffSChristian Brueffer.Pp
8817019bffSChristian BruefferIt is possible to configure a duplication probability.
8917019bffSChristian BruefferAs the dice
9017019bffSChristian Bruefferdecides, the currently active packet stays in the queue while a copy
9117019bffSChristian Bruefferof the packet is sent out.
9217019bffSChristian BruefferNothing prevents a packet from being
9317019bffSChristian Bruefferduplicated multiple times.
9417019bffSChristian Brueffer.Pp
9517019bffSChristian BruefferPackets are dropped with an increasing probability depending on the
9617019bffSChristian Brueffersize of the packet, if a
9717019bffSChristian Brueffer.Va ber
9817019bffSChristian Brueffer(bit error rate) is configured.
9917019bffSChristian Brueffer.Pp
10017019bffSChristian BruefferSurviving packets are delayed by the time the packet would need to
10117019bffSChristian Brueffertravel through a link of the configured bandwidth.
10217019bffSChristian BruefferIf this outbound
10317019bffSChristian Bruefferqueue is full, the packet is dropped.
10417019bffSChristian Brueffer.Sh CONTROL MESSAGES
10517019bffSChristian BruefferThis node type supports the generic control messages and the following
10617019bffSChristian Bruefferspecific messages.
10717019bffSChristian Brueffer.Bl -tag -width foo
10817019bffSChristian Brueffer.It Dv NGM_PIPE_SET_CFG Pq Ic setcfg
10917019bffSChristian BruefferSet node configuration to the one specified in
11017019bffSChristian Brueffer.Vt "struct ng_pipe_cfg"
11117019bffSChristian Brueffer.Pp
11217019bffSChristian BruefferNote: To set a value to zero, specify -1 instead.
11317019bffSChristian BruefferThis allows omitting configuration values, which should not be
11417019bffSChristian Brueffermodified.
11517019bffSChristian Brueffer.It Dv NGM_PIPE_GET_CFG Pq Ic getcfg
11617019bffSChristian BruefferReturn current node configuration as
11717019bffSChristian Brueffer.Vt "struct ng_pipe_cfg"
11817019bffSChristian Brueffer.Bd -literal
11917019bffSChristian Bruefferstruct ng_pipe_cfg {
12017019bffSChristian Brueffer  u_int64_t  bandwidth;     /* bits per second */
12117019bffSChristian Brueffer  u_int64_t  delay;         /* additional delay, usec */
12217019bffSChristian Brueffer  u_int32_t  header_offset; /* offset of IP header in bytes */
12317019bffSChristian Brueffer  u_int32_t  overhead;      /* assumed L2 overhead in bytes */
12417019bffSChristian Brueffer  struct ng_pipe_hookcfg  downstream;
12517019bffSChristian Brueffer  struct ng_pipe_hookcfg  upstream;
12617019bffSChristian Brueffer};
12717019bffSChristian Brueffer
12817019bffSChristian Brueffer/* Config structure for one hook */
12917019bffSChristian Bruefferstruct ng_pipe_hookcfg {
13017019bffSChristian Brueffer  u_int64_t  bandwidth;       /* bits per second */
131*502305f0SMarko Zec  u_int64_t  ber;             /* avg. interval between bit errors (1 / BER) */
13217019bffSChristian Brueffer  u_int32_t  qin_size_limit;  /* number of queue items */
13317019bffSChristian Brueffer  u_int32_t  qout_size_limit; /* number of queue items */
13417019bffSChristian Brueffer  u_int32_t  duplicate;       /* probability in % */
13517019bffSChristian Brueffer  u_int32_t  fifo;            /* 0 = off, 1 = on */
13617019bffSChristian Brueffer  u_int32_t  drr;             /* 0 = off, 1 = 2048 bytes, or x bytes */
13717019bffSChristian Brueffer  u_int32_t  wfq;             /* 0 = off, 1 = on */
13817019bffSChristian Brueffer  u_int32_t  droptail;        /* 0 = off, 1 = on */
13917019bffSChristian Brueffer  u_int32_t  drophead;        /* 0 = off, 1 = on */
14017019bffSChristian Brueffer};
14117019bffSChristian Brueffer.Ed
14217019bffSChristian Brueffer.It Dv NGM_PIPE_GET_STATS Pq Ic getstats
14317019bffSChristian BruefferReturn node statistics as
14417019bffSChristian Brueffer.Vt "struct ng_pipe_stats"
14517019bffSChristian Brueffer.Bd -literal
14617019bffSChristian Brueffer/* Statistics structure for one hook */
14717019bffSChristian Bruefferstruct ng_pipe_hookstat {
14817019bffSChristian Brueffer  u_int64_t  fwd_octets;
14917019bffSChristian Brueffer  u_int64_t  fwd_frames;
15017019bffSChristian Brueffer  u_int64_t  in_disc_octets;
15117019bffSChristian Brueffer  u_int64_t  in_disc_frames;
15217019bffSChristian Brueffer  u_int64_t  out_disc_octets;
15317019bffSChristian Brueffer  u_int64_t  out_disc_frames;
15417019bffSChristian Brueffer};
15517019bffSChristian Brueffer
15617019bffSChristian Brueffer/* Statistics structure returned by NGM_PIPE_GET_STATS */
15717019bffSChristian Bruefferstruct ng_pipe_stats {
15817019bffSChristian Brueffer  struct ng_pipe_hookstat  downstream;
15917019bffSChristian Brueffer  struct ng_pipe_hookstat  upstream;
16017019bffSChristian Brueffer};
16117019bffSChristian Brueffer.Ed
16217019bffSChristian Brueffer.It Dv NGM_PIPE_CLR_STATS Pq Ic clrstats
16317019bffSChristian BruefferClear node statistics.
16417019bffSChristian Brueffer.It Dv NGM_PIPE_GETCLR_STATS Pq Ic getclrstats
16517019bffSChristian BruefferAtomically return and clear node statistics.
16617019bffSChristian Brueffer.It Dv NGM_PIPE_GET_RUN Pq Ic getrun
16717019bffSChristian BruefferReturn node statistics as
16817019bffSChristian Brueffer.Vt "struct ng_pipe_run"
16917019bffSChristian Brueffer.Bd -literal
17017019bffSChristian Brueffer/* Runtime structure for one hook */
17117019bffSChristian Bruefferstruct ng_pipe_hookrun {
17217019bffSChristian Brueffer  u_int32_t  fifo_queues;
17317019bffSChristian Brueffer  u_int32_t  qin_octets;
17417019bffSChristian Brueffer  u_int32_t  qin_frames;
17517019bffSChristian Brueffer  u_int32_t  qout_octets;
17617019bffSChristian Brueffer  u_int32_t  qout_frames;
17717019bffSChristian Brueffer};
17817019bffSChristian Brueffer
17917019bffSChristian Brueffer/* Runtime structure returned by NGM_PIPE_GET_RUN */
18017019bffSChristian Bruefferstruct ng_pipe_run {
18117019bffSChristian Brueffer  struct ng_pipe_hookrun  downstream;
18217019bffSChristian Brueffer  struct ng_pipe_hookrun  upstream;
18317019bffSChristian Brueffer};
18417019bffSChristian Brueffer.Ed
18517019bffSChristian Brueffer.El
18617019bffSChristian Brueffer.Sh SHUTDOWN
18717019bffSChristian BruefferThis node shuts down upon receipt of a
18817019bffSChristian Brueffer.Dv NGM_SHUTDOWN
18917019bffSChristian Brueffercontrol message, or when all hooks have been disconnected.
19017019bffSChristian Brueffer.Sh EXAMPLES
19117019bffSChristian BruefferLimit outgoing data rate over fxp0 Ethernet interface to 20Mbps in
19217019bffSChristian Bruefferfifo mode and incoming to 50kbps in drr mode and 2% duplicate
19317019bffSChristian Bruefferprobability.
19417019bffSChristian Brueffer.Bd -literal -offset indent
19517019bffSChristian Brueffer/usr/sbin/ngctl -f- <<-SEQ
19617019bffSChristian Brueffer  mkpeer fxp0: pipe lower lower
19717019bffSChristian Brueffer  name fxp0:lower fxp0_pipe
19817019bffSChristian Brueffer  connect fxp0: fxp0_pipe: upper upper
19917019bffSChristian Brueffer  msg fxp0_pipe: setcfg { downstream={ bandwidth=20000000 fifo=1 } }
20017019bffSChristian Brueffer  msg fxp0_pipe: setcfg { upstream={ bandwidth=500000 drr=1 duplicate=2 } }
20117019bffSChristian BruefferSEQ
20217019bffSChristian Brueffer.Ed
20317019bffSChristian Brueffer.Sh SEE ALSO
20417019bffSChristian Brueffer.Xr netgraph 4 ,
20517019bffSChristian Brueffer.Xr ngctl 8
20617019bffSChristian Brueffer.Sh AUTHORS
20717019bffSChristian Brueffer.An Lutz Donnerhacke Aq Mt lutz@donnerhacke.de
20817019bffSChristian Brueffer.Pq man page
20917019bffSChristian Brueffer.Sh BUGS
21017019bffSChristian BruefferError handling for memory issues is missing.
21117019bffSChristian BruefferIf kernel memory cannot be allocated immediately, a kernel panic will
21217019bffSChristian Bruefferbe triggered.
21317019bffSChristian BruefferSame happens if an mbuf is fragmented within the transport headers.
214