Class: OSPFv2::LSDB::Link

Inherits:
Object show all
Includes:
Common
Defined in:
lib/ls_db/links.rb

Constant Summary collapse

RouterId =

FIXME: all IE should be in an IE namespace

Class.new(OSPFv2::Id)
NeighborId =
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 = {}) ⇒ Link

TODO: :metric => [10,20] … revisit

:metric_ifa => 10, :metric_ifb=>20


92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/ls_db/links.rb', line 92

def initialize(arg={})
  @_state = :down
  @_id = self.class.incr_count
  @prefix=nil
  @router_id= RouterId.new arg[:router_id] || '1.1.1.1'
  @neighbor_id= NeighborId.new arg[:neighbor_id] || '2.2.2.2'
  @metric = 0
  set arg
  @lsas=[]
  Link << self
  self
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



139
140
141
142
143
144
145
# File 'lib/ls_db/links.rb', line 139

def method_missing(name, *args, &block)
  if name.to_s =~ /^(local|remote)_address/
    (__send__ "#{$1}_prefix").split('/')[0]
  else
    super
  end
end

Instance Attribute Details

#local_lsaObject

Returns the value of attribute local_lsa.



114
115
116
# File 'lib/ls_db/links.rb', line 114

def local_lsa
  @local_lsa
end

#metricObject (readonly)

Returns the value of attribute metric.



88
89
90
# File 'lib/ls_db/links.rb', line 88

def metric
  @metric
end

#neighbor_idObject (readonly)

Returns the value of attribute neighbor_id.



88
89
90
# File 'lib/ls_db/links.rb', line 88

def neighbor_id
  @neighbor_id
end

#remote_lsaObject

Returns the value of attribute remote_lsa.



114
115
116
# File 'lib/ls_db/links.rb', line 114

def remote_lsa
  @remote_lsa
end

#router_idObject (readonly)

Returns the value of attribute router_id.



88
89
90
# File 'lib/ls_db/links.rb', line 88

def router_id
  @router_id
end

Class Method Details

.<<(val) ⇒ Object



35
36
37
38
# File 'lib/ls_db/links.rb', line 35

def <<(val)
  @_links ||={}
  @_links.store(val.id, val)
end

.[](val) ⇒ Object



76
77
78
# File 'lib/ls_db/links.rb', line 76

def [](val)
  @_links[val]
end

.allObject



40
41
42
43
# File 'lib/ls_db/links.rb', line 40

def all
  @_links ||={}
  @_links
end

.base_ip_addr(addr = LINK_BASE_ADDRESS) ⇒ Object



64
65
66
# File 'lib/ls_db/links.rb', line 64

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

.countObject



50
51
52
# File 'lib/ls_db/links.rb', line 50

def count
  @count ||= 0
end

.find_by_id(router_id) ⇒ Object



68
69
70
# File 'lib/ls_db/links.rb', line 68

def find_by_id(router_id)
  all.find_all { |k,v| v.router_id.to_ip == router_id }
end

.idsObject



45
46
47
48
# File 'lib/ls_db/links.rb', line 45

def ids
  @_links ||={}
  @_links.keys
end

.incr_countObject



54
55
56
57
# File 'lib/ls_db/links.rb', line 54

def incr_count
  self.count
  @count += 1
end

.resetObject



59
60
61
62
# File 'lib/ls_db/links.rb', line 59

def reset
  @_links={}
  @count = nil
end

.reset_ip_addrObject



72
73
74
# File 'lib/ls_db/links.rb', line 72

def reset_ip_addr
  @base_addr=nil
end

Instance Method Details

#idObject



110
111
112
# File 'lib/ls_db/links.rb', line 110

def id
  @_id
end

#networkObject



124
125
126
# File 'lib/ls_db/links.rb', line 124

def network
  @network ||=IPAddr.new(Link.base_ip_addr.^(@_id-1))
end

#network_to_sObject



135
136
137
# File 'lib/ls_db/links.rb', line 135

def network_to_s
  [network, network.mlen].join('/')
end

#to_sObject



128
129
130
131
132
133
# File 'lib/ls_db/links.rb', line 128

def to_s
  rid = router_id.to_s.split(":")
  nid = neighbor_id.to_s.split(":")
  sprintf("%3d\# %s: %-15.15s  %s:%-15.15s Network %-15.15s %s",
  @_id, rid[0], rid[1], nid[0], nid[1], network_to_s, metric)
end