-
Notifications
You must be signed in to change notification settings - Fork 1
/
delsa.lua
106 lines (87 loc) · 2.24 KB
/
delsa.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env lua
-- -*-lua-*-
--
-- $Id: delsa.lua $
--
-- Author: Markus Stenberg <[email protected]>
--
-- Copyright (c) 2012 cisco Systems, Inc.
--
-- Created: Fri Oct 5 00:09:17 2012 mstenber
-- Last modified: Wed Jul 17 17:21:38 2013 mstenber
-- Edit time: 54 min
--
-- this is variant with the neighbor topology + various pieces of
-- LSA/AC information stored within additionally. It is useful for
-- simulating number of elsa_pa nodes.
require 'mst'
require 'elsa_pa'
require 'dneigh'
module(..., package.seeall)
dummy_if_table = {
get_if=function (ifname)
return {
get_hwaddr=function ()
return '00:11:22:33:44:55'
end
}
end
}
delsa = dneigh.dneigh:new_subclass{class='delsa', mandatory={'hwf'}}
function delsa:init()
dneigh.dneigh.init(self)
self.lsas = self.lsas or {}
end
function delsa:repr_data()
return string.format('#hwf=%d #iid=%d #lsas=%d #neigh=%d #routes=%d',
mst.count(self.hwf),
mst.count(self.iid),
mst.count(self.lsas),
mst.count(self.neigh),
mst.count(self.routes))
end
function delsa:get_hwf(rid)
return self.hwf[rid]
end
function delsa:iterate_lsa(rid0, f, criteria)
local c = self:get_connected(rid0)
self:a(c)
self:d('iterate_lsa', rid0)
for rid, body in pairs(self.lsas)
do
if c[rid] or self.assume_connected
then
self:d(' matched', rid)
f{rid=rid, body=body}
else
self:d(' not reachable', rid)
end
end
end
function delsa:notify_ospf_changed(rid)
local epa = self.nodes[rid]
if epa
then
epa:ospf_changed()
end
end
function delsa:originate_lsa(lsa)
self:a(lsa.type == elsa_pa.AC_TYPE)
local old = self.lsas[lsa.rid]
if old == lsa.body
then
self:d('originate_lsa failed, same body', lsa.rid)
return
end
self:d('originate_lsa - new lsa for', lsa.rid)
self.lsas[lsa.rid] = lsa.body
-- notify self + others that the lsas changed
for rid, _ in pairs(self:get_connected(lsa.rid))
do
self:d(' notifying change', rid)
self:notify_ospf_changed(rid)
end
end
function delsa:change_rid()
self.rid_changed = true
end