The
source
node acts as a source of packets according to the parameters set up
using control messages and input packets.
The
node type is used primarily for testing and benchmarking.
HOOKS
The
source
node has two hooks:
input
and
output
The
output
hook must remain connected, its disconnection will shutdown the node.
OPERATION
The operation of the node is as follows.
Packets received on the
input
hook are queued internally.
When
output
hook is connected,
node assumes that its neighbour node is of
ng_ether4
node type.
The neighbour is queried for its interface name.
The
node then uses queue of the interface for its evil purposes.
The
node also disables
autosrc
option on neighbour
ng_ether4
node.
If interface name cannot be obtained automatically, it should
be configured explicitly with the
NGM_SOURCE_SETIFACE
control message, and
autosrc
should be turned off on
ng_ether4
node manually.
Once interface is configured, upon receipt of a
NGM_SOURCE_START
control message the node starts sending
the previously queued packets out the
output
hook on every clock tick as fast
as the connected interface will take them.
While active, on every clock tick the node checks the available space
in the interface queue and sends that many packets out its
output
hook.
Once the number of packets indicated in the start message has been
sent, or upon receipt of a
NGM_SOURCE_STOP
message, the node stops sending data.
CONTROL MESSAGES
This node type supports the generic control messages as well as the following,
which must be sent with the
NGM_SOURCE_COOKIE
attached.
NGM_SOURCE_GET_STATS (getstats
)
Returns a structure containing the following fields:
outOctets
The number of octets/bytes sent out the
output
hook.
outFrames
The number of frames/packets sent out the
output
hook.
queueOctets
The number of octets queued from the
input
hook.
queueFrames
The number of frames queued from the
input
hook.
startTime
The time the last start message was received.
endTime
The time the last end message was received or
the output packet count was reached.
elapsedTime
Either
endTime - startTime
or current time
-
startTime
NGM_SOURCE_CLR_STATS (clrstats
)
Clears and resets the statistics returned by
getstats
(except
queueOctets
and
queueFrames )
NGM_SOURCE_GETCLR_STATS (getclrstats
)
As
getstats
but clears the statistics at the same time.
NGM_SOURCE_START (start
)
This message requires a single
Vt uint64_t
parameter which is the number of packets to
send before stopping.
Node starts sending the queued packets out the
output
hook.
The
output
hook must be connected and node must have
interface configured.
NGM_SOURCE_STOP (stop
)
Stops the node if it is active.
NGM_SOURCE_CLR_DATA (clrdata
)
Clears the packets queued from the
input
hook.
NGM_SOURCE_SETIFACE (setiface
)
This message requires the name of the interface
to be configured as an argument.
NGM_SOURCE_SETPPS (setpps
)
This message requires a single
Vt uint32_t
parameter which puts upper limit on the amount of packets
sent per second.
NGM_SOURCE_SET_TIMESTAMP (settimestamp
)
This message specifies that a timestamp (in the format of a
Vt struct timeval )
should be inserted in the transmitted packets.
This message requires a structure containing the following fields:
offset
The offset from the beginning of the packet at which the timestamp is to be
inserted.
flags
Set to 1 to enable the timestamp.
NGM_SOURCE_GET_TIMESTAMP (gettimestamp
)
Returns the current timestamp settings in the form of the structure described
above.
NGM_SOURCE_SET_COUNTER (setcounter
)
This message specifies that a counter should be embedded in transmitted
packets.
Up to four counters may be independently configured.
This message requires a structure containing the following fields:
offset
The offset from the beginning of the packet at which the counter is to be
inserted.
flags
Set to 1 to enable the counter.
width
The byte width of the counter.
It may be 1, 2, or 4.
next_val
The value for the next insertion of the counter.
min_val
The minimum value to be used by the counter.
max_val
The maximum value to be used by the counter.
increment
The value to be added to the counter after each insertion.
It may be negative.
index
The counter to be configured, from 0 to 3.
NGM_SOURCE_GET_COUNTER (getcounter
)
This message requires a single
Vt uint8_t
parameter which specifies the counter to query.
Returns the current counter settings in the form of the structure described
above.
SHUTDOWN
This node shuts down upon receipt of a
NGM_SHUTDOWN
control message, when all hooks have been disconnected, or when the
output
hook has been disconnected.
EXAMPLES
Attach the node to an
ng_ether4
node for an interface.
If
ng_ether
is
not already loaded you will need to do so.
For example, these commands
load the
ng_ether
module and attach the
output
hook of a new
source
node to
orphans
hook of the
bge0:ng_ether
node.
At this point the new node can be referred to as
``bge0:orphans
''
The
node can be given its own name like this:
"ngctl name bge0:orphans src0"
After which it can be referred to as
``src0:
''
Once created, packets can be sent to the node as raw binary data.
Each packet must be delivered in a separate netgraph message.
The following example uses a short Perl script to convert the hex
representation of an ICMP packet to binary and deliver it to the
source
node's
input
hook via
nghook(8):
The times are from
Vt struct timeval Ns s ,
the
tv_sec
field is seconds since
the Epoch and can be converted into a date string via TCL's [clock
format] or via the
date(1)
command: