Skip to content

Fix LAG member selection using packet data hash - #1423

Open
Devansh-567 wants to merge 1 commit into
p4lang:mainfrom
Devansh-567:fix-lag-member-selection
Open

Fix LAG member selection using packet data hash#1423
Devansh-567 wants to merge 1 commit into
p4lang:mainfrom
Devansh-567:fix-lag-member-selection

Conversation

@Devansh-567

Copy link
Copy Markdown
Contributor

Problem

In McSimplePreLAG::replicate() (src/bm_sim/simple_pre_lag.cpp), the value used to pick a member port within a LAG was a hardcoded constant:

int lag_hash = 0xFF;  // TODO(unknown): get lag hash from metadata
...
port_count1 = (lag_hash % lag_entry.member_count) + 1;

Since lag_hash never varies, every packet replicated through a given LAG always resolves to the same member index, defeating the entire point of a LAG (spreading traffic across members).

Fix

  • McSimplePre::McIn (include/bm/bm_sim/simple_pre.h) gains a new uint64_t hash{0} field. Callers that replicate over a LAG populate it with a hash derived from per-packet data; callers/targets that don't care about LAGs (e.g. l2_switch, which uses plain McSimplePre) are unaffected because it defaults to 0.
  • McSimplePreLAG::replicate() now uses ingress_info.hash instead of the hardcoded 0xFF.
  • simple_switch and psa_switch (the two targets that use McSimplePreLAG) now compute a hash of the packet's bytes with the existing bm::hash::xxh64 helper and pass it through: pre->replicate({mgid, lag_hash}). Hashing the packet's own bytes (rather than e.g. a monotonic counter) means packets from the same flow keep landing on the same LAG member, which is the behavior real LAG hashing is expected to have.

Testing

  • Added McSimplePreLAG.LAGHashSelectsMember in tests/test_pre.cpp: creates a 4-member LAG and calls replicate() with several different hash values, asserting that the selected member follows the expected hash % member_count mapping and that all 4 members are reachable (this test would have failed before the fix, since every hash value used to resolve to the same member).
  • Built and ran the full test suite locally (cmake + ctest, with WITH_THRIFT=ON -DWITH_NANOMSG=ON -DWITH_TARGETS=ON): 46/47 tests pass. The one failure (test_switch/SerializeState2) is unrelated to this
    change, it's an environment issue (missing Python thrift module for runtime_CLI.py in the sandbox used to test this), not a regression.
  • Verified simple_switch and psa_switch (the two targets touched) build and their own test suites (test_packet_redirect, test_swap, test_queueing, test_recirc, test_parser_error, test_hash, test_internet_checksum) pass unchanged.
  • Ran tools/cpplint.py on all changed files; confirmed zero new lint warnings versus the pre-change baseline (the warnings cpplint reports in psa_switch.cpp and simple_pre.h are pre-existing, unrelated to the lines touched here).

Files changed

  • include/bm/bm_sim/simple_pre.h
  • src/bm_sim/simple_pre_lag.cpp
  • targets/simple_switch/simple_switch.cpp
  • targets/psa_switch/psa_switch.cpp
  • tests/test_pre.cpp

…data hash

Signed-off-by: Devansh-567 <devansh.jay.singh@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant