|
| 1 | +/* |
| 2 | +Copyright 2013-present Barefoot Networks, Inc. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +#include <core.p4> |
| 18 | + |
| 19 | +#include "spec-ex09.p4" |
| 20 | + |
| 21 | +struct Tcp_option_sack_top |
| 22 | +{ |
| 23 | + int<8> kind; |
| 24 | + bit<8> length; |
| 25 | + bool f; |
| 26 | + bit<7> padding; |
| 27 | +} |
| 28 | +parser Tcp_option_parser(packet_in b, |
| 29 | + out Tcp_option_stack vec) |
| 30 | +{ |
| 31 | + state start { |
| 32 | + transition select(b.lookahead<bit<8>>()) { |
| 33 | + 8w0x0 : parse_tcp_option_end; |
| 34 | + 8w0x1 : parse_tcp_option_nop; |
| 35 | + 8w0x2 : parse_tcp_option_ss; |
| 36 | + 8w0x3 : parse_tcp_option_s; |
| 37 | + 8w0x5 : parse_tcp_option_sack; |
| 38 | + } |
| 39 | + } |
| 40 | + state parse_tcp_option_end { |
| 41 | + b.extract(vec.next.end); |
| 42 | + transition accept; |
| 43 | + } |
| 44 | + state parse_tcp_option_nop { |
| 45 | + b.extract(vec.next.nop); |
| 46 | + transition start; |
| 47 | + } |
| 48 | + state parse_tcp_option_ss { |
| 49 | + b.extract(vec.next.ss); |
| 50 | + transition start; |
| 51 | + } |
| 52 | + state parse_tcp_option_s { |
| 53 | + b.extract(vec.next.s); |
| 54 | + transition start; |
| 55 | + } |
| 56 | + state parse_tcp_option_sack { |
| 57 | + b.extract(vec.next.sack, |
| 58 | + (bit<32>)(8 * (b.lookahead<Tcp_option_sack_top>().length) - |
| 59 | + 16)); |
| 60 | + transition start; |
| 61 | + } |
| 62 | +} |
| 63 | + |
| 64 | +parser pr<H>(packet_in b, out H h); |
| 65 | +package top<H>(pr<H> p); |
| 66 | + |
| 67 | +top(Tcp_option_parser()) main; |
0 commit comments