1 ; SPDX-License-Identifier: BSD-3-Clause
2 ; Copyright(c) 2022 Intel Corporation
4 ; This simple example illustrates how to compute a hash signature over an n-tuple set of fields read
5 ; from the packet headers and/or the packet meta-data by using the "hash" instruction. In this
6 ; specific example, the n-tuple is the classical DiffServ 5-tuple.
21 bit<16> identification
37 header ethernet instanceof ethernet_h
38 header ipv4 instanceof ipv4_h
39 header udp instanceof udp_h
54 metadata instanceof metadata_t
69 // Prepare the n-tuple to be hashed in meta-data.
71 // This is required when:
72 // a) The n-tuple fields are part of different headers;
73 // b) Some n-tuple fields come from headers and some from meta-data.
75 mov m.src_addr h.ipv4.src_addr
76 mov m.dst_addr h.ipv4.dst_addr
77 mov m.protocol h.ipv4.protocol
78 mov m.src_port h.udp.src_port
79 mov m.dst_port h.udp.dst_port
82 // Compute the hash over the n-tuple.
85 // a) Hash function: jhash. Another available option is crc32.
86 // b) Destination (i.e. hash result): m.hash;
87 // c) Source (i.e. n-tuple to be hashed): The 5-tuple formed by the meta-data fields
88 // (m.src_addr, m.dst_addr, m.protocol, m.src_port, m.dst_port). Only the first and
89 // the last n-tuple fields are specified in the hash instruction, but all the fields
90 // in between are part of the n-tuple to be hashed.
92 hash jhash m.hash m.src_addr m.dst_port
95 // Use the computed hash to create a uniform distribution of pkts across the 4 output ports.