Filtering UDP traffic using p4rtshell


I’m trying to use traffic filter example on P4Pi with t4p4s target to filter UDP packets by their source port. When I filter by IPv4 source address the packets drop correctly. To add filters I’m using p4rtshell as control plane with the following commands:

te = table_entry["MyIngress.udp_srcPort_filter"](action="MyIngress.drop")
te.match["hdr.udp.srcPort"] = <source_port>

This doesn’t filter traffic at all. I tested packets with empty payload and tried to filter on UDP length which also didn’t work. When I checked hdr.udp.isValid() it seems to return true which confuses me even more.

Can you help me resolve this issue?

I do not know if the t4p4s target has detailed logging capabilities that can be enabled that are in any way similar to the ones in the BMv2 simple_switch_grpc process, but if it does, I would recommend enabling those and seeing what it says happens while a sample UDP packet that you think should match is processed.

Also, if you could publish complete P4 source code and any relevant controller programs of an example that successfully filters by IPv4 source address where the packets drop as you expect, vs. the smallest changes you can make that tries to filter instead by UDP source port but does not drop packets as as you expect, that may help others diagnose the issue.

The filter was using an ipv4.src.hit() OR ipv4.dst.hit() but for udp there was an AND statement, and I just missed it. That was what was causing my issue.