forked from ligato/vpp-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathafpacket_config_test.go
535 lines (471 loc) · 18.3 KB
/
afpacket_config_test.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
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
// Copyright (c) 2018 Cisco and/or its affiliates.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package ifplugin_test
import (
"testing"
"github.com/ligato/cn-infra/logging"
"github.com/ligato/cn-infra/logging/logrus"
"github.com/ligato/cn-infra/utils/safeclose"
"github.com/ligato/vpp-agent/idxvpp/nametoidx"
ap_api "github.com/ligato/vpp-agent/plugins/vpp/binapi/af_packet"
if_api "github.com/ligato/vpp-agent/plugins/vpp/binapi/interfaces"
"github.com/ligato/vpp-agent/plugins/vpp/ifplugin"
"github.com/ligato/vpp-agent/plugins/vpp/ifplugin/ifaceidx"
"github.com/ligato/vpp-agent/plugins/vpp/ifplugin/vppcalls"
"github.com/ligato/vpp-agent/plugins/vpp/model/interfaces"
"github.com/ligato/vpp-agent/tests/vppcallmock"
. "github.com/onsi/gomega"
)
/* AF_PACKET test cases */
// Configure af packet interface with unavailable host
func TestAfPacketConfigureHostNotAvail(t *testing.T) {
ctx, plugin, _ := afPacketTestSetup(t)
defer afPacketTestTeardown(ctx)
// Data
data := getTestAfPacketData("if1", []string{"10.0.0.1/24"}, "host1")
// Test configure af packet with host unavailable
swIfIdx, pending, err := plugin.ConfigureAfPacketInterface(data)
Expect(err).To(BeNil())
Expect(swIfIdx).To(BeZero())
Expect(pending).To(BeTrue())
exists, pending, cachedData := plugin.GetAfPacketStatusByName("if1")
Expect(exists).To(BeTrue())
Expect(pending).To(BeTrue())
Expect(cachedData).ToNot(BeNil())
exists, pending, cachedData = plugin.GetAfPacketStatusByHost("host1")
Expect(exists).To(BeTrue())
Expect(pending).To(BeTrue())
Expect(cachedData).ToNot(BeNil())
}
// Configure af packet interface
func TestAfPacketConfigureHostAvail(t *testing.T) {
ctx, plugin, _ := afPacketTestSetup(t)
defer afPacketTestTeardown(ctx)
// Reply set
ctx.MockVpp.MockReply(&ap_api.AfPacketCreateReply{
SwIfIndex: 2,
})
ctx.MockVpp.MockReply(&if_api.SwInterfaceTagAddDelReply{})
// Data
data := getTestAfPacketData("if1", []string{"10.0.0.1/24"}, "host1")
// Test af packet
plugin.ResolveCreatedLinuxInterface("host1", "host1", 1)
swIfIdx, pending, err := plugin.ConfigureAfPacketInterface(data)
Expect(err).To(BeNil())
Expect(swIfIdx).To(BeEquivalentTo(2))
Expect(pending).To(BeFalse())
exists, pending, cachedData := plugin.GetAfPacketStatusByName("if1")
Expect(exists).To(BeTrue())
Expect(pending).To(BeFalse())
Expect(cachedData).ToNot(BeNil())
exists, pending, cachedData = plugin.GetAfPacketStatusByHost("host1")
Expect(exists).To(BeTrue())
Expect(pending).To(BeFalse())
Expect(cachedData).ToNot(BeNil())
}
// Configure af packet with error reply from VPP API
func TestAfPacketConfigureHostAvailError(t *testing.T) {
ctx, plugin, _ := afPacketTestSetup(t)
defer afPacketTestTeardown(ctx)
// Reply set
ctx.MockVpp.MockReply(&ap_api.AfPacketCreateReply{
Retval: 1,
SwIfIndex: 2,
})
// Data
data := getTestAfPacketData("if1", []string{"10.0.0.1/24"}, "host1")
// Test configure af packet with return value != 0
plugin.ResolveCreatedLinuxInterface("host1", "host1", 1)
swIfIdx, pending, err := plugin.ConfigureAfPacketInterface(data)
Expect(err).ToNot(BeNil())
Expect(swIfIdx).To(BeZero())
Expect(pending).To(BeTrue())
exists, pending, cachedData := plugin.GetAfPacketStatusByName("if1")
Expect(exists).To(BeTrue())
Expect(cachedData).ToNot(BeNil())
exists, pending, cachedData = plugin.GetAfPacketStatusByHost("host1")
Expect(exists).To(BeTrue())
Expect(cachedData).ToNot(BeNil())
}
// Configure af packet as incorrect interface type
func TestAfPacketConfigureIncorrectTypeError(t *testing.T) {
ctx, plugin, _ := afPacketTestSetup(t)
defer afPacketTestTeardown(ctx)
// Data
data := getTestAfPacketData("host1", []string{"10.0.0.1/24"}, "host1")
data.Type = interfaces.InterfaceType_SOFTWARE_LOOPBACK
// Test configure af packet with incorrect type
swIfIdx, pending, err := plugin.ConfigureAfPacketInterface(data)
Expect(err).ToNot(BeNil())
Expect(swIfIdx).To(BeZero())
Expect(pending).To(BeFalse())
exists, _, _ := plugin.GetAfPacketStatusByName("if1")
Expect(exists).To(BeFalse())
exists, _, _ = plugin.GetAfPacketStatusByHost("host1")
Expect(exists).To(BeFalse())
}
// Call af packet modification which causes recreation of the interface
func TestAfPacketModifyRecreateChangedHost(t *testing.T) {
ctx, plugin, _ := afPacketTestSetup(t)
defer afPacketTestTeardown(ctx)
// Reply set
ctx.MockVpp.MockReply(&ap_api.AfPacketCreateReply{
SwIfIndex: 1,
})
ctx.MockVpp.MockReply(&if_api.SwInterfaceTagAddDelReply{})
// Data
oldData := getTestAfPacketData("if1", []string{"10.0.0.1/24"}, "host1")
newData := getTestAfPacketData("if1", []string{"10.0.0.2/24"}, "host2")
// Test configure initial af packet data
plugin.ResolveCreatedLinuxInterface("host1", "host1", 1)
swIfIdx, pending, err := plugin.ConfigureAfPacketInterface(oldData)
Expect(err).To(BeNil())
Expect(swIfIdx).To(BeEquivalentTo(1))
Expect(pending).To(BeFalse())
// Test modify af packet
recreate, err := plugin.ModifyAfPacketInterface(newData, oldData)
Expect(err).To(BeNil())
Expect(recreate).To(BeTrue())
}
// Test modify pending af packet interface
func TestAfPacketModifyRecreatePending(t *testing.T) {
ctx, plugin, _ := afPacketTestSetup(t)
defer afPacketTestTeardown(ctx)
// Reply set
ctx.MockVpp.MockReply(&ap_api.AfPacketCreateReply{
SwIfIndex: 1,
})
ctx.MockVpp.MockReply(&if_api.SwInterfaceTagAddDelReply{})
// Data
oldData := getTestAfPacketData("if1", []string{"10.0.0.1/24"}, "host1")
newData := getTestAfPacketData("if1", []string{"10.0.0.1/24"}, "host1")
// Test configure initial af packet data
_, pending, err := plugin.ConfigureAfPacketInterface(oldData)
Expect(err).To(BeNil())
Expect(pending).To(BeTrue())
// Test modify
recreate, err := plugin.ModifyAfPacketInterface(newData, oldData)
Expect(err).To(BeNil())
Expect(recreate).To(BeTrue())
}
// Modify recreate of af packet interface which was not found
func TestAfPacketModifyRecreateNotFound(t *testing.T) {
ctx, plugin, _ := afPacketTestSetup(t)
defer afPacketTestTeardown(ctx)
// Data
oldData := getTestAfPacketData("if1", []string{"10.0.0.1/24"}, "host1")
newData := getTestAfPacketData("if1", []string{"10.0.0.1/24"}, "host2")
// Test af packet modify
recreate, err := plugin.ModifyAfPacketInterface(newData, oldData)
Expect(err).To(BeNil())
Expect(recreate).To(BeTrue())
}
// Modify af packet interface without recreation
func TestAfPacketModifyNoRecreate(t *testing.T) {
ctx, plugin, _ := afPacketTestSetup(t)
defer afPacketTestTeardown(ctx)
// Reply set
ctx.MockVpp.MockReply(&ap_api.AfPacketCreateReply{
SwIfIndex: 1,
})
ctx.MockVpp.MockReply(&if_api.SwInterfaceTagAddDelReply{})
// Data
oldData := getTestAfPacketData("if1", []string{"10.0.0.1/24"}, "host1")
newData := getTestAfPacketData("if1", []string{"10.0.0.1/24"}, "host1")
// Test configure initial data
plugin.ResolveCreatedLinuxInterface("host1", "host1", 1)
swIfIdx, pending, err := plugin.ConfigureAfPacketInterface(oldData)
Expect(err).To(BeNil())
Expect(swIfIdx).To(BeEquivalentTo(1))
Expect(pending).To(BeFalse())
// Test modify
recreate, err := plugin.ModifyAfPacketInterface(newData, oldData)
Expect(err).To(BeNil())
Expect(recreate).To(BeFalse())
exists, pending, cachedData := plugin.GetAfPacketStatusByName("if1")
Expect(exists).To(BeTrue())
Expect(pending).To(BeFalse())
Expect(cachedData).ToNot(BeNil())
exists, pending, cachedData = plugin.GetAfPacketStatusByHost("host1")
Expect(exists).To(BeTrue())
Expect(pending).To(BeFalse())
Expect(cachedData).ToNot(BeNil())
}
// Modify af packet with incorrect interface type
func TestAfPacketModifyIncorrectType(t *testing.T) {
ctx, plugin, _ := afPacketTestSetup(t)
defer afPacketTestTeardown(ctx)
// Reply set
ctx.MockVpp.MockReply(&ap_api.AfPacketCreateReply{
SwIfIndex: 1,
})
ctx.MockVpp.MockReply(&if_api.SwInterfaceTagAddDelReply{})
// Data
oldData := getTestAfPacketData("if1", []string{"10.0.0.1/24"}, "host1")
newData := getTestAfPacketData("if1", []string{"10.0.0.1/24"}, "host2")
newData.Type = interfaces.InterfaceType_SOFTWARE_LOOPBACK
// Test configure initial data
plugin.ResolveCreatedLinuxInterface("host1", "host1", 1)
swIfIdx, pending, err := plugin.ConfigureAfPacketInterface(oldData)
Expect(err).To(BeNil())
Expect(swIfIdx).To(BeEquivalentTo(1))
Expect(pending).To(BeFalse())
// Test modify with incorrect type
_, err = plugin.ModifyAfPacketInterface(newData, oldData)
Expect(err).ToNot(BeNil())
}
// Af packet delete
func TestAfPacketDelete(t *testing.T) {
ctx, plugin, _ := afPacketTestSetup(t)
defer afPacketTestTeardown(ctx)
// Reply set
ctx.MockVpp.MockReply(&ap_api.AfPacketCreateReply{ // Create
SwIfIndex: 1,
})
ctx.MockVpp.MockReply(&if_api.SwInterfaceTagAddDelReply{})
ctx.MockVpp.MockReply(&ap_api.AfPacketDeleteReply{}) // Delete
ctx.MockVpp.MockReply(&if_api.SwInterfaceTagAddDelReply{})
// Data
data := getTestAfPacketData("if1", []string{"10.0.0.1/24"}, "host1")
// Test configure initial af packet data
plugin.ResolveCreatedLinuxInterface("host1", "host1", 1)
swIfIdx, pending, err := plugin.ConfigureAfPacketInterface(data)
Expect(err).To(BeNil())
Expect(swIfIdx).To(BeEquivalentTo(1))
Expect(pending).To(BeFalse())
exists, pending, cachedData := plugin.GetAfPacketStatusByName("if1")
Expect(exists).To(BeTrue())
Expect(pending).To(BeFalse())
Expect(cachedData).ToNot(BeNil())
exists, pending, cachedData = plugin.GetAfPacketStatusByHost("host1")
Expect(exists).To(BeTrue())
Expect(pending).To(BeFalse())
Expect(cachedData).ToNot(BeNil())
// Test af packet delete
err = plugin.DeleteAfPacketInterface(data, 1)
Expect(err).To(BeNil())
exists, _, _ = plugin.GetAfPacketStatusByName("if1")
Expect(exists).To(BeFalse())
exists, _, _ = plugin.GetAfPacketStatusByHost("host1")
Expect(exists).To(BeFalse())
}
// Delete af packet with incorrect interface type data
func TestAfPacketDeleteIncorrectType(t *testing.T) {
ctx, plugin, _ := afPacketTestSetup(t)
defer afPacketTestTeardown(ctx)
// Reply set
ctx.MockVpp.MockReply(&ap_api.AfPacketCreateReply{
SwIfIndex: 1,
})
ctx.MockVpp.MockReply(&if_api.SwInterfaceTagAddDelReply{})
// Data
data := getTestAfPacketData("if1", []string{"10.0.0.1/24"}, "host1")
modifiedData := getTestAfPacketData("if1", []string{"10.0.0.1/24"}, "host1")
modifiedData.Type = interfaces.InterfaceType_SOFTWARE_LOOPBACK
// Test configure initial af packet
plugin.ResolveCreatedLinuxInterface("host1", "host1", 1)
swIfIdx, pending, err := plugin.ConfigureAfPacketInterface(data)
Expect(err).To(BeNil())
Expect(swIfIdx).To(BeEquivalentTo(1))
Expect(pending).To(BeFalse())
// Test delete with incorrect type
err = plugin.DeleteAfPacketInterface(modifiedData, 1)
Expect(err).ToNot(BeNil())
}
// Register new linux interface and test af packet behaviour
func TestAfPacketNewLinuxInterfaceHostFound(t *testing.T) {
ctx, plugin, _ := afPacketTestSetup(t)
defer afPacketTestTeardown(ctx)
// Reply set
ctx.MockVpp.MockReply(&ap_api.AfPacketCreateReply{
SwIfIndex: 1,
})
ctx.MockVpp.MockReply(&if_api.SwInterfaceTagAddDelReply{})
// Data
data := getTestAfPacketData("if1", []string{"10.0.0.1/24"}, "host1")
// Test registered linux interface
_, pending, err := plugin.ConfigureAfPacketInterface(data)
Expect(err).To(BeNil())
Expect(pending).To(BeTrue())
config := plugin.ResolveCreatedLinuxInterface("host1", "host1", 1)
Expect(config).ToNot(BeNil())
Expect(config.Afpacket.HostIfName).To(BeEquivalentTo("host1"))
Expect(plugin.GetHostInterfacesEntry("host1")).To(BeTrue())
}
// Register new linux interface while af packet is not pending. Note: this is a case which should NOT happen
func TestAfPacketNewLinuxInterfaceHostNotPending(t *testing.T) {
ctx, plugin, _ := afPacketTestSetup(t)
defer afPacketTestTeardown(ctx)
// Reply set
ctx.MockVpp.MockReply(&ap_api.AfPacketCreateReply{
SwIfIndex: 1,
})
ctx.MockVpp.MockReply(&if_api.SwInterfaceTagAddDelReply{})
ctx.MockVpp.MockReply(&ap_api.AfPacketDeleteReply{})
ctx.MockVpp.MockReply(&if_api.SwInterfaceTagAddDelReply{})
// Data
data := getTestAfPacketData("if1", []string{"10.0.0.1/24"}, "host1")
// Test registered linux interface
plugin.ResolveCreatedLinuxInterface("host1", "host1", 1)
_, pending, err := plugin.ConfigureAfPacketInterface(data)
Expect(err).To(BeNil())
Expect(pending).To(BeFalse())
config := plugin.ResolveCreatedLinuxInterface("host1", "host1", 1)
Expect(config).ToNot(BeNil())
Expect(config.Afpacket.HostIfName).To(BeEquivalentTo("host1"))
Expect(plugin.GetHostInterfacesEntry("host1")).To(BeTrue())
}
// Test new linux interface which is not a host
func TestAfPacketNewLinuxInterfaceHostNotFound(t *testing.T) {
ctx, plugin, _ := afPacketTestSetup(t)
defer afPacketTestTeardown(ctx)
Expect(plugin.GetHostInterfacesEntry("host1")).To(BeFalse())
// Test registered linux interface
config := plugin.ResolveCreatedLinuxInterface("host1", "host1", 1)
Expect(config).To(BeNil())
Expect(plugin.GetHostInterfacesEntry("host1")).To(BeTrue())
}
// Test new linux interface while linux plugin is not available
func TestAfPacketNewLinuxInterfaceNoLinux(t *testing.T) {
ctx := vppcallmock.SetupTestCtx(t)
defer ctx.TeardownTestCtx()
// Logger
log := logrus.DefaultLogger()
log.SetLevel(logging.DebugLevel)
// Interface indices
swIfIndices := ifaceidx.NewSwIfIndex(nametoidx.NewNameToIdx(log, "afpacket", nil))
// Configurator
plugin := &ifplugin.AFPacketConfigurator{}
ifHandler := vppcalls.NewIfVppHandler(ctx.MockChannel, log, nil)
err := plugin.Init(log, ifHandler, nil, swIfIndices)
Expect(err).To(BeNil())
// Test registered linux interface
config := plugin.ResolveCreatedLinuxInterface("host1", "host1", 1)
Expect(config).To(BeNil())
}
// Un-register linux interface
func TestAfPacketDeletedLinuxInterface(t *testing.T) {
ctx, plugin, _ := afPacketTestSetup(t)
defer afPacketTestTeardown(ctx)
// Reply set
ctx.MockVpp.MockReply(&ap_api.AfPacketCreateReply{})
ctx.MockVpp.MockReply(&if_api.SwInterfaceTagAddDelReply{})
ctx.MockVpp.MockReply(&ap_api.AfPacketDeleteReply{})
ctx.MockVpp.MockReply(&if_api.SwInterfaceTagAddDelReply{})
// Data
data := getTestAfPacketData("if1", []string{"10.0.0.1/24"}, "host1")
// Prepare
_, pending, err := plugin.ConfigureAfPacketInterface(data)
Expect(err).To(BeNil())
Expect(pending).To(BeTrue())
// Test un-registered linux interface
plugin.ResolveDeletedLinuxInterface("host1", "host1", 1)
exists, _, _ := plugin.GetAfPacketStatusByHost("host1")
Expect(exists).To(BeTrue())
exists, _, _ = plugin.GetAfPacketStatusByName("host1")
Expect(exists).To(BeFalse())
Expect(plugin.GetHostInterfacesEntry("host1")).To(BeFalse())
}
// Un-register linux interface while host is not found
func TestAfPacketDeletedLinuxInterfaceHostNotFound(t *testing.T) {
ctx, plugin, _ := afPacketTestSetup(t)
defer afPacketTestTeardown(ctx)
// Prepare
plugin.ResolveCreatedLinuxInterface("host1", "host1", 1)
// Test un-registered linux interface
plugin.ResolveDeletedLinuxInterface("host1", "host1", 1)
Expect(plugin.GetHostInterfacesEntry("host1")).To(BeFalse())
}
// Un-register linux interface with linux plugin not initialized
func TestAfPacketDeleteLinuxInterfaceNoLinux(t *testing.T) {
ctx := vppcallmock.SetupTestCtx(t)
defer ctx.TeardownTestCtx()
// Logger
log := logrus.DefaultLogger()
log.SetLevel(logging.DebugLevel)
// Interface indices
swIfIndices := ifaceidx.NewSwIfIndex(nametoidx.NewNameToIdx(log, "afpacket", nil))
// Configurator
plugin := &ifplugin.AFPacketConfigurator{}
ifHandler := vppcalls.NewIfVppHandler(ctx.MockChannel, log, nil)
err := plugin.Init(log, ifHandler, nil, swIfIndices)
Expect(err).To(BeNil())
// Prepare
plugin.ResolveCreatedLinuxInterface("host1", "host1", 1)
// Test un-registered linux interface
plugin.ResolveDeletedLinuxInterface("host1", "host1", 1)
Expect(plugin.GetHostInterfacesEntry("host1")).To(BeFalse())
err = safeclose.Close(ctx)
Expect(err).To(BeNil())
}
// Check if 'IsPending' returns correct output
func TestAfPacketIsPending(t *testing.T) {
ctx, plugin, _ := afPacketTestSetup(t)
defer afPacketTestTeardown(ctx)
// Reply set
ctx.MockVpp.MockReply(&ap_api.AfPacketCreateReply{})
ctx.MockVpp.MockReply(&if_api.SwInterfaceTagAddDelReply{})
ctx.MockVpp.MockReply(&ap_api.AfPacketCreateReply{})
ctx.MockVpp.MockReply(&if_api.SwInterfaceTagAddDelReply{})
// Data
firstData := getTestAfPacketData("if1", []string{"10.0.0.1/24"}, "host1")
secondData := getTestAfPacketData("if2", []string{"10.0.0.2/24"}, "host2")
// Prepare
plugin.ResolveCreatedLinuxInterface("host2", "host2", 3)
_, pending, err := plugin.ConfigureAfPacketInterface(firstData)
Expect(err).To(BeNil())
Expect(pending).To(BeTrue())
_, pending, err = plugin.ConfigureAfPacketInterface(secondData)
Expect(err).To(BeNil())
Expect(pending).To(BeFalse())
// Test 'IsPending'
isPending := plugin.IsPendingAfPacket(firstData)
Expect(isPending).To(BeTrue())
isPending = plugin.IsPendingAfPacket(secondData)
Expect(isPending).To(BeFalse())
}
/* AF_PACKET Test Setup */
func afPacketTestSetup(t *testing.T) (*vppcallmock.TestCtx, *ifplugin.AFPacketConfigurator, ifaceidx.SwIfIndexRW) {
RegisterTestingT(t)
ctx := vppcallmock.SetupTestCtx(t)
// Logger
log := logrus.DefaultLogger()
log.SetLevel(logging.DebugLevel)
// Interface indices
swIfIndices := ifaceidx.NewSwIfIndex(nametoidx.NewNameToIdx(log, "afpacket", nil))
// Configurator
plugin := &ifplugin.AFPacketConfigurator{}
ifHandler := vppcalls.NewIfVppHandler(ctx.MockChannel, log, nil)
err := plugin.Init(log, ifHandler, struct{}{}, swIfIndices)
Expect(err).To(BeNil())
return ctx, plugin, swIfIndices
}
func afPacketTestTeardown(ctx *vppcallmock.TestCtx) {
ctx.TeardownTestCtx()
err := safeclose.Close(ctx)
Expect(err).To(BeNil())
logging.DefaultRegistry.ClearRegistry()
}
/* AF_PACKET Test Data */
func getTestAfPacketData(ifName string, addresses []string, host string) *interfaces.Interfaces_Interface {
return &interfaces.Interfaces_Interface{
Name: ifName,
Type: interfaces.InterfaceType_AF_PACKET_INTERFACE,
Enabled: true,
IpAddresses: addresses,
Afpacket: &interfaces.Interfaces_Interface_Afpacket{
HostIfName: host,
},
}
}