Defines general utility functions.
More...
Go to the source code of this file.
|
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...
|
|
Defines general utility functions.
- Todo:
TODO docu
local unpackers ... crashes lua2dox parser
Definition in file utils.lua.
Byte swap for 16 bit integers.
- Parameters
-
- Returns
- Byte swapped integer
function checksum |
( |
data |
, |
|
|
len |
|
|
) |
| |
Calculate a 16 bit checksum.
- Parameters
-
data | cdata to calculate the checksum for. |
len | Number of bytes to calculate the checksum for. |
- Returns
- 16 bit integer
function dumpHex |
( |
data |
, |
|
|
bytes |
|
|
) |
| |
Print a hex dump of cdata.
- Parameters
-
data | The cdata to be dumped. |
bytes | Number of bytes to dump. |
function errorf |
( |
str |
, |
|
|
|
... |
|
) |
| |
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
-
val | Current value (number) |
max | Maximum allowed value of val (number) |
- Returns
- Incremented and wrapped number
- Examples:
- l3-tcp-syn-flood.lua.
TODO.
- Todo:
- docu
- Parameters
-
- Returns
function mapVarArg |
( |
f |
, |
|
|
|
... |
|
) |
| |
TODO.
- Todo:
- docu
- Parameters
-
- Returns
function mergeTables |
( |
|
... | ) |
|
Merge tables.
- Parameters
-
args | Arbitrary amount of tables to get merged. |
function parseIP4Address |
( |
ip |
| ) |
|
Parse a string to an IPv4 address.
- Parameters
-
ip | address in string format |
- Returns
- address in uint32 format or nil if invalid address
function parseIP6Address |
( |
ip |
| ) |
|
Parse a string to an IPv6 address.
- Parameters
-
ip | address in string format |
- Returns
- address in ip6_address format or nil if invalid address
function parseIPAddress |
( |
ip |
| ) |
|
function parseMacAddress |
( |
mac |
| ) |
|
Parse a string to a MAC address.
- Parameters
-
mac | address 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
-
average | the 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.
TODO.
- Todo:
- docu
- Parameters
-
- Returns
function printf |
( |
str |
, |
|
|
|
... |
|
) |
| |
function range |
( |
max |
, |
|
|
start |
, |
|
|
|
... |
|
) |
| |
Return all integerss in the range [start, max].
- Parameters
-
max | upper bound |
start | lower bound, default = 1 |
function rateToByteDelay |
( |
rate |
, |
|
|
size |
|
|
) |
| |
TODO.
- Todo:
- docu
- Parameters
-
- Returns
TODO.
- Todo:
- docu
- Parameters
-
- Returns
function tonumberall |
( |
|
... | ) |
|
function tostringall |
( |
|
... | ) |
|
TODO.
- Todo:
- docu
- Parameters
-
- Returns