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)


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

define_field :body, Types::String

#typeInteger

16-bit DUID type

Returns:

  • (Integer)


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

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

Instance Method Details

#human_typeString

Get human-readable type

Returns:

  • (String)

Since:

  • 2.5.0



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

def human_type
  self[:type].to_human
end

#read(str) ⇒ DUID

Populate object from binary string

Parameters:

  • str (String)

Returns:

Since:

  • 2.5.0



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

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



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

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