Class: OSPFv2::Router

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

Constant Summary

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, #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, #retransmit, #to_hash, #to_s_verbose

Methods included from TO_S

#to_s

Methods included from Common

#ivar_to_klassname, #ivars, #set, #to_hash

Constructor Details

#initialize(arg = {}) ⇒ Router

Returns a new instance of Router.



204
205
206
207
208
209
210
211
212
# File 'lib/lsa/router.rb', line 204

def initialize(arg={})
  super
  @links=[]
  @nwveb ||=0
  @ls_type = LsType.new(:router_lsa)
  
  # arg.merge!({:ls_type => 1}) if arg.is_a?(Hash)
  [[:abr,1],[:asbr,2],[:vl,4],[:wild,8],[:nssa,16]].each { |x| def_bit(*x) } unless respond_to? :set_abr
end

Dynamic Method Handling

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

Instance Attribute Details

Returns the value of attribute links.



202
203
204
# File 'lib/lsa/router.rb', line 202

def links
  @links
end

#nwvebObject (readonly)

Returns the value of attribute nwveb.



202
203
204
# File 'lib/lsa/router.rb', line 202

def nwveb
  @nwveb
end

Class Method Details

.new_hash(h) ⇒ Object



318
319
320
321
322
323
# File 'lib/lsa/router.rb', line 318

def self.new_hash(h)
  r = new(h)
  r.instance_eval { @nwveb = h[:nwveb] || 0}
  h[:links].each { |l| r << l } if h[:links]
  r
end

Instance Method Details

#<<(link) ⇒ Object



228
229
230
231
# File 'lib/lsa/router.rb', line 228

def <<(link)
  @links << RouterLink.factory(link)
  self
end

#[](*args) ⇒ Object Also known as: lookup



264
265
266
267
268
269
270
271
272
# File 'lib/lsa/router.rb', line 264

def [](*args)
  if args.size==1
    @links[*args]
  else
    ltype, link_id = args_to_key(*args)
    link = links.find_all { |x| (x.router_link_type.to_i == ltype) and (x.link_id.to_hash == link_id) }
    link.empty? ? nil : link[0]
  end
end

#args_to_key(*args) ⇒ Object

FIXME: make link_id an integer …



285
286
287
288
289
290
291
292
293
# File 'lib/lsa/router.rb', line 285

def args_to_key(*args)
  if args.size==1 and args[0].is_a?(RouterLink)
    [args[0].router_link_type.to_i, args[0].link_id.to_hash]
  elsif args.size==2 and args[0].is_a?(Symbol) and args[1].is_a?(String)
    [RouterLinkType.to_i(args[0]), args[1]]
  elsif args.size==2 and args[0].is_a?(Fixnum) and args[1].is_a?(String)
    args
  end
end

#delete(*args) ⇒ Object



275
276
277
278
# File 'lib/lsa/router.rb', line 275

def delete(*args)
  ltype, link_id = args_to_key(*args)
  links.delete_if { |x| x.router_link_type.to_i == ltype and x.link_id.to_hash == link_id }
end

#eachObject



280
281
282
# File 'lib/lsa/router.rb', line 280

def each
  links.each { |x| yield(x)  }
end

#encodeObject

--------------------------------+ | 0 Nt|W|V|E|B| 0 | # links | --------------------------------+



217
218
219
220
221
222
# File 'lib/lsa/router.rb', line 217

def encode
  lsa = []
  lsa << [@nwveb,0,@links.size].pack('CCn')
  lsa << @links.collect { |x| x.encode } unless @links.empty?
  super(lsa.join)
end

#has_link?(*args) ⇒ Boolean

Returns:

  • (Boolean)


260
261
262
# File 'lib/lsa/router.rb', line 260

def has_link?(*args)
  self[*args] ? true : false
end


233
234
235
# File 'lib/lsa/router.rb', line 233

def number_of_link
  @links.size
end

#parse(s) ⇒ Object



237
238
239
240
241
242
243
# File 'lib/lsa/router.rb', line 237

def parse(s)
  @nwveb, _, nlinks, links = super(s).unpack('CCna*')
  while links.size>0
    ntos= links[9..10].unpack('C')[0]
    self << links.slice!(0,12+ntos*4)
  end
end

#to_s_defaultObject



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

def to_s_default
  super  +
  ['', nwveb_to_s, *links.collect {|x| x.to_s }].join("\n   ")
end

#to_s_junosObject



250
251
252
# File 'lib/lsa/router.rb', line 250

def to_s_junos
  super
end

#to_s_junos_verboseObject



254
255
256
257
258
# File 'lib/lsa/router.rb', line 254

def to_s_junos_verbose
  link_hdr = "  bits 0x#{nwveb.to_i}, link count #{links.size}"
  links_to_s = links.collect {|link| link.to_s_junos }
  super + ['', link_hdr, *links_to_s].join("\n")
end