Skip to content

Commit

Permalink
ipfix probe: add test.snabb
Browse files Browse the repository at this point in the history
  • Loading branch information
eugeneia committed Oct 5, 2022
1 parent 97e9369 commit c508b40
Show file tree
Hide file tree
Showing 6 changed files with 183 additions and 14 deletions.
28 changes: 18 additions & 10 deletions src/program/ipfix/lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ function configure_graph (arg, in_graph)
return graph, config
end

function configure_rss_graph (config, inputs, outputs, log_date, rss_group)
function configure_rss_graph (config, inputs, outputs, log_date, rss_group, input_type)
input_type = input_type or 'pci'
local graph = app_graph.new()

local rss_name = "rss"..(rss_group or '')
Expand All @@ -242,16 +243,23 @@ function configure_rss_graph (config, inputs, outputs, log_date, rss_group)
-- An input describes a physical interface
local tags, in_app_specs = {}, {}
for n, input in ipairs(inputs) do
local pci_name = normalize_pci_name(input.device)
local input_name = "input_"..pci_name
local in_link, in_app = in_apps.pci(input)
table.insert(in_app_specs,
{ pciaddr = input.device,
name = input_name,
ifname = input.name or pci_name,
ifalias = input.description })
local input_name, link_name, in_link, in_app
if input_type == 'pci' then
local pci_name = normalize_pci_name(input.device)
input_name, link_name = "input_"..pci_name, pci_name
in_link, in_app = in_apps.pci(input)
table.insert(in_app_specs,
{ pciaddr = input.device,
name = input_name,
ifname = input.name or pci_name,
ifalias = input.description })
elseif input_type == 'pcap' then
input_name, link_name = 'pcap', 'pcap'
in_link, in_app = in_apps.pcap(input)
else
error("Unsupported input_type: "..input_type)
end
app_graph.app(graph, input_name, unpack(in_app))
local link_name = pci_name
if input.tag then
local tag = input.tag
assert(not(tags[tag]), "Tag not unique: "..tag)
Expand Down
2 changes: 2 additions & 0 deletions src/program/ipfix/probe/README
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Available options:
-r, --real-time Enable real-time SCHED_FIFO scheduler.
-p, --no-profile Disable VMProfile.
-h, --help Print this help text and exit.
-T, --test-pcap PCAP Testing: read packets from PCAP instead
of NIC.

The mandatory argument <config> must be a path to the initial
configuration file.
Expand Down
16 changes: 12 additions & 4 deletions src/program/ipfix/probe/probe.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ local long_opts = {
name = "n",
busywait ="b",
["real-time"] = "r",
["no-profile"] = "p"
["no-profile"] = "p",
["test-pcap"] = "T"
}
local opt = "hn:brp"
local opt = "hn:brpT:"
local opt_handler = {}
local name
local busywait, real_time, profile = false, false, true
Expand All @@ -32,6 +33,8 @@ function opt_handler.n (arg) name = arg end
function opt_handler.b () busywait = true end
function opt_handler.r () real_time = true end
function opt_handler.p () profile = false end
local pcap_input
function opt_handler.T (arg) pcap_input = arg end

function run (args)
args = lib.dogetopt(args, opt_handler, opt, long_opts)
Expand All @@ -49,7 +52,7 @@ local probe_cpuset = cpuset.new()
local function update_cpuset (cpu_pool)
local cpu_set = {}
if cpu_pool then
for _, cpu in ipairs(cpu_pool.cpu) do
for _, cpu in ipairs(cpu_pool.cpu or {}) do
if not probe_cpuset:contains(cpu) then
probe_cpuset:add(cpu)
end
Expand Down Expand Up @@ -202,6 +205,11 @@ function setup_workers (config)
for rss_group = 1, rss.hardware_scaling.rss_groups do
local inputs, outputs = {}, {}
for device, opt in pairs(interfaces) do
if pcap_input then
table.insert(inputs, pcap_input)
break
end

ensure_device_unique(device, interfaces)
local input = lib.deepcopy(opt)
input.device = device
Expand Down Expand Up @@ -341,7 +349,7 @@ function setup_workers (config)
})
end
workers["rss"..rss_group] = probe.configure_rss_graph(
rss_config, inputs, outputs, ipfix.log_date, rss_group
rss_config, inputs, outputs, ipfix.log_date, rss_group, pcap_input and 'pcap'
)
end

Expand Down
Binary file not shown.
106 changes: 106 additions & 0 deletions src/program/ipfix/tests/test.snabb
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#!../../../snabb

-- A test script for 'snabb ipfix probe'

local ipfix_probe = require("program.ipfix.probe.probe")
local config_rpc = require("program.config.common")
local worker = require("core.worker")
local lib = require("core.lib")


local function get_state (pid, path)
local opts = { command='get-state', with_path=true, is_config=false }
local args = config_rpc.parse_command_line({tostring(pid), path}, opts)
if args.error then
return args
end
local response = config_rpc.call_leader(
args.instance_id, 'get-state',
{ schema = args.schema_name, revision = args.revision_date,
path = args.path, print_default = args.print_default,
format = args.format })
return response
end

local function print_state (pid, path)
local r = get_state(pid, path)
if r.error then
error(r.error)
else
print(r.state)
end
end

local function get_counter (pid, path)
local r = get_state(pid, path)
if r.error then
error(r.error)
else
return tonumber(r.state)
end
end

-- Script

local pcap = "program/ipfix/tests/sanitized500k_truncated128.pcap"
local confpath = "program/ipfix/tests/test_v4_v6_dnshttp.conf"

-- Maybe decompress pcap
if not io.open(pcap) then
local cmd = "bunzip2 -k "..pcap..".bz2"
print(cmd)
os.execute(cmd)
end

local probe_pid = worker.start('ipfix_probe',
([[require("program.ipfix.probe.probe").run{
"-T", %q, %q
}]]):format(pcap, confpath))

local ip4_flows = "/snabbflow-state/exporter[name=ip]/template[id=1256]/flows-exported"
local ip6_flows = "/snabbflow-state/exporter[name=ip]/template[id=1512]/flows-exported"
local http4_flows = "/snabbflow-state/exporter[name=dnshttp]/template[id=257]/flows-exported"
local dns4_flows = "/snabbflow-state/exporter[name=dnshttp]/template[id=258]/flows-exported"
local http6_flows = "/snabbflow-state/exporter[name=dnshttp]/template[id=513]/flows-exported"
local dns6_flows = "/snabbflow-state/exporter[name=dnshttp]/template[id=514]/flows-exported"


local prev_ip4_flows = 0
local function complete ()
local ok, ret = pcall(function ()
return get_counter(probe_pid, ip4_flows)
end)
if not ok then
return false
end
if prev_ip4_flows > 0 and prev_ip4_flows == ret then
return true
else
prev_ip4_flows = ret
return false
end
end

lib.waitfor2("exported flows", complete, 60, 2*1000000) -- 2s interval

print("/snabbflow-state/exporter:")
print_state(probe_pid, "/snabbflow-state/exporter")

local function expect (counter, expected, tolerance)
print(counter)
print("expected:", expected, "+/-", math.floor(expected*tolerance))
local actual = get_counter(probe_pid, counter)
print("actual:", actual)
local diff = math.abs(1-actual/expected)
assert(diff <= tolerance, "Flows mismatch!")
end

expect(ip4_flows, 30000, 0.1)
expect(ip6_flows, 1400, 0.1)
expect(http4_flows, 200, 0.2)
expect(dns4_flows, 1300, 0.2)
expect(http6_flows, 10, 0.3)
expect(dns6_flows, 700, 0.2)


worker.stop('ipfix_probe')
45 changes: 45 additions & 0 deletions src/program/ipfix/tests/test_v4_v6_dnshttp.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
snabbflow-config {
interface {
device "00:00.0";
}
flow-director {
class {
exporter dnshttp;
order 1;
filter "(ip or ip6) and ((udp port 53) or tcp dst port 80)";
continue true;
}
default-class {
exporter ip;
}
remove-ipv6-extension-headers true;
}
ipfix {
idle-timeout 2;
active-timeout 2;
flush-timeout 2;
scan-time 0.1;
exporter-ip 10.0.0.1;
collector-pool { name c1; collector { ip 10.0.0.2; port 4739; } }
maps {
pfx4-to-as { file "program/ipfix/tests/maps/pfx4_to_as.csv"; }
pfx6-to-as { file "program/ipfix/tests/maps/pfx6_to_as.csv"; }
vlan-to-ifindex { file "program/ipfix/tests/maps/vlan_to_ifindex"; }
mac-to-as { file "program/ipfix/tests/maps/mac_to_as"; }
}
exporter {
name ip;
template "v4_extended";
template "v6_extended";
collector-pool c1;
}
exporter {
name dnshttp;
template "v4_HTTP";
template "v4_DNS";
template "v6_HTTP";
template "v6_DNS";
collector-pool c1;
}
}
}

0 comments on commit c508b40

Please sign in to comment.