Search code examples
network-programmingswitchingp4-lang

Can I remove a packet payload inside a .p4 program?


I would like to know if it's possible to completely remove a packet payload from a packet inside a .p4 program or at least modify it to random data. The reason behind this is that I'm cloning a packet and sending it to a different host (monitor) and this host does not need the packets payload.


Solution

  • Depends on what are you trying to do. If you would like to remove the some kind of header then it's enough to call

    hdr.random_header.setInvalid() 
    

    if you call that in Egress it should remove fields of the header from the packet. If you have len fields in headers you might also use

    truncate(new_size)
    

    when you know the size of packet without payload. If you already know easier option please share it here.