Carmelo Cascone | 4f01102 | 2017-06-05 01:41:02 -0400 | [diff] [blame] | 1 | metadata intrinsic_metadata_t intrinsic_metadata; |
| 2 | |
| 3 | parser start { |
| 4 | return parse_ethernet; |
| 5 | } |
| 6 | |
| 7 | #define ETHERTYPE_IPV4 0x0800 |
| 8 | |
| 9 | header ethernet_t ethernet; |
| 10 | |
| 11 | parser parse_ethernet { |
| 12 | extract(ethernet); |
| 13 | return select(latest.etherType) { |
| 14 | ETHERTYPE_IPV4 : parse_ipv4; |
| 15 | default : ingress; |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | header ipv4_t ipv4; |
| 20 | |
| 21 | #define IP_PROTOCOLS_TCP 6 |
| 22 | #define IP_PROTOCOLS_UDP 17 |
| 23 | |
| 24 | parser parse_ipv4 { |
| 25 | extract(ipv4); |
| 26 | return select(latest.fragOffset, latest.protocol) { |
| 27 | IP_PROTOCOLS_TCP : parse_tcp; |
| 28 | IP_PROTOCOLS_UDP : parse_udp; |
| 29 | default: ingress; |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | header tcp_t tcp; |
| 34 | |
| 35 | parser parse_tcp { |
| 36 | extract(tcp); |
| 37 | return ingress; |
| 38 | } |
| 39 | |
| 40 | header udp_t udp; |
| 41 | |
| 42 | parser parse_udp { |
| 43 | extract(udp); |
| 44 | return ingress; |
| 45 | } |