Class: PacketGen::Header::OSPFv2::LSAHeader
- Inherits:
-
Types::Fields
- Object
- Types::Fields
- PacketGen::Header::OSPFv2::LSAHeader
- 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.
Direct Known Subclasses
Constant Summary collapse
- TYPES =
LSA Types
{ 'Router' => 1, 'Network' => 2, 'Summary-IP' => 3, 'Summary-ABSR' => 4, 'AS-External' => 5 }.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.
-
#dc_opt ⇒ Boolean
This bit describes the router’s handling of demand circuits.
- #dn_opt ⇒ Boolean
-
#e_opt ⇒ Boolean
This bit describes the way AS-external-LSAs are flooded.
-
#l_opt ⇒ Boolean
This specifies if a LLS Data block is present.
-
#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.
-
#mc_opt ⇒ Boolean
This bit describes whether IP multicast datagrams are forwarded.
- #mt_opt ⇒ Boolean
-
#n_opt ⇒ Boolean
This bit specifies if NSSA is supported.
- #o_opt ⇒ Boolean
-
#options ⇒ Integer
8-bit options field.
- #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.
62 |
# File 'lib/packetgen/header/ospfv2/lsa_header.rb', line 62 define_field :advertising_router, IP::Addr |
#age ⇒ Integer
The time in seconds since the LSA was originated.
47 |
# File 'lib/packetgen/header/ospfv2/lsa_header.rb', line 47 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.
72 |
# File 'lib/packetgen/header/ospfv2/lsa_header.rb', line 72 define_field :checksum, Types::Int16 |
#dc_opt ⇒ Boolean
This bit describes the router’s handling of demand circuits.
49 |
# File 'lib/packetgen/header/ospfv2/lsa_header.rb', line 49 OSPFv2.(self) |
#e_opt ⇒ Boolean
This bit describes the way AS-external-LSAs are flooded.
49 |
# File 'lib/packetgen/header/ospfv2/lsa_header.rb', line 49 OSPFv2.(self) |
#l_opt ⇒ Boolean
This specifies if a LLS Data block is present.
49 |
# File 'lib/packetgen/header/ospfv2/lsa_header.rb', line 49 OSPFv2.(self) |
#length ⇒ Integer
Length of the LSA, including the header.
76 |
# File 'lib/packetgen/header/ospfv2/lsa_header.rb', line 76 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.
58 |
# File 'lib/packetgen/header/ospfv2/lsa_header.rb', line 58 define_field :link_state_id, IP::Addr |
#mc_opt ⇒ Boolean
This bit describes whether IP multicast datagrams are forwarded.
49 |
# File 'lib/packetgen/header/ospfv2/lsa_header.rb', line 49 OSPFv2.(self) |
#n_opt ⇒ Boolean
This bit specifies if NSSA is supported.
49 |
# File 'lib/packetgen/header/ospfv2/lsa_header.rb', line 49 OSPFv2.(self) |
#options ⇒ Integer
49 |
# File 'lib/packetgen/header/ospfv2/lsa_header.rb', line 49 OSPFv2.(self) |
Instance Method Details
#calc_checksum ⇒ Integer
Compute and set Fletcher-16 checksum on LSA
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_length ⇒ Integer
Compute length and set length
field
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_type ⇒ String
Get human-readable type
104 105 106 |
# File 'lib/packetgen/header/ospfv2/lsa_header.rb', line 104 def human_type self[:type].to_human end |
#to_human ⇒ String
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 |