Class: PacketGen::Header::IGMPv3

Inherits:
IGMP show all
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

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 IGMPv3 header may have additionnal fields. These fields are handled by additional headers (see MQ).

Create a IGMPv3 header

# standalone
igmp = PacketGen::Header::IGMPv3.new
# in a packet
pkt = PacketGen.gen('IP').add('IGMPv3')
# access to IGMPv3 header
pkt.igmp    # => PacketGen::Header::IGMPv3

IGMPv3 attributes

igmp.type = 'MembershipQuery'   # or 0x11
igmp.max_resp_time = 20
igmp.checksum = 0x248a

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 fields 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 fields 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

Author:

  • Sylvain Daubert

Since:

  • 2.4.0

Defined Under Namespace

Classes: GroupRecord, GroupRecords, MQ, MR

Constant Summary collapse

TYPES =

Known types

Since:

  • 2.4.0

{
  '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

Instance Method Summary collapse

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

Methods inherited from Types::Fields

#[], #[]=, #bits_on, define_bit_fields_on, define_field, define_field_after, define_field_before, #fields, fields, inherited, #initialize, #inspect, #offset_of, #optional?, #optional_fields, #present?, #read, remove_bit_fields_on, remove_field, #sz, #to_h, #to_s, update_field

Constructor Details

This class inherits a constructor from PacketGen::Header::Base

Class Method Details

.decode(value) ⇒ Integer

Decode value for IGMPv3 Max Resp Code and QQIC. See RFC 3376 §4.1.1 and §4.1.7.

Parameters:

  • value (Integer)

Returns:

  • (Integer)

Since:

  • 2.4.0


100
101
102
103
104
105
106
107
108
# File 'lib/packetgen/header/igmpv3.rb', line 100

def self.decode(value)
  if value < 128
    value
  else
    mant = value & 0xf
    exp = (value >> 4) & 0x7
    (0x10 | mant) << (exp + 3)
  end
end

.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.

Parameters:

  • value (Integer)

Returns:

  • (Integer)

Since:

  • 2.4.0


80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/packetgen/header/igmpv3.rb', line 80

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

#calc_checksumInteger

Compute checksum and set checksum field

Returns:

  • (Integer)

Since:

  • 2.4.0


127
128
129
130
# File 'lib/packetgen/header/igmpv3.rb', line 127

def calc_checksum
  sum = IP.sum16(self)
  self.checksum = IP.reduce_checksum(sum)
end

#max_resp_timeInteger Also known as: max_resp_code

Getter for max_resp_time for IGMPv3 packets. Use decode.

Returns:

  • (Integer)

Since:

  • 2.4.0


112
113
114
# File 'lib/packetgen/header/igmpv3.rb', line 112

def max_resp_time
  IGMPv3.decode(self[:max_resp_time].value || self[:max_resp_time].default)
end

#max_resp_time=(value) ⇒ Integer Also known as: max_resp_code=

Setter for max_resp_time for IGMPv3 packets. Use encode.

Parameters:

  • value (Integer)

Returns:

  • (Integer)

Since:

  • 2.4.0


120
121
122
# File 'lib/packetgen/header/igmpv3.rb', line 120

def max_resp_time=(value)
  self[:max_resp_time].value = IGMPv3.encode(value)
end