Class: OSPFv2::LocalInterfaceIpAddress_Tlv

Inherits:
Object
  • Object
show all
Includes:
Common, SubTlv
Defined in:
lib/lsa/tlv/local_interface.rb

Constant Summary collapse

IpAddress =
Class.new(Id)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Common

#ivar_to_klassname, #ivars, #set, #to_hash

Methods included from SubTlv

factory

Methods included from Tlv

factory

Constructor Details

#initialize(arg = {}) ⇒ LocalInterfaceIpAddress_Tlv

Returns a new instance of LocalInterfaceIpAddress_Tlv.



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/lsa/tlv/local_interface.rb', line 24

def initialize(arg={})
  @tlv_type = 3
  @ip_address = IpAddress.new

  if arg.is_a?(Hash) then
    set(arg.dup)
  elsif arg.is_a?(String)
    __parse(arg)
  else
    raise ArgumentError, "Invalid argument", caller
  end
end

Instance Attribute Details

#ip_addressObject (readonly)

Returns the value of attribute ip_address.



20
21
22
# File 'lib/lsa/tlv/local_interface.rb', line 20

def ip_address
  @ip_address
end

#tlv_typeObject (readonly)

Returns the value of attribute tlv_type.



20
21
22
# File 'lib/lsa/tlv/local_interface.rb', line 20

def tlv_type
  @tlv_type
end

Instance Method Details

#__parse(s) ⇒ Object



41
42
43
44
# File 'lib/lsa/tlv/local_interface.rb', line 41

def __parse(s)
  @tlv_type, _, ip_address = s.unpack('nna*')
  @ip_address = IpAddress.new_ntoh(ip_address)
end

#encodeObject



37
38
39
# File 'lib/lsa/tlv/local_interface.rb', line 37

def encode
  [@tlv_type, 4, @ip_address.encode].pack('nna*')
end

#to_sObject



47
48
49
# File 'lib/lsa/tlv/local_interface.rb', line 47

def to_s
  "Interface Address : #{ip_address.to_ip}"
end

#to_s_junos_style(ident = 0) ⇒ Object



51
52
53
# File 'lib/lsa/tlv/local_interface.rb', line 51

def to_s_junos_style(ident=0)
  "  "*ident + "RtrAddr (1), length #{@length}: #{router_id.to_ip}"
end