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)


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

define_field :advertising_router, IP::Addr

#ageInteger

The time in seconds since the LSA was originated.

Returns:

  • (Integer)


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

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/ospfv2/lsa_header.rb', line 72

define_field :checksum, Types::Int16

#dc_optBoolean

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

Returns:

  • (Boolean)


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

OSPFv2.define_options(self)

#dn_optBoolean

Returns:

  • (Boolean)


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

OSPFv2.define_options(self)

#e_optBoolean

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

Returns:

  • (Boolean)


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

OSPFv2.define_options(self)

#l_optBoolean

This specifies if a LLS Data block is present.

Returns:

  • (Boolean)


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

OSPFv2.define_options(self)

#lengthInteger

Length of the LSA, including the header.

Returns:

  • (Integer)


76
# File 'lib/packetgen/header/ospfv2/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/ospfv2/lsa_header.rb', line 58

define_field :link_state_id, IP::Addr

#mc_optBoolean

This bit describes whether IP multicast datagrams are forwarded.

Returns:

  • (Boolean)


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

OSPFv2.define_options(self)

#mt_optBoolean

Returns:

  • (Boolean)


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

OSPFv2.define_options(self)

#n_optBoolean

This bit specifies if NSSA is supported.

Returns:

  • (Boolean)


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

OSPFv2.define_options(self)

#o_optBoolean

Returns:

  • (Boolean)


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

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)


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

OSPFv2.define_options(self)

#sequence_numberInteger Also known as: seqnum

Returns:

  • (Integer)


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

define_field :sequence_number, Types::Int32

#typeInteger

The type of the LSA.

Returns:

  • (Integer)


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

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



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/packetgen/header/ospfv2/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/ospfv2/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/ospfv2/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/ospfv2/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/ospfv2/lsa_header.rb', line 115

def to_lsa_header
  LSAHeader.new(self.to_h)
end