Skip to content

Commit

Permalink
New logger for existing files [part 2]
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominik Scholz committed Sep 15, 2015
1 parent ebc73fe commit fbd1f7a
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 56 deletions.
3 changes: 2 additions & 1 deletion lua/include/bitmask.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
--- @todo TODO docu
---------------------------------

local log = require "log"
local ffi = require "ffi"
ffi.cdef [[
struct mg_bitmask{
Expand Down Expand Up @@ -39,7 +40,7 @@ local mg_bitMask = {}
function mod.createBitMask(size)
return setmetatable({
bitmask = ffi.gc(ffi.C.mg_bitmask_create(size), function (self)
print("I HAVE BEEN DESTRUCTED")
log:debug("I HAVE BEEN DESTRUCTED")
ffi.C.mg_bitmask_free(self)
end )
}, mg_bitMask)
Expand Down
5 changes: 3 additions & 2 deletions lua/include/distribute.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
local ffi = require "ffi"
local dpdk = require "dpdk"
local serpent = require "Serpent"
local log = require "log"

ffi.cdef [[
struct mg_distribute_queue{
Expand Down Expand Up @@ -101,7 +102,7 @@ function mod.createDistributor(socket, entryOffset, nrOutputs, alwaysFlush)

return setmetatable({
cfg = ffi.gc(ffi.C.mg_distribute_create(entryOffset, nrOutputs, alwaysFlush), function(self)
print "lpm garbage"
log:debug("lpm garbage")
ffi.C.mg_NOT_YET_IMPLEMENTED(self) -- FIXME
end),
socket = socket
Expand All @@ -125,7 +126,7 @@ function mg_distribute:registerOutput(outputNumber, txQueue, bufferSize, timeout
local portID = txQueue.id
local queueID = txQueue.qid

print ("register output NR " .. tostring(outputNumber) .. " -> port = " .. tostring(portID) .. " queue = " .. tostring(queueID) .. " timeout = " .. tostring(cycles_timeout))
log:info("register output NR " .. tostring(outputNumber) .. " -> port = " .. tostring(portID) .. " queue = " .. tostring(queueID) .. " timeout = " .. tostring(cycles_timeout))
ffi.C.mg_distribute_register_output(self.cfg, outputNumber, portID, queueID, bufferSize, cycles_timeout)
end

Expand Down
23 changes: 12 additions & 11 deletions lua/include/filter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ local ffi = require "ffi"
local dpdk = require "dpdk"
local mbitmask = require "bitmask"
local err = require "error"
local log = require "log"

mod.DROP = -1

Expand All @@ -28,15 +29,15 @@ deviceDependent[device.PCI_ID_XL710] = require "filter_i40e"
function dev:l2Filter(etype, queue)
if type(queue) == "table" then
if queue.dev.id ~= self.id then
error("Queue must belong to the device being configured")
log:fatal("Queue must belong to the device being configured")
end
queue = queue.qid
end
local fun = deviceDependent[self:getPciId()].l2Filter
if fun then
return fun(self, etype, queue)
else
errorf("l2Filter not supported, or not yet implemented for this device")
log:fatal("l2Filter not supported, or not yet implemented for this device")
end
end

Expand Down Expand Up @@ -65,7 +66,7 @@ function dev:addHW5tupleFilter(filter, queue, priority)
if fun then
return fun(self, filter, queue, priority)
else
errorf("addHW5tupleFilter not supported, or not yet implemented for this device")
log:fatal("addHW5tupleFilter not supported, or not yet implemented for this device")
end
end

Expand All @@ -84,7 +85,7 @@ function dev:filterTimestamps(queue, offset, ntype, ver)
end
offset = offset or 21
if offset ~= 21 then
error("other offsets are not yet supported")
log:fatal("Other offsets are not yet supported")
end
mtype = mtype or 0
ver = ver or 2
Expand Down Expand Up @@ -156,7 +157,7 @@ function mod.create5TupleFilter(socket, acx, numCategories, maxNRules)
local result = setmetatable({
acx = acx or ffi.gc(ffi.C.mg_5tuple_create_filter(socket, maxNRules), function(self)
-- FIXME: why is destructor never called?
print "5tuple garbage"
log:debug("5tuple garbage")
ffi.C.mg_5tuple_destruct_filter(self)
end),
built = false,
Expand Down Expand Up @@ -190,12 +191,12 @@ function mg_filter_5tuple:bindValuesToCategory(values, category)
-- bind bitmask to all categories, which do not yet have an associated bitmask
for i = 1,self.numRealCategories do
if (self.out_values[i-1] == nil) then
print("assigned default at category " .. tostring(i))
log:debug("Assigned default at category " .. tostring(i))
self.out_values[i-1] = values
end
end
else
print("assigned bitmask to category " .. tostring(category))
log:debug("Assigned bitmask to category " .. tostring(category))
self.out_values[category-1] = values
end
return values
Expand All @@ -219,12 +220,12 @@ function mg_filter_5tuple:bindBitmaskToCategory(bitmask, category)
-- bind bitmask to all categories, which do not yet have an associated bitmask
for i = 1,self.numRealCategories do
if (self.out_masks[i-1] == nil) then
print("assigned default at category " .. tostring(i))
log:debug("Assigned default at category " .. tostring(i))
self.out_masks[i-1] = bitmask.bitmask
end
end
else
print("assigned bitmask to category " .. tostring(category))
log:debug("Assigned bitmask to category " .. tostring(category))
self.out_masks[category-1] = bitmask.bitmask
end
return bitmask
Expand All @@ -244,7 +245,7 @@ end
--- @value 32bit integer value associated with this rule. Value is not allowed to be 0
function mg_filter_5tuple:addRule(rule, priority, category_mask, value)
if(value == 0) then
error("ERROR: Adding a rule with a 0 value is not allowed")
log:fatal("Adding a rule with a 0 value is not allowed")
end
self.buit = false
return ffi.C.mg_5tuple_add_rule(self.acx, rule, priority, category_mask, value)
Expand All @@ -268,7 +269,7 @@ end
--- @return 0 on successfull completion.
function mg_filter_5tuple:classifyBurst(pkts, inMask)
if not self.built then
print("Warning: New rules have been added without building the filter!")
log:warn("New rules have been added without building the filter!")
end
--numCategories = numCategories or self.numCategories
return ffi.C.mg_5tuple_classify_burst(self.acx, pkts.array, inMask.bitmask, self.numCategories, self.numRealCategories, self.out_masks, self.out_values)
Expand Down
5 changes: 3 additions & 2 deletions lua/include/filter_ixgbe.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ local ffi = require "ffi"
local dpdk = require "dpdk"
local mbitmask = require "bitmask"
local err = require "error"
local log = require "log"

local ETQF_BASE = 0x00005128
local ETQS_BASE = 0x0000EC00
Expand Down Expand Up @@ -96,7 +97,7 @@ function mod.addHW5tupleFilter(dev, filter, queue, priority)

sfilter.priority = priority or 1
if(sfilter.priority > 7 or sfilter.priority < 1) then
ferror("Filter priority has to be a number from 1 to 7")
log:fatal("Filter priority has to be a number from 1 to 7")
return
end

Expand Down Expand Up @@ -126,7 +127,7 @@ function mod.addHW5tupleFilter(dev, filter, queue, priority)
end

if (state ~= 0) then
errorf("Filter not successfully added: %s", err.getstr(-state))
log:fatal("Filter not successfully added: %s", err.getstr(-state))
end

return idx
Expand Down
3 changes: 2 additions & 1 deletion lua/include/histogram.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ local histogram = {}
histogram.__index = histogram

local serpent = require "Serpent"
local log = require "log"

function histogram:create()
local histo = setmetatable({}, histogram)
Expand Down Expand Up @@ -128,7 +129,7 @@ function histogram:save(file)
if self.dirty then self:calc() end
local close = false
if type(file) ~= "userdata" then
printf("Saving histogram to '%s'", file)
log:info("Saving histogram to '%s'", file)
file = io.open(file, "w+")
close = true
end
Expand Down
41 changes: 21 additions & 20 deletions lua/include/ipsec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ local mod = {}
local dpdkc = require "dpdkc"
local dpdk = require "dpdk"
local ffi = require "ffi"
local log ? require "log"

-- Intel X540 registers
local SECTXCTRL = 0x00008800
Expand Down Expand Up @@ -51,7 +52,7 @@ end
-- Helper function to clear a single bit
function clear_bit32(reg32, idx)
if idx < 0 or idx > 31 then
error("Idx must be in range 0-31")
log:fatal("Idx must be in range 0-31")
end
local mask = bit.bnot(bit.lshift(0x1, idx))
return bit.band(reg32, mask)
Expand All @@ -60,7 +61,7 @@ end
-- Helper function to set a single bit
function set_bit32(reg32, idx)
if idx < 0 or idx > 31 then
error("Idx must be in range 0-31")
log:fatal("Idx must be in range 0-31")
end
return bit.bor(reg32, bit.lshift(0x1, idx))
end
Expand All @@ -78,7 +79,7 @@ end
function set_bits32(reg32, from, to, value)
local upper_limit = math.pow(2, ((from-to)+1))-1 --i.e. (2^num_bits)-1
if value < 0 or value > upper_limit then
error("Value must be in range 0-"..upper_limit)
log:fatal("Value must be in range 0-"..upper_limit)
end
local tmp = clear_bits32(reg32, from, to)
return bit.bor(tmp, bit.lshift(value, to))
Expand Down Expand Up @@ -225,13 +226,13 @@ end
--- @param salt 32 bit AES salt (as hex string)
function mod.tx_set_key(port, idx, key, salt)
if idx > 1023 or idx < 0 then
error("Idx must be in range 0-1023")
log:fatal("Idx must be in range 0-1023")
end
if string.len(key) ~= 32 then
error("Key must be 128 bit (hex string).")
log:fatal("Key must be 128 bit (hex string).")
end
if string.len(salt) ~= 8 then
error("Salt must be 32 bit (hex string).")
log:fatal("Salt must be 32 bit (hex string).")
end

local key_3 = tonumber(string.sub(key, 1, 8), 16) --MSB
Expand Down Expand Up @@ -263,7 +264,7 @@ end
--- @return Key and Salt (as hex string)
function mod.tx_get_key(port, idx)
if idx > 1023 or idx < 0 then
error("Idx must be in range 0-1023")
log:fatal("Idx must be in range 0-1023")
end

-- Prepare command to read key from SA_IDX
Expand Down Expand Up @@ -297,13 +298,13 @@ end
--- @param decrypt ESP mode (1=ESP decrypt and authenticate, 0=ESP authenticate only)
function mod.rx_set_key(port, idx, key, salt, ip_ver, proto, decrypt)
if idx > 1023 or idx < 0 then
error("Idx must be in range 0-1023")
log:fatal("Idx must be in range 0-1023")
end
if string.len(key) ~= 32 then
error("Key must be 128 bit (hex string).")
log:fatal("Key must be 128 bit (hex string).")
end
if string.len(salt) ~= 8 then
error("Salt must be 32 bit (hex string).")
log:fatal("Salt must be 32 bit (hex string).")
end

local ipv6 = nil
Expand All @@ -312,7 +313,7 @@ function mod.rx_set_key(port, idx, key, salt, ip_ver, proto, decrypt)
elseif ip_ver == 6 then
ipv6 = 1
else
error("IP version must be either 4 or 6")
log:fatal("IP version must be either 4 or 6")
end

local esp = nil
Expand All @@ -321,12 +322,12 @@ function mod.rx_set_key(port, idx, key, salt, ip_ver, proto, decrypt)
elseif proto == "ah" then
esp = 0
else
error("Protocol must be either 'esp' or 'ah'")
log:fatal("Protocol must be either 'esp' or 'ah'")
end

local esp_mode = decrypt or 0
if esp_mode ~= 1 and esp_mode ~= 0 then
error("ESP Decrypt must be either 0 or 1")
log:fatal("ESP Decrypt must be either 0 or 1")
end

local key_3 = tonumber(string.sub(key, 1, 8), 16) --MSB
Expand Down Expand Up @@ -369,7 +370,7 @@ end
--- IPv6 Flag (1=SA is valid for IPv6, 0=SA is valid for IPv4)
function mod.rx_get_key(port, idx)
if idx > 1023 or idx < 0 then
error("Idx must be in range 0-1023")
log:fatal("Idx must be in range 0-1023")
end

-- Prepare command to read from KEY_TABLE at TB_IDX
Expand Down Expand Up @@ -405,7 +406,7 @@ end
--- @param ip_addr IP(v4/v6)-Address to set (as string)
function mod.rx_set_ip(port, idx, ip_addr)
if idx > 127 or idx < 0 then
error("Idx must be in range 0-127")
log_fatal("Idx must be in range 0-127")
end

local ip, is_ipv4 = parseIPAddress(ip_addr)
Expand Down Expand Up @@ -447,7 +448,7 @@ end
--- @return The IP(v4/v6)-Address (as string) and a IP Version Flag (true=IPv4, false=IPv6)
function mod.rx_get_ip(port, idx, is_ipv4)
if idx > 127 or idx < 0 then
error("Idx must be in range 0-127")
log:fatal("Idx must be in range 0-127")
end
if is_ipv4 == nil then
is_ipv4 = true
Expand Down Expand Up @@ -493,13 +494,13 @@ end
--- @param ip_idx Reference to the IP table. This must match the idx of the corresponding IP table entry.
function mod.rx_set_spi(port, idx, spi, ip_idx)
if idx > 1023 or idx < 0 then
error("Idx must be in range 0-1023")
log:fatal("Idx must be in range 0-1023")
end
if spi > 0xFFFFFFFF or spi < 0 then
error("Spi must be in range 0x0-0xFFFFFFFF")
log:fatal("Spi must be in range 0x0-0xFFFFFFFF")
end
if ip_idx > 127 or ip_idx < 0 then
error("IP_Idx must be in range 0-127")
log:fatal("IP_Idx must be in range 0-127")
end

-- Prepare command to write SPI_TABLE at TB_IDX
Expand All @@ -525,7 +526,7 @@ end
--- @return The SPI and the corresponding Index into the IP table
function mod.rx_get_spi(port, idx)
if idx > 1023 or idx < 0 then
error("Idx must be in range 0-1023")
log:fatal("Idx must be in range 0-1023")
end

-- Prepare command to read from SPI_TABLE at TB_IDX
Expand Down
3 changes: 2 additions & 1 deletion lua/include/lock.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ local mod = {}

local ffi = require "ffi"
local stp = require "StackTracePlus"
local log = require "log"

ffi.cdef [[
struct lock { };
Expand Down Expand Up @@ -65,7 +66,7 @@ function lock:__call(func, ...)
self:unlock()
if not ok then
-- FIXME: this output is going to be ugly because it will output the local err as well :>
error("caught error in lock-wrapped call, inner error: " .. err, 2)
log:fatal("Caught error in lock-wrapped call, inner error: " .. err, 2)
end
end

Expand Down
5 changes: 3 additions & 2 deletions lua/include/lpm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ local band, lshift, rshift = bit.band, bit.lshift, bit.rshift
local dpdkc = require "dpdkc"
local dpdk = require "dpdk"
local serpent = require "Serpent"
local log = require "log"
require "memory"
--local burst = require "burst"

Expand Down Expand Up @@ -87,7 +88,7 @@ function mod.createLpm4Table(socket, table, entry_ctype)
return setmetatable({
table = table or ffi.gc(ffi.C.mg_table_lpm_create(params, socket, ffi.sizeof(entry_ctype)), function(self)
-- FIXME: why is destructor never called?
print "lpm garbage"
log:debug("lpm garbage")
ffi.C.mg_table_lpm_free(self)
end),
entry_ctype = entry_ctype
Expand Down Expand Up @@ -185,7 +186,7 @@ function mod.decrementTTL(pkts, in_mask, out_mask, ipv4)
end
end
else
errorf("TTL decrement for ipv6 not yet implemented")
log:fatal("TTL decrement for ipv6 not yet implemented")
end
end

Expand Down
Loading

0 comments on commit fbd1f7a

Please sign in to comment.