Class: PacketGen::Header::OSPFv2::ArrayOfLSA

Inherits:
Types::Array show all
Defined in:
lib/packetgen/header/ospfv2/lsa.rb

Overview

This class defines a specialized array to handle series of LSAs. It recognizes known LSA types and infers correct type.

Author:

  • Sylvain Daubert

Since:

  • 2.5.0

Constant Summary

Constants inherited from Types::Array

Types::Array::HUMAN_SEPARATOR

Instance Method Summary collapse

Methods inherited from Types::Array

#<<, #==, #[], #clear, #clear!, #delete, #delete_at, #each, #empty?, #first, #force_binary, #initialize_copy, #last, #push, set_of, #size, #sz, #to_a, #to_human, #to_s

Constructor Details

#initialize(options = {}) ⇒ ArrayOfLSA

Returns a new instance of ArrayOfLSA.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • counter (Types::Int)

    Int object used as a counter for this set

  • only_headers (Boolean)

    if true, only LSAHeaders will be added to this array.

Since:

  • 2.5.0



192
193
194
195
# File 'lib/packetgen/header/ospfv2/lsa.rb', line 192

def initialize(options={})
  super()
  @only_headers = options[:only_headers] || false
end

Instance Method Details

#read(str) ⇒ self

Populate object from a string

Parameters:

  • str (String)

Returns:

  • (self)

Since:

  • 2.5.0



200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/packetgen/header/ospfv2/lsa.rb', line 200

def read(str)
  clear
  return self if str.nil?
  return self if @counter && @counter.to_i.zero?
  force_binary str
  until str.empty?
    lsa = LSAHeader.new.read(str)
    unless @only_headers
      klass = get_lsa_class_by_human_type(lsa.human_type)
      lsa = klass.new.read(str[0...lsa.length])
    end
    self.push lsa
    str.slice!(0, lsa.sz)
    break if @counter && (self.size == @counter.to_i)
  end
  self
end