Class: OSPFv2::MtMetric

Inherits:
Object show all
Defined in:
lib/ie/mt_metric.rb

Instance Method Summary collapse

Constructor Details

#initialize(arg = {}) ⇒ MtMetric

Returns a new instance of MtMetric.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/ie/mt_metric.rb', line 58

def initialize(arg={})
  arg = arg.dup
  @_id,@_metric=0,0
  if arg.is_a?(Hash)
    set arg
  elsif arg.is_a?(String)
    parse arg
  elsif arg.is_a?(self.class)
    parse arg.encode
  elsif arg.is_a?(Array) and arg.size==2
    @_id, @_metric = arg
  else
    raise ArgumentError, "Invalid Argument: #{arg.inspect}"
  end
end

Instance Method Details

#encodeObject



96
97
98
99
100
101
# File 'lib/ie/mt_metric.rb', line 96

def encode
  m = []
  m << [id].pack('C')
  m << [metric].pack('N').unpack('C4')[1..-1].pack('C3')
  m.join
end

#idObject



83
84
85
# File 'lib/ie/mt_metric.rb', line 83

def id
  @_id
end

#id=(val) ⇒ Object



86
87
88
# File 'lib/ie/mt_metric.rb', line 86

def id=(val)
  @_id=val
end

#metricObject



89
90
91
# File 'lib/ie/mt_metric.rb', line 89

def metric
  @_metric
end

#metric=(val) ⇒ Object



92
93
94
# File 'lib/ie/mt_metric.rb', line 92

def metric=(val)
  @_metric=val
end

#parse(s) ⇒ Object



103
104
105
106
# File 'lib/ie/mt_metric.rb', line 103

def parse(s)
  @_id, *metric = s.unpack('C4')
  @_metric = [0,*metric].pack('C4').unpack('N')[0]
end

#set(arg) ⇒ Object



74
75
76
77
# File 'lib/ie/mt_metric.rb', line 74

def set(arg)
  @_id = arg[:id] if arg[:id]
  @_metric = arg[:metric] if arg[:metric]
end

#to_hashObject



79
80
81
# File 'lib/ie/mt_metric.rb', line 79

def to_hash
  {:id=>id, :metric=> metric}
end

#to_sObject



108
109
110
# File 'lib/ie/mt_metric.rb', line 108

def to_s
  "Topology #{id}, Metric #{metric}"
end

#to_s_junosObject



112
113
114
# File 'lib/ie/mt_metric.rb', line 112

def to_s_junos
  "Topology (ID #{id}) -> Metric: #{metric}"
end