jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1 | /* |
| 2 | * IS-IS Rout(e)ing protocol - isis_spf.c |
| 3 | * The SPT algorithm |
| 4 | * |
| 5 | * Copyright (C) 2001,2002 Sampo Saaristo |
| 6 | * Tampere University of Technology |
| 7 | * Institute of Communications Engineering |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify it |
| 10 | * under the terms of the GNU General Public Licenseas published by the Free |
| 11 | * Software Foundation; either version 2 of the License, or (at your option) |
| 12 | * any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful,but WITHOUT |
| 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 17 | * more details. |
| 18 | |
| 19 | * You should have received a copy of the GNU General Public License along |
| 20 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 21 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 22 | */ |
| 23 | |
| 24 | #include <stdlib.h> |
| 25 | #include <stdio.h> |
| 26 | #include <zebra.h> |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 27 | |
| 28 | #include "thread.h" |
| 29 | #include "linklist.h" |
| 30 | #include "vty.h" |
| 31 | #include "log.h" |
| 32 | #include "command.h" |
| 33 | #include "memory.h" |
| 34 | #include "prefix.h" |
| 35 | #include "hash.h" |
| 36 | #include "if.h" |
| 37 | #include "table.h" |
| 38 | |
| 39 | #include "isis_constants.h" |
| 40 | #include "isis_common.h" |
| 41 | #include "dict.h" |
| 42 | #include "isisd.h" |
| 43 | #include "isis_misc.h" |
| 44 | #include "isis_adjacency.h" |
| 45 | #include "isis_circuit.h" |
| 46 | #include "isis_tlv.h" |
| 47 | #include "isis_pdu.h" |
| 48 | #include "isis_lsp.h" |
| 49 | #include "isis_dynhn.h" |
| 50 | #include "isis_spf.h" |
| 51 | #include "isis_route.h" |
| 52 | #include "isis_csm.h" |
| 53 | |
| 54 | extern struct isis *isis; |
| 55 | extern struct thread_master *master; |
| 56 | extern struct host host; |
| 57 | |
| 58 | int isis_run_spf_l1 (struct thread *thread); |
| 59 | int isis_run_spf_l2 (struct thread *thread); |
| 60 | |
| 61 | /* performace issue ???? */ |
| 62 | void |
| 63 | union_adjlist( struct list *target, struct list *source ) |
| 64 | { |
| 65 | struct isis_adjacency *adj, *adj2; |
| 66 | struct listnode *node, *node2; |
| 67 | |
| 68 | zlog_info ("Union adjlist!"); |
| 69 | for (node = listhead (source); node; nextnode (node)) { |
| 70 | adj = getdata (node); |
| 71 | |
| 72 | /* lookup adjacency in the source list */ |
| 73 | for (node2 = listhead (target); node2; nextnode (node2)) { |
| 74 | adj2 = getdata(node2); |
| 75 | if (adj == adj2) break; |
| 76 | } |
| 77 | |
| 78 | if (!node2) listnode_add (target, adj); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | |
| 83 | /* 7.2.7 */ |
| 84 | void |
| 85 | remove_excess_adjs (struct list *adjs) |
| 86 | { |
| 87 | struct listnode *node, *excess = NULL; |
| 88 | struct isis_adjacency *adj, *candidate = NULL; |
| 89 | int comp; |
| 90 | |
| 91 | for (node = listhead (adjs); node; nextnode (node)) { |
| 92 | if (excess == NULL) |
| 93 | excess = node; |
| 94 | candidate = getdata (excess); |
| 95 | adj = getdata (node); |
| 96 | if (candidate->sys_type < adj->sys_type) { |
| 97 | excess = node; |
| 98 | candidate = adj; |
| 99 | continue; |
| 100 | } |
| 101 | if (candidate->sys_type > adj->sys_type) |
| 102 | continue; |
| 103 | |
| 104 | comp = memcmp (candidate->sysid, adj->sysid, ISIS_SYS_ID_LEN); |
| 105 | if (comp > 0) { |
| 106 | excess = node; |
| 107 | candidate = adj; |
| 108 | continue; |
| 109 | } |
| 110 | if (comp < 0) |
| 111 | continue; |
| 112 | |
| 113 | if (candidate->circuit->circuit_id > adj->circuit->circuit_id) { |
| 114 | excess = node; |
| 115 | candidate = adj; |
| 116 | continue; |
| 117 | } |
| 118 | |
| 119 | if (candidate->circuit->circuit_id < adj->circuit->circuit_id) |
| 120 | continue; |
| 121 | |
| 122 | comp = memcmp (candidate->snpa, adj->snpa, ETH_ALEN); |
| 123 | if (comp > 0) { |
| 124 | excess = node; |
| 125 | candidate = adj; |
| 126 | continue; |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | list_delete_node (adjs, excess); |
| 131 | |
| 132 | return; |
| 133 | } |
| 134 | |
| 135 | const char * |
| 136 | vtype2string (enum vertextype vtype) |
| 137 | { |
| 138 | switch (vtype) { |
| 139 | case VTYPE_PSEUDO_IS: |
| 140 | return "pseudo_IS"; |
| 141 | break; |
| 142 | case VTYPE_NONPSEUDO_IS: |
| 143 | return "IS"; |
| 144 | break; |
| 145 | case VTYPE_ES: |
| 146 | return "ES"; |
| 147 | break; |
| 148 | case VTYPE_IPREACH_INTERNAL: |
| 149 | return "IP internal"; |
| 150 | break; |
| 151 | case VTYPE_IPREACH_EXTERNAL: |
| 152 | return "IP external"; |
| 153 | break; |
| 154 | #ifdef HAVE_IPV6 |
| 155 | case VTYPE_IP6REACH_INTERNAL: |
| 156 | return "IP6 internal"; |
| 157 | break; |
| 158 | case VTYPE_IP6REACH_EXTERNAL: |
| 159 | return "IP6 external"; |
| 160 | break; |
| 161 | #endif /* HAVE_IPV6 */ |
| 162 | default: |
| 163 | return "UNKNOWN"; |
| 164 | } |
| 165 | return NULL; /* Not reached */ |
| 166 | } |
| 167 | |
| 168 | char * |
| 169 | vid2string (struct isis_vertex *vertex, u_char *buff) |
| 170 | { |
| 171 | switch (vertex->type) { |
| 172 | case VTYPE_PSEUDO_IS: |
| 173 | return rawlspid_print (vertex->N.id); |
| 174 | break; |
| 175 | case VTYPE_NONPSEUDO_IS: |
| 176 | case VTYPE_ES: |
| 177 | return sysid_print (vertex->N.id); |
| 178 | break; |
| 179 | case VTYPE_IPREACH_INTERNAL: |
| 180 | case VTYPE_IPREACH_EXTERNAL: |
| 181 | #ifdef HAVE_IPV6 |
| 182 | case VTYPE_IP6REACH_INTERNAL: |
| 183 | case VTYPE_IP6REACH_EXTERNAL: |
| 184 | #endif /* HAVE_IPV6 */ |
| 185 | prefix2str ((struct prefix *)&vertex->N.prefix, buff, BUFSIZ); |
| 186 | break; |
| 187 | default: |
| 188 | return "UNKNOWN"; |
| 189 | } |
| 190 | |
| 191 | return buff; |
| 192 | } |
| 193 | |
| 194 | struct isis_spftree * |
| 195 | isis_spftree_new () |
| 196 | { |
| 197 | struct isis_spftree *tree; |
| 198 | |
| 199 | tree = XMALLOC (MTYPE_ISIS_SPFTREE, sizeof (struct isis_spftree)); |
| 200 | if (tree == NULL) { |
| 201 | zlog_err ("ISIS-Spf: isis_spftree_new Out of memory!"); |
| 202 | return NULL; |
| 203 | } |
| 204 | memset (tree, 0, sizeof (struct isis_spftree)); |
| 205 | |
| 206 | tree->tents = list_new (); |
| 207 | tree->paths = list_new (); |
| 208 | return tree; |
| 209 | } |
| 210 | |
| 211 | void |
| 212 | isis_vertex_del (struct isis_vertex *vertex) |
| 213 | { |
| 214 | |
| 215 | list_delete (vertex->Adj_N); |
| 216 | |
| 217 | XFREE (MTYPE_ISIS_VERTEX, vertex); |
| 218 | |
| 219 | return; |
| 220 | } |
| 221 | |
| 222 | void |
| 223 | isis_spftree_del (struct isis_spftree *spftree) |
| 224 | { |
| 225 | |
| 226 | spftree->tents->del = (void *)isis_vertex_del; |
| 227 | list_delete (spftree->tents); |
| 228 | |
| 229 | spftree->paths->del = (void *)isis_vertex_del; |
| 230 | list_delete (spftree->paths); |
| 231 | |
| 232 | XFREE (MTYPE_ISIS_SPFTREE, spftree); |
| 233 | |
| 234 | return; |
| 235 | } |
| 236 | |
| 237 | void |
| 238 | spftree_area_init (struct isis_area *area) |
| 239 | { |
| 240 | |
| 241 | if ((area->is_type & IS_LEVEL_1) && area->spftree[0] == NULL) { |
| 242 | area->spftree[0] = isis_spftree_new (); |
| 243 | #ifdef HAVE_IPV6 |
| 244 | area->spftree6[0] = isis_spftree_new (); |
| 245 | #endif |
| 246 | |
| 247 | /* thread_add_timer (master, isis_run_spf_l1, area, |
| 248 | isis_jitter (PERIODIC_SPF_INTERVAL, 10)); */ |
| 249 | } |
| 250 | |
| 251 | if ((area->is_type & IS_LEVEL_2) && area->spftree[1] == NULL) { |
| 252 | area->spftree[1] = isis_spftree_new (); |
| 253 | #ifdef HAVE_IPV6 |
| 254 | area->spftree6[1] = isis_spftree_new (); |
| 255 | #endif |
| 256 | /* thread_add_timer (master, isis_run_spf_l2, area, |
| 257 | isis_jitter (PERIODIC_SPF_INTERVAL, 10)); */ |
| 258 | } |
| 259 | |
| 260 | return; |
| 261 | } |
| 262 | |
| 263 | struct isis_vertex * |
| 264 | isis_vertex_new (void *id, enum vertextype vtype) |
| 265 | { |
| 266 | struct isis_vertex *vertex; |
| 267 | |
| 268 | vertex = XMALLOC (MTYPE_ISIS_VERTEX, sizeof (struct isis_vertex)); |
| 269 | if (vertex == NULL) { |
| 270 | zlog_err ("isis_vertex_new Out of memory!"); |
| 271 | return NULL; |
| 272 | } |
| 273 | |
| 274 | memset (vertex, 0, sizeof (struct isis_vertex)); |
| 275 | vertex->type = vtype; |
| 276 | switch (vtype) { |
| 277 | case VTYPE_ES: |
| 278 | case VTYPE_NONPSEUDO_IS: |
| 279 | memcpy (vertex->N.id, (u_char *)id, ISIS_SYS_ID_LEN); |
| 280 | break; |
| 281 | case VTYPE_PSEUDO_IS: |
| 282 | memcpy (vertex->N.id, (u_char *)id, ISIS_SYS_ID_LEN + 1); |
| 283 | break; |
| 284 | case VTYPE_IPREACH_INTERNAL: |
| 285 | case VTYPE_IPREACH_EXTERNAL: |
| 286 | #ifdef HAVE_IPV6 |
| 287 | case VTYPE_IP6REACH_INTERNAL: |
| 288 | case VTYPE_IP6REACH_EXTERNAL: |
| 289 | #endif /* HAVE_IPV6 */ |
| 290 | memcpy (&vertex->N.prefix, (struct prefix *)id, |
| 291 | sizeof (struct prefix)); |
| 292 | break; |
| 293 | default: |
| 294 | zlog_err ("WTF!"); |
| 295 | } |
| 296 | |
| 297 | vertex->Adj_N = list_new (); |
| 298 | |
| 299 | return vertex; |
| 300 | } |
| 301 | |
| 302 | /* |
| 303 | * Add this IS to the root of SPT |
| 304 | */ |
| 305 | void |
| 306 | isis_spf_add_self (struct isis_spftree *spftree, struct isis_area *area, |
| 307 | int level) |
| 308 | { |
| 309 | struct isis_vertex *vertex; |
| 310 | struct isis_lsp *lsp; |
| 311 | u_char lspid[ISIS_SYS_ID_LEN + 2]; |
| 312 | #ifdef EXTREME_DEBUG |
| 313 | u_char buff[BUFSIZ]; |
| 314 | #endif /* EXTREME_DEBUG */ |
| 315 | memcpy (lspid, isis->sysid, ISIS_SYS_ID_LEN); |
| 316 | LSP_PSEUDO_ID(lspid) = 0; |
| 317 | LSP_FRAGMENT(lspid) = 0; |
| 318 | |
| 319 | lsp = lsp_search (lspid, area->lspdb[level - 1]); |
| 320 | |
| 321 | if (lsp == NULL) |
| 322 | zlog_warn ("ISIS-Spf: could not find own l%d LSP!", level); |
| 323 | |
| 324 | vertex = isis_vertex_new (isis->sysid, VTYPE_NONPSEUDO_IS); |
| 325 | vertex->lsp = lsp; |
| 326 | |
| 327 | listnode_add (spftree->paths, vertex); |
| 328 | |
| 329 | #ifdef EXTREME_DEBUG |
| 330 | zlog_info ("ISIS-Spf: added this IS %s %s depth %d dist %d to PATHS", |
| 331 | vtype2string(vertex->type), vid2string(vertex, buff), |
| 332 | vertex->depth, vertex->d_N); |
| 333 | #endif /* EXTREME_DEBUG */ |
| 334 | |
| 335 | return; |
| 336 | } |
| 337 | |
| 338 | struct isis_vertex * |
| 339 | isis_find_vertex (struct list *list, void *id, enum vertextype vtype) |
| 340 | { |
| 341 | struct listnode *node; |
| 342 | struct isis_vertex *vertex; |
| 343 | struct prefix *p1, *p2; |
| 344 | |
| 345 | for (node = listhead (list); node; nextnode (node)) { |
| 346 | vertex = getdata (node); |
| 347 | if (vertex->type != vtype) |
| 348 | continue; |
| 349 | switch (vtype) { |
| 350 | case VTYPE_ES: |
| 351 | case VTYPE_NONPSEUDO_IS: |
| 352 | if (memcmp ((u_char *)id, vertex->N.id, ISIS_SYS_ID_LEN) == 0) |
| 353 | return vertex; |
| 354 | break; |
| 355 | case VTYPE_PSEUDO_IS: |
| 356 | if (memcmp ((u_char *)id, vertex->N.id, ISIS_SYS_ID_LEN + 1) == 0) |
| 357 | return vertex; |
| 358 | break; |
| 359 | case VTYPE_IPREACH_INTERNAL: |
| 360 | case VTYPE_IPREACH_EXTERNAL: |
| 361 | #ifdef HAVE_IPV6 |
| 362 | case VTYPE_IP6REACH_INTERNAL: |
| 363 | case VTYPE_IP6REACH_EXTERNAL: |
| 364 | #endif /* HAVE_IPV6 */ |
| 365 | p1 = (struct prefix *)id; |
| 366 | p2 = (struct prefix *)&vertex->N.id; |
| 367 | if (p1->family == p2->family && p1->prefixlen == p2->prefixlen && |
| 368 | memcmp (&p1->u.prefix, &p2->u.prefix, PSIZE (p1->prefixlen)) == 0) |
| 369 | return vertex; |
| 370 | break; |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | return NULL; |
| 375 | } |
| 376 | |
| 377 | |
| 378 | |
| 379 | /* |
| 380 | * Add a vertex to TENT sorted by cost and by vertextype on tie break situation |
| 381 | */ |
| 382 | struct isis_vertex * |
| 383 | isis_spf_add2tent (struct isis_spftree *spftree, enum vertextype vtype, |
| 384 | void *id, struct isis_adjacency *adj, u_int16_t cost, |
| 385 | int depth, int family) |
| 386 | { |
| 387 | struct isis_vertex *vertex, *v; |
| 388 | struct listnode *node; |
| 389 | #ifdef EXTREME_DEBUG |
| 390 | u_char buff[BUFSIZ]; |
| 391 | #endif |
| 392 | |
| 393 | vertex = isis_vertex_new (id, vtype); |
| 394 | vertex->d_N = cost; |
| 395 | vertex->depth = depth; |
| 396 | |
| 397 | if (adj) |
| 398 | listnode_add (vertex->Adj_N, adj); |
| 399 | #ifdef EXTREME_DEBUG |
| 400 | zlog_info ("ISIS-Spf: add to TENT %s %s depth %d dist %d", |
| 401 | vtype2string(vertex->type), vid2string(vertex, buff), |
| 402 | vertex->depth, vertex->d_N); |
| 403 | #endif /* EXTREME_DEBUG */ |
| 404 | listnode_add (spftree->tents, vertex); |
| 405 | if (list_isempty (spftree->tents)) { |
| 406 | listnode_add (spftree->tents, vertex); |
| 407 | return vertex; |
| 408 | } |
| 409 | for (node = listhead (spftree->tents); node; nextnode (node)) { |
| 410 | v = getdata (node); |
| 411 | if (v->d_N > vertex->d_N) { |
| 412 | list_add_node_prev (spftree->tents, node, vertex); |
| 413 | break; |
| 414 | } else if (v->d_N == vertex->d_N) { |
| 415 | /* Tie break, add according to type */ |
| 416 | while (v && v->d_N == vertex->d_N && v->type > vertex->type) { |
| 417 | if (v->type > vertex->type) { |
| 418 | break; |
| 419 | } |
| 420 | nextnode (node); |
| 421 | (node) ? (v = getdata (node)) : (v = NULL); |
| 422 | } |
| 423 | list_add_node_prev (spftree->tents, node, vertex); |
| 424 | break; |
| 425 | } else if (node->next == NULL) { |
| 426 | list_add_node_next (spftree->tents, node, vertex); |
| 427 | break; |
| 428 | } |
| 429 | } |
| 430 | return vertex; |
| 431 | } |
| 432 | |
| 433 | struct isis_vertex * |
| 434 | isis_spf_add_local (struct isis_spftree *spftree, enum vertextype vtype, |
| 435 | void *id, struct isis_adjacency *adj, u_int16_t cost, |
| 436 | int family) |
| 437 | { |
| 438 | struct isis_vertex *vertex; |
| 439 | |
| 440 | vertex = isis_find_vertex (spftree->tents, id, vtype); |
| 441 | |
| 442 | if (vertex) { |
| 443 | /* C.2.5 c) */ |
| 444 | if (vertex->d_N == cost) { |
| 445 | if (adj) |
| 446 | listnode_add (vertex->Adj_N, adj); |
| 447 | /* d) */ |
| 448 | if (listcount (vertex->Adj_N) > ISIS_MAX_PATH_SPLITS) |
| 449 | remove_excess_adjs (vertex->Adj_N); |
| 450 | } |
| 451 | /* f) */ |
| 452 | else if (vertex->d_N > cost) { |
| 453 | listnode_delete (spftree->tents, vertex); |
| 454 | goto add2tent; |
| 455 | } |
| 456 | /* e) do nothing */ |
| 457 | return vertex; |
| 458 | } |
| 459 | |
| 460 | add2tent: |
| 461 | return isis_spf_add2tent (spftree, vtype, id, adj, cost, 1, family); |
| 462 | } |
| 463 | |
| 464 | void |
| 465 | process_N (struct isis_spftree *spftree, enum vertextype vtype, void *id, |
| 466 | u_int16_t dist, u_int16_t depth, struct isis_adjacency *adj, |
| 467 | int family) |
| 468 | { |
| 469 | struct isis_vertex *vertex; |
| 470 | #ifdef EXTREME_DEBUG |
| 471 | u_char buff[255]; |
| 472 | #endif |
| 473 | |
| 474 | /* C.2.6 b) */ |
| 475 | if (dist > MAX_PATH_METRIC) |
| 476 | return; |
| 477 | /* c) */ |
| 478 | vertex = isis_find_vertex (spftree->paths, id, vtype); |
| 479 | if (vertex) { |
| 480 | #ifdef EXTREME_DEBUG |
| 481 | zlog_info ("ISIS-Spf: process_N %s %s dist %d already found from PATH", |
| 482 | vtype2string(vtype), vid2string(vertex, buff), dist); |
| 483 | #endif /* EXTREME_DEBUG */ |
| 484 | assert (dist >= vertex->d_N); |
| 485 | return; |
| 486 | } |
| 487 | |
| 488 | vertex = isis_find_vertex (spftree->tents, id, vtype); |
| 489 | /* d) */ |
| 490 | if (vertex) { |
| 491 | /* 1) */ |
| 492 | #ifdef EXTREME_DEBUG |
| 493 | zlog_info ("ISIS-Spf: process_N %s %s dist %d", |
| 494 | vtype2string(vtype), vid2string(vertex, buff), dist); |
| 495 | #endif /* EXTREME_DEBUG */ |
| 496 | if (vertex->d_N == dist) { |
| 497 | if (adj) |
| 498 | listnode_add (vertex->Adj_N, adj); |
| 499 | /* 2) */ |
| 500 | if (listcount(vertex->Adj_N) > ISIS_MAX_PATH_SPLITS) |
| 501 | remove_excess_adjs (vertex->Adj_N); |
| 502 | /* 3) */ |
| 503 | return; |
| 504 | } else if (vertex->d_N < dist) { |
| 505 | return; |
| 506 | /* 4) */ |
| 507 | } else { |
| 508 | listnode_delete (spftree->tents, vertex); |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | isis_spf_add2tent (spftree, vtype, id, adj, dist, depth, family); |
| 513 | return; |
| 514 | } |
| 515 | |
| 516 | /* |
| 517 | * C.2.6 Step 1 |
| 518 | */ |
| 519 | int |
| 520 | isis_spf_process_lsp (struct isis_spftree *spftree, struct isis_lsp *lsp, |
| 521 | uint16_t cost, uint16_t depth, int family) |
| 522 | { |
| 523 | struct listnode *node, *fragnode = NULL; |
| 524 | u_int16_t dist; |
| 525 | struct is_neigh *is_neigh; |
| 526 | struct ipv4_reachability *ipreach; |
| 527 | enum vertextype vtype; |
| 528 | struct prefix prefix; |
| 529 | #ifdef HAVE_IPV6 |
| 530 | struct ipv6_reachability *ip6reach; |
| 531 | #endif /* HAVE_IPV6 */ |
| 532 | |
| 533 | |
| 534 | if (!lsp->adj) |
| 535 | return ISIS_WARNING; |
| 536 | if (lsp->tlv_data.nlpids == NULL || |
| 537 | !speaks (lsp->tlv_data.nlpids, family)) |
| 538 | return ISIS_OK; |
| 539 | |
| 540 | lspfragloop: |
| 541 | if (lsp->lsp_header->seq_num == 0) { |
| 542 | zlog_warn ("isis_spf_process_lsp(): lsp with 0 seq_num" |
| 543 | " - do not process"); |
| 544 | return ISIS_WARNING; |
| 545 | } |
| 546 | |
| 547 | if (!ISIS_MASK_LSP_OL_BIT(lsp->lsp_header->lsp_bits)) { |
| 548 | if (lsp->tlv_data.is_neighs) { |
| 549 | for (node = listhead (lsp->tlv_data.is_neighs); node; nextnode (node)) { |
| 550 | is_neigh = getdata (node); |
| 551 | /* C.2.6 a) */ |
| 552 | /* Two way connectivity */ |
| 553 | if (!memcmp (is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN)) |
| 554 | continue; |
| 555 | dist = cost + is_neigh->metrics.metric_default; |
| 556 | vtype = LSP_PSEUDO_ID(is_neigh->neigh_id) ? VTYPE_PSEUDO_IS |
| 557 | : VTYPE_NONPSEUDO_IS; |
| 558 | process_N (spftree, vtype, (void *)is_neigh->neigh_id, dist, depth+1, |
| 559 | lsp->adj, family); |
| 560 | } |
| 561 | } |
| 562 | if (family == AF_INET && lsp->tlv_data.ipv4_int_reachs) { |
| 563 | prefix.family = AF_INET; |
| 564 | for (node = listhead (lsp->tlv_data.ipv4_int_reachs); node; |
| 565 | nextnode (node)) { |
| 566 | ipreach = getdata (node); |
| 567 | dist = cost + ipreach->metrics.metric_default; |
| 568 | vtype = VTYPE_IPREACH_INTERNAL; |
| 569 | prefix.u.prefix4 = ipreach->prefix; |
| 570 | prefix.prefixlen = ip_masklen (ipreach->mask); |
| 571 | process_N (spftree, vtype, (void *)&prefix, dist, depth + 1, |
| 572 | lsp->adj, family); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | if (family == AF_INET && lsp->tlv_data.ipv4_ext_reachs) { |
| 577 | prefix.family = AF_INET; |
| 578 | for (node = listhead (lsp->tlv_data.ipv4_ext_reachs); node; |
| 579 | nextnode (node)) { |
| 580 | ipreach = getdata (node); |
| 581 | dist = cost + ipreach->metrics.metric_default; |
| 582 | vtype = VTYPE_IPREACH_EXTERNAL; |
| 583 | prefix.u.prefix4 = ipreach->prefix; |
| 584 | prefix.prefixlen = ip_masklen (ipreach->mask); |
| 585 | process_N (spftree, vtype, (void *)&prefix, dist, depth + 1, |
| 586 | lsp->adj, family); |
| 587 | } |
| 588 | } |
| 589 | #ifdef HAVE_IPV6 |
| 590 | if (family == AF_INET6 && lsp->tlv_data.ipv6_reachs) { |
| 591 | prefix.family = AF_INET6; |
| 592 | for (node = listhead (lsp->tlv_data.ipv6_reachs); node; |
| 593 | nextnode (node)) { |
| 594 | ip6reach = getdata (node); |
| 595 | dist = cost + ip6reach->metric; |
| 596 | vtype = (ip6reach->control_info & CTRL_INFO_DISTRIBUTION) ? |
| 597 | VTYPE_IP6REACH_EXTERNAL : VTYPE_IP6REACH_INTERNAL; |
| 598 | prefix.prefixlen = ip6reach->prefix_len; |
| 599 | memcpy (&prefix.u.prefix6.s6_addr, ip6reach->prefix, |
| 600 | PSIZE(ip6reach->prefix_len)); |
| 601 | process_N (spftree, vtype, (void *)&prefix, dist, depth + 1, |
| 602 | lsp->adj, family); |
| 603 | } |
| 604 | } |
| 605 | #endif /* HAVE_IPV6 */ |
| 606 | } |
| 607 | |
| 608 | if (fragnode == NULL) |
| 609 | fragnode = listhead (lsp->lspu.frags); |
| 610 | else |
| 611 | fragnode = nextnode (fragnode); |
| 612 | |
| 613 | if (fragnode) { |
| 614 | lsp = getdata (fragnode); |
| 615 | goto lspfragloop; |
| 616 | } |
| 617 | |
| 618 | return ISIS_OK; |
| 619 | } |
| 620 | |
| 621 | int |
| 622 | isis_spf_process_pseudo_lsp (struct isis_spftree *spftree,struct isis_lsp *lsp, |
| 623 | uint16_t cost, uint16_t depth, int family) |
| 624 | { |
| 625 | struct listnode *node, *fragnode = NULL; |
| 626 | struct is_neigh *is_neigh; |
| 627 | enum vertextype vtype; |
| 628 | |
| 629 | pseudofragloop: |
| 630 | |
| 631 | if (lsp->lsp_header->seq_num == 0) { |
| 632 | zlog_warn ("isis_spf_process_pseudo_lsp(): lsp with 0 seq_num" |
| 633 | " - do not process"); |
| 634 | return ISIS_WARNING; |
| 635 | } |
| 636 | |
| 637 | for (node = (lsp->tlv_data.is_neighs ? |
| 638 | listhead (lsp->tlv_data.is_neighs) : NULL); |
| 639 | node; nextnode (node)) { |
| 640 | is_neigh = getdata (node); |
| 641 | vtype = LSP_PSEUDO_ID(is_neigh->neigh_id) ? VTYPE_PSEUDO_IS |
| 642 | : VTYPE_NONPSEUDO_IS; |
| 643 | /* Two way connectivity */ |
| 644 | if (!memcmp (is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN)) |
| 645 | continue; |
| 646 | if (isis_find_vertex (spftree->tents, (void *)is_neigh->neigh_id, vtype) |
| 647 | == NULL && |
| 648 | isis_find_vertex (spftree->paths, (void *)is_neigh->neigh_id, vtype) |
| 649 | == NULL) { |
| 650 | /* C.2.5 i) */ |
| 651 | isis_spf_add2tent (spftree, vtype, is_neigh->neigh_id, lsp->adj, |
| 652 | cost, depth, family); |
| 653 | } |
| 654 | } |
| 655 | |
| 656 | if (fragnode == NULL) |
| 657 | fragnode = listhead (lsp->lspu.frags); |
| 658 | else |
| 659 | fragnode = nextnode (fragnode); |
| 660 | |
| 661 | if (fragnode) { |
| 662 | lsp = getdata (fragnode); |
| 663 | goto pseudofragloop; |
| 664 | } |
| 665 | |
| 666 | |
| 667 | return ISIS_OK; |
| 668 | } |
| 669 | |
| 670 | int |
| 671 | isis_spf_preload_tent (struct isis_spftree *spftree, |
| 672 | struct isis_area *area, int level, int family) |
| 673 | { |
| 674 | struct isis_vertex *vertex; |
| 675 | struct isis_circuit *circuit; |
| 676 | struct listnode *cnode, *anode, *ipnode; |
| 677 | struct isis_adjacency *adj; |
| 678 | struct isis_lsp *lsp; |
| 679 | struct list *adj_list; |
| 680 | struct list *adjdb; |
| 681 | struct prefix_ipv4 *ipv4; |
| 682 | struct prefix prefix; |
| 683 | int retval = ISIS_OK; |
| 684 | u_char lsp_id[ISIS_SYS_ID_LEN + 2]; |
| 685 | #ifdef HAVE_IPV6 |
| 686 | struct prefix_ipv6 *ipv6; |
| 687 | #endif /* HAVE_IPV6 */ |
| 688 | |
| 689 | for (cnode = listhead (area->circuit_list); cnode; nextnode (cnode)) { |
| 690 | circuit = getdata (cnode); |
| 691 | if (circuit->state != C_STATE_UP) |
| 692 | continue; |
| 693 | if (!(circuit->circuit_is_type & level)) |
| 694 | continue; |
| 695 | if (family == AF_INET && !circuit->ip_router) |
| 696 | continue; |
| 697 | #ifdef HAVE_IPV6 |
| 698 | if (family == AF_INET6 && !circuit->ipv6_router) |
| 699 | continue; |
| 700 | #endif /* HAVE_IPV6 */ |
| 701 | /* |
| 702 | * Add IP(v6) addresses of this circuit |
| 703 | */ |
| 704 | if (family == AF_INET) { |
| 705 | prefix.family = AF_INET; |
| 706 | for (ipnode = (circuit->ip_addrs ? listhead (circuit->ip_addrs) : NULL); |
| 707 | ipnode; nextnode (ipnode)) { |
| 708 | ipv4 = getdata (ipnode); |
| 709 | prefix.u.prefix4 = ipv4->prefix; |
| 710 | prefix.prefixlen = ipv4->prefixlen; |
| 711 | isis_spf_add_local (spftree, VTYPE_IPREACH_INTERNAL, &prefix, NULL, 0, |
| 712 | family); |
| 713 | } |
| 714 | } |
| 715 | #ifdef HAVE_IPV6 |
| 716 | if (family == AF_INET6) { |
| 717 | prefix.family = AF_INET6; |
| 718 | for (ipnode = (circuit->ipv6_non_link ? listhead |
| 719 | (circuit->ipv6_non_link) : NULL); ipnode; |
| 720 | nextnode (ipnode)) { |
| 721 | ipv6 = getdata (ipnode); |
| 722 | prefix.prefixlen = ipv6->prefixlen; |
| 723 | prefix.u.prefix6 = ipv6->prefix; |
| 724 | isis_spf_add_local (spftree, VTYPE_IP6REACH_INTERNAL, |
| 725 | &prefix, NULL, 0, family); |
| 726 | } |
| 727 | } |
| 728 | #endif /* HAVE_IPV6 */ |
| 729 | if (circuit->circ_type == CIRCUIT_T_BROADCAST ) { |
| 730 | /* |
| 731 | * Add the adjacencies |
| 732 | */ |
| 733 | adj_list = list_new (); |
| 734 | adjdb = circuit->u.bc.adjdb[level - 1]; |
| 735 | isis_adj_build_up_list (adjdb, adj_list); |
| 736 | if (listcount (adj_list) == 0) { |
| 737 | list_delete (adj_list); |
| 738 | zlog_warn ("ISIS-Spf: no L%d adjacencies on circuit %s", |
| 739 | level, circuit->interface->name); |
| 740 | continue; |
| 741 | } |
| 742 | anode = listhead (adj_list); |
| 743 | while (anode) { |
| 744 | adj = getdata (anode); |
hasso | 2097cd8 | 2003-12-23 11:51:08 +0000 | [diff] [blame] | 745 | if (!speaks (&adj->nlpids, family)) { |
| 746 | anode = nextnode (anode); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 747 | continue; |
hasso | 2097cd8 | 2003-12-23 11:51:08 +0000 | [diff] [blame] | 748 | } |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 749 | switch (adj->sys_type) { |
| 750 | case ISIS_SYSTYPE_ES: |
| 751 | isis_spf_add_local (spftree, VTYPE_ES, adj->sysid, adj, |
| 752 | circuit->metrics[level - 1].metric_default, |
| 753 | family); |
| 754 | break; |
| 755 | case ISIS_SYSTYPE_IS: |
| 756 | case ISIS_SYSTYPE_L1_IS: |
| 757 | case ISIS_SYSTYPE_L2_IS: |
| 758 | vertex = |
| 759 | isis_spf_add_local (spftree, VTYPE_NONPSEUDO_IS, |
| 760 | adj->sysid, adj, |
| 761 | circuit->metrics[level - 1].metric_default, |
| 762 | family); |
| 763 | memcpy (lsp_id, adj->sysid, ISIS_SYS_ID_LEN); |
| 764 | LSP_PSEUDO_ID(lsp_id) = 0; |
| 765 | LSP_FRAGMENT(lsp_id) = 0; |
| 766 | lsp = lsp_search (lsp_id, area->lspdb[level - 1]); |
| 767 | if (!lsp) |
| 768 | zlog_warn ("No lsp found for IS adjacency"); |
| 769 | /* else { |
| 770 | isis_spf_process_lsp (spftree, lsp, vertex->d_N, 1, family); |
| 771 | } */ |
| 772 | break; |
| 773 | case ISIS_SYSTYPE_UNKNOWN: |
| 774 | default: |
| 775 | zlog_warn ("isis_spf_preload_tent unknow adj type"); |
| 776 | } |
| 777 | anode = nextnode (anode); |
| 778 | } |
| 779 | list_delete (adj_list); |
| 780 | /* |
| 781 | * Add the pseudonode |
| 782 | */ |
| 783 | if (level == 1) |
| 784 | memcpy (lsp_id, circuit->u.bc.l1_desig_is, ISIS_SYS_ID_LEN + 1); |
| 785 | else |
| 786 | memcpy (lsp_id, circuit->u.bc.l2_desig_is, ISIS_SYS_ID_LEN + 1); |
| 787 | lsp = lsp_search (lsp_id, area->lspdb[level - 1]); |
| 788 | adj = isis_adj_lookup (lsp_id, adjdb); |
| 789 | /* if no adj, we are the dis or error */ |
| 790 | if (!adj && !circuit->u.bc.is_dr[level - 1]) { |
| 791 | zlog_warn ("ISIS-Spf: No adjacency found for DR"); |
| 792 | } |
| 793 | if (lsp == NULL || lsp->lsp_header->rem_lifetime == 0) { |
| 794 | zlog_warn ("ISIS-Spf: No lsp found for DR"); |
| 795 | } else { |
| 796 | isis_spf_process_pseudo_lsp |
| 797 | (spftree, lsp, circuit->metrics[level - 1].metric_default, 0, |
| 798 | family); |
| 799 | |
| 800 | } |
| 801 | } else if (circuit->circ_type == CIRCUIT_T_P2P ) { |
| 802 | adj = circuit->u.p2p.neighbor; |
| 803 | if (!adj) |
| 804 | continue; |
| 805 | switch (adj->sys_type) { |
| 806 | case ISIS_SYSTYPE_ES: |
| 807 | isis_spf_add_local (spftree, VTYPE_ES, adj->sysid, adj, |
| 808 | circuit->metrics[level - 1].metric_default, |
| 809 | family); |
| 810 | break; |
| 811 | case ISIS_SYSTYPE_IS: |
| 812 | case ISIS_SYSTYPE_L1_IS: |
| 813 | case ISIS_SYSTYPE_L2_IS: |
| 814 | if (speaks (&adj->nlpids, family)) |
| 815 | isis_spf_add_local (spftree, VTYPE_NONPSEUDO_IS, adj->sysid, adj, |
| 816 | circuit->metrics[level - 1].metric_default, |
| 817 | family); |
| 818 | break; |
| 819 | case ISIS_SYSTYPE_UNKNOWN: |
| 820 | default: |
| 821 | zlog_warn ("isis_spf_preload_tent unknow adj type"); |
| 822 | break; |
| 823 | } |
| 824 | } else { |
| 825 | zlog_warn ("isis_spf_preload_tent unsupported media"); |
| 826 | retval = ISIS_WARNING; |
| 827 | } |
| 828 | |
| 829 | } |
| 830 | |
| 831 | return retval; |
| 832 | } |
| 833 | |
| 834 | /* |
| 835 | * The parent(s) for vertex is set when added to TENT list |
| 836 | * now we just put the child pointer(s) in place |
| 837 | */ |
| 838 | void |
| 839 | add_to_paths (struct isis_spftree *spftree, struct isis_vertex *vertex, |
| 840 | struct isis_area *area) |
| 841 | { |
| 842 | |
| 843 | #ifdef EXTREME_DEBUG |
| 844 | u_char buff[BUFSIZ]; |
| 845 | #endif /* EXTREME_DEBUG */ |
| 846 | listnode_add (spftree->paths, vertex); |
| 847 | |
| 848 | #ifdef EXTREME_DEBUG |
| 849 | zlog_info ("ISIS-Spf: added %s %s depth %d dist %d to PATHS", |
| 850 | vtype2string(vertex->type), vid2string(vertex, buff), |
| 851 | vertex->depth, vertex->d_N); |
| 852 | #endif /* EXTREME_DEBUG */ |
| 853 | if (vertex->type > VTYPE_ES) { |
| 854 | if (listcount(vertex->Adj_N) > 0) |
| 855 | isis_route_create ((struct prefix *)&vertex->N.prefix, |
| 856 | vertex->d_N, vertex->depth, vertex->Adj_N, area); |
| 857 | else if (isis->debugs & DEBUG_SPF_EVENTS) |
| 858 | zlog_info ("ISIS-Spf: no adjacencies do not install route"); |
| 859 | } |
| 860 | |
| 861 | return; |
| 862 | } |
| 863 | |
| 864 | |
| 865 | void |
| 866 | init_spt (struct isis_spftree *spftree) |
| 867 | { |
| 868 | spftree->tents->del = spftree->paths->del = (void *)isis_vertex_del; |
| 869 | list_delete_all_node (spftree->tents); |
| 870 | list_delete_all_node (spftree->paths); |
| 871 | spftree->tents->del = spftree->paths->del = NULL; |
| 872 | |
| 873 | return; |
| 874 | } |
| 875 | |
| 876 | int |
| 877 | isis_run_spf (struct isis_area *area, int level, int family) |
| 878 | { |
| 879 | int retval = ISIS_OK; |
| 880 | struct listnode *node; |
| 881 | struct isis_vertex *vertex; |
| 882 | struct isis_spftree *spftree = NULL; |
| 883 | u_char lsp_id[ISIS_SYS_ID_LEN + 2]; |
| 884 | struct isis_lsp *lsp; |
| 885 | |
| 886 | if (family == AF_INET) |
| 887 | spftree = area->spftree[level - 1]; |
| 888 | #ifdef HAVE_IPV6 |
| 889 | else if (family == AF_INET6) |
| 890 | spftree = area->spftree6[level - 1]; |
| 891 | #endif |
| 892 | |
| 893 | assert (spftree); |
| 894 | |
| 895 | /* |
| 896 | * C.2.5 Step 0 |
| 897 | */ |
| 898 | init_spt (spftree); |
| 899 | /* a) */ |
| 900 | isis_spf_add_self (spftree, area, level); |
| 901 | /* b) */ |
| 902 | retval = isis_spf_preload_tent (spftree, area, level, family); |
| 903 | |
| 904 | /* |
| 905 | * C.2.7 Step 2 |
| 906 | */ |
| 907 | if (listcount (spftree->tents) == 0) { |
| 908 | zlog_warn ("ISIS-Spf: TENT is empty"); |
| 909 | spftree->lastrun = time (NULL); |
| 910 | return retval; |
| 911 | } |
| 912 | |
| 913 | while (listcount (spftree->tents) > 0) { |
| 914 | node = listhead (spftree->tents); |
| 915 | vertex = getdata (node); |
| 916 | /* Remove from tent list */ |
| 917 | list_delete_node (spftree->tents, node); |
| 918 | if (isis_find_vertex (spftree->paths, vertex->N.id, vertex->type)) |
| 919 | continue; |
| 920 | add_to_paths (spftree, vertex, area); |
| 921 | if (vertex->type == VTYPE_PSEUDO_IS || |
| 922 | vertex->type == VTYPE_NONPSEUDO_IS) { |
| 923 | memcpy (lsp_id, vertex->N.id, ISIS_SYS_ID_LEN + 1); |
| 924 | LSP_FRAGMENT(lsp_id) = 0; |
| 925 | lsp = lsp_search (lsp_id, area->lspdb[level - 1]); |
| 926 | if (lsp) { |
| 927 | if (LSP_PSEUDO_ID (lsp_id)) { |
| 928 | isis_spf_process_pseudo_lsp (spftree, lsp, vertex->d_N, |
| 929 | vertex->depth, family); |
| 930 | |
| 931 | } else { |
| 932 | isis_spf_process_lsp (spftree, lsp, vertex->d_N, vertex->depth, |
| 933 | family); |
| 934 | } |
| 935 | } else { |
| 936 | zlog_warn ("ISIS-Spf: No LSP found for %s", rawlspid_print (lsp_id)); |
| 937 | } |
| 938 | } |
| 939 | } |
| 940 | |
| 941 | thread_add_event (master, isis_route_validate, area, 0); |
| 942 | spftree->lastrun = time (NULL); |
| 943 | spftree->pending = 0; |
| 944 | |
| 945 | if (level == 1) |
hasso | d70f99e | 2004-02-11 20:26:31 +0000 | [diff] [blame] | 946 | THREAD_TIMER_ON(master, spftree->t_spf_periodic, isis_run_spf_l1, area, |
| 947 | isis_jitter(PERIODIC_SPF_INTERVAL, 10)); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 948 | else |
hasso | d70f99e | 2004-02-11 20:26:31 +0000 | [diff] [blame] | 949 | THREAD_TIMER_ON(master, spftree->t_spf_periodic, isis_run_spf_l2, area, |
| 950 | isis_jitter(PERIODIC_SPF_INTERVAL, 10)); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 951 | |
| 952 | return retval; |
| 953 | } |
| 954 | |
| 955 | int |
| 956 | isis_run_spf_l1 (struct thread *thread) |
| 957 | { |
| 958 | struct isis_area *area; |
| 959 | int retval = ISIS_OK; |
| 960 | |
| 961 | area = THREAD_ARG(thread); |
| 962 | assert (area); |
| 963 | |
| 964 | if (!(area->is_type & IS_LEVEL_1)) { |
| 965 | if (isis->debugs & DEBUG_SPF_EVENTS) { |
| 966 | zlog_warn ("ISIS-SPF (%s) area does not share level", area->area_tag); |
| 967 | } |
| 968 | return ISIS_WARNING; |
| 969 | } |
| 970 | |
| 971 | if (isis->debugs & DEBUG_SPF_EVENTS) { |
| 972 | zlog_info ("ISIS-Spf (%s) L1 SPF needed, periodic SPF", |
| 973 | area->area_tag); |
| 974 | } |
| 975 | |
| 976 | if (area->ip_circuits) |
| 977 | retval = isis_run_spf (area, 1, AF_INET); |
| 978 | #ifdef HAVE_IPV6 |
| 979 | if (area->ipv6_circuits) |
| 980 | retval = isis_run_spf (area, 1, AF_INET6); |
| 981 | #endif |
| 982 | return retval; |
| 983 | } |
| 984 | |
| 985 | int |
| 986 | isis_run_spf_l2 (struct thread *thread) |
| 987 | { |
| 988 | struct isis_area *area; |
| 989 | int retval = ISIS_OK; |
| 990 | |
| 991 | area = THREAD_ARG(thread); |
| 992 | assert (area); |
| 993 | |
| 994 | if (!(area->is_type & IS_LEVEL_2)) { |
| 995 | if (isis->debugs & DEBUG_SPF_EVENTS) { |
| 996 | zlog_warn ("ISIS-SPF (%s) area does not share level", area->area_tag); |
| 997 | } |
| 998 | return ISIS_WARNING; |
| 999 | } |
| 1000 | |
| 1001 | if (isis->debugs & DEBUG_SPF_EVENTS) { |
| 1002 | zlog_info ("ISIS-Spf (%s) L2 SPF needed, periodic SPF", |
| 1003 | area->area_tag); |
| 1004 | } |
| 1005 | |
| 1006 | if (area->ip_circuits) |
| 1007 | retval = isis_run_spf (area, 2, AF_INET); |
| 1008 | #ifdef HAVE_IPV6 |
| 1009 | if (area->ipv6_circuits) |
| 1010 | retval = isis_run_spf (area, 2, AF_INET6); |
| 1011 | #endif |
| 1012 | |
| 1013 | return retval; |
| 1014 | } |
| 1015 | |
| 1016 | int |
| 1017 | isis_spf_schedule (struct isis_area *area, int level) |
| 1018 | { |
| 1019 | int retval = ISIS_OK; |
| 1020 | struct isis_spftree *spftree = area->spftree[level - 1]; |
| 1021 | time_t diff, now = time (NULL); |
| 1022 | |
| 1023 | if (spftree->pending) |
| 1024 | return retval; |
| 1025 | |
| 1026 | diff = now - spftree->lastrun; |
| 1027 | |
| 1028 | /* FIXME: let's wait a minute before doing the SPF */ |
| 1029 | if (now - isis->uptime < 60 || isis->uptime == 0) { |
| 1030 | if (level == 1) |
| 1031 | thread_add_timer (master, isis_run_spf_l1, area, |
| 1032 | 60); |
| 1033 | else |
| 1034 | thread_add_timer (master, isis_run_spf_l2, area, |
| 1035 | 60); |
| 1036 | |
| 1037 | spftree->pending = 1; |
| 1038 | return retval; |
| 1039 | } |
hasso | 00995cf | 2004-05-19 13:43:50 +0000 | [diff] [blame^] | 1040 | /* FIXME: This stuff is just mess. All spf thread add/cancel |
| 1041 | logic should be reviewed. */ |
| 1042 | /* THREAD_TIMER_OFF(spftree->t_spf_periodic); */ |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1043 | |
| 1044 | if (diff < MINIMUM_SPF_INTERVAL) { |
| 1045 | if (level == 1) |
| 1046 | thread_add_timer (master, isis_run_spf_l1, area, |
| 1047 | MINIMUM_SPF_INTERVAL - diff); |
| 1048 | else |
| 1049 | thread_add_timer (master, isis_run_spf_l2, area, |
| 1050 | MINIMUM_SPF_INTERVAL - diff); |
| 1051 | |
| 1052 | spftree->pending = 1; |
| 1053 | } else { |
| 1054 | spftree->pending = 0; |
| 1055 | retval = isis_run_spf (area, level, AF_INET); |
| 1056 | } |
| 1057 | |
| 1058 | return retval; |
| 1059 | } |
| 1060 | |
| 1061 | #ifdef HAVE_IPV6 |
| 1062 | int |
| 1063 | isis_spf_schedule6 (struct isis_area *area, int level) |
| 1064 | { |
| 1065 | int retval = ISIS_OK; |
| 1066 | struct isis_spftree *spftree = area->spftree6[level - 1]; |
| 1067 | time_t diff, now = time (NULL); |
| 1068 | |
| 1069 | if (spftree->pending) |
| 1070 | return retval; |
| 1071 | |
| 1072 | diff = now - spftree->lastrun; |
| 1073 | |
hasso | d70f99e | 2004-02-11 20:26:31 +0000 | [diff] [blame] | 1074 | THREAD_TIMER_OFF(spftree->t_spf_periodic); |
jardin | eb5d44e | 2003-12-23 08:09:43 +0000 | [diff] [blame] | 1075 | |
| 1076 | /* FIXME: let's wait a minute before doing the SPF */ |
| 1077 | if (now - isis->uptime < 60 || isis->uptime == 0) { |
| 1078 | if (level == 1) |
| 1079 | thread_add_timer (master, isis_run_spf_l1, area, |
| 1080 | 60); |
| 1081 | else |
| 1082 | thread_add_timer (master, isis_run_spf_l2, area, |
| 1083 | 60); |
| 1084 | |
| 1085 | spftree->pending = 1; |
| 1086 | return retval; |
| 1087 | } |
| 1088 | |
| 1089 | |
| 1090 | if (diff < MINIMUM_SPF_INTERVAL) { |
| 1091 | if (level == 1) |
| 1092 | thread_add_timer (master, isis_run_spf_l1, area, |
| 1093 | MINIMUM_SPF_INTERVAL - diff); |
| 1094 | else |
| 1095 | thread_add_timer (master, isis_run_spf_l2, area, |
| 1096 | MINIMUM_SPF_INTERVAL - diff); |
| 1097 | |
| 1098 | spftree->pending = 1; |
| 1099 | } else { |
| 1100 | spftree->pending = 0; |
| 1101 | retval = isis_run_spf (area, level, AF_INET6); |
| 1102 | } |
| 1103 | |
| 1104 | return retval; |
| 1105 | } |
| 1106 | |
| 1107 | #endif |
| 1108 | |
| 1109 | void |
| 1110 | isis_print_paths (struct vty *vty, struct list *paths) |
| 1111 | { |
| 1112 | struct listnode *node, *anode; |
| 1113 | struct isis_vertex *vertex; |
| 1114 | struct isis_dynhn *dyn, *nh_dyn = NULL; |
| 1115 | struct isis_adjacency *adj; |
| 1116 | #ifdef EXTREME_DEBUG |
| 1117 | u_char buff[255]; |
| 1118 | #endif |
| 1119 | |
| 1120 | vty_out (vty, "System Id Metric Next-Hop" |
| 1121 | " Interface SNPA%s", VTY_NEWLINE); |
| 1122 | for (node = listhead (paths); node; nextnode (node)) { |
| 1123 | vertex = getdata (node); |
| 1124 | if (vertex->type != VTYPE_NONPSEUDO_IS) |
| 1125 | continue; |
| 1126 | if (memcmp (vertex->N.id, isis->sysid, ISIS_SYS_ID_LEN) == 0) { |
| 1127 | vty_out (vty, "%s --%s", host.name, VTY_NEWLINE); |
| 1128 | } else { |
| 1129 | dyn = dynhn_find_by_id ((u_char *)vertex->N.id); |
| 1130 | anode = listhead (vertex->Adj_N); |
| 1131 | adj = getdata (anode); |
| 1132 | if (adj) { |
| 1133 | nh_dyn = dynhn_find_by_id (adj->sysid); |
| 1134 | vty_out (vty, "%-20s %-10u %-20s %-11s %-5s%s", |
| 1135 | (dyn != NULL) ? dyn->name.name : |
| 1136 | (u_char *)rawlspid_print ((u_char *)vertex->N.id), |
| 1137 | vertex->d_N, (nh_dyn != NULL) ? nh_dyn->name.name : |
| 1138 | (u_char *)rawlspid_print (adj->sysid), |
| 1139 | adj->circuit->interface->name, |
| 1140 | snpa_print (adj->snpa), VTY_NEWLINE); |
| 1141 | } else { |
| 1142 | vty_out (vty, "%s %u %s", dyn ? dyn->name.name : |
| 1143 | (u_char *)rawlspid_print (vertex->N.id), |
| 1144 | vertex->d_N, VTY_NEWLINE); |
| 1145 | } |
| 1146 | |
| 1147 | } |
| 1148 | #if 0 |
| 1149 | vty_out (vty, "%s %s %u %s", vtype2string(vertex->type), |
| 1150 | vid2string(vertex, buff), vertex->d_N, VTY_NEWLINE); |
| 1151 | #endif |
| 1152 | } |
| 1153 | |
| 1154 | |
| 1155 | } |
| 1156 | |
| 1157 | DEFUN (show_isis_topology, |
| 1158 | show_isis_topology_cmd, |
| 1159 | "show isis topology", |
| 1160 | SHOW_STR |
| 1161 | "IS-IS information\n" |
| 1162 | "IS-IS paths to Intermediate Systems\n") |
| 1163 | { |
| 1164 | struct listnode *node; |
| 1165 | struct isis_area *area; |
| 1166 | int level; |
| 1167 | |
| 1168 | if (!isis->area_list || isis->area_list->count == 0) |
| 1169 | return CMD_SUCCESS; |
| 1170 | |
| 1171 | for (node = listhead (isis->area_list); node; nextnode (node)) { |
| 1172 | area = getdata (node); |
| 1173 | |
| 1174 | vty_out (vty, "Area %s:%s", area->area_tag ? area->area_tag : "null", |
| 1175 | VTY_NEWLINE); |
| 1176 | |
| 1177 | for (level=0; level < ISIS_LEVELS; level++) { |
| 1178 | if (area->ip_circuits > 0 && area->spftree[level] |
| 1179 | && area->spftree[level]->paths->count > 0) { |
| 1180 | vty_out (vty, "IS-IS paths to level-%d routers that speak IP%s", |
| 1181 | level+1, VTY_NEWLINE); |
| 1182 | isis_print_paths (vty, area->spftree[level]->paths); |
| 1183 | } |
| 1184 | #ifdef HAVE_IPV6 |
| 1185 | if (area->ipv6_circuits > 0 && area->spftree6[level] |
| 1186 | && area->spftree6[level]->paths->count > 0) { |
| 1187 | vty_out (vty, "IS-IS paths to level-%d routers that speak IPv6%s", |
| 1188 | level+1, VTY_NEWLINE); |
| 1189 | isis_print_paths (vty, area->spftree6[level]->paths); |
| 1190 | } |
| 1191 | #endif /* HAVE_IPV6 */ |
| 1192 | } |
| 1193 | } |
| 1194 | |
| 1195 | return CMD_SUCCESS; |
| 1196 | } |
| 1197 | |
| 1198 | |
| 1199 | DEFUN (show_isis_topology_l1, |
| 1200 | show_isis_topology_l1_cmd, |
| 1201 | "show isis topology level-1", |
| 1202 | SHOW_STR |
| 1203 | "IS-IS information\n" |
| 1204 | "IS-IS paths to Intermediate Systems\n" |
| 1205 | "Paths to all level-1 routers in the area\n") |
| 1206 | { |
| 1207 | struct listnode *node; |
| 1208 | struct isis_area *area; |
| 1209 | |
| 1210 | if (!isis->area_list || isis->area_list->count == 0) |
| 1211 | return CMD_SUCCESS; |
| 1212 | |
| 1213 | for (node = listhead (isis->area_list); node; nextnode (node)) { |
| 1214 | area = getdata (node); |
| 1215 | |
| 1216 | vty_out (vty, "Area %s:%s", area->area_tag ? area->area_tag : "null", |
| 1217 | VTY_NEWLINE); |
| 1218 | |
| 1219 | if (area->ip_circuits > 0 && area->spftree[0] |
| 1220 | && area->spftree[0]->paths->count > 0) { |
| 1221 | vty_out (vty, "IS-IS paths to level-1 routers that speak IP%s", |
| 1222 | VTY_NEWLINE); |
| 1223 | isis_print_paths (vty, area->spftree[0]->paths); |
| 1224 | } |
| 1225 | #ifdef HAVE_IPV6 |
| 1226 | if (area->ipv6_circuits > 0 && area->spftree6[0] |
| 1227 | && area->spftree6[0]->paths->count > 0) { |
| 1228 | vty_out (vty, "IS-IS paths to level-1 routers that speak IPv6%s", |
| 1229 | VTY_NEWLINE); |
| 1230 | isis_print_paths (vty, area->spftree6[0]->paths); |
| 1231 | } |
| 1232 | #endif /* HAVE_IPV6 */ |
| 1233 | } |
| 1234 | |
| 1235 | |
| 1236 | return CMD_SUCCESS; |
| 1237 | } |
| 1238 | |
| 1239 | DEFUN (show_isis_topology_l2, |
| 1240 | show_isis_topology_l2_cmd, |
| 1241 | "show isis topology level-2", |
| 1242 | SHOW_STR |
| 1243 | "IS-IS information\n" |
| 1244 | "IS-IS paths to Intermediate Systems\n" |
| 1245 | "Paths to all level-2 routers in the domain\n") |
| 1246 | { |
| 1247 | struct listnode *node; |
| 1248 | struct isis_area *area; |
| 1249 | |
| 1250 | if (!isis->area_list || isis->area_list->count == 0) |
| 1251 | return CMD_SUCCESS; |
| 1252 | |
| 1253 | for (node = listhead (isis->area_list); node; nextnode (node)) { |
| 1254 | area = getdata (node); |
| 1255 | |
| 1256 | vty_out (vty, "Area %s:%s", area->area_tag ? area->area_tag : "null", |
| 1257 | VTY_NEWLINE); |
| 1258 | |
| 1259 | if (area->ip_circuits > 0 && area->spftree[1] |
| 1260 | && area->spftree[1]->paths->count > 0) { |
| 1261 | vty_out (vty, "IS-IS paths to level-2 routers that speak IP%s", |
| 1262 | VTY_NEWLINE); |
| 1263 | isis_print_paths (vty, area->spftree[1]->paths); |
| 1264 | } |
| 1265 | #ifdef HAVE_IPV6 |
| 1266 | if (area->ipv6_circuits > 0 && area->spftree6[1] |
| 1267 | && area->spftree6[1]->paths->count > 0) { |
| 1268 | vty_out (vty, "IS-IS paths to level-2 routers that speak IPv6%s", |
| 1269 | VTY_NEWLINE); |
| 1270 | isis_print_paths (vty, area->spftree6[1]->paths); |
| 1271 | } |
| 1272 | #endif /* HAVE_IPV6 */ |
| 1273 | } |
| 1274 | |
| 1275 | |
| 1276 | return CMD_SUCCESS; |
| 1277 | } |
| 1278 | |
| 1279 | |
| 1280 | void |
| 1281 | isis_spf_cmds_init () |
| 1282 | { |
| 1283 | install_element (VIEW_NODE, &show_isis_topology_cmd); |
| 1284 | install_element (VIEW_NODE, &show_isis_topology_l1_cmd); |
| 1285 | install_element (VIEW_NODE, &show_isis_topology_l2_cmd); |
| 1286 | |
| 1287 | install_element (ENABLE_NODE, &show_isis_topology_cmd); |
| 1288 | install_element (ENABLE_NODE, &show_isis_topology_l1_cmd); |
| 1289 | install_element (ENABLE_NODE, &show_isis_topology_l2_cmd); |
| 1290 | } |