MoonGen
 All Files Functions Variables Pages
ip6.lua File Reference

Internet protocol (v6) utility. More...

Go to the source code of this file.

Functions

function ip6Addr get ()
 Retrieve the IPv6 address. More...
 
function ip6Addr set (addr)
 Set the IPv6 address. More...
 
function ip6Addr setString (ip)
 Set the IPv6 address. More...
 
function ip6Addr __eq (lhs, rhs)
 Test equality of two IPv6 addresses. More...
 
function ip6Addr __add (lhs, rhs)
 Add a number to an IPv6 address. More...
 
function ip6Addr add (val)
 Add a number to an IPv6 address in-place. More...
 
function ip6Addr __sub (val)
 Subtract a number from an IPv6 address. More...
 
function ip6Addr getString (doByteSwap)
 Retrieve the string representation of an IPv6 address. More...
 
function ip6Header setVersion (int)
 Set the version. More...
 
function ip6Header getVersion ()
 Retrieve the version. More...
 
function ip6Header getVersionString ()
 Retrieve the version. More...
 
function ip6Header setTrafficClass (int)
 Set the traffic class. More...
 
function ip6Header getTrafficClass ()
 Retrieve the traffic class. More...
 
function ip6Header getTrafficClassString ()
 Retrieve the traffic class. More...
 
function ip6Header setFlowLabel (int)
 Set the flow label. More...
 
function ip6Header getFlowLabel ()
 Retrieve the flow label. More...
 
function ip6Header getFlowLabelString ()
 Retrieve the flow label. More...
 
function ip6Header setLength (int)
 Set the payload length. More...
 
function ip6Header getLength ()
 Retrieve the length. More...
 
function ip6Header getLengthString ()
 Retrieve the length. More...
 
function ip6Header setNextHeader (int)
 Set the next header. More...
 
function ip6Header getNextHeader ()
 Retrieve the next header. More...
 
function ip6Header getNextHeaderString ()
 Retrieve the next header. More...
 
function ip6Header setTTL (int)
 Set the time-to-live (TTL). More...
 
function ip6Header getTTL ()
 Retrieve the time-to-live. More...
 
function ip6Header getTTLString ()
 Retrieve the time-to-live. More...
 
function ip6Header setDst (addr)
 Set the destination address. More...
 
function ip6Header getDst ()
 Retrieve the IP6 destination address. More...
 
function ip6Header setSrc (addr)
 Set the source address. More...
 
function ip6Header getSrc ()
 Retrieve the IP6 source address. More...
 
function ip6Header setDstString (str)
 Set the destination address. More...
 
function ip6Header getDstString ()
 Retrieve the IP6 destination address. More...
 
function ip6Header setSrcString (str)
 Set the source address. More...
 
function ip6Header getSrcString ()
 Retrieve the IP6 source address. More...
 
function ip6Header fill (args, pre)
 Set all members of the ip6 header. More...
 
function ip6Header get (pre)
 Retrieve the values of all members. More...
 
function ip6Header getString ()
 Retrieve the values of all members. More...
 
function ip6Header resolveNextHeader ()
 Resolve which header comes after this one (in a packet). More...
 
function ip6Header setDefaultNamedArgs (pre, namedArgs, nextHeader, accumulatedLength)
 Change the default values for namedArguments (for fill/get). More...
 

Variables

local ip6 = {}
 IP6 protocol constants.
 
ip6 PROTO_TCP = 0x06
 NextHeader field value for Tcp.
 
ip6 PROTO_UDP = 0x11
 NextHeader field value for Udp.
 
ip6 PROTO_ICMP = 0x3a
 NextHeader field value for Icmp.
 
local ip6Addr = {}
 Module for ip6_address struct (see headers.lua).
 
local ip6Header = {}
 Module for ip6_header struct (see headers.lua).
 
pkt getIP6Packet = packetCreate("eth", "ip6")
 Cast the packet to an IP6 packet.
 

Detailed Description

Internet protocol (v6) utility.

Utility functions for the ip6_address and ip6_header structs defined in headers.lua .
Includes:

  • IP6 constants
  • IP6 address utility
  • IP6 header utility
  • Definition of IP6 packets

Definition in file ip6.lua.

Function Documentation

function ip6Addr __add ( lhs  ,
rhs   
)

Add a number to an IPv6 address.

Max. 64bit, commutative.

Parameters
lhsAddress in 'union ip6_address' format.
rhsNumber to add (64 bit integer).
Returns
Resulting address in 'union ip6_address' format.
function ip6Addr __eq ( lhs  ,
rhs   
)

Test equality of two IPv6 addresses.

Parameters
lhsAddress in 'union ip6_address' format.
rhsAddress in 'union ip6_address' format.
Returns
true if equal, false otherwise.
function ip6Addr __sub ( val  )

Subtract a number from an IPv6 address.

Max. 64 bit.

Parameters
valNumber to substract (64 bit integer).
Returns
Resulting address in 'union ip6_address' format.
function ip6Addr add ( val  )

Add a number to an IPv6 address in-place.

Max 64 bit.

Parameters
valNumber to add (64 bit integer).
function ip6Header fill ( args  ,
pre   
)

Set all members of the ip6 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: ip6Version, ip6TrafficClass, ip6FlowLabel, ip6Length, ip6NextHeader, ip6TTL, ip6Src, ip6Dst
preprefix for namedArgs. Default 'ip6'.
fill() --- only default values
fill{ ip6Src="f880::ab", ip6TTL=101 } --- all members are set to default values with the exception of ip6Src and ip6TTL
function ip6Addr get ( )

Retrieve the IPv6 address.

Returns
Address in 'union ip6_address' format.
function ip6Header get ( pre  )

Retrieve the values of all members.

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

Retrieve the IP6 destination address.

Returns
Address in 'union ip6_address' format.
function ip6Header getDstString ( )

Retrieve the IP6 destination address.

Returns
Address in string format.
function ip6Header getFlowLabel ( )

Retrieve the flow label.

Returns
Flow label as 20 bit integer.
function ip6Header getFlowLabelString ( )

Retrieve the flow label.

Returns
Flow label as string.
function ip6Header getLength ( )

Retrieve the length.

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

Retrieve the length.

Returns
Length as string.
function ip6Header getNextHeader ( )

Retrieve the next header.

Returns
Next header as 8 bit integer.
function ip6Header getNextHeaderString ( )

Retrieve the next header.

Returns
Next header as string.
function ip6Header getSrc ( )

Retrieve the IP6 source address.

Returns
Address in 'union ip6_address' format.
function ip6Header getSrcString ( )

Retrieve the IP6 source address.

Returns
Address in source format.
function ip6Addr getString ( doByteSwap  )

Retrieve the string representation of an IPv6 address.

Assumes 'union ip6_address' is in network byteorder.

Parameters
doByteSwapOptional change the byteorder of the ip6 address before returning the string representation.
Returns
Address in string format.
function ip6Header getString ( )

Retrieve the values of all members.

Returns
Values in string format.
function ip6Header getTrafficClass ( )

Retrieve the traffic class.

Returns
Traffic class as 8 bit integer.
function ip6Header getTrafficClassString ( )

Retrieve the traffic class.

Returns
Traffic class as string.
function ip6Header getTTL ( )

Retrieve the time-to-live.

Returns
TTL as 8 bit integer.
function ip6Header getTTLString ( )

Retrieve the time-to-live.

Returns
TTL as string.
function ip6Header getVersion ( )

Retrieve the version.

Returns
Version as 4 bit integer.
function ip6Header getVersionString ( )

Retrieve the version.

Returns
Version as string.
function ip6Header 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 ip6Addr set ( addr  )

Set the IPv6 address.

Parameters
addrAddress in 'union ip6_address' format.
function ip6Header 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. 'ip6'
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
ip6Header:fill
function ip6Header setDst ( addr  )

Set the destination address.

Parameters
addrAddress in 'union ip6_address' format.
function ip6Header setDstString ( str  )

Set the destination address.

Parameters
strAddress in string format.
function ip6Header setFlowLabel ( int  )

Set the flow label.

Parameters
intFlow label of the ip6 header as 20 bit integer.
function ip6Header setLength ( int  )

Set the payload length.

Parameters
intLength of the ip6 header payload (hence, excluding l2 and l3 headers). 16 bit integer.
function ip6Header setNextHeader ( int  )

Set the next header.

Parameters
intNext header of the ip6 header as 8 bit integer.
function ip6Header setSrc ( addr  )

Set the source address.

Parameters
addrAddress in 'union ip6_address' format.
function ip6Header setSrcString ( str  )

Set the source address.

Parameters
strAddress in string format.
function ip6Addr setString ( ip  )

Set the IPv6 address.

Parameters
ipAddress in string format.
function ip6Header setTrafficClass ( int  )

Set the traffic class.

Parameters
intTraffic class of the ip6 header as 8 bit integer.
function ip6Header setTTL ( int  )

Set the time-to-live (TTL).

Parameters
intTTL of the ip6 header as 8 bit integer.
function ip6Header setVersion ( int  )

Set the version.

Parameters
intIP6 header version as 4 bit integer. Should always be '6'.