Class: PacketGen::Header::OSPFv3::IPv6Prefix
- Inherits:
-
BinStruct::Struct
- Object
- BinStruct::Struct
- PacketGen::Header::OSPFv3::IPv6Prefix
- Includes:
- BinStruct::Structable
- 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 ⇒ Integer
This bit controls an inter-area-prefix-LSAs or AS-external-LSAs re-advertisement in a VPN environment.
-
#la_opt ⇒ Integer
The “local address” capability bit.
-
#length ⇒ Integer
Prefix length, in bits.
-
#nu_opt ⇒ Integer
The “no unicast” capability bit.
-
#options ⇒ Options
Prefix capabilities.
-
#p_opt ⇒ Integer
The “propagate” bit.
-
#prefix ⇒ BinStruct::ArrayOfInt32
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) ⇒ self
Set prefix from a human-readable string.
-
#to_human ⇒ String
Get human-readable prefix.
Instance Attribute Details
#dn_opt ⇒ Integer
This bit controls an inter-area-prefix-LSAs or AS-external-LSAs re-advertisement in a VPN environment.
47 |
# File 'lib/packetgen/header/ospfv3/ipv6_prefix.rb', line 47 define_bit_attr :options, zz: 3, dn_opt: 1, p_opt: 1, z: 1, la_opt: 1, nu_opt: 1 |
#la_opt ⇒ Integer
The “local address” capability bit. If set, the prefix is actually an IPv6 interface address of the Advertising Router.
47 |
# File 'lib/packetgen/header/ospfv3/ipv6_prefix.rb', line 47 define_bit_attr :options, zz: 3, dn_opt: 1, p_opt: 1, z: 1, la_opt: 1, nu_opt: 1 |
#length ⇒ Integer
Prefix length, in bits
26 |
# File 'lib/packetgen/header/ospfv3/ipv6_prefix.rb', line 26 define_attr :length, BinStruct::Int8 |
#nu_opt ⇒ Integer
The “no unicast” capability bit. If set, the prefix should be excluded from IPv6 unicast calculations.
47 |
# File 'lib/packetgen/header/ospfv3/ipv6_prefix.rb', line 47 define_bit_attr :options, zz: 3, dn_opt: 1, p_opt: 1, z: 1, la_opt: 1, nu_opt: 1 |
#options ⇒ Options
47 |
# File 'lib/packetgen/header/ospfv3/ipv6_prefix.rb', line 47 define_bit_attr :options, zz: 3, dn_opt: 1, p_opt: 1, z: 1, la_opt: 1, nu_opt: 1 |
#p_opt ⇒ Integer
The “propagate” bit. Set on NSSA area prefixes that should be readvertised by the translating NSSA area border.
47 |
# File 'lib/packetgen/header/ospfv3/ipv6_prefix.rb', line 47 define_bit_attr :options, zz: 3, dn_opt: 1, p_opt: 1, z: 1, la_opt: 1, nu_opt: 1 |
#prefix ⇒ BinStruct::ArrayOfInt32
IPv6 Prefix as an array of 32-bit words
55 |
# File 'lib/packetgen/header/ospfv3/ipv6_prefix.rb', line 55 define_attr :prefix, BinStruct::ArrayOfInt32, builder: ->(h, t) { t.new(length_from: -> { h.length / 8 }) } |
#reserved ⇒ Integer
Reserved field in most of LSA types.
51 |
# File 'lib/packetgen/header/ospfv3/ipv6_prefix.rb', line 51 define_attr :reserved, BinStruct::Int16 |
Instance Method Details
#from_human(str) ⇒ self
Set prefix from a human-readable string. This method cannot set #options field.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/packetgen/header/ospfv3/ipv6_prefix.rb', line 75 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 self end |
#to_human ⇒ String
Get human-readable prefix
59 60 61 62 63 64 65 66 |
# File 'lib/packetgen/header/ospfv3/ipv6_prefix.rb', line 59 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 |