Class: OSPFv2::UnreservedBandwidth_Tlv
- Defined in:
- lib/lsa/tlv/unreserved_bandwidth.rb
Instance Attribute Summary collapse
-
#tlv_type ⇒ Object
readonly
Returns the value of attribute tlv_type.
-
#unreserved_bw ⇒ Object
readonly
Returns the value of attribute unreserved_bw.
Instance Method Summary collapse
- #__parse(s) ⇒ Object
- #encode ⇒ Object
-
#initialize(arg = {}) ⇒ UnreservedBandwidth_Tlv
constructor
A new instance of UnreservedBandwidth_Tlv.
- #to_hash ⇒ Object
- #to_s ⇒ Object
Methods included from Common
#ivar_to_klassname, #ivars, #set
Methods included from SubTlv
Methods included from Tlv
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_type ⇒ Object (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_bw ⇒ Object (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 |
#encode ⇒ Object
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_hash ⇒ Object
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_s ⇒ Object
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 |