xref: /dpdk/examples/pipeline/examples/rss.spec (revision 8ba342ce6f098b53768bea9553204fc4e5bdbd35)
1; SPDX-License-Identifier: BSD-3-Clause
2; Copyright(c) 2023 Intel Corporation
3
4; This simple example illustrates how to compute an RSS hash signature over an n-tuple set of fields
5; read from the packet headers and/or the packet meta-data by using the "rss" instruction. In this
6; specific example, the n-tuple is the (IPv4 source address, IPv4 destination address) 2-tuple.
7
8//
9// Headers
10//
11struct ethernet_h {
12	bit<48> dst_addr
13	bit<48> src_addr
14	bit<16> ethertype
15}
16
17struct ipv4_h {
18	bit<8> ver_ihl
19	bit<8> diffserv
20	bit<16> total_len
21	bit<16> identification
22	bit<16> flags_offset
23	bit<8> ttl
24	bit<8> protocol
25	bit<16> hdr_checksum
26	bit<32> src_addr
27	bit<32> dst_addr
28}
29
30header ethernet instanceof ethernet_h
31header ipv4 instanceof ipv4_h
32
33//
34// Meta-data.
35//
36struct metadata_t {
37	bit<32> port
38	bit<32> hash
39}
40
41metadata instanceof metadata_t
42
43//
44// RSS.
45//
46rss rss0
47
48//
49// Pipeline.
50//
51apply {
52	//
53	// RX and parse.
54	//
55	rx m.port
56	extract h.ethernet
57	extract h.ipv4
58
59	//
60	// Compute the RSS hash over the n-tuple.
61	//
62	// Details:
63	//    a) RSS object name: rss0;
64	//    b) Destination (i.e. hash result): m.hash;
65	//    c) Source (i.e. n-tuple to be hashed): The 2-tuple formed by the header fields
66	//       (h.ipv4.src_addr, h.ipv4.dst_addr). Only the first and the last n-tuple fields are
67	//       specified in the RSS instruction, but all the fields in between are part of the
68	//       n-tuple to be hashed.
69	//
70	rss rss0 m.hash h.ipv4.src_addr h.ipv4.dst_addr
71
72	//
73	// Use the computed hash to create a uniform distribution of pkts across the 4 output ports.
74	//
75	and m.hash 3
76	mov m.port m.hash
77
78	//
79	// De-parse and TX.
80	//
81	emit h.ethernet
82	emit h.ipv4
83	tx m.port
84}
85