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