class PacketGen::Header::OSPFv3::LSAHeader

This class handles {OSPFv3 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

Constants

TYPES

LSA known types

Public Instance Methods

calc_checksum() click to toggle source

Compute and set Fletcher-16 checksum on LSA @return [Integer]

# File lib/packetgen/header/ospfv3/lsa_header.rb, line 80
def calc_checksum
  bytes = to_s[2..-1].unpack('C*')

  c0 = c1 = 0
  bytes.each do |byte|
    c0 += byte
    c1 += c0
  end
  c0 %= 255
  c1 %= 255

  x = ((sz - 16 - 1) * 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_length() click to toggle source

Compute length and set length field @return [Integer]

# File lib/packetgen/header/ospfv3/lsa_header.rb, line 100
def calc_length
  self.length = Base.calculate_and_set_length(self)
end
human_type() click to toggle source

Get human-readable type @return [String]

# File lib/packetgen/header/ospfv3/lsa_header.rb, line 106
def human_type
  self[:type].to_human
end
to_human() click to toggle source

@return [String]

# File lib/packetgen/header/ospfv3/lsa_header.rb, line 111
def to_human
  "LSA<#{human_type},#{link_state_id},#{advertising_router}>"
end
to_lsa_header() click to toggle source

Extract header from current LSA @return [LSAHeader]

# File lib/packetgen/header/ospfv3/lsa_header.rb, line 117
def to_lsa_header
  LSAHeader.new(self.to_h)
end