test/test_parser_netflow9.rb in fluent-plugin-netflow-0.2.1 vs test/test_parser_netflow9.rb in fluent-plugin-netflow-0.2.2
- old
+ new
@@ -13,22 +13,34 @@
def raw_template
@raw_template ||= File.read(File.expand_path('../dump/netflow.v9.template.dump', __FILE__))
end
+ def raw_mpls_template
+ @raw_mpls_template ||= File.read(File.expand_path('../dump/netflow.v9.mpls-template.dump', __FILE__))
+ end
+
def raw_data
@raw_data ||= File.read(File.expand_path('../dump/netflow.v9.dump', __FILE__))
end
+ def raw_mpls_data
+ @raw_mpls_data ||= File.read(File.expand_path('../dump/netflow.v9.mpls-data.dump', __FILE__))
+ end
+
def raw_sampler_template
@raw_sampler_template ||= File.read(File.expand_path('../dump/netflow.v9.sampler_template.dump', __FILE__))
end
def raw_sampler_data
@raw_sampler_data ||= File.read(File.expand_path('../dump/netflow.v9.sampler.dump', __FILE__))
end
+ def raw_2byte_as_template
+ @raw_2byte_as_template ||= File.read(File.expand_path('../dump/netflow.v9.template.as2.dump', __FILE__))
+ end
+
DEFAULT_HOST = '127.0.0.1'
test 'parse netflow v9 binary data before loading corresponding template' do
parser = create_parser
@@ -124,7 +136,35 @@
parsed << [time, record]
end
assert_equal nil, parsed.first[1]['sampling_algorithm']
assert_equal nil, parsed.first[1]['sampling_interval']
+ end
+
+ test 'parse netflow v9 binary data with templates whose AS field length varies' do
+ parser = create_parser
+
+ parsed = []
+ [raw_2byte_as_template, raw_template].each {|raw| parser.call(raw, DEFAULT_HOST){} }
+ parser.call(raw_data, DEFAULT_HOST) do |time, record|
+ parsed << [time, record]
+ end
+
+ assert_equal 1, parsed.size
+ assert_equal 0, parsed.first[1]['src_as']
+ assert_equal 65000, parsed.first[1]['dst_as']
+ end
+
+ test 'parse netflow v9 binary data contains mpls information' do
+ parser = create_parser
+
+ parsed = []
+ [raw_sampler_template, raw_sampler_data, raw_mpls_template].each {|raw| parser.call(raw, DEFAULT_HOST){} }
+ parser.call(raw_mpls_data, DEFAULT_HOST) do |time, record|
+ parsed << [time, record]
+ end
+
+ assert_equal 24002, parsed.first[1]['mpls_label_1']
+ assert_equal '192.168.32.100', parsed.first[1]['ipv4_src_addr']
+ assert_equal '172.16.32.2', parsed.first[1]['ipv4_dst_addr']
end
end