-
Notifications
You must be signed in to change notification settings - Fork 298
/
probe.lua
193 lines (178 loc) · 5 KB
/
probe.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
-- This module implements the `snabb flow_export` command
module(..., package.seeall)
local lib = require("core.lib")
local long_opts = {
help = "h",
jit = "j",
duration = "D",
port = "p",
transport = 1,
["host-ip"] = "a",
["input-type"] = "i",
["output-type"] = "o",
["mtu"] = 1,
["netflow-v9"] = 0,
["ipfix"] = 0,
["active-timeout"] = 1,
["idle-timeout"] = 1,
["observation-domain"] = 1,
["template-refresh"] = 1,
["flush-timeout"] = 1,
["cache-size"] = 1,
["scan-time"] = 1,
["pfx-to-as"] = 1,
["maps-log"] = 1,
["vlan-to-ifindex"] = 1,
["mac-to-as"] = 1,
["cpu"] = 1,
["busy-wait"] = "b"
}
function run (args)
local duration
local busywait = false
local jit = { opts = {} }
local input_type, output_type = "pci", "pci"
local host_mac
local host_ip = '10.0.0.1' -- Just to have a default.
local collector_ip = '10.0.0.2' -- Likewise.
local port = 4739
local mtu = 1514
local active_timeout, idle_timeout, flush_timeout, scan_time
local observation_domain, template_refresh_interval
local cache_size
local ipfix_version = 10
local templates = {}
local maps = {}
local maps_logfile
local pfx_to_as, vlan_to_ifindex, mac_to_as
local cpu
-- TODO: better input validation
local opt = {
h = function (arg)
print(require("program.ipfix.probe.README_inc"))
main.exit(0)
end,
D = function (arg)
duration = assert(tonumber(arg), "expected number for duration")
end,
i = function (arg)
input_type = arg
end,
o = function (arg)
output_type = arg
end,
p = function (arg)
port = assert(tonumber(arg), "expected number for port")
end,
m = function (arg)
host_mac = arg
end,
a = function (arg)
host_ip = arg
end,
c = function (arg)
collector_ip = arg
end,
b = function (arg)
busywait = true
end,
["active-timeout"] = function (arg)
active_timeout =
assert(tonumber(arg), "expected number for active timeout")
end,
["idle-timeout"] = function (arg)
idle_timeout =
assert(tonumber(arg), "expected number for idle timeout")
end,
["flush-timeout"] = function (arg)
flush_timeout =
assert(tonumber(arg), "expected number for flush timeout")
end,
["scan-time"] = function (arg)
scan_time =
assert(tonumber(arg), "expected number for scan time")
end,
["observation-domain"] = function (arg)
observation_domain =
assert(tonumber(arg), "expected number for observation domain")
end,
["template-refresh"] = function (arg)
template_refresh_interval =
assert(tonumber(arg), "expected number for template refresh interval")
end,
["cache-size"] = function (arg)
cache_size =
assert(tonumber(arg), "expected number for cache size")
end,
["pfx-to-as"] = function (arg)
if arg then
maps.pfx_to_as = arg
end
end,
["vlan-to-ifindex"] = function (arg)
if arg then
maps.vlan_to_ifindex = arg
end
end,
["mac-to-as"] = function (arg)
if arg then
maps.mac_to_as = arg
end
end,
["maps-log"] = function (arg)
if arg ~= "" then
maps_logfile = arg
end
end,
ipfix = function (arg)
ipfix_version = 10
end,
["netflow-v9"] = function (arg)
ipfix_version = 9
end,
["mtu"] = function (arg)
mtu = tonumber(arg)
end,
-- TODO: not implemented
["transport"] = function (arg) end,
["cpu"] = function (arg)
cpu = tonumber(arg)
end,
j = require("program.ipfix.lib").parse_jit_option_fn(jit)
}
args = lib.dogetopt(args, opt, "hD:i:o:p:m:a:c:j:b", long_opts)
if #args < 2 then
print(require("program.ipfix.probe.README_inc"))
main.exit(1)
elseif #args == 2 then
table.insert(args, 'v4')
table.insert(args, 'v6')
end
local input, output = args[1], args[2]
for i = 3, #args do
table.insert(templates, args[i])
end
local probe_config = {
active_timeout = active_timeout,
idle_timeout = idle_timeout,
flush_timeout = flush_timeout,
cache_size = cache_size,
scan_time = scan_time,
observation_domain = observation_domain,
template_refresh_interval = template_refresh_interval,
ipfix_version = ipfix_version,
exporter_ip = host_ip,
exporter_mac = host_mac,
collector_ip = collector_ip,
collector_port = port,
mtu = mtu,
templates = templates,
maps = maps,
maps_logfile = maps_logfile,
output_type = output_type,
output = output,
input_type = input_type,
input = input
}
require("program.ipfix.lib").run(probe_config, duration, busywait, cpu, jit)
end