-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Implement ECMP for unsafe_routes #1332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
445ef40
Allow defining multiple vias for a route.
dioss-Machiel ff9fecc
Implement failover for multipath routes.
dioss-Machiel 4d8cb52
Handle linux routing table updates
dioss-Machiel 1eaabb6
Implement weighted ECMP with hash-threshold mapping
dioss-Machiel 0cc2f98
Update config parser to allow setting a weight per gateway
dioss-Machiel 71eb668
Code review remarks: rename instances of "ip" to "addr"
dioss-Machiel 4f908e9
Code review remarks: resolve nits
dioss-Machiel 2ef6b46
Code review remarks: Move hashPacket and balancePacket
dioss-Machiel d78a038
Code review remarks: cache packet in original chosen gateway if no ga…
dioss-Machiel 5ca3550
Code review remarks: Don't force a crash or recovery
dioss-Machiel 2bb7f2c
Code review remarks: resolve nits
dioss-Machiel b59fb5d
Code review remarks: Create extra type for Gateways and improve logging
dioss-Machiel bda3573
Change hashing algorithm for ECMP routing.
dioss-Machiel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| package nebula | ||
|
|
||
| import ( | ||
| "net/netip" | ||
| "testing" | ||
|
|
||
| "github.com/slackhq/nebula/firewall" | ||
| "github.com/slackhq/nebula/routing" | ||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestPacketsAreBalancedEqually(t *testing.T) { | ||
|
|
||
| gateways := []routing.Gateway{} | ||
|
|
||
| gw1Ip := netip.MustParseAddr("1.0.0.1") | ||
| gw2Ip := netip.MustParseAddr("1.0.0.2") | ||
| gw3Ip := netip.MustParseAddr("1.0.0.3") | ||
|
|
||
| gateways = append(gateways, routing.NewGateway(gw1Ip, 1)) | ||
| gateways = append(gateways, routing.NewGateway(gw2Ip, 1)) | ||
| gateways = append(gateways, routing.NewGateway(gw3Ip, 1)) | ||
|
|
||
| routing.RebalanceGateways(gateways) | ||
|
|
||
| gw1count := 0 | ||
| gw2count := 0 | ||
| gw3count := 0 | ||
|
|
||
| iterationCount := uint16(65535) | ||
| for i := uint16(0); i < iterationCount; i++ { | ||
| packet := firewall.Packet{ | ||
| LocalAddr: netip.MustParseAddr("192.168.1.1"), | ||
| RemoteAddr: netip.MustParseAddr("10.0.0.1"), | ||
| LocalPort: i, | ||
| RemotePort: 65535 - i, | ||
| Protocol: 6, // TCP | ||
| Fragment: false, | ||
| } | ||
|
|
||
| selectedGw := balancePacket(&packet, gateways) | ||
|
|
||
| switch selectedGw { | ||
| case gw1Ip: | ||
| gw1count += 1 | ||
| case gw2Ip: | ||
| gw2count += 1 | ||
| case gw3Ip: | ||
| gw3count += 1 | ||
| } | ||
|
|
||
| } | ||
|
|
||
| // Assert packets are balanced, allow variation of up to 100 packets per gateway | ||
| assert.InDeltaf(t, iterationCount/3, gw1count, 100, "Expected %d +/- 100, but got %d", iterationCount/3, gw1count) | ||
| assert.InDeltaf(t, iterationCount/3, gw2count, 100, "Expected %d +/- 100, but got %d", iterationCount/3, gw1count) | ||
| assert.InDeltaf(t, iterationCount/3, gw3count, 100, "Expected %d +/- 100, but got %d", iterationCount/3, gw1count) | ||
|
|
||
| } | ||
|
|
||
| func TestPacketsAreBalancedByPriority(t *testing.T) { | ||
|
|
||
| gateways := []routing.Gateway{} | ||
|
|
||
| gw1Ip := netip.MustParseAddr("1.0.0.1") | ||
| gw2Ip := netip.MustParseAddr("1.0.0.2") | ||
|
|
||
| gateways = append(gateways, routing.NewGateway(gw1Ip, 10)) | ||
| gateways = append(gateways, routing.NewGateway(gw2Ip, 5)) | ||
|
|
||
| routing.RebalanceGateways(gateways) | ||
|
|
||
| gw1count := 0 | ||
| gw2count := 0 | ||
|
|
||
| iterationCount := uint16(65535) | ||
| for i := uint16(0); i < iterationCount; i++ { | ||
| packet := firewall.Packet{ | ||
| LocalAddr: netip.MustParseAddr("192.168.1.1"), | ||
| RemoteAddr: netip.MustParseAddr("10.0.0.1"), | ||
| LocalPort: i, | ||
| RemotePort: 65535 - i, | ||
| Protocol: 6, // TCP | ||
| Fragment: false, | ||
| } | ||
|
|
||
| selectedGw := balancePacket(&packet, gateways) | ||
|
|
||
| switch selectedGw { | ||
| case gw1Ip: | ||
| gw1count += 1 | ||
| case gw2Ip: | ||
| gw2count += 1 | ||
| } | ||
|
|
||
| } | ||
|
|
||
| iterationCountAsFloat := float32(iterationCount) | ||
|
|
||
| assert.InDeltaf(t, iterationCountAsFloat*(2.0/3.0), gw1count, 100, "Expected %d +/- 100, but got %d", iterationCountAsFloat*(2.0/3.0), gw1count) | ||
| assert.InDeltaf(t, iterationCountAsFloat*(1.0/3.0), gw2count, 100, "Expected %d +/- 100, but got %d", iterationCountAsFloat*(1.0/3.0), gw2count) | ||
| } |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.