MoonGen
 All Files Functions Variables Pages
udp.lua File Reference

User datagram protocol (UDP) utility. More...

Go to the source code of this file.

Functions

function udpHeader setSrcPort (int)
 Set the source port. More...
 
function udpHeader getSrcPort ()
 Retrieve the UDP source port. More...
 
function udpHeader getSrcPortString ()
 Retrieve the UDP source port. More...
 
function udpHeader setDstPort (int)
 Set the destination port. More...
 
function udpHeader getDstPort ()
 Retrieve the UDP destination port. More...
 
function udpHeader getDstPortString ()
 Retrieve the UDP destination port. More...
 
function udpHeader setLength (int)
 Set the length. More...
 
function udpHeader getLength ()
 Retrieve the length. More...
 
function udpHeader getLengthString ()
 Retrieve the length. More...
 
function udpHeader setChecksum (int)
 Set the checksum. More...
 
function udpHeader calculateChecksum (len)
 Calculate the checksum. More...
 
function udpHeader getChecksum ()
 Retrieve the checksum. More...
 
function udpHeader getChecksumString ()
 Retrieve the checksum. More...
 
function udpHeader fill (args, pre)
 Set all members of the udp header. More...
 
function udpHeader get (pre)
 Retrieve the values of all members. More...
 
function udpHeader getString ()
 Retrieve the values of all members. More...
 
function udpHeader resolveNextHeader ()
 Resolve which header comes after this one (in a packet). More...
 
function udpHeader setDefaultNamedArgs (pre, namedArgs, nextHeader, accumulatedLength)
 Change the default values for namedArguments (for fill/get). More...
 

Variables

local udp = {}
 Udp protocol constants.
 
udp PORT_PTP_EVENTS = 319
 Well known port for Ptp event message.
 
udp PORT_PTP_GENERAL_MESSAGES = 320
 Well known port for Ptp general message.
 
local udpHeader = {}
 Module for udp_header struct (see headers.lua).
 
pkt getUdp4Packet = packetCreate("eth", "ip4", "udp")
 Cast the packet to an Udp (IP4) packet.
 
pkt getUdp6Packet = packetCreate("eth", "ip6", "udp")
 Cast the packet to an Udp (IP6) packet.
 
pkt getUdpPacket = function(self, ip4)
 Cast the packet to an Udp packet, either using IP4 (nil/true) or IP6 (false), depending on the passed boolean.
 

Detailed Description

User datagram protocol (UDP) utility.

Utility functions for udp_header struct defined in headers.lua .
Includes:

  • Udp constants
  • Udp header utility
  • Definition of Udp packets

Definition in file udp.lua.

Function Documentation

function udpHeader calculateChecksum ( len  )

Calculate the checksum.

Todo:
FIXME NYI
function udpHeader fill ( args  ,
pre   
)

Set all members of the udp header.

Per default, all members are set to default values specified in the respective set function. Optional named arguments can be used to set a member to a user-provided value.

Parameters
argsTable of named arguments. Available arguments: udpSrc, udpDst, udpLength, udpChecksum
preprefix for namedArgs. Default 'udp'.
fill() --- only default values
fill{ udpSrc=44566, ip6Length=101 } --- all members are set to default values with the exception of udpSrc
function udpHeader get ( pre  )

Retrieve the values of all members.

Parameters
preprefix for namedArgs. Default 'udp'.
Returns
Table of named arguments. For a list of arguments see "See also".
See Also
udpHeader:fill
function udpHeader getChecksum ( )

Retrieve the checksum.

Returns
Checksum as 16 bit integer.
function udpHeader getChecksumString ( )

Retrieve the checksum.

Returns
Checksum as string.
function udpHeader getDstPort ( )

Retrieve the UDP destination port.

Returns
Port as 16 bit integer.
function udpHeader getDstPortString ( )

Retrieve the UDP destination port.

Returns
Port as string.
function udpHeader getLength ( )

Retrieve the length.

Returns
Length as 16 bit integer.
function udpHeader getLengthString ( )

Retrieve the length.

Returns
Length as string.
function udpHeader getSrcPort ( )

Retrieve the UDP source port.

Returns
Port as 16 bit integer.
function udpHeader getSrcPortString ( )

Retrieve the UDP source port.

Returns
Port as string.
function udpHeader getString ( )

Retrieve the values of all members.

Returns
Values in string format.
function udpHeader resolveNextHeader ( )

Resolve which header comes after this one (in a packet).

For instance: in tcp/udp based on the ports. This function must exist and is only used when get/dump is executed on an unknown (mbuf not yet casted to e.g. tcpv6 packet) packet (mbuf)

Returns
String next header (e.g. 'udp', 'icmp', nil)
function udpHeader setChecksum ( int  )

Set the checksum.

Parameters
intChecksum of the udp header as 16 bit integer.
function udpHeader setDefaultNamedArgs ( pre  ,
namedArgs  ,
nextHeader  ,
accumulatedLength   
)

Change the default values for namedArguments (for fill/get).

This can be used to for instance calculate a length value based on the total packet length. See proto/ip4.setDefaultNamedArgs as an example. This function must exist and is only used by packet.fill.

Parameters
preThe prefix used for the namedArgs, e.g. 'udp'
namedArgsTable of named arguments (see See Also)
nextHeaderThe header following after this header in a packet
accumulatedLengthThe so far accumulated length for previous headers in a packet
Returns
Table of namedArgs
See Also
ip4Header:fill
function udpHeader setDstPort ( int  )

Set the destination port.

Parameters
intDestination port of the udp header as 16 bit integer.
function udpHeader setLength ( int  )

Set the length.

Parameters
intLength of the udp header plus payload (excluding l2 and l3). 16 bit integer.
function udpHeader setSrcPort ( int  )

Set the source port.

Parameters
intSource port of the udp header as 16 bit integer.