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)


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

define_field :advertising_router, IP::Addr

#ageInteger

The time in seconds since the LSA was originated.

Returns:

  • (Integer)


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

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)


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

define_field :checksum, Types::Int16

#lengthInteger

Length of the LSA, including the header.

Returns:

  • (Integer)


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

define_field :length, Types::Int16

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

Returns:

  • (String)


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

define_field :link_state_id, IP::Addr

#sequence_numberInteger Also known as: seqnum

Returns:

  • (Integer)


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

define_field :sequence_number, Types::Int32

#typeInteger

The type of the LSA.

Returns:

  • (Integer)


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

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



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

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



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

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

#human_typeString

Get human-readable type

Returns:

  • (String)

Since:

  • 2.5.0



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

def human_type
  self[:type].to_human
end

#to_humanString

Returns:

  • (String)

Since:

  • 2.5.0



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

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



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

def to_lsa_header
  LSAHeader.new(self.to_h)
end