Class: EventMachine::SFlow::Datagram
- Inherits:
-
Object
- Object
- EventMachine::SFlow::Datagram
- Defined in:
- lib/em-sflow/packet/datagram.rb
Instance Attribute Summary collapse
-
#agent ⇒ Object
readonly
Returns the value of attribute agent.
-
#datagram_sequence ⇒ Object
readonly
Returns the value of attribute datagram_sequence.
-
#samples ⇒ Object
readonly
Returns the value of attribute samples.
-
#sub_agent_id ⇒ Object
readonly
Returns the value of attribute sub_agent_id.
-
#uptime ⇒ Object
readonly
Returns the value of attribute uptime.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
-
#initialize(data) ⇒ Datagram
constructor
A new instance of Datagram.
Constructor Details
#initialize(data) ⇒ Datagram
Returns a new instance of Datagram.
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 |
# File 'lib/em-sflow/packet/datagram.rb', line 4 def initialize data data.extend EM::SFlow::BinaryString @samples = [] @version, ip_version = data.unpack("NN") data.advance(8) if ip_version == 1 @agent = IPAddr.new(data.unpack("N").first, Socket::AF_INET) data.advance(4) else ip_elements = data.unpack("NNNN") @agent = IPAddr.new((ip_elements[0] << 96) + (ip_elements[1] << 64) + (ip_elements[2] << 32) + ip_elements[3], Socket::AF_INET6) data.advance(16) end @sub_agent_id, @datagram_sequence, @uptime, sample_count = data.unpack("NNNN") data.advance(16) sample_count.times do enterprise_format, length = data.unpack("NN") enterprise = enterprise_format >> 12 format = enterprise_format & (2 ** 12 - 1) data.advance(8) sample_data = data.advance(length) if enterprise == 0 && format == 1 @samples << EM::SFlow::FlowSample.new(sample_data) elsif enterprise == 0 && format == 2 @samples << EM::SFlow::CounterSample.new(sample_data) elsif enterprise == 0 && format == 3 @samples << EM::SFlow::ExpandedFlowSample.new(sample_data) elsif enterprise == 0 && format == 4 # @samples << EM::SFlow::ExpandedCounterSample.new(sample_data) end end end |
Instance Attribute Details
#agent ⇒ Object (readonly)
Returns the value of attribute agent.
2 3 4 |
# File 'lib/em-sflow/packet/datagram.rb', line 2 def agent @agent end |
#datagram_sequence ⇒ Object (readonly)
Returns the value of attribute datagram_sequence.
2 3 4 |
# File 'lib/em-sflow/packet/datagram.rb', line 2 def datagram_sequence @datagram_sequence end |
#samples ⇒ Object (readonly)
Returns the value of attribute samples.
2 3 4 |
# File 'lib/em-sflow/packet/datagram.rb', line 2 def samples @samples end |
#sub_agent_id ⇒ Object (readonly)
Returns the value of attribute sub_agent_id.
2 3 4 |
# File 'lib/em-sflow/packet/datagram.rb', line 2 def sub_agent_id @sub_agent_id end |
#uptime ⇒ Object (readonly)
Returns the value of attribute uptime.
2 3 4 |
# File 'lib/em-sflow/packet/datagram.rb', line 2 def uptime @uptime end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
2 3 4 |
# File 'lib/em-sflow/packet/datagram.rb', line 2 def version @version end |