Class: PacketGen::Header::OSPFv3::LSAHeader
- Inherits:
-
Types::Fields
- Object
- Types::Fields
- PacketGen::Header::OSPFv3::LSAHeader
- 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.
Direct Known Subclasses
Constant Summary collapse
- TYPES =
LSA known types
{ '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
-
#advertising_router ⇒ String
The Router ID of the router that originated the LSA.
-
#age ⇒ Integer
The time in seconds since the LSA was originated.
-
#checksum ⇒ Integer
The Fletcher checksum of the complete contents of the LSA, including the LSA header but excluding the LS age field.
-
#length ⇒ Integer
Length of the LSA, including the header.
-
#link_state_id ⇒ String
This field identifies the portion of the internet environment that is being described by the LSA.
- #sequence_number ⇒ Integer (also: #seqnum)
-
#type ⇒ Integer
The type of the LSA.
Instance Method Summary collapse
-
#calc_checksum ⇒ Integer
Compute and set Fletcher-16 checksum on LSA.
-
#calc_length ⇒ Integer
Compute length and set
length
field. -
#human_type ⇒ String
Get human-readable type.
- #to_human ⇒ String
-
#to_lsa_header ⇒ LSAHeader
Extract header from current LSA.
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_router ⇒ String
The Router ID of the router that originated the LSA.
63 |
# File 'lib/packetgen/header/ospfv3/lsa_header.rb', line 63 define_field :advertising_router, IP::Addr |
#age ⇒ Integer
The time in seconds since the LSA was originated.
50 |
# File 'lib/packetgen/header/ospfv3/lsa_header.rb', line 50 define_field :age, Types::Int16 |
#checksum ⇒ Integer
The Fletcher checksum of the complete contents of the LSA, including the LSA header but excluding the LS age field.
73 |
# File 'lib/packetgen/header/ospfv3/lsa_header.rb', line 73 define_field :checksum, Types::Int16 |
#length ⇒ Integer
Length of the LSA, including the header.
77 |
# File 'lib/packetgen/header/ospfv3/lsa_header.rb', line 77 define_field :length, Types::Int16 |
#link_state_id ⇒ String
This field identifies the portion of the internet environment that is being described by the LSA.
59 |
# File 'lib/packetgen/header/ospfv3/lsa_header.rb', line 59 define_field :link_state_id, IP::Addr |
Instance Method Details
#calc_checksum ⇒ Integer
Compute and set Fletcher-16 checksum on LSA
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_length ⇒ Integer
Compute length and set length
field
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_type ⇒ String
Get human-readable type
105 106 107 |
# File 'lib/packetgen/header/ospfv3/lsa_header.rb', line 105 def human_type self[:type].to_human end |
#to_human ⇒ String
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 |