-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
183 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |