[P4-dev] Parse a sflow packet which contain N numbers of samples (header + payload)

lee cyrus LEE_LOKYIN_c2 at lab.ntt.co.jp
Wed Dec 26 23:58:44 EST 2018


A little background a what I am working/investigating on. I have a pcap 
file filled with sflow packets. Each packet is formed with Outer headers 
+ Samples, and the Samples are bunch of Inner header + Payload. The 
picture below is the structure of a sflow packet that I am trying to 
parse. What I am trying to do is to remove some header inside each Inner 
Header section.

| Outer Headers  (4 headers)

| Inner Headers     (9 headers)

| Payload

| Inner Headers     (9 headers)

| Payload

| ...... (Inner header + payload can stack up to 10 sets)

Since I only want to modify the Inner Header section, I want to parse 
the outer header and inner header but not the payload. But as the 
picture above shown that each inner header is separated by a payload and 
I need to parse that payload in order to parse the next inner header. I 
did create a header that will extract the payload bits but because each 
payload is quite large so eventually I ended up with a compile error 
said "not enough local memory for thread local, failed to allocate local 
memory". So I got two work around to this problem but both of them don't 
seems to be feasible.

1)    The first work around is to define only two sets of inner header + 
payload and use recirculate() to iterate all the sample. But there is 
another problem. There isn't any function regarding to skipping bits. 
Obviously during the second iteration I don't want to parse the inner 
headers that has been modified before. I read other thread that was 
posted in 2015, they said P4 didn't have explicit "skip" function in the 
parser. I also read the latest P4_14 spec and it doesn't said anything 
about skipping as well. So I wonder has P4 implement anything similar 
like that now.

2)    The second work around is remove and add the modified inner 
headers with its payload to the bottom of the sample stack. But I found 
the location where the add header function will add to is right after 
the last parsed header. Which means I will have to parse everything 
inside the packet in order to add to the bottom of the stack. But this 
is impossible because of the memory error.

To conclude my problem, I want to know how to parse a packet with this 
sort of structure where it has payload in between each inner headers. 
There aren't any post regarding to parsing sflow packet so I don't know 
what is the recommended way to do so. If anyone have any ideas or 
experience with sflow packet. Please share your information with me. I 
will deeply appreciate any inputs.

Thanks in advance,

Cyrus Lee

More information about the P4-dev mailing list