Class: PacketGen::Header::OSPFv3::IPv6Prefix
- Inherits:
-
Types::Fields
- Object
- Types::Fields
- PacketGen::Header::OSPFv3::IPv6Prefix
- Includes:
- Types::Fieldable
- Defined in:
- lib/packetgen/header/ospfv3/ipv6_prefix.rb
Overview
This class handles IPv6 prefixes, as defined in RFC 5340 §A.4.1. A IPv6 prefix consists of:
Instance Attribute Summary collapse
-
#dn_opt ⇒ Boolean
This bit controls an inter-area-prefix-LSAs or AS-external-LSAs re-advertisement in a VPN environment.
-
#la_opt ⇒ Boolean
The “local address” capability bit.
-
#length ⇒ Integer
Prefix length, in bits.
-
#nu_opt ⇒ Boolean
The “no unicast” capability bit.
-
#options ⇒ Options
Prefix capabilities.
-
#p_opt ⇒ Boolean
The “propagate” bit.
-
#prefix ⇒ Prefix
IPv6 Prefix as an array of 32-bit words.
-
#reserved ⇒ Integer
Reserved field in most of LSA types.
Instance Method Summary collapse
-
#from_human(str) ⇒ void
Set prefix from a human-readable string.
-
#to_human ⇒ String
Get human-readable prefix.
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
#dn_opt ⇒ Boolean
This bit controls an inter-area-prefix-LSAs or AS-external-LSAs re-advertisement in a VPN environment.
57 |
# File 'lib/packetgen/header/ospfv3/ipv6_prefix.rb', line 57 define_bit_fields_on :options, :zz, 3, :dn_opt, :p_opt, :z, :la_opt, :nu_opt |
#la_opt ⇒ Boolean
The “local address” capability bit. If set, the prefix is actually an IPv6 interface address of the Advertising Router.
57 |
# File 'lib/packetgen/header/ospfv3/ipv6_prefix.rb', line 57 define_bit_fields_on :options, :zz, 3, :dn_opt, :p_opt, :z, :la_opt, :nu_opt |
#length ⇒ Integer
Prefix length, in bits
26 |
# File 'lib/packetgen/header/ospfv3/ipv6_prefix.rb', line 26 define_field :length, Types::Int8 |
#nu_opt ⇒ Boolean
The “no unicast” capability bit. If set, the prefix should be excluded from IPv6 unicast calculations.
57 |
# File 'lib/packetgen/header/ospfv3/ipv6_prefix.rb', line 57 define_bit_fields_on :options, :zz, 3, :dn_opt, :p_opt, :z, :la_opt, :nu_opt |
#options ⇒ Options
31 |
# File 'lib/packetgen/header/ospfv3/ipv6_prefix.rb', line 31 define_field :options, Types::Int8 |
#p_opt ⇒ Boolean
The “propagate” bit. Set on NSSA area prefixes that should be readvertised by the translating NSSA area border.
57 |
# File 'lib/packetgen/header/ospfv3/ipv6_prefix.rb', line 57 define_bit_fields_on :options, :zz, 3, :dn_opt, :p_opt, :z, :la_opt, :nu_opt |
#prefix ⇒ Prefix
IPv6 Prefix as an array of 32-bit words
39 |
# File 'lib/packetgen/header/ospfv3/ipv6_prefix.rb', line 39 define_field :prefix, Types::ArrayOfInt32, builder: ->(h, t) { t.new(length_from: -> { h.length / 8 }) } |
Instance Method Details
#from_human(str) ⇒ void
This method returns an undefined value.
Set prefix from a human-readable string. This method cannot set #options field.
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/packetgen/header/ospfv3/ipv6_prefix.rb', line 74 def from_human(str) ary, len = ary_and_prefix_len_from_str(str) self.prefix.clear ary.each_with_index do |v, i| if i.even? self.prefix << v else self.prefix.last.value = (self.prefix.last.to_i << 16) | v.to_i end end self.length = len end |
#to_human ⇒ String
Get human-readable prefix
61 62 63 64 65 66 67 68 |
# File 'lib/packetgen/header/ospfv3/ipv6_prefix.rb', line 61 def to_human ary = prefix.map(&:to_i).map do |v| "#{((v >> 16) & 0xffff).to_s(16)}:#{(v & 0xffff).to_s(16)}" end pfx = ary.join(':') pfx += '::' if prefix.size < (128 / 32) "#{IPAddr.new(pfx)}/#{length}" end |