Skip to content

Commit

Permalink
Add support for sinceEpoch field in bfd session (#97)
Browse files Browse the repository at this point in the history
* Add support for sinceEpoch field in bfd session

* Switch to defaulting of the type
  • Loading branch information
unixsurfer authored Oct 26, 2023
1 parent a0396f6 commit d9098f3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
11 changes: 8 additions & 3 deletions 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|Init)\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+(\d{1,})?\s+([0-9\.]+)\s+([0-9\.]+)$`)
}

type bfdContext struct {
Expand Down Expand Up @@ -45,14 +45,19 @@ func parseBFDSessionLine(c *bfdContext) {
if m == nil {
return
}
var since_epoch int64
if m[5] != "" {
since_epoch = parseInt(m[5])
}

sess := protocol.BFDSession{
ProtocolName: c.protocol,
IP: m[1],
Interface: m[2],
Since: parseUptime(m[4]),
Interval: parseFloat(m[5]),
Timeout: parseFloat(m[6]),
SinceEpoch: since_epoch,
Interval: parseFloat(m[6]),
Timeout: parseFloat(m[7]),
}

if m[3] == "Up" {
Expand Down
5 changes: 4 additions & 1 deletion parser/bfd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestParseBFDSessions(t *testing.T) {
data := `BIRD 2.0.7 ready.
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.9 enp0s2 Up 2022-01-27 09:00:00 1697620076 0.100 1.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`

Expand All @@ -30,6 +30,7 @@ IP address Interface State Since Interval Timeout
Interface: "enp0s2",
Up: true,
Since: 3600,
SinceEpoch: 1697620076,
Interval: 0.1,
Timeout: 1,
}
Expand All @@ -39,6 +40,7 @@ IP address Interface State Since Interval Timeout
Interface: "enp0s2",
Up: false,
Since: 7200,
SinceEpoch: 0,
Interval: 0.3,
Timeout: 0,
}
Expand All @@ -48,6 +50,7 @@ IP address Interface State Since Interval Timeout
Interface: "enp0s2",
Up: false,
Since: 7200,
SinceEpoch: 0,
Interval: 0.3,
Timeout: 5,
}
Expand Down
1 change: 1 addition & 0 deletions protocol/bfd_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type BFDSession struct {
Interface string
Up bool
Since int
SinceEpoch int64
Interval float64
Timeout float64
}

0 comments on commit d9098f3

Please sign in to comment.