Class: PacketGen::Header::OSPFv3::IPv6Prefix
- Inherits:
-
Types::Fields
- Object
- Types::Fields
- PacketGen::Header::OSPFv3::IPv6Prefix
- 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 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.
54 |
# File 'lib/packetgen/header/ospfv3/ipv6_prefix.rb', line 54 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.
54 |
# File 'lib/packetgen/header/ospfv3/ipv6_prefix.rb', line 54 define_bit_fields_on :options, :zz, 3, :dn_opt, :p_opt, :z, :la_opt, :nu_opt |
#length ⇒ Integer
Prefix length, in bits
23 |
# File 'lib/packetgen/header/ospfv3/ipv6_prefix.rb', line 23 define_field :length, Types::Int8 |
#nu_opt ⇒ Boolean
The “no unicast” capability bit. If set, the prefix should be excluded from IPv6 unicast calculations.
54 |
# File 'lib/packetgen/header/ospfv3/ipv6_prefix.rb', line 54 define_bit_fields_on :options, :zz, 3, :dn_opt, :p_opt, :z, :la_opt, :nu_opt |
#options ⇒ Options
28 |
# File 'lib/packetgen/header/ospfv3/ipv6_prefix.rb', line 28 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.
54 |
# File 'lib/packetgen/header/ospfv3/ipv6_prefix.rb', line 54 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
36 |
# File 'lib/packetgen/header/ospfv3/ipv6_prefix.rb', line 36 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.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/packetgen/header/ospfv3/ipv6_prefix.rb', line 71 def from_human(str) pfx, len = str.split('/') len = (len || 128).to_i addr = IPv6::Addr.new.from_human(pfx) ary_size = (len + 31) / 32 ary = addr.to_a[0...ary_size * 2] 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
58 59 60 61 62 63 64 65 |
# File 'lib/packetgen/header/ospfv3/ipv6_prefix.rb', line 58 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 |