Running Script Files

Pktgen can read and run files with default values and configurations via the -f commandline option (Pktgen Commandline Options).

These files can either be .pkt files with Pktgen runtime commands as shown in the previous section or .lua files with the same commands and options in Lua syntax.

For example here is a pktgen instance that read a .pkt file:

pktgen -l 0-4 -n 3 --proc-type auto --socket-mem 128,128 -- \
             -P -m "[1:3].0, [2:4].1" -f test/set_seq.pkt

Where the test/set_seq.pkt (included in the pktgen repository) is as follows:

seq 0 all 0000:4455:6677 0000:1234:5678 10.11.0.1 10.10.0.1/16 5 6 ipv4 udp 1 128
set all seqCnt 1

The Lua version (test/set_seq.lua in pktgen repository) is clearer and allows extension through standard Lua or user defined functions:

-- manual for more comment options.
require "Pktgen"
local seq_table = {         -- entries can be in any order
    ["eth_dst_addr"] = "0011:4455:6677",
    ["eth_src_addr"] = "0011:1234:5678",
    ["ip_dst_addr"] = "10.12.0.1",
    ["ip_src_addr"] = "10.12.0.1/16",   -- the 16 is the size of the mask value
    ["sport"] = 9,          -- Standard port numbers
    ["dport"] = 10,         -- Standard port numbers
    ["ethType"] = "ipv4",   -- ipv4|ipv6|vlan
    ["ipProto"] = "udp",    -- udp|tcp|icmp
    ["vlanid"] = 1,         -- 1 - 4095
    ["pktSize"] = 128,      -- 64 - 1518
    ["teid"] = 3,
    ["cos"] = 5,
    ["tos"] = 6
  };
-- seqTable( seq#, portlist, table );
pktgen.seqTable(0, "all", seq_table );
pktgen.set("all", "seq_cnt", 1);

The Lua interface is explained in the next section Using Lua with Pktgen.