ospf6_spf.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  1. /*
  2. * Copyright (C) 2003 Yasuhiro Ohara
  3. *
  4. * This file is part of GNU Zebra.
  5. *
  6. * GNU Zebra is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2, or (at your option) any
  9. * later version.
  10. *
  11. * GNU Zebra is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with GNU Zebra; see the file COPYING. If not, write to the
  18. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19. * Boston, MA 02111-1307, USA.
  20. */
  21. /* Shortest Path First calculation for OSPFv3 */
  22. #include <zebra.h>
  23. #include "log.h"
  24. #include "memory.h"
  25. #include "command.h"
  26. #include "vty.h"
  27. #include "prefix.h"
  28. #include "pqueue.h"
  29. #include "linklist.h"
  30. #include "thread.h"
  31. #include "ospf6_lsa.h"
  32. #include "ospf6_lsdb.h"
  33. #include "ospf6_route.h"
  34. #include "ospf6_area.h"
  35. #include "ospf6_spf.h"
  36. #include "ospf6_intra.h"
  37. #include "ospf6_interface.h"
  38. #include "ospf6d.h"
  39. unsigned char conf_debug_ospf6_spf = 0;
  40. int
  41. ospf6_vertex_cmp (void *a, void *b)
  42. {
  43. struct ospf6_vertex *va = (struct ospf6_vertex *) a;
  44. struct ospf6_vertex *vb = (struct ospf6_vertex *) b;
  45. /* ascending order */
  46. return (va->cost - vb->cost);
  47. }
  48. int
  49. ospf6_vertex_id_cmp (void *a, void *b)
  50. {
  51. struct ospf6_vertex *va = (struct ospf6_vertex *) a;
  52. struct ospf6_vertex *vb = (struct ospf6_vertex *) b;
  53. int ret = 0;
  54. ret = ntohl (ospf6_linkstate_prefix_adv_router (&va->vertex_id)) -
  55. ntohl (ospf6_linkstate_prefix_adv_router (&vb->vertex_id));
  56. if (ret)
  57. return ret;
  58. ret = ntohl (ospf6_linkstate_prefix_id (&va->vertex_id)) -
  59. ntohl (ospf6_linkstate_prefix_id (&vb->vertex_id));
  60. return ret;
  61. }
  62. struct ospf6_vertex *
  63. ospf6_vertex_create (struct ospf6_lsa *lsa)
  64. {
  65. struct ospf6_vertex *v;
  66. int i;
  67. v = (struct ospf6_vertex *)
  68. XMALLOC (MTYPE_OSPF6_VERTEX, sizeof (struct ospf6_vertex));
  69. /* type */
  70. if (ntohs (lsa->header->type) == OSPF6_LSTYPE_ROUTER)
  71. v->type = OSPF6_VERTEX_TYPE_ROUTER;
  72. else if (ntohs (lsa->header->type) == OSPF6_LSTYPE_NETWORK)
  73. v->type = OSPF6_VERTEX_TYPE_NETWORK;
  74. else
  75. assert (0);
  76. /* vertex_id */
  77. ospf6_linkstate_prefix (lsa->header->adv_router, lsa->header->id,
  78. &v->vertex_id);
  79. /* name */
  80. ospf6_linkstate_prefix2str (&v->vertex_id, v->name, sizeof (v->name));
  81. /* Associated LSA */
  82. v->lsa = lsa;
  83. /* capability bits + options */
  84. v->capability = *(u_char *)(OSPF6_LSA_HEADER_END (lsa->header));
  85. v->options[0] = *(u_char *)(OSPF6_LSA_HEADER_END (lsa->header) + 1);
  86. v->options[1] = *(u_char *)(OSPF6_LSA_HEADER_END (lsa->header) + 2);
  87. v->options[2] = *(u_char *)(OSPF6_LSA_HEADER_END (lsa->header) + 3);
  88. for (i = 0; i < OSPF6_MULTI_PATH_LIMIT; i++)
  89. ospf6_nexthop_clear (&v->nexthop[i]);
  90. v->parent = NULL;
  91. v->child_list = list_new ();
  92. v->child_list->cmp = ospf6_vertex_id_cmp;
  93. return v;
  94. }
  95. void
  96. ospf6_vertex_delete (struct ospf6_vertex *v)
  97. {
  98. list_delete (v->child_list);
  99. XFREE (MTYPE_OSPF6_VERTEX, v);
  100. }
  101. struct ospf6_lsa *
  102. ospf6_lsdesc_lsa (caddr_t lsdesc, struct ospf6_vertex *v)
  103. {
  104. struct ospf6_lsa *lsa;
  105. u_int16_t type = 0;
  106. u_int32_t id = 0, adv_router = 0;
  107. if (VERTEX_IS_TYPE (NETWORK, v))
  108. {
  109. type = htons (OSPF6_LSTYPE_ROUTER);
  110. id = htonl (0);
  111. adv_router = NETWORK_LSDESC_GET_NBR_ROUTERID (lsdesc);
  112. }
  113. else
  114. {
  115. if (ROUTER_LSDESC_IS_TYPE (POINTTOPOINT, lsdesc))
  116. {
  117. type = htons (OSPF6_LSTYPE_ROUTER);
  118. id = htonl (0);
  119. adv_router = ROUTER_LSDESC_GET_NBR_ROUTERID (lsdesc);
  120. }
  121. else if (ROUTER_LSDESC_IS_TYPE (TRANSIT_NETWORK, lsdesc))
  122. {
  123. type = htons (OSPF6_LSTYPE_NETWORK);
  124. id = htonl (ROUTER_LSDESC_GET_NBR_IFID (lsdesc));
  125. adv_router = ROUTER_LSDESC_GET_NBR_ROUTERID (lsdesc);
  126. }
  127. }
  128. lsa = ospf6_lsdb_lookup (type, id, adv_router, v->area->lsdb);
  129. if (IS_OSPF6_DEBUG_SPF (PROCESS))
  130. {
  131. char ibuf[16], abuf[16];
  132. inet_ntop (AF_INET, &id, ibuf, sizeof (ibuf));
  133. inet_ntop (AF_INET, &adv_router, abuf, sizeof (abuf));
  134. if (lsa)
  135. zlog_info (" Link to: %s", lsa->name);
  136. else
  137. zlog_info (" Link to: [%s Id:%s Adv:%s] No LSA",
  138. ospf6_lstype_name (type), ibuf, abuf);
  139. }
  140. return lsa;
  141. }
  142. char *
  143. ospf6_lsdesc_backlink (struct ospf6_lsa *lsa,
  144. caddr_t lsdesc, struct ospf6_vertex *v)
  145. {
  146. caddr_t backlink, found = NULL;
  147. int size;
  148. size = (OSPF6_LSA_IS_TYPE (ROUTER, lsa) ?
  149. sizeof (struct ospf6_router_lsdesc) :
  150. sizeof (struct ospf6_network_lsdesc));
  151. for (backlink = OSPF6_LSA_HEADER_END (lsa->header) + 4;
  152. backlink + size <= OSPF6_LSA_END (lsa->header); backlink += size)
  153. {
  154. assert (! (OSPF6_LSA_IS_TYPE (NETWORK, lsa) &&
  155. VERTEX_IS_TYPE (NETWORK, v)));
  156. if (OSPF6_LSA_IS_TYPE (NETWORK, lsa) &&
  157. NETWORK_LSDESC_GET_NBR_ROUTERID (backlink)
  158. == v->lsa->header->adv_router)
  159. found = backlink;
  160. else if (VERTEX_IS_TYPE (NETWORK, v) &&
  161. ROUTER_LSDESC_IS_TYPE (TRANSIT_NETWORK, backlink) &&
  162. ROUTER_LSDESC_GET_NBR_ROUTERID (backlink)
  163. == v->lsa->header->adv_router &&
  164. ROUTER_LSDESC_GET_NBR_IFID (backlink)
  165. == ntohl (v->lsa->header->id))
  166. found = backlink;
  167. else
  168. {
  169. if (! ROUTER_LSDESC_IS_TYPE (POINTTOPOINT, backlink) ||
  170. ! ROUTER_LSDESC_IS_TYPE (POINTTOPOINT, lsdesc))
  171. continue;
  172. if (ROUTER_LSDESC_GET_NBR_IFID (backlink) !=
  173. ROUTER_LSDESC_GET_IFID (lsdesc) ||
  174. ROUTER_LSDESC_GET_NBR_IFID (lsdesc) !=
  175. ROUTER_LSDESC_GET_IFID (backlink))
  176. continue;
  177. if (ROUTER_LSDESC_GET_NBR_ROUTERID (backlink) !=
  178. v->lsa->header->adv_router ||
  179. ROUTER_LSDESC_GET_NBR_ROUTERID (lsdesc) !=
  180. lsa->header->adv_router)
  181. continue;
  182. found = backlink;
  183. }
  184. }
  185. if (IS_OSPF6_DEBUG_SPF (PROCESS))
  186. zlog_info (" Backlink %s", (found ? "OK" : "FAIL"));
  187. return found;
  188. }
  189. void
  190. ospf6_nexthop_calc (struct ospf6_vertex *w, struct ospf6_vertex *v,
  191. caddr_t lsdesc)
  192. {
  193. int i, ifindex;
  194. struct ospf6_interface *oi;
  195. u_int16_t type;
  196. u_int32_t adv_router;
  197. struct ospf6_lsa *lsa;
  198. struct ospf6_link_lsa *link_lsa;
  199. char buf[64];
  200. assert (VERTEX_IS_TYPE (ROUTER, w));
  201. ifindex = (VERTEX_IS_TYPE (NETWORK, v) ? v->nexthop[0].ifindex :
  202. ROUTER_LSDESC_GET_IFID (lsdesc));
  203. oi = ospf6_interface_lookup_by_ifindex (ifindex);
  204. if (oi == NULL)
  205. {
  206. if (IS_OSPF6_DEBUG_SPF (PROCESS))
  207. zlog_warn ("Can't find interface in SPF: ifindex %d", ifindex);
  208. return;
  209. }
  210. type = htons (OSPF6_LSTYPE_LINK);
  211. adv_router = (VERTEX_IS_TYPE (NETWORK, v) ?
  212. NETWORK_LSDESC_GET_NBR_ROUTERID (lsdesc) :
  213. ROUTER_LSDESC_GET_NBR_ROUTERID (lsdesc));
  214. i = 0;
  215. for (lsa = ospf6_lsdb_type_router_head (type, adv_router, oi->lsdb); lsa;
  216. lsa = ospf6_lsdb_type_router_next (type, adv_router, lsa))
  217. {
  218. if (VERTEX_IS_TYPE (ROUTER, v) &&
  219. htonl (ROUTER_LSDESC_GET_NBR_IFID (lsdesc)) != lsa->header->id)
  220. continue;
  221. link_lsa = (struct ospf6_link_lsa *) OSPF6_LSA_HEADER_END (lsa->header);
  222. if (IS_OSPF6_DEBUG_SPF (PROCESS))
  223. {
  224. inet_ntop (AF_INET6, &link_lsa->linklocal_addr, buf, sizeof (buf));
  225. zlog_info (" nexthop %s from %s", buf, lsa->name);
  226. }
  227. if (i < OSPF6_MULTI_PATH_LIMIT)
  228. {
  229. memcpy (&w->nexthop[i].address, &link_lsa->linklocal_addr,
  230. sizeof (struct in6_addr));
  231. w->nexthop[i].ifindex = ifindex;
  232. i++;
  233. }
  234. }
  235. if (i == 0 && IS_OSPF6_DEBUG_SPF (PROCESS))
  236. zlog_info ("No nexthop for %s found", w->name);
  237. }
  238. int
  239. ospf6_spf_install (struct ospf6_vertex *v,
  240. struct ospf6_route_table *result_table)
  241. {
  242. struct ospf6_route *route;
  243. int i, j;
  244. struct ospf6_vertex *prev, *w;
  245. struct listnode *node;
  246. if (IS_OSPF6_DEBUG_SPF (PROCESS))
  247. zlog_info ("SPF install %s hops %d cost %d",
  248. v->name, v->hops, v->cost);
  249. route = ospf6_route_lookup (&v->vertex_id, result_table);
  250. if (route && route->path.cost < v->cost)
  251. {
  252. if (IS_OSPF6_DEBUG_SPF (PROCESS))
  253. zlog_info (" already installed with lower cost (%d), ignore",
  254. route->path.cost);
  255. ospf6_vertex_delete (v);
  256. return -1;
  257. }
  258. else if (route && route->path.cost == v->cost)
  259. {
  260. if (IS_OSPF6_DEBUG_SPF (PROCESS))
  261. zlog_info (" another path found, merge");
  262. for (i = 0; ospf6_nexthop_is_set (&v->nexthop[i]) &&
  263. i < OSPF6_MULTI_PATH_LIMIT; i++)
  264. {
  265. for (j = 0; j < OSPF6_MULTI_PATH_LIMIT; j++)
  266. {
  267. if (ospf6_nexthop_is_set (&route->nexthop[j]))
  268. {
  269. if (ospf6_nexthop_is_same (&route->nexthop[j],
  270. &v->nexthop[i]))
  271. break;
  272. else
  273. continue;
  274. }
  275. ospf6_nexthop_copy (&route->nexthop[j], &v->nexthop[i]);
  276. break;
  277. }
  278. }
  279. prev = (struct ospf6_vertex *) route->route_option;
  280. if (prev->hops > v->hops)
  281. {
  282. LIST_LOOP (prev->child_list, w, node)
  283. {
  284. assert (w->parent == prev);
  285. w->parent = v;
  286. listnode_add_sort (v->child_list, w);
  287. }
  288. listnode_delete (prev->parent->child_list, prev);
  289. listnode_add_sort (v->parent->child_list, v);
  290. ospf6_vertex_delete (prev);
  291. route->route_option = v;
  292. }
  293. else
  294. ospf6_vertex_delete (v);
  295. return -1;
  296. }
  297. /* There should be no case where candidate being installed (variable
  298. "v") is closer than the one in the SPF tree (variable "route").
  299. In the case something has gone wrong with the behavior of
  300. Priority-Queue. */
  301. /* the case where the route exists already is handled and returned
  302. up to here. */
  303. assert (route == NULL);
  304. route = ospf6_route_create ();
  305. memcpy (&route->prefix, &v->vertex_id, sizeof (struct prefix));
  306. route->type = OSPF6_DEST_TYPE_LINKSTATE;
  307. route->path.type = OSPF6_PATH_TYPE_INTRA;
  308. route->path.origin.type = v->lsa->header->type;
  309. route->path.origin.id = v->lsa->header->id;
  310. route->path.origin.adv_router = v->lsa->header->adv_router;
  311. route->path.metric_type = 1;
  312. route->path.cost = v->cost;
  313. route->path.cost_e2 = v->hops;
  314. route->path.router_bits = v->capability;
  315. route->path.options[0] = v->options[0];
  316. route->path.options[1] = v->options[1];
  317. route->path.options[2] = v->options[2];
  318. for (i = 0; ospf6_nexthop_is_set (&v->nexthop[i]) &&
  319. i < OSPF6_MULTI_PATH_LIMIT; i++)
  320. ospf6_nexthop_copy (&route->nexthop[i], &v->nexthop[i]);
  321. if (v->parent)
  322. listnode_add_sort (v->parent->child_list, v);
  323. route->route_option = v;
  324. ospf6_route_add (route, result_table);
  325. return 0;
  326. }
  327. void
  328. ospf6_spf_table_finish (struct ospf6_route_table *result_table)
  329. {
  330. struct ospf6_route *route;
  331. struct ospf6_vertex *v;
  332. for (route = ospf6_route_head (result_table); route;
  333. route = ospf6_route_next (route))
  334. {
  335. v = (struct ospf6_vertex *) route->route_option;
  336. ospf6_vertex_delete (v);
  337. ospf6_route_remove (route, result_table);
  338. }
  339. }
  340. /* RFC2328 16.1. Calculating the shortest-path tree for an area */
  341. /* RFC2740 3.8.1. Calculating the shortest path tree for an area */
  342. void
  343. ospf6_spf_calculation (u_int32_t router_id,
  344. struct ospf6_route_table *result_table,
  345. struct ospf6_area *oa)
  346. {
  347. struct pqueue *candidate_list;
  348. struct ospf6_vertex *root, *v, *w;
  349. int i;
  350. int size;
  351. caddr_t lsdesc;
  352. struct ospf6_lsa *lsa;
  353. /* initialize */
  354. candidate_list = pqueue_create ();
  355. candidate_list->cmp = ospf6_vertex_cmp;
  356. ospf6_spf_table_finish (result_table);
  357. /* Install the calculating router itself as the root of the SPF tree */
  358. /* construct root vertex */
  359. lsa = ospf6_lsdb_lookup (htons (OSPF6_LSTYPE_ROUTER), htonl (0),
  360. router_id, oa->lsdb);
  361. if (lsa == NULL)
  362. return;
  363. root = ospf6_vertex_create (lsa);
  364. root->area = oa;
  365. root->cost = 0;
  366. root->hops = 0;
  367. root->nexthop[0].ifindex = 0; /* loopbak I/F is better ... */
  368. inet_pton (AF_INET6, "::1", &root->nexthop[0].address);
  369. /* Actually insert root to the candidate-list as the only candidate */
  370. pqueue_enqueue (root, candidate_list);
  371. /* Iterate until candidate-list becomes empty */
  372. while (candidate_list->size)
  373. {
  374. /* get closest candidate from priority queue */
  375. v = pqueue_dequeue (candidate_list);
  376. /* installing may result in merging or rejecting of the vertex */
  377. if (ospf6_spf_install (v, result_table) < 0)
  378. continue;
  379. /* For each LS description in the just-added vertex V's LSA */
  380. size = (VERTEX_IS_TYPE (ROUTER, v) ?
  381. sizeof (struct ospf6_router_lsdesc) :
  382. sizeof (struct ospf6_network_lsdesc));
  383. for (lsdesc = OSPF6_LSA_HEADER_END (v->lsa->header) + 4;
  384. lsdesc + size <= OSPF6_LSA_END (v->lsa->header); lsdesc += size)
  385. {
  386. lsa = ospf6_lsdesc_lsa (lsdesc, v);
  387. if (lsa == NULL)
  388. continue;
  389. if (! ospf6_lsdesc_backlink (lsa, lsdesc, v))
  390. continue;
  391. w = ospf6_vertex_create (lsa);
  392. w->area = oa;
  393. w->parent = v;
  394. if (VERTEX_IS_TYPE (ROUTER, v))
  395. {
  396. w->cost = v->cost + ROUTER_LSDESC_GET_METRIC (lsdesc);
  397. w->hops = v->hops + (VERTEX_IS_TYPE (NETWORK, w) ? 0 : 1);
  398. }
  399. else /* NETWORK */
  400. {
  401. w->cost = v->cost;
  402. w->hops = v->hops + 1;
  403. }
  404. /* nexthop calculation */
  405. if (w->hops == 0)
  406. w->nexthop[0].ifindex = ROUTER_LSDESC_GET_IFID (lsdesc);
  407. else if (w->hops == 1 && v->hops == 0)
  408. ospf6_nexthop_calc (w, v, lsdesc);
  409. else
  410. {
  411. for (i = 0; ospf6_nexthop_is_set (&v->nexthop[i]) &&
  412. i < OSPF6_MULTI_PATH_LIMIT; i++)
  413. ospf6_nexthop_copy (&w->nexthop[i], &v->nexthop[i]);
  414. }
  415. /* add new candidate to the candidate_list */
  416. if (IS_OSPF6_DEBUG_SPF (PROCESS))
  417. zlog_info (" New candidate: %s hops %d cost %d",
  418. w->name, w->hops, w->cost);
  419. pqueue_enqueue (w, candidate_list);
  420. }
  421. }
  422. pqueue_delete (candidate_list);
  423. }
  424. void
  425. ospf6_spf_log_database (struct ospf6_area *oa)
  426. {
  427. char *p, *end, buffer[256];
  428. struct listnode *node;
  429. struct ospf6_interface *oi;
  430. p = buffer;
  431. end = buffer + sizeof (buffer);
  432. snprintf (p, end - p, "SPF on DB (#LSAs):");
  433. p = (buffer + strlen (buffer) < end ? buffer + strlen (buffer) : end);
  434. snprintf (p, end - p, " Area %s: %d", oa->name, oa->lsdb->count);
  435. p = (buffer + strlen (buffer) < end ? buffer + strlen (buffer) : end);
  436. for (node = listhead (oa->if_list); node; nextnode (node))
  437. {
  438. oi = (struct ospf6_interface *) getdata (node);
  439. snprintf (p, end - p, " I/F %s: %d",
  440. oi->interface->name, oi->lsdb->count);
  441. p = (buffer + strlen (buffer) < end ? buffer + strlen (buffer) : end);
  442. }
  443. zlog_info ("%s", buffer);
  444. }
  445. int
  446. ospf6_spf_calculation_thread (struct thread *t)
  447. {
  448. struct ospf6_area *oa;
  449. struct timeval start, end, runtime;
  450. oa = (struct ospf6_area *) THREAD_ARG (t);
  451. oa->thread_spf_calculation = NULL;
  452. if (IS_OSPF6_DEBUG_SPF (PROCESS))
  453. zlog_info ("SPF calculation for Area %s", oa->name);
  454. if (IS_OSPF6_DEBUG_SPF (DATABASE))
  455. ospf6_spf_log_database (oa);
  456. /* execute SPF calculation */
  457. gettimeofday (&start, (struct timezone *) NULL);
  458. ospf6_spf_calculation (oa->ospf6->router_id, oa->spf_table, oa);
  459. gettimeofday (&end, (struct timezone *) NULL);
  460. timersub (&end, &start, &runtime);
  461. if (IS_OSPF6_DEBUG_SPF (PROCESS) || IS_OSPF6_DEBUG_SPF (TIME))
  462. zlog_info ("SPF runtime: %ld sec %ld usec",
  463. runtime.tv_sec, runtime.tv_usec);
  464. ospf6_intra_route_calculation (oa);
  465. ospf6_intra_brouter_calculation (oa);
  466. return 0;
  467. }
  468. void
  469. ospf6_spf_schedule (struct ospf6_area *oa)
  470. {
  471. if (oa->thread_spf_calculation)
  472. return;
  473. oa->thread_spf_calculation =
  474. thread_add_event (master, ospf6_spf_calculation_thread, oa, 0);
  475. }
  476. void
  477. ospf6_spf_display_subtree (struct vty *vty, const char *prefix, int rest,
  478. struct ospf6_vertex *v)
  479. {
  480. struct listnode *node;
  481. struct ospf6_vertex *c;
  482. char *next_prefix;
  483. int len;
  484. int restnum;
  485. /* "prefix" is the space prefix of the display line */
  486. vty_out (vty, "%s+-%s [%d]%s", prefix, v->name, v->cost, VNL);
  487. len = strlen (prefix) + 4;
  488. next_prefix = (char *) malloc (len);
  489. if (next_prefix == NULL)
  490. {
  491. vty_out (vty, "malloc failed%s", VNL);
  492. return;
  493. }
  494. snprintf (next_prefix, len, "%s%s", prefix, (rest ? "| " : " "));
  495. restnum = listcount (v->child_list);
  496. LIST_LOOP (v->child_list, c, node)
  497. {
  498. restnum--;
  499. ospf6_spf_display_subtree (vty, next_prefix, restnum, c);
  500. }
  501. free (next_prefix);
  502. }
  503. DEFUN (debug_ospf6_spf_process,
  504. debug_ospf6_spf_process_cmd,
  505. "debug ospf6 spf process",
  506. DEBUG_STR
  507. OSPF6_STR
  508. "Debug SPF Calculation\n"
  509. "Debug Detailed SPF Process\n"
  510. )
  511. {
  512. unsigned char level = 0;
  513. level = OSPF6_DEBUG_SPF_PROCESS;
  514. OSPF6_DEBUG_SPF_ON (level);
  515. return CMD_SUCCESS;
  516. }
  517. DEFUN (debug_ospf6_spf_time,
  518. debug_ospf6_spf_time_cmd,
  519. "debug ospf6 spf time",
  520. DEBUG_STR
  521. OSPF6_STR
  522. "Debug SPF Calculation\n"
  523. "Measure time taken by SPF Calculation\n"
  524. )
  525. {
  526. unsigned char level = 0;
  527. level = OSPF6_DEBUG_SPF_TIME;
  528. OSPF6_DEBUG_SPF_ON (level);
  529. return CMD_SUCCESS;
  530. }
  531. DEFUN (debug_ospf6_spf_database,
  532. debug_ospf6_spf_database_cmd,
  533. "debug ospf6 spf database",
  534. DEBUG_STR
  535. OSPF6_STR
  536. "Debug SPF Calculation\n"
  537. "Log number of LSAs at SPF Calculation time\n"
  538. )
  539. {
  540. unsigned char level = 0;
  541. level = OSPF6_DEBUG_SPF_DATABASE;
  542. OSPF6_DEBUG_SPF_ON (level);
  543. return CMD_SUCCESS;
  544. }
  545. DEFUN (no_debug_ospf6_spf_process,
  546. no_debug_ospf6_spf_process_cmd,
  547. "no debug ospf6 spf process",
  548. NO_STR
  549. DEBUG_STR
  550. OSPF6_STR
  551. "Quit Debugging SPF Calculation\n"
  552. "Quit Debugging Detailed SPF Process\n"
  553. )
  554. {
  555. unsigned char level = 0;
  556. level = OSPF6_DEBUG_SPF_PROCESS;
  557. OSPF6_DEBUG_SPF_OFF (level);
  558. return CMD_SUCCESS;
  559. }
  560. DEFUN (no_debug_ospf6_spf_time,
  561. no_debug_ospf6_spf_time_cmd,
  562. "no debug ospf6 spf time",
  563. NO_STR
  564. DEBUG_STR
  565. OSPF6_STR
  566. "Quit Debugging SPF Calculation\n"
  567. "Quit Measuring time taken by SPF Calculation\n"
  568. )
  569. {
  570. unsigned char level = 0;
  571. level = OSPF6_DEBUG_SPF_TIME;
  572. OSPF6_DEBUG_SPF_OFF (level);
  573. return CMD_SUCCESS;
  574. }
  575. DEFUN (no_debug_ospf6_spf_database,
  576. no_debug_ospf6_spf_database_cmd,
  577. "no debug ospf6 spf database",
  578. NO_STR
  579. DEBUG_STR
  580. OSPF6_STR
  581. "Debug SPF Calculation\n"
  582. "Quit Logging number of LSAs at SPF Calculation time\n"
  583. )
  584. {
  585. unsigned char level = 0;
  586. level = OSPF6_DEBUG_SPF_DATABASE;
  587. OSPF6_DEBUG_SPF_OFF (level);
  588. return CMD_SUCCESS;
  589. }
  590. int
  591. config_write_ospf6_debug_spf (struct vty *vty)
  592. {
  593. if (IS_OSPF6_DEBUG_SPF (PROCESS))
  594. vty_out (vty, "debug ospf6 spf process%s", VNL);
  595. if (IS_OSPF6_DEBUG_SPF (TIME))
  596. vty_out (vty, "debug ospf6 spf time%s", VNL);
  597. if (IS_OSPF6_DEBUG_SPF (DATABASE))
  598. vty_out (vty, "debug ospf6 spf database%s", VNL);
  599. return 0;
  600. }
  601. void
  602. install_element_ospf6_debug_spf ()
  603. {
  604. install_element (ENABLE_NODE, &debug_ospf6_spf_process_cmd);
  605. install_element (ENABLE_NODE, &debug_ospf6_spf_time_cmd);
  606. install_element (ENABLE_NODE, &debug_ospf6_spf_database_cmd);
  607. install_element (ENABLE_NODE, &no_debug_ospf6_spf_process_cmd);
  608. install_element (ENABLE_NODE, &no_debug_ospf6_spf_time_cmd);
  609. install_element (ENABLE_NODE, &no_debug_ospf6_spf_database_cmd);
  610. install_element (CONFIG_NODE, &debug_ospf6_spf_process_cmd);
  611. install_element (CONFIG_NODE, &debug_ospf6_spf_time_cmd);
  612. install_element (CONFIG_NODE, &debug_ospf6_spf_database_cmd);
  613. install_element (CONFIG_NODE, &no_debug_ospf6_spf_process_cmd);
  614. install_element (CONFIG_NODE, &no_debug_ospf6_spf_time_cmd);
  615. install_element (CONFIG_NODE, &no_debug_ospf6_spf_database_cmd);
  616. }
  617. void
  618. ospf6_spf_init ()
  619. {
  620. }