em-sflow 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  == Summary
4
4
 
5
- This gem collects, parses, and optionally proxies sampled flow records from network switches and routers. For information about sFlow, refer to www.sflow.org[http://www.sflow.org].
5
+ This gem collects, parses, and optionally proxies sampled flow records from network switches and routers. For information about sFlow, refer to http://www.sflow.org.
6
6
 
7
7
  == Features
8
8
 
@@ -17,31 +17,26 @@ Version 1.0.0
17
17
 
18
18
  Collector:
19
19
 
20
- EM.run {
21
- c = EventMachine::SFlow::Collector.new(:host => "127.0.0.1")
20
+ c = EventMachine::SFlow::Collector.new(:host => "127.0.0.1")
22
21
 
23
- c.on_sflow do |pkt|
24
- puts "Got #{pkt.samples.count} samples"
22
+ c.on_sflow do |pkt|
23
+ puts "Got #{pkt.samples.count} samples"
25
24
 
26
- pkt.samples.each do |sample|
27
- sample.records.each do |record|
28
- if record.is_a? EM::SFlow::RawPacketHeader
29
- puts "Received a sampled packet from #{pkt.agent} of length #{record.header.size}"
30
- elsif record.is_a? EM::SFlow::GenericInterfaceCounters
31
- puts "Interface #{record.if_index} on #{pkt.agent} has seen #{record.if_in_octets} inbound bytes, #{record.if_out_octets} outbound bytes"
32
- end
25
+ pkt.samples.each do |sample|
26
+ sample.records.each do |record|
27
+ if record.is_a? EM::SFlow::RawPacketHeader
28
+ puts "Received a sampled packet from #{pkt.agent} of length #{record.header.size}"
29
+ elsif record.is_a? EM::SFlow::GenericInterfaceCounters
30
+ puts "Interface #{record.if_index} on #{pkt.agent} has seen #{record.if_in_octets} inbound bytes, #{record.if_out_octets} outbound bytes"
33
31
  end
34
32
  end
35
33
  end
36
- }
34
+ end
37
35
 
38
36
  Proxy:
39
37
 
40
- EM.run {
41
- c = EventMachine::SFlow::Collector.new(:host => "127.0.0.1")
42
-
43
- c.proxy_to "192.168.1.1"
44
- }
38
+ c = EventMachine::SFlow::Collector.new(:host => "127.0.0.1")
39
+ c.proxy_to "192.168.1.1"
45
40
 
46
41
  Multiple callbacks and proxy targets can be defined simultaneously
47
42
 
data/lib/em-sflow.rb CHANGED
@@ -6,8 +6,10 @@ require "ipaddr"
6
6
  require "em-sflow/collector"
7
7
  require "em-sflow/datagram_handler"
8
8
  require "em-sflow/binary_string"
9
+ require "em-sflow/flow_record"
9
10
  require "em-sflow/packet/datagram"
10
11
  require "em-sflow/packet/flow_sample"
12
+ require "em-sflow/packet/expanded_flow_sample"
11
13
  require "em-sflow/packet/counter_sample"
12
14
  require "em-sflow/packet/raw_packet_header"
13
15
  require "em-sflow/packet/generic_interface_counters"
@@ -0,0 +1,55 @@
1
+ module EventMachine
2
+ module SFlow
3
+ module FlowRecord
4
+ def to_flow_records!(record_count)
5
+ records = []
6
+ record_count.times do
7
+ enterprise_format, length = unpack("NN")
8
+
9
+ enterprise = enterprise_format >> 12
10
+ format = enterprise_format & (2 ** 12 - 1)
11
+
12
+ self.advance(8)
13
+
14
+ record_data = self.advance(length)
15
+
16
+ if enterprise == 0 && format == 1
17
+ records << EM::SFlow::RawPacketHeader.new(record_data)
18
+ elsif enterprise == 0 && format == 2
19
+ # records << EM::SFlow::EthernetFrameData.new(record_data)
20
+ elsif enterprise == 0 && format == 3
21
+ # records << EM::SFlow::IPv4Data.new(record_data)
22
+ elsif enterprise == 0 && format == 4
23
+ # records << EM::SFlow::IPv6Data.new(record_data)
24
+ elsif enterprise == 0 && format == 1001
25
+ # records << EM::SFlow::ExtendedSwitchData.new(record_data)
26
+ elsif enterprise == 0 && format == 1002
27
+ # records << EM::SFlow::ExtendedRouterData.new(record_data)
28
+ elsif enterprise == 0 && format == 1003
29
+ # records << EM::SFlow::ExtendedGatewayData.new(record_data)
30
+ elsif enterprise == 0 && format == 1004
31
+ # records << EM::SFlow::ExtendedUserData.new(record_data)
32
+ elsif enterprise == 0 && format == 1005
33
+ # records << EM::SFlow::ExtendedUrlData.new(record_data)
34
+ elsif enterprise == 0 && format == 1006
35
+ # records << EM::SFlow::ExtendedMplsData.new(record_data)
36
+ elsif enterprise == 0 && format == 1007
37
+ # records << EM::SFlow::ExtendedNatData.new(record_data)
38
+ elsif enterprise == 0 && format == 1008
39
+ # records << EM::SFlow::ExtendedMplsTunnel.new(record_data)
40
+ elsif enterprise == 0 && format == 1009
41
+ # records << EM::SFlow::ExtendedMplsVc.new(record_data)
42
+ elsif enterprise == 0 && format == 1010
43
+ # records << EM::SFlow::ExtendedMplsFec.new(record_data)
44
+ elsif enterprise == 0 && format == 1011
45
+ # records << EM::SFlow::ExtendedMplsLvpFec.new(record_data)
46
+ elsif enterprise == 0 && format == 1012
47
+ # records << EM::SFlow::ExtendedVlanTunnel.new(record_data)
48
+ end
49
+ end
50
+
51
+ records
52
+ end
53
+ end
54
+ end
55
+ end
@@ -37,7 +37,7 @@ class EventMachine::SFlow::Datagram
37
37
  elsif enterprise == 0 && format == 2
38
38
  @samples << EM::SFlow::CounterSample.new(sample_data)
39
39
  elsif enterprise == 0 && format == 3
40
- # @samples << EM::SFlow::ExpandedFlowSample.new(sample_data)
40
+ @samples << EM::SFlow::ExpandedFlowSample.new(sample_data)
41
41
  elsif enterprise == 0 && format == 4
42
42
  # @samples << EM::SFlow::ExpandedCounterSample.new(sample_data)
43
43
  end
@@ -0,0 +1,14 @@
1
+ class EventMachine::SFlow::ExpandedFlowSample
2
+ attr_accessor :sequence_number, :source_class, :source_value, :sampling_rate, :sample_pool, :drop_count, :input_type, :input_value, :output_type, :output_value, :records
3
+
4
+ def initialize data
5
+ data.extend EM::SFlow::BinaryString
6
+ data.extend EM::SFlow::FlowRecord
7
+
8
+ @sequence_number, @source_class, @source_value, @sampling_rate, @sample_pool, @drop_count, @input_type, @input_value, @output_type, @output_value, record_count = data.unpack("NNNNNNNNNNN")
9
+
10
+ data.advance(44)
11
+
12
+ @records = data.to_flow_records!(record_count)
13
+ end
14
+ end
@@ -3,6 +3,7 @@ class EventMachine::SFlow::FlowSample
3
3
 
4
4
  def initialize data
5
5
  data.extend EM::SFlow::BinaryString
6
+ data.extend EM::SFlow::FlowRecord
6
7
 
7
8
  @records = []
8
9
 
@@ -13,49 +14,6 @@ class EventMachine::SFlow::FlowSample
13
14
 
14
15
  data.advance(32)
15
16
 
16
- record_count.times do
17
- enterprise_format, length = data.unpack("NN")
18
-
19
- enterprise = enterprise_format >> 12
20
- format = enterprise_format & (2 ** 12 - 1)
21
-
22
- data.advance(8)
23
-
24
- record_data = data.advance(length)
25
-
26
- if enterprise == 0 && format == 1
27
- @records << EM::SFlow::RawPacketHeader.new(record_data)
28
- elsif enterprise == 0 && format == 2
29
- # @records << EM::SFlow::EthernetFrameData.new(record_data)
30
- elsif enterprise == 0 && format == 3
31
- # @records << EM::SFlow::IPv4Data.new(record_data)
32
- elsif enterprise == 0 && format == 4
33
- # @records << EM::SFlow::IPv6Data.new(record_data)
34
- elsif enterprise == 0 && format == 1001
35
- # @records << EM::SFlow::ExtendedSwitchData.new(record_data)
36
- elsif enterprise == 0 && format == 1002
37
- # @records << EM::SFlow::ExtendedRouterData.new(record_data)
38
- elsif enterprise == 0 && format == 1003
39
- # @records << EM::SFlow::ExtendedGatewayData.new(record_data)
40
- elsif enterprise == 0 && format == 1004
41
- # @records << EM::SFlow::ExtendedUserData.new(record_data)
42
- elsif enterprise == 0 && format == 1005
43
- # @records << EM::SFlow::ExtendedUrlData.new(record_data)
44
- elsif enterprise == 0 && format == 1006
45
- # @records << EM::SFlow::ExtendedMplsData.new(record_data)
46
- elsif enterprise == 0 && format == 1007
47
- # @records << EM::SFlow::ExtendedNatData.new(record_data)
48
- elsif enterprise == 0 && format == 1008
49
- # @records << EM::SFlow::ExtendedMplsTunnel.new(record_data)
50
- elsif enterprise == 0 && format == 1009
51
- # @records << EM::SFlow::ExtendedMplsVc.new(record_data)
52
- elsif enterprise == 0 && format == 1010
53
- # @records << EM::SFlow::ExtendedMplsFec.new(record_data)
54
- elsif enterprise == 0 && format == 1011
55
- # @records << EM::SFlow::ExtendedMplsLvpFec.new(record_data)
56
- elsif enterprise == 0 && format == 1012
57
- # @records << EM::SFlow::ExtendedVlanTunnel.new(record_data)
58
- end
59
- end
17
+ @records = data.to_flow_records!(record_count)
60
18
  end
61
19
  end
@@ -1,5 +1,5 @@
1
1
  module EventMachine
2
2
  module SFlow
3
- VERSION = "1.0.1"
3
+ VERSION = "1.0.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,35 +1,46 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: em-sflow
3
- version: !ruby/object:Gem::Version
4
- version: 1.0.1
5
- prerelease:
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 2
9
+ version: 1.0.2
6
10
  platform: ruby
7
- authors:
11
+ authors:
8
12
  - Norman Elton
9
13
  autorequire:
10
14
  bindir: bin
11
15
  cert_chain: []
12
- date: 2012-04-30 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
16
+
17
+ date: 2013-04-05 00:00:00 -04:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
15
21
  name: eventmachine
16
- requirement: &70342806966360 !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 12
30
+ - 10
21
31
  version: 0.12.10
22
32
  type: :runtime
23
- prerelease: false
24
- version_requirements: *70342806966360
33
+ version_requirements: *id001
25
34
  description: EventMachine-powered sFlow Collector
26
- email:
35
+ email:
27
36
  - normelton@gmail.com
28
37
  executables: []
38
+
29
39
  extensions: []
30
- extra_rdoc_files:
40
+
41
+ extra_rdoc_files:
31
42
  - README.rdoc
32
- files:
43
+ files:
33
44
  - .gitignore
34
45
  - Gemfile
35
46
  - LICENSE
@@ -40,41 +51,49 @@ files:
40
51
  - lib/em-sflow/binary_string.rb
41
52
  - lib/em-sflow/collector.rb
42
53
  - lib/em-sflow/datagram_handler.rb
54
+ - lib/em-sflow/flow_record.rb
43
55
  - lib/em-sflow/packet/counter_sample.rb
44
56
  - lib/em-sflow/packet/datagram.rb
45
57
  - lib/em-sflow/packet/ethernet_interface_counters.rb
58
+ - lib/em-sflow/packet/expanded_flow_sample.rb
46
59
  - lib/em-sflow/packet/flow_sample.rb
47
60
  - lib/em-sflow/packet/generic_interface_counters.rb
48
61
  - lib/em-sflow/packet/raw_packet_header.rb
49
62
  - lib/em-sflow/version.rb
63
+ has_rdoc: true
50
64
  homepage: http://github.com/normelton/em-sflow
51
65
  licenses: []
66
+
52
67
  post_install_message:
53
- rdoc_options:
68
+ rdoc_options:
54
69
  - --line-numbers
55
70
  - --inline-source
56
71
  - --title
57
72
  - EM-SFLOW
58
73
  - --main
59
74
  - README.rdoc
60
- require_paths:
75
+ require_paths:
61
76
  - lib
62
- required_ruby_version: !ruby/object:Gem::Requirement
63
- none: false
64
- requirements:
65
- - - ! '>='
66
- - !ruby/object:Gem::Version
67
- version: '0'
68
- required_rubygems_version: !ruby/object:Gem::Requirement
69
- none: false
70
- requirements:
71
- - - ! '>='
72
- - !ruby/object:Gem::Version
73
- version: '0'
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ segments:
82
+ - 0
83
+ version: "0"
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ segments:
89
+ - 0
90
+ version: "0"
74
91
  requirements: []
92
+
75
93
  rubyforge_project:
76
- rubygems_version: 1.8.5
94
+ rubygems_version: 1.3.6
77
95
  signing_key:
78
96
  specification_version: 3
79
97
  summary: EventMachine-powered sFlow Collector
80
98
  test_files: []
99
+