forked from ligato/vpp-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dump.go
433 lines (384 loc) · 12 KB
/
dump.go
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
package configurator
import (
"errors"
"github.com/ligato/cn-infra/logging"
"golang.org/x/net/context"
rpc "github.com/ligato/vpp-agent/api/configurator"
vpp_abf "github.com/ligato/vpp-agent/api/models/vpp/abf"
vpp_acl "github.com/ligato/vpp-agent/api/models/vpp/acl"
vpp_interfaces "github.com/ligato/vpp-agent/api/models/vpp/interfaces"
vpp_ipsec "github.com/ligato/vpp-agent/api/models/vpp/ipsec"
vpp_l2 "github.com/ligato/vpp-agent/api/models/vpp/l2"
vpp_l3 "github.com/ligato/vpp-agent/api/models/vpp/l3"
vpp_nat "github.com/ligato/vpp-agent/api/models/vpp/nat"
vpp_punt "github.com/ligato/vpp-agent/api/models/vpp/punt"
iflinuxcalls "github.com/ligato/vpp-agent/plugins/linux/ifplugin/linuxcalls"
l3linuxcalls "github.com/ligato/vpp-agent/plugins/linux/l3plugin/linuxcalls"
abfvppcalls "github.com/ligato/vpp-agent/plugins/vpp/abfplugin/vppcalls"
aclvppcalls "github.com/ligato/vpp-agent/plugins/vpp/aclplugin/vppcalls"
ifvppcalls "github.com/ligato/vpp-agent/plugins/vpp/ifplugin/vppcalls"
ipsecvppcalls "github.com/ligato/vpp-agent/plugins/vpp/ipsecplugin/vppcalls"
l2vppcalls "github.com/ligato/vpp-agent/plugins/vpp/l2plugin/vppcalls"
l3vppcalls "github.com/ligato/vpp-agent/plugins/vpp/l3plugin/vppcalls"
natvppcalls "github.com/ligato/vpp-agent/plugins/vpp/natplugin/vppcalls"
"github.com/ligato/vpp-agent/plugins/vpp/puntplugin/vppcalls"
)
type dumpService struct {
log logging.Logger
// VPP Handlers
// core
ifHandler ifvppcalls.InterfaceVppRead
l2Handler l2vppcalls.L2VppAPI
l3Handler l3vppcalls.L3VppAPI
ipsecHandler ipsecvppcalls.IPSecVPPRead
// plugins
aclHandler aclvppcalls.ACLVppRead
abfHandler abfvppcalls.ABFVppRead
natHandler natvppcalls.NatVppRead
puntHandler vppcalls.PuntVPPRead
// Linux handlers
linuxIfHandler iflinuxcalls.NetlinkAPIRead
linuxL3Handler l3linuxcalls.NetlinkAPIRead
}
// Dump implements Dump method for Configurator
func (svc *dumpService) Dump(context.Context, *rpc.DumpRequest) (*rpc.DumpResponse, error) {
defer trackOperation("Dump")()
svc.log.Debugf("Received Dump request..")
dump := newConfig()
var err error
// core
dump.VppConfig.Interfaces, err = svc.DumpInterfaces()
if err != nil {
svc.log.Errorf("DumpInterfaces failed: %v", err)
return nil, err
}
dump.VppConfig.BridgeDomains, err = svc.DumpBDs()
if err != nil {
svc.log.Errorf("DumpBDs failed: %v", err)
return nil, err
}
dump.VppConfig.Fibs, err = svc.DumpFIBs()
if err != nil {
svc.log.Errorf("DumpFIBs failed: %v", err)
return nil, err
}
dump.VppConfig.XconnectPairs, err = svc.DumpXConnects()
if err != nil {
svc.log.Errorf("DumpXConnects failed: %v", err)
return nil, err
}
dump.VppConfig.Routes, err = svc.DumpRoutes()
if err != nil {
svc.log.Errorf("DumpRoutes failed: %v", err)
return nil, err
}
dump.VppConfig.Arps, err = svc.DumpARPs()
if err != nil {
svc.log.Errorf("DumpARPs failed: %v", err)
return nil, err
}
dump.VppConfig.IpsecSpds, err = svc.DumpIPSecSPDs()
if err != nil {
svc.log.Errorf("DumpIPSecSPDs failed: %v", err)
return nil, err
}
dump.VppConfig.IpsecSas, err = svc.DumpIPSecSAs()
if err != nil {
svc.log.Errorf("DumpIPSecSAs failed: %v", err)
return nil, err
}
// plugins
dump.VppConfig.Acls, err = svc.DumpACLs()
if err != nil {
svc.log.Errorf("DumpACLs failed: %v", err)
return nil, err
}
dump.VppConfig.Abfs, err = svc.DumpABFs()
if err != nil {
svc.log.Errorf("DumpABFs failed: %v", err)
return nil, err
}
dump.VppConfig.Nat44Global, err = svc.DumpNAT44Global()
if err != nil {
svc.log.Errorf("DumpNAT44Global failed: %v", err)
return nil, err
}
dump.VppConfig.Dnat44S, err = svc.DumpDNAT44s()
if err != nil {
svc.log.Errorf("DumpDNAT44s failed: %v", err)
return nil, err
}
dump.VppConfig.PuntTohosts, err = svc.DumpPunt()
if err != nil {
svc.log.Errorf("DumpPunt failed: %v", err)
return nil, err
}
dump.VppConfig.PuntExceptions, err = svc.DumpPuntExceptions()
if err != nil {
svc.log.Errorf("DumpPuntExceptions failed: %v", err)
return nil, err
}
// FIXME: linux interfaces should return known proto instead of netlink
// state.LinuxData.Interfaces, _ = svc.DumpLinuxInterfaces()
return &rpc.DumpResponse{Dump: dump}, nil
}
// DumpInterfaces reads interfaces and returns them as an *InterfaceResponse. If reading ends up with error,
// only error is send back in response
func (svc *dumpService) DumpInterfaces() (ifs []*vpp_interfaces.Interface, err error) {
if svc.ifHandler == nil {
// handler is not available
return nil, nil
}
ifDetails, err := svc.ifHandler.DumpInterfaces()
if err != nil {
return nil, err
}
for _, iface := range ifDetails {
ifs = append(ifs, iface.Interface)
}
return ifs, nil
}
// DumpIPSecSPDs reads IPSec SPD and returns them as an *IPSecSPDResponse. If reading ends up with error,
// only error is send back in response
func (svc *dumpService) DumpIPSecSPDs() (spds []*vpp_ipsec.SecurityPolicyDatabase, err error) {
if svc.ipsecHandler == nil {
// handler is not available
return nil, nil
}
spdDetails, err := svc.ipsecHandler.DumpIPSecSPD()
if err != nil {
return nil, err
}
for _, spd := range spdDetails {
spds = append(spds, spd.Spd)
}
return spds, nil
}
// DumpIPSecSAs reads IPSec SA and returns them as an *IPSecSAResponse. If reading ends up with error,
// only error is send back in response
func (svc *dumpService) DumpIPSecSAs() (sas []*vpp_ipsec.SecurityAssociation, err error) {
if svc.ipsecHandler == nil {
// handler is not available
return nil, nil
}
saDetails, err := svc.ipsecHandler.DumpIPSecSA()
if err != nil {
return nil, err
}
for _, sa := range saDetails {
sas = append(sas, sa.Sa)
}
return sas, nil
}
// DumpBDs reads bridge domains and returns them as an *BDResponse. If reading ends up with error,
// only error is send back in response
func (svc *dumpService) DumpBDs() (bds []*vpp_l2.BridgeDomain, err error) {
if svc.l2Handler == nil {
// handler is not available
return nil, nil
}
bdDetails, err := svc.l2Handler.DumpBridgeDomains()
if err != nil {
return nil, err
}
for _, bd := range bdDetails {
bds = append(bds, bd.Bd)
}
return bds, nil
}
// DumpFIBs reads FIBs and returns them as an *FibResponse. If reading ends up with error,
// only error is send back in response
func (svc *dumpService) DumpFIBs() (fibs []*vpp_l2.FIBEntry, err error) {
if svc.l2Handler == nil {
// handler is not available
return nil, nil
}
fibDetails, err := svc.l2Handler.DumpL2FIBs()
if err != nil {
return nil, err
}
for _, fib := range fibDetails {
fibs = append(fibs, fib.Fib)
}
return fibs, nil
}
// DumpXConnects reads cross connects and returns them as an *XcResponse. If reading ends up with error,
// only error is send back in response
func (svc *dumpService) DumpXConnects() (xcs []*vpp_l2.XConnectPair, err error) {
if svc.l2Handler == nil {
// handler is not available
return nil, nil
}
xcDetails, err := svc.l2Handler.DumpXConnectPairs()
if err != nil {
return nil, err
}
for _, xc := range xcDetails {
xcs = append(xcs, xc.Xc)
}
return xcs, nil
}
// DumpRoutes reads VPP routes and returns them as an *RoutesResponse. If reading ends up with error,
// only error is send back in response
func (svc *dumpService) DumpRoutes() (routes []*vpp_l3.Route, err error) {
if svc.l3Handler == nil {
// handler is not available
return nil, nil
}
rtDetails, err := svc.l3Handler.DumpRoutes()
if err != nil {
return nil, err
}
for _, rt := range rtDetails {
routes = append(routes, rt.Route)
}
return routes, nil
}
// DumpARPs reads VPP ARPs and returns them as an *ARPsResponse. If reading ends up with error,
// only error is send back in response
func (svc *dumpService) DumpARPs() (arps []*vpp_l3.ARPEntry, err error) {
if svc.l3Handler == nil {
// handler is not available
return nil, nil
}
arpDetails, err := svc.l3Handler.DumpArpEntries()
if err != nil {
return nil, err
}
for _, arp := range arpDetails {
arps = append(arps, arp.Arp)
}
return arps, nil
}
// DumpACLs reads IP/MACIP access lists and returns them as an *AclResponse. If reading ends up with error,
// only error is send back in response
func (svc *dumpService) DumpACLs() (acls []*vpp_acl.ACL, err error) {
if svc.aclHandler == nil {
// handler is not available
return nil, nil
}
ipACLs, err := svc.aclHandler.DumpACL()
if err != nil {
return nil, err
}
macIPACLs, err := svc.aclHandler.DumpMACIPACL()
if err != nil {
return nil, err
}
for _, aclDetails := range ipACLs {
acls = append(acls, aclDetails.ACL)
}
for _, aclDetails := range macIPACLs {
acls = append(acls, aclDetails.ACL)
}
return acls, nil
}
// DumpABFs reads the ACL-based forwarding and returns data read as an *AbfResponse. If the reading ends up with
// an error, only the error is send back in the response
func (svc *dumpService) DumpABFs() (abfs []*vpp_abf.ABF, err error) {
if svc.abfHandler == nil {
// handler is not available
return nil, nil
}
abfPolicy, err := svc.abfHandler.DumpABFPolicy()
if err != nil {
return nil, err
}
for _, abfDetails := range abfPolicy {
abfs = append(abfs, abfDetails.ABF)
}
return abfs, nil
}
// DumpNAT44GLobal dumps NAT44Global
func (svc *dumpService) DumpNAT44Global() (glob *vpp_nat.Nat44Global, err error) {
if svc.natHandler == nil {
// handler is not available
return nil, nil
}
glob, err = svc.natHandler.Nat44GlobalConfigDump()
if err != nil {
return nil, err
}
return glob, nil
}
// DumpDNAT44s dumps DNat44
func (svc *dumpService) DumpDNAT44s() (dnats []*vpp_nat.DNat44, err error) {
if svc.natHandler == nil {
// handler is not available
return nil, nil
}
dnats, err = svc.natHandler.DNat44Dump()
if err != nil {
return nil, err
}
return dnats, nil
}
// DumpPunt reads VPP Punt socket registrations and returns them as an *PuntResponse.
func (svc *dumpService) DumpPunt() (punts []*vpp_punt.ToHost, err error) {
if svc.puntHandler == nil {
// handler is not available
return nil, nil
}
dump, err := svc.puntHandler.DumpRegisteredPuntSockets()
if err != nil {
return nil, err
}
for _, puntDetails := range dump {
punts = append(punts, puntDetails.PuntData)
}
return punts, nil
}
// DumpPuntExceptions reads VPP Punt exceptions and returns them as an *PuntResponse.
func (svc *dumpService) DumpPuntExceptions() (punts []*vpp_punt.Exception, err error) {
if svc.puntHandler == nil {
return nil, errors.New("puntHandler is not available")
}
dump, err := svc.puntHandler.DumpExceptions()
if err != nil {
return nil, err
}
for _, puntDetails := range dump {
punts = append(punts, puntDetails.Exception)
}
return punts, nil
}
// DumpLinuxInterfaces reads linux interfaces and returns them as an *LinuxInterfaceResponse. If reading ends up with error,
// only error is send back in response
/*func (svc *dumpService) DumpLinuxInterfaces() ([]*linux_interfaces.Interface, error) {
var linuxIfs []*linux_interfaces.Interface
ifDetails, err := svc.linuxIfHandler.GetLinkList()
if err != nil {
return nil, err
}
for _, iface := range ifDetails {
linuxIfs = append(linuxIfs, )
}
return linuxIfs, nil
}
// DumpLinuxARPs reads linux ARPs and returns them as an *LinuxARPsResponse. If reading ends up with error,
// only error is send back in response
func (svc *dumpService) DumpLinuxARPs(ctx context.Context, request *rpc.DumpRequest) (*rpc.LinuxARPsResponse, error) {
var linuxArps []*linuxL3.LinuxStaticArpEntries_ArpEntry
arpDetails, err := svc.linuxL3Handler.DumpArpEntries()
if err != nil {
return nil, err
}
for _, arp := range arpDetails {
linuxArps = append(linuxArps, arp.Arp)
}
return &rpc.LinuxARPsResponse{LinuxArpEntries: linuxArps}, nil
}
// DumpLinuxRoutes reads linux routes and returns them as an *LinuxRoutesResponse. If reading ends up with error,
// only error is send back in response
func (svc *dumpService) DumpLinuxRoutes(ctx context.Context, request *rpc.DumpRequest) (*rpc.LinuxRoutesResponse, error) {
var linuxRoutes []*linuxL3.LinuxStaticRoutes_Route
rtDetails, err := svc.linuxL3Handler.DumpRoutes()
if err != nil {
return nil, err
}
for _, rt := range rtDetails {
linuxRoutes = append(linuxRoutes, rt.Route)
}
return &rpc.LinuxRoutesResponse{LinuxRoutes: linuxRoutes}, nil
}
*/