3
* Copyright (C) 1999, 2000 Alex Zinin, Kunihiro Ishiguro, Toshiaki Takada
5
* This file is part of GNU Zebra.
7
* GNU Zebra is free software; you can redistribute it and/or modify it
8
* under the terms of the GNU General Public License as published by the
9
* Free Software Foundation; either version 2, or (at your option) any
12
* GNU Zebra is distributed in the hope that it will be useful, but
13
* WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with GNU Zebra; see the file COPYING. If not, write to the Free
19
* Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
29
#include "ospfd/ospfd.h"
30
#include "ospfd/ospf_asbr.h"
31
#include "ospfd/ospf_lsa.h"
32
#include "ospfd/ospf_lsdb.h"
37
struct ospf_lsdb *new;
39
new = XCALLOC (MTYPE_OSPF_LSDB, sizeof (struct ospf_lsdb));
46
ospf_lsdb_init (struct ospf_lsdb *lsdb)
50
for (i = OSPF_MIN_LSA; i < OSPF_MAX_LSA; i++)
51
lsdb->type[i].db = route_table_init ();
55
ospf_lsdb_free (struct ospf_lsdb *lsdb)
57
ospf_lsdb_cleanup (lsdb);
58
XFREE (MTYPE_OSPF_LSDB, lsdb);
62
ospf_lsdb_cleanup (struct ospf_lsdb *lsdb)
66
assert (lsdb->total == 0);
68
ospf_lsdb_delete_all (lsdb);
70
for (i = OSPF_MIN_LSA; i < OSPF_MAX_LSA; i++)
71
route_table_finish (lsdb->type[i].db);
75
lsdb_prefix_set (struct prefix_ls *lp, struct ospf_lsa *lsa)
77
memset (lp, 0, sizeof (struct prefix_ls));
80
lp->id = lsa->data->id;
81
lp->adv_router = lsa->data->adv_router;
84
/* Add new LSA to lsdb. */
86
ospf_lsdb_add (struct ospf_lsdb *lsdb, struct ospf_lsa *lsa)
88
struct route_table *table;
90
struct route_node *rn;
93
table = lsdb->type[lsa->data->type].db;
94
lsdb_prefix_set (&lp, lsa);
95
rn = route_node_get (table, (struct prefix *)&lp);
98
if (IS_LSA_SELF (lsa))
99
lsdb->type[lsa->data->type].count_self++;
100
lsdb->type[lsa->data->type].count++;
109
lsdb->type[old->data->type].checksum -= ntohs(old->data->checksum);
111
ospf_lsa_unlock (rn->info);
112
route_unlock_node (rn);
115
#ifdef MONITOR_LSDB_CHANGE
116
if (lsdb->new_lsa_hook != NULL)
117
(* lsdb->new_lsa_hook)(lsa);
118
#endif /* MONITOR_LSDB_CHANGE */
119
lsdb->type[lsa->data->type].checksum += ntohs(lsa->data->checksum);
120
rn->info = ospf_lsa_lock (lsa);
124
ospf_lsdb_delete (struct ospf_lsdb *lsdb, struct ospf_lsa *lsa)
126
struct route_table *table;
128
struct route_node *rn;
130
table = lsdb->type[lsa->data->type].db;
131
lsdb_prefix_set (&lp, lsa);
132
rn = route_node_lookup (table, (struct prefix *) &lp);
136
if (IS_LSA_SELF (lsa))
137
lsdb->type[lsa->data->type].count_self--;
138
lsdb->type[lsa->data->type].count--;
139
lsdb->type[lsa->data->type].checksum -= ntohs(lsa->data->checksum);
142
route_unlock_node (rn);
143
route_unlock_node (rn);
144
#ifdef MONITOR_LSDB_CHANGE
145
if (lsdb->del_lsa_hook != NULL)
146
(* lsdb->del_lsa_hook)(lsa);
147
#endif /* MONITOR_LSDB_CHANGE */
148
ospf_lsa_unlock (lsa);
154
ospf_lsdb_delete_all (struct ospf_lsdb *lsdb)
156
struct route_table *table;
157
struct route_node *rn;
158
struct ospf_lsa *lsa;
161
for (i = OSPF_MIN_LSA; i < OSPF_MAX_LSA; i++)
163
table = lsdb->type[i].db;
164
for (rn = route_top (table); rn; rn = route_next (rn))
165
if ((lsa = (rn->info)) != NULL)
167
if (IS_LSA_SELF (lsa))
168
lsdb->type[i].count_self--;
169
lsdb->type[i].count--;
170
lsdb->type[i].checksum -= ntohs(lsa->data->checksum);
173
route_unlock_node (rn);
174
#ifdef MONITOR_LSDB_CHANGE
175
if (lsdb->del_lsa_hook != NULL)
176
(* lsdb->del_lsa_hook)(lsa);
177
#endif /* MONITOR_LSDB_CHANGE */
178
ospf_lsa_unlock (lsa);
184
ospf_lsdb_clean_stat (struct ospf_lsdb *lsdb)
186
struct route_table *table;
187
struct route_node *rn;
188
struct ospf_lsa *lsa;
191
for (i = OSPF_MIN_LSA; i < OSPF_MAX_LSA; i++)
193
table = lsdb->type[i].db;
194
for (rn = route_top (table); rn; rn = route_next (rn))
195
if ((lsa = (rn->info)) != NULL)
196
lsa->stat = LSA_SPF_NOT_EXPLORED;
201
ospf_lsdb_lookup (struct ospf_lsdb *lsdb, struct ospf_lsa *lsa)
203
struct route_table *table;
205
struct route_node *rn;
206
struct ospf_lsa *find;
208
table = lsdb->type[lsa->data->type].db;
209
lsdb_prefix_set (&lp, lsa);
210
rn = route_node_lookup (table, (struct prefix *) &lp);
214
route_unlock_node (rn);
221
ospf_lsdb_lookup_by_id (struct ospf_lsdb *lsdb, u_char type,
222
struct in_addr id, struct in_addr adv_router)
224
struct route_table *table;
226
struct route_node *rn;
227
struct ospf_lsa *find;
229
table = lsdb->type[type].db;
231
memset (&lp, 0, sizeof (struct prefix_ls));
235
lp.adv_router = adv_router;
237
rn = route_node_lookup (table, (struct prefix *) &lp);
241
route_unlock_node (rn);
248
ospf_lsdb_lookup_by_id_next (struct ospf_lsdb *lsdb, u_char type,
249
struct in_addr id, struct in_addr adv_router,
252
struct route_table *table;
254
struct route_node *rn;
255
struct ospf_lsa *find;
257
table = lsdb->type[type].db;
259
memset (&lp, 0, sizeof (struct prefix_ls));
263
lp.adv_router = adv_router;
266
rn = route_top (table);
269
rn = route_node_get (table, (struct prefix *) &lp);
270
rn = route_next (rn);
273
for (; rn; rn = route_next (rn))
280
route_unlock_node (rn);
287
ospf_lsdb_count_all (struct ospf_lsdb *lsdb)
293
ospf_lsdb_count (struct ospf_lsdb *lsdb, int type)
295
return lsdb->type[type].count;
299
ospf_lsdb_count_self (struct ospf_lsdb *lsdb, int type)
301
return lsdb->type[type].count_self;
305
ospf_lsdb_checksum (struct ospf_lsdb *lsdb, int type)
307
return lsdb->type[type].checksum;
311
ospf_lsdb_isempty (struct ospf_lsdb *lsdb)
313
return (lsdb->total == 0);