Class: PacketGen::Header::OSPFv2::LSUpdate
- Inherits:
-
Base
- Object
- Types::Fields
- Base
- PacketGen::Header::OSPFv2::LSUpdate
- Defined in:
- lib/packetgen/header/ospfv2/ls_update.rb
Overview
This class handles OSPFv2 Link State Update packets payload. The LSU payload 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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| # LSAs |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
+- +-+
| LSAs |
+- +-+
| ... |
This paylod is implemented with two fields:
-
#lsas_count, a Types::Int32 field,
-
and #lsas, an ArrayOfLSA object.
Create a LSUpdate payload
# standalone
lsu = PacketGen::Header::OSPFv2::LSUpdate.new
# in a packet
pkt = PacketGen.gen('IP', src: source_ip).add('OSPFv2').add('OSPFv2::LSUpdate')
# make IP header correct for OSPF
pkt.ospfize
# access to LSUpdate payload
lsu = pkt.ospfv2_lsupdate # => PacketGen::Header::OSPFv2::LSUpdate
Add LSAs to a LSUpdate payload
Adding LSAs with ArrayOfLSA#<< automagically update #lsas_count. To not update it, use ArrayOfLSA#push.
lsu.lsas << { type: 'Router', age: 40, link_state_id: '0.0.0.1', advertising_router: '1.1.1.1', sequence_number: 42 }
lsu.lsas_count #=> 1
# add a link to Router LSA
lsu.lsas.first.links << { type: 1, metric: 10, id: '1.1.1.1' }
Instance Attribute Summary collapse
-
#lsas ⇒ ArrayOfLSA
Array of LSAs.
-
#lsas_count ⇒ Integer
Count of LSAs included in this update.
Instance Method Summary collapse
-
#calc_checksum ⇒ void
Calculate checksums of all LSAs.
-
#calc_length ⇒ Object
Calculate length of all LSAs.
Methods inherited from Base
bind, calculate_and_set_length, #header_id, inherited, #initialize, #ip_header, #ll_header
Methods included from PacketGen::Headerable
#added_to_packet, included, #method_name, #packet, #packet=, #parse?, #protocol_name, #read
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::Header::Base
Instance Attribute Details
#lsas ⇒ ArrayOfLSA
Array of LSAs
54 |
# File 'lib/packetgen/header/ospfv2/ls_update.rb', line 54 define_field :lsas, ArrayOfLSA, builder: ->(h, t) { t.new(counter: h[:lsas_count]) } |
Instance Method Details
#calc_checksum ⇒ void
This method returns an undefined value.
Calculate checksums of all LSAs
58 59 60 |
# File 'lib/packetgen/header/ospfv2/ls_update.rb', line 58 def calc_checksum lsas.each(&:calc_checksum) end |
#calc_length ⇒ Object
Calculate length of all LSAs
63 64 65 |
# File 'lib/packetgen/header/ospfv2/ls_update.rb', line 63 def calc_length lsas.each(&:calc_length) end |