Class: OSPFv2::UnreservedBandwidth_Tlv

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Common

#ivar_to_klassname, #ivars, #set

Methods included from SubTlv

factory

Methods included from Tlv

factory

Constructor Details

#initialize(arg = {}) ⇒ UnreservedBandwidth_Tlv

Returns a new instance of UnreservedBandwidth_Tlv.



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/lsa/tlv/unreserved_bandwidth.rb', line 21

def initialize(arg={})
  @tlv_type = 8
  @unreserved_bw = [0]*8

  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

#tlv_typeObject (readonly)

Returns the value of attribute tlv_type.



19
20
21
# File 'lib/lsa/tlv/unreserved_bandwidth.rb', line 19

def tlv_type
  @tlv_type
end

#unreserved_bwObject (readonly)

Returns the value of attribute unreserved_bw.



19
20
21
# File 'lib/lsa/tlv/unreserved_bandwidth.rb', line 19

def unreserved_bw
  @unreserved_bw
end

Instance Method Details

#__parse(s) ⇒ Object



39
40
41
42
# File 'lib/lsa/tlv/unreserved_bandwidth.rb', line 39

def __parse(s)
  @tlv_type, _, *unreserved_bw = s.unpack('nng*')
  @unreserved_bw = unreserved_bw.collect {|bw| (bw*8).to_i }
end

#encodeObject



34
35
36
37
# File 'lib/lsa/tlv/unreserved_bandwidth.rb', line 34

def encode
  [@tlv_type, 32].pack('nn') +
  unreserved_bw.collect { |bw|   bw / 8.0 }.pack('g*')
end

#to_hashObject



44
45
46
47
48
# File 'lib/lsa/tlv/unreserved_bandwidth.rb', line 44

def to_hash
  h=super
  h[:unreserved_bw] = unreserved_bw
  h
end

#to_sObject



49
50
51
# File 'lib/lsa/tlv/unreserved_bandwidth.rb', line 49

def to_s
  "Unreserved bandwidth : " + unreserved_bw.collect { |bw| "%s" % bw }.join(", ")
end