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.



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

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.



71
72
73
# File 'lib/ie/external_route.rb', line 71

def forwarding_address
  @forwarding_address
end

#metricObject (readonly)

Returns the value of attribute metric.



71
72
73
# File 'lib/ie/external_route.rb', line 71

def metric
  @metric
end

#mt_idObject (readonly)

Returns the value of attribute mt_id.



71
72
73
# File 'lib/ie/external_route.rb', line 71

def mt_id
  @mt_id
end

#tagObject (readonly)

Returns the value of attribute tag.



71
72
73
# File 'lib/ie/external_route.rb', line 71

def tag
  @tag
end

#typeObject (readonly)

Returns the value of attribute type.



71
72
73
# File 'lib/ie/external_route.rb', line 71

def type
  @type
end

Class Method Details

.new_hash(h) ⇒ Object



173
174
175
176
177
178
179
180
# File 'lib/ie/external_route.rb', line 173

def ExternalRoute_Base.new_hash(h)
  raise unless h.is_a?(Hash)
  if h.has_key? :mt_metrics
    MtExternalRoute.new(h)
  else
    ExternalRoute.new(h)
  end
end

Instance Method Details

#encodeObject



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

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

#parse(s) ⇒ Object



112
113
114
115
116
# File 'lib/ie/external_route.rb', line 112

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



118
119
120
# File 'lib/ie/external_route.rb', line 118

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