MoonGen
 All Files Functions Variables Pages
utils.lua File Reference

Defines general utility functions. More...

Go to the source code of this file.

Functions

function printf (str,...)
 Print a formatted string. More...
 
function errorf (str,...)
 Print a formatted error string. More...
 
function mapVarArg (f,...)
 TODO. More...
 
function map (t, f)
 TODO. More...
 
function tostringall (...)
 TODO. More...
 
function tonumberall (...)
 TODO. More...
 
function toCsv (...)
 TODO. More...
 
function printCsv (...)
 TODO. More...
 
function poissonDelay (average)
 Get the time to wait (in byte-times) for the next packet based on a poisson process. More...
 
function rateToByteDelay (rate, size)
 TODO. More...
 
function bswap16 (n)
 Byte swap for 16 bit integers. More...
 
function checksum (data, len)
 Calculate a 16 bit checksum. More...
 
function parseMacAddress (mac)
 Parse a string to a MAC address. More...
 
function parseIPAddress (ip)
 Parse a string to an IP address. More...
 
function parseIP4Address (ip)
 Parse a string to an IPv4 address. More...
 
function parseIP6Address (ip)
 Parse a string to an IPv6 address. More...
 
function getTimeMicros ()
 Retrieve the system time with microseconds accuracy. More...
 
function dumpHex (data, bytes)
 Print a hex dump of cdata. More...
 
function mergeTables (...)
 Merge tables. More...
 
function range (max, start,...)
 Return all integerss in the range [start, max]. More...
 
function incAndWrap (val, max)
 Increment a wrapping counter, i.e. More...
 

Detailed Description

Defines general utility functions.

Todo:

TODO docu

local unpackers ... crashes lua2dox parser

Definition in file utils.lua.

Function Documentation

function bswap16 ( n  )

Byte swap for 16 bit integers.

Parameters
n16 bit integer
Returns
Byte swapped integer
function checksum ( data  ,
len   
)

Calculate a 16 bit checksum.

Parameters
datacdata to calculate the checksum for.
lenNumber of bytes to calculate the checksum for.
Returns
16 bit integer
function dumpHex ( data  ,
bytes   
)

Print a hex dump of cdata.

Parameters
dataThe cdata to be dumped.
bytesNumber of bytes to dump.
function errorf ( str  ,
  ... 
)

Print a formatted error string.

Todo:
docu
Parameters
str
args
Examples:
l2-poisson-load-latency.lua, l3-tcp-syn-flood.lua, and timestamps.lua.
function getTimeMicros ( )

Retrieve the system time with microseconds accuracy.

Todo:
use some C function to get microseconds.
Returns
System time in hh:mm:ss.uuuuuu format.
function incAndWrap ( val  ,
max   
)

Increment a wrapping counter, i.e.

(val + 1) % max This function is optimized to generate branchless code and faster than a naive modulo-based implementation.

Note
: all attempts to wrap this in a nice and simple class have failed (~30% performance impact).
Parameters
valCurrent value (number)
maxMaximum allowed value of val (number)
Returns
Incremented and wrapped number
Examples:
l3-tcp-syn-flood.lua.
function map ( ,
 
)

TODO.

Todo:
docu
Parameters
t
f
Returns
function mapVarArg ( ,
  ... 
)

TODO.

Todo:
docu
Parameters
f
args
Returns
function mergeTables (   ...)

Merge tables.

Parameters
argsArbitrary amount of tables to get merged.
function parseIP4Address ( ip  )

Parse a string to an IPv4 address.

Parameters
ipaddress in string format
Returns
address in uint32 format or nil if invalid address
function parseIP6Address ( ip  )

Parse a string to an IPv6 address.

Parameters
ipaddress in string format
Returns
address in ip6_address format or nil if invalid address
function parseIPAddress ( ip  )

Parse a string to an IP address.

Returns
address ip address in ip4_address or ip6_address format or nil if invalid address
boolean true if IPv4 address, false otherwise
Examples:
l3-tcp-syn-flood.lua, and quality-of-service-test.lua.
function parseMacAddress ( mac  )

Parse a string to a MAC address.

Parameters
macaddress in string format
Returns
address in mac_address format or nil if invalid address
function poissonDelay ( average  )

Get the time to wait (in byte-times) for the next packet based on a poisson process.

Parameters
averagethe average wait time between two packets
Returns
the number of byte-times to wait to achieve the given average wait-time
Examples:
l2-poisson-load-latency.lua.
function printCsv (   ...)

TODO.

Todo:
docu
Parameters
args
Returns
function printf ( str  ,
  ... 
)

Print a formatted string.

Todo:
docu
Parameters
str
args
return
Examples:
l3-tcp-syn-flood.lua, and quality-of-service-test.lua.
function range ( max  ,
start  ,
  ... 
)

Return all integerss in the range [start, max].

Parameters
maxupper bound
startlower bound, default = 1
function rateToByteDelay ( rate  ,
size   
)

TODO.

Todo:
docu
Parameters
rate
size
Returns
function toCsv (   ...)

TODO.

Todo:
docu
Parameters
args
Returns
function tonumberall (   ...)

TODO.

Todo:
docu
Parameters
args
Returns
Examples:
l2-poisson-load-latency.lua.
function tostringall (   ...)

TODO.

Todo:
docu
Parameters
args
Returns