]>
Commit | Line | Data |
---|---|---|
718e3744 | 1 | /* |
2 | * OSPFv3 Top Level Data Structure | |
3 | * Copyright (C) 1999 Yasuhiro Ohara | |
4 | * | |
5 | * This file is part of GNU Zebra. | |
6 | * | |
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 | |
10 | * later version. | |
11 | * | |
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. | |
16 | * | |
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 | |
19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
20 | * Boston, MA 02111-1307, USA. | |
21 | */ | |
22 | ||
23 | #include <zebra.h> | |
24 | ||
25 | #include "log.h" | |
26 | #include "memory.h" | |
27 | #include "vty.h" | |
28 | #include "linklist.h" | |
29 | #include "prefix.h" | |
30 | #include "table.h" | |
31 | #include "thread.h" | |
32 | #include "command.h" | |
33 | ||
34 | #include "ospf6_hook.h" | |
35 | #include "ospf6_proto.h" | |
36 | #include "ospf6_prefix.h" | |
37 | #include "ospf6_lsa.h" | |
38 | #include "ospf6_lsdb.h" | |
39 | ||
40 | #include "ospf6_message.h" | |
41 | #include "ospf6_neighbor.h" | |
42 | #include "ospf6_interface.h" | |
43 | #include "ospf6_area.h" | |
44 | #include "ospf6_top.h" | |
45 | ||
46 | #include "ospf6_route.h" | |
47 | #include "ospf6_zebra.h" | |
48 | ||
49 | #include "ospf6_nsm.h" | |
50 | #include "ospf6_asbr.h" | |
51 | #include "ospf6_abr.h" | |
52 | ||
53 | #define HEADER_DEPENDENCY | |
54 | #include "ospf6d.h" | |
55 | #undef HEADER_DEPENDENCY | |
56 | ||
57 | /* global ospf6d variable */ | |
58 | struct ospf6 *ospf6; | |
59 | ||
60 | static void | |
61 | ospf6_top_foreach_area (struct ospf6 *o6, void *arg, int val, | |
62 | void (*func) (void *, int, void *)) | |
63 | { | |
64 | listnode node; | |
65 | struct ospf6_area *o6a; | |
66 | ||
67 | for (node = listhead (o6->area_list); node; nextnode (node)) | |
68 | { | |
69 | o6a = (struct ospf6_area *) getdata (node); | |
70 | (*func) (arg, val, o6a); | |
71 | } | |
72 | } | |
73 | ||
74 | static void | |
75 | ospf6_top_foreach_interface (struct ospf6 *o6, void *arg, int val, | |
76 | void (*func) (void *, int, void *)) | |
77 | { | |
78 | listnode node; | |
79 | struct ospf6_area *o6a; | |
80 | ||
81 | for (node = listhead (o6->area_list); node; nextnode (node)) | |
82 | { | |
83 | o6a = (struct ospf6_area *) getdata (node); | |
84 | (*o6a->foreach_if) (o6a, arg, val, func); | |
85 | } | |
86 | } | |
87 | ||
88 | static void | |
89 | ospf6_top_foreach_neighbor (struct ospf6 *o6, void *arg, int val, | |
90 | void (*func) (void *, int, void *)) | |
91 | { | |
92 | listnode node; | |
93 | struct ospf6_area *o6a; | |
94 | ||
95 | for (node = listhead (o6->area_list); node; nextnode (node)) | |
96 | { | |
97 | o6a = (struct ospf6_area *) getdata (node); | |
98 | (*o6a->foreach_nei) (o6a, arg, val, func); | |
99 | } | |
100 | } | |
101 | ||
102 | static int | |
103 | ospf6_top_maxage_remover (struct thread *t) | |
104 | { | |
105 | int count; | |
106 | struct ospf6 *o6 = (struct ospf6 *) THREAD_ARG (t); | |
107 | ||
108 | o6->maxage_remover = (struct thread *) NULL; | |
109 | ||
110 | count = 0; | |
111 | o6->foreach_nei (o6, &count, NBS_EXCHANGE, ospf6_count_state); | |
112 | o6->foreach_nei (o6, &count, NBS_LOADING, ospf6_count_state); | |
113 | if (count != 0) | |
114 | return 0; | |
115 | ||
116 | ospf6_lsdb_remove_maxage (o6->lsdb); | |
117 | return 0; | |
118 | } | |
119 | ||
120 | void | |
121 | ospf6_top_schedule_maxage_remover (void *arg, int val, struct ospf6 *o6) | |
122 | { | |
123 | if (o6->maxage_remover != NULL) | |
124 | return; | |
125 | ||
126 | o6->maxage_remover = | |
127 | thread_add_event (master, ospf6_top_maxage_remover, o6, 0); | |
128 | } | |
129 | ||
130 | void | |
131 | ospf6_show (struct vty *vty) | |
132 | { | |
133 | listnode n; | |
134 | struct ospf6_area *area; | |
135 | char id_string[32]; | |
136 | unsigned long day, hour, min, sec; | |
137 | struct timeval now, running; | |
138 | ||
139 | /* process id, router id */ | |
140 | inet_ntop (AF_INET, &ospf6->router_id, id_string, sizeof (id_string)); | |
141 | vty_out (vty, " Routing Process (%lu) with ID %s%s", | |
142 | ospf6->process_id, id_string, VTY_NEWLINE); | |
143 | ||
144 | /* running time */ | |
145 | gettimeofday (&now, (struct timezone *)NULL); | |
146 | ospf6_timeval_sub (&now, &ospf6->starttime, &running); | |
147 | ospf6_timeval_decode (&running, &day, &hour, &min, &sec, NULL, NULL); | |
148 | vty_out (vty, " Running %ld days %ld hours %ld minutes %ld seconds%s", | |
149 | day, hour, min, sec, VTY_NEWLINE); | |
150 | ||
151 | vty_out (vty, " Supports only single TOS(TOS0) routes%s", VTY_NEWLINE); | |
152 | ||
153 | /* Redistribute config */ | |
154 | ospf6_redistribute_show_config (vty); | |
155 | ||
156 | /* LSAs */ | |
157 | vty_out (vty, " Number of AS scoped LSAs is %u%s", | |
158 | ospf6->lsdb->count, VTY_NEWLINE); | |
159 | vty_out (vty, " Route calculation executed %d times%s", | |
160 | ospf6->stat_route_calculation_execed, VTY_NEWLINE); | |
161 | ||
162 | /* Route Statistics */ | |
163 | #if 0 | |
164 | ospf6_route_statistics_show (vty, ospf6->route_table); | |
165 | #endif | |
166 | ||
167 | /* Areas */ | |
168 | vty_out (vty, " Number of areas in this router is %u%s", | |
169 | listcount (ospf6->area_list), VTY_NEWLINE); | |
170 | for (n = listhead (ospf6->area_list); n; nextnode (n)) | |
171 | { | |
172 | area = (struct ospf6_area *) getdata (n); | |
173 | ospf6_area_show (vty, area); | |
174 | } | |
175 | } | |
176 | ||
177 | void | |
178 | ospf6_statistics_show (struct vty *vty, struct ospf6 *o6) | |
179 | { | |
180 | listnode node; | |
181 | struct ospf6_area *o6a; | |
182 | char running_time[128]; | |
183 | struct timeval now, running; | |
184 | ||
185 | gettimeofday (&now, (struct timezone *) NULL); | |
186 | ospf6_timeval_sub (&now, &o6->starttime, &running); | |
187 | ospf6_timeval_string (&running, running_time, sizeof (running_time)); | |
188 | ||
189 | vty_out (vty, "Statistics of OSPF process %ld%s", | |
190 | o6->process_id, VTY_NEWLINE); | |
191 | vty_out (vty, " Running: %s%s", running_time, VTY_NEWLINE); | |
192 | ||
193 | #if 0 | |
194 | ospf6_route_statistics_show (vty, o6->route_table); | |
195 | #endif | |
196 | ||
197 | for (node = listhead (o6->area_list); node; nextnode (node)) | |
198 | { | |
199 | o6a = (struct ospf6_area *) getdata (node); | |
200 | ospf6_area_statistics_show (vty, o6a); | |
201 | } | |
202 | } | |
203 | ||
204 | static struct ospf6 * | |
205 | ospf6_new () | |
206 | { | |
207 | struct ospf6 *new; | |
208 | new = XMALLOC (MTYPE_OSPF6_TOP, sizeof (struct ospf6)); | |
209 | if (new) | |
210 | memset (new, 0, sizeof (struct ospf6)); | |
211 | return new; | |
212 | } | |
213 | ||
214 | void | |
215 | ospf6_free (struct ospf6 *ospf6) | |
216 | { | |
217 | XFREE (MTYPE_OSPF6_TOP, ospf6); | |
218 | } | |
219 | ||
220 | void | |
221 | ospf6_top_topology_add (struct ospf6_route_req *request) | |
222 | { | |
223 | assert (request->route.type == OSPF6_DEST_TYPE_ROUTER); | |
224 | if (CHECK_FLAG (request->path.router_bits, OSPF6_ROUTER_LSA_BIT_E)) | |
225 | ospf6_asbr_asbr_entry_add (request); | |
226 | } | |
227 | ||
228 | void | |
229 | ospf6_top_topology_remove (struct ospf6_route_req *request) | |
230 | { | |
231 | assert (request->route.type == OSPF6_DEST_TYPE_ROUTER); | |
232 | if (CHECK_FLAG (request->path.router_bits, OSPF6_ROUTER_LSA_BIT_E)) | |
233 | ospf6_asbr_asbr_entry_remove (request); | |
234 | } | |
235 | ||
236 | struct ospf6 * | |
237 | ospf6_create (unsigned long process_id) | |
238 | { | |
239 | struct ospf6 *o6; | |
240 | char namebuf[64]; | |
241 | ||
242 | o6 = ospf6_new (); | |
243 | ||
244 | /* initialize */ | |
245 | gettimeofday (&o6->starttime, (struct timezone *)NULL); | |
246 | o6->process_id = process_id; | |
247 | o6->version = OSPF6_VERSION; | |
248 | o6->area_list = list_new (); | |
249 | ||
250 | o6->lsdb = ospf6_lsdb_create (); | |
251 | ||
252 | o6->foreach_area = ospf6_top_foreach_area; | |
253 | o6->foreach_if = ospf6_top_foreach_interface; | |
254 | o6->foreach_nei = ospf6_top_foreach_neighbor; | |
255 | ||
256 | snprintf (namebuf, sizeof (namebuf), "InterTopology table"); | |
257 | o6->topology_table = ospf6_route_table_create (namebuf); | |
258 | ospf6_route_hook_register (ospf6_top_topology_add, | |
259 | ospf6_top_topology_add, | |
260 | ospf6_top_topology_remove, | |
261 | o6->topology_table); | |
262 | ||
263 | #if 0 | |
264 | snprintf (namebuf, sizeof (namebuf), "External table"); | |
265 | o6->external_table = ospf6_route_table_create (namebuf); | |
266 | ospf6_route_hook_register (ospf6_asbr_external_route_add, | |
267 | ospf6_asbr_external_route_add, | |
268 | ospf6_asbr_external_route_remove, | |
269 | o6->external_table); | |
270 | #endif /*0*/ | |
271 | ||
272 | snprintf (namebuf, sizeof (namebuf), "Top route table"); | |
273 | o6->route_table = ospf6_route_table_create (namebuf); | |
274 | ospf6_route_hook_register (ospf6_zebra_route_update_add, | |
275 | ospf6_zebra_route_update_add, | |
276 | ospf6_zebra_route_update_remove, | |
277 | o6->route_table); | |
278 | ospf6_route_hook_register (ospf6_abr_route_add, | |
279 | ospf6_abr_route_add, | |
280 | ospf6_abr_route_remove, | |
281 | o6->route_table); | |
282 | ||
283 | return o6; | |
284 | } | |
285 | ||
286 | void | |
287 | ospf6_delete (struct ospf6 *ospf6) | |
288 | { | |
e26bbeba | 289 | if (!ospf6) |
290 | return; | |
291 | ||
718e3744 | 292 | ospf6_route_remove_all (ospf6->route_table); |
293 | ospf6_free (ospf6); | |
294 | } | |
295 | ||
296 | struct ospf6 * | |
297 | ospf6_start () | |
298 | { | |
299 | if (ospf6) | |
300 | return ospf6; | |
301 | ||
302 | ospf6 = ospf6_create (0); | |
303 | return ospf6; | |
304 | } | |
305 | ||
306 | void | |
307 | ospf6_stop () | |
308 | { | |
309 | if (!ospf6) | |
310 | return; | |
311 | ||
312 | ospf6_delete (ospf6); | |
313 | ospf6 = NULL; | |
314 | } | |
315 | ||
316 | int | |
317 | ospf6_is_asbr (struct ospf6 *o6) | |
318 | { | |
319 | int i = 0; | |
320 | i |= ospf6_zebra_is_redistribute (ZEBRA_ROUTE_SYSTEM); | |
321 | i |= ospf6_zebra_is_redistribute (ZEBRA_ROUTE_CONNECT); | |
322 | i |= ospf6_zebra_is_redistribute (ZEBRA_ROUTE_STATIC); | |
323 | i |= ospf6_zebra_is_redistribute (ZEBRA_ROUTE_KERNEL); | |
324 | i |= ospf6_zebra_is_redistribute (ZEBRA_ROUTE_RIPNG); | |
325 | i |= ospf6_zebra_is_redistribute (ZEBRA_ROUTE_BGP); | |
326 | return (i); | |
327 | } | |
328 | ||
329 | DEFUN (show_ipv6_ospf6_route, | |
330 | show_ipv6_ospf6_route_cmd, | |
331 | "show ipv6 ospf6 route", | |
332 | SHOW_STR | |
333 | IP6_STR | |
334 | OSPF6_STR | |
335 | "Routing table\n" | |
336 | ) | |
337 | { | |
338 | OSPF6_CMD_CHECK_RUNNING (); | |
339 | return ospf6_route_table_show (vty, argc, argv, ospf6->route_table); | |
340 | } | |
341 | ||
342 | ALIAS (show_ipv6_ospf6_route, | |
343 | show_ipv6_ospf6_route_prefix_cmd, | |
344 | "show ipv6 ospf6 route (X::X|detail)", | |
345 | SHOW_STR | |
346 | IP6_STR | |
347 | OSPF6_STR | |
348 | "Routing table\n" | |
349 | "match IPv6 prefix\n" | |
350 | ) | |
351 | ||
352 | DEFUN (show_ipv6_ospf6_topology, | |
353 | show_ipv6_ospf6_topology_cmd, | |
354 | "show ipv6 ospf6 topology", | |
355 | SHOW_STR | |
356 | IP6_STR | |
357 | OSPF6_STR | |
358 | "Inter Area topology information\n" | |
359 | ) | |
360 | { | |
361 | OSPF6_CMD_CHECK_RUNNING (); | |
362 | return ospf6_route_table_show (vty, argc, argv, ospf6->topology_table); | |
363 | } | |
364 | ||
365 | ALIAS (show_ipv6_ospf6_topology, | |
366 | show_ipv6_ospf6_topology_router_cmd, | |
367 | "show ipv6 ospf6 topology (A.B.C.D|<0-4294967295>|detail)", | |
368 | SHOW_STR | |
369 | IP6_STR | |
370 | OSPF6_STR | |
371 | "Inter Area topology information\n" | |
372 | OSPF6_ROUTER_ID_STR | |
373 | OSPF6_ROUTER_ID_STR | |
374 | "Detailed information\n" | |
375 | ) | |
376 | ||
377 | ALIAS (show_ipv6_ospf6_topology, | |
378 | show_ipv6_ospf6_topology_router_lsid_cmd, | |
379 | "show ipv6 ospf6 topology (A.B.C.D|<0-4294967295>) (A.B.C.D|<0-4294967295>)", | |
380 | SHOW_STR | |
381 | IP6_STR | |
382 | OSPF6_STR | |
383 | "Inter Area topology information\n" | |
384 | OSPF6_ROUTER_ID_STR | |
385 | OSPF6_ROUTER_ID_STR | |
386 | OSPF6_LS_ID_STR | |
387 | OSPF6_LS_ID_STR | |
388 | ) | |
389 | ||
390 | void | |
391 | ospf6_top_init () | |
392 | { | |
393 | install_element (VIEW_NODE, &show_ipv6_ospf6_route_cmd); | |
394 | install_element (VIEW_NODE, &show_ipv6_ospf6_route_prefix_cmd); | |
395 | install_element (VIEW_NODE, &show_ipv6_ospf6_topology_cmd); | |
396 | install_element (VIEW_NODE, &show_ipv6_ospf6_topology_router_cmd); | |
397 | install_element (VIEW_NODE, &show_ipv6_ospf6_topology_router_lsid_cmd); | |
398 | install_element (ENABLE_NODE, &show_ipv6_ospf6_route_cmd); | |
399 | install_element (ENABLE_NODE, &show_ipv6_ospf6_route_prefix_cmd); | |
400 | install_element (ENABLE_NODE, &show_ipv6_ospf6_topology_cmd); | |
401 | install_element (ENABLE_NODE, &show_ipv6_ospf6_topology_router_cmd); | |
402 | install_element (ENABLE_NODE, &show_ipv6_ospf6_topology_router_lsid_cmd); | |
403 | } | |
404 |