server: jitter BFD control packet transmission - #3581
Open
notsrch wants to merge 1 commit into
Open
Conversation
RFC 5880 section 6.8.7 requires the interval between periodic BFD control packets to be reduced on every packet by a random value of 0 to 25%, and, when the detect multiplier is 1, to stay between 75% and 90% of the transmission interval. gobgp drove transmission with a fixed time.Ticker, so every packet left exactly on the configured period. Sessions that start at similar times therefore stay in lockstep, and a speaker with many BFD peers on the same interval transmits them as a repeating burst instead of spreading them across the period. Replace the ticker with a timer that is re-armed before each transmission with a fresh interval: a uniformly random 75% to 100% of the configured desired minimum TX interval, narrowed to 75% to 90% when the detect multiplier is 1. Re-arming before the packet is written keeps the time spent sending out of the gap between packets. The random source is randRange, which already picks the BFD source port. A new test pins the inclusive endpoints of both jitter windows. Fixes osrg#3562 Assisted-by: Claude Sonnet 5 <noreply@anthropic.com> Assisted-by: Claude Opus 5 <noreply@anthropic.com> Assisted-by: Claude Fable 5 <noreply@anthropic.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.
Fixes #3562.
What was wrong
The BFD transmit path drove transmission with a fixed
time.Ticker, so every control packet leftexactly on the configured period. RFC 5880 section 6.8.7 requires the interval to be reduced on
every packet by a random value of 0 to 25%, and to stay between 75% and 90% of the transmission
interval when the detect multiplier is 1. Without jitter, sessions that start at similar times stay
in lockstep, and a speaker with many BFD peers on the same interval transmits them as a repeating
burst instead of spreading them across the period.
What this changes
eventTxbecomes a*time.Timerthat the peer loop re-arms before each transmission with a freshinterval: a uniformly random 75% to 100% of the configured desired minimum TX interval, narrowed to
75% to 90% when the detect multiplier is 1. Re-arming before the packet is written keeps the time
spent sending out of the gap between packets, which matters against the 90% ceiling in the
multiplier-1 case.
The issue asked which random source to use: this uses
randRange, which already picks the BFDsource port. It draws whole percentage points rather than a continuous value (as the FSM's idle
hold-time jitter does), because 26 discrete values are directly assertable in a test and the RFC
only requires a random reduction within the window.
Jitter only shortens intervals, so the remote system's detection margin widens; it never rises
above the configured interval. Event-driven packets — poll replies and the poll sent on reaching
Up — are not periodic transmissions and are unchanged.
Out of scope, as proposed in the issue: raising the transmit interval to the peer's Required Min RX
Interval (#3563) and slowing transmission to one second while the session is down (#3564). Both
only change what base interval feeds the jitter, which now lives in one method; this PR changes the
type of
eventTxfirst so those can follow in sequence.Checks from the issue
Test_JitteredTxIntervaldraws the interval 1000times per case and asserts the observed minimum and maximum land exactly on 75% and 100% of the
configured interval. Endpoint equality also bounds every sample in between. The chance either
endpoint never appears is about 1e-17, so the test is not timing-dependent and cannot flake the
way a wall-clock packet capture in CI would.
narrowed endpoints (75% and 90%) for a multiplier-1 peer.
exceeds it, so the negotiated rate is still satisfied.
Test_TxPacketfails if the timer everstops re-arming, and the pre-existing state-transition and expiry tests all pass unchanged.
go test -race ./pkg/server/passes.Assisted-by: Claude noreply@anthropic.com