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
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
|
/*
* Copyright (c) 20022 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.
*/
#define HICN_PCS_TESTING
#include "vpp.h"
#include <pcs.h>
#include <unity.h>
#include <unity_fixture.h>
/*
* Global PCS instance common to each test
*/
static hicn_pit_cs_t global_pcs;
TEST_GROUP (PCS);
/**
* Default PIT elements
*/
#define MAX_PIT_ELEMENTS 1000000
/**
* Default CS elements
*/
#define MAX_CS_ELEMENTS (MAX_PIT_ELEMENTS / 10)
TEST_SETUP (PCS)
{
hicn_pit_cs_t *pcs = &global_pcs;
hicn_pit_create (pcs, MAX_PIT_ELEMENTS, MAX_CS_ELEMENTS);
}
TEST_TEAR_DOWN (PCS)
{
hicn_pit_cs_t *pcs = &global_pcs;
hicn_pit_destroy (pcs);
}
TEST (PCS, Create)
{
hicn_pit_cs_t *pcs = &global_pcs;
// Check counters
TEST_ASSERT_EQUAL (0, pcs->pcs_pit_count);
TEST_ASSERT_EQUAL (0, pcs->pcs_cs_count);
TEST_ASSERT_EQUAL (0, pcs->pcs_pcs_alloc);
TEST_ASSERT_EQUAL (0, pcs->pcs_pcs_dealloc);
TEST_ASSERT_EQUAL (MAX_PIT_ELEMENTS, pcs->max_pit_size);
TEST_ASSERT_EQUAL (MAX_CS_ELEMENTS, pcs->policy_state.max);
printf ("PIT entry size: %lu", sizeof (hicn_pcs_entry_t));
}
TEST (PCS, Destroy)
{
// Global PCS instance
}
TEST (PCS, LookupEmpty)
{
hicn_pit_cs_t *pcs = &global_pcs;
hicn_name_t name;
int ret = hicn_name_create ("b001::abcd", 0, &name);
TEST_ASSERT_EQUAL (0, ret);
hicn_pcs_entry_t *pcs_entry;
ret = hicn_pcs_lookup_one (pcs, &name, &pcs_entry);
TEST_ASSERT_EQUAL (HICN_ERROR_PCS_NOT_FOUND, ret);
TEST_ASSERT_EQUAL (NULL, pcs_entry);
}
TEST (PCS, InsertPITEntryAndLookup)
{
hicn_pit_cs_t *pcs = &global_pcs;
// Add entry to the PCS
int ret = 0;
// Allocate name
hicn_name_t name;
hicn_name_create ("b001::1234", 0, &name);
// Create PCS entry
hicn_pcs_entry_t *pcs_entry;
ret = hicn_pcs_lookup_one (pcs, &name, &pcs_entry);
// We will not find the entry
TEST_ASSERT_EQUAL (ret, HICN_ERROR_PCS_NOT_FOUND);
TEST_ASSERT_EQUAL (NULL, pcs_entry);
// Get a new PIT entry from the pool
// TODO Check if the hicn_pcs_entry_pit_get is needed here
pcs_entry = hicn_pcs_entry_pit_get (pcs, 0, 0);
TEST_ASSERT_NOT_NULL (pcs_entry);
TEST_ASSERT_EQUAL (hicn_pcs_get_pcs_alloc (pcs), 1);
// Insert PIT entry
ret = hicn_pcs_pit_insert (pcs, pcs_entry, &name);
TEST_ASSERT_EQUAL (HICN_ERROR_NONE, ret);
TEST_ASSERT_EQUAL (hicn_pcs_get_pit_count (pcs), 1);
TEST_ASSERT_EQUAL (hicn_pcs_get_cs_count (pcs), 0);
// Lookup PIT entry
hicn_pcs_entry_t *pcs_entry_ret = NULL;
ret = hicn_pcs_lookup_one (pcs, &name, &pcs_entry_ret);
TEST_ASSERT_EQUAL (HICN_ERROR_NONE, ret);
TEST_ASSERT_NOT_NULL (pcs_entry_ret);
TEST_ASSERT_EQUAL (pcs_entry, pcs_entry_ret);
// Release PIT entry
hicn_pcs_entry_remove_lock (pcs, pcs_entry);
TEST_ASSERT_EQUAL (hicn_pcs_get_pcs_dealloc (pcs), 1);
TEST_ASSERT_EQUAL (hicn_pcs_get_pit_count (pcs), 0);
TEST_ASSERT_EQUAL (hicn_pcs_get_cs_count (pcs), 0);
// Lookup PIT entry again, we should not find it
ret = hicn_pcs_lookup_one (pcs, &name, &pcs_entry_ret);
TEST_ASSERT_EQUAL (HICN_ERROR_PCS_NOT_FOUND, ret);
TEST_ASSERT_EQUAL (NULL, pcs_entry_ret);
}
TEST (PCS, InsertCSEntryAndLookup)
{
hicn_pit_cs_t *pcs = &global_pcs;
// Add entry to the PCS
int ret = 0;
// Allocate name
hicn_name_t name;
hicn_name_create ("b008::5555", 0, &name);
// Create PCS entry
hicn_pcs_entry_t *pcs_entry;
ret = hicn_pcs_lookup_one (pcs, &name, &pcs_entry);
// We will not find the entry
TEST_ASSERT_EQUAL (ret, HICN_ERROR_PCS_NOT_FOUND);
TEST_ASSERT_EQUAL (NULL, pcs_entry);
// Get a buffer
u32 buffer_index = 198274;
// Get a new entry from the pool
pcs_entry = hicn_pcs_entry_cs_get (pcs, 0, buffer_index);
TEST_ASSERT_NOT_NULL (pcs_entry);
TEST_ASSERT_EQUAL (1, hicn_pcs_get_pcs_alloc (pcs));
// Insert CS entry
ret = hicn_pcs_cs_insert (pcs, pcs_entry, &name);
TEST_ASSERT_EQUAL (HICN_ERROR_NONE, ret);
TEST_ASSERT_EQUAL (hicn_pcs_get_pit_count (pcs), 0);
TEST_ASSERT_EQUAL (hicn_pcs_get_cs_count (pcs), 1);
// Lookup CS entry
hicn_pcs_entry_t *pcs_entry_ret = NULL;
ret = hicn_pcs_lookup_one (pcs, &name, &pcs_entry_ret);
TEST_ASSERT_EQUAL (HICN_ERROR_NONE, ret);
TEST_ASSERT_TRUE (pcs_entry_ret->flags & HICN_PCS_ENTRY_CS_FLAG);
TEST_ASSERT_NOT_NULL (pcs_entry_ret);
TEST_ASSERT_EQUAL (pcs_entry, pcs_entry_ret);
// Release CS entry
hicn_pcs_entry_remove_lock (pcs, pcs_entry);
TEST_ASSERT_EQUAL (1, hicn_pcs_get_pcs_dealloc (pcs));
TEST_ASSERT_EQUAL (0, hicn_pcs_get_pit_count (pcs));
TEST_ASSERT_EQUAL (0, hicn_pcs_get_cs_count (pcs));
// Lookup CS entry again, we should not find it
ret = hicn_pcs_lookup_one (pcs, &name, &pcs_entry_ret);
TEST_ASSERT_EQUAL (HICN_ERROR_PCS_NOT_FOUND, ret);
TEST_ASSERT_EQUAL (NULL, pcs_entry_ret);
}
TEST (PCS, PitToCS)
{
hicn_pit_cs_t *pcs = &global_pcs;
// Add entry to the PCS
int ret = 0;
// Allocate name
hicn_name_t name;
hicn_name_create ("b001::1234", 0, &name);
// Create PCS entry
hicn_pcs_entry_t *pcs_entry;
ret = hicn_pcs_lookup_one (pcs, &name, &pcs_entry);
// We will not find the entry
TEST_ASSERT_EQUAL (ret, HICN_ERROR_PCS_NOT_FOUND);
TEST_ASSERT_EQUAL (NULL, pcs_entry);
// Get a new entry from the pool
// TODO Check if the hicn_pcs_entry_pit_get is needed here
pcs_entry = hicn_pcs_entry_pit_get (pcs, 0, 0);
TEST_ASSERT_NOT_NULL (pcs_entry);
TEST_ASSERT_EQUAL (hicn_pcs_get_pcs_alloc (pcs), 1);
// Insert PIT entry
ret = hicn_pcs_pit_insert (pcs, pcs_entry, &name);
TEST_ASSERT_EQUAL (HICN_ERROR_NONE, ret);
TEST_ASSERT_EQUAL (hicn_pcs_get_pit_count (pcs), 1);
TEST_ASSERT_EQUAL (hicn_pcs_get_cs_count (pcs), 0);
// Lookup PIT entry
hicn_pcs_entry_t *pcs_entry_ret = NULL;
ret = hicn_pcs_lookup_one (pcs, &name, &pcs_entry_ret);
TEST_ASSERT_EQUAL (HICN_ERROR_NONE, ret);
TEST_ASSERT_NOT_NULL (pcs_entry_ret);
TEST_ASSERT_EQUAL (pcs_entry, pcs_entry_ret);
// Found the PIT entry we inserted before.
// Double check is not a CS
TEST_ASSERT_FALSE (pcs_entry_ret->flags & HICN_PCS_ENTRY_CS_FLAG);
// Turn the PIT entry into a CS
hicn_pit_to_cs (pcs, pcs_entry, /* random buffer index */ 12345);
// Check counters
TEST_ASSERT_EQUAL (hicn_pcs_get_pit_count (pcs), 0);
TEST_ASSERT_EQUAL (hicn_pcs_get_cs_count (pcs), 1);
// Make sure entry is now a CS
TEST_ASSERT_TRUE (pcs_entry_ret->flags & HICN_PCS_ENTRY_CS_FLAG);
}
TEST (PCS, CheckCSLruConsistency)
{
hicn_pit_cs_t *pcs = &global_pcs;
// Add entry to the PCS
int ret = 0;
// Allocate name
hicn_name_t name;
hicn_name_create ("b001::1234", 0, &name);
// Create CS entry
hicn_pcs_entry_t *pcs_entry;
// Get a new entry from the pool
// TODO Check if the hicn_pcs_entry_pit_get is needed here
pcs_entry = hicn_pcs_entry_cs_get (pcs, 0, 0);
TEST_ASSERT_NOT_NULL (pcs_entry);
TEST_ASSERT_EQUAL (hicn_pcs_get_pcs_alloc (pcs), 1);
// Insert CS entry
ret = hicn_pcs_cs_insert (pcs, pcs_entry, &name);
TEST_ASSERT_EQUAL (HICN_ERROR_NONE, ret);
TEST_ASSERT_EQUAL (hicn_pcs_get_cs_count (pcs), 1);
TEST_ASSERT_EQUAL (hicn_pcs_get_pit_count (pcs), 0);
// Get pcs_entry index
uint32_t pcs_entry_index = hicn_pcs_entry_get_index (pcs, pcs_entry);
// Check LRU
hicn_cs_policy_t *policy_state = hicn_pcs_get_policy_state (pcs);
// Make sure MAX corresponds to what we set
TEST_ASSERT_EQUAL (MAX_CS_ELEMENTS, hicn_cs_policy_get_max (policy_state));
TEST_ASSERT_EQUAL (pcs_entry_index, hicn_cs_policy_get_head (policy_state));
TEST_ASSERT_EQUAL (pcs_entry_index, hicn_cs_policy_get_tail (policy_state));
TEST_ASSERT_EQUAL (1, hicn_cs_policy_get_count (policy_state));
// Check pointers of the entry
TEST_ASSERT_EQUAL (HICN_CS_POLICY_END_OF_CHAIN,
hicn_pcs_entry_cs_get_next (pcs_entry));
TEST_ASSERT_EQUAL (HICN_CS_POLICY_END_OF_CHAIN,
hicn_pcs_entry_cs_get_prev (pcs_entry));
// Lookup the entry itself
ret = hicn_pcs_lookup_one (pcs, &name, &pcs_entry);
// Check again the pointers of the entry
TEST_ASSERT_EQUAL (HICN_CS_POLICY_END_OF_CHAIN,
hicn_pcs_entry_cs_get_next (pcs_entry));
TEST_ASSERT_EQUAL (HICN_CS_POLICY_END_OF_CHAIN,
hicn_pcs_entry_cs_get_prev (pcs_entry));
// Remove CS entry
hicn_pcs_entry_remove_lock (pcs, pcs_entry);
TEST_ASSERT_EQUAL (1, hicn_pcs_get_pcs_dealloc (pcs));
TEST_ASSERT_EQUAL (0, hicn_pcs_get_pit_count (pcs));
TEST_ASSERT_EQUAL (0, hicn_pcs_get_cs_count (pcs));
// Check again LRU
TEST_ASSERT_EQUAL (HICN_CS_POLICY_END_OF_CHAIN,
hicn_cs_policy_get_head (policy_state));
TEST_ASSERT_EQUAL (HICN_CS_POLICY_END_OF_CHAIN,
hicn_cs_policy_get_tail (policy_state));
TEST_ASSERT_EQUAL (0, hicn_cs_policy_get_count (policy_state));
// Let's insert now 2 entries
hicn_pcs_entry_t *pcs_entry0;
hicn_pcs_entry_t *pcs_entry1;
pcs_entry0 = hicn_pcs_entry_cs_get (pcs, 0, 0);
TEST_ASSERT_NOT_NULL (pcs_entry0);
hicn_name_t name0;
hicn_name_create ("b001::abcd", 123, &name0);
u32 index0 = hicn_pcs_entry_get_index (pcs, pcs_entry0);
pcs_entry1 = hicn_pcs_entry_cs_get (pcs, 0, 0);
TEST_ASSERT_NOT_NULL (pcs_entry1);
hicn_name_t name1;
hicn_name_create ("b001::9999", 321, &name1);
u32 index1 = hicn_pcs_entry_get_index (pcs, pcs_entry1);
// Insert CS entry
ret = hicn_pcs_cs_insert (pcs, pcs_entry0, &name0);
ret = hicn_pcs_cs_insert (pcs, pcs_entry1, &name1);
// Check LRU. index1 was inserted last, so it should be at the head
TEST_ASSERT_EQUAL (index1, hicn_cs_policy_get_head (policy_state));
// index0 was inserted first, so it should be at the tail
TEST_ASSERT_EQUAL (index0, hicn_cs_policy_get_tail (policy_state));
// And count shoould be 2
TEST_ASSERT_EQUAL (2, hicn_cs_policy_get_count (policy_state));
// Check pointers of the entries
// pcs_entry0 should be at the tail
TEST_ASSERT_EQUAL (HICN_CS_POLICY_END_OF_CHAIN,
hicn_pcs_entry_cs_get_next (pcs_entry0));
TEST_ASSERT_EQUAL (index1, hicn_pcs_entry_cs_get_prev (pcs_entry0));
// pcs_entry1 should be at the head
TEST_ASSERT_EQUAL (index0, hicn_pcs_entry_cs_get_next (pcs_entry1));
TEST_ASSERT_EQUAL (HICN_CS_POLICY_END_OF_CHAIN,
hicn_pcs_entry_cs_get_prev (pcs_entry1));
// Let's lookup for entry 0 and check if the LRU is updated correctly
ret = hicn_pcs_lookup_one (pcs, &name0, &pcs_entry);
TEST_ASSERT_EQUAL (HICN_ERROR_NONE, ret);
TEST_ASSERT_EQUAL (index0, hicn_pcs_entry_get_index (pcs, pcs_entry));
// Check pointers of the entries
// pcs_entry1 should be at the tail
TEST_ASSERT_EQUAL (HICN_CS_POLICY_END_OF_CHAIN,
hicn_pcs_entry_cs_get_next (pcs_entry1));
TEST_ASSERT_EQUAL (index0, hicn_pcs_entry_cs_get_prev (pcs_entry1));
// pcs_entry0 should be at the head
TEST_ASSERT_EQUAL (index1, hicn_pcs_entry_cs_get_next (pcs_entry0));
TEST_ASSERT_EQUAL (HICN_CS_POLICY_END_OF_CHAIN,
hicn_pcs_entry_cs_get_prev (pcs_entry0));
// index0 should be now the head
TEST_ASSERT_EQUAL (index0, hicn_cs_policy_get_head (policy_state));
// index1 should be now the tail
TEST_ASSERT_EQUAL (index1, hicn_cs_policy_get_tail (policy_state));
}
TEST (PCS, CheckCSLruMax)
{
hicn_pit_cs_t *pcs = &global_pcs;
int i, ret = 0;
;
u32 pcs_entry_index = 0;
u32 pcs_entry_index0 = 0;
u32 pcs_entry_index1 = 0;
hicn_pcs_entry_t *pcs_entry = NULL;
hicn_name_t name;
const hicn_cs_policy_t *policy_state = hicn_pcs_get_policy_state (pcs);
for (i = 0; i < MAX_CS_ELEMENTS; i++)
{
// Allocate name
ret = hicn_name_create ("b004::aaaa", i, &name);
TEST_ASSERT_EQUAL (0, ret);
// Create CS entry
// Get a new entry from the pool
// TODO Check if the hicn_pcs_entry_pit_get is needed here
pcs_entry = hicn_pcs_entry_cs_get (pcs, 0, i);
TEST_ASSERT_NOT_NULL (pcs_entry);
TEST_ASSERT_EQUAL (i + 1, hicn_pcs_get_pcs_alloc (pcs));
pcs_entry_index = hicn_pcs_entry_get_index (pcs, pcs_entry);
if (i == 0)
{
pcs_entry_index0 = pcs_entry_index;
}
if (i == 1)
{
pcs_entry_index1 = pcs_entry_index;
}
// Insert CS entry
ret = hicn_pcs_cs_insert (pcs, pcs_entry, &name);
TEST_ASSERT_EQUAL (HICN_ERROR_NONE, ret);
TEST_ASSERT_EQUAL (hicn_pcs_get_cs_count (pcs), i + 1);
TEST_ASSERT_EQUAL (hicn_pcs_get_pit_count (pcs), 0);
// Check LRU
TEST_ASSERT_EQUAL (pcs_entry_index,
hicn_cs_policy_get_head (policy_state));
TEST_ASSERT_EQUAL (pcs_entry_index0,
hicn_cs_policy_get_tail (policy_state));
TEST_ASSERT_EQUAL (i + 1, hicn_cs_policy_get_count (policy_state));
}
// In this moment the CS should be full
TEST_ASSERT_EQUAL (hicn_cs_policy_get_max (policy_state),
hicn_cs_policy_get_count (policy_state));
// Next insertion should:
// - evict the tail
// - update the head
// - make a coffee because I am tired
ret = hicn_name_create ("b004::aaaa", i, &name);
TEST_ASSERT_EQUAL (0, ret);
pcs_entry = hicn_pcs_entry_cs_get (pcs, 0, i);
TEST_ASSERT_NOT_NULL (pcs_entry);
TEST_ASSERT_EQUAL (i + 1, hicn_pcs_get_pcs_alloc (pcs));
pcs_entry_index = hicn_pcs_entry_get_index (pcs, pcs_entry);
// Insert CS entry
ret = hicn_pcs_cs_insert (pcs, pcs_entry, &name);
TEST_ASSERT_EQUAL (HICN_ERROR_NONE, ret);
TEST_ASSERT_EQUAL (hicn_pcs_get_cs_count (pcs), i);
TEST_ASSERT_EQUAL (hicn_pcs_get_pit_count (pcs), 0);
// Check LRU
TEST_ASSERT_EQUAL (pcs_entry_index, hicn_cs_policy_get_head (policy_state));
// pcs_entry_index1 should be have eveicted, and pcs_entry_index1 should be
// the tail
TEST_ASSERT_EQUAL (pcs_entry_index1, hicn_cs_policy_get_tail (policy_state));
// Make pcs_entry_index0 was freed.
TEST_ASSERT_TRUE (
pool_is_free_index (pcs->pcs_entries_pool, pcs_entry_index0));
}
TEST (PCS, AddIngressFacesToPITEntry)
{
hicn_pit_cs_t *pcs = &global_pcs;
// Add entry to the PCS
int ret = 0;
// Allocate name
hicn_name_t name;
hicn_name_create ("b001::9876", 0, &name);
// Create PCS entry
hicn_pcs_entry_t *pcs_entry;
ret = hicn_pcs_lookup_one (pcs, &name, &pcs_entry);
// We will not find the entry
TEST_ASSERT_EQUAL (ret, HICN_ERROR_PCS_NOT_FOUND);
TEST_ASSERT_EQUAL (NULL, pcs_entry);
// Get a new entry from the pool
// TODO Check if the hicn_pcs_entry_pit_get is needed here
f64 tnow = 10.0;
pcs_entry = hicn_pcs_entry_pit_get (pcs, tnow, 0);
TEST_ASSERT_NOT_NULL (pcs_entry);
TEST_ASSERT_EQUAL (hicn_pcs_get_pcs_alloc (pcs), 1);
const u32 faceid = 20;
// The face should not be in the PIT entry
TEST_ASSERT_EQUAL (0, hicn_pcs_entry_pit_search (pcs_entry, faceid));
// Add ingress face to pit entry
hicn_pcs_entry_pit_add_face (pcs_entry, faceid);
// Insert PIT entry
ret = hicn_pcs_pit_insert (pcs, pcs_entry, &name);
TEST_ASSERT_EQUAL (HICN_ERROR_NONE, ret);
TEST_ASSERT_EQUAL (hicn_pcs_get_pit_count (pcs), 1);
TEST_ASSERT_EQUAL (hicn_pcs_get_cs_count (pcs), 0);
// Lookup PIT entry
hicn_pcs_entry_t *pcs_entry_ret = NULL;
ret = hicn_pcs_lookup_one (pcs, &name, &pcs_entry_ret);
TEST_ASSERT_EQUAL (HICN_ERROR_NONE, ret);
TEST_ASSERT_NOT_NULL (pcs_entry_ret);
TEST_ASSERT_EQUAL (pcs_entry, pcs_entry_ret);
// Check everything is fine
ret = hicn_pcs_entry_pit_search (pcs_entry_ret, faceid);
// Face 20 should be in the entry
TEST_ASSERT_EQUAL (ret, 1);
// Get faces and make sure
// - there is only one face
// - the face is 20
TEST_ASSERT_EQUAL (1, hicn_pcs_entry_pit_get_n_faces (pcs_entry_ret));
TEST_ASSERT_EQUAL (20, hicn_pcs_entry_pit_get_dpo_face (pcs_entry_ret, 0));
// Release PIT entry
hicn_pcs_entry_remove_lock (pcs, pcs_entry_ret);
TEST_ASSERT_EQUAL (hicn_pcs_get_pcs_dealloc (pcs), 1);
TEST_ASSERT_EQUAL (hicn_pcs_get_pit_count (pcs), 0);
TEST_ASSERT_EQUAL (hicn_pcs_get_cs_count (pcs), 0);
// Lookup PIT entry again, we should not find it
ret = hicn_pcs_lookup_one (pcs, &name, &pcs_entry_ret);
TEST_ASSERT_EQUAL (HICN_ERROR_PCS_NOT_FOUND, ret);
TEST_ASSERT_EQUAL (NULL, pcs_entry_ret);
}
TEST (PCS, AddIngressFacesToPitEntryCornerCases)
{
hicn_pit_cs_t *pcs = &global_pcs;
// Add entry to the PCS
int ret = 0;
// Allocate name
hicn_name_t name;
hicn_name_create ("b001::9876", 0, &name);
// Create PCS entry
hicn_pcs_entry_t *pcs_entry;
ret = hicn_pcs_lookup_one (pcs, &name, &pcs_entry);
// We will not find the entry
TEST_ASSERT_EQUAL (ret, HICN_ERROR_PCS_NOT_FOUND);
TEST_ASSERT_EQUAL (NULL, pcs_entry);
// Get a new entry from the pool
// TODO Check if the hicn_pcs_entry_pit_get is needed here
f64 tnow = 10.0;
pcs_entry = hicn_pcs_entry_pit_get (pcs, tnow, 0);
TEST_ASSERT_NOT_NULL (pcs_entry);
TEST_ASSERT_EQUAL (hicn_pcs_get_pcs_alloc (pcs), 1);
// Let's initialize HICN_FACE_DB_INLINE_FACES + 1 face IDs
u32 faceids[HICN_FACE_DB_INLINE_FACES + 1];
for (u32 i = 0; i < HICN_FACE_DB_INLINE_FACES + 1; i++)
faceids[i] = rand () % HICN_PARAM_FACES_MAX;
// The faces should not be in the PIT entry
for (u32 i = 0; i < HICN_FACE_DB_INLINE_FACES + 1; i++)
TEST_ASSERT_EQUAL (0, hicn_pcs_entry_pit_search (pcs_entry, faceids[i]));
// Add ingress faces to pit entry
for (u32 i = 0; i < HICN_FACE_DB_INLINE_FACES + 1; i++)
hicn_pcs_entry_pit_add_face (pcs_entry, faceids[i]);
// Insert PIT entry
ret = hicn_pcs_pit_insert (pcs, pcs_entry, &name);
TEST_ASSERT_EQUAL (HICN_ERROR_NONE, ret);
TEST_ASSERT_EQUAL (hicn_pcs_get_pit_count (pcs), 1);
TEST_ASSERT_EQUAL (hicn_pcs_get_cs_count (pcs), 0);
// Lookup PIT entry
hicn_pcs_entry_t *pcs_entry_ret = NULL;
ret = hicn_pcs_lookup_one (pcs, &name, &pcs_entry_ret);
TEST_ASSERT_EQUAL (HICN_ERROR_NONE, ret);
TEST_ASSERT_NOT_NULL (pcs_entry_ret);
TEST_ASSERT_EQUAL (pcs_entry, pcs_entry_ret);
// Check everything is fine
for (u32 i = 0; i < HICN_FACE_DB_INLINE_FACES + 1; i++)
{
ret = hicn_pcs_entry_pit_search (pcs_entry_ret, faceids[i]);
// Face 20 should be in the entry
TEST_ASSERT_EQUAL (1, ret);
}
// Get faces and make sure
// - there are HICN_FACE_DB_INLINE_FACES + 1 faces
// - the first HICN_FACE_DB_INLINE_FACES are stored in the PIT entry
// - the face HICN_FACE_DB_INLINE_FACES + 1 is stored in the array of
// additional faces, so outside PIT entry
TEST_ASSERT_EQUAL (HICN_FACE_DB_INLINE_FACES + 1,
hicn_pcs_entry_pit_get_n_faces (pcs_entry_ret));
for (u32 i = 0; i < HICN_FACE_DB_INLINE_FACES + 1; i++)
TEST_ASSERT_EQUAL (faceids[i],
hicn_pcs_entry_pit_get_dpo_face (pcs_entry_ret, i));
// Release PIT entry
hicn_pcs_entry_remove_lock (pcs, pcs_entry_ret);
TEST_ASSERT_EQUAL (hicn_pcs_get_pcs_dealloc (pcs), 1);
TEST_ASSERT_EQUAL (hicn_pcs_get_pit_count (pcs), 0);
TEST_ASSERT_EQUAL (hicn_pcs_get_cs_count (pcs), 0);
// Lookup PIT entry again, we should not find it
ret = hicn_pcs_lookup_one (pcs, &name, &pcs_entry_ret);
TEST_ASSERT_EQUAL (HICN_ERROR_PCS_NOT_FOUND, ret);
TEST_ASSERT_EQUAL (NULL, pcs_entry_ret);
}
TEST_GROUP_RUNNER (PCS)
{
RUN_TEST_CASE (PCS, Create)
RUN_TEST_CASE (PCS, Destroy)
RUN_TEST_CASE (PCS, LookupEmpty)
RUN_TEST_CASE (PCS, InsertPITEntryAndLookup)
RUN_TEST_CASE (PCS, InsertCSEntryAndLookup)
RUN_TEST_CASE (PCS, PitToCS)
RUN_TEST_CASE (PCS, CheckCSLruConsistency)
RUN_TEST_CASE (PCS, CheckCSLruMax)
RUN_TEST_CASE (PCS, AddIngressFacesToPITEntry)
RUN_TEST_CASE (PCS, AddIngressFacesToPitEntryCornerCases)
}
|