MoonGen
 All Files Functions Variables Pages
ethernet.lua File Reference

Ethernet protocol utility. More...

Go to the source code of this file.

Functions

function macAddr get ()
 Retrieve the MAC address. More...
 
function macAddr set (addr)
 Set the MAC address. More...
 
function macAddr setString (mac)
 Set the MAC address. More...
 
function macAddr __eq (lhs, rhs)
 Test equality of two MAC addresses. More...
 
function macAddr getString ()
 Retrieve the string representation of a MAC address. More...
 
function etherHeader setDst (addr)
 Set the destination MAC address. More...
 
function etherHeader getDst (addr)
 Retrieve the destination MAC address. More...
 
function etherHeader setSrc (addr)
 Set the source MAC address. More...
 
function etherHeader getSrc (addr)
 Retrieve the source MAC address. More...
 
function etherHeader setDstString (str)
 Set the destination MAC address. More...
 
function etherHeader getDstString ()
 Retrieve the destination MAC address. More...
 
function etherHeader setSrcString (str)
 Set the source MAC address. More...
 
function etherHeader getSrcString ()
 Retrieve the source MAC address. More...
 
function etherHeader setType (int)
 Set the EtherType. More...
 
function etherHeader getType ()
 Retrieve the EtherType. More...
 
function etherHeader getTypeString ()
 Retrieve the ether type. More...
 
function etherHeader fill (args, pre)
 Set all members of the ethernet header. More...
 
function etherHeader get (pre)
 Retrieve the values of all members. More...
 
function etherHeader resolveNextHeader ()
 Resolve which header comes after this one (in a packet). More...
 
function etherHeader setDefaultNamedArgs (pre, namedArgs, nextHeader, accumulatedLength)
 Change the default values for namedArguments (for fill/get). More...
 

Variables

local eth = {}
 Ethernet protocol constants.
 
eth TYPE_IP = 0x0800
 EtherType for IP4.
 
eth TYPE_ARP = 0x0806
 EtherType for Arp.
 
eth TYPE_IP6 = 0x86dd
 EtherType for IP6.
 
eth TYPE_PTP = 0x88f7
 EtherType for Ptp.
 
eth BROADCAST = "ff:ff:ff:ff:ff:ff"
 Ethernet broadcast address.
 
local macAddr = {}
 Module for mac_address struct (see headers.lua).
 
local etherHeader = {}
 Module for ethernet_header struct (see headers.lua).
 
pkt getEthernetPacket = packetCreate("eth")
 Cast the packet to an ethernet packet.
 
pkt getEthPacket = pkt.getEthernetPacket
 Cast the packet to an ethernet packet (alias for pkt.getEthernetPacket)
 

Detailed Description

Ethernet protocol utility.

Utility functions for the mac_address and ethernet_header structs defined in headers.lua .
Includes:

  • Ethernet constants
  • Mac address utility
  • Ethernet header utility
  • Definition of ethernet packets

Definition in file ethernet.lua.

Function Documentation

function macAddr __eq ( lhs  ,
rhs   
)

Test equality of two MAC addresses.

Parameters
lhsAddress in 'struct mac_address' format.
rhsAddress in 'struct mac_address' format.
Returns
true if equal, false otherwise.
function etherHeader fill ( args  ,
pre   
)

Set all members of the ethernet 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.
Exemplary invocations:

fill() --- only default values
fill{ ethSrc="12:23:34:45:56:67", ethType=0x137 } --- default value for ethDst; ethSrc and ethType user-specified
Parameters
argsTable of named arguments. Available arguments: Src, Dst, Type
prePrefix for namedArgs. Default 'eth'.
function macAddr get ( )

Retrieve the MAC address.

Returns
Address in 'struct mac_address' format.
function etherHeader get ( pre  )

Retrieve the values of all members.

Parameters
prePrefix for namedArgs. Default 'eth'.
Returns
Table of named arguments. For a list of arguments see "See Also".
See Also
etherHeader:fill
function etherHeader getDst ( addr  )

Retrieve the destination MAC address.

Returns
Address in 'struct mac_address' format.
function etherHeader getDstString ( )

Retrieve the destination MAC address.

Returns
Address in string format.
function etherHeader getSrc ( addr  )

Retrieve the source MAC address.

Returns
Address in 'struct mac_address' format.
function etherHeader getSrcString ( )

Retrieve the source MAC address.

Returns
Address in string format.
function macAddr getString ( )

Retrieve the string representation of a MAC address.

Retrieve the values of all members.

Returns
Address in string format.
Values in string format.
function etherHeader getType ( )

Retrieve the EtherType.

Returns
EtherType as 16 bit integer.
function etherHeader getTypeString ( )

Retrieve the ether type.

Returns
EtherType as string.
function etherHeader 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. 'eth', 'ip4', nil)
function macAddr set ( addr  )

Set the MAC address.

Parameters
addrAddress in 'struct mac_address' format.
function etherHeader 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. 'eth'
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
etherHeader:fill
function etherHeader setDst ( addr  )

Set the destination MAC address.

Parameters
addrAddress in 'struct mac_address' format.
function etherHeader setDstString ( str  )

Set the destination MAC address.

Parameters
strAddress in string format.
function etherHeader setSrc ( addr  )

Set the source MAC address.

Parameters
addrAddress in 'struct mac_address' format.
function etherHeader setSrcString ( str  )

Set the source MAC address.

Parameters
strAddress in string format.
function macAddr setString ( mac  )

Set the MAC address.

Parameters
macAddress in string format.
function etherHeader setType ( int  )

Set the EtherType.

Parameters
intEtherType as 16 bit integer.