-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_mac.lua
More file actions
executable file
·60 lines (53 loc) · 1.7 KB
/
test_mac.lua
File metadata and controls
executable file
·60 lines (53 loc) · 1.7 KB
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
#!/usr/bin/env luajit
ldablooms = require('ldablooms')
error_rate = 0.05
function mac_gen(random_file)
local bytes = random_file:read(6)
local a, b, c, d, e, f = string.byte(bytes, 1, 6)
return string.format('%02x', a) .. ':' .. string.format('%02x', b) .. ':' .. string.format('%02x', c) .. ':' .. string.format('%02x', d) .. ':' .. string.format('%02x', e) .. ':' .. string.format('%02x', f)
end
function add_to_bloom(bloom, num)
local rfile = io.open('/dev/urandom')
local macfile = io.open('mac_added.txt', 'w')
for i=1, num do
local mac = mac_gen(rfile)
bloom:add(mac, i)
macfile:write(mac .. '\n')
end
bloom:flush()
macfile:close()
rfile:close()
end
function check_true(bloom)
for mac in io.lines('mac_added.txt') do
if bloom:check(mac) ~= true then
io.stderr:write(string.format('ERROR: MAC %s exists in list file, but not in bloom filter', mac))
end
end
end
function check_maybe_false(bloom, num)
local rfile = io.open('/dev/urandom')
local macfile = io.open('mac_exists.txt', 'w')
local n = 0
for i=1, num do
local mac = mac_gen(rfile)
if bloom:check(mac, i) == true then
macfile:write(mac .. '\n')
n = n + 1
end
end
rfile:close()
print(n .. ' MAC addresses exist already. Really?')
end
function test()
local bloom = ldablooms.Dablooms:new(100000, error_rate, 'test2.dablooms')
os.setlocale('')
print(os.date('%c'), 'start filling bloom filter')
add_to_bloom(bloom, 10000000)
print(os.date('%c'), 'finished filling bloom filter. start checking true')
check_true(bloom)
print(os.date('%c'), 'finished checking true. start check false')
check_maybe_false(bloom, 10000000)
print(os.date('%c'), 'all done')
end
test()