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

Function l2_init

core/modules/l2_forward.cc:59–89  ·  view source on GitHub ↗

* l2_init: * Initilizes the l2_table. * It creates the slots of MAX_TABLE_SIZE multiplied by MAX_BUCKET_SIZE. * * @l2tbl: pointer to * @size: number of hash value entries. must be power of 2, greater than 0, and * less than equal to MAX_TABLE_SIZE (2^30) * @bucket: number of slots per hash value. must be power of 2, greater than 0, * and less than equal to MAX_BUCKET_SIZE (

Source from the content-addressed store, hash-verified

57 * and less than equal to MAX_BUCKET_SIZE (4)
58 */
59static int l2_init(struct l2_table *l2tbl, int size, int bucket) {
60 if (size <= 0 || size > MAX_TABLE_SIZE || !is_power_of_2(size)) {
61 return -EINVAL;
62 }
63
64 if (bucket <= 0 || bucket > MAX_BUCKET_SIZE || !is_power_of_2(bucket)) {
65 return -EINVAL;
66 }
67
68 if (l2tbl == nullptr) {
69 return -EINVAL;
70 }
71
72 l2tbl->table = new(std::nothrow) l2_entry[size * bucket]{};
73
74 if (l2tbl->table == nullptr) {
75 return -ENOMEM;
76 }
77
78 l2tbl->size = size;
79 l2tbl->bucket = bucket;
80
81 /* calculates the log_2 (size) */
82 l2tbl->size_power = 0;
83 while (size > 1) {
84 size = size >> 1;
85 l2tbl->size_power += 1;
86 }
87
88 return 0;
89}
90
91static int l2_deinit(struct l2_table *l2tbl) {
92 if (l2tbl == nullptr || l2tbl->table == nullptr || l2tbl->size == 0 ||

Callers 5

l2_forward_init_testFunction · 0.85
l2_forward_entry_testFunction · 0.85
l2_forward_flush_testFunction · 0.85
InitMethod · 0.85

Calls 1

is_power_of_2Function · 0.85

Tested by

no test coverage detected