No relevant resource is found in the selected language.

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Read our privacy policy>Search


To have a better experience, please upgrade your IE browser.


Understanding the Hash Algorithm

Rate and give feedback:
Huawei uses machine translation combined with human proofreading to translate this document to different languages in order to help you better understand the content of this document. Note: Even the most advanced machine translation cannot match the quality of professional translators. Huawei shall not bear any responsibility for translation accuracy and it is recommended that you refer to the English document (a link for which has been provided).
Understanding the Hash Algorithm

Understanding the Hash Algorithm



In network deployment, when multiple forwarding paths are available, load balancing is often deployed. After load balancing mode is deployed, packets can be forwarded based on the packets' input location (port), service type (protocol), packet content, flow table, and timestamp; alternatively, random or round-robin per-packet load balancing can be performed to fully utilize links and improve the forwarding efficiency.

Timestamp-based, random, or round-robin per-packet forwarding is seldom deployed. This is because it may cause out-of-order packets or multiple copies of the same packets on the destination server after traffic of the same user is transmitted along different paths on the network. Generally, packets are load balanced based on the service type or packet content (the 5-tuple includes the source IP address, destination IP address, protocol number, source port, and destination port).

The common load balancing process includes input (traffic and valid packet fields), processing (calculation by the hash algorithm), and output (traffic forwarding through the corresponding outbound interface based on the calculation result). The hash calculation result directly affects the load balancing effect. Therefore, how to use the hash algorithm for calculation is particularly important in load balancing deployment.


The commands and configuration examples used in this document may be supported only by some switch models. For details about the support capability, see the product documentation.

Hash Algorithm

A hash algorithm converts fixed-length or variable-length input into fixed-length output. The output is a hash value. This conversion is a compression mapping. Generally, the hash value space is far less than that the input space, and different inputs may be converted into the same output. In addition, a hash value cannot be used to uniquely identify an input value. In a simple word, hash algorithm compresses a message of a certain length into a fixed-length message digest.

Figure 1-1 Hash algorithm process

Figure 1-1 illustrates the hash calculation process:

  1. Obtain packet header information. In case of common IP packets, the fields of source MAC address, destination MAC address, source IP address, destination IP address, VLAN ID, and Layer 4 port number need to be obtained. In case of tunnel packets, the preceding fields of the outer and inner packets need to be obtained. Based on the configured hash model, the information is used as the reference values of hash factors. The reference values can be set using commands.
  2. Calculate hash factors based on the hash algorithm and seed to generate a hash key.

    The hash algorithm is a fixed type of algorithm provided by chips. Different algorithms have different effects on different traffic models, and multiple algorithms are available for selection. The algorithm to be used can be specified using commands.

    Seed is a value used for hash calculation. If the hash factors are the same, the seed value affects the calculated hash key value. The seed value can be set using commands.

  3. To enable the same hash factor to change more frequently and flexibly adapt to different hash scenarios, chips can offset 0 to 15 bits from the hash key value. The number of bits to be offset from the hash key value can be set using commands.
  4. The number of bits to be offset from the hash key value can be set using commands.

Load Balancing Modes

After the hash algorithm configuration is determined, two load balancing modes affect traffic forwarding.

Elastic Load Balancing

In robust load balancing mode, when the number of links increases or decreases, only some traffic is switched between links. For example, a link aggregation group contains three member links and data is forwarded based on the hash key value. If a link is faulty and cannot forward data, traffic is re-allocated to the other two working links when elastic load balancing is not configured. If elastic load balancing is configured, the traffic allocated to the other two links is still transmitted over the two links, and the traffic on the faulty link is evenly distributed to the two links. This has little impact on services. After the faulty link recovers, some traffic is switched from the two links to the recovered link. The traffic volume on each link is not the same as that before the link fault occurs.

To configure elastic load balancing, run the load-balance enhanced resilient profile profile-name command.

Load Balancing Based on the Same Source and Destination

Identical source and destination indicate that bidirectional data packets of a network connection must be sent out from the same outbound interface. During network traffic analysis, a device needs to analyze bidirectional traffic between the communicating parties for traffic information analysis. For this purpose, packets of the communicating parties need to be forwarded to the same device for analysis. The requires the device to support packet forwarding based on the same source and destination.

The following provides the configuration for your reference:

Eth-Trunk (CE8800&CE7800&CE6800&CE5800)

<HUAWEI> system-view
[~HUAWEI] load-balance profile default
[~HUAWEI-load-balance-profile-default] eth-trunk hash-mode 5

ECMP (CE8800&CE7800&CE6800&CE5800)

<HUAWEI> system-view
[~HUAWEI] load-balance ecmp
[~HUAWEI-ecmp] hashmode 5

ECMP & Eth-Trunk (CE12800)

<HUAWEI> system-view
[~HUAWEI] load-balance profile default
[~HUAWEI-load-balance-profile-default] mode symmetry

Typical Problems

Hash Polarization

Hash polarization indicates that traffic is unevenly load balanced after being hashed twice or more. This situation is common in multiple inter-device hashing operations. That is, ECMP hashing is performed at the first network layer, and ECMP or Eth-Trunk hashing is performed at the second network layer. On the same device, if multiple Eth-Trunks function as ECMP outbound interfaces, hash polarization may occur.

Problem Description

Figure 1-2 Hash polarization

In Figure 1-2, there are four types of flows on the inbound interface of Switch A and four equal-cost links for outbound interfaces. According to hash calculation, flows 3 and 4 are transmitted to Switch B through the two upper links. Flows 1 and 2 are transmitted to Switch C through the two lower links. The outbound interfaces of Switch B also have four equal-cost links. If the hash algorithm of Switch B is the same as or similar to that of Switch A, the hash result indicates that flows 3 and 4 are transmitted through the two upper links and that no flow is transmitted through the two lower links. A similar situation occurs on Switch C. If traffic is quite unevenly load balanced between ECMP equal-cost routes or Eth-Trunk member interfaces, hash polarization occurs.

Actually, implementing the hash function of switches depends on chips. Therefore, when switches using the same type of chip are located at the adjacent network layers, hash polarization may occur. If both Eth-Trunk hashing and ECMP hashing exist on the same device, hash polarization may also occur.

Therefore, if ECMP or Eth-Trunk hashing is deployed on a multi-layer network, you need to consider the risk of hash polarization.


If uneven load balancing or hash polarization occurs during traffic forwarding, you can adjust the hash algorithm on the device to solve the problem. For example, for an inter-device polarization scenario similar to that shown in #EN-US_TOPIC_0107595925/fig6159632175110, the hash algorithm on Switch A can be adjusted to solve this problem.

The following configurations are provided for reference.

Method for adjusting ECMP (CE8800&CE7800&CE6800&CE5800)

<HUAWEI> system-view
[~HUAWEI] load-balance ecmp
[~HUAWEI-ecmp] hashmode 4

Method for adjusting ECMP (CE12800)

<HUAWEI> system-view
[~HUAWEI] load-balance profile default
[~HUAWEI-load-balance-profile-default] ecmp hash-mode 3

If Eth-Trunk is used for load balancing, the configuration is as follows:

<HUAWEI> system-view
[~HUAWEI] load-balance profile default
[~HUAWEI-load-balance-profile-default] eth-trunk hash-mode 5

If hash polarization occurs when both Eth-Trunk hashing and ECMP hashing exist on the same device, adjust the hash-mode of ECMP and Eth-Trunk to select different hash algorithms. If the problem persists, adjust the universal-id of hash calculation in Eth-Trunk load balancing. The configuration is as follows:

<HUAWEI> system-view
[~HUAWEI] load-balance profile default
[~HUAWEI-load-balance-profile-default] eth-trunk universal-id  5

Related Information

According to the hash algorithm, the following factors affect the hash calculation result:

  • Hash factor: can be configured based on the traffic model.

    The hash factor configuration commands are:

    ip [ src-ip | dst-ip | l4-src-port | l4-dst-port | protocol ] *

    ipv6 [ src-ip | dst-ip | protocol | l4-src-port | l4-dst-port ] *

    l2 [ src-mac | dst-mac | vlan | eth-type ] *

  • Hash algorithm: is selected using the hash-mode hash-mode-id parameter.
  • Seed value: is set using the seed seed-data command. If multiple vendors' devices exist on the network, it is recommended that the seed values of different vendors' devices be set the same.
  • Offset: is set using the universal-id universal-id parameter. The value ranges from 1 to 16. The value 1 indicates the hash calculation result is not offset. Generally, a hash algorithm has a specific offset value. If multiple vendors' devices exist on the network, it is recommended that the seed values of different vendors' devices be set the same.
  • Offset algorithm: is fixed on chips and cannot be changed on CE devices.

Switch vendors can select and combine hash algorithms and offset values only based on the preceding hash calculation parameters supported by chips for hash calculation. The hash load balancing effect is closely related to the traffic model. For flow-based hashing, theoretically, no hash parameter settings are applicable to all service scenarios.

If hash polarization or uneven load balancing occurs on the network, adjust the hash calculation parameters of network devices at different network layers to implement differentiated hash calculation and solve the problem.

Updated: 2019-07-01

Document ID: EDOC1100086965

Views: 572

Downloads: 17

Average rating:
This Document Applies to these Products
Related Documents
Related Version
Previous Next