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

Inherits:
BinStruct::Struct
  • Object
show all
Includes:
BinStruct::Structable
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

Instance Attribute Details

#bodyString

This method is abstract.

replaced by specific attributes in subclasses

DUID data.

Returns:

  • (String)


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

define_attr :body, BinStruct::String

#typeInteger

16-bit DUID type

Returns:

  • (Integer)


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

define_attr :type, BinStruct::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