ospf6_top.c 11 KB

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