xref: /freebsd/share/man/man4/ng_source.4 (revision 58b1cfde0d18c9aaf12736b97660683c5985a403)
158b1cfdeSEd Maste.\" Copyright 2002-2006 Sandvine Inc.
2585ff168SJulian Elischer.\" All rights reserved.
3585ff168SJulian Elischer.\"
4585ff168SJulian Elischer.\" Subject to the following obligations and disclaimer of warranty, use and
5585ff168SJulian Elischer.\" redistribution of this software, in source or object code forms, with or
6585ff168SJulian Elischer.\" without modifications are expressly permitted by Sandvine Inc.; provided,
7585ff168SJulian Elischer.\" however, that:
8585ff168SJulian Elischer.\" 1. Any and all reproductions of the source or object code must include the
9585ff168SJulian Elischer.\"    copyright notice above and the following disclaimer of warranties; and
10585ff168SJulian Elischer.\" 2. No rights are granted, in any manner or form, to use Sandvine Inc.
11585ff168SJulian Elischer.\"    trademarks, including the mark "SANDVINE" on advertising, endorsements,
12585ff168SJulian Elischer.\"    or otherwise except as such appears in the above copyright notice or in
13585ff168SJulian Elischer.\"    the software.
14585ff168SJulian Elischer.\"
15585ff168SJulian Elischer.\" THIS SOFTWARE IS BEING PROVIDED BY SANDVINE "AS IS", AND TO THE MAXIMUM
16585ff168SJulian Elischer.\" EXTENT PERMITTED BY LAW, SANDVINE MAKES NO REPRESENTATIONS OR WARRANTIES,
17585ff168SJulian Elischer.\" EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE, INCLUDING WITHOUT LIMITATION,
18585ff168SJulian Elischer.\" ANY AND ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
19585ff168SJulian Elischer.\" PURPOSE, OR NON-INFRINGEMENT.  SANDVINE DOES NOT WARRANT, GUARANTEE, OR
20585ff168SJulian Elischer.\" MAKE ANY REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE
21585ff168SJulian Elischer.\" USE OF THIS SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY
22585ff168SJulian Elischer.\" OR OTHERWISE.  IN NO EVENT SHALL SANDVINE BE LIABLE FOR ANY DAMAGES
23585ff168SJulian Elischer.\" RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING
24585ff168SJulian Elischer.\" WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
25585ff168SJulian Elischer.\" PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR
26585ff168SJulian Elischer.\" SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
27585ff168SJulian Elischer.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28585ff168SJulian Elischer.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29585ff168SJulian Elischer.\" THIS SOFTWARE, EVEN IF SANDVINE IS ADVISED OF THE POSSIBILITY OF SUCH
30585ff168SJulian Elischer.\" DAMAGE.
31585ff168SJulian Elischer.\"
32585ff168SJulian Elischer.\" Author: Dave Chapeskie <dchapeskie@sandvine.com>
33585ff168SJulian Elischer.\" $FreeBSD$
34585ff168SJulian Elischer.\"
3558b1cfdeSEd Maste.Dd October 22, 2006
36585ff168SJulian Elischer.Dt NG_SOURCE 4
37585ff168SJulian Elischer.Os
38585ff168SJulian Elischer.Sh NAME
39585ff168SJulian Elischer.Nm ng_source
4037684cf3SGleb Smirnoff.Nd netgraph node for traffic generation
41585ff168SJulian Elischer.Sh SYNOPSIS
42fbad9e2dSRuslan Ermilov.In sys/types.h
43585ff168SJulian Elischer.In netgraph/ng_source.h
44585ff168SJulian Elischer.Sh DESCRIPTION
45585ff168SJulian ElischerThe
46585ff168SJulian Elischer.Nm source
47585ff168SJulian Elischernode acts as a source of packets according to the parameters set up
48585ff168SJulian Elischerusing control messages and input packets.
4976648c1fSRuslan ErmilovThe
5037684cf3SGleb Smirnoff.Nm
5137684cf3SGleb Smirnoffnode type is used primarily for testing and benchmarking.
52585ff168SJulian Elischer.Sh HOOKS
53585ff168SJulian ElischerThe
54585ff168SJulian Elischer.Nm source
5576648c1fSRuslan Ermilovnode has two hooks:
5637684cf3SGleb Smirnoff.Va input
5776648c1fSRuslan Ermilovand
5837684cf3SGleb Smirnoff.Va output .
5976648c1fSRuslan ErmilovThe
6037684cf3SGleb Smirnoff.Va output
61585ff168SJulian Elischerhook must remain connected, its disconnection will shutdown the node.
6237684cf3SGleb Smirnoff.Sh OPERATION
6337684cf3SGleb SmirnoffThe operation of the node is as follows.
6437684cf3SGleb SmirnoffPackets received on the
6537684cf3SGleb Smirnoff.Va input
6637684cf3SGleb Smirnoffhook are queued internally.
6737684cf3SGleb SmirnoffWhen
6837684cf3SGleb Smirnoff.Va output
6937684cf3SGleb Smirnoffhook is connected,
7037684cf3SGleb Smirnoff.Nm
7137684cf3SGleb Smirnoffnode assumes that its neighbour node is of
724f068961SRuslan Ermilov.Xr ng_ether 4
7337684cf3SGleb Smirnoffnode type.
744f068961SRuslan ErmilovThe neighbour is queried for its interface name.
754f068961SRuslan ErmilovThe
7637684cf3SGleb Smirnoff.Nm
7737684cf3SGleb Smirnoffnode then uses queue of the interface for its evil purposes.
784f068961SRuslan ErmilovThe
7937684cf3SGleb Smirnoff.Nm
8037684cf3SGleb Smirnoffnode also disables
8137684cf3SGleb Smirnoff.Va autosrc
8237684cf3SGleb Smirnoffoption on neighbour
834f068961SRuslan Ermilov.Xr ng_ether 4
8437684cf3SGleb Smirnoffnode.
854f068961SRuslan ErmilovIf interface name cannot be obtained automatically, it should
864f068961SRuslan Ermilovbe configured explicitly with the
8737684cf3SGleb Smirnoff.Dv NGM_SOURCE_SETIFACE
8837684cf3SGleb Smirnoffcontrol message, and
8937684cf3SGleb Smirnoff.Va autosrc
9037684cf3SGleb Smirnoffshould be turned off on
914f068961SRuslan Ermilov.Xr ng_ether 4
9237684cf3SGleb Smirnoffnode manually.
9337684cf3SGleb Smirnoff.Pp
944f068961SRuslan ErmilovOnce interface is configured, upon receipt of a
9537684cf3SGleb Smirnoff.Dv NGM_SOURCE_START
9637684cf3SGleb Smirnoffcontrol message the node starts sending
9737684cf3SGleb Smirnoffthe previously queued packets out the
9837684cf3SGleb Smirnoff.Va output
9937684cf3SGleb Smirnoffhook on every clock tick as fast
10037684cf3SGleb Smirnoffas the connected interface will take them.
10137684cf3SGleb SmirnoffWhile active, on every clock tick the node checks the available space
10237684cf3SGleb Smirnoffin the interface queue and sends that many packets out its
10337684cf3SGleb Smirnoff.Va output
10437684cf3SGleb Smirnoffhook.
1054f068961SRuslan ErmilovOnce the number of packets indicated in the start message has been
1064f068961SRuslan Ermilovsent, or upon receipt of a
1074f068961SRuslan Ermilov.Dv NGM_SOURCE_STOP
1084f068961SRuslan Ermilovmessage, the node stops sending data.
109585ff168SJulian Elischer.Sh CONTROL MESSAGES
110585ff168SJulian ElischerThis node type supports the generic control messages as well as the following,
111585ff168SJulian Elischerwhich must be sent with the
11276648c1fSRuslan Ermilov.Dv NGM_SOURCE_COOKIE
113585ff168SJulian Elischerattached.
11476648c1fSRuslan Ermilov.Bl -tag -width indent
11576648c1fSRuslan Ermilov.It Dv NGM_SOURCE_GET_STATS Pq Ic getstats
116585ff168SJulian ElischerReturns a structure containing the following fields:
11776648c1fSRuslan Ermilov.Bl -tag -width indent
11876648c1fSRuslan Ermilov.It Va outOctets
11976648c1fSRuslan ErmilovThe number of octets/bytes sent out the
1204f068961SRuslan Ermilov.Va output
12176648c1fSRuslan Ermilovhook.
12276648c1fSRuslan Ermilov.It Va outFrames
12376648c1fSRuslan ErmilovThe number of frames/packets sent out the
1244f068961SRuslan Ermilov.Va output
12576648c1fSRuslan Ermilovhook.
12676648c1fSRuslan Ermilov.It Va queueOctets
12776648c1fSRuslan ErmilovThe number of octets queued from the
1284f068961SRuslan Ermilov.Va input
12976648c1fSRuslan Ermilovhook.
13076648c1fSRuslan Ermilov.It Va queueFrames
13176648c1fSRuslan ErmilovThe number of frames queued from the
1324f068961SRuslan Ermilov.Va input
13376648c1fSRuslan Ermilovhook.
13476648c1fSRuslan Ermilov.It Va startTime
13576648c1fSRuslan ErmilovThe time the last start message was received.
13676648c1fSRuslan Ermilov.It Va endTime
13776648c1fSRuslan ErmilovThe time the last end message was received or
138585ff168SJulian Elischerthe output packet count was reached.
13976648c1fSRuslan Ermilov.It Va elapsedTime
14076648c1fSRuslan ErmilovEither
14176648c1fSRuslan Ermilov.Va endTime Li \- Va startTime
14276648c1fSRuslan Ermilovor current time
14376648c1fSRuslan Ermilov\-
14476648c1fSRuslan Ermilov.Va startTime .
145585ff168SJulian Elischer.El
14676648c1fSRuslan Ermilov.It Dv NGM_SOURCE_CLR_STATS Pq Ic clrstats
14776648c1fSRuslan ErmilovClears and resets the statistics returned by
14876648c1fSRuslan Ermilov.Ic getstats
14976648c1fSRuslan Ermilov(except
15076648c1fSRuslan Ermilov.Va queueOctets
15176648c1fSRuslan Ermilovand
15276648c1fSRuslan Ermilov.Va queueFrames ) .
15376648c1fSRuslan Ermilov.It Dv NGM_SOURCE_GETCLR_STATS Pq Ic getclrstats
15476648c1fSRuslan ErmilovAs
15576648c1fSRuslan Ermilov.Ic getstats
15676648c1fSRuslan Ermilovbut clears the statistics at the same time.
15776648c1fSRuslan Ermilov.It Dv NGM_SOURCE_START Pq Ic start
15837684cf3SGleb SmirnoffThis message requires a single
15937684cf3SGleb Smirnoff.Vt uint64_t
16076648c1fSRuslan Ermilovparameter which is the number of packets to
161585ff168SJulian Elischersend before stopping.
1624f068961SRuslan ErmilovNode starts sending the queued packets out the
1634f068961SRuslan Ermilov.Va output
1644f068961SRuslan Ermilovhook.
1654f068961SRuslan ErmilovThe
1664f068961SRuslan Ermilov.Va output
1674f068961SRuslan Ermilovhook must be connected and node must have
16837684cf3SGleb Smirnoffinterface configured.
16976648c1fSRuslan Ermilov.It Dv NGM_SOURCE_STOP Pq Ic stop
170585ff168SJulian ElischerStops the node if it is active.
17176648c1fSRuslan Ermilov.It Dv NGM_SOURCE_CLR_DATA Pq Ic clrdata
17276648c1fSRuslan ErmilovClears the packets queued from the
1734f068961SRuslan Ermilov.Va input
17476648c1fSRuslan Ermilovhook.
17537684cf3SGleb Smirnoff.It Dv NGM_SOURCE_SETIFACE Pq Ic setiface
1764f068961SRuslan ErmilovThis message requires the name of the interface
1774f068961SRuslan Ermilovto be configured as an argument.
17872235857SGleb Smirnoff.It Dv NGM_SOURCE_SETPPS Pq Ic setpps
17972235857SGleb SmirnoffThis message requires a single
18072235857SGleb Smirnoff.Vt uint32_t
18172235857SGleb Smirnoffparameter which puts upper limit on the amount of packets
18272235857SGleb Smirnoffsent per second.
183585ff168SJulian Elischer.El
184585ff168SJulian Elischer.Sh SHUTDOWN
185585ff168SJulian ElischerThis node shuts down upon receipt of a
186585ff168SJulian Elischer.Dv NGM_SHUTDOWN
1874f068961SRuslan Ermilovcontrol message, when all hooks have been disconnected, or when the
18837684cf3SGleb Smirnoff.Va output
189585ff168SJulian Elischerhook has been disconnected.
19076648c1fSRuslan Ermilov.Sh EXAMPLES
19176648c1fSRuslan ErmilovAttach the node to an
19276648c1fSRuslan Ermilov.Xr ng_ether 4
19376648c1fSRuslan Ermilovnode for an interface.
19476648c1fSRuslan ErmilovIf
19576648c1fSRuslan Ermilov.Nm ng_ether
19676648c1fSRuslan Ermilovis
19776648c1fSRuslan Ermilovnot already loaded you will need to do so.
19876648c1fSRuslan ErmilovFor example, these commands
19976648c1fSRuslan Ermilovload the
20076648c1fSRuslan Ermilov.Nm ng_ether
20176648c1fSRuslan Ermilovmodule and attach the
2024f068961SRuslan Ermilov.Va output
20376648c1fSRuslan Ermilovhook of a new
20476648c1fSRuslan Ermilov.Nm source
20576648c1fSRuslan Ermilovnode to
2064f068961SRuslan Ermilov.Va orphans
20776648c1fSRuslan Ermilovhook of the
20876648c1fSRuslan Ermilov.Li bge0:
20976648c1fSRuslan Ermilov.Nm ng_ether
21076648c1fSRuslan Ermilovnode.
21176648c1fSRuslan Ermilov.Bd -literal -offset indent
21276648c1fSRuslan Ermilovkldload ng_ether
21376648c1fSRuslan Ermilovngctl mkpeer bge0: source orphans output
214585ff168SJulian Elischer.Ed
215585ff168SJulian Elischer.Pp
21676648c1fSRuslan ErmilovAt this point the new node can be referred to as
21776648c1fSRuslan Ermilov.Dq Li bge0:orphans .
21876648c1fSRuslan ErmilovThe
21976648c1fSRuslan Ermilovnode can be given its own name like this:
220585ff168SJulian Elischer.Pp
22176648c1fSRuslan Ermilov.Dl "ngctl name bge0:orphans src0"
222585ff168SJulian Elischer.Pp
22376648c1fSRuslan ErmilovAfter which it can be referred to as
22476648c1fSRuslan Ermilov.Dq Li src0: .
225585ff168SJulian Elischer.Pp
22658b1cfdeSEd MasteOnce created, packets can be sent to the node as raw binary data.
22758b1cfdeSEd MasteEach packet must be delivered in a separate netgraph message.
228585ff168SJulian Elischer.Pp
22958b1cfdeSEd MasteThe following example uses a short Perl script to convert the hex
23058b1cfdeSEd Masterepresentation of an ICMP packet to binary and deliver it to the
23176648c1fSRuslan Ermilov.Nm source
23276648c1fSRuslan Ermilovnode's
2334f068961SRuslan Ermilov.Va input
23476648c1fSRuslan Ermilovhook via
23576648c1fSRuslan Ermilov.Xr nghook 8 :
23658b1cfdeSEd Maste.Bd -literal -offset indent
23758b1cfdeSEd Masteperl -pe 's/(..)[ \et\en]*/chr(hex($1))/ge' <<EOF | nghook src0: input
23858b1cfdeSEd Masteff ff ff ff ff ff 00 00 00 00 00 00 08 00 45 00
23958b1cfdeSEd Maste00 54 cb 13 00 00 40 01 b9 87 c0 a8 2b 65 0a 00
24058b1cfdeSEd Maste00 01 08 00 f8 d0 c9 76 00 00 45 37 01 73 00 01
24158b1cfdeSEd Maste04 0a 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15
24258b1cfdeSEd Maste16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25
24358b1cfdeSEd Maste26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35
24458b1cfdeSEd Maste36 37
24558b1cfdeSEd MasteEOF
24658b1cfdeSEd Maste.Ed
247585ff168SJulian Elischer.Pp
248585ff168SJulian ElischerTo check that the node has queued these packets you can get the node
249585ff168SJulian Elischerstatistics:
25076648c1fSRuslan Ermilov.Bd -literal -offset indent
25176648c1fSRuslan Ermilovngctl msg bge0:orphans getstats
252585ff168SJulian ElischerArgs:   { queueOctets=64 queueFrames=1 }
253585ff168SJulian Elischer.Ed
254585ff168SJulian Elischer.Pp
25576648c1fSRuslan ErmilovSend as many packets as required out the
2564f068961SRuslan Ermilov.Va output
25776648c1fSRuslan Ermilovhook:
258585ff168SJulian Elischer.Pp
25976648c1fSRuslan Ermilov.Dl "ngctl msg bge0:orphans start 16"
26076648c1fSRuslan Ermilov.Pp
26176648c1fSRuslan ErmilovEither wait for them to be sent (periodically fetching stats if desired)
262585ff168SJulian Elischeror send the stop message:
263585ff168SJulian Elischer.Pp
26476648c1fSRuslan Ermilov.Dl "ngctl msg bge0:orphans stop"
26576648c1fSRuslan Ermilov.Pp
26676648c1fSRuslan ErmilovCheck the statistics (here we use
26776648c1fSRuslan Ermilov.Ic getclrstats
26876648c1fSRuslan Ermilovto also clear the statistics):
26976648c1fSRuslan Ermilov.Bd -literal -offset indent
27076648c1fSRuslan Ermilovngctl msg bge0:orphans getclrstats
271585ff168SJulian ElischerArgs:   { outOctets=1024 outFrames=16 queueOctets=64 queueFrames=1
272585ff168SJulian ElischerstartTime={ tv_sec=1035305880 tv_usec=758036 } endTime={ tv_sec=1035305880
273585ff168SJulian Elischertv_usec=759041 } elapsedTime={ tv_usec=1005 } }
274585ff168SJulian Elischer.Ed
275585ff168SJulian Elischer.Pp
27676648c1fSRuslan ErmilovThe times are from
27776648c1fSRuslan Ermilov.Vt "struct timeval" Ns s ,
27876648c1fSRuslan Ermilovthe
27976648c1fSRuslan Ermilov.Va tv_sec
28076648c1fSRuslan Ermilovfield is seconds since
28176648c1fSRuslan Ermilovthe Epoch and can be converted into a date string via TCL's [clock
28276648c1fSRuslan Ermilovformat] or via the
28376648c1fSRuslan Ermilov.Xr date 1
28476648c1fSRuslan Ermilovcommand:
28576648c1fSRuslan Ermilov.Bd -literal -offset indent
28676648c1fSRuslan Ermilovdate -r 1035305880
287585ff168SJulian ElischerTue Oct 22 12:58:00 EDT 2002
288585ff168SJulian Elischer.Ed
289585ff168SJulian Elischer.Sh SEE ALSO
290585ff168SJulian Elischer.Xr netgraph 4 ,
291585ff168SJulian Elischer.Xr ng_echo 4 ,
292585ff168SJulian Elischer.Xr ng_hole 4 ,
293585ff168SJulian Elischer.Xr ng_tee 4 ,
29476648c1fSRuslan Ermilov.Xr ngctl 8 ,
295585ff168SJulian Elischer.Xr nghook 8
296585ff168SJulian Elischer.Sh HISTORY
297585ff168SJulian ElischerThe
298585ff168SJulian Elischer.Nm
299585ff168SJulian Elischernode type was implemented in
300585ff168SJulian Elischer.Fx 4.8 .
301585ff168SJulian Elischer.Sh AUTHORS
302585ff168SJulian Elischer.An Dave Chapeskie Aq dchapeskie@SANDVINE.com
303