aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet/hash/hash.rst
blob: 3db74e2f093a273c6a165defb8d0567705325a98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
.. _hash_doc:

Hash Infra
==========

Overview
________

Modern physical NICs uses packet flow hash for different purposes, i.e. Receive
Side Scaling, flow steering and interface bonding etc. NICs can also provide
packet flow hash prepended to data packet as metadata which can be used by
applications without recomputing the packet flow hash.

As more and more services are deployed in virtualized environment, making use of
virtual interfaces to interconnect those services.

The Hash Infrastructure
_______________________

VPP implements software based hashing functionality which can be used for different
purposes. It also provides users a centralized way to registry custom hash functions
based on traffic profile to be used in different vpp features i.e. Multi-TXQ,
software RSS or bonding driver.

Data structures
^^^^^^^^^^^^^^^

Hashing infra provides two types of hashing functions:
``VNET_HASH_FN_TYPE_ETHERNET`` and ``VNET_HASH_FN_TYPE_IP`` for ethernet traffic and
IP traffic respectively.
Hashing infra provides uniform signature to the functions to be implemented:

.. code:: c

  void (*vnet_hash_fn_t) (void **p, u32 *h, u32 n_packets);

Here ``**p`` is the array of pointers pointing to the beginning of packet headers
(either ethernet or ip).
``*h`` is an empty array of size n_packets. On return, it will contain hashes.
``n_packets`` is the number of packets pass to this function.

Custom hashing functions can be registered through ``VNET_REGISTER_HASH_FUNCTION``.
Users need to provide a name, description, priority and hashing functions for
registration.

Default hashing function is selected based on the highest priority among the registered
hashing functions.

.. code:: c

  typedef struct vnet_hash_function_registration
  {
    const char *name;
    const char *description;
    int priority;
    vnet_hash_fn_t function[VNET_HASH_FN_TYPE_N];

    struct vnet_hash_function_registration *next;
  } vnet_hash_function_registration_t;

For example, ``crc32c_5tuple`` provides two hashing functions: for IP traffic and for
ethernet traffic. It uses 5 tuples from the flow to compute the crc32 hash on it.

.. code:: c

  void vnet_crc32c_5tuple_ip_func (void **p, u32 *hash, u32 n_packets);
  void vnet_crc32c_5tuple_ethernet_func (void **p, u32 *hash, u32 n_packets);

  VNET_REGISTER_HASH_FUNCTION (crc32c_5tuple, static) = {
    .name = "crc32c-5tuple",
    .description = "IPv4/IPv6 header and TCP/UDP ports",
    .priority = 50,
    .function[VNET_HASH_FN_TYPE_ETHERNET] = vnet_crc32c_5tuple_ethernet_func,
    .function[VNET_HASH_FN_TYPE_IP] = vnet_crc32c_5tuple_ip_func,
  };


Users can see all the registered hash functions along with priority and description.

Hash API
^^^^^^^^

There is no Hash API at the moment.

Hash CLI
^^^^^^^^

::

  show hash