Document Name | Link |
---|---|
SONiC Generic Hash | [https://github.com/sonic-net/SONiC/doc/hash/hash-design.md] |
The hashing algorithm is used to make traffic-forwarding decisions for traffic exiting the switch. It makes hashing decisions based on values in various packet fields, as well as on the hash seed value. The packet fields used by the hashing algorithm varies by the configuration on the switch.
For ECMP, the hashing algorithm determines how incoming traffic is forwarded to the next-hop device. For LAG, the hashing algorithm determines how traffic is placed onto the LAG member links to manage bandwidth by evenly load-balancing traffic across the outgoing links.
Generic Hash is a feature which allows user to configure which hash fields suppose to be used by hashing algorithm by providing global switch hash configuration for ECMP and LAG.
The sonic-mgmt generic hash tests validate whether the hash configurations can be applied successfully and the hash behaviour is as expected.
- Ethernet packet hashing configuration with inner/outer IP frames
- Global switch hash configuration for ECMP and LAG
- Warm/Fast reboot
- config: set switch hash global configuration
- show: display switch hash global configuration or capabilities
This feature will provide error handling for the next situations:
- Invalid parameter value
This feature will provide error handling for the next situations:
- Missing parameters
- Invalid parameter value
- Parameter removal
- Configuration removal
The test is to verify the hash configuration can be added/updated by the generic hash, and the ECMP and lag hash behavior will change according to the generic hash configurations.
No scale or performance test related
The following command can be used to configure generic hash:
config
|--- switch-hash
|--- global
|--- ecmp-hash ARGS
|--- lag-hash ARGS
Examples: The following command updates switch hash global:
config switch-hash global ecmp-hash \
'DST_MAC' \
'SRC_MAC' \
'ETHERTYPE' \
'IP_PROTOCOL' \
'DST_IP' \
'SRC_IP' \
'L4_DST_PORT' \
'L4_SRC_PORT' \
'INNER_DST_MAC' \
'INNER_SRC_MAC' \
'INNER_ETHERTYPE' \
'INNER_IP_PROTOCOL' \
'INNER_DST_IP' \
'INNER_SRC_IP' \
'INNER_L4_DST_PORT' \
'INNER_L4_SRC_PORT'
config switch-hash global lag-hash \
'DST_MAC' \
'SRC_MAC' \
'ETHERTYPE' \
'IP_PROTOCOL' \
'DST_IP' \
'SRC_IP' \
'L4_DST_PORT' \
'L4_SRC_PORT' \
'INNER_DST_MAC' \
'INNER_SRC_MAC' \
'INNER_ETHERTYPE' \
'INNER_IP_PROTOCOL' \
'INNER_DST_IP' \
'INNER_SRC_IP' \
'INNER_L4_DST_PORT' \
'INNER_L4_SRC_PORT'
The following command shows switch hash global configuration:
show
|--- switch-hash
|--- global
|--- capabilities
Example: The following command shows switch hash global configuration:
root@sonic:/home/admin# show switch-hash global
ECMP HASH LAG HASH
----------------- -----------------
DST_MAC DST_MAC
SRC_MAC SRC_MAC
ETHERTYPE ETHERTYPE
IP_PROTOCOL IP_PROTOCOL
DST_IP DST_IP
SRC_IP SRC_IP
L4_DST_PORT L4_DST_PORT
L4_SRC_PORT L4_SRC_PORT
INNER_DST_MAC INNER_DST_MAC
INNER_SRC_MAC INNER_SRC_MAC
INNER_ETHERTYPE INNER_ETHERTYPE
INNER_IP_PROTOCOL INNER_IP_PROTOCOL
INNER_DST_IP INNER_DST_IP
INNER_SRC_IP INNER_SRC_IP
INNER_L4_DST_PORT INNER_L4_DST_PORT
INNER_L4_SRC_PORT INNER_L4_SRC_PORT
The following command shows switch hash capabilities:
root@sonic:/home/admin# show switch-hash capabilities
ECMP HASH LAG HASH
----------------- -----------------
IN_PORT IN_PORT
DST_MAC DST_MAC
SRC_MAC SRC_MAC
ETHERTYPE ETHERTYPE
VLAN_ID VLAN_ID
IP_PROTOCOL IP_PROTOCOL
DST_IP DST_IP
SRC_IP SRC_IP
L4_DST_PORT L4_DST_PORT
L4_SRC_PORT L4_SRC_PORT
INNER_DST_MAC INNER_DST_MAC
INNER_SRC_MAC INNER_SRC_MAC
INNER_ETHERTYPE INNER_ETHERTYPE
INNER_IP_PROTOCOL INNER_IP_PROTOCOL
INNER_DST_IP INNER_DST_IP
INNER_SRC_IP INNER_SRC_IP
INNER_L4_DST_PORT INNER_L4_DST_PORT
INNER_L4_SRC_PORT INNER_L4_SRC_PORT
{
"SWITCH_HASH": {
"GLOBAL": {
"ecmp_hash": [
"DST_MAC",
"SRC_MAC",
"ETHERTYPE",
"IP_PROTOCOL",
"DST_IP",
"SRC_IP",
"L4_DST_PORT",
"L4_SRC_PORT",
"INNER_DST_MAC",
"INNER_SRC_MAC",
"INNER_ETHERTYPE",
"INNER_IP_PROTOCOL",
"INNER_DST_IP",
"INNER_SRC_IP",
"INNER_L4_DST_PORT",
"INNER_L4_SRC_PORT"
],
"lag_hash": [
"DST_MAC",
"SRC_MAC",
"ETHERTYPE",
"IP_PROTOCOL",
"DST_IP",
"SRC_IP",
"L4_DST_PORT",
"L4_SRC_PORT",
"INNER_DST_MAC",
"INNER_SRC_MAC",
"INNER_ETHERTYPE",
"INNER_IP_PROTOCOL",
"INNER_DST_IP",
"INNER_SRC_IP",
"INNER_L4_DST_PORT",
"INNER_L4_SRC_PORT"
]
}
}
}
The test should support t0 and t1 topologies.
No. | Test Case | Test Purpose |
---|---|---|
1 | test_hash_capability | Verify the “show switch-hash capabilities” gets the supported hash fields. |
2 | test_ecmp_hash | Verify the basic functionality of ecmp hash with a single hash field |
3 | test_lag_hash | Verify the basic functionality of lag hash with a single hash field |
4 | test_ecmp_and_lag_hash | Verify the hash functionality with all ecmp and lag hash fields configured |
5 | test_nexthop_flap | Verify the ecmp hash functionality when there is nexthop flap |
6 | test_lag_member_flap | Verify the lag hash functionality when there is lag member flap |
7 | test_lag_member_remove_add | Verify the lag hash functionality after a lag member is removed and added back to a portchannel |
8 | test_reboot | Verify there is no hash configuration inconsistence before and after reload/reboot |
9 | test_backend_error_messages | Verify there are backend errors in syslog when the hash config is removed or updated with invalid values via redis cli |
- The tested hash field in each test case is randomly selected from a pre-defined field list per asic type. Currently these fields are tested as default: 'IN_PORT', 'SRC_MAC', 'DST_MAC', 'ETHERTYPE', 'VLAN_ID', 'IP_PROTOCOL', 'SRC_IP', 'DST_IP', 'L4_SRC_PORT', 'L4_DST_PORT', 'INNER_SRC_IP', 'INNER_DST_IP'.
- DST_MAC, ETHERTYPE, VLAN_ID fields are only tested in lag hash test cases, because L2 traffic is needed to test these fields, and there is no ecmp hash when the traffic is fowarded in L2.
- IPv4 and IPv6 are covered in the test, but the versions(including the inner version when testing the inner fields) are randomly selected in the test cases.
- For the inner fields, three types of encapsulations are covered: IPinIP, VxLAN and NVGRE. For the VxLAN packet, the default port 4789 and a custom port 13330 are covered in the test.
- For the reboot test, reboot type is randomly selected from config reload, cold, warm and fast reboot.
- The random selections of hash fields, ip versions, encapsulation types and reboot types can be controlled by pytest options. The user is able to set each of the option as 'random', 'all', or a specific value.
- Get the supported hash fields via cli "show switch-hash capabilities"
- Check the fields are as expected.
- The test is using the default links and routes in a t0/t1 testbed.
- Randomly select a hash field and configure it to the ecmp hash list via cli "config switch-hash global ecmp-hash".
- Configure the lag hash list to exclude the selected field to verify the lag hash configuration does not affect the hash result.
- Send traffic with changing values of the field under test from a downlink ptf port to uplink destination via multiple nexthops.
- Check the traffic is balanced over the nexthops.
- If the uplinks are portchannels with multiple members, check the traffic is not balanced over the members.
- The test is using the default links and routes in a t0/t1 testbed, and only runs on setups which have multi-member portchannel uplinks.
- Randomly select a hash field and configure it to the lag hash list via cli "config switch-hash global lag-hash".
- Configure the ecmp hash list to exclude the selected field to verify the ecmp hash configuration does not affect the hash result.
- If the hash field is DST_MAC, ETHERTYPE or VLAN_ID, take the steps 5-7, otherwise skip them.
- Choose one downlink interface and one uplink interface, remove all ip/ipv6 addresses on them.
- Remove the downlink interface from the existing vlan if it is t0 topology.
- For the DST_MAC, ETHERTYPE fields, add the chosen interfaces to a same vlan; For VLAN_ID field, add the interfaces to multiple vlans.
- Send traffic with changing values of the field under test from a downlink ptf port to uplink destination via the portchannels.
- Check the traffic is forwarded through only one portchannel and is balanced over the members.
- The test is using the default links and routes in a t0/t1 testbed.
- Configure all the supported hash fields for the ecmp and lag hash.
- Randomly select one hash field to test.
- Send traffic with changing values of the field under test from a downlink ptf port to uplink destination.
- Check the traffc is balanced over all the uplink physical ports.
- The test is using the default links and routes in a t0/t1 testbed.
- Configure all the supported hash fields for the ecmp and lag hash.
- Randomly select one hash field to test.
- Send traffic with changing values of the field under test from a downlink ptf port to uplink destination.
- Check the traffic is balanced over all the uplink ports.
- Randomly shutdown 1 nexthop interface.
- Send the traffic again.
- Check the traffic is balanced over all remaining uplink ports with no packet loss.
- Recover the interface and do shutdown/startup on the interface 3 more times.
- Send the traffic again.
- Check the traffic is balanced over all uplink ports with no packet loss.
- The test is using the default links and routes in a t0/t1 testbed, and only runs on setups which have multi-member portchannel uplinks.
- Configure all the supported hash fields for the ecmp and lag hash.
- Randomly select one hash field to test.
- If the hash field is DST_MAC, ETHERTYPE or VLAN_ID, take the steps 5-7, otherwise skip them.
- Choose one downlink interface and one uplink interface, remove all ip/ipv6 addresses on them.
- Remove the downlink interface from the existing vlan if it is t0 topology.
- For the DST_MAC, ETHERTYPE fields, add the chosen interfaces to a same vlan; For VLAN_ID field, add the interfaces to multiple vlans.
- Send traffic with changing values of the field under test from a downlink ptf port to uplink destination.
- Check the traffic is balanced over all the uplink ports.
- Randomly shutdown 1 member port in all uplink portchannels.
- Send the traffic again.
- Check the traffic is balanced over all remaining uplink ports with no packet loss.
- Recover the members and do shutdown/startup on them 3 more times.
- Send the traffic again.
- Check the traffic is balanced over all uplink ports with no packet loss.
- The test is using the default links and routes in a t0/t1 testbed, and only runs on setups which have multi-member portchannel uplinks.
- Configure all the supported hash fields for the ecmp and lag hash.
- Randomly select one hash field to test.
- If the hash field is DST_MAC, ETHERTYPE or VLAN_ID, take the steps 5-7, otherwise skip them.
- Choose one downlink interface and one uplink interface, remove all ip/ipv6 addresses on them.
- Remove the downlink interface from the existing vlan if it is t0 topology.
- For the DST_MAC, ETHERTYPE fields, add the chosen interfaces to a same vlan; For VLAN_ID field, add the interfaces to multiple vlans.
- Send traffic with changing values of the field under test from a downlink ptf port to uplink destination.
- Check the traffic is balanced over all the uplink ports.
- Randomly remove 1 member port from each uplink portchannels.
- Add the member ports back to the portchannels.
- Send the traffic again.
- Check the traffic is balanced over all uplink ports with no packet loss.
- The test is using the default links and routes in a t0/t1 testbed.
- Configure all the supported hash fields for the ecmp and lag hash.
- Randomly select one hash field to test.
- Randomly select a reboot type from reload or fast/warm/cold reboot, if reload or cold reboot, save the configuration before the reload/reboot.
- Send traffic with changing values of the field under test from a downlink ptf port to uplink destination.
- Check the traffic is balanced over all the uplink ports.
- Do the reload/reboot.
- After the reload/reboot, check the generic hash config via cli, it should keep the same as it was before the reload/reboot.
- Send traffic again.
- Check the traffic is balanced over all the uplink ports.
- Config ecmp and lag hash via cli.
- Remove the ecmp hash key via redis cli.
- Check there is a warning printed in the syslog.
- Remove the lag hash key via redis cli.
- Check there is a warning printed in the syslog.
- Re-config the ecmp and lag hash via cli.
- Update the ecmp hash fields with an invalid value via redis cli.
- Check there is a warning printed in the syslog.
- Update the lag hash fields with an invalid value via redis cli.
- Check there is a warning printed in the syslog.
- Re-config the ecmp and lag hash via cli.
- Remove the generic hash key via redis cli.
- Check there is a warning printed in the syslog.