Class: PacketGen::Header::DHCPv6::DUID Abstract

Inherits:
Types::Fields show all
Includes:
Types::Fieldable
Defined in:
lib/packetgen/header/dhcpv6/duid.rb

Overview

This class is abstract.

Base class for DUID (DHCP Unique ID)

Author:

  • Sylvain Daubert

Since:

  • 2.5.0

Direct Known Subclasses

DUID_EN, DUID_LL, DUID_LLT

Constant Summary collapse

TYPES =

Since:

  • 2.5.0

{
  'DUID-LLT' => 1,
  'DUID-EN' => 2,
  'DUID-LL' => 3
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Types::Fieldable

#format_inspect, #sz, #to_s, #type_name

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?, remove_bit_fields_on, remove_field, #sz, #to_h, #to_s, update_field

Constructor Details

This class inherits a constructor from PacketGen::Types::Fields

Instance Attribute Details

#bodyString

This method is abstract.

replaced by specific fields in subclasses

DUID data.

Returns:

  • (String)


30
# File 'lib/packetgen/header/dhcpv6/duid.rb', line 30

define_field :body, Types::String

#typeInteger

16-bit DUID type

Returns:

  • (Integer)


25
# File 'lib/packetgen/header/dhcpv6/duid.rb', line 25

define_field :type, Types::Int16Enum, enum: TYPES

Instance Method Details

#human_typeString

Get human-readable type

Returns:

  • (String)

Since:

  • 2.5.0



64
65
66
# File 'lib/packetgen/header/dhcpv6/duid.rb', line 64

def human_type
  self[:type].to_human
end

#read(str) ⇒ DUID

Populate object from binary string

Parameters:

  • str (String)

Returns:

Since:

  • 2.5.0



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/packetgen/header/dhcpv6/duid.rb', line 38

def read(str)
  if self.instance_of?(DUID)
    super
    case type
    when 1
      DUID_LLT.new.read(str)
    when 2
      DUID_EN.new.read(str)
    when 3
      DUID_LL.new.read(str)
    else
      self
    end
  else
    private_read str
  end
end

#to_humanString

Get human-readable DUID description

Returns:

  • (String)

Since:

  • 2.5.0



58
59
60
# File 'lib/packetgen/header/dhcpv6/duid.rb', line 58

def to_human
  "DUID<#{type},#{body.inspect}>"
end