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.\" 3555c60b64SEd Maste.Dd March 1, 2007 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. 114*c60bda17SJoel Dahl.Bl -tag -width foo 11576648c1fSRuslan Ermilov.It Dv NGM_SOURCE_GET_STATS Pq Ic getstats 116585ff168SJulian ElischerReturns a structure containing the following fields: 117*c60bda17SJoel Dahl.Bl -tag -width ".Va elapsedTime" 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. 18355c60b64SEd Maste.It Dv NGM_SOURCE_SET_TIMESTAMP Pq Ic settimestamp 18455c60b64SEd MasteThis message specifies that a timestamp (in the format of a 185dcc76067SEd Maste.Vt "struct timeval" ) 18655c60b64SEd Masteshould be inserted in the transmitted packets. 18755c60b64SEd MasteThis message requires a structure containing the following fields: 188*c60bda17SJoel Dahl.Bl -tag -width ".Va offset" 18955c60b64SEd Maste.It Va offset 19055c60b64SEd MasteThe offset from the beginning of the packet at which the timestamp is to be 19155c60b64SEd Masteinserted. 19255c60b64SEd Maste.It Va flags 19355c60b64SEd MasteSet to 1 to enable the timestamp. 19455c60b64SEd Maste.El 19555c60b64SEd Maste.It Dv NGM_SOURCE_GET_TIMESTAMP Pq Ic gettimestamp 19655c60b64SEd MasteReturns the current timestamp settings in the form of the structure described 19755c60b64SEd Masteabove. 19855c60b64SEd Maste.It Dv NGM_SOURCE_SET_COUNTER Pq Ic setcounter 19955c60b64SEd MasteThis message specifies that a counter should be embedded in transmitted 20055c60b64SEd Mastepackets. 20155c60b64SEd MasteUp to four counters may be independently configured. 20255c60b64SEd MasteThis message requires a structure containing the following fields: 203*c60bda17SJoel Dahl.Bl -tag -width ".Va increment" 20455c60b64SEd Maste.It Va offset 20555c60b64SEd MasteThe offset from the beginning of the packet at which the counter is to be 20655c60b64SEd Masteinserted. 20755c60b64SEd Maste.It Va flags 20855c60b64SEd MasteSet to 1 to enable the counter. 20955c60b64SEd Maste.It Va width 210dcc76067SEd MasteThe byte width of the counter. 211dcc76067SEd MasteIt may be 1, 2, or 4. 21255c60b64SEd Maste.It Va next_val 21355c60b64SEd MasteThe value for the next insertion of the counter. 21455c60b64SEd Maste.It Va min_val 21555c60b64SEd MasteThe minimum value to be used by the counter. 21655c60b64SEd Maste.It Va max_val 21755c60b64SEd MasteThe maximum value to be used by the counter. 21855c60b64SEd Maste.It Va increment 21955c60b64SEd MasteThe value to be added to the counter after each insertion. 22055c60b64SEd MasteIt may be negative. 22155c60b64SEd Maste.It Va index 22255c60b64SEd MasteThe counter to be configured, from 0 to 3. 22355c60b64SEd Maste.El 22455c60b64SEd Maste.It Dv NGM_SOURCE_GET_COUNTER Pq Ic getcounter 22555c60b64SEd MasteThis message requires a single 22655c60b64SEd Maste.Vt uint8_t 22755c60b64SEd Masteparameter which specifies the counter to query. 22855c60b64SEd MasteReturns the current counter settings in the form of the structure described 22955c60b64SEd Masteabove. 230585ff168SJulian Elischer.El 231585ff168SJulian Elischer.Sh SHUTDOWN 232585ff168SJulian ElischerThis node shuts down upon receipt of a 233585ff168SJulian Elischer.Dv NGM_SHUTDOWN 2344f068961SRuslan Ermilovcontrol message, when all hooks have been disconnected, or when the 23537684cf3SGleb Smirnoff.Va output 236585ff168SJulian Elischerhook has been disconnected. 23776648c1fSRuslan Ermilov.Sh EXAMPLES 23876648c1fSRuslan ErmilovAttach the node to an 23976648c1fSRuslan Ermilov.Xr ng_ether 4 24076648c1fSRuslan Ermilovnode for an interface. 24176648c1fSRuslan ErmilovIf 24276648c1fSRuslan Ermilov.Nm ng_ether 24376648c1fSRuslan Ermilovis 24476648c1fSRuslan Ermilovnot already loaded you will need to do so. 24576648c1fSRuslan ErmilovFor example, these commands 24676648c1fSRuslan Ermilovload the 24776648c1fSRuslan Ermilov.Nm ng_ether 24876648c1fSRuslan Ermilovmodule and attach the 2494f068961SRuslan Ermilov.Va output 25076648c1fSRuslan Ermilovhook of a new 25176648c1fSRuslan Ermilov.Nm source 25276648c1fSRuslan Ermilovnode to 2534f068961SRuslan Ermilov.Va orphans 25476648c1fSRuslan Ermilovhook of the 25576648c1fSRuslan Ermilov.Li bge0: 25676648c1fSRuslan Ermilov.Nm ng_ether 25776648c1fSRuslan Ermilovnode. 25876648c1fSRuslan Ermilov.Bd -literal -offset indent 25976648c1fSRuslan Ermilovkldload ng_ether 26076648c1fSRuslan Ermilovngctl mkpeer bge0: source orphans output 261585ff168SJulian Elischer.Ed 262585ff168SJulian Elischer.Pp 26376648c1fSRuslan ErmilovAt this point the new node can be referred to as 26476648c1fSRuslan Ermilov.Dq Li bge0:orphans . 26576648c1fSRuslan ErmilovThe 26676648c1fSRuslan Ermilovnode can be given its own name like this: 267585ff168SJulian Elischer.Pp 26876648c1fSRuslan Ermilov.Dl "ngctl name bge0:orphans src0" 269585ff168SJulian Elischer.Pp 27076648c1fSRuslan ErmilovAfter which it can be referred to as 27176648c1fSRuslan Ermilov.Dq Li src0: . 272585ff168SJulian Elischer.Pp 27358b1cfdeSEd MasteOnce created, packets can be sent to the node as raw binary data. 27458b1cfdeSEd MasteEach packet must be delivered in a separate netgraph message. 275585ff168SJulian Elischer.Pp 27658b1cfdeSEd MasteThe following example uses a short Perl script to convert the hex 27758b1cfdeSEd Masterepresentation of an ICMP packet to binary and deliver it to the 27876648c1fSRuslan Ermilov.Nm source 27976648c1fSRuslan Ermilovnode's 2804f068961SRuslan Ermilov.Va input 28176648c1fSRuslan Ermilovhook via 28276648c1fSRuslan Ermilov.Xr nghook 8 : 28358b1cfdeSEd Maste.Bd -literal -offset indent 28458b1cfdeSEd Masteperl -pe 's/(..)[ \et\en]*/chr(hex($1))/ge' <<EOF | nghook src0: input 28558b1cfdeSEd Masteff ff ff ff ff ff 00 00 00 00 00 00 08 00 45 00 28658b1cfdeSEd Maste00 54 cb 13 00 00 40 01 b9 87 c0 a8 2b 65 0a 00 28758b1cfdeSEd Maste00 01 08 00 f8 d0 c9 76 00 00 45 37 01 73 00 01 28858b1cfdeSEd Maste04 0a 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 28958b1cfdeSEd Maste16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 29058b1cfdeSEd Maste26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 29158b1cfdeSEd Maste36 37 29258b1cfdeSEd MasteEOF 29358b1cfdeSEd Maste.Ed 294585ff168SJulian Elischer.Pp 295585ff168SJulian ElischerTo check that the node has queued these packets you can get the node 296585ff168SJulian Elischerstatistics: 29776648c1fSRuslan Ermilov.Bd -literal -offset indent 29876648c1fSRuslan Ermilovngctl msg bge0:orphans getstats 299585ff168SJulian ElischerArgs: { queueOctets=64 queueFrames=1 } 300585ff168SJulian Elischer.Ed 301585ff168SJulian Elischer.Pp 30276648c1fSRuslan ErmilovSend as many packets as required out the 3034f068961SRuslan Ermilov.Va output 30476648c1fSRuslan Ermilovhook: 305585ff168SJulian Elischer.Pp 30676648c1fSRuslan Ermilov.Dl "ngctl msg bge0:orphans start 16" 30776648c1fSRuslan Ermilov.Pp 30876648c1fSRuslan ErmilovEither wait for them to be sent (periodically fetching stats if desired) 309585ff168SJulian Elischeror send the stop message: 310585ff168SJulian Elischer.Pp 31176648c1fSRuslan Ermilov.Dl "ngctl msg bge0:orphans stop" 31276648c1fSRuslan Ermilov.Pp 31376648c1fSRuslan ErmilovCheck the statistics (here we use 31476648c1fSRuslan Ermilov.Ic getclrstats 31576648c1fSRuslan Ermilovto also clear the statistics): 31676648c1fSRuslan Ermilov.Bd -literal -offset indent 31776648c1fSRuslan Ermilovngctl msg bge0:orphans getclrstats 318585ff168SJulian ElischerArgs: { outOctets=1024 outFrames=16 queueOctets=64 queueFrames=1 319585ff168SJulian ElischerstartTime={ tv_sec=1035305880 tv_usec=758036 } endTime={ tv_sec=1035305880 320585ff168SJulian Elischertv_usec=759041 } elapsedTime={ tv_usec=1005 } } 321585ff168SJulian Elischer.Ed 322585ff168SJulian Elischer.Pp 32376648c1fSRuslan ErmilovThe times are from 32476648c1fSRuslan Ermilov.Vt "struct timeval" Ns s , 32576648c1fSRuslan Ermilovthe 32676648c1fSRuslan Ermilov.Va tv_sec 32776648c1fSRuslan Ermilovfield is seconds since 32876648c1fSRuslan Ermilovthe Epoch and can be converted into a date string via TCL's [clock 32976648c1fSRuslan Ermilovformat] or via the 33076648c1fSRuslan Ermilov.Xr date 1 33176648c1fSRuslan Ermilovcommand: 33276648c1fSRuslan Ermilov.Bd -literal -offset indent 33376648c1fSRuslan Ermilovdate -r 1035305880 334585ff168SJulian ElischerTue Oct 22 12:58:00 EDT 2002 335585ff168SJulian Elischer.Ed 336585ff168SJulian Elischer.Sh SEE ALSO 337585ff168SJulian Elischer.Xr netgraph 4 , 338585ff168SJulian Elischer.Xr ng_echo 4 , 339585ff168SJulian Elischer.Xr ng_hole 4 , 340585ff168SJulian Elischer.Xr ng_tee 4 , 34176648c1fSRuslan Ermilov.Xr ngctl 8 , 342585ff168SJulian Elischer.Xr nghook 8 343585ff168SJulian Elischer.Sh HISTORY 344585ff168SJulian ElischerThe 345585ff168SJulian Elischer.Nm 346585ff168SJulian Elischernode type was implemented in 347585ff168SJulian Elischer.Fx 4.8 . 348585ff168SJulian Elischer.Sh AUTHORS 34955c60b64SEd Maste.An Dave Chapeskie 350