-
Notifications
You must be signed in to change notification settings - Fork 299
/
report.lua
47 lines (39 loc) · 1.36 KB
/
report.lua
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
-- report.lua -- Reporting status for operation and maintenance
--
-- Copyright 2012 Snabb GmbH. See the file COPYING for license details.
module("report",package.seeall)
local lfs = require("lfs")
local ffi = require("ffi")
commanddir = nil
-- Scan commanddir/* for scripts to execute.
-- For each script S we first execute with output to S.out and then remove S.
function scan ()
local oldstdout, oldstderr = io.stdout, io.stderr
if commanddir ~= nil then
for filename in lfs.dir(commanddir) do
if string.match(filename, ".out") == nil then
path = commanddir.."/"..filename
local output = io.open(path..".out", "w+")
io.stdout, io.stderr = output, output
local status, value = pcall(function () dofile(path) end)
if status == false then
output:write(tostring(value))
end
output:close()
os.remove(path)
end
end
io.stdout, io.stderr = oldstdout, oldstderr
end
end
-- Functions that can be interesting to call
function dump_forwarding_table()
io.stdout:write("-- Snabb Switch forwarding table:\n")
for key,value in pairs(switch.fdb.table) do
io.stdout:write(formatmac(key) .. " -> " .. tostring(value) .. "\n")
end
end
function formatmac (string)
local byte = function (c) return string.format(":%02X",string.byte(c)) end
return string.sub(string.gsub(string, ".", byte), 2)
end