xref: /freebsd/share/man/man4/ng_car.4 (revision fa9896e082a1046ff4fbc75fcba4d18d1f2efc19)
1db5bc679SAlexander Motin.\" Copyright (c) 2005 Nuno Antunes <nuno.antunes@gmail.com>
2d886f546SAlexander Motin.\" Copyright (c) 2007 Alexander Motin <mav@FreeBSD.org>
3db5bc679SAlexander Motin.\" All rights reserved.
4db5bc679SAlexander Motin.\"
5db5bc679SAlexander Motin.\" Redistribution and use in source and binary forms, with or without
6db5bc679SAlexander Motin.\" modification, are permitted provided that the following conditions
7db5bc679SAlexander Motin.\" are met:
8db5bc679SAlexander Motin.\" 1. Redistributions of source code must retain the above copyright
9db5bc679SAlexander Motin.\"    notice, this list of conditions and the following disclaimer.
10db5bc679SAlexander Motin.\" 2. Redistributions in binary form must reproduce the above copyright
11db5bc679SAlexander Motin.\"    notice, this list of conditions and the following disclaimer in the
12db5bc679SAlexander Motin.\"    documentation and/or other materials provided with the distribution.
13db5bc679SAlexander Motin.\"
14db5bc679SAlexander Motin.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15db5bc679SAlexander Motin.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16db5bc679SAlexander Motin.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17db5bc679SAlexander Motin.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18db5bc679SAlexander Motin.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19db5bc679SAlexander Motin.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20db5bc679SAlexander Motin.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21db5bc679SAlexander Motin.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22db5bc679SAlexander Motin.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23db5bc679SAlexander Motin.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24db5bc679SAlexander Motin.\" SUCH DAMAGE.
25db5bc679SAlexander Motin.\"
26*d0d2e523SLutz Donnerhacke.Dd January 27, 2021
27db5bc679SAlexander Motin.Dt NG_CAR 4
28db5bc679SAlexander Motin.Os
29db5bc679SAlexander Motin.Sh NAME
30db5bc679SAlexander Motin.Nm ng_car
31f6ac2391SJoel Dahl.Nd Committed Access Rate netgraph node type
32db5bc679SAlexander Motin.Sh SYNOPSIS
33db5bc679SAlexander Motin.In netgraph/ng_car.h
34db5bc679SAlexander Motin.Sh DESCRIPTION
35db5bc679SAlexander MotinThe
36db5bc679SAlexander Motin.Nm car
37db5bc679SAlexander Motinnode type limits traffic flowing through it using:
38db5bc679SAlexander Motin.Pp
39db5bc679SAlexander Motin.Bl -bullet -compact
40db5bc679SAlexander Motin.It
41d4261539SChristian BruefferSingle rate three color marker as described in RFC 2697,
42db5bc679SAlexander Motin.It
43d4261539SChristian BruefferTwo rate three color marker as described in RFC 2698,
44db5bc679SAlexander Motin.It
45db5bc679SAlexander MotinRED-like rate limit algorithm used by Cisco,
46db5bc679SAlexander Motin.It
47db5bc679SAlexander MotinTraffic shaping with RED.
48db5bc679SAlexander Motin.El
49db5bc679SAlexander Motin.Sh HOOKS
50db5bc679SAlexander MotinThis node type supports the following hooks:
51c60bda17SJoel Dahl.Bl -tag -width ".Va upper"
52db5bc679SAlexander Motin.It Va upper
53db5bc679SAlexander MotinHook leading to upper layer protocols.
54db5bc679SAlexander Motin.It Va lower
55db5bc679SAlexander MotinHook leading to lower layer protocols.
56db5bc679SAlexander Motin.El
57db5bc679SAlexander Motin.Pp
58db5bc679SAlexander MotinTraffic flowing from
59db5bc679SAlexander Motin.Va upper
60db5bc679SAlexander Motinto
61db5bc679SAlexander Motin.Va lower
62db5bc679SAlexander Motinis considered
63db5bc679SAlexander Motin.Sy downstream
64db5bc679SAlexander Motintraffic.
65db5bc679SAlexander MotinTraffic flowing from
66db5bc679SAlexander Motin.Va lower
67db5bc679SAlexander Motinto
68db5bc679SAlexander Motin.Va upper
69db5bc679SAlexander Motinis considered
70db5bc679SAlexander Motin.Sy upstream
71db5bc679SAlexander Motintraffic.
72db5bc679SAlexander Motin.Sh MODES OF OPERATION
73cd27e26cSAlexander MotinEach hook can operate in one of the following modes:
74c60bda17SJoel Dahl.Bl -tag -width foo
75db5bc679SAlexander Motin.It Dv NG_CAR_SINGLE_RATE
76d4261539SChristian BruefferSingle rate three color marker as described in RFC 2697.
77cd27e26cSAlexander MotinCommitted burst packets are counted as green, extended burst packets are
78cd27e26cSAlexander Motincounted as yellow and exceeding packets are counted as red.
79cd27e26cSAlexander MotinCommitted burst getting refilled with CIR (Committed Information Rate) speed.
80db5bc679SAlexander MotinWhen it is full, exceeded burst getting refilled.
81db5bc679SAlexander Motin.It Dv NG_CAR_DOUBLE_RATE
82d886f546SAlexander MotinTwo rate three color marker as described in RFC 2698.
83cd27e26cSAlexander MotinCommitted burst packets are counted as green, peak burst packets are counted
84cd27e26cSAlexander Motinas yellow and exceeding packets are counted as red.
85cd27e26cSAlexander MotinCommitted burst getting refilled with CIR speed.
86cd27e26cSAlexander MotinPeak burst getting refilled with PIR (Peak Information Rate) speed at the
87cd27e26cSAlexander Motinsame time.
88db5bc679SAlexander Motin.It Dv NG_CAR_RED
89cd27e26cSAlexander MotinSimilar to
90cd27e26cSAlexander Motin.Dv NG_CAR_SINGLE_RATE ,
91cd27e26cSAlexander Motinbut with different understanding of extended burst.
92cd27e26cSAlexander MotinWhen normal burst exceeded and extended burst is used, packets are counted
93cd27e26cSAlexander Motinred with probability equal to part of extended burst consumed.
94cd27e26cSAlexander MotinExtended burst getting refilled first.
95cd27e26cSAlexander MotinWhen it is full, committed burst getting refilled.
96cd27e26cSAlexander MotinThis behavior is similar to RED active queue management algorithm.
97db5bc679SAlexander Motin.Pp
9806450dbeSAlexander MotinThis algorithm is more polite to the TCP traffic than NG_CAR_SINGLE_RATE.
99db5bc679SAlexander Motin.It Dv NG_CAR_SHAPE
100db5bc679SAlexander MotinCommitted burst packets are counted as green, exceeding packets are delayed
101cd27e26cSAlexander Motinby queue with RED management and counted as yellow.
102cd27e26cSAlexander MotinPackets dropped by queue counted as red.
103db5bc679SAlexander MotinQueue parameters are hardcoded: length 99 packets, min_th 8 packets, max_p 100%.
104db5bc679SAlexander Motin.Pp
10506450dbeSAlexander MotinTraffic shaping is much more polite to the TCP traffic than rate limit on
10606450dbeSAlexander Motinlinks with bandwidth * delay product less than 6-8 TCP segments, but it
107cd27e26cSAlexander Motinconsumes additional system resources for queue processing.
108db5bc679SAlexander Motin.El
109*d0d2e523SLutz Donnerhacke.Pp
110259c0b2fSAlexander MotinBy default, all information rates are measured in bits per second and bursts
11125972509SEdward Tomasz Napieralaare measured in bytes.
11225972509SEdward Tomasz NapieralaBut when NG_CAR_COUNT_PACKETS option is enabled,
113259c0b2fSAlexander Motinrates are measured in packets per second and bursts are in packets.
114db5bc679SAlexander Motin.Sh CONTROL MESSAGES
115db5bc679SAlexander MotinThis node type supports the generic control messages and the following
116db5bc679SAlexander Motinspecific messages.
117c60bda17SJoel Dahl.Bl -tag -width foo
118c60bda17SJoel Dahl.It Dv NGM_CAR_SET_CONF Pq Ic setconf
119db5bc679SAlexander MotinSet node configuration to the specified at
120db5bc679SAlexander Motin.Vt "struct ng_car_bulkconf"
121c60bda17SJoel Dahl.It Dv NGM_CAR_GET_CONF Pq Ic getconf
122db5bc679SAlexander MotinReturn current node configuration as
123db5bc679SAlexander Motin.Vt "struct ng_car_bulkconf"
124cd27e26cSAlexander Motin.Bd -literal
125db5bc679SAlexander Motinstruct ng_car_hookconf {
1267c64ddd5SWarren Block	uint64_t cbs;		/* Committed burst size (bytes) */
127c60bda17SJoel Dahl	uint64_t ebs;		/* Exceeded/Peak burst size (bytes) */
1287c64ddd5SWarren Block	uint64_t cir;		/* Committed information rate (bits/s) */
129c60bda17SJoel Dahl	uint64_t pir;		/* Peak information rate (bits/s) */
1306b99842aSEd Schouten	uint8_t  green_action;	/* Action for green packets */
1316b99842aSEd Schouten	uint8_t  yellow_action;	/* Action for yellow packets */
1326b99842aSEd Schouten	uint8_t  red_action;	/* Action for red packets */
133c60bda17SJoel Dahl	uint8_t  mode;		/* single/double rate, ... */
134c60bda17SJoel Dahl	uint8_t  opt;		/* color-aware or color-blind */
135db5bc679SAlexander Motin};
136db5bc679SAlexander Motin
137259c0b2fSAlexander Motin/* possible actions (..._action) */
138259c0b2fSAlexander Motinenum {
139259c0b2fSAlexander Motin    NG_CAR_ACTION_FORWARD = 1,
140*d0d2e523SLutz Donnerhacke    NG_CAR_ACTION_DROP,
141*d0d2e523SLutz Donnerhacke    NG_CAR_ACTION_MARK
142259c0b2fSAlexander Motin};
143259c0b2fSAlexander Motin
144259c0b2fSAlexander Motin/* operation modes (mode) */
145259c0b2fSAlexander Motinenum {
146259c0b2fSAlexander Motin    NG_CAR_SINGLE_RATE = 0,
147259c0b2fSAlexander Motin    NG_CAR_DOUBLE_RATE,
148259c0b2fSAlexander Motin    NG_CAR_RED,
149259c0b2fSAlexander Motin    NG_CAR_SHAPE
150259c0b2fSAlexander Motin};
151259c0b2fSAlexander Motin
152*d0d2e523SLutz Donnerhacke/* mode options (bits for opt) */
153*d0d2e523SLutz Donnerhacke#define NG_CAR_COLOR_AWARE	1
154259c0b2fSAlexander Motin#define NG_CAR_COUNT_PACKETS	2
155259c0b2fSAlexander Motin
156db5bc679SAlexander Motinstruct ng_car_bulkconf {
157db5bc679SAlexander Motin	struct ng_car_hookconf upstream;
158db5bc679SAlexander Motin	struct ng_car_hookconf downstream;
159db5bc679SAlexander Motin};
160db5bc679SAlexander Motin.Ed
161c60bda17SJoel Dahl.It Dv NGM_CAR_GET_STATS Pq Ic getstats
162db5bc679SAlexander MotinReturn node statistics as
163db5bc679SAlexander Motin.Vt "struct ng_car_bulkstats"
164cd27e26cSAlexander Motin.Bd -literal
165db5bc679SAlexander Motinstruct ng_car_hookstats {
166c60bda17SJoel Dahl	uint64_t passed_pkts;	/* Counter for passed packets */
167def4e701SGleb Smirnoff	uint64_t dropped_pkts;	/* Counter for dropped packets */
168c60bda17SJoel Dahl	uint64_t green_pkts;	/* Counter for green packets */
169c60bda17SJoel Dahl	uint64_t yellow_pkts;	/* Counter for yellow packets */
170c60bda17SJoel Dahl	uint64_t red_pkts;	/* Counter for red packets */
171c60bda17SJoel Dahl	uint64_t errors;	/* Counter for operation errors */
172db5bc679SAlexander Motin};
173db5bc679SAlexander Motin
174db5bc679SAlexander Motinstruct ng_car_bulkstats {
175db5bc679SAlexander Motin	struct ng_car_hookstats upstream;
176db5bc679SAlexander Motin	struct ng_car_hookstats downstream;
177db5bc679SAlexander Motin};
178db5bc679SAlexander Motin.Ed
179c60bda17SJoel Dahl.It Dv NGM_CAR_CLR_STATS Pq Ic clrstats
180db5bc679SAlexander MotinClear node statistics.
181c60bda17SJoel Dahl.It Dv NGM_CAR_GETCLR_STATS Pq Ic getclrstats
182d4261539SChristian BruefferAtomically return and clear node statistics.
183db5bc679SAlexander Motin.El
184db5bc679SAlexander Motin.Sh SHUTDOWN
185db5bc679SAlexander MotinThis node shuts down upon receipt of a
186db5bc679SAlexander Motin.Dv NGM_SHUTDOWN
187db5bc679SAlexander Motincontrol message, or when all hooks have been disconnected.
1889cce7404SAlexander Motin.Sh EXAMPLES
1899cce7404SAlexander MotinLimit outgoing data rate over fxp0 Ethernet interface to 20Mbit/s
1909cce7404SAlexander Motinand incoming packet rate to 5000pps.
1919cce7404SAlexander Motin.Bd -literal -offset indent
1929cce7404SAlexander Motin/usr/sbin/ngctl -f- <<-SEQ
1939cce7404SAlexander Motin	mkpeer fxp0: car lower lower
1949cce7404SAlexander Motin	name fxp0:lower fxp0_car
1959cce7404SAlexander Motin	connect fxp0: fxp0_car: upper upper
1969cce7404SAlexander Motin	msg fxp0_car: setconf { downstream={ cir=20000000 cbs=2500000 ebs=2500000 greenAction=1 yellowAction=1 redAction=2 mode=2 } upstream={ cir=5000 cbs=100 ebs=100 greenAction=1 yellowAction=1 redAction=2 mode=2 opt=2 } }
1979cce7404SAlexander MotinSEQ
1989cce7404SAlexander Motin.Ed
199db5bc679SAlexander Motin.Sh SEE ALSO
200db5bc679SAlexander Motin.Xr netgraph 4 ,
201db5bc679SAlexander Motin.Xr ngctl 8
202db5bc679SAlexander Motin.Rs
203db5bc679SAlexander Motin.%A J. Heinanen
204db5bc679SAlexander Motin.%T "A Single Rate Three Color Marker"
205db5bc679SAlexander Motin.%O RFC 2697
206db5bc679SAlexander Motin.Re
207db5bc679SAlexander Motin.Rs
208db5bc679SAlexander Motin.%A J. Heinanen
209db5bc679SAlexander Motin.%T "A Two Rate Three Color Marker"
210db5bc679SAlexander Motin.%O RFC 2698
211db5bc679SAlexander Motin.Re
212db5bc679SAlexander Motin.Sh AUTHORS
2136c899950SBaptiste Daroussin.An Nuno Antunes Aq Mt nuno.antunes@gmail.com
2146c899950SBaptiste Daroussin.An Alexander Motin Aq Mt mav@FreeBSD.org
215db5bc679SAlexander Motin.Sh BUGS
216cd27e26cSAlexander MotinAt this moment only DROP and FORWARD actions are implemented.
217