Class: OSPFv2::External_Base

Inherits:
Lsa show all
Defined in:
lib/lsa/external.rb

Direct Known Subclasses

AsExternal

Constant Summary collapse

Netmask =
Class.new(OSPFv2::Id)
ExternalRoute =
Class.new(OSPFv2::ExternalRoute)

Constants inherited from Lsa

Lsa::AdvertisingRouter, Lsa::LsAge, Lsa::LsId, Lsa::MODX

Constants included from Constant

Constant::DATABASE_DESCRIPTION, Constant::HELLO, Constant::LINK_STATE_ACKNOWLEDGEMENT, Constant::LINK_STATE_REQUEST, Constant::LINK_STATE_UPDATE, Constant::V2, Constant::V3

Instance Attribute Summary collapse

Attributes inherited from Lsa

#advertising_router, #ls_age, #ls_id, #opaque_id, #opaque_type, #options, #sequence_number

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Lsa

#<=>, #ack, #encode_header, #encode_request, factory, #find_lsa_from_link, #force_refresh, #header_lsa, #is_acked?, #is_opaque?, #key, #ls_type, #lsdb_link_id, #lsdb_link_id=, #maxage, #maxaged?, #method_missing, new_ntop, #refresh, #refresh2, #retransmit

Methods included from Common

#ivar_to_klassname, #ivars, #set

Constructor Details

#initialize(ls_type, arg = {}) ⇒ External_Base

Returns a new instance of External_Base.



166
167
168
169
170
171
# File 'lib/lsa/external.rb', line 166

def initialize(ls_type, arg={})
  @netmask, @external_route = nil
  @mt_metrics=[]
  @ls_type = LsType.new(ls_type)
  super arg
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class OSPFv2::Lsa

Instance Attribute Details

#external_routeObject (readonly)

Returns the value of attribute external_route.



163
164
165
# File 'lib/lsa/external.rb', line 163

def external_route
  @external_route
end

#mt_metricsObject

Returns the value of attribute mt_metrics.



163
164
165
# File 'lib/lsa/external.rb', line 163

def mt_metrics
  @mt_metrics
end

#netmaskObject (readonly)

Returns the value of attribute netmask.



163
164
165
# File 'lib/lsa/external.rb', line 163

def netmask
  @netmask
end

Class Method Details

.base_ip_addr(addr = EXTERNAL_BASE_ADDRESS) ⇒ Object



297
298
299
# File 'lib/lsa/external.rb', line 297

def base_ip_addr(addr=EXTERNAL_BASE_ADDRESS)
  @base_addr ||= IPAddr.new(addr)
end

.countObject



284
285
286
# File 'lib/lsa/external.rb', line 284

def count
  @count ||= 0
end

.incr_countObject



288
289
290
291
# File 'lib/lsa/external.rb', line 288

def incr_count
  self.count
  @count += 1
end

.networkObject



301
302
303
# File 'lib/lsa/external.rb', line 301

def network
  @base_addr + count
end

.new_lsdb(arg = {}) ⇒ Object



305
306
307
# File 'lib/lsa/external.rb', line 305

def new_lsdb(arg={})
  new({:network=> base_ip_addr ^ incr_count}.merge(arg))
end

.resetObject



293
294
295
# File 'lib/lsa/external.rb', line 293

def reset
  @count = nil
end

Instance Method Details

#<<(ext_route) ⇒ Object



257
258
259
260
261
262
263
264
# File 'lib/lsa/external.rb', line 257

def <<(ext_route)
  @mt_metrics ||=[]
  # p "calling MtExternalRoute with #{ext_route.inspect}"
  route = MtExternalRoute.new(ext_route)
  # p route
  @mt_metrics << route
  self
end

#encodeObject



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

def encode
  @netmask ||= Netmask.new
  external =[]
  external << netmask.encode
  external << external_route.encode
  external << mt_metrics.collect { |x| x.encode } if mt_metrics
  super external.join
end

#forwarding_address=(val) ⇒ Object



266
267
268
# File 'lib/lsa/external.rb', line 266

def forwarding_address=(val)
  @external_route.forwarding_address=(val)
end

#metric=(val) ⇒ Object



278
279
280
# File 'lib/lsa/external.rb', line 278

def metric=(val)
  @external_route.metric=(val)
end

#parse(s) ⇒ Object



182
183
184
185
186
187
188
189
190
# File 'lib/lsa/external.rb', line 182

def parse(s)
  s = super(s)
  netmask, external_route = s.slice!(0,16).unpack('Na*')
  @netmask = Netmask.new netmask
  @external_route = ExternalRoute.new external_route
  while s.size>0
    self << MtExternalRoute.new(s.slice!(0,12))
  end
end

#tag=(val) ⇒ Object



274
275
276
# File 'lib/lsa/external.rb', line 274

def tag=(val)
  @external_route.tag=(val)
end

#to_hashObject



192
193
194
# File 'lib/lsa/external.rb', line 192

def to_hash
  super
end

#to_sObject



196
197
198
# File 'lib/lsa/external.rb', line 196

def to_s
  super
end

#to_s_iosObject

Network Mask: /24

Metric Type: 1 (Comparable directly to link state metric)
TOS: 0 
Metric: 0 
Forward Address: 0.0.0.0
External Route Tag: 0
Metric Type: 1 (Comparable directly to link state metric)
TOS: 10 
Metric: 20 
Forward Address: 0.0.0.0
External Route Tag: 10


212
213
214
# File 'lib/lsa/external.rb', line 212

def to_s_ios
  super + external_route.tag.to_s
end

#to_s_ios_verboseObject



216
217
218
219
220
221
222
223
224
225
226
# File 'lib/lsa/external.rb', line 216

def to_s_ios_verbose
  s = []
  mt_metrics = self.mt_metrics.collect
  s << super
  s << "Network Mask: #{netmask}"
  ext = []
  ext << "    #{external_route}"
  ext << mt_metrics.collect { |x| x.to_s }
  s << ext.join("\n      ")
  s.join("\n  ")
end

#to_s_junosObject



235
236
237
# File 'lib/lsa/external.rb', line 235

def to_s_junos
  super
end

#to_s_junos_verboseObject

Extern 50.0.2.0 128.3.0.1 0x80000001 39 0x0 0x1454 48

mask 255.255.255.0
Topology default (ID 0)
  Type: 1, Metric: 0, Fwd addr: 0.0.0.0, Tag: 0.0.0.0
Topology default (ID 0)
  Type: 1, Metric: 30, Fwd addr: 0.0.0.0, Tag: 0.0.0.10


245
246
247
248
249
# File 'lib/lsa/external.rb', line 245

def to_s_junos_verbose
  mt_metrics = self.mt_metrics.collect
  super  +
  ['',netmask, external_route, *mt_metrics ].collect { |x| x.to_s }.join("\n   ")
end

#to_s_verboseObject



229
230
231
232
233
# File 'lib/lsa/external.rb', line 229

def to_s_verbose
  mt_metrics = self.mt_metrics.collect
  super  +
  ['',netmask, external_route, *mt_metrics ].collect { |x| x.to_s }.join("\n   ")
end

#type=(val) ⇒ Object



270
271
272
# File 'lib/lsa/external.rb', line 270

def type=(val)
  @external_route.type=(val)
end