Class: PacketGen::Header::IGMPv3
- Defined in:
- lib/packetgen/header/igmpv3.rb,
lib/packetgen/header/igmpv3/mq.rb,
lib/packetgen/header/igmpv3/mr.rb,
lib/packetgen/header/igmpv3/group_record.rb more...
Overview
This class supports IGMPv3 (RFC3376).
From RFC 3376, a IGMP header has the following format:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type | Max Resp Code | Checksum |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
A IGMP header consists of:
-
a #type field (
BinStruct::Int8Enum
type), -
a #max_resp_time field (
BinStruct::Int8
type), -
a #checksum field (
BinStruct::Int16
type), -
and a #body, containing more fields (see below).
A IGMPv3 header may have additionnal fields. These attributes are handled by additional headers (see MQ).
IGMPv3 specifics
Max Resp Code
#max_resp_code field of IGMPv3 packets is encoded differently than previous versions. This encoding permits to set value up to 31743 (instead of 255 for IGMPv2).
This encoding is handled by #max_resp_code accessors:
igmp.max_resp_code = 10000
igmp.max_resp_code #=> 9728 error due to encoding as a floating point value
IGMPv3 Membership Query
With IGMPv3, a Membership Query packet has more attributes than with IGMPv2. To handle those fields, an additional header should be used:
pkt = PacketGen.gen('IP').add('IGMPv3', type: 'MembershipQuery').add('IGMPv3::MQ')
pkt.igmpv3 #=> PacketGen::Header::IGMPv3
pkt.igmpv3_mq #=> PacketGen::Header::IGMPv3::MQ
IGMPv3 Membership Report
With IGMPv3, a Membership Report packet has more attributes than with IGMPv2. To handle those fields, an additional header should be used:
pkt = PacketGen.gen('IP').add('IGMPv3', type: 'MembershipQuery').add('IGMPv3::MR')
pkt.igmpv3 #=> PacketGen::Header::IGMPv3
pkt.igmpv3_mr #=> PacketGen::Header::IGMPv3::MR
Defined Under Namespace
Classes: GroupRecord, GroupRecords, MQ, MR
Constant Summary collapse
- TYPES =
Known types
{ 'MembershipQuery' => 0x11, 'MembershipReport' => 0x22, }.freeze
Constants inherited from IGMP
PacketGen::Header::IGMP::IP_PROTOCOL
Instance Attribute Summary
Attributes inherited from IGMP
#body, #checksum, #group_addr, #type
Class Method Summary collapse
-
.decode(value) ⇒ Integer
Decode value for IGMPv3 Max Resp Code and QQIC.
-
.encode(value) ⇒ Integer
Encode value for IGMPv3 Max Resp Code and QQIC.
Instance Method Summary collapse
-
#calc_checksum ⇒ Integer
Compute checksum and set
checksum
field. -
#max_resp_time ⇒ Integer
(also: #max_resp_code)
Getter for
max_resp_time
for IGMPv3 packets. -
#max_resp_time=(value) ⇒ Integer
(also: #max_resp_code=)
Setter for
max_resp_time
for IGMPv3 packets.
Methods inherited from IGMP
#added_to_packet, #human_type, #igmpize
Methods inherited from Base
bind, calculate_and_set_length, #header_id, inherited, #initialize, #ip_header, #ll_header
Methods included from PacketGen::Headerable
#added_to_packet, included, #method_name, #packet, #packet=, #parse?, #protocol_name, #read, #to_s
Constructor Details
This class inherits a constructor from PacketGen::Header::Base
Class Method Details
permalink .decode(value) ⇒ Integer
Decode value for IGMPv3 Max Resp Code and QQIC. See RFC 3376 §4.1.1 and §4.1.7.
102 103 104 105 106 107 108 109 110 |
# File 'lib/packetgen/header/igmpv3.rb', line 102 def self.decode(value) if value < 128 value else mant = value & 0xf exp = (value >> 4) & 0x7 (0x10 | mant) << (exp + 3) end end |
permalink .encode(value) ⇒ Integer
Encode value for IGMPv3 Max Resp Code and QQIC. Value may be encoded as a float, so some error may occur. See RFC 3376 §4.1.1 and §4.1.7.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/packetgen/header/igmpv3.rb', line 82 def self.encode(value) if value < 128 value elsif value > 31_743 255 else exp = 0 value >>= 3 while value > 31 exp += 1 value >>= 1 end 0x80 | (exp << 4) | (value & 0xf) end end |
Instance Method Details
permalink #calc_checksum ⇒ Integer
Compute checksum and set checksum
field
129 130 131 132 |
# File 'lib/packetgen/header/igmpv3.rb', line 129 def calc_checksum sum = IP.sum16(self) self.checksum = IP.reduce_checksum(sum) end |
permalink #max_resp_time ⇒ Integer Also known as: max_resp_code
Getter for max_resp_time
for IGMPv3 packets. Use decode.
114 115 116 |
# File 'lib/packetgen/header/igmpv3.rb', line 114 def max_resp_time IGMPv3.decode(self[:max_resp_time].value || self[:max_resp_time].default) end |
permalink #max_resp_time=(value) ⇒ Integer Also known as: max_resp_code=
Setter for max_resp_time
for IGMPv3 packets. Use encode.
122 123 124 |
# File 'lib/packetgen/header/igmpv3.rb', line 122 def max_resp_time=(value) self[:max_resp_time].value = IGMPv3.encode(value) end |