lib/packetgen/header/ospfv3/lsa.rb in packetgen-2.8.7 vs lib/packetgen/header/ospfv3/lsa.rb in packetgen-3.0.0

- old
+ new

@@ -70,11 +70,11 @@ define_field :flags, Types::Int8 # @!macro define_ospfv3_options OSPFv3.define_options(self) # @attribute links # @return [ArrayOfLink] - define_field :links, ArrayOfLink + define_field :links, ArrayOfLink, builder: ->(h, t) { t.new(length_from: -> { h.length - h.offset_of(:links) }) } # @!attribute nt_flag # @return [Boolean] # @!attribute v_flag # @return [Boolean] @@ -101,11 +101,11 @@ # @!macro define_ospfv3_options OSPFv3.define_options(self) # @!attribute routers # List of routers attached to the link. # @return [IP::ArrayOfAddr] - define_field :routers, IP::ArrayOfAddr + define_field :routers, IP::ArrayOfAddr, builder: ->(h, t) { t.new(length_from: -> { h.length - h.offset_of(:routers) }) } end # This class handles OSPFv3 LSA Intra-Area-Prefix payloads. # # An Intra-Area-Prefix payloads is composed of: @@ -173,50 +173,29 @@ # @return [Integer] define_field :prefix_count, Types::Int32 # @!attribute prefixes # List of IPv6 prefixes to be associated with the link. # @return [ArrayOfIPv6Prefix] - define_field :prefixes, ArrayOfIPv6Prefix + define_field :prefixes, ArrayOfIPv6Prefix, builder: ->(h, t) { t.new(counter: h[:prefix_count]) } end # This class defines a specialized {Types::Array array} to handle series # of {LSA LSAs} or {LSAHeader LSAHeaders}. It recognizes known LSA types # and infers correct type. # @author Sylvain Daubert class ArrayOfLSA < Types::Array - set_of LSA + set_of LSAHeader # @param [Hash] options # @option options [Types::Int] counter Int object used as a counter for this set # @option options [Boolean] only_headers if +true+, only {LSAHeader LSAHeaders} # will be added to this array. def initialize(options={}) super @only_headers = options[:only_headers] || false end - # Populate object from a string - # @param [String] str - # @return [self] - 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 - private def record_from_hash(hsh) unless hsh.key? :type raise ArgumentError, 'hash should have :type key' @@ -242,9 +221,13 @@ if OSPFv3.const_defined? klassname OSPFv3.const_get klassname else LSA end + end + + def real_type(lsah) + @only_headers ? lsah.class : get_lsa_class_by_human_type(lsah.human_type) end end end end end