Class: PacketGen::Header::OSPFv3::IPv6Prefix

Inherits:
Types::Fields show all
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:

  • a 8-bit #length field (length of the prefix, in bits),

  • a 8-bit #options field, giving prefix capabilities,

  • a 16-bit #reserved field (but it may be used in some LSA),

  • and an array of 32-bit words to encode prefix itself (#prefix). This array consumes ((PrefixLength + 31) / 32) 32-bit words.

Since:

  • 2.5.0

Instance Attribute Summary collapse

Instance Method Summary collapse

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_optBoolean

This bit controls an inter-area-prefix-LSAs or AS-external-LSAs re-advertisement in a VPN environment.

Returns:

  • (Boolean)

56
# File 'lib/packetgen/header/ospfv3/ipv6_prefix.rb', line 56

define_bit_fields_on :options, :zz, 3, :dn_opt, :p_opt, :z, :la_opt, :nu_opt

#la_optBoolean

The “local address” capability bit. If set, the prefix is actually an IPv6 interface address of the Advertising Router.

Returns:

  • (Boolean)

56
# File 'lib/packetgen/header/ospfv3/ipv6_prefix.rb', line 56

define_bit_fields_on :options, :zz, 3, :dn_opt, :p_opt, :z, :la_opt, :nu_opt

#lengthInteger

Prefix length, in bits

Returns:

  • (Integer)

25
# File 'lib/packetgen/header/ospfv3/ipv6_prefix.rb', line 25

define_field :length, Types::Int8

#nu_optBoolean

The “no unicast” capability bit. If set, the prefix should be excluded from IPv6 unicast calculations.

Returns:

  • (Boolean)

56
# File 'lib/packetgen/header/ospfv3/ipv6_prefix.rb', line 56

define_bit_fields_on :options, :zz, 3, :dn_opt, :p_opt, :z, :la_opt, :nu_opt

#optionsOptions

Prefix capabilities. See also capability bits: #dn_opt, #p_opt, #la_opt and #nu_opt.

Returns:

  • (Options)

30
# File 'lib/packetgen/header/ospfv3/ipv6_prefix.rb', line 30

define_field :options, Types::Int8

#p_optBoolean

The “propagate” bit. Set on NSSA area prefixes that should be readvertised by the translating NSSA area border.

Returns:

  • (Boolean)

56
# File 'lib/packetgen/header/ospfv3/ipv6_prefix.rb', line 56

define_bit_fields_on :options, :zz, 3, :dn_opt, :p_opt, :z, :la_opt, :nu_opt

#prefixPrefix

IPv6 Prefix as an array of 32-bit words

Returns:

  • (Prefix)

38
# File 'lib/packetgen/header/ospfv3/ipv6_prefix.rb', line 38

define_field :prefix, Types::ArrayOfInt32, builder: ->(h, t) { t.new(length_from: -> { h.length / 8 }) }

#reservedInteger

Reserved field in most of LSA types.

Returns:

  • (Integer)

34
# File 'lib/packetgen/header/ospfv3/ipv6_prefix.rb', line 34

define_field :reserved, Types::Int16

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.

Parameters:

  • str (String)

Since:

  • 2.5.0


73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/packetgen/header/ospfv3/ipv6_prefix.rb', line 73

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_humanString

Get human-readable prefix

Returns:

  • (String)

Since:

  • 2.5.0


60
61
62
63
64
65
66
67
# File 'lib/packetgen/header/ospfv3/ipv6_prefix.rb', line 60

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