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 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 4976648c1fSRuslan Ermilov.Dv output 5076648c1fSRuslan Ermilovhook must also be connected to a node that responds to the 5176648c1fSRuslan Ermilov.Dv NGM_ETHER_COOKIE Ns / Ns 5276648c1fSRuslan Ermilov.Dv NGM_ETHER_GET_IFINDEX 5376648c1fSRuslan Ermilovmessage (e.g., an 5476648c1fSRuslan Ermilov.Xr ng_ether 4 55585ff168SJulian Elischernode). 56585ff168SJulian ElischerThis type is used for testing and debugging. 57585ff168SJulian Elischer.Pp 58585ff168SJulian ElischerThe operation of the node is as follows: 5976648c1fSRuslan Ermilov.Bl -bullet 60585ff168SJulian Elischer.It 6176648c1fSRuslan ErmilovPackets received on the 6276648c1fSRuslan Ermilov.Dv input 6376648c1fSRuslan Ermilovhook are queued internally. 64585ff168SJulian Elischer.It 6576648c1fSRuslan ErmilovOn reception of a 6676648c1fSRuslan Ermilov.Dv NGM_SOURCE_START 6776648c1fSRuslan Ermilovmessage the node starts sending 6876648c1fSRuslan Ermilovthe queued packets out the 6976648c1fSRuslan Ermilov.Dv output 7076648c1fSRuslan Ermilovhook on every clock tick as fast 71585ff168SJulian Elischeras the connect interface will take them. 72585ff168SJulian Elischer.It 73585ff168SJulian ElischerWhile active, on every clock tick the node checks the available space 7476648c1fSRuslan Ermilovin the 7576648c1fSRuslan Ermilov.Va ifqueue 7676648c1fSRuslan Ermilovof the interface connected to the output hook and sends 7776648c1fSRuslan Ermilovthat many packets out its 7876648c1fSRuslan Ermilov.Dv output 7976648c1fSRuslan Ermilovhook. 80585ff168SJulian Elischer.It 81585ff168SJulian ElischerOnce the number of packets indicated in the start message have been 82585ff168SJulian Elischersent, or on reception of a stop message, the node stops sending data. 83585ff168SJulian Elischer.El 84585ff168SJulian Elischer.Sh HOOKS 85585ff168SJulian ElischerThe 86585ff168SJulian Elischer.Nm source 8776648c1fSRuslan Ermilovnode has two hooks: 8876648c1fSRuslan Ermilov.Dv input 8976648c1fSRuslan Ermilovand 9076648c1fSRuslan Ermilov.Dv output . 9176648c1fSRuslan ErmilovThe 9276648c1fSRuslan Ermilov.Dv output 93585ff168SJulian Elischerhook must remain connected, its disconnection will shutdown the node. 94585ff168SJulian Elischer.Sh CONTROL MESSAGES 95585ff168SJulian ElischerThis node type supports the generic control messages as well as the following, 96585ff168SJulian Elischerwhich must be sent with the 9776648c1fSRuslan Ermilov.Dv NGM_SOURCE_COOKIE 98585ff168SJulian Elischerattached. 9976648c1fSRuslan Ermilov.Bl -tag -width indent 10076648c1fSRuslan Ermilov.It Dv NGM_SOURCE_GET_STATS Pq Ic getstats 101585ff168SJulian ElischerReturns a structure containing the following fields: 10276648c1fSRuslan Ermilov.Bl -tag -width indent 10376648c1fSRuslan Ermilov.It Va outOctets 10476648c1fSRuslan ErmilovThe number of octets/bytes sent out the 10576648c1fSRuslan Ermilov.Dv output 10676648c1fSRuslan Ermilovhook. 10776648c1fSRuslan Ermilov.It Va outFrames 10876648c1fSRuslan ErmilovThe number of frames/packets sent out the 10976648c1fSRuslan Ermilov.Dv output 11076648c1fSRuslan Ermilovhook. 11176648c1fSRuslan Ermilov.It Va queueOctets 11276648c1fSRuslan ErmilovThe number of octets queued from the 11376648c1fSRuslan Ermilov.Dv input 11476648c1fSRuslan Ermilovhook. 11576648c1fSRuslan Ermilov.It Va queueFrames 11676648c1fSRuslan ErmilovThe number of frames queued from the 11776648c1fSRuslan Ermilov.Dv input 11876648c1fSRuslan Ermilovhook. 11976648c1fSRuslan Ermilov.It Va startTime 12076648c1fSRuslan ErmilovThe time the last start message was received. 12176648c1fSRuslan Ermilov.It Va endTime 12276648c1fSRuslan ErmilovThe time the last end message was received or 123585ff168SJulian Elischerthe output packet count was reached. 12476648c1fSRuslan Ermilov.It Va elapsedTime 12576648c1fSRuslan ErmilovEither 12676648c1fSRuslan Ermilov.Va endTime Li \- Va startTime 12776648c1fSRuslan Ermilovor current time 12876648c1fSRuslan Ermilov\- 12976648c1fSRuslan Ermilov.Va startTime . 130585ff168SJulian Elischer.El 13176648c1fSRuslan Ermilov.It Dv NGM_SOURCE_CLR_STATS Pq Ic clrstats 13276648c1fSRuslan ErmilovClears and resets the statistics returned by 13376648c1fSRuslan Ermilov.Ic getstats 13476648c1fSRuslan Ermilov(except 13576648c1fSRuslan Ermilov.Va queueOctets 13676648c1fSRuslan Ermilovand 13776648c1fSRuslan Ermilov.Va queueFrames ) . 13876648c1fSRuslan Ermilov.It Dv NGM_SOURCE_GETCLR_STATS Pq Ic getclrstats 13976648c1fSRuslan ErmilovAs 14076648c1fSRuslan Ermilov.Ic getstats 14176648c1fSRuslan Ermilovbut clears the statistics at the same time. 14276648c1fSRuslan Ermilov.It Dv NGM_SOURCE_START Pq Ic start 14376648c1fSRuslan Ermilov.Bl -bullet 144585ff168SJulian Elischer.It 14576648c1fSRuslan ErmilovTakes a single 14676648c1fSRuslan Ermilov.Vt u_int64_t 14776648c1fSRuslan Ermilovparameter which is the number of packets to 148585ff168SJulian Elischersend before stopping. 149585ff168SJulian Elischer.It 150585ff168SJulian ElischerStarts sending the queued packets out the output hook. 151585ff168SJulian Elischer.It 15276648c1fSRuslan ErmilovThe output hook must be connected or 15376648c1fSRuslan Ermilov.Er EINVAL 15476648c1fSRuslan Ermilovis returned. 155585ff168SJulian Elischer.It 156585ff168SJulian ElischerThe node connected to the output hook must respond to 15776648c1fSRuslan Ermilov.Dv NGM_ETHER_GET_IFINDEX 15876648c1fSRuslan Ermilovwhich is used to get the 15976648c1fSRuslan Ermilov.Va ifqueue 16076648c1fSRuslan Ermilovof the attached interface. 161585ff168SJulian Elischer.It 16276648c1fSRuslan Ermilov.Dv NGM_ETHER_SET_AUTOSRC 16376648c1fSRuslan Ermilovis sent to the node connected to the 16476648c1fSRuslan Ermilov.Dv output 16576648c1fSRuslan Ermilovhook 166585ff168SJulian Elischerto turn off automatic ethernet source address overwriting (any errors 167585ff168SJulian Elischerfrom this message are ignored). 168585ff168SJulian Elischer.El 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 17376648c1fSRuslan Ermilov.Dv input 17476648c1fSRuslan Ermilovhook. 175585ff168SJulian Elischer.El 176585ff168SJulian Elischer.Sh SHUTDOWN 177585ff168SJulian ElischerThis node shuts down upon receipt of a 178585ff168SJulian Elischer.Dv NGM_SHUTDOWN 179585ff168SJulian Elischercontrol message, or when the 18076648c1fSRuslan Ermilov.Dv output 181585ff168SJulian Elischerhook has been disconnected. 18276648c1fSRuslan Ermilov.Sh EXAMPLES 18376648c1fSRuslan ErmilovAttach the node to an 18476648c1fSRuslan Ermilov.Xr ng_ether 4 18576648c1fSRuslan Ermilovnode for an interface. 18676648c1fSRuslan ErmilovIf 18776648c1fSRuslan Ermilov.Nm ng_ether 18876648c1fSRuslan Ermilovis 18976648c1fSRuslan Ermilovnot already loaded you will need to do so. 19076648c1fSRuslan ErmilovFor example, these commands 19176648c1fSRuslan Ermilovload the 19276648c1fSRuslan Ermilov.Nm ng_ether 19376648c1fSRuslan Ermilovmodule and attach the 19476648c1fSRuslan Ermilov.Dv output 19576648c1fSRuslan Ermilovhook of a new 19676648c1fSRuslan Ermilov.Nm source 19776648c1fSRuslan Ermilovnode to 19876648c1fSRuslan Ermilov.Dv orphans 19976648c1fSRuslan Ermilovhook of the 20076648c1fSRuslan Ermilov.Li bge0: 20176648c1fSRuslan Ermilov.Nm ng_ether 20276648c1fSRuslan Ermilovnode. 20376648c1fSRuslan Ermilov.Bd -literal -offset indent 20476648c1fSRuslan Ermilovkldload ng_ether 20576648c1fSRuslan Ermilovngctl mkpeer bge0: source orphans output 206585ff168SJulian Elischer.Ed 207585ff168SJulian Elischer.Pp 20876648c1fSRuslan ErmilovAt this point the new node can be referred to as 20976648c1fSRuslan Ermilov.Dq Li bge0:orphans . 21076648c1fSRuslan ErmilovThe 21176648c1fSRuslan Ermilovnode can be given its own name like this: 212585ff168SJulian Elischer.Pp 21376648c1fSRuslan Ermilov.Dl "ngctl name bge0:orphans src0" 214585ff168SJulian Elischer.Pp 21576648c1fSRuslan ErmilovAfter which it can be referred to as 21676648c1fSRuslan Ermilov.Dq Li src0: . 217585ff168SJulian Elischer.Pp 21876648c1fSRuslan ErmilovOnce created, packets need to be sent to the node, the TCL net package 219585ff168SJulian Elischercan be used to generate these packets: 220585ff168SJulian Elischer.Pp 221585ff168SJulian Elischer[Sandvine specific TCL code example omitted] 222585ff168SJulian Elischer.Pp 22376648c1fSRuslan ErmilovTo feed the output of the above TCL script to the 22476648c1fSRuslan Ermilov.Nm source 22576648c1fSRuslan Ermilovnode's 22676648c1fSRuslan Ermilov.Dv input 22776648c1fSRuslan Ermilovhook via 22876648c1fSRuslan Ermilov.Xr nghook 8 : 22976648c1fSRuslan Ermilov.Pp 23076648c1fSRuslan Ermilov.Dl "tcl genPacket | nghook bge0:orphans input" 231585ff168SJulian Elischer.Pp 232585ff168SJulian ElischerTo check that the node has queued these packets you can get the node 233585ff168SJulian Elischerstatistics: 23476648c1fSRuslan Ermilov.Bd -literal -offset indent 23576648c1fSRuslan Ermilovngctl msg bge0:orphans getstats 236585ff168SJulian ElischerArgs: { queueOctets=64 queueFrames=1 } 237585ff168SJulian Elischer.Ed 238585ff168SJulian Elischer.Pp 23976648c1fSRuslan ErmilovSend as many packets as required out the 24076648c1fSRuslan Ermilov.Dv output 24176648c1fSRuslan Ermilovhook: 242585ff168SJulian Elischer.Pp 24376648c1fSRuslan Ermilov.Dl "ngctl msg bge0:orphans start 16" 24476648c1fSRuslan Ermilov.Pp 24576648c1fSRuslan ErmilovEither wait for them to be sent (periodically fetching stats if desired) 246585ff168SJulian Elischeror send the stop message: 247585ff168SJulian Elischer.Pp 24876648c1fSRuslan Ermilov.Dl "ngctl msg bge0:orphans stop" 24976648c1fSRuslan Ermilov.Pp 25076648c1fSRuslan ErmilovCheck the statistics (here we use 25176648c1fSRuslan Ermilov.Ic getclrstats 25276648c1fSRuslan Ermilovto also clear the statistics): 25376648c1fSRuslan Ermilov.Bd -literal -offset indent 25476648c1fSRuslan Ermilovngctl msg bge0:orphans getclrstats 255585ff168SJulian ElischerArgs: { outOctets=1024 outFrames=16 queueOctets=64 queueFrames=1 256585ff168SJulian ElischerstartTime={ tv_sec=1035305880 tv_usec=758036 } endTime={ tv_sec=1035305880 257585ff168SJulian Elischertv_usec=759041 } elapsedTime={ tv_usec=1005 } } 258585ff168SJulian Elischer.Ed 259585ff168SJulian Elischer.Pp 26076648c1fSRuslan ErmilovThe times are from 26176648c1fSRuslan Ermilov.Vt "struct timeval" Ns s , 26276648c1fSRuslan Ermilovthe 26376648c1fSRuslan Ermilov.Va tv_sec 26476648c1fSRuslan Ermilovfield is seconds since 26576648c1fSRuslan Ermilovthe Epoch and can be converted into a date string via TCL's [clock 26676648c1fSRuslan Ermilovformat] or via the 26776648c1fSRuslan Ermilov.Xr date 1 26876648c1fSRuslan Ermilovcommand: 26976648c1fSRuslan Ermilov.Bd -literal -offset indent 27076648c1fSRuslan Ermilovdate -r 1035305880 271585ff168SJulian ElischerTue Oct 22 12:58:00 EDT 2002 272585ff168SJulian Elischer.Ed 273585ff168SJulian Elischer.Sh IMPLEMENTATION NOTES 27476648c1fSRuslan Ermilov.No ( Fx 4.4 27576648c1fSRuslan Ermilovversion) 276585ff168SJulian Elischer.Pp 27776648c1fSRuslan ErmilovThe use of 27876648c1fSRuslan Ermilov.Xr splimp 9 27976648c1fSRuslan Ermilovaround the 28076648c1fSRuslan Ermilov.Dv NG_SEND_DATA 28176648c1fSRuslan Ermilovloop is important. 28276648c1fSRuslan ErmilovWithout it, 28376648c1fSRuslan Ermilovthe time taken by a single invocation of 28476648c1fSRuslan Ermilov.Fn ng_source_intr 28576648c1fSRuslan Ermilovbecomes too 28676648c1fSRuslan Ermilovlarge and the packet rate drops. 28776648c1fSRuslan ErmilovProbably due to the NIC starting to 288585ff168SJulian Elischersend the packets right away. 289585ff168SJulian Elischer.Pp 290585ff168SJulian ElischerCopying all the packets in one loop and sending them in another inside 29176648c1fSRuslan Ermilovof 29276648c1fSRuslan Ermilov.Fn ng_source_send 29376648c1fSRuslan Ermilovis done to limit how long we are at 29476648c1fSRuslan Ermilov.Xr splimp 9 29576648c1fSRuslan Ermilovand gave 29676648c1fSRuslan Ermilovminor packet rate increases (~5% at 256 byte packets). 29776648c1fSRuslan ErmilovHowever note 29876648c1fSRuslan Ermilovthat if there are errors in the send loop, the remaining copied packets 29976648c1fSRuslan Ermilovare simply freed and discarded; thus we skip those packets, and ordering 300585ff168SJulian Elischerof the input queue to the output is not maintained. 301585ff168SJulian Elischer.Pp 30276648c1fSRuslan ErmilovCalling 30376648c1fSRuslan Ermilov.Xr timeout 9 30476648c1fSRuslan Ermilovat the end of 30576648c1fSRuslan Ermilov.Fn ng_source_intr 30676648c1fSRuslan Ermilovinstead of near the 30776648c1fSRuslan Ermilovbeginning is done to help avoid CPU starvation if 30876648c1fSRuslan Ermilov.Fn ng_source_intr 30976648c1fSRuslan Ermilovtakes a long time to run. 310585ff168SJulian Elischer.Pp 31176648c1fSRuslan ErmilovThe use of 31276648c1fSRuslan Ermilov.Xr splnet 9 31376648c1fSRuslan Ermilovmay be sub-optimal. 31476648c1fSRuslan ErmilovIt is used for synchronization 31576648c1fSRuslan Ermilovwithin the node (e.g., data received on the 31676648c1fSRuslan Ermilov.Dv input 31776648c1fSRuslan Ermilovhook while 31876648c1fSRuslan Ermilov.Fn ng_source_send 31976648c1fSRuslan Ermilovis active) but we do not want to hold it too long and risk 320585ff168SJulian Elischerstarving the NIC. 321585ff168SJulian Elischer.Pp 32276648c1fSRuslan ErmilovFor clarity and simplicity, debugging messages and instrumentation code 32376648c1fSRuslan Ermilovhas been removed. 32476648c1fSRuslan ErmilovOn i386 one can include 32576648c1fSRuslan Ermilov.Aq Pa machine/cpufunc.h 32676648c1fSRuslan Ermilovto have access to the 32776648c1fSRuslan Ermilov.Fn rdtsc 32876648c1fSRuslan Ermilovfunction to read the instruction counter at the 32976648c1fSRuslan Ermilovstart and end of 33076648c1fSRuslan Ermilov.Fn ng_source_intr . 33176648c1fSRuslan ErmilovAlso useful is the packet count returned by 33276648c1fSRuslan Ermilov.Fn ng_source_send . 33376648c1fSRuslan ErmilovDo not try to report such things from within 33476648c1fSRuslan Ermilov.Fn ng_source_intr , 33576648c1fSRuslan Ermilovinstead include the values in 33676648c1fSRuslan Ermilov.Va sc->stats . 337585ff168SJulian Elischer.Sh SEE ALSO 338585ff168SJulian Elischer.Xr netgraph 4 , 339585ff168SJulian Elischer.Xr ng_echo 4 , 340585ff168SJulian Elischer.Xr ng_hole 4 , 341585ff168SJulian Elischer.Xr ng_tee 4 , 34276648c1fSRuslan Ermilov.Xr ngctl 8 , 343585ff168SJulian Elischer.Xr nghook 8 344585ff168SJulian Elischer.Sh HISTORY 345585ff168SJulian ElischerThe 346585ff168SJulian Elischer.Nm 347585ff168SJulian Elischernode type was implemented in 348585ff168SJulian Elischer.Fx 4.8 . 349585ff168SJulian Elischer.Sh AUTHORS 350585ff168SJulian Elischer.An Dave Chapeskie Aq dchapeskie@SANDVINE.com 351