Class: PacketGen::Header::OSPFv2::LSAHeader

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

Overview

This class handles OSPFv2 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             |    Options    |    LS type    |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                        Link State ID                          |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                     Advertising Router                        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                     LS sequence number                        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|         LS checksum           |             length            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

About LSA headers

LSA headers are used as-is in DbDescription payload. 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, LSAASExternal, LSANetwork, LSARouter

Constant Summary collapse

TYPES =

LSA Types

Since:

  • 2.5.0

{
  'Router' => 1,
  'Network' => 2,
  'Summary-IP' => 3,
  'Summary-ABSR' => 4,
  'AS-External' => 5
}.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)

61
# File 'lib/packetgen/header/ospfv2/lsa_header.rb', line 61

define_field :advertising_router, IP::Addr

#ageInteger

The time in seconds since the LSA was originated.

Returns:

  • (Integer)

46
# File 'lib/packetgen/header/ospfv2/lsa_header.rb', line 46

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)

71
# File 'lib/packetgen/header/ospfv2/lsa_header.rb', line 71

define_field :checksum, Types::Int16

#dc_optBoolean

This bit describes the router's handling of demand circuits.

Returns:

  • (Boolean)

48
# File 'lib/packetgen/header/ospfv2/lsa_header.rb', line 48

OSPFv2.define_options(self)

#dn_optBoolean

Returns:

  • (Boolean)

48
# File 'lib/packetgen/header/ospfv2/lsa_header.rb', line 48

OSPFv2.define_options(self)

#e_optBoolean

This bit describes the way AS-external-LSAs are flooded.

Returns:

  • (Boolean)

48
# File 'lib/packetgen/header/ospfv2/lsa_header.rb', line 48

OSPFv2.define_options(self)

#l_optBoolean

This specifies if a LLS Data block is present.

Returns:

  • (Boolean)

48
# File 'lib/packetgen/header/ospfv2/lsa_header.rb', line 48

OSPFv2.define_options(self)

#lengthInteger

Length of the LSA, including the header.

Returns:

  • (Integer)

75
# File 'lib/packetgen/header/ospfv2/lsa_header.rb', line 75

define_field :length, Types::Int16

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

Returns:

  • (String)

57
# File 'lib/packetgen/header/ospfv2/lsa_header.rb', line 57

define_field :link_state_id, IP::Addr

#mc_optBoolean

This bit describes whether IP multicast datagrams are forwarded.

Returns:

  • (Boolean)

48
# File 'lib/packetgen/header/ospfv2/lsa_header.rb', line 48

OSPFv2.define_options(self)

#mt_optBoolean

Returns:

  • (Boolean)

48
# File 'lib/packetgen/header/ospfv2/lsa_header.rb', line 48

OSPFv2.define_options(self)

#n_optBoolean

This bit specifies if NSSA is supported.

Returns:

  • (Boolean)

48
# File 'lib/packetgen/header/ospfv2/lsa_header.rb', line 48

OSPFv2.define_options(self)

#o_optBoolean

Returns:

  • (Boolean)

48
# File 'lib/packetgen/header/ospfv2/lsa_header.rb', line 48

OSPFv2.define_options(self)

#optionsInteger

8-bit options field. Handle #mt_opt, #e_opt, #mc_opt, #n_opt, #l_opt, #dc_opt, #o_opt and #dn_opt.

Returns:

  • (Integer)

48
# File 'lib/packetgen/header/ospfv2/lsa_header.rb', line 48

OSPFv2.define_options(self)

#sequence_numberInteger Also known as: seqnum

Returns:

  • (Integer)

64
# File 'lib/packetgen/header/ospfv2/lsa_header.rb', line 64

define_field :sequence_number, Types::Int32

#typeInteger

The type of the LSA.

Returns:

  • (Integer)

52
# File 'lib/packetgen/header/ospfv2/lsa_header.rb', line 52

define_field :type, Types::Int8Enum, enum: TYPES

Instance Method Details

#calc_checksumInteger

Compute and set Fletcher-16 checksum on LSA

Returns:

  • (Integer)

Since:

  • 2.5.0


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

def calc_checksum
  c0 = c1 = 0
  to_s[2..-1].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


97
98
99
# File 'lib/packetgen/header/ospfv2/lsa_header.rb', line 97

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

#human_typeString

Get human-readable type

Returns:

  • (String)

Since:

  • 2.5.0


103
104
105
# File 'lib/packetgen/header/ospfv2/lsa_header.rb', line 103

def human_type
  self[:type].to_human
end

#to_humanString

Returns:

  • (String)

Since:

  • 2.5.0


108
109
110
# File 'lib/packetgen/header/ospfv2/lsa_header.rb', line 108

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


114
115
116
# File 'lib/packetgen/header/ospfv2/lsa_header.rb', line 114

def to_lsa_header
  LSAHeader.new(self.to_h)
end