Class: OSPFv2::ExternalRoute_Base

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/ie/external_route.rb

Direct Known Subclasses

ExternalRoute, MtExternalRoute

Constant Summary collapse

ForwardingAddress =
Class.new(OSPFv2::Id)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Common

#ivar_to_klassname, #ivars, #set, #to_hash

Constructor Details

#initialize(arg = {}) ⇒ ExternalRoute_Base

Returns a new instance of ExternalRoute_Base.



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/ie/external_route.rb', line 85

def initialize(arg={})
  arg = arg.dup
  self.metric=0
  self.type=:e1
  self.tag=0
  self.mt_id=0
  if arg.is_a?(Hash)
    set arg
  elsif arg.is_a?(String)
    parse arg
  elsif arg.is_a?(self.class)
    parse arg.encode
  else
    raise ArgumentError, "Invalid Argument: #{arg.inspect}"
  end
end

Instance Attribute Details

#forwarding_addressObject (readonly)

Returns the value of attribute forwarding_address.



69
70
71
# File 'lib/ie/external_route.rb', line 69

def forwarding_address
  @forwarding_address
end

#metricObject (readonly)

Returns the value of attribute metric.



69
70
71
# File 'lib/ie/external_route.rb', line 69

def metric
  @metric
end

#mt_idObject (readonly)

Returns the value of attribute mt_id.



69
70
71
# File 'lib/ie/external_route.rb', line 69

def mt_id
  @mt_id
end

#tagObject (readonly)

Returns the value of attribute tag.



69
70
71
# File 'lib/ie/external_route.rb', line 69

def tag
  @tag
end

#typeObject (readonly)

Returns the value of attribute type.



69
70
71
# File 'lib/ie/external_route.rb', line 69

def type
  @type
end

Class Method Details

.new_hash(h) ⇒ Object



171
172
173
174
175
176
177
# File 'lib/ie/external_route.rb', line 171

def ExternalRoute_Base.new_hash(h)
  if h[:mt_metrics]
    MtExternalRoute.new(h)
  else
    ExternalRoute.new(h)
  end
end

Instance Method Details

#encodeObject



102
103
104
105
106
107
108
# File 'lib/ie/external_route.rb', line 102

def encode
  external =[]
  external << encoded_e_id_metric
  external << forwarding_address.encode
  external << [tag].pack('N')
  external.join
end

#parse(s) ⇒ Object



110
111
112
113
114
# File 'lib/ie/external_route.rb', line 110

def parse(s)
  long1, long2, @tag = s.unpack('NNN')
  @type, @mt_id, @metric = parse_e_id_metric(long1)
  @forwarding_address = ForwardingAddress.new(long2)
end

#to_sObject



116
117
118
# File 'lib/ie/external_route.rb', line 116

def to_s
  "#{type.to_s.upcase} (ID #{mt_id}) Metric: #{metric.to_i} Forwarding: #{forwarding_address.to_ip} Tag: #{tag}"
end