From 7e254ab26fd5b382be6bcce28c1368e1808567b6 Mon Sep 17 00:00:00 2001 From: Pavlos Parisis Date: Wed, 18 Oct 2023 13:30:30 +0200 Subject: [PATCH] Add support for sinceEpoch field in bfd session --- parser/bfd.go | 13 ++++++++++--- parser/bfd_test.go | 5 ++++- protocol/bfd_session.go | 1 + 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/parser/bfd.go b/parser/bfd.go index 0d3dd5e..d50fd78 100644 --- a/parser/bfd.go +++ b/parser/bfd.go @@ -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 { @@ -45,14 +45,21 @@ func parseBFDSessionLine(c *bfdContext) { if m == nil { return } + var since_epoch int64 + if m[5] == "" { + since_epoch = 0 + } else { + 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" { diff --git a/parser/bfd_test.go b/parser/bfd_test.go index 665a062..9e6e527 100644 --- a/parser/bfd_test.go +++ b/parser/bfd_test.go @@ -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` @@ -30,6 +30,7 @@ IP address Interface State Since Interval Timeout Interface: "enp0s2", Up: true, Since: 3600, + SinceEpoch: 1697620076, Interval: 0.1, Timeout: 1, } @@ -39,6 +40,7 @@ IP address Interface State Since Interval Timeout Interface: "enp0s2", Up: false, Since: 7200, + SinceEpoch: 0, Interval: 0.3, Timeout: 0, } @@ -48,6 +50,7 @@ IP address Interface State Since Interval Timeout Interface: "enp0s2", Up: false, Since: 7200, + SinceEpoch: 0, Interval: 0.3, Timeout: 5, } diff --git a/protocol/bfd_session.go b/protocol/bfd_session.go index 26a450b..d80a92c 100644 --- a/protocol/bfd_session.go +++ b/protocol/bfd_session.go @@ -6,6 +6,7 @@ type BFDSession struct { Interface string Up bool Since int + SinceEpoch int64 Interval float64 Timeout float64 }