1 ; SPDX-License-Identifier: BSD-3-Clause
2 ; Copyright(c) 2020 Intel Corporation
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.
30 bit<16> identification
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
60 metadata instanceof metadata_t
68 // Extract the fixed size Ethernet header.
71 // Extract the variable size IPv4 header with up to 10 options.
73 mov m.options_size h.ipv4_top.ver_ihl
74 and m.options_size 0xF
77 extract h.ipv4 m.options_size
79 // Extract the fixed size UDP header.
82 // Modify the UDP header.
83 mov h.udp.src_port 0xAABB
84 mov h.udp.dst_port 0xCCDD
86 // Decide the output port.
89 // Emit the Ethernet, IPv4 and UDP headers.