wgengine/router: consolidate routes before reconfiguring router for mobile clients
This helps reduce memory pressure on tailnets with large numbers of routes. Updates tailscale/corp#19332 Signed-off-by: Percy Wegmann <percy@tailscale.com>
This commit is contained in:

committed by
Percy Wegmann

parent
add62af7c6
commit
c8e912896e
68
wgengine/router/consolidating_router_test.go
Normal file
68
wgengine/router/consolidating_router_test.go
Normal file
@ -0,0 +1,68 @@
|
||||
// Copyright (c) Tailscale Inc & AUTHORS
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
package router
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/netip"
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
)
|
||||
|
||||
func TestConsolidateRoutes(t *testing.T) {
|
||||
parseRoutes := func(routes ...string) []netip.Prefix {
|
||||
parsed := make([]netip.Prefix, 0, len(routes))
|
||||
for _, routeString := range routes {
|
||||
route, err := netip.ParsePrefix(routeString)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
parsed = append(parsed, route)
|
||||
}
|
||||
return parsed
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
cfg *Config
|
||||
want *Config
|
||||
}{
|
||||
{
|
||||
"nil cfg",
|
||||
nil,
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"single route",
|
||||
&Config{Routes: parseRoutes("10.0.0.0/32")},
|
||||
&Config{Routes: parseRoutes("10.0.0.0/32")},
|
||||
},
|
||||
{
|
||||
"two routes from different families",
|
||||
&Config{Routes: parseRoutes("10.0.0.0/32", "2603:1030:c02::/47")},
|
||||
&Config{Routes: parseRoutes("10.0.0.0/32", "2603:1030:c02::/47")},
|
||||
},
|
||||
{
|
||||
"two disjoint routes",
|
||||
&Config{Routes: parseRoutes("10.0.0.0/32", "10.0.2.0/32")},
|
||||
&Config{Routes: parseRoutes("10.0.0.0/32", "10.0.2.0/32")},
|
||||
},
|
||||
{
|
||||
"two overlapping routes",
|
||||
&Config{Routes: parseRoutes("10.0.0.0/32", "10.0.0.0/31")},
|
||||
&Config{Routes: parseRoutes("10.0.0.0/31")},
|
||||
},
|
||||
}
|
||||
|
||||
cr := &consolidatingRouter{logf: log.Printf}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
got := cr.consolidateRoutes(test.cfg)
|
||||
if diff := cmp.Diff(got, test.want); diff != "" {
|
||||
t.Errorf("wrong result; (-got+want):%v", diff)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user