| #ifndef __PARSER_P4__ |
| #define __PARSER_P4__ |
| #include "defines.p4" |
| #include "headers.p4" |
| |
| header packet_in_t packet_in_hdr; |
| header packet_out_t packet_out_hdr; |
| header ethernet_t ethernet; |
| header ipv4_t ipv4; |
| header tcp_t tcp; |
| header udp_t udp; |
| |
| parser start { |
| // FIXME: Cheat the compiler to generate the deparser of packet in |
| // This is just a hack, we assume first 8 bit of etherType won't be 0 |
| return select( current(96, 8) ) { |
| NULL_ETH_TYPE : parse_pkt_in; |
| default : default_parser; |
| } |
| } |
| |
| parser parse_pkt_in { |
| extract(packet_in_hdr); |
| return parse_ethernet; |
| } |
| |
| parser default_parser { |
| return select(IGR_PORT_FIELD) { |
| CPU_PORT : parse_pkt_out; |
| default : parse_ethernet; |
| } |
| } |
| |
| parser parse_pkt_out { |
| extract(packet_out_hdr); |
| return parse_ethernet; |
| } |
| |
| parser parse_ethernet { |
| extract(ethernet); |
| return select(latest.etherType) { |
| ETHERTYPE_IPV4 : parse_ipv4; |
| default : ingress; |
| } |
| } |
| |
| parser parse_ipv4 { |
| extract(ipv4); |
| return select(latest.fragOffset, latest.protocol) { |
| IP_PROTOCOLS_TCP : parse_tcp; |
| IP_PROTOCOLS_UDP : parse_udp; |
| default: ingress; |
| } |
| } |
| |
| parser parse_tcp { |
| extract(tcp); |
| return ingress; |
| } |
| |
| parser parse_udp { |
| extract(udp); |
| return ingress; |
| } |
| |
| #endif |