class PacketGen::Header::OSPFv2::LSAHeader
This class handles {OSPFv2 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
Constants
Public Instance Methods
calc_checksum()
click to toggle source
Compute and set Fletcher-16 checksum on LSA
@return [Integer]
# File lib/packetgen/header/ospfv2/lsa_header.rb, line 79 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/ospfv2/lsa_header.rb, line 99 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/ospfv2/lsa_header.rb, line 105 def human_type self[:type].to_human end
to_human()
click to toggle source
@return [String]
# File lib/packetgen/header/ospfv2/lsa_header.rb, line 110 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/ospfv2/lsa_header.rb, line 116 def to_lsa_header LSAHeader.new(self.to_h) end