MCPcopy Create free account
hub / github.com/NetSys/bess / l2_forward_collision_test

Function l2_forward_collision_test

core/modules/l2_forward.cc:470–518  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

468}
469
470static void l2_forward_collision_test() {
471 const int h_size = 4;
472 const int b_size = 4;
473 const int max_hb_cnt = h_size * b_size;
474
475 int ret;
476 int i;
477 struct l2_table l2tbl;
478
479 uint64_t addr[max_hb_cnt];
480 uint16_t idx[max_hb_cnt];
481 int success[max_hb_cnt];
482 uint32_t offset;
483
484 ret = l2_init(&l2tbl, h_size, b_size);
485 DCHECK_EQ(ret, 0);
486
487 /* collision happens */
488 for (i = 0; i < max_hb_cnt; i++) {
489 addr[i] = random() % ULONG_MAX;
490 idx[i] = random() % USHRT_MAX;
491
492 ret = l2_add_entry(&l2tbl, addr[i], idx[i]);
493 LOG(INFO) << "insert result: " << addr[i] << " " << idx[i] << " " << ret;
494 success[i] = (ret >= 0);
495 }
496
497 /* collision happens */
498 for (i = 0; i < max_hb_cnt; i++) {
499 uint16_t gate_index;
500 gate_index = 0;
501 offset = 0;
502
503 ret = l2_find(&l2tbl, addr[i], &gate_index);
504
505 LOG(INFO) << "find result: " << addr[i] << " " << gate_index << " "
506 << offset;
507
508 if (success[i]) {
509 DCHECK_EQ(ret, 0);
510 DCHECK_EQ(idx[i], gate_index);
511 } else {
512 DCHECK_NE(ret, 0);
513 }
514 }
515
516 ret = l2_deinit(&l2tbl);
517 DCHECK_EQ(ret, 0);
518}
519
520int test_all() {
521 l2_forward_init_test();

Callers 1

test_allFunction · 0.85

Calls 4

l2_initFunction · 0.85
l2_add_entryFunction · 0.85
l2_findFunction · 0.85
l2_deinitFunction · 0.85

Tested by 1

test_allFunction · 0.68