Skip to content
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

Don't count the wrong things #116

Merged
merged 2 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions cmd/stayrtr/stayrtr.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func isValidPrefixLength(prefix netip.Prefix, maxLength uint8) bool {
// Will return a deduped slice, as well as total VRPs, IPv4 VRPs, IPv6 VRPs, BGPsec Keys and ASPA records
func processData(vrplistjson []prefixfile.VRPJson,
brklistjson []prefixfile.BgpSecKeyJson,
aspajson []prefixfile.VAPJson) /*Export*/ ([]rtr.VRP, []rtr.BgpsecKey, []rtr.VAP, int, int, int) {
aspajson []prefixfile.VAPJson) /*Export*/ ([]rtr.VRP, []rtr.BgpsecKey, []rtr.VAP, int, int) {
filterDuplicates := make(map[string]struct{})

// It may be tempting to change this to a simple time.Since() but that will
Expand Down Expand Up @@ -331,7 +331,7 @@ func processData(vrplistjson []prefixfile.VRPJson,
})
}

return vrplist, brklist, aspalist, countv4 + countv6, countv4, countv6
return vrplist, brklist, aspalist, countv4, countv6
}

type IdenticalFile struct {
Expand Down Expand Up @@ -380,7 +380,8 @@ func (s *state) updateFromNewState() error {
vrpsjson, aspajson, bgpsecjson = s.slurm.FilterAssert(vrpsjson, aspajson, bgpsecjson, log.StandardLogger())
}

vrps, brks, vaps, count, countv4, countv6 := processData(vrpsjson, bgpsecjson, aspajson)
vrps, brks, vaps, countv4, countv6 := processData(vrpsjson, bgpsecjson, aspajson)
count := len(vrps) + len(brks) + len(vaps)

log.Infof("New update (%v uniques, %v total prefixes, %v vaps, %v router keys).", len(vrps), count, len(vaps), len(brks))
return s.applyUpdateFromNewState(vrps, brks, vaps, sessid, vrpsjson, bgpsecjson, aspajson, countv4, countv6)
Expand Down Expand Up @@ -422,7 +423,8 @@ func (s *state) reloadFromCurrentState() error {
vrpsjson, aspajson, bgpsecjson = s.slurm.FilterAssert(vrpsjson, aspajson, bgpsecjson, log.StandardLogger())
}

vrps, brks, vaps, count, countv4, countv6 := processData(vrpsjson, bgpsecjson, aspajson)
vrps, brks, vaps, countv4, countv6 := processData(vrpsjson, bgpsecjson, aspajson)
count := len(vrps) + len(brks) + len(vaps)
if s.server.CountSDs() != count {
log.Infof("New update to old state (%v uniques, %v total prefixes). (old %v - new %v)", len(vrps), count, s.server.CountSDs(), count)
return s.applyUpdateFromNewState(vrps, brks, vaps, sessid, vrpsjson, bgpsecjson, aspajson, countv4, countv6)
Expand Down
6 changes: 3 additions & 3 deletions cmd/stayrtr/stayrtr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func TestProcessData(t *testing.T) {
Expires: &ExpiredTime,
},
)
got, _, _, count, v4count, v6count := processData(stuff, nil, nil)
got, _, _, v4count, v6count := processData(stuff, nil, nil)
want := []rtr.VRP{
{
Prefix: netip.MustParsePrefix("2001:db8::/32"),
Expand All @@ -118,8 +118,8 @@ func TestProcessData(t *testing.T) {
ASN: 123,
},
}
if count != 3 || v4count != 2 || v6count != 1 {
t.Errorf("Wanted count = 3, v4count = 2, v6count = 1, but got %d, %d, %d", count, v4count, v6count)
if v4count != 2 || v6count != 1 {
t.Errorf("Wanted v4count = 2, v6count = 1, but got %d, %d", v4count, v6count)
}

opts := []cmp.Option{
Expand Down
Loading