xref: /freebsd/share/man/man4/ng_source.4 (revision fbad9e2d95b59d1c0403f04df62d6d7cb4ea7c4a)
1585ff168SJulian Elischer.\" Copyright 2002 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.\"
35585ff168SJulian Elischer.Dd November 1, 2002
36585ff168SJulian Elischer.Dt NG_SOURCE 4
37585ff168SJulian Elischer.Os
38585ff168SJulian Elischer.Sh NAME
39585ff168SJulian Elischer.Nm ng_source
40585ff168SJulian Elischer.Nd netgraph discard node type
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
5076648c1fSRuslan Ermilov.Dv output
5176648c1fSRuslan Ermilovhook must also be connected to a node that responds to the
5276648c1fSRuslan Ermilov.Dv NGM_ETHER_COOKIE Ns / Ns
5376648c1fSRuslan Ermilov.Dv NGM_ETHER_GET_IFINDEX
5476648c1fSRuslan Ermilovmessage (e.g., an
5576648c1fSRuslan Ermilov.Xr ng_ether 4
56585ff168SJulian Elischernode).
57585ff168SJulian ElischerThis type is used for testing and debugging.
58585ff168SJulian Elischer.Pp
59585ff168SJulian ElischerThe operation of the node is as follows:
6076648c1fSRuslan Ermilov.Bl -bullet
61585ff168SJulian Elischer.It
6276648c1fSRuslan ErmilovPackets received on the
6376648c1fSRuslan Ermilov.Dv input
6476648c1fSRuslan Ermilovhook are queued internally.
65585ff168SJulian Elischer.It
6676648c1fSRuslan ErmilovOn reception of a
6776648c1fSRuslan Ermilov.Dv NGM_SOURCE_START
6876648c1fSRuslan Ermilovmessage the node starts sending
6976648c1fSRuslan Ermilovthe queued packets out the
7076648c1fSRuslan Ermilov.Dv output
7176648c1fSRuslan Ermilovhook on every clock tick as fast
72585ff168SJulian Elischeras the connect interface will take them.
73585ff168SJulian Elischer.It
74585ff168SJulian ElischerWhile active, on every clock tick the node checks the available space
7576648c1fSRuslan Ermilovin the
7676648c1fSRuslan Ermilov.Va ifqueue
7776648c1fSRuslan Ermilovof the interface connected to the output hook and sends
7876648c1fSRuslan Ermilovthat many packets out its
7976648c1fSRuslan Ermilov.Dv output
8076648c1fSRuslan Ermilovhook.
81585ff168SJulian Elischer.It
82585ff168SJulian ElischerOnce the number of packets indicated in the start message have been
83585ff168SJulian Elischersent, or on reception of a stop message, the node stops sending data.
84585ff168SJulian Elischer.El
85585ff168SJulian Elischer.Sh HOOKS
86585ff168SJulian ElischerThe
87585ff168SJulian Elischer.Nm source
8876648c1fSRuslan Ermilovnode has two hooks:
8976648c1fSRuslan Ermilov.Dv input
9076648c1fSRuslan Ermilovand
9176648c1fSRuslan Ermilov.Dv output .
9276648c1fSRuslan ErmilovThe
9376648c1fSRuslan Ermilov.Dv output
94585ff168SJulian Elischerhook must remain connected, its disconnection will shutdown the node.
95585ff168SJulian Elischer.Sh CONTROL MESSAGES
96585ff168SJulian ElischerThis node type supports the generic control messages as well as the following,
97585ff168SJulian Elischerwhich must be sent with the
9876648c1fSRuslan Ermilov.Dv NGM_SOURCE_COOKIE
99585ff168SJulian Elischerattached.
10076648c1fSRuslan Ermilov.Bl -tag -width indent
10176648c1fSRuslan Ermilov.It Dv NGM_SOURCE_GET_STATS Pq Ic getstats
102585ff168SJulian ElischerReturns a structure containing the following fields:
10376648c1fSRuslan Ermilov.Bl -tag -width indent
10476648c1fSRuslan Ermilov.It Va outOctets
10576648c1fSRuslan ErmilovThe number of octets/bytes sent out the
10676648c1fSRuslan Ermilov.Dv output
10776648c1fSRuslan Ermilovhook.
10876648c1fSRuslan Ermilov.It Va outFrames
10976648c1fSRuslan ErmilovThe number of frames/packets sent out the
11076648c1fSRuslan Ermilov.Dv output
11176648c1fSRuslan Ermilovhook.
11276648c1fSRuslan Ermilov.It Va queueOctets
11376648c1fSRuslan ErmilovThe number of octets queued from the
11476648c1fSRuslan Ermilov.Dv input
11576648c1fSRuslan Ermilovhook.
11676648c1fSRuslan Ermilov.It Va queueFrames
11776648c1fSRuslan ErmilovThe number of frames queued from the
11876648c1fSRuslan Ermilov.Dv input
11976648c1fSRuslan Ermilovhook.
12076648c1fSRuslan Ermilov.It Va startTime
12176648c1fSRuslan ErmilovThe time the last start message was received.
12276648c1fSRuslan Ermilov.It Va endTime
12376648c1fSRuslan ErmilovThe time the last end message was received or
124585ff168SJulian Elischerthe output packet count was reached.
12576648c1fSRuslan Ermilov.It Va elapsedTime
12676648c1fSRuslan ErmilovEither
12776648c1fSRuslan Ermilov.Va endTime Li \- Va startTime
12876648c1fSRuslan Ermilovor current time
12976648c1fSRuslan Ermilov\-
13076648c1fSRuslan Ermilov.Va startTime .
131585ff168SJulian Elischer.El
13276648c1fSRuslan Ermilov.It Dv NGM_SOURCE_CLR_STATS Pq Ic clrstats
13376648c1fSRuslan ErmilovClears and resets the statistics returned by
13476648c1fSRuslan Ermilov.Ic getstats
13576648c1fSRuslan Ermilov(except
13676648c1fSRuslan Ermilov.Va queueOctets
13776648c1fSRuslan Ermilovand
13876648c1fSRuslan Ermilov.Va queueFrames ) .
13976648c1fSRuslan Ermilov.It Dv NGM_SOURCE_GETCLR_STATS Pq Ic getclrstats
14076648c1fSRuslan ErmilovAs
14176648c1fSRuslan Ermilov.Ic getstats
14276648c1fSRuslan Ermilovbut clears the statistics at the same time.
14376648c1fSRuslan Ermilov.It Dv NGM_SOURCE_START Pq Ic start
14476648c1fSRuslan Ermilov.Bl -bullet
145585ff168SJulian Elischer.It
14676648c1fSRuslan ErmilovTakes a single
14776648c1fSRuslan Ermilov.Vt u_int64_t
14876648c1fSRuslan Ermilovparameter which is the number of packets to
149585ff168SJulian Elischersend before stopping.
150585ff168SJulian Elischer.It
151585ff168SJulian ElischerStarts sending the queued packets out the output hook.
152585ff168SJulian Elischer.It
15376648c1fSRuslan ErmilovThe output hook must be connected or
15476648c1fSRuslan Ermilov.Er EINVAL
15576648c1fSRuslan Ermilovis returned.
156585ff168SJulian Elischer.It
157585ff168SJulian ElischerThe node connected to the output hook must respond to
15876648c1fSRuslan Ermilov.Dv NGM_ETHER_GET_IFINDEX
15976648c1fSRuslan Ermilovwhich is used to get the
16076648c1fSRuslan Ermilov.Va ifqueue
16176648c1fSRuslan Ermilovof the attached interface.
162585ff168SJulian Elischer.It
16376648c1fSRuslan Ermilov.Dv NGM_ETHER_SET_AUTOSRC
16476648c1fSRuslan Ermilovis sent to the node connected to the
16576648c1fSRuslan Ermilov.Dv output
16676648c1fSRuslan Ermilovhook
167c5f116aaSChristian Bruefferto turn off automatic Ethernet source address overwriting (any errors
168585ff168SJulian Elischerfrom this message are ignored).
169585ff168SJulian Elischer.El
17076648c1fSRuslan Ermilov.It Dv NGM_SOURCE_STOP Pq Ic stop
171585ff168SJulian ElischerStops the node if it is active.
17276648c1fSRuslan Ermilov.It Dv NGM_SOURCE_CLR_DATA Pq Ic clrdata
17376648c1fSRuslan ErmilovClears the packets queued from the
17476648c1fSRuslan Ermilov.Dv input
17576648c1fSRuslan Ermilovhook.
176585ff168SJulian Elischer.El
177585ff168SJulian Elischer.Sh SHUTDOWN
178585ff168SJulian ElischerThis node shuts down upon receipt of a
179585ff168SJulian Elischer.Dv NGM_SHUTDOWN
180585ff168SJulian Elischercontrol message, or when the
18176648c1fSRuslan Ermilov.Dv output
182585ff168SJulian Elischerhook has been disconnected.
1839cbda590SRuslan Ermilov.Sh IMPLEMENTATION NOTES
1849cbda590SRuslan Ermilov.No ( Fx 4.4
1859cbda590SRuslan Ermilovversion)
1869cbda590SRuslan Ermilov.Pp
1879cbda590SRuslan ErmilovThe use of
1889cbda590SRuslan Ermilov.Xr splimp 9
1899cbda590SRuslan Ermilovaround the
1909cbda590SRuslan Ermilov.Dv NG_SEND_DATA
1919cbda590SRuslan Ermilovloop is important.
1929cbda590SRuslan ErmilovWithout it,
1939cbda590SRuslan Ermilovthe time taken by a single invocation of
1949cbda590SRuslan Ermilov.Fn ng_source_intr
1959cbda590SRuslan Ermilovbecomes too
1969cbda590SRuslan Ermilovlarge and the packet rate drops.
1979cbda590SRuslan ErmilovProbably due to the NIC starting to
1989cbda590SRuslan Ermilovsend the packets right away.
1999cbda590SRuslan Ermilov.Pp
2009cbda590SRuslan ErmilovCopying all the packets in one loop and sending them in another inside
2019cbda590SRuslan Ermilovof
2029cbda590SRuslan Ermilov.Fn ng_source_send
2039cbda590SRuslan Ermilovis done to limit how long we are at
2049cbda590SRuslan Ermilov.Xr splimp 9
2059cbda590SRuslan Ermilovand gave
2069cbda590SRuslan Ermilovminor packet rate increases (~5% at 256 byte packets).
2079cbda590SRuslan ErmilovHowever note
2089cbda590SRuslan Ermilovthat if there are errors in the send loop, the remaining copied packets
2099cbda590SRuslan Ermilovare simply freed and discarded; thus we skip those packets, and ordering
2109cbda590SRuslan Ermilovof the input queue to the output is not maintained.
2119cbda590SRuslan Ermilov.Pp
2129cbda590SRuslan ErmilovCalling
2139cbda590SRuslan Ermilov.Xr timeout 9
2149cbda590SRuslan Ermilovat the end of
2159cbda590SRuslan Ermilov.Fn ng_source_intr
2169cbda590SRuslan Ermilovinstead of near the
2179cbda590SRuslan Ermilovbeginning is done to help avoid CPU starvation if
2189cbda590SRuslan Ermilov.Fn ng_source_intr
2199cbda590SRuslan Ermilovtakes a long time to run.
2209cbda590SRuslan Ermilov.Pp
2219cbda590SRuslan ErmilovThe use of
2229cbda590SRuslan Ermilov.Xr splnet 9
2239cbda590SRuslan Ermilovmay be sub-optimal.
2249cbda590SRuslan ErmilovIt is used for synchronization
2259cbda590SRuslan Ermilovwithin the node (e.g., data received on the
2269cbda590SRuslan Ermilov.Dv input
2279cbda590SRuslan Ermilovhook while
2289cbda590SRuslan Ermilov.Fn ng_source_send
2299cbda590SRuslan Ermilovis active) but we do not want to hold it too long and risk
2309cbda590SRuslan Ermilovstarving the NIC.
2319cbda590SRuslan Ermilov.Pp
2329cbda590SRuslan ErmilovFor clarity and simplicity, debugging messages and instrumentation code
2339cbda590SRuslan Ermilovhas been removed.
2349cbda590SRuslan ErmilovOn i386 one can include
2359cbda590SRuslan Ermilov.In machine/cpufunc.h
2369cbda590SRuslan Ermilovto have access to the
2379cbda590SRuslan Ermilov.Fn rdtsc
2389cbda590SRuslan Ermilovfunction to read the instruction counter at the
2399cbda590SRuslan Ermilovstart and end of
2409cbda590SRuslan Ermilov.Fn ng_source_intr .
2419cbda590SRuslan ErmilovAlso useful is the packet count returned by
2429cbda590SRuslan Ermilov.Fn ng_source_send .
2439cbda590SRuslan ErmilovDo not try to report such things from within
2449cbda590SRuslan Ermilov.Fn ng_source_intr ,
2459cbda590SRuslan Ermilovinstead include the values in
2469cbda590SRuslan Ermilov.Va sc->stats .
24776648c1fSRuslan Ermilov.Sh EXAMPLES
24876648c1fSRuslan ErmilovAttach the node to an
24976648c1fSRuslan Ermilov.Xr ng_ether 4
25076648c1fSRuslan Ermilovnode for an interface.
25176648c1fSRuslan ErmilovIf
25276648c1fSRuslan Ermilov.Nm ng_ether
25376648c1fSRuslan Ermilovis
25476648c1fSRuslan Ermilovnot already loaded you will need to do so.
25576648c1fSRuslan ErmilovFor example, these commands
25676648c1fSRuslan Ermilovload the
25776648c1fSRuslan Ermilov.Nm ng_ether
25876648c1fSRuslan Ermilovmodule and attach the
25976648c1fSRuslan Ermilov.Dv output
26076648c1fSRuslan Ermilovhook of a new
26176648c1fSRuslan Ermilov.Nm source
26276648c1fSRuslan Ermilovnode to
26376648c1fSRuslan Ermilov.Dv orphans
26476648c1fSRuslan Ermilovhook of the
26576648c1fSRuslan Ermilov.Li bge0:
26676648c1fSRuslan Ermilov.Nm ng_ether
26776648c1fSRuslan Ermilovnode.
26876648c1fSRuslan Ermilov.Bd -literal -offset indent
26976648c1fSRuslan Ermilovkldload ng_ether
27076648c1fSRuslan Ermilovngctl mkpeer bge0: source orphans output
271585ff168SJulian Elischer.Ed
272585ff168SJulian Elischer.Pp
27376648c1fSRuslan ErmilovAt this point the new node can be referred to as
27476648c1fSRuslan Ermilov.Dq Li bge0:orphans .
27576648c1fSRuslan ErmilovThe
27676648c1fSRuslan Ermilovnode can be given its own name like this:
277585ff168SJulian Elischer.Pp
27876648c1fSRuslan Ermilov.Dl "ngctl name bge0:orphans src0"
279585ff168SJulian Elischer.Pp
28076648c1fSRuslan ErmilovAfter which it can be referred to as
28176648c1fSRuslan Ermilov.Dq Li src0: .
282585ff168SJulian Elischer.Pp
28376648c1fSRuslan ErmilovOnce created, packets need to be sent to the node, the TCL net package
284585ff168SJulian Elischercan be used to generate these packets:
285585ff168SJulian Elischer.Pp
286585ff168SJulian Elischer[Sandvine specific TCL code example omitted]
287585ff168SJulian Elischer.Pp
28876648c1fSRuslan ErmilovTo feed the output of the above TCL script to the
28976648c1fSRuslan Ermilov.Nm source
29076648c1fSRuslan Ermilovnode's
29176648c1fSRuslan Ermilov.Dv input
29276648c1fSRuslan Ermilovhook via
29376648c1fSRuslan Ermilov.Xr nghook 8 :
29476648c1fSRuslan Ermilov.Pp
29576648c1fSRuslan Ermilov.Dl "tcl genPacket | nghook bge0:orphans input"
296585ff168SJulian Elischer.Pp
297585ff168SJulian ElischerTo check that the node has queued these packets you can get the node
298585ff168SJulian Elischerstatistics:
29976648c1fSRuslan Ermilov.Bd -literal -offset indent
30076648c1fSRuslan Ermilovngctl msg bge0:orphans getstats
301585ff168SJulian ElischerArgs:   { queueOctets=64 queueFrames=1 }
302585ff168SJulian Elischer.Ed
303585ff168SJulian Elischer.Pp
30476648c1fSRuslan ErmilovSend as many packets as required out the
30576648c1fSRuslan Ermilov.Dv output
30676648c1fSRuslan Ermilovhook:
307585ff168SJulian Elischer.Pp
30876648c1fSRuslan Ermilov.Dl "ngctl msg bge0:orphans start 16"
30976648c1fSRuslan Ermilov.Pp
31076648c1fSRuslan ErmilovEither wait for them to be sent (periodically fetching stats if desired)
311585ff168SJulian Elischeror send the stop message:
312585ff168SJulian Elischer.Pp
31376648c1fSRuslan Ermilov.Dl "ngctl msg bge0:orphans stop"
31476648c1fSRuslan Ermilov.Pp
31576648c1fSRuslan ErmilovCheck the statistics (here we use
31676648c1fSRuslan Ermilov.Ic getclrstats
31776648c1fSRuslan Ermilovto also clear the statistics):
31876648c1fSRuslan Ermilov.Bd -literal -offset indent
31976648c1fSRuslan Ermilovngctl msg bge0:orphans getclrstats
320585ff168SJulian ElischerArgs:   { outOctets=1024 outFrames=16 queueOctets=64 queueFrames=1
321585ff168SJulian ElischerstartTime={ tv_sec=1035305880 tv_usec=758036 } endTime={ tv_sec=1035305880
322585ff168SJulian Elischertv_usec=759041 } elapsedTime={ tv_usec=1005 } }
323585ff168SJulian Elischer.Ed
324585ff168SJulian Elischer.Pp
32576648c1fSRuslan ErmilovThe times are from
32676648c1fSRuslan Ermilov.Vt "struct timeval" Ns s ,
32776648c1fSRuslan Ermilovthe
32876648c1fSRuslan Ermilov.Va tv_sec
32976648c1fSRuslan Ermilovfield is seconds since
33076648c1fSRuslan Ermilovthe Epoch and can be converted into a date string via TCL's [clock
33176648c1fSRuslan Ermilovformat] or via the
33276648c1fSRuslan Ermilov.Xr date 1
33376648c1fSRuslan Ermilovcommand:
33476648c1fSRuslan Ermilov.Bd -literal -offset indent
33576648c1fSRuslan Ermilovdate -r 1035305880
336585ff168SJulian ElischerTue Oct 22 12:58:00 EDT 2002
337585ff168SJulian Elischer.Ed
338585ff168SJulian Elischer.Sh SEE ALSO
339585ff168SJulian Elischer.Xr netgraph 4 ,
340585ff168SJulian Elischer.Xr ng_echo 4 ,
341585ff168SJulian Elischer.Xr ng_hole 4 ,
342585ff168SJulian Elischer.Xr ng_tee 4 ,
34376648c1fSRuslan Ermilov.Xr ngctl 8 ,
344585ff168SJulian Elischer.Xr nghook 8
345585ff168SJulian Elischer.Sh HISTORY
346585ff168SJulian ElischerThe
347585ff168SJulian Elischer.Nm
348585ff168SJulian Elischernode type was implemented in
349585ff168SJulian Elischer.Fx 4.8 .
350585ff168SJulian Elischer.Sh AUTHORS
351585ff168SJulian Elischer.An Dave Chapeskie Aq dchapeskie@SANDVINE.com
352