P4 is a domain-specific language that programs network switch hardware (ASICs like Intel Tofino, SmartNICs, FPGA routers). It defines custom packet parsers, match-action tables, and pipeline headers without modifying switch hardware microcode.
p4
parser MyParser(packet_in packet, out headers hdr) {
state start {
packet.extract(hdr.ethernet);
transition select(hdr.ethernet.etherType) {
0x0800: parse_ipv4;
default: accept;
}
}
}