155c60b64SEd Maste.\" Copyright 2002-2007 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.\" 3255c60b64SEd Maste.\" Author: Dave Chapeskie 33585ff168SJulian Elischer.\" $FreeBSD$ 34585ff168SJulian Elischer.\" 35*75e7ef74SLutz Donnerhacke.Dd January 18, 2021 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 94*75e7ef74SLutz DonnerhackeIf the node is connected to a netgraph network, which does not 95*75e7ef74SLutz Donnerhacketerminate in a real 96*75e7ef74SLutz Donnerhacke.Xr ng_ether 4 97*75e7ef74SLutz Donnerhackeinterface, limit the packet injection rate explicitly with the 98*75e7ef74SLutz Donnerhacke.Va NGM_SOURCE_SETPPS 99*75e7ef74SLutz Donnerhackecontrol message. 100*75e7ef74SLutz Donnerhacke.Pp 101*75e7ef74SLutz DonnerhackeUpon receipt of a 10237684cf3SGleb Smirnoff.Dv NGM_SOURCE_START 10337684cf3SGleb Smirnoffcontrol message the node starts sending 10437684cf3SGleb Smirnoffthe previously queued packets out the 10537684cf3SGleb Smirnoff.Va output 10637684cf3SGleb Smirnoffhook on every clock tick as fast 10737684cf3SGleb Smirnoffas the connected interface will take them. 10837684cf3SGleb SmirnoffWhile active, on every clock tick the node checks the available space 10937684cf3SGleb Smirnoffin the interface queue and sends that many packets out its 11037684cf3SGleb Smirnoff.Va output 11137684cf3SGleb Smirnoffhook. 1124f068961SRuslan ErmilovOnce the number of packets indicated in the start message has been 1134f068961SRuslan Ermilovsent, or upon receipt of a 1144f068961SRuslan Ermilov.Dv NGM_SOURCE_STOP 1154f068961SRuslan Ermilovmessage, the node stops sending data. 116585ff168SJulian Elischer.Sh CONTROL MESSAGES 117585ff168SJulian ElischerThis node type supports the generic control messages as well as the following, 118585ff168SJulian Elischerwhich must be sent with the 11976648c1fSRuslan Ermilov.Dv NGM_SOURCE_COOKIE 120585ff168SJulian Elischerattached. 121c60bda17SJoel Dahl.Bl -tag -width foo 12276648c1fSRuslan Ermilov.It Dv NGM_SOURCE_GET_STATS Pq Ic getstats 123585ff168SJulian ElischerReturns a structure containing the following fields: 124c60bda17SJoel Dahl.Bl -tag -width ".Va elapsedTime" 12576648c1fSRuslan Ermilov.It Va outOctets 12676648c1fSRuslan ErmilovThe number of octets/bytes sent out the 1274f068961SRuslan Ermilov.Va output 12876648c1fSRuslan Ermilovhook. 12976648c1fSRuslan Ermilov.It Va outFrames 13076648c1fSRuslan ErmilovThe number of frames/packets sent out the 1314f068961SRuslan Ermilov.Va output 13276648c1fSRuslan Ermilovhook. 13376648c1fSRuslan Ermilov.It Va queueOctets 13476648c1fSRuslan ErmilovThe number of octets queued from the 1354f068961SRuslan Ermilov.Va input 13676648c1fSRuslan Ermilovhook. 13776648c1fSRuslan Ermilov.It Va queueFrames 13876648c1fSRuslan ErmilovThe number of frames queued from the 1394f068961SRuslan Ermilov.Va input 14076648c1fSRuslan Ermilovhook. 14176648c1fSRuslan Ermilov.It Va startTime 14276648c1fSRuslan ErmilovThe time the last start message was received. 14376648c1fSRuslan Ermilov.It Va endTime 14476648c1fSRuslan ErmilovThe time the last end message was received or 145585ff168SJulian Elischerthe output packet count was reached. 14676648c1fSRuslan Ermilov.It Va elapsedTime 14776648c1fSRuslan ErmilovEither 14876648c1fSRuslan Ermilov.Va endTime Li \- Va startTime 14976648c1fSRuslan Ermilovor current time 15076648c1fSRuslan Ermilov\- 15176648c1fSRuslan Ermilov.Va startTime . 152585ff168SJulian Elischer.El 15376648c1fSRuslan Ermilov.It Dv NGM_SOURCE_CLR_STATS Pq Ic clrstats 15476648c1fSRuslan ErmilovClears and resets the statistics returned by 15576648c1fSRuslan Ermilov.Ic getstats 15676648c1fSRuslan Ermilov(except 15776648c1fSRuslan Ermilov.Va queueOctets 15876648c1fSRuslan Ermilovand 15976648c1fSRuslan Ermilov.Va queueFrames ) . 16076648c1fSRuslan Ermilov.It Dv NGM_SOURCE_GETCLR_STATS Pq Ic getclrstats 16176648c1fSRuslan ErmilovAs 16276648c1fSRuslan Ermilov.Ic getstats 16376648c1fSRuslan Ermilovbut clears the statistics at the same time. 16476648c1fSRuslan Ermilov.It Dv NGM_SOURCE_START Pq Ic start 16537684cf3SGleb SmirnoffThis message requires a single 16637684cf3SGleb Smirnoff.Vt uint64_t 16776648c1fSRuslan Ermilovparameter which is the number of packets to 168585ff168SJulian Elischersend before stopping. 1694f068961SRuslan ErmilovNode starts sending the queued packets out the 1704f068961SRuslan Ermilov.Va output 1714f068961SRuslan Ermilovhook. 1724f068961SRuslan ErmilovThe 1734f068961SRuslan Ermilov.Va output 1744f068961SRuslan Ermilovhook must be connected and node must have 17537684cf3SGleb Smirnoffinterface configured. 17676648c1fSRuslan Ermilov.It Dv NGM_SOURCE_STOP Pq Ic stop 177585ff168SJulian ElischerStops the node if it is active. 17876648c1fSRuslan Ermilov.It Dv NGM_SOURCE_CLR_DATA Pq Ic clrdata 17976648c1fSRuslan ErmilovClears the packets queued from the 1804f068961SRuslan Ermilov.Va input 18176648c1fSRuslan Ermilovhook. 18237684cf3SGleb Smirnoff.It Dv NGM_SOURCE_SETIFACE Pq Ic setiface 1834f068961SRuslan ErmilovThis message requires the name of the interface 1844f068961SRuslan Ermilovto be configured as an argument. 18572235857SGleb Smirnoff.It Dv NGM_SOURCE_SETPPS Pq Ic setpps 18672235857SGleb SmirnoffThis message requires a single 18772235857SGleb Smirnoff.Vt uint32_t 18872235857SGleb Smirnoffparameter which puts upper limit on the amount of packets 18972235857SGleb Smirnoffsent per second. 19055c60b64SEd Maste.It Dv NGM_SOURCE_SET_TIMESTAMP Pq Ic settimestamp 19155c60b64SEd MasteThis message specifies that a timestamp (in the format of a 192dcc76067SEd Maste.Vt "struct timeval" ) 19355c60b64SEd Masteshould be inserted in the transmitted packets. 19455c60b64SEd MasteThis message requires a structure containing the following fields: 195c60bda17SJoel Dahl.Bl -tag -width ".Va offset" 19655c60b64SEd Maste.It Va offset 19755c60b64SEd MasteThe offset from the beginning of the packet at which the timestamp is to be 19855c60b64SEd Masteinserted. 19955c60b64SEd Maste.It Va flags 20055c60b64SEd MasteSet to 1 to enable the timestamp. 20155c60b64SEd Maste.El 20255c60b64SEd Maste.It Dv NGM_SOURCE_GET_TIMESTAMP Pq Ic gettimestamp 20355c60b64SEd MasteReturns the current timestamp settings in the form of the structure described 20455c60b64SEd Masteabove. 20555c60b64SEd Maste.It Dv NGM_SOURCE_SET_COUNTER Pq Ic setcounter 20655c60b64SEd MasteThis message specifies that a counter should be embedded in transmitted 20755c60b64SEd Mastepackets. 20855c60b64SEd MasteUp to four counters may be independently configured. 20955c60b64SEd MasteThis message requires a structure containing the following fields: 210c60bda17SJoel Dahl.Bl -tag -width ".Va increment" 21155c60b64SEd Maste.It Va offset 21255c60b64SEd MasteThe offset from the beginning of the packet at which the counter is to be 21355c60b64SEd Masteinserted. 21455c60b64SEd Maste.It Va flags 21555c60b64SEd MasteSet to 1 to enable the counter. 21655c60b64SEd Maste.It Va width 217dcc76067SEd MasteThe byte width of the counter. 218dcc76067SEd MasteIt may be 1, 2, or 4. 21955c60b64SEd Maste.It Va next_val 22055c60b64SEd MasteThe value for the next insertion of the counter. 22155c60b64SEd Maste.It Va min_val 22255c60b64SEd MasteThe minimum value to be used by the counter. 22355c60b64SEd Maste.It Va max_val 22455c60b64SEd MasteThe maximum value to be used by the counter. 22555c60b64SEd Maste.It Va increment 22655c60b64SEd MasteThe value to be added to the counter after each insertion. 22755c60b64SEd MasteIt may be negative. 22855c60b64SEd Maste.It Va index 22955c60b64SEd MasteThe counter to be configured, from 0 to 3. 23055c60b64SEd Maste.El 23155c60b64SEd Maste.It Dv NGM_SOURCE_GET_COUNTER Pq Ic getcounter 23255c60b64SEd MasteThis message requires a single 23355c60b64SEd Maste.Vt uint8_t 23455c60b64SEd Masteparameter which specifies the counter to query. 23555c60b64SEd MasteReturns the current counter settings in the form of the structure described 23655c60b64SEd Masteabove. 237585ff168SJulian Elischer.El 238585ff168SJulian Elischer.Sh SHUTDOWN 239585ff168SJulian ElischerThis node shuts down upon receipt of a 240585ff168SJulian Elischer.Dv NGM_SHUTDOWN 2414f068961SRuslan Ermilovcontrol message, when all hooks have been disconnected, or when the 24237684cf3SGleb Smirnoff.Va output 243585ff168SJulian Elischerhook has been disconnected. 24476648c1fSRuslan Ermilov.Sh EXAMPLES 24576648c1fSRuslan ErmilovAttach the node to an 24676648c1fSRuslan Ermilov.Xr ng_ether 4 24776648c1fSRuslan Ermilovnode for an interface. 24876648c1fSRuslan ErmilovIf 24976648c1fSRuslan Ermilov.Nm ng_ether 25076648c1fSRuslan Ermilovis 25176648c1fSRuslan Ermilovnot already loaded you will need to do so. 25276648c1fSRuslan ErmilovFor example, these commands 25376648c1fSRuslan Ermilovload the 25476648c1fSRuslan Ermilov.Nm ng_ether 25576648c1fSRuslan Ermilovmodule and attach the 2564f068961SRuslan Ermilov.Va output 25776648c1fSRuslan Ermilovhook of a new 25876648c1fSRuslan Ermilov.Nm source 25976648c1fSRuslan Ermilovnode to 2604f068961SRuslan Ermilov.Va orphans 26176648c1fSRuslan Ermilovhook of the 26276648c1fSRuslan Ermilov.Li bge0: 26376648c1fSRuslan Ermilov.Nm ng_ether 26476648c1fSRuslan Ermilovnode. 26576648c1fSRuslan Ermilov.Bd -literal -offset indent 26676648c1fSRuslan Ermilovkldload ng_ether 26776648c1fSRuslan Ermilovngctl mkpeer bge0: source orphans output 268585ff168SJulian Elischer.Ed 269585ff168SJulian Elischer.Pp 27076648c1fSRuslan ErmilovAt this point the new node can be referred to as 27176648c1fSRuslan Ermilov.Dq Li bge0:orphans . 27276648c1fSRuslan ErmilovThe 27376648c1fSRuslan Ermilovnode can be given its own name like this: 274585ff168SJulian Elischer.Pp 27576648c1fSRuslan Ermilov.Dl "ngctl name bge0:orphans src0" 276585ff168SJulian Elischer.Pp 27776648c1fSRuslan ErmilovAfter which it can be referred to as 27876648c1fSRuslan Ermilov.Dq Li src0: . 279585ff168SJulian Elischer.Pp 28058b1cfdeSEd MasteOnce created, packets can be sent to the node as raw binary data. 28158b1cfdeSEd MasteEach packet must be delivered in a separate netgraph message. 282585ff168SJulian Elischer.Pp 28358b1cfdeSEd MasteThe following example uses a short Perl script to convert the hex 28458b1cfdeSEd Masterepresentation of an ICMP packet to binary and deliver it to the 28576648c1fSRuslan Ermilov.Nm source 28676648c1fSRuslan Ermilovnode's 2874f068961SRuslan Ermilov.Va input 28876648c1fSRuslan Ermilovhook via 28976648c1fSRuslan Ermilov.Xr nghook 8 : 29058b1cfdeSEd Maste.Bd -literal -offset indent 29158b1cfdeSEd Masteperl -pe 's/(..)[ \et\en]*/chr(hex($1))/ge' <<EOF | nghook src0: input 29258b1cfdeSEd Masteff ff ff ff ff ff 00 00 00 00 00 00 08 00 45 00 29358b1cfdeSEd Maste00 54 cb 13 00 00 40 01 b9 87 c0 a8 2b 65 0a 00 29458b1cfdeSEd Maste00 01 08 00 f8 d0 c9 76 00 00 45 37 01 73 00 01 29558b1cfdeSEd Maste04 0a 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 29658b1cfdeSEd Maste16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 29758b1cfdeSEd Maste26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 29858b1cfdeSEd Maste36 37 29958b1cfdeSEd MasteEOF 30058b1cfdeSEd Maste.Ed 301585ff168SJulian Elischer.Pp 302585ff168SJulian ElischerTo check that the node has queued these packets you can get the node 303585ff168SJulian Elischerstatistics: 30476648c1fSRuslan Ermilov.Bd -literal -offset indent 30576648c1fSRuslan Ermilovngctl msg bge0:orphans getstats 306585ff168SJulian ElischerArgs: { queueOctets=64 queueFrames=1 } 307585ff168SJulian Elischer.Ed 308585ff168SJulian Elischer.Pp 30976648c1fSRuslan ErmilovSend as many packets as required out the 3104f068961SRuslan Ermilov.Va output 31176648c1fSRuslan Ermilovhook: 312585ff168SJulian Elischer.Pp 31376648c1fSRuslan Ermilov.Dl "ngctl msg bge0:orphans start 16" 31476648c1fSRuslan Ermilov.Pp 31576648c1fSRuslan ErmilovEither wait for them to be sent (periodically fetching stats if desired) 316585ff168SJulian Elischeror send the stop message: 317585ff168SJulian Elischer.Pp 31876648c1fSRuslan Ermilov.Dl "ngctl msg bge0:orphans stop" 31976648c1fSRuslan Ermilov.Pp 32076648c1fSRuslan ErmilovCheck the statistics (here we use 32176648c1fSRuslan Ermilov.Ic getclrstats 32276648c1fSRuslan Ermilovto also clear the statistics): 32376648c1fSRuslan Ermilov.Bd -literal -offset indent 32476648c1fSRuslan Ermilovngctl msg bge0:orphans getclrstats 325585ff168SJulian ElischerArgs: { outOctets=1024 outFrames=16 queueOctets=64 queueFrames=1 326585ff168SJulian ElischerstartTime={ tv_sec=1035305880 tv_usec=758036 } endTime={ tv_sec=1035305880 327585ff168SJulian Elischertv_usec=759041 } elapsedTime={ tv_usec=1005 } } 328585ff168SJulian Elischer.Ed 329585ff168SJulian Elischer.Pp 33076648c1fSRuslan ErmilovThe times are from 33176648c1fSRuslan Ermilov.Vt "struct timeval" Ns s , 33276648c1fSRuslan Ermilovthe 33376648c1fSRuslan Ermilov.Va tv_sec 33476648c1fSRuslan Ermilovfield is seconds since 33576648c1fSRuslan Ermilovthe Epoch and can be converted into a date string via TCL's [clock 33676648c1fSRuslan Ermilovformat] or via the 33776648c1fSRuslan Ermilov.Xr date 1 33876648c1fSRuslan Ermilovcommand: 33976648c1fSRuslan Ermilov.Bd -literal -offset indent 34076648c1fSRuslan Ermilovdate -r 1035305880 341585ff168SJulian ElischerTue Oct 22 12:58:00 EDT 2002 342585ff168SJulian Elischer.Ed 343585ff168SJulian Elischer.Sh SEE ALSO 344585ff168SJulian Elischer.Xr netgraph 4 , 345585ff168SJulian Elischer.Xr ng_echo 4 , 346585ff168SJulian Elischer.Xr ng_hole 4 , 347585ff168SJulian Elischer.Xr ng_tee 4 , 34876648c1fSRuslan Ermilov.Xr ngctl 8 , 349585ff168SJulian Elischer.Xr nghook 8 350585ff168SJulian Elischer.Sh HISTORY 351585ff168SJulian ElischerThe 352585ff168SJulian Elischer.Nm 353585ff168SJulian Elischernode type was implemented in 354585ff168SJulian Elischer.Fx 4.8 . 355585ff168SJulian Elischer.Sh AUTHORS 35655c60b64SEd Maste.An Dave Chapeskie 357