Skip to content

Commit

Permalink
Fix collecting for bfd sessions stucked in Init state (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
noevhlev authored May 9, 2023
1 parent 4468379 commit ca13cd9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion parser/bfd.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var (
)

func init() {
bfdSessionRegex = regexp.MustCompile(`^([^\s]+)\s+([^\s]+)\s+(Up|Down)\s+(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}|[^\s]+)\s+([0-9\.]+)\s+([0-9\.]+)$`)
bfdSessionRegex = regexp.MustCompile(`^([^\s]+)\s+([^\s]+)\s+(Up|Down|Init)\s+(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}|[^\s]+)\s+([0-9\.]+)\s+([0-9\.]+)$`)
}

type bfdContext struct {
Expand Down
16 changes: 13 additions & 3 deletions parser/bfd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ func TestParseBFDSessions(t *testing.T) {
bfd1:
IP address Interface State Since Interval Timeout
192.168.64.9 enp0s2 Up 2022-01-27 09:00:00 0.100 1.000
192.168.64.10 enp0s2 Down 2022-01-27 08:00:00 0.300 0.000`
192.168.64.10 enp0s2 Down 2022-01-27 08:00:00 0.300 0.000
192.168.64.12 enp0s2 Init 2022-01-27 08:00:00 0.300 5.000`

s := ParseBFDSessions("bfd1", []byte(data))

assert.Equal(t, 2, len(s), "session count")
assert.Equal(t, 3, len(s), "session count")

s1 := protocol.BFDSession{
ProtocolName: "bfd1",
Expand All @@ -41,5 +42,14 @@ IP address Interface State Since Interval Timeout
Interval: 0.3,
Timeout: 0,
}
assert.Equal(t, []*protocol.BFDSession{&s1, &s2}, s, "sessions")
s3 := protocol.BFDSession{
ProtocolName: "bfd1",
IP: "192.168.64.12",
Interface: "enp0s2",
Up: false,
Since: 7200,
Interval: 0.3,
Timeout: 5,
}
assert.Equal(t, []*protocol.BFDSession{&s1, &s2, &s3}, s, "sessions")
}

0 comments on commit ca13cd9

Please sign in to comment.