pktgen / Pktgen-DPDK

DPDK based packet generator
Other
377 stars 117 forks source link

Invalid portlist #191

Closed jalalmostafa closed 1 year ago

jalalmostafa commented 1 year ago

scripts/rfc2544.lua throws invalid portlist after v23.03 release

The exception was introduced after the tag pktgen-23.03.0 on the tag commit it is not thrown.

lua-shell: scripts/rfc2544.lua:125: invalid portlist
stack traceback:
    [C]: in function 'pktgen.reset'
    scripts/rfc2544.lua:125: in upvalue 'setupTraffic'
    scripts/rfc2544.lua:565: in function 'main'
    scripts/rfc2544.lua:588: in main chunk
KeithWiles commented 1 year ago

The function pktgen.reset() calls pktgen_get_portlist() with the value passed from Lua. The value can be a string or int or uint. In this case the pktgen.reset("all") is used at least that is what I see in the rfc2544.lua at line 119. Maybe you changed the script as the error output is reporting line 125 in the lua script. The pktgen_get_portlist() function will compare the string to "all" and then just send all of the bits in the portlist variable and return. If the pktgen.reset("foo") then I could see this error.

Is the rfc2544.lua script been changed? If not then we need to make sure we are looking at the version on github.com/pktgen branch main. I have been making a number of changes to the fix-latency-bug branch and it will be pushed to main I hope this month.

jalalmostafa commented 1 year ago

It is true that I did some modifications but I kept pktgen.reset("all") as it is. I was debugging a bit it seems the error is thrown when the port is "all". Anyway I switched to main and the same problem is happening when the port is all.

The port list is not parsed correctly when all is used. I did some code modifications on pktgen_get_portlist to know the source of the problem:

static inline portlist_t
pktgen_get_portlist(lua_State *L, int index)
{
    portlist_t portlist = INVALID_PORTLIST;
    if (lua_isstring(L, index)) {
        printf("portlist is string\n");
        const char* s = luaL_checkstring(L, 1);
        printf("portlist is %s\n", s);
        if (portlist_parse(s, &portlist) < 0)
            portlist = INVALID_PORTLIST;
        printf("parsed portlist: %ld, INVALID_PORTLIST: %ld\n", portlist, INVALID_PORTLIST);
    } else if (lua_isnumber(L, index))
        portlist = (uint64_t)lua_tonumber(L, index);
    else if (lua_isinteger(L, index))
        portlist = (uint64_t)lua_tointeger(L, index);

    return portlist;
}

but:

[  INFO ] Starting RFC-2544 script
[NOTICE ] See test log for results: RFC2544_throughput_results.txt
portlist is string
portlist is all
parsed portlist: -1, INVALID_PORTLIST: -1
lua-shell: scripts/rfc2544.lua:119: invalid portlist
stack traceback:
    [C]: in function 'pktgen.reset'
    scripts/rfc2544.lua:119: in upvalue 'setupTraffic'
    scripts/rfc2544.lua:502: in function 'main'
    scripts/rfc2544.lua:521: in main chunk

On the other hand, using the actual port number instead of all works just fine.

KeithWiles commented 1 year ago

I think I found the problem. Please try the branch called fix-portlist and let me know if that fixes the problem.

The problem was I changed the Lua code in app/lpktgenlib.c to detect an invalid portlist, but I was setting -1 in portlist and then called the portlist_parse() and in the case of all it needed to clear the portlist and then add the correct number of ports to the uint64_t value.

Thanks for finding this problem.

jalalmostafa commented 1 year ago

Thanks, Keith. It works.