Skip to main content
. 2023 Apr 7;23(8):3817. doi: 10.3390/s23083817
Algorithm 1 Add to a slot
Require: a hash table with N slots, hash_table; each slot contains three fields: ip, mac, counter; an array with k random numbers, rand; the length of a bucket, row_length; the threshold, T;
1: procedure ADD-A-SLOT(src_ip, dst_mac)
2:  now_column, empty_flag, empty_index, find_flag, hash_value0
3:  insert_slotip: src_ip, mac: dst_mac, counter: 1
4:  for i = 1 to k do
5:    hash_valuehash(src_ip, dst_mac, randi)
6:    now_indexnow_columnrow_length+hash_value
7:    now_columnnow_column+1
8:    read_slotread_hash_table(now_index)
9:    if empty_flag=0 and read_slot.counter=0 then
10:       empty_flag1
11:       empty_indexnow_index
12:    else if read_slot.ip=src_ip and read_slot.mac=dst_mac then
13:       insert_slot.counterread_slot.counter+1
14:       if insert_slot.counterT then
15:         alert_to_controller(dst_mac)
16:         insert_slotip: 0, mac:0, counter: 0
17:       end if
18:       write_hash_table(now_index, insert_slot)
19:       find_flag1
20:    end if
21:  end for
22:  if find_flag=0 and empty_flag=1 then
23:    write_hash_table(empty_index, insert_slot)
24:  end if
25: end procedure