MoonGen
|
Utility functions for packets (rte_mbuf). More...
Go to the source code of this file.
Functions | |
function pkt | getTimestamp () |
Retrieve the time stamp information. More... | |
function pkt | hasTimestamp () |
Check if the PKT_RX_IEEE1588_TMST flag is set. More... | |
function pkt | setVlan (vlan, pcp, cfi) |
Offload VLAN tagging to the NIC for this packet. | |
function pkt | getVlan () |
Get the VLAN associated with a received packet. | |
function pkt | setDelay (delay) |
Set the time to wait before the packet is sent for software rate-controlled send methods. | |
function pkt | setRate (rate) |
function pkt | setSize (size) |
function pkt | get () |
Returns the packet data cast to the best fitting packet struct. More... | |
function pkt | dump (bytes) |
Dumps the packet data cast to the best fitting packet struct. More... | |
function pkt | offloadIPSec (idx, sec_type, esp_mode) |
Use IPsec offloading. More... | |
function pkt | setESPTrailerLength (len) |
Set the ESP trailer length. More... | |
function pkt | offloadIPChecksum (ipv4, l2_len, l3_len) |
Instruct the NIC to calculate the IP checksum for this packet. More... | |
function pkt | offloadUdpChecksum (ipv4, l2_len, l3_len) |
Instruct the NIC to calculate the IP and UDP checksum for this packet. More... | |
function pkt | offloadTcpChecksum (ipv4, l2_len, l3_len) |
Instruct the NIC to calculate the IP and TCP checksum for this packet. More... | |
function pkt | enableTimestamps () |
function | packetCreate (...) |
Create struct and functions for a new packet. More... | |
function | getHeaderMember (v) |
Get the name of the header and the name of the respective member of a packet. More... | |
function | packetGetHeaders (self) |
Get all headers of a packet as list. More... | |
function | packetGetHeader (self, h) |
Get the specified header of a packet (e.g. More... | |
function | packetDump (self, bytes) |
Print a hex dump of a packet. More... | |
function | packetFill (self, namedArgs) |
Set all members of all headers. More... | |
function | packetGet (self) |
Retrieve the values of all members as list of named arguments. More... | |
function | packetResolveLastHeader (self) |
Try to find out what the next header in the payload of this packet is. More... | |
function | packetSetLength (args) |
Set length for all headers. More... | |
function | packetCalculateChecksums (args) |
Calculate all checksums manually (not offloading them). More... | |
function | packetMakeStruct (...) |
Creates a packet struct (cdata) consisting of different headers. More... | |
Variables | |
local | pkt = {} |
Module for packets (rte_mbuf) | |
pkt | packetStructs = {} |
Table that contains the names and args of all created packet structs. | |
Utility functions for packets (rte_mbuf).
Includes:
Definition in file packet.lua.
function pkt dump | ( | bytes | ) |
Dumps the packet data cast to the best fitting packet struct.
bytes | number of bytes to dump, optional |
function pkt get | ( | ) |
Returns the packet data cast to the best fitting packet struct.
Starting with ethernet header.
function getHeaderMember | ( | v | ) |
Get the name of the header and the name of the respective member of a packet.
v | Either the name of the header (then the member has the same name), or a table { header, member } |
function pkt getTimestamp | ( | ) |
Retrieve the time stamp information.
function pkt hasTimestamp | ( | ) |
Check if the PKT_RX_IEEE1588_TMST flag is set.
Turns out that this flag is pretty pointless, it does not indicate if the packet was actually timestamped, just that it came from a queue/filter with timestamping enabled. You probably want to use device:hasTimestamp() and check the sequence number.
function pkt offloadIPChecksum | ( | ipv4 | , |
l2_len | , | ||
l3_len | |||
) |
Instruct the NIC to calculate the IP checksum for this packet.
ipv4 | Boolean to decide whether the packet uses IPv4 (set to nil/true) or IPv6 (set to anything else). In case it is an IPv6 packet, do nothing (the header has no checksum). |
l2_len | Length of the layer 2 header in bytes (default 14 bytes for ethernet). |
l3_len | Length of the layer 3 header in bytes (default 20 bytes for IPv4). |
function pkt offloadIPSec | ( | idx | , |
sec_type | , | ||
esp_mode | |||
) |
Use IPsec offloading.
idx | SA_IDX to use |
sec_type | IPSec type to use ("esp"/"ah") |
esp_mode | ESP mode to use encrypt(1) or authenticate(0) |
function pkt offloadTcpChecksum | ( | ipv4 | , |
l2_len | , | ||
l3_len | |||
) |
Instruct the NIC to calculate the IP and TCP checksum for this packet.
ipv4 | Boolean to decide whether the packet uses IPv4 (set to nil/true) or IPv6 (set to anything else). |
l2_len | Length of the layer 2 header in bytes (default 14 bytes for ethernet). |
l3_len | Length of the layer 3 header in bytes (default 20 bytes for IPv4, 40 bytes for IPv6). |
function pkt offloadUdpChecksum | ( | ipv4 | , |
l2_len | , | ||
l3_len | |||
) |
Instruct the NIC to calculate the IP and UDP checksum for this packet.
ipv4 | Boolean to decide whether the packet uses IPv4 (set to nil/true) or IPv6 (set to anything else). |
l2_len | Length of the layer 2 header in bytes (default 14 bytes for ethernet). |
l3_len | Length of the layer 3 header in bytes (default 20 bytes for IPv4, 40 bytes for IPv6). |
function packetCalculateChecksums | ( | args | ) |
Calculate all checksums manually (not offloading them).
There also exist functions to calculate the checksum of only one header. Naming convention: pkt:calculate<member>Checksum() (for all existing packets member = {Ip, Tcp, Udp, Icmp})
function packetCreate | ( | ... | ) |
Create struct and functions for a new packet.
For implemented headers (see proto/) these packets are defined in the section 'Packet struct' of each protocol file
args | list of keywords (see makeStruct) |
function packetDump | ( | self | , |
bytes | |||
) |
Print a hex dump of a packet.
self | the packet |
bytes | Number of bytes to dump. If no size is specified the payload is truncated. |
function packetFill | ( | self | , |
namedArgs | |||
) |
Set all members of all headers.
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. The argument 'pktLength' can be used to automatically calculate and set the length member of headers (e.g. ip header).
self | The packet |
args | Table of named arguments. For a list of available arguments see "See also" |
function packetGet | ( | self | ) |
Retrieve the values of all members as list of named arguments.
self | The packet |
function packetGetHeader | ( | self | , |
h | |||
) |
Get the specified header of a packet (e.g.
self.eth).
self | the packet (cdata) |
h | header to be returned |
function packetGetHeaders | ( | self | ) |
Get all headers of a packet as list.
self | The packet |
function packetMakeStruct | ( | ... | ) |
Creates a packet struct (cdata) consisting of different headers.
Simply list the headers in the order you want them to be in a packet. If you want the member to be named differently, use the following syntax: normal: <header> ; different membername: { <header>, <member> }. Supported keywords: eth, arp, ptp, ip, ip6, udp, tcp, icmp
The name of the created (internal) struct looks as follows: struct HEADER1_MEMBER1__HEADER2_MEMBER2 ... Only the "</strong>" (double underscore) has the special meaning of "a new header starts with name everything until "_" (single underscore)>, followed by the member name <everything after "_" until next header starts (indicated by next __)>"
args | list of keywords/tables of keyword-member pairs |
function packetResolveLastHeader | ( | self | ) |
Try to find out what the next header in the payload of this packet is.
This function is only used for buf:get/buf:dump
self | The packet |
function packetSetLength | ( | args | ) |
Set length for all headers.
Necessary when sending variable sized packets.
self | The packet |
length | Length of the packet. Value for respective length member of headers get calculated using this value. |
function pkt setESPTrailerLength | ( | len | ) |
Set the ESP trailer length.
len | ESP Trailer length in bytes |