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.\" 34*75e7ef74SLutz Donnerhacke.Dd January 18, 2021 35585ff168SJulian Elischer.Dt NG_SOURCE 4 36585ff168SJulian Elischer.Os 37585ff168SJulian Elischer.Sh NAME 38585ff168SJulian Elischer.Nm ng_source 3937684cf3SGleb Smirnoff.Nd netgraph node for traffic generation 40585ff168SJulian Elischer.Sh SYNOPSIS 41fbad9e2dSRuslan Ermilov.In sys/types.h 42585ff168SJulian Elischer.In netgraph/ng_source.h 43585ff168SJulian Elischer.Sh DESCRIPTION 44585ff168SJulian ElischerThe 45585ff168SJulian Elischer.Nm source 46585ff168SJulian Elischernode acts as a source of packets according to the parameters set up 47585ff168SJulian Elischerusing control messages and input packets. 4876648c1fSRuslan ErmilovThe 4937684cf3SGleb Smirnoff.Nm 5037684cf3SGleb Smirnoffnode type is used primarily for testing and benchmarking. 51585ff168SJulian Elischer.Sh HOOKS 52585ff168SJulian ElischerThe 53585ff168SJulian Elischer.Nm source 5476648c1fSRuslan Ermilovnode has two hooks: 5537684cf3SGleb Smirnoff.Va input 5676648c1fSRuslan Ermilovand 5737684cf3SGleb Smirnoff.Va output . 5876648c1fSRuslan ErmilovThe 5937684cf3SGleb Smirnoff.Va output 60585ff168SJulian Elischerhook must remain connected, its disconnection will shutdown the node. 6137684cf3SGleb Smirnoff.Sh OPERATION 6237684cf3SGleb SmirnoffThe operation of the node is as follows. 6337684cf3SGleb SmirnoffPackets received on the 6437684cf3SGleb Smirnoff.Va input 6537684cf3SGleb Smirnoffhook are queued internally. 6637684cf3SGleb SmirnoffWhen 6737684cf3SGleb Smirnoff.Va output 6837684cf3SGleb Smirnoffhook is connected, 6937684cf3SGleb Smirnoff.Nm 7037684cf3SGleb Smirnoffnode assumes that its neighbour node is of 714f068961SRuslan Ermilov.Xr ng_ether 4 7237684cf3SGleb Smirnoffnode type. 734f068961SRuslan ErmilovThe neighbour is queried for its interface name. 744f068961SRuslan ErmilovThe 7537684cf3SGleb Smirnoff.Nm 7637684cf3SGleb Smirnoffnode then uses queue of the interface for its evil purposes. 774f068961SRuslan ErmilovThe 7837684cf3SGleb Smirnoff.Nm 7937684cf3SGleb Smirnoffnode also disables 8037684cf3SGleb Smirnoff.Va autosrc 8137684cf3SGleb Smirnoffoption on neighbour 824f068961SRuslan Ermilov.Xr ng_ether 4 8337684cf3SGleb Smirnoffnode. 844f068961SRuslan ErmilovIf interface name cannot be obtained automatically, it should 854f068961SRuslan Ermilovbe configured explicitly with the 8637684cf3SGleb Smirnoff.Dv NGM_SOURCE_SETIFACE 8737684cf3SGleb Smirnoffcontrol message, and 8837684cf3SGleb Smirnoff.Va autosrc 8937684cf3SGleb Smirnoffshould be turned off on 904f068961SRuslan Ermilov.Xr ng_ether 4 9137684cf3SGleb Smirnoffnode manually. 9237684cf3SGleb Smirnoff.Pp 93*75e7ef74SLutz DonnerhackeIf the node is connected to a netgraph network, which does not 94*75e7ef74SLutz Donnerhacketerminate in a real 95*75e7ef74SLutz Donnerhacke.Xr ng_ether 4 96*75e7ef74SLutz Donnerhackeinterface, limit the packet injection rate explicitly with the 97*75e7ef74SLutz Donnerhacke.Va NGM_SOURCE_SETPPS 98*75e7ef74SLutz Donnerhackecontrol message. 99*75e7ef74SLutz Donnerhacke.Pp 100*75e7ef74SLutz DonnerhackeUpon receipt of a 10137684cf3SGleb Smirnoff.Dv NGM_SOURCE_START 10237684cf3SGleb Smirnoffcontrol message the node starts sending 10337684cf3SGleb Smirnoffthe previously queued packets out the 10437684cf3SGleb Smirnoff.Va output 10537684cf3SGleb Smirnoffhook on every clock tick as fast 10637684cf3SGleb Smirnoffas the connected interface will take them. 10737684cf3SGleb SmirnoffWhile active, on every clock tick the node checks the available space 10837684cf3SGleb Smirnoffin the interface queue and sends that many packets out its 10937684cf3SGleb Smirnoff.Va output 11037684cf3SGleb Smirnoffhook. 1114f068961SRuslan ErmilovOnce the number of packets indicated in the start message has been 1124f068961SRuslan Ermilovsent, or upon receipt of a 1134f068961SRuslan Ermilov.Dv NGM_SOURCE_STOP 1144f068961SRuslan Ermilovmessage, the node stops sending data. 115585ff168SJulian Elischer.Sh CONTROL MESSAGES 116585ff168SJulian ElischerThis node type supports the generic control messages as well as the following, 117585ff168SJulian Elischerwhich must be sent with the 11876648c1fSRuslan Ermilov.Dv NGM_SOURCE_COOKIE 119585ff168SJulian Elischerattached. 120c60bda17SJoel Dahl.Bl -tag -width foo 12176648c1fSRuslan Ermilov.It Dv NGM_SOURCE_GET_STATS Pq Ic getstats 122585ff168SJulian ElischerReturns a structure containing the following fields: 123c60bda17SJoel Dahl.Bl -tag -width ".Va elapsedTime" 12476648c1fSRuslan Ermilov.It Va outOctets 12576648c1fSRuslan ErmilovThe number of octets/bytes sent out the 1264f068961SRuslan Ermilov.Va output 12776648c1fSRuslan Ermilovhook. 12876648c1fSRuslan Ermilov.It Va outFrames 12976648c1fSRuslan ErmilovThe number of frames/packets sent out the 1304f068961SRuslan Ermilov.Va output 13176648c1fSRuslan Ermilovhook. 13276648c1fSRuslan Ermilov.It Va queueOctets 13376648c1fSRuslan ErmilovThe number of octets queued from the 1344f068961SRuslan Ermilov.Va input 13576648c1fSRuslan Ermilovhook. 13676648c1fSRuslan Ermilov.It Va queueFrames 13776648c1fSRuslan ErmilovThe number of frames queued from the 1384f068961SRuslan Ermilov.Va input 13976648c1fSRuslan Ermilovhook. 14076648c1fSRuslan Ermilov.It Va startTime 14176648c1fSRuslan ErmilovThe time the last start message was received. 14276648c1fSRuslan Ermilov.It Va endTime 14376648c1fSRuslan ErmilovThe time the last end message was received or 144585ff168SJulian Elischerthe output packet count was reached. 14576648c1fSRuslan Ermilov.It Va elapsedTime 14676648c1fSRuslan ErmilovEither 14776648c1fSRuslan Ermilov.Va endTime Li \- Va startTime 14876648c1fSRuslan Ermilovor current time 14976648c1fSRuslan Ermilov\- 15076648c1fSRuslan Ermilov.Va startTime . 151585ff168SJulian Elischer.El 15276648c1fSRuslan Ermilov.It Dv NGM_SOURCE_CLR_STATS Pq Ic clrstats 15376648c1fSRuslan ErmilovClears and resets the statistics returned by 15476648c1fSRuslan Ermilov.Ic getstats 15576648c1fSRuslan Ermilov(except 15676648c1fSRuslan Ermilov.Va queueOctets 15776648c1fSRuslan Ermilovand 15876648c1fSRuslan Ermilov.Va queueFrames ) . 15976648c1fSRuslan Ermilov.It Dv NGM_SOURCE_GETCLR_STATS Pq Ic getclrstats 16076648c1fSRuslan ErmilovAs 16176648c1fSRuslan Ermilov.Ic getstats 16276648c1fSRuslan Ermilovbut clears the statistics at the same time. 16376648c1fSRuslan Ermilov.It Dv NGM_SOURCE_START Pq Ic start 16437684cf3SGleb SmirnoffThis message requires a single 16537684cf3SGleb Smirnoff.Vt uint64_t 16676648c1fSRuslan Ermilovparameter which is the number of packets to 167585ff168SJulian Elischersend before stopping. 1684f068961SRuslan ErmilovNode starts sending the queued packets out the 1694f068961SRuslan Ermilov.Va output 1704f068961SRuslan Ermilovhook. 1714f068961SRuslan ErmilovThe 1724f068961SRuslan Ermilov.Va output 1734f068961SRuslan Ermilovhook must be connected and node must have 17437684cf3SGleb Smirnoffinterface configured. 17576648c1fSRuslan Ermilov.It Dv NGM_SOURCE_STOP Pq Ic stop 176585ff168SJulian ElischerStops the node if it is active. 17776648c1fSRuslan Ermilov.It Dv NGM_SOURCE_CLR_DATA Pq Ic clrdata 17876648c1fSRuslan ErmilovClears the packets queued from the 1794f068961SRuslan Ermilov.Va input 18076648c1fSRuslan Ermilovhook. 18137684cf3SGleb Smirnoff.It Dv NGM_SOURCE_SETIFACE Pq Ic setiface 1824f068961SRuslan ErmilovThis message requires the name of the interface 1834f068961SRuslan Ermilovto be configured as an argument. 18472235857SGleb Smirnoff.It Dv NGM_SOURCE_SETPPS Pq Ic setpps 18572235857SGleb SmirnoffThis message requires a single 18672235857SGleb Smirnoff.Vt uint32_t 18772235857SGleb Smirnoffparameter which puts upper limit on the amount of packets 18872235857SGleb Smirnoffsent per second. 18955c60b64SEd Maste.It Dv NGM_SOURCE_SET_TIMESTAMP Pq Ic settimestamp 19055c60b64SEd MasteThis message specifies that a timestamp (in the format of a 191dcc76067SEd Maste.Vt "struct timeval" ) 19255c60b64SEd Masteshould be inserted in the transmitted packets. 19355c60b64SEd MasteThis message requires a structure containing the following fields: 194c60bda17SJoel Dahl.Bl -tag -width ".Va offset" 19555c60b64SEd Maste.It Va offset 19655c60b64SEd MasteThe offset from the beginning of the packet at which the timestamp is to be 19755c60b64SEd Masteinserted. 19855c60b64SEd Maste.It Va flags 19955c60b64SEd MasteSet to 1 to enable the timestamp. 20055c60b64SEd Maste.El 20155c60b64SEd Maste.It Dv NGM_SOURCE_GET_TIMESTAMP Pq Ic gettimestamp 20255c60b64SEd MasteReturns the current timestamp settings in the form of the structure described 20355c60b64SEd Masteabove. 20455c60b64SEd Maste.It Dv NGM_SOURCE_SET_COUNTER Pq Ic setcounter 20555c60b64SEd MasteThis message specifies that a counter should be embedded in transmitted 20655c60b64SEd Mastepackets. 20755c60b64SEd MasteUp to four counters may be independently configured. 20855c60b64SEd MasteThis message requires a structure containing the following fields: 209c60bda17SJoel Dahl.Bl -tag -width ".Va increment" 21055c60b64SEd Maste.It Va offset 21155c60b64SEd MasteThe offset from the beginning of the packet at which the counter is to be 21255c60b64SEd Masteinserted. 21355c60b64SEd Maste.It Va flags 21455c60b64SEd MasteSet to 1 to enable the counter. 21555c60b64SEd Maste.It Va width 216dcc76067SEd MasteThe byte width of the counter. 217dcc76067SEd MasteIt may be 1, 2, or 4. 21855c60b64SEd Maste.It Va next_val 21955c60b64SEd MasteThe value for the next insertion of the counter. 22055c60b64SEd Maste.It Va min_val 22155c60b64SEd MasteThe minimum value to be used by the counter. 22255c60b64SEd Maste.It Va max_val 22355c60b64SEd MasteThe maximum value to be used by the counter. 22455c60b64SEd Maste.It Va increment 22555c60b64SEd MasteThe value to be added to the counter after each insertion. 22655c60b64SEd MasteIt may be negative. 22755c60b64SEd Maste.It Va index 22855c60b64SEd MasteThe counter to be configured, from 0 to 3. 22955c60b64SEd Maste.El 23055c60b64SEd Maste.It Dv NGM_SOURCE_GET_COUNTER Pq Ic getcounter 23155c60b64SEd MasteThis message requires a single 23255c60b64SEd Maste.Vt uint8_t 23355c60b64SEd Masteparameter which specifies the counter to query. 23455c60b64SEd MasteReturns the current counter settings in the form of the structure described 23555c60b64SEd Masteabove. 236585ff168SJulian Elischer.El 237585ff168SJulian Elischer.Sh SHUTDOWN 238585ff168SJulian ElischerThis node shuts down upon receipt of a 239585ff168SJulian Elischer.Dv NGM_SHUTDOWN 2404f068961SRuslan Ermilovcontrol message, when all hooks have been disconnected, or when the 24137684cf3SGleb Smirnoff.Va output 242585ff168SJulian Elischerhook has been disconnected. 24376648c1fSRuslan Ermilov.Sh EXAMPLES 24476648c1fSRuslan ErmilovAttach the node to an 24576648c1fSRuslan Ermilov.Xr ng_ether 4 24676648c1fSRuslan Ermilovnode for an interface. 24776648c1fSRuslan ErmilovIf 24876648c1fSRuslan Ermilov.Nm ng_ether 24976648c1fSRuslan Ermilovis 25076648c1fSRuslan Ermilovnot already loaded you will need to do so. 25176648c1fSRuslan ErmilovFor example, these commands 25276648c1fSRuslan Ermilovload the 25376648c1fSRuslan Ermilov.Nm ng_ether 25476648c1fSRuslan Ermilovmodule and attach the 2554f068961SRuslan Ermilov.Va output 25676648c1fSRuslan Ermilovhook of a new 25776648c1fSRuslan Ermilov.Nm source 25876648c1fSRuslan Ermilovnode to 2594f068961SRuslan Ermilov.Va orphans 26076648c1fSRuslan Ermilovhook of the 26176648c1fSRuslan Ermilov.Li bge0: 26276648c1fSRuslan Ermilov.Nm ng_ether 26376648c1fSRuslan Ermilovnode. 26476648c1fSRuslan Ermilov.Bd -literal -offset indent 26576648c1fSRuslan Ermilovkldload ng_ether 26676648c1fSRuslan Ermilovngctl mkpeer bge0: source orphans output 267585ff168SJulian Elischer.Ed 268585ff168SJulian Elischer.Pp 26976648c1fSRuslan ErmilovAt this point the new node can be referred to as 27076648c1fSRuslan Ermilov.Dq Li bge0:orphans . 27176648c1fSRuslan ErmilovThe 27276648c1fSRuslan Ermilovnode can be given its own name like this: 273585ff168SJulian Elischer.Pp 27476648c1fSRuslan Ermilov.Dl "ngctl name bge0:orphans src0" 275585ff168SJulian Elischer.Pp 27676648c1fSRuslan ErmilovAfter which it can be referred to as 27776648c1fSRuslan Ermilov.Dq Li src0: . 278585ff168SJulian Elischer.Pp 27958b1cfdeSEd MasteOnce created, packets can be sent to the node as raw binary data. 28058b1cfdeSEd MasteEach packet must be delivered in a separate netgraph message. 281585ff168SJulian Elischer.Pp 28258b1cfdeSEd MasteThe following example uses a short Perl script to convert the hex 28358b1cfdeSEd Masterepresentation of an ICMP packet to binary and deliver it to the 28476648c1fSRuslan Ermilov.Nm source 28576648c1fSRuslan Ermilovnode's 2864f068961SRuslan Ermilov.Va input 28776648c1fSRuslan Ermilovhook via 28876648c1fSRuslan Ermilov.Xr nghook 8 : 28958b1cfdeSEd Maste.Bd -literal -offset indent 29058b1cfdeSEd Masteperl -pe 's/(..)[ \et\en]*/chr(hex($1))/ge' <<EOF | nghook src0: input 29158b1cfdeSEd Masteff ff ff ff ff ff 00 00 00 00 00 00 08 00 45 00 29258b1cfdeSEd Maste00 54 cb 13 00 00 40 01 b9 87 c0 a8 2b 65 0a 00 29358b1cfdeSEd Maste00 01 08 00 f8 d0 c9 76 00 00 45 37 01 73 00 01 29458b1cfdeSEd Maste04 0a 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 29558b1cfdeSEd Maste16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 29658b1cfdeSEd Maste26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 29758b1cfdeSEd Maste36 37 29858b1cfdeSEd MasteEOF 29958b1cfdeSEd Maste.Ed 300585ff168SJulian Elischer.Pp 301585ff168SJulian ElischerTo check that the node has queued these packets you can get the node 302585ff168SJulian Elischerstatistics: 30376648c1fSRuslan Ermilov.Bd -literal -offset indent 30476648c1fSRuslan Ermilovngctl msg bge0:orphans getstats 305585ff168SJulian ElischerArgs: { queueOctets=64 queueFrames=1 } 306585ff168SJulian Elischer.Ed 307585ff168SJulian Elischer.Pp 30876648c1fSRuslan ErmilovSend as many packets as required out the 3094f068961SRuslan Ermilov.Va output 31076648c1fSRuslan Ermilovhook: 311585ff168SJulian Elischer.Pp 31276648c1fSRuslan Ermilov.Dl "ngctl msg bge0:orphans start 16" 31376648c1fSRuslan Ermilov.Pp 31476648c1fSRuslan ErmilovEither wait for them to be sent (periodically fetching stats if desired) 315585ff168SJulian Elischeror send the stop message: 316585ff168SJulian Elischer.Pp 31776648c1fSRuslan Ermilov.Dl "ngctl msg bge0:orphans stop" 31876648c1fSRuslan Ermilov.Pp 31976648c1fSRuslan ErmilovCheck the statistics (here we use 32076648c1fSRuslan Ermilov.Ic getclrstats 32176648c1fSRuslan Ermilovto also clear the statistics): 32276648c1fSRuslan Ermilov.Bd -literal -offset indent 32376648c1fSRuslan Ermilovngctl msg bge0:orphans getclrstats 324585ff168SJulian ElischerArgs: { outOctets=1024 outFrames=16 queueOctets=64 queueFrames=1 325585ff168SJulian ElischerstartTime={ tv_sec=1035305880 tv_usec=758036 } endTime={ tv_sec=1035305880 326585ff168SJulian Elischertv_usec=759041 } elapsedTime={ tv_usec=1005 } } 327585ff168SJulian Elischer.Ed 328585ff168SJulian Elischer.Pp 32976648c1fSRuslan ErmilovThe times are from 33076648c1fSRuslan Ermilov.Vt "struct timeval" Ns s , 33176648c1fSRuslan Ermilovthe 33276648c1fSRuslan Ermilov.Va tv_sec 33376648c1fSRuslan Ermilovfield is seconds since 33476648c1fSRuslan Ermilovthe Epoch and can be converted into a date string via TCL's [clock 33576648c1fSRuslan Ermilovformat] or via the 33676648c1fSRuslan Ermilov.Xr date 1 33776648c1fSRuslan Ermilovcommand: 33876648c1fSRuslan Ermilov.Bd -literal -offset indent 33976648c1fSRuslan Ermilovdate -r 1035305880 340585ff168SJulian ElischerTue Oct 22 12:58:00 EDT 2002 341585ff168SJulian Elischer.Ed 342585ff168SJulian Elischer.Sh SEE ALSO 343585ff168SJulian Elischer.Xr netgraph 4 , 344585ff168SJulian Elischer.Xr ng_echo 4 , 345585ff168SJulian Elischer.Xr ng_hole 4 , 346585ff168SJulian Elischer.Xr ng_tee 4 , 34776648c1fSRuslan Ermilov.Xr ngctl 8 , 348585ff168SJulian Elischer.Xr nghook 8 349585ff168SJulian Elischer.Sh HISTORY 350585ff168SJulian ElischerThe 351585ff168SJulian Elischer.Nm 352585ff168SJulian Elischernode type was implemented in 353585ff168SJulian Elischer.Fx 4.8 . 354585ff168SJulian Elischer.Sh AUTHORS 35555c60b64SEd Maste.An Dave Chapeskie 356