Class: PacketGen::Header::OSPFv3::LSAHeader

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

Overview

This class handles OSPFv3 LSA header. A LSA 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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|           LS Age              |           LS Type             |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                        Link State ID                          |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                     Advertising Router                        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                     LS sequence number                        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|         LS checksum           |             length            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

About LSA headers

LSA headers are used as-is in DbDescription and LSAck payloads. But this class is also a base class for different LSA class, as LSARouter.

Author:

  • Sylvain Daubert

Since:

  • 2.5.0

Direct Known Subclasses

LSA, LSAIntraAreaPrefix, LSALink, LSANetwork, LSARouter

Constant Summary collapse

TYPES =

LSA known types

Since:

  • 2.5.0

{
  'Router' => 0x2001,
  'Network' => 0x2002,
  'Inter-Area-Prefix' => 0x2003,
  'Inter-Area-Router' => 0x2004,
  'AS-External' => 0x4005,
  'NSSA' => 0x2007,
  'Link' => 0x0008,
  'Intra-Area-Prefix' => 0x2009
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Types::Fieldable

#format_inspect, #read, #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?, #read, 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

#advertising_routerString

The Router ID of the router that originated the LSA.

Returns:

  • (String)


62
# File 'lib/packetgen/header/ospfv3/lsa_header.rb', line 62

define_field :advertising_router, IP::Addr

#ageInteger

The time in seconds since the LSA was originated.

Returns:

  • (Integer)


49
# File 'lib/packetgen/header/ospfv3/lsa_header.rb', line 49

define_field :age, Types::Int16

#checksumInteger

The Fletcher checksum of the complete contents of the LSA, including the LSA header but excluding the LS age field.

Returns:

  • (Integer)


72
# File 'lib/packetgen/header/ospfv3/lsa_header.rb', line 72

define_field :checksum, Types::Int16

#lengthInteger

Length of the LSA, including the header.

Returns:

  • (Integer)


76
# File 'lib/packetgen/header/ospfv3/lsa_header.rb', line 76

define_field :length, Types::Int16

This field identifies the portion of the internet environment that is being described by the LSA.

Returns:

  • (String)


58
# File 'lib/packetgen/header/ospfv3/lsa_header.rb', line 58

define_field :link_state_id, IP::Addr

#sequence_numberInteger Also known as: seqnum

Returns:

  • (Integer)


65
# File 'lib/packetgen/header/ospfv3/lsa_header.rb', line 65

define_field :sequence_number, Types::Int32

#typeInteger

The type of the LSA.

Returns:

  • (Integer)


53
# File 'lib/packetgen/header/ospfv3/lsa_header.rb', line 53

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

Instance Method Details

#calc_checksumInteger

Compute and set Fletcher-16 checksum on LSA

Returns:

  • (Integer)

Since:

  • 2.5.0



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

def calc_checksum
  c0 = c1 = 0
  to_s[2..].unpack('C*').each do |byte|
    c0 += byte
    c1 += c0
  end
  c0 %= 255
  c1 %= 255

  x = ((sz - 17) * c0 - c1) % 255
  x += 255 if x <= 0
  y = 255 * 2 - c0 - x
  y -= 255 if y > 255
  self.checksum = (x << 8) | y
end

#calc_lengthInteger

Compute length and set length field

Returns:

  • (Integer)

Since:

  • 2.5.0



98
99
100
# File 'lib/packetgen/header/ospfv3/lsa_header.rb', line 98

def calc_length
  self.length = Base.calculate_and_set_length(self)
end

#human_typeString

Get human-readable type

Returns:

  • (String)

Since:

  • 2.5.0



104
105
106
# File 'lib/packetgen/header/ospfv3/lsa_header.rb', line 104

def human_type
  self[:type].to_human
end

#to_humanString

Returns:

  • (String)

Since:

  • 2.5.0



109
110
111
# File 'lib/packetgen/header/ospfv3/lsa_header.rb', line 109

def to_human
  "LSA<#{human_type},#{link_state_id},#{advertising_router}>"
end

#to_lsa_headerLSAHeader

Extract header from current LSA

Returns:

Since:

  • 2.5.0



115
116
117
# File 'lib/packetgen/header/ospfv3/lsa_header.rb', line 115

def to_lsa_header
  LSAHeader.new(self.to_h)
end