-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparse_test.go
More file actions
190 lines (179 loc) · 6.04 KB
/
parse_test.go
File metadata and controls
190 lines (179 loc) · 6.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
package main
import (
"net"
"reflect"
"testing"
"time"
)
var StatusInDefault = `
BIRD 2.15.1 ready.
BIRD 2.15.1
Router ID is 192.168.32.79
Hostname is infra2
Current server time is 2024-10-13 14:39:40.531
Last reboot on 2024-10-12 20:41:10.197
Last reconfiguration on 2024-10-13 09:25:06.844
Daemon is up and running
`
func TestParseShowStatus(t *testing.T) {
type args struct {
in string
}
tests := []struct {
name string
args args
want ShowStatus
}{
{name: "show status", args: args{in: StatusInDefault}, want: ShowStatus{RouterId: net.IP{192, 168, 32, 79}.To16(), Hostname: "infra2"}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := ParseShowStatus(tt.args.in); !reflect.DeepEqual(got, tt.want) {
t.Errorf("ParseShowStatus() = %+v, want %+v", got, tt.want)
}
})
}
}
var showProtocolsAllDefault = `
BIRD 2.15.1 ready.
Name Proto Table State Since Info
helpers Static master4 up 2024-10-12 20:41:10
Channel ipv4
State: UP
Table: master4
Preference: 200
Input filter: ACCEPT
Output filter: ACCEPT
Routes: 0 imported, 0 exported, 0 preferred
Route change stats: received rejected filtered ignored accepted
Import updates: 0 0 0 0 0
Import withdraws: 0 0 --- 0 0
Export updates: 0 0 0 --- 0
Export withdraws: 0 --- --- --- 0
device1 Device --- up 2024-10-12 20:41:10
direct1 Direct --- up 2024-10-12 20:41:10
Channel ipv4
State: UP
Table: master4
Preference: 240
Input filter: ACCEPT
Output filter: REJECT
Routes: 2 imported, 0 exported, 2 preferred
Route change stats: received rejected filtered ignored accepted
Import updates: 2 0 0 0 2
Import withdraws: 0 0 --- 0 0
Export updates: 0 0 0 --- 0
Export withdraws: 0 --- --- --- 0
Channel ipv6
State: UP
Table: master6
Preference: 240
Input filter: ACCEPT
Output filter: REJECT
Routes: 2 imported, 0 exported, 2 preferred
Route change stats: received rejected filtered ignored accepted
Import updates: 2 0 0 0 2
Import withdraws: 0 0 --- 0 0
Export updates: 0 0 0 --- 0
Export withdraws: 0 --- --- --- 0
ber1_gw1 BGP --- up 2024-10-12 20:41:14 Established
BGP state: Established
Neighbor address: 192.168.32.1
Neighbor AS: 64846
Local AS: 64846
Neighbor ID: 192.168.32.1
Local capabilities
Multiprotocol
AF announced: ipv4
Route refresh
Graceful restart
4-octet AS numbers
Enhanced refresh
Long-lived graceful restart
Neighbor capabilities
Multiprotocol
AF announced: ipv4
Route refresh
4-octet AS numbers
Session: internal multihop AS4
Source address: 192.168.32.79
Hold timer: 10.639/15
Keepalive timer: 0.627/5
Send hold timer: 24.635/30
Channel ipv4
State: UP
Table: master4
Preference: 100
Input filter: (unnamed)
Output filter: (unnamed)
Routes: 21 imported, 0 exported, 21 preferred
Route change stats: received rejected filtered ignored accepted
Import updates: 1674 0 0 18 1656
Import withdraws: 459 0 --- 0 459
Export updates: 1658 1656 2 --- 0
Export withdraws: 459 --- --- --- 0
BGP Next hop: 192.168.32.79
IGP IPv4 table: master4
xxx_gw1 BGP --- start 2024-10-13 09:25:06 Active Socket: No route to host
BGP state: Active
Neighbor address: 192.168.32.253
Neighbor AS: 64846
Local AS: 64846
Connect delay: 3.102/5
Last error: Socket: No route to host
Channel ipv4
State: DOWN
Table: master4
Preference: 100
Input filter: (unnamed)
Output filter: (unnamed)
IGP IPv4 table: master4
`
func mustParseTime(t time.Time, err error) time.Time {
if err != nil {
panic(err)
}
return t
}
func TestParseShowProtocolsAll(t *testing.T) {
type args struct {
in string
}
tests := []struct {
name string
args args
want []ProtocolBGPStatus
}{
{name: "show protocols all", args: args{in: showProtocolsAllDefault}, want: []ProtocolBGPStatus{
{
Name: "ber1_gw1",
Table: "",
Up: true,
State: "Established",
Since: mustParseTime(time.Parse(time.DateTime, "2024-10-12 20:41:14")),
NeighborAddress: net.IPv4(192, 168, 32, 1),
LocalAs: 64846,
Channels: map[string]ProtocolBGPChannel{
"ipv4": {Name: "ipv4", Imported: 21, Exported: 0, Preferred: 21},
},
},
{
Name: "xxx_gw1",
Table: "",
Up: false,
State: "Active",
Since: mustParseTime(time.Parse(time.DateTime, "2024-10-13 09:25:06")),
NeighborAddress: net.IPv4(192, 168, 32, 253),
LocalAs: 64846,
Channels: map[string]ProtocolBGPChannel{},
},
}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := ParseShowProtocolsAll(tt.args.in); !reflect.DeepEqual(got, tt.want) {
t.Errorf("ParseShowProtocolsAll() = %v, want %v", got, tt.want)
}
})
}
}