Fix LAG member selection using packet data hash - #1423
Open
Devansh-567 wants to merge 1 commit into
Open
Conversation
…data hash Signed-off-by: Devansh-567 <devansh.jay.singh@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:Since
lag_hashnever 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 newuint64_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 plainMcSimplePre) are unaffected because it defaults to 0.McSimplePreLAG::replicate()now usesingress_info.hashinstead of the hardcoded0xFF.simple_switchandpsa_switch(the two targets that useMcSimplePreLAG) now compute a hash of the packet's bytes with the existingbm::hash::xxh64helper 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
McSimplePreLAG.LAGHashSelectsMemberintests/test_pre.cpp: creates a 4-member LAG and callsreplicate()with several differenthashvalues, asserting that the selected member follows the expectedhash % member_countmapping 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).cmake+ctest, withWITH_THRIFT=ON -DWITH_NANOMSG=ON -DWITH_TARGETS=ON): 46/47 tests pass. The one failure (test_switch/SerializeState2) is unrelated to thischange, it's an environment issue (missing Python
thriftmodule forruntime_CLI.pyin the sandbox used to test this), not a regression.simple_switchandpsa_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.tools/cpplint.pyon all changed files; confirmed zero new lint warnings versus the pre-change baseline (the warnings cpplint reports inpsa_switch.cppandsimple_pre.hare pre-existing, unrelated to the lines touched here).Files changed
include/bm/bm_sim/simple_pre.hsrc/bm_sim/simple_pre_lag.cpptargets/simple_switch/simple_switch.cpptargets/psa_switch/psa_switch.cpptests/test_pre.cpp