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
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, #ls_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?, #key, #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
|
# File 'lib/lsa/router.rb', line 204
def initialize(arg={})
super
@links=[]
@nwveb ||=0
[[:abr,1],[:asbr,2],[:vl,4],[:wild,8],[:nssa,16]].each { |x| def_bit *x }
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
|
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
326
327
328
329
330
331
|
# File 'lib/lsa/router.rb', line 326
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
226
227
228
229
|
# File 'lib/lsa/router.rb', line 226
def <<(link)
@links << RouterLink.factory(link)
self
end
|
#[](*args) ⇒ Object
Also known as:
lookup
262
263
264
265
266
267
268
269
270
|
# File 'lib/lsa/router.rb', line 262
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 …
283
284
285
286
287
288
289
290
291
|
# File 'lib/lsa/router.rb', line 283
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
273
274
275
276
|
# File 'lib/lsa/router.rb', line 273
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
|
278
279
280
|
# File 'lib/lsa/router.rb', line 278
def each
links.each { |x| yield(x) }
end
|
-
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
-+ | 0 Nt|W|V|E|B| 0 | # links | -
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
-+
215
216
217
218
219
220
|
# File 'lib/lsa/router.rb', line 215
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
258
259
260
|
# File 'lib/lsa/router.rb', line 258
def has_link?(*args)
self[*args] ? true : false
end
|
#number_of_link ⇒ Object
231
232
233
|
# File 'lib/lsa/router.rb', line 231
def number_of_link
@links.size
end
|
235
236
237
238
239
240
241
|
# File 'lib/lsa/router.rb', line 235
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_default ⇒ Object
243
244
245
246
|
# File 'lib/lsa/router.rb', line 243
def to_s_default
super +
['', nwveb_to_s, *links.collect {|x| x.to_s6 }].join("\n ")
end
|
#to_s_junos ⇒ Object
248
249
250
|
# File 'lib/lsa/router.rb', line 248
def to_s_junos
super
end
|
#to_s_junos_verbose ⇒ Object
252
253
254
255
256
|
# File 'lib/lsa/router.rb', line 252
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
|