• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

openconfig / gribigo / 10085762241

18 Jul 2024 10:36PM UTC coverage: 73.509% (+0.2%) from 73.287%
10085762241

push

github

web-flow
Merge pull request #238 from nflath/duplicate-nh

Add IPv6 Get() test and add metadata to the Get() tests.

75 of 77 new or added lines in 1 file covered. (97.4%)

8 existing lines in 1 file now uncovered.

6288 of 8554 relevant lines covered (73.51%)

0.79 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.47
/compliance/get.go
1
// Copyright 2021 Google LLC
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//      http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15
package compliance
16

17
import (
18
        "context"
19
        "encoding/binary"
20
        "fmt"
21
        "net"
22
        "testing"
23
        "time"
24

25
        log "github.com/golang/glog"
26
        "github.com/openconfig/gribigo/chk"
27
        "github.com/openconfig/gribigo/client"
28
        "github.com/openconfig/gribigo/constants"
29
        "github.com/openconfig/gribigo/fluent"
30
)
31

32
// GetNH validates that an installed next-hop is returned via the Get RPC.
33
func GetNH(c *fluent.GRIBIClient, wantACK fluent.ProgrammingResult, t testing.TB, _ ...TestOpt) {
1✔
34
        defer flushServer(c, t)
1✔
35
        ops := []func(){
1✔
36
                func() {
2✔
37
                        c.Modify().AddEntry(t,
1✔
38
                                fluent.NextHopEntry().
1✔
39
                                        WithNetworkInstance(defaultNetworkInstanceName).
1✔
40
                                        WithIndex(1).
1✔
41
                                        WithIPAddress("192.0.2.3"))
1✔
42
                },
1✔
43
        }
44

45
        res := DoModifyOps(c, t, ops, wantACK, false)
1✔
46

1✔
47
        chk.HasResult(t, res,
1✔
48
                fluent.OperationResult().
1✔
49
                        WithNextHopOperation(1).
1✔
50
                        WithOperationType(constants.Add).
1✔
51
                        WithProgrammingResult(wantACK).
1✔
52
                        AsResult(),
1✔
53
                chk.IgnoreOperationID(),
1✔
54
        )
1✔
55

1✔
56
        ctx := context.Background()
1✔
57
        c.Start(ctx, t)
1✔
58
        defer c.Stop(t)
1✔
59
        gr, err := c.Get().
1✔
60
                WithNetworkInstance(defaultNetworkInstanceName).
1✔
61
                WithAFT(fluent.NextHop).
1✔
62
                Send()
1✔
63

1✔
64
        if err != nil {
1✔
65
                t.Fatalf("got unexpected error from get, got: %v", err)
×
66
        }
×
67

68
        chk.GetResponseHasEntries(t, gr,
1✔
69
                fluent.NextHopEntry().
1✔
70
                        WithNetworkInstance(defaultNetworkInstanceName).
1✔
71
                        WithIndex(1).
1✔
72
                        WithIPAddress("192.0.2.3"))
1✔
73

74
}
75

76
// GetNHG validates that an installed next-hop-group is returned via the Get RPC.
77
func GetNHG(c *fluent.GRIBIClient, wantACK fluent.ProgrammingResult, t testing.TB, _ ...TestOpt) {
1✔
78
        defer flushServer(c, t)
1✔
79
        ops := []func(){
1✔
80
                func() {
2✔
81
                        c.Modify().AddEntry(t,
1✔
82
                                fluent.NextHopEntry().
1✔
83
                                        WithNetworkInstance(defaultNetworkInstanceName).
1✔
84
                                        WithIndex(1).
1✔
85
                                        WithIPAddress("192.0.2.3"))
1✔
86
                },
1✔
87
                func() {
1✔
88
                        c.Modify().AddEntry(t,
1✔
89
                                fluent.NextHopGroupEntry().
1✔
90
                                        WithNetworkInstance(defaultNetworkInstanceName).
1✔
91
                                        WithID(1).
1✔
92
                                        AddNextHop(1, 1))
1✔
93
                },
1✔
94
        }
95

96
        res := DoModifyOps(c, t, ops, wantACK, false)
1✔
97

1✔
98
        chk.HasResult(t, res,
1✔
99
                fluent.OperationResult().
1✔
100
                        WithNextHopOperation(1).
1✔
101
                        WithOperationType(constants.Add).
1✔
102
                        WithProgrammingResult(wantACK).
1✔
103
                        AsResult(),
1✔
104
                chk.IgnoreOperationID(),
1✔
105
        )
1✔
106

1✔
107
        chk.HasResult(t, res,
1✔
108
                fluent.OperationResult().
1✔
109
                        WithNextHopGroupOperation(1).
1✔
110
                        WithOperationType(constants.Add).
1✔
111
                        WithProgrammingResult(wantACK).
1✔
112
                        AsResult(),
1✔
113
                chk.IgnoreOperationID(),
1✔
114
        )
1✔
115

1✔
116
        ctx := context.Background()
1✔
117
        c.Start(ctx, t)
1✔
118
        defer c.Stop(t)
1✔
119
        gr, err := c.Get().
1✔
120
                WithNetworkInstance(defaultNetworkInstanceName).
1✔
121
                WithAFT(fluent.NextHopGroup).
1✔
122
                Send()
1✔
123

1✔
124
        if err != nil {
1✔
125
                t.Fatalf("got unexpected error from get, got: %v", err)
×
126
        }
×
127

128
        chk.GetResponseHasEntries(t, gr,
1✔
129
                fluent.NextHopGroupEntry().
1✔
130
                        WithNetworkInstance(defaultNetworkInstanceName).
1✔
131
                        WithID(1).
1✔
132
                        AddNextHop(1, 1),
1✔
133
        )
1✔
134
}
135

136
// GetIPv4 validates that an installed IPv4 entry is returned via the Get RPC.
137
func GetIPv4(c *fluent.GRIBIClient, wantACK fluent.ProgrammingResult, t testing.TB, _ ...TestOpt) {
1✔
138
        defer flushServer(c, t)
1✔
139

1✔
140
        ops := []func(){
1✔
141
                func() {
2✔
142
                        c.Modify().AddEntry(t,
1✔
143
                                fluent.NextHopEntry().
1✔
144
                                        WithNetworkInstance(defaultNetworkInstanceName).
1✔
145
                                        WithIndex(1).
1✔
146
                                        WithIPAddress("192.0.2.3"))
1✔
147
                },
1✔
148
                func() {
1✔
149
                        c.Modify().AddEntry(t,
1✔
150
                                fluent.NextHopGroupEntry().
1✔
151
                                        WithNetworkInstance(defaultNetworkInstanceName).
1✔
152
                                        WithID(1).
1✔
153
                                        AddNextHop(1, 1))
1✔
154
                },
1✔
155
                func() {
1✔
156
                        c.Modify().AddEntry(t,
1✔
157
                                fluent.IPv4Entry().
1✔
158
                                        WithNetworkInstance(defaultNetworkInstanceName).
1✔
159
                                        WithNextHopGroup(1).
1✔
160
                                        WithPrefix("42.42.42.42/32").
1✔
161
                                        WithMetadata([]byte{1, 2, 3, 4, 5, 6, 7, 8}))
1✔
162
                },
1✔
163
        }
164

165
        res := DoModifyOps(c, t, ops, wantACK, false)
1✔
166

1✔
167
        chk.HasResult(t, res,
1✔
168
                fluent.OperationResult().
1✔
169
                        WithNextHopOperation(1).
1✔
170
                        WithOperationType(constants.Add).
1✔
171
                        WithProgrammingResult(wantACK).
1✔
172
                        AsResult(),
1✔
173
                chk.IgnoreOperationID(),
1✔
174
        )
1✔
175

1✔
176
        chk.HasResult(t, res,
1✔
177
                fluent.OperationResult().
1✔
178
                        WithNextHopGroupOperation(1).
1✔
179
                        WithOperationType(constants.Add).
1✔
180
                        WithProgrammingResult(wantACK).
1✔
181
                        AsResult(),
1✔
182
                chk.IgnoreOperationID(),
1✔
183
        )
1✔
184

1✔
185
        chk.HasResult(t, res,
1✔
186
                fluent.OperationResult().
1✔
187
                        WithIPv4Operation("42.42.42.42/32").
1✔
188
                        WithOperationType(constants.Add).
1✔
189
                        WithProgrammingResult(wantACK).
1✔
190
                        AsResult(),
1✔
191
                chk.IgnoreOperationID(),
1✔
192
        )
1✔
193

1✔
194
        ctx := context.Background()
1✔
195
        c.Start(ctx, t)
1✔
196
        defer c.Stop(t)
1✔
197
        gr, err := c.Get().
1✔
198
                WithNetworkInstance(defaultNetworkInstanceName).
1✔
199
                WithAFT(fluent.IPv4).
1✔
200
                Send()
1✔
201

1✔
202
        if err != nil {
1✔
203
                t.Fatalf("got unexpected error from get, got: %v", err)
×
204
        }
×
205

206
        chk.GetResponseHasEntries(t, gr,
1✔
207
                fluent.IPv4Entry().
1✔
208
                        WithNetworkInstance(defaultNetworkInstanceName).
1✔
209
                        WithNextHopGroup(1).
1✔
210
                        WithPrefix("42.42.42.42/32").
1✔
211
                        WithMetadata([]byte{1, 2, 3, 4, 5, 6, 7, 8}),
1✔
212
        )
1✔
213
}
214

215
// GetIPv6 validates that an installed IPv6 entry is returned via the Get RPC.
216
func GetIPv6(c *fluent.GRIBIClient, wantACK fluent.ProgrammingResult, t testing.TB, _ ...TestOpt) {
1✔
217
        defer flushServer(c, t)
1✔
218

1✔
219
        ops := []func(){
1✔
220
                func() {
2✔
221
                        c.Modify().AddEntry(t,
1✔
222
                                fluent.NextHopEntry().
1✔
223
                                        WithNetworkInstance(defaultNetworkInstanceName).
1✔
224
                                        WithIndex(1).
1✔
225
                                        WithIPAddress("192.0.2.3"))
1✔
226
                },
1✔
227
                func() {
1✔
228
                        c.Modify().AddEntry(t,
1✔
229
                                fluent.NextHopGroupEntry().
1✔
230
                                        WithNetworkInstance(defaultNetworkInstanceName).
1✔
231
                                        WithID(1).
1✔
232
                                        AddNextHop(1, 1))
1✔
233
                },
1✔
234
                func() {
1✔
235
                        c.Modify().AddEntry(t,
1✔
236
                                fluent.IPv6Entry().
1✔
237
                                        WithNetworkInstance(defaultNetworkInstanceName).
1✔
238
                                        WithNextHopGroup(1).
1✔
239
                                        WithPrefix("2001:db8::/32").
1✔
240
                                        WithMetadata([]byte{1, 2, 3, 4, 5, 6, 7, 8}))
1✔
241
                },
1✔
242
        }
243

244
        res := DoModifyOps(c, t, ops, wantACK, false)
1✔
245

1✔
246
        chk.HasResult(t, res,
1✔
247
                fluent.OperationResult().
1✔
248
                        WithNextHopOperation(1).
1✔
249
                        WithOperationType(constants.Add).
1✔
250
                        WithProgrammingResult(wantACK).
1✔
251
                        AsResult(),
1✔
252
                chk.IgnoreOperationID(),
1✔
253
        )
1✔
254

1✔
255
        chk.HasResult(t, res,
1✔
256
                fluent.OperationResult().
1✔
257
                        WithNextHopGroupOperation(1).
1✔
258
                        WithOperationType(constants.Add).
1✔
259
                        WithProgrammingResult(wantACK).
1✔
260
                        AsResult(),
1✔
261
                chk.IgnoreOperationID(),
1✔
262
        )
1✔
263

1✔
264
        chk.HasResult(t, res,
1✔
265
                fluent.OperationResult().
1✔
266
                        WithIPv6Operation("2001:db8::/32").
1✔
267
                        WithOperationType(constants.Add).
1✔
268
                        WithProgrammingResult(wantACK).
1✔
269
                        AsResult(),
1✔
270
                chk.IgnoreOperationID(),
1✔
271
        )
1✔
272

1✔
273
        ctx := context.Background()
1✔
274
        c.Start(ctx, t)
1✔
275
        defer c.Stop(t)
1✔
276
        gr, err := c.Get().
1✔
277
                WithNetworkInstance(defaultNetworkInstanceName).
1✔
278
                WithAFT(fluent.IPv6).
1✔
279
                Send()
1✔
280

1✔
281
        if err != nil {
1✔
NEW
282
                t.Fatalf("got unexpected error from get, got: %v", err)
×
NEW
283
        }
×
284

285
        chk.GetResponseHasEntries(t, gr,
1✔
286
                fluent.IPv6Entry().
1✔
287
                        WithNetworkInstance(defaultNetworkInstanceName).
1✔
288
                        WithNextHopGroup(1).
1✔
289
                        WithPrefix("2001:db8::/32").
1✔
290
                        WithMetadata([]byte{1, 2, 3, 4, 5, 6, 7, 8}),
1✔
291
        )
1✔
292
}
293

294
// GetIPv4Chain validates that Get for all AFTs returns the chain of IPv4Entry->NHG->NH
295
// required.
296
func GetIPv4Chain(c *fluent.GRIBIClient, wantACK fluent.ProgrammingResult, t testing.TB, _ ...TestOpt) {
1✔
297
        defer flushServer(c, t)
1✔
298

1✔
299
        ops := []func(){
1✔
300
                func() {
2✔
301
                        c.Modify().AddEntry(t,
1✔
302
                                fluent.NextHopEntry().
1✔
303
                                        WithNetworkInstance(defaultNetworkInstanceName).
1✔
304
                                        WithIndex(1).
1✔
305
                                        WithIPAddress("192.0.2.3"))
1✔
306
                },
1✔
307
                func() {
1✔
308
                        c.Modify().AddEntry(t,
1✔
309
                                fluent.NextHopGroupEntry().
1✔
310
                                        WithNetworkInstance(defaultNetworkInstanceName).
1✔
311
                                        WithID(1).
1✔
312
                                        AddNextHop(1, 1))
1✔
313
                },
1✔
314
                func() {
1✔
315
                        c.Modify().AddEntry(t,
1✔
316
                                fluent.IPv4Entry().
1✔
317
                                        WithNetworkInstance(defaultNetworkInstanceName).
1✔
318
                                        WithNextHopGroup(1).
1✔
319
                                        WithPrefix("42.42.42.42/32"))
1✔
320
                },
1✔
321
        }
322

323
        res := DoModifyOps(c, t, ops, wantACK, false)
1✔
324

1✔
325
        chk.HasResult(t, res,
1✔
326
                fluent.OperationResult().
1✔
327
                        WithNextHopOperation(1).
1✔
328
                        WithOperationType(constants.Add).
1✔
329
                        WithProgrammingResult(wantACK).
1✔
330
                        AsResult(),
1✔
331
                chk.IgnoreOperationID(),
1✔
332
        )
1✔
333

1✔
334
        chk.HasResult(t, res,
1✔
335
                fluent.OperationResult().
1✔
336
                        WithNextHopGroupOperation(1).
1✔
337
                        WithOperationType(constants.Add).
1✔
338
                        WithProgrammingResult(wantACK).
1✔
339
                        AsResult(),
1✔
340
                chk.IgnoreOperationID(),
1✔
341
        )
1✔
342

1✔
343
        chk.HasResult(t, res,
1✔
344
                fluent.OperationResult().
1✔
345
                        WithIPv4Operation("42.42.42.42/32").
1✔
346
                        WithOperationType(constants.Add).
1✔
347
                        WithProgrammingResult(wantACK).
1✔
348
                        AsResult(),
1✔
349
                chk.IgnoreOperationID(),
1✔
350
        )
1✔
351

1✔
352
        ctx := context.Background()
1✔
353
        c.Start(ctx, t)
1✔
354
        defer c.Stop(t)
1✔
355
        gr, err := c.Get().
1✔
356
                WithNetworkInstance(defaultNetworkInstanceName).
1✔
357
                WithAFT(fluent.AllAFTs).
1✔
358
                Send()
1✔
359

1✔
360
        if err != nil {
1✔
361
                t.Fatalf("got unexpected error from get, got: %v", err)
×
362
        }
×
363

364
        chk.GetResponseHasEntries(t, gr,
1✔
365
                fluent.IPv4Entry().
1✔
366
                        WithNetworkInstance(defaultNetworkInstanceName).
1✔
367
                        WithNextHopGroup(1).
1✔
368
                        WithPrefix("42.42.42.42/32"),
1✔
369
                fluent.NextHopGroupEntry().
1✔
370
                        WithNetworkInstance(defaultNetworkInstanceName).
1✔
371
                        WithID(1).
1✔
372
                        AddNextHop(1, 1),
1✔
373
                fluent.NextHopEntry().
1✔
374
                        WithNetworkInstance(defaultNetworkInstanceName).
1✔
375
                        WithIndex(1).
1✔
376
                        WithIPAddress("192.0.2.3"),
1✔
377
        )
1✔
378
}
379

380
// indexAsIPv4 converts a uint32 index into an IP address, using the baseSlashEight argument as the
381
// starting point. For example, if an index = 1 is provided with baseSlashEight = 1 the address
382
// returned is 1.0.0.1.
383
func indexAsIPv4(i uint32, baseSlashEight int) string {
1✔
384
        ip := make(net.IP, 4)
1✔
385
        binary.BigEndian.PutUint32(ip, uint32(i)+uint32(baseSlashEight*16777216))
1✔
386
        return ip.String()
1✔
387
}
1✔
388

389
// populateNNHs creates N next-hops based via the client, c, expecting the wanACK back from
390
// the server. Errors are reported via the testing.TB provided.
391
func populateNNHs(c *fluent.GRIBIClient, n int, wantACK fluent.ProgrammingResult, t testing.TB) {
1✔
392
        ops := []func(){}
1✔
393
        for i := 0; i < n; i++ {
2✔
394
                j := i + 1
1✔
395
                ops = append(ops, func() {
2✔
396
                        c.Modify().AddEntry(t,
1✔
397
                                fluent.NextHopEntry().
1✔
398
                                        WithNetworkInstance(defaultNetworkInstanceName).
1✔
399
                                        WithIndex(uint64(j)).
1✔
400
                                        WithIPAddress(indexAsIPv4(uint32(i), 1)))
1✔
401
                })
1✔
402
        }
403

404
        log.V(2).Infof("doing programming")
1✔
405
        res := DoModifyOps(c, t, ops, wantACK, false)
1✔
406
        log.V(2).Infof("finished programming")
1✔
407

1✔
408
        log.V(2).Infof("doing check for %d nexthops", n)
1✔
409

1✔
410
        wants := []*client.OpResult{}
1✔
411
        for i := 0; i < n; i++ {
2✔
412
                wants = append(wants,
1✔
413
                        fluent.OperationResult().
1✔
414
                                WithNextHopOperation(uint64(i)+1).
1✔
415
                                WithProgrammingResult(wantACK).
1✔
416
                                WithOperationType(constants.Add).
1✔
417
                                AsResult())
1✔
418
        }
1✔
419
        chk.HasResultsCache(t, res, wants, chk.IgnoreOperationID())
1✔
420
}
421

422
// GetBenchmarkNH benchmarks the performance of Get populating the server with N next-hop
423
// instances and measuring latency of the Get returned by the server. No validation of
424
// the returned contents is performed.
425
func GetBenchmarkNH(c *fluent.GRIBIClient, wantACK fluent.ProgrammingResult, t testing.TB, _ ...TestOpt) {
1✔
426
        for _, i := range []int{10, 100, 1000} {
2✔
427
                populateNNHs(c, i, wantACK, t)
1✔
428
                ctx := context.Background()
1✔
429
                c.Start(ctx, t)
1✔
430

1✔
431
                start := time.Now()
1✔
432
                _, err := c.Get().
1✔
433
                        WithNetworkInstance(defaultNetworkInstanceName).
1✔
434
                        WithAFT(fluent.NextHop).
1✔
435
                        Send()
1✔
436
                end := time.Now()
1✔
437
                if err != nil {
1✔
438
                        flushServer(c, t)
×
439
                        t.Fatalf("got unexpected error, %v", err)
×
440
                }
×
441

442
                latency := end.Sub(start).Nanoseconds()
1✔
443
                fmt.Printf("latency for %d NHs: %d\n", i, latency)
1✔
444
                flushServer(c, t)
1✔
445
                c.Stop(t)
1✔
446
        }
447
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc