examples/l3fwd: add vector stubs for RISC-V
[dpdk.git] / examples / pipeline / examples / varbit.spec
1 ; SPDX-License-Identifier: BSD-3-Clause
2 ; Copyright(c) 2020 Intel Corporation
3
4 ; This simple example illustrates how to work with variable size headers. The assumed input packet
5 ; is Ethernet/IPv4/UDP, with the IPv4 header containing between 0 and 40 bytes of options. To locate
6 ; the start of the UDP header, the size of the IPv4 header needs to be detected first, which is done
7 ; by reading the first byte of the IPv4 header that carries the 4-bit Internet Header Length (IHL)
8 ; field; this read is done with the "lookahead" instruction, which does not advance the extract
9 ; pointer within the input packet buffer. Once the size of the IPv4 header options is known for the
10 ; current packet, the IPv4 header is extracted by using the two-argument "extract" instruction. Then
11 ; the UDP header is extracted and modified.
12
13 //
14 // Headers
15 //
16 struct ethernet_h {
17         bit<48> dst_addr
18         bit<48> src_addr
19         bit<16> ethertype
20 }
21
22 struct ipv4_top_h {
23         bit<8> ver_ihl
24 }
25
26 struct ipv4_h {
27         bit<8> ver_ihl
28         bit<8> diffserv
29         bit<16> total_len
30         bit<16> identification
31         bit<16> flags_offset
32         bit<8> ttl
33         bit<8> protocol
34         bit<16> hdr_checksum
35         bit<32> src_addr
36         bit<32> dst_addr
37         varbit<320> options
38 }
39
40 struct udp_h {
41         bit<16> src_port
42         bit<16> dst_port
43         bit<16> length
44         bit<16> checksum
45 }
46
47 header ethernet instanceof ethernet_h
48 header ipv4_top instanceof ipv4_top_h
49 header ipv4 instanceof ipv4_h
50 header udp instanceof udp_h
51
52 //
53 // Meta-data
54 //
55 struct metadata_t {
56         bit<32> port
57         bit<32> options_size
58 }
59
60 metadata instanceof metadata_t
61
62 //
63 // Pipeline.
64 //
65 apply {
66         rx m.port
67
68         // Extract the fixed size Ethernet header.
69         extract h.ethernet
70
71         // Extract the variable size IPv4 header with up to 10 options.
72         lookahead h.ipv4_top
73         mov m.options_size h.ipv4_top.ver_ihl
74         and m.options_size 0xF
75         sub m.options_size 5
76         shl m.options_size 2
77         extract h.ipv4 m.options_size
78
79         // Extract the fixed size UDP header.
80         extract h.udp
81
82         // Modify the UDP header.
83         mov h.udp.src_port 0xAABB
84         mov h.udp.dst_port 0xCCDD
85
86         // Decide the output port.
87         xor m.port 1
88
89         // Emit the Ethernet, IPv4 and UDP headers.
90         emit h.ethernet
91         emit h.ipv4
92         emit h.udp
93
94         tx m.port
95 }