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