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

Inherits:
BinStruct::Struct
  • Object
show all
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:

  • 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.

Author:

  • Sylvain Daubert

Since:

  • 2.5.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#dn_optInteger

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

Returns:

  • (Integer)


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_optInteger

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

Returns:

  • (Integer)


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

#lengthInteger

Prefix length, in bits

Returns:

  • (Integer)


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

define_attr :length, BinStruct::Int8

#nu_optInteger

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

Returns:

  • (Integer)


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

#optionsOptions

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

Returns:

  • (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_optInteger

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

Returns:

  • (Integer)


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

#prefixBinStruct::ArrayOfInt32

IPv6 Prefix as an array of 32-bit words

Returns:

  • (BinStruct::ArrayOfInt32)


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 }) }

#reservedInteger

Reserved field in most of LSA types.

Returns:

  • (Integer)


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.

Examples:

prefix = PacketGen::Header::OSPFv3::IPv6Prefix.new.from_human("2000::/64")
prefix.to_human #=> "2000::/64"

Parameters:

  • str (String)

Returns:

  • (self)

Since:

  • 2.5.0



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_humanString

Get human-readable prefix

Returns:

  • (String)

Since:

  • 2.5.0



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