Pktgen 运行脚本文件

来源:互联网 发布:linux epoll wait 编辑:程序博客网 时间:2024/06/05 23:51
Pktgen 运行脚本文件
    pktgen可以读取并运行脚本文件来进行默认配置或修改配置
    在命令行选项加上 -f
    
    脚本可以是 .pkt 文件,pkt文件主要是前面介绍的命令组成的
    脚本可以是 .lua 文件,也是由相同的命令和选项组成,只是用的lua语法
    
    下面有个运行脚本文件的例子:
    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
    
    
    [root@localhost pktgen-3.3.3]# cat test/set_seq.cmd
    # seq <seq#> <portlist> dst-Mac src-Mac dst-IP src-IP/netmask sport dport ipv4|ipv6|vlan udp|tcp|icmp vid pktsize
    seq 0 all 0000:4455:6677 0000:1234:5678 10.11.0.1 10.10.0.1/16 5 6 ipv4 udp 1 128 0
    set all seq_cnt 1

    可以看出 .pkt/.cmd 就是把命令写在文件中
    
    [root@localhost pktgen-3.3.3]# cat test/set_seq.lua
    -- Lua uses '--' as comment to end of line read the
    -- manual for more comment options.
    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
      };
    -- seqTable( seq#, portlist, table );
    pktgen.seqTable(0, "all", seq_table );
    pktgen.set("all", "seq_cnt", 1);
    
    lua的脚本看起来复杂些,但这里教了我们如何给自己的C程序绑定到别的语言
    即语言绑定,
    我们需要知道 lua 脚本的语法?还有lua 能操作pktgen的那些东西?
原创粉丝点击