Skip to content

Commit d9098f3

Browse files
authored
Add support for sinceEpoch field in bfd session (#97)
* Add support for sinceEpoch field in bfd session * Switch to defaulting of the type
1 parent a0396f6 commit d9098f3

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

parser/bfd.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var (
1414
)
1515

1616
func init() {
17-
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\.]+)$`)
17+
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\.]+)$`)
1818
}
1919

2020
type bfdContext struct {
@@ -45,14 +45,19 @@ func parseBFDSessionLine(c *bfdContext) {
4545
if m == nil {
4646
return
4747
}
48+
var since_epoch int64
49+
if m[5] != "" {
50+
since_epoch = parseInt(m[5])
51+
}
4852

4953
sess := protocol.BFDSession{
5054
ProtocolName: c.protocol,
5155
IP: m[1],
5256
Interface: m[2],
5357
Since: parseUptime(m[4]),
54-
Interval: parseFloat(m[5]),
55-
Timeout: parseFloat(m[6]),
58+
SinceEpoch: since_epoch,
59+
Interval: parseFloat(m[6]),
60+
Timeout: parseFloat(m[7]),
5661
}
5762

5863
if m[3] == "Up" {

parser/bfd_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func TestParseBFDSessions(t *testing.T) {
1616
data := `BIRD 2.0.7 ready.
1717
bfd1:
1818
IP address Interface State Since Interval Timeout
19-
192.168.64.9 enp0s2 Up 2022-01-27 09:00:00 0.100 1.000
19+
192.168.64.9 enp0s2 Up 2022-01-27 09:00:00 1697620076 0.100 1.000
2020
192.168.64.10 enp0s2 Down 2022-01-27 08:00:00 0.300 0.000
2121
192.168.64.12 enp0s2 Init 2022-01-27 08:00:00 0.300 5.000`
2222

@@ -30,6 +30,7 @@ IP address Interface State Since Interval Timeout
3030
Interface: "enp0s2",
3131
Up: true,
3232
Since: 3600,
33+
SinceEpoch: 1697620076,
3334
Interval: 0.1,
3435
Timeout: 1,
3536
}
@@ -39,6 +40,7 @@ IP address Interface State Since Interval Timeout
3940
Interface: "enp0s2",
4041
Up: false,
4142
Since: 7200,
43+
SinceEpoch: 0,
4244
Interval: 0.3,
4345
Timeout: 0,
4446
}
@@ -48,6 +50,7 @@ IP address Interface State Since Interval Timeout
4850
Interface: "enp0s2",
4951
Up: false,
5052
Since: 7200,
53+
SinceEpoch: 0,
5154
Interval: 0.3,
5255
Timeout: 5,
5356
}

protocol/bfd_session.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ type BFDSession struct {
66
Interface string
77
Up bool
88
Since int
9+
SinceEpoch int64
910
Interval float64
1011
Timeout float64
1112
}

0 commit comments

Comments
 (0)