Skip to content

Commit

Permalink
Merge pull request #116 from cjeker/fix_count_in_processData
Browse files Browse the repository at this point in the history
Don't count the wrong things
  • Loading branch information
ties authored Feb 29, 2024
2 parents b773a90 + 48740ff commit 78a0c69
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
10 changes: 6 additions & 4 deletions cmd/stayrtr/stayrtr.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,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 @@ -338,7 +338,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 @@ -387,7 +387,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 @@ -429,7 +430,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

0 comments on commit 78a0c69

Please sign in to comment.