paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1 | /* |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2 | * Copyright (C) 2003 Yasuhiro Ohara |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3 | * |
| 4 | * This file is part of GNU Zebra. |
| 5 | * |
| 6 | * GNU Zebra is free software; you can redistribute it and/or modify it |
| 7 | * under the terms of the GNU General Public License as published by the |
| 8 | * Free Software Foundation; either version 2, or (at your option) any |
| 9 | * later version. |
| 10 | * |
| 11 | * GNU Zebra is distributed in the hope that it will be useful, but |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with GNU Zebra; see the file COPYING. If not, write to the |
| 18 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 19 | * Boston, MA 02111-1307, USA. |
| 20 | */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 21 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 22 | /* Shortest Path First calculation for OSPFv3 */ |
| 23 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 24 | #include <zebra.h> |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 25 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 26 | #include "log.h" |
| 27 | #include "memory.h" |
| 28 | #include "command.h" |
| 29 | #include "vty.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 30 | #include "prefix.h" |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 31 | #include "pqueue.h" |
| 32 | #include "linklist.h" |
| 33 | #include "thread.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 34 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 35 | #include "ospf6_lsa.h" |
| 36 | #include "ospf6_lsdb.h" |
| 37 | #include "ospf6_route.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 38 | #include "ospf6_area.h" |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 39 | #include "ospf6_spf.h" |
| 40 | #include "ospf6_intra.h" |
| 41 | #include "ospf6_interface.h" |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 42 | #include "ospf6d.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 43 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 44 | unsigned char conf_debug_ospf6_spf = 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 45 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 46 | static int |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 47 | ospf6_vertex_cmp (void *a, void *b) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 48 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 49 | struct ospf6_vertex *va = (struct ospf6_vertex *) a; |
| 50 | struct ospf6_vertex *vb = (struct ospf6_vertex *) b; |
| 51 | |
| 52 | /* ascending order */ |
Dmitrij Tejblum | 403138e | 2011-01-13 18:25:40 +0300 | [diff] [blame] | 53 | if (va->cost != vb->cost) |
| 54 | return (va->cost - vb->cost); |
| 55 | return (va->hops - vb->hops); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 56 | } |
| 57 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 58 | static int |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 59 | ospf6_vertex_id_cmp (void *a, void *b) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 60 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 61 | struct ospf6_vertex *va = (struct ospf6_vertex *) a; |
| 62 | struct ospf6_vertex *vb = (struct ospf6_vertex *) b; |
| 63 | int ret = 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 64 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 65 | ret = ntohl (ospf6_linkstate_prefix_adv_router (&va->vertex_id)) - |
| 66 | ntohl (ospf6_linkstate_prefix_adv_router (&vb->vertex_id)); |
| 67 | if (ret) |
| 68 | return ret; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 69 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 70 | ret = ntohl (ospf6_linkstate_prefix_id (&va->vertex_id)) - |
| 71 | ntohl (ospf6_linkstate_prefix_id (&vb->vertex_id)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 72 | return ret; |
| 73 | } |
| 74 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 75 | static struct ospf6_vertex * |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 76 | ospf6_vertex_create (struct ospf6_lsa *lsa) |
| 77 | { |
| 78 | struct ospf6_vertex *v; |
| 79 | int i; |
| 80 | |
| 81 | v = (struct ospf6_vertex *) |
| 82 | XMALLOC (MTYPE_OSPF6_VERTEX, sizeof (struct ospf6_vertex)); |
| 83 | |
| 84 | /* type */ |
| 85 | if (ntohs (lsa->header->type) == OSPF6_LSTYPE_ROUTER) |
| 86 | v->type = OSPF6_VERTEX_TYPE_ROUTER; |
| 87 | else if (ntohs (lsa->header->type) == OSPF6_LSTYPE_NETWORK) |
| 88 | v->type = OSPF6_VERTEX_TYPE_NETWORK; |
| 89 | else |
| 90 | assert (0); |
| 91 | |
| 92 | /* vertex_id */ |
| 93 | ospf6_linkstate_prefix (lsa->header->adv_router, lsa->header->id, |
| 94 | &v->vertex_id); |
| 95 | |
| 96 | /* name */ |
| 97 | ospf6_linkstate_prefix2str (&v->vertex_id, v->name, sizeof (v->name)); |
| 98 | |
| 99 | /* Associated LSA */ |
| 100 | v->lsa = lsa; |
| 101 | |
| 102 | /* capability bits + options */ |
| 103 | v->capability = *(u_char *)(OSPF6_LSA_HEADER_END (lsa->header)); |
| 104 | v->options[0] = *(u_char *)(OSPF6_LSA_HEADER_END (lsa->header) + 1); |
| 105 | v->options[1] = *(u_char *)(OSPF6_LSA_HEADER_END (lsa->header) + 2); |
| 106 | v->options[2] = *(u_char *)(OSPF6_LSA_HEADER_END (lsa->header) + 3); |
| 107 | |
| 108 | for (i = 0; i < OSPF6_MULTI_PATH_LIMIT; i++) |
| 109 | ospf6_nexthop_clear (&v->nexthop[i]); |
| 110 | |
| 111 | v->parent = NULL; |
| 112 | v->child_list = list_new (); |
| 113 | v->child_list->cmp = ospf6_vertex_id_cmp; |
| 114 | |
| 115 | return v; |
| 116 | } |
| 117 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 118 | static void |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 119 | ospf6_vertex_delete (struct ospf6_vertex *v) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 120 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 121 | list_delete (v->child_list); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 122 | XFREE (MTYPE_OSPF6_VERTEX, v); |
| 123 | } |
| 124 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 125 | static struct ospf6_lsa * |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 126 | ospf6_lsdesc_lsa (caddr_t lsdesc, struct ospf6_vertex *v) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 127 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 128 | struct ospf6_lsa *lsa; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 129 | u_int16_t type = 0; |
| 130 | u_int32_t id = 0, adv_router = 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 131 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 132 | if (VERTEX_IS_TYPE (NETWORK, v)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 133 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 134 | type = htons (OSPF6_LSTYPE_ROUTER); |
| 135 | id = htonl (0); |
| 136 | adv_router = NETWORK_LSDESC_GET_NBR_ROUTERID (lsdesc); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 137 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 138 | else |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 139 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 140 | if (ROUTER_LSDESC_IS_TYPE (POINTTOPOINT, lsdesc)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 141 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 142 | type = htons (OSPF6_LSTYPE_ROUTER); |
| 143 | id = htonl (0); |
| 144 | adv_router = ROUTER_LSDESC_GET_NBR_ROUTERID (lsdesc); |
| 145 | } |
| 146 | else if (ROUTER_LSDESC_IS_TYPE (TRANSIT_NETWORK, lsdesc)) |
| 147 | { |
| 148 | type = htons (OSPF6_LSTYPE_NETWORK); |
| 149 | id = htonl (ROUTER_LSDESC_GET_NBR_IFID (lsdesc)); |
| 150 | adv_router = ROUTER_LSDESC_GET_NBR_ROUTERID (lsdesc); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 151 | } |
| 152 | } |
| 153 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 154 | lsa = ospf6_lsdb_lookup (type, id, adv_router, v->area->lsdb); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 155 | |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame] | 156 | if (IS_OSPF6_DEBUG_SPF (PROCESS)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 157 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 158 | char ibuf[16], abuf[16]; |
| 159 | inet_ntop (AF_INET, &id, ibuf, sizeof (ibuf)); |
| 160 | inet_ntop (AF_INET, &adv_router, abuf, sizeof (abuf)); |
| 161 | if (lsa) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 162 | zlog_debug (" Link to: %s", lsa->name); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 163 | else |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 164 | zlog_debug (" Link to: [%s Id:%s Adv:%s] No LSA", |
| 165 | ospf6_lstype_name (type), ibuf, abuf); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 166 | } |
| 167 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 168 | return lsa; |
| 169 | } |
| 170 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 171 | static char * |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 172 | ospf6_lsdesc_backlink (struct ospf6_lsa *lsa, |
| 173 | caddr_t lsdesc, struct ospf6_vertex *v) |
| 174 | { |
| 175 | caddr_t backlink, found = NULL; |
| 176 | int size; |
| 177 | |
| 178 | size = (OSPF6_LSA_IS_TYPE (ROUTER, lsa) ? |
| 179 | sizeof (struct ospf6_router_lsdesc) : |
| 180 | sizeof (struct ospf6_network_lsdesc)); |
| 181 | for (backlink = OSPF6_LSA_HEADER_END (lsa->header) + 4; |
| 182 | backlink + size <= OSPF6_LSA_END (lsa->header); backlink += size) |
| 183 | { |
| 184 | assert (! (OSPF6_LSA_IS_TYPE (NETWORK, lsa) && |
| 185 | VERTEX_IS_TYPE (NETWORK, v))); |
| 186 | |
| 187 | if (OSPF6_LSA_IS_TYPE (NETWORK, lsa) && |
| 188 | NETWORK_LSDESC_GET_NBR_ROUTERID (backlink) |
| 189 | == v->lsa->header->adv_router) |
| 190 | found = backlink; |
| 191 | else if (VERTEX_IS_TYPE (NETWORK, v) && |
| 192 | ROUTER_LSDESC_IS_TYPE (TRANSIT_NETWORK, backlink) && |
| 193 | ROUTER_LSDESC_GET_NBR_ROUTERID (backlink) |
| 194 | == v->lsa->header->adv_router && |
| 195 | ROUTER_LSDESC_GET_NBR_IFID (backlink) |
| 196 | == ntohl (v->lsa->header->id)) |
| 197 | found = backlink; |
| 198 | else |
| 199 | { |
| 200 | if (! ROUTER_LSDESC_IS_TYPE (POINTTOPOINT, backlink) || |
| 201 | ! ROUTER_LSDESC_IS_TYPE (POINTTOPOINT, lsdesc)) |
| 202 | continue; |
| 203 | if (ROUTER_LSDESC_GET_NBR_IFID (backlink) != |
| 204 | ROUTER_LSDESC_GET_IFID (lsdesc) || |
| 205 | ROUTER_LSDESC_GET_NBR_IFID (lsdesc) != |
| 206 | ROUTER_LSDESC_GET_IFID (backlink)) |
| 207 | continue; |
| 208 | if (ROUTER_LSDESC_GET_NBR_ROUTERID (backlink) != |
| 209 | v->lsa->header->adv_router || |
| 210 | ROUTER_LSDESC_GET_NBR_ROUTERID (lsdesc) != |
| 211 | lsa->header->adv_router) |
| 212 | continue; |
| 213 | found = backlink; |
| 214 | } |
| 215 | } |
| 216 | |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame] | 217 | if (IS_OSPF6_DEBUG_SPF (PROCESS)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 218 | zlog_debug (" Backlink %s", (found ? "OK" : "FAIL")); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 219 | |
| 220 | return found; |
| 221 | } |
| 222 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 223 | static void |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 224 | ospf6_nexthop_calc (struct ospf6_vertex *w, struct ospf6_vertex *v, |
| 225 | caddr_t lsdesc) |
| 226 | { |
| 227 | int i, ifindex; |
| 228 | struct ospf6_interface *oi; |
| 229 | u_int16_t type; |
| 230 | u_int32_t adv_router; |
| 231 | struct ospf6_lsa *lsa; |
| 232 | struct ospf6_link_lsa *link_lsa; |
| 233 | char buf[64]; |
| 234 | |
| 235 | assert (VERTEX_IS_TYPE (ROUTER, w)); |
| 236 | ifindex = (VERTEX_IS_TYPE (NETWORK, v) ? v->nexthop[0].ifindex : |
| 237 | ROUTER_LSDESC_GET_IFID (lsdesc)); |
| 238 | oi = ospf6_interface_lookup_by_ifindex (ifindex); |
| 239 | if (oi == NULL) |
| 240 | { |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame] | 241 | if (IS_OSPF6_DEBUG_SPF (PROCESS)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 242 | zlog_debug ("Can't find interface in SPF: ifindex %d", ifindex); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 243 | return; |
| 244 | } |
| 245 | |
| 246 | type = htons (OSPF6_LSTYPE_LINK); |
| 247 | adv_router = (VERTEX_IS_TYPE (NETWORK, v) ? |
| 248 | NETWORK_LSDESC_GET_NBR_ROUTERID (lsdesc) : |
| 249 | ROUTER_LSDESC_GET_NBR_ROUTERID (lsdesc)); |
| 250 | |
| 251 | i = 0; |
| 252 | for (lsa = ospf6_lsdb_type_router_head (type, adv_router, oi->lsdb); lsa; |
| 253 | lsa = ospf6_lsdb_type_router_next (type, adv_router, lsa)) |
| 254 | { |
| 255 | if (VERTEX_IS_TYPE (ROUTER, v) && |
| 256 | htonl (ROUTER_LSDESC_GET_NBR_IFID (lsdesc)) != lsa->header->id) |
| 257 | continue; |
| 258 | |
| 259 | link_lsa = (struct ospf6_link_lsa *) OSPF6_LSA_HEADER_END (lsa->header); |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame] | 260 | if (IS_OSPF6_DEBUG_SPF (PROCESS)) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 261 | { |
| 262 | inet_ntop (AF_INET6, &link_lsa->linklocal_addr, buf, sizeof (buf)); |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 263 | zlog_debug (" nexthop %s from %s", buf, lsa->name); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | if (i < OSPF6_MULTI_PATH_LIMIT) |
| 267 | { |
| 268 | memcpy (&w->nexthop[i].address, &link_lsa->linklocal_addr, |
| 269 | sizeof (struct in6_addr)); |
| 270 | w->nexthop[i].ifindex = ifindex; |
| 271 | i++; |
| 272 | } |
| 273 | } |
| 274 | |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame] | 275 | if (i == 0 && IS_OSPF6_DEBUG_SPF (PROCESS)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 276 | zlog_debug ("No nexthop for %s found", w->name); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 277 | } |
| 278 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 279 | static int |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 280 | ospf6_spf_install (struct ospf6_vertex *v, |
| 281 | struct ospf6_route_table *result_table) |
| 282 | { |
| 283 | struct ospf6_route *route; |
| 284 | int i, j; |
Denis Ovsienko | 87362ce | 2011-08-27 22:19:34 +0400 | [diff] [blame] | 285 | struct ospf6_vertex *prev; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 286 | |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame] | 287 | if (IS_OSPF6_DEBUG_SPF (PROCESS)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 288 | zlog_debug ("SPF install %s hops %d cost %d", |
| 289 | v->name, v->hops, v->cost); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 290 | |
| 291 | route = ospf6_route_lookup (&v->vertex_id, result_table); |
| 292 | if (route && route->path.cost < v->cost) |
| 293 | { |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame] | 294 | if (IS_OSPF6_DEBUG_SPF (PROCESS)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 295 | zlog_debug (" already installed with lower cost (%d), ignore", |
| 296 | route->path.cost); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 297 | ospf6_vertex_delete (v); |
| 298 | return -1; |
| 299 | } |
| 300 | else if (route && route->path.cost == v->cost) |
| 301 | { |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame] | 302 | if (IS_OSPF6_DEBUG_SPF (PROCESS)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 303 | zlog_debug (" another path found, merge"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 304 | |
| 305 | for (i = 0; ospf6_nexthop_is_set (&v->nexthop[i]) && |
| 306 | i < OSPF6_MULTI_PATH_LIMIT; i++) |
| 307 | { |
| 308 | for (j = 0; j < OSPF6_MULTI_PATH_LIMIT; j++) |
| 309 | { |
| 310 | if (ospf6_nexthop_is_set (&route->nexthop[j])) |
| 311 | { |
| 312 | if (ospf6_nexthop_is_same (&route->nexthop[j], |
| 313 | &v->nexthop[i])) |
| 314 | break; |
| 315 | else |
| 316 | continue; |
| 317 | } |
| 318 | ospf6_nexthop_copy (&route->nexthop[j], &v->nexthop[i]); |
| 319 | break; |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | prev = (struct ospf6_vertex *) route->route_option; |
Dmitrij Tejblum | 403138e | 2011-01-13 18:25:40 +0300 | [diff] [blame] | 324 | assert (prev->hops <= v->hops); |
| 325 | ospf6_vertex_delete (v); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 326 | |
| 327 | return -1; |
| 328 | } |
| 329 | |
| 330 | /* There should be no case where candidate being installed (variable |
| 331 | "v") is closer than the one in the SPF tree (variable "route"). |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 332 | In the case something has gone wrong with the behavior of |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 333 | Priority-Queue. */ |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 334 | |
| 335 | /* the case where the route exists already is handled and returned |
| 336 | up to here. */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 337 | assert (route == NULL); |
| 338 | |
| 339 | route = ospf6_route_create (); |
| 340 | memcpy (&route->prefix, &v->vertex_id, sizeof (struct prefix)); |
| 341 | route->type = OSPF6_DEST_TYPE_LINKSTATE; |
| 342 | route->path.type = OSPF6_PATH_TYPE_INTRA; |
| 343 | route->path.origin.type = v->lsa->header->type; |
| 344 | route->path.origin.id = v->lsa->header->id; |
| 345 | route->path.origin.adv_router = v->lsa->header->adv_router; |
| 346 | route->path.metric_type = 1; |
| 347 | route->path.cost = v->cost; |
| 348 | route->path.cost_e2 = v->hops; |
| 349 | route->path.router_bits = v->capability; |
| 350 | route->path.options[0] = v->options[0]; |
| 351 | route->path.options[1] = v->options[1]; |
| 352 | route->path.options[2] = v->options[2]; |
| 353 | |
| 354 | for (i = 0; ospf6_nexthop_is_set (&v->nexthop[i]) && |
| 355 | i < OSPF6_MULTI_PATH_LIMIT; i++) |
| 356 | ospf6_nexthop_copy (&route->nexthop[i], &v->nexthop[i]); |
| 357 | |
| 358 | if (v->parent) |
| 359 | listnode_add_sort (v->parent->child_list, v); |
| 360 | route->route_option = v; |
| 361 | |
| 362 | ospf6_route_add (route, result_table); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 363 | return 0; |
| 364 | } |
| 365 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 366 | void |
| 367 | ospf6_spf_table_finish (struct ospf6_route_table *result_table) |
| 368 | { |
| 369 | struct ospf6_route *route; |
| 370 | struct ospf6_vertex *v; |
| 371 | for (route = ospf6_route_head (result_table); route; |
| 372 | route = ospf6_route_next (route)) |
| 373 | { |
| 374 | v = (struct ospf6_vertex *) route->route_option; |
| 375 | ospf6_vertex_delete (v); |
| 376 | ospf6_route_remove (route, result_table); |
| 377 | } |
| 378 | } |
| 379 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 380 | /* RFC2328 16.1. Calculating the shortest-path tree for an area */ |
| 381 | /* RFC2740 3.8.1. Calculating the shortest path tree for an area */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 382 | void |
| 383 | ospf6_spf_calculation (u_int32_t router_id, |
| 384 | struct ospf6_route_table *result_table, |
| 385 | struct ospf6_area *oa) |
| 386 | { |
| 387 | struct pqueue *candidate_list; |
| 388 | struct ospf6_vertex *root, *v, *w; |
| 389 | int i; |
| 390 | int size; |
| 391 | caddr_t lsdesc; |
| 392 | struct ospf6_lsa *lsa; |
| 393 | |
Tom Goff | b48cebb | 2011-12-14 14:11:29 +0400 | [diff] [blame] | 394 | ospf6_spf_table_finish (result_table); |
| 395 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 396 | /* Install the calculating router itself as the root of the SPF tree */ |
| 397 | /* construct root vertex */ |
| 398 | lsa = ospf6_lsdb_lookup (htons (OSPF6_LSTYPE_ROUTER), htonl (0), |
| 399 | router_id, oa->lsdb); |
| 400 | if (lsa == NULL) |
| 401 | return; |
Tom Goff | 1d19234 | 2010-11-10 13:02:38 -0800 | [diff] [blame] | 402 | |
| 403 | /* initialize */ |
| 404 | candidate_list = pqueue_create (); |
| 405 | candidate_list->cmp = ospf6_vertex_cmp; |
| 406 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 407 | root = ospf6_vertex_create (lsa); |
| 408 | root->area = oa; |
| 409 | root->cost = 0; |
| 410 | root->hops = 0; |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 411 | root->nexthop[0].ifindex = 0; /* loopbak I/F is better ... */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 412 | inet_pton (AF_INET6, "::1", &root->nexthop[0].address); |
| 413 | |
| 414 | /* Actually insert root to the candidate-list as the only candidate */ |
| 415 | pqueue_enqueue (root, candidate_list); |
| 416 | |
| 417 | /* Iterate until candidate-list becomes empty */ |
| 418 | while (candidate_list->size) |
| 419 | { |
| 420 | /* get closest candidate from priority queue */ |
| 421 | v = pqueue_dequeue (candidate_list); |
| 422 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 423 | /* installing may result in merging or rejecting of the vertex */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 424 | if (ospf6_spf_install (v, result_table) < 0) |
| 425 | continue; |
| 426 | |
Dinesh Dutt | f41b4a0 | 2013-08-24 08:00:37 +0000 | [diff] [blame] | 427 | /* Skip overloaded routers */ |
| 428 | if ((OSPF6_LSA_IS_TYPE (ROUTER, v->lsa) && |
| 429 | ospf6_router_is_stub_router (v->lsa))) |
| 430 | continue; |
| 431 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 432 | /* For each LS description in the just-added vertex V's LSA */ |
| 433 | size = (VERTEX_IS_TYPE (ROUTER, v) ? |
| 434 | sizeof (struct ospf6_router_lsdesc) : |
| 435 | sizeof (struct ospf6_network_lsdesc)); |
| 436 | for (lsdesc = OSPF6_LSA_HEADER_END (v->lsa->header) + 4; |
| 437 | lsdesc + size <= OSPF6_LSA_END (v->lsa->header); lsdesc += size) |
| 438 | { |
| 439 | lsa = ospf6_lsdesc_lsa (lsdesc, v); |
| 440 | if (lsa == NULL) |
| 441 | continue; |
| 442 | |
| 443 | if (! ospf6_lsdesc_backlink (lsa, lsdesc, v)) |
| 444 | continue; |
| 445 | |
| 446 | w = ospf6_vertex_create (lsa); |
| 447 | w->area = oa; |
| 448 | w->parent = v; |
| 449 | if (VERTEX_IS_TYPE (ROUTER, v)) |
| 450 | { |
| 451 | w->cost = v->cost + ROUTER_LSDESC_GET_METRIC (lsdesc); |
| 452 | w->hops = v->hops + (VERTEX_IS_TYPE (NETWORK, w) ? 0 : 1); |
| 453 | } |
| 454 | else /* NETWORK */ |
| 455 | { |
| 456 | w->cost = v->cost; |
| 457 | w->hops = v->hops + 1; |
| 458 | } |
| 459 | |
| 460 | /* nexthop calculation */ |
| 461 | if (w->hops == 0) |
| 462 | w->nexthop[0].ifindex = ROUTER_LSDESC_GET_IFID (lsdesc); |
| 463 | else if (w->hops == 1 && v->hops == 0) |
| 464 | ospf6_nexthop_calc (w, v, lsdesc); |
| 465 | else |
| 466 | { |
| 467 | for (i = 0; ospf6_nexthop_is_set (&v->nexthop[i]) && |
| 468 | i < OSPF6_MULTI_PATH_LIMIT; i++) |
| 469 | ospf6_nexthop_copy (&w->nexthop[i], &v->nexthop[i]); |
| 470 | } |
| 471 | |
| 472 | /* add new candidate to the candidate_list */ |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame] | 473 | if (IS_OSPF6_DEBUG_SPF (PROCESS)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 474 | zlog_debug (" New candidate: %s hops %d cost %d", |
| 475 | w->name, w->hops, w->cost); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 476 | pqueue_enqueue (w, candidate_list); |
| 477 | } |
| 478 | } |
| 479 | |
| 480 | pqueue_delete (candidate_list); |
Vincent Bernat | ea86e40 | 2012-06-04 10:29:49 +0200 | [diff] [blame] | 481 | |
| 482 | oa->spf_calculation++; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 483 | } |
| 484 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 485 | static void |
hasso | 2680aa2 | 2004-11-25 20:54:46 +0000 | [diff] [blame] | 486 | ospf6_spf_log_database (struct ospf6_area *oa) |
| 487 | { |
| 488 | char *p, *end, buffer[256]; |
| 489 | struct listnode *node; |
| 490 | struct ospf6_interface *oi; |
| 491 | |
| 492 | p = buffer; |
| 493 | end = buffer + sizeof (buffer); |
| 494 | |
| 495 | snprintf (p, end - p, "SPF on DB (#LSAs):"); |
| 496 | p = (buffer + strlen (buffer) < end ? buffer + strlen (buffer) : end); |
| 497 | snprintf (p, end - p, " Area %s: %d", oa->name, oa->lsdb->count); |
| 498 | p = (buffer + strlen (buffer) < end ? buffer + strlen (buffer) : end); |
| 499 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 500 | for (ALL_LIST_ELEMENTS_RO (oa->if_list, node, oi)) |
hasso | 2680aa2 | 2004-11-25 20:54:46 +0000 | [diff] [blame] | 501 | { |
hasso | 2680aa2 | 2004-11-25 20:54:46 +0000 | [diff] [blame] | 502 | snprintf (p, end - p, " I/F %s: %d", |
| 503 | oi->interface->name, oi->lsdb->count); |
| 504 | p = (buffer + strlen (buffer) < end ? buffer + strlen (buffer) : end); |
| 505 | } |
| 506 | |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 507 | zlog_debug ("%s", buffer); |
hasso | 2680aa2 | 2004-11-25 20:54:46 +0000 | [diff] [blame] | 508 | } |
| 509 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 510 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 511 | ospf6_spf_calculation_thread (struct thread *t) |
| 512 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 513 | struct ospf6_area *oa; |
Dinesh Dutt | 3810e06 | 2013-08-24 07:54:09 +0000 | [diff] [blame] | 514 | struct ospf6 *ospf6; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 515 | struct timeval start, end, runtime; |
Dinesh Dutt | 3810e06 | 2013-08-24 07:54:09 +0000 | [diff] [blame] | 516 | struct listnode *node; |
| 517 | struct ospf6_route *route; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 518 | |
Dinesh Dutt | 3810e06 | 2013-08-24 07:54:09 +0000 | [diff] [blame] | 519 | ospf6 = (struct ospf6 *)THREAD_ARG (t); |
| 520 | ospf6->t_spf_calc = NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 521 | |
| 522 | /* execute SPF calculation */ |
Takashi Sogabe | 86f72dc | 2009-06-22 13:07:02 +0900 | [diff] [blame] | 523 | quagga_gettime (QUAGGA_CLK_MONOTONIC, &start); |
Dinesh Dutt | 3810e06 | 2013-08-24 07:54:09 +0000 | [diff] [blame] | 524 | |
| 525 | for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, node, oa)) |
| 526 | { |
| 527 | |
| 528 | if (oa == ospf6->backbone) |
| 529 | continue; |
| 530 | |
| 531 | if (IS_OSPF6_DEBUG_SPF (PROCESS)) |
| 532 | zlog_debug ("SPF calculation for Area %s", oa->name); |
| 533 | if (IS_OSPF6_DEBUG_SPF (DATABASE)) |
| 534 | ospf6_spf_log_database (oa); |
| 535 | |
| 536 | ospf6_spf_calculation (ospf6->router_id, oa->spf_table, oa); |
| 537 | ospf6_intra_route_calculation (oa); |
| 538 | ospf6_intra_brouter_calculation (oa); |
| 539 | } |
| 540 | |
| 541 | if (ospf6->backbone) |
| 542 | { |
| 543 | if (IS_OSPF6_DEBUG_SPF (PROCESS)) |
| 544 | zlog_debug ("SPF calculation for Backbone area %s", |
| 545 | ospf6->backbone->name); |
| 546 | if (IS_OSPF6_DEBUG_SPF (DATABASE)) |
| 547 | ospf6_spf_log_database(ospf6->backbone); |
| 548 | |
| 549 | ospf6_spf_calculation(ospf6->router_id, ospf6->backbone->spf_table, |
| 550 | ospf6->backbone); |
| 551 | ospf6_intra_route_calculation(ospf6->backbone); |
| 552 | ospf6_intra_brouter_calculation(ospf6->backbone); |
| 553 | } |
| 554 | |
| 555 | /* Redo summaries if required */ |
| 556 | for (route = ospf6_route_head (ospf6->route_table); route; |
| 557 | route = ospf6_route_next (route)) |
| 558 | ospf6_abr_originate_summary(route); |
| 559 | |
Takashi Sogabe | 86f72dc | 2009-06-22 13:07:02 +0900 | [diff] [blame] | 560 | quagga_gettime (QUAGGA_CLK_MONOTONIC, &end); |
hasso | 2680aa2 | 2004-11-25 20:54:46 +0000 | [diff] [blame] | 561 | timersub (&end, &start, &runtime); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 562 | |
Dinesh Dutt | 3810e06 | 2013-08-24 07:54:09 +0000 | [diff] [blame] | 563 | ospf6->ts_spf_duration = runtime; |
| 564 | |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame] | 565 | if (IS_OSPF6_DEBUG_SPF (PROCESS) || IS_OSPF6_DEBUG_SPF (TIME)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 566 | zlog_debug ("SPF runtime: %ld sec %ld usec", |
| 567 | runtime.tv_sec, runtime.tv_usec); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 568 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 569 | return 0; |
| 570 | } |
| 571 | |
Dinesh Dutt | 3810e06 | 2013-08-24 07:54:09 +0000 | [diff] [blame] | 572 | /* Add schedule for SPF calculation. To avoid frequenst SPF calc, we |
| 573 | set timer for SPF calc. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 574 | void |
Dinesh Dutt | 3810e06 | 2013-08-24 07:54:09 +0000 | [diff] [blame] | 575 | ospf6_spf_schedule (struct ospf6 *ospf6) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 576 | { |
Dinesh Dutt | 3810e06 | 2013-08-24 07:54:09 +0000 | [diff] [blame] | 577 | unsigned long delay, elapsed, ht; |
| 578 | struct timeval now, result; |
| 579 | |
| 580 | if (IS_OSPF6_DEBUG_SPF(PROCESS) || IS_OSPF6_DEBUG_SPF (TIME)) |
| 581 | zlog_debug ("SPF: calculation timer scheduled"); |
| 582 | |
| 583 | /* OSPF instance does not exist. */ |
| 584 | if (ospf6 == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 585 | return; |
Dinesh Dutt | 3810e06 | 2013-08-24 07:54:09 +0000 | [diff] [blame] | 586 | |
| 587 | /* SPF calculation timer is already scheduled. */ |
| 588 | if (ospf6->t_spf_calc) |
| 589 | { |
| 590 | if (IS_OSPF6_DEBUG_SPF(PROCESS) || IS_OSPF6_DEBUG_SPF (TIME)) |
| 591 | zlog_debug ("SPF: calculation timer is already scheduled: %p", |
| 592 | ospf6->t_spf_calc); |
| 593 | return; |
| 594 | } |
| 595 | |
| 596 | /* XXX Monotic timers: we only care about relative time here. */ |
| 597 | now = recent_relative_time (); |
| 598 | timersub (&now, &ospf6->ts_spf, &result); |
| 599 | |
| 600 | elapsed = (result.tv_sec * 1000) + (result.tv_usec / 1000); |
| 601 | ht = ospf6->spf_holdtime * ospf6->spf_hold_multiplier; |
| 602 | |
| 603 | if (ht > ospf6->spf_max_holdtime) |
| 604 | ht = ospf6->spf_max_holdtime; |
| 605 | |
| 606 | /* Get SPF calculation delay time. */ |
| 607 | if (elapsed < ht) |
| 608 | { |
| 609 | /* Got an event within the hold time of last SPF. We need to |
| 610 | * increase the hold_multiplier, if it's not already at/past |
| 611 | * maximum value, and wasn't already increased.. |
| 612 | */ |
| 613 | if (ht < ospf6->spf_max_holdtime) |
| 614 | ospf6->spf_hold_multiplier++; |
| 615 | |
| 616 | /* always honour the SPF initial delay */ |
| 617 | if ( (ht - elapsed) < ospf6->spf_delay) |
| 618 | delay = ospf6->spf_delay; |
| 619 | else |
| 620 | delay = ht - elapsed; |
| 621 | } |
| 622 | else |
| 623 | { |
| 624 | /* Event is past required hold-time of last SPF */ |
| 625 | delay = ospf6->spf_delay; |
| 626 | ospf6->spf_hold_multiplier = 1; |
| 627 | } |
| 628 | |
| 629 | if (IS_OSPF6_DEBUG_SPF(PROCESS) || IS_OSPF6_DEBUG_SPF (TIME)) |
| 630 | zlog_debug ("SPF: calculation timer delay = %ld", delay); |
| 631 | |
| 632 | zlog_info ("SPF: Scheduled in %ld msec", delay); |
| 633 | |
| 634 | ospf6->t_spf_calc = |
| 635 | thread_add_timer_msec (master, ospf6_spf_calculation_thread, ospf6, delay); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | void |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 639 | ospf6_spf_display_subtree (struct vty *vty, const char *prefix, int rest, |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 640 | struct ospf6_vertex *v) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 641 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 642 | struct listnode *node, *nnode; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 643 | struct ospf6_vertex *c; |
| 644 | char *next_prefix; |
| 645 | int len; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 646 | int restnum; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 647 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 648 | /* "prefix" is the space prefix of the display line */ |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 649 | vty_out (vty, "%s+-%s [%d]%s", prefix, v->name, v->cost, VNL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 650 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 651 | len = strlen (prefix) + 4; |
| 652 | next_prefix = (char *) malloc (len); |
| 653 | if (next_prefix == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 654 | { |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 655 | vty_out (vty, "malloc failed%s", VNL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 656 | return; |
| 657 | } |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 658 | snprintf (next_prefix, len, "%s%s", prefix, (rest ? "| " : " ")); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 659 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 660 | restnum = listcount (v->child_list); |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 661 | for (ALL_LIST_ELEMENTS (v->child_list, node, nnode, c)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 662 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 663 | restnum--; |
| 664 | ospf6_spf_display_subtree (vty, next_prefix, restnum, c); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 665 | } |
| 666 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 667 | free (next_prefix); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 668 | } |
| 669 | |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame] | 670 | DEFUN (debug_ospf6_spf_process, |
| 671 | debug_ospf6_spf_process_cmd, |
| 672 | "debug ospf6 spf process", |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 673 | DEBUG_STR |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 674 | OSPF6_STR |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 675 | "Debug SPF Calculation\n" |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame] | 676 | "Debug Detailed SPF Process\n" |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 677 | ) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 678 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 679 | unsigned char level = 0; |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame] | 680 | level = OSPF6_DEBUG_SPF_PROCESS; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 681 | OSPF6_DEBUG_SPF_ON (level); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 682 | return CMD_SUCCESS; |
| 683 | } |
| 684 | |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame] | 685 | DEFUN (debug_ospf6_spf_time, |
| 686 | debug_ospf6_spf_time_cmd, |
| 687 | "debug ospf6 spf time", |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 688 | DEBUG_STR |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 689 | OSPF6_STR |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 690 | "Debug SPF Calculation\n" |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame] | 691 | "Measure time taken by SPF Calculation\n" |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 692 | ) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 693 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 694 | unsigned char level = 0; |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame] | 695 | level = OSPF6_DEBUG_SPF_TIME; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 696 | OSPF6_DEBUG_SPF_ON (level); |
| 697 | return CMD_SUCCESS; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 698 | } |
| 699 | |
hasso | 2680aa2 | 2004-11-25 20:54:46 +0000 | [diff] [blame] | 700 | DEFUN (debug_ospf6_spf_database, |
| 701 | debug_ospf6_spf_database_cmd, |
| 702 | "debug ospf6 spf database", |
| 703 | DEBUG_STR |
| 704 | OSPF6_STR |
| 705 | "Debug SPF Calculation\n" |
| 706 | "Log number of LSAs at SPF Calculation time\n" |
| 707 | ) |
| 708 | { |
| 709 | unsigned char level = 0; |
| 710 | level = OSPF6_DEBUG_SPF_DATABASE; |
| 711 | OSPF6_DEBUG_SPF_ON (level); |
| 712 | return CMD_SUCCESS; |
| 713 | } |
| 714 | |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame] | 715 | DEFUN (no_debug_ospf6_spf_process, |
| 716 | no_debug_ospf6_spf_process_cmd, |
| 717 | "no debug ospf6 spf process", |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 718 | NO_STR |
| 719 | DEBUG_STR |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 720 | OSPF6_STR |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 721 | "Quit Debugging SPF Calculation\n" |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame] | 722 | "Quit Debugging Detailed SPF Process\n" |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 723 | ) |
| 724 | { |
| 725 | unsigned char level = 0; |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame] | 726 | level = OSPF6_DEBUG_SPF_PROCESS; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 727 | OSPF6_DEBUG_SPF_OFF (level); |
| 728 | return CMD_SUCCESS; |
| 729 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 730 | |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame] | 731 | DEFUN (no_debug_ospf6_spf_time, |
| 732 | no_debug_ospf6_spf_time_cmd, |
| 733 | "no debug ospf6 spf time", |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 734 | NO_STR |
| 735 | DEBUG_STR |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 736 | OSPF6_STR |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 737 | "Quit Debugging SPF Calculation\n" |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame] | 738 | "Quit Measuring time taken by SPF Calculation\n" |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 739 | ) |
| 740 | { |
| 741 | unsigned char level = 0; |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame] | 742 | level = OSPF6_DEBUG_SPF_TIME; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 743 | OSPF6_DEBUG_SPF_OFF (level); |
| 744 | return CMD_SUCCESS; |
| 745 | } |
| 746 | |
hasso | 2680aa2 | 2004-11-25 20:54:46 +0000 | [diff] [blame] | 747 | DEFUN (no_debug_ospf6_spf_database, |
| 748 | no_debug_ospf6_spf_database_cmd, |
| 749 | "no debug ospf6 spf database", |
| 750 | NO_STR |
| 751 | DEBUG_STR |
| 752 | OSPF6_STR |
| 753 | "Debug SPF Calculation\n" |
| 754 | "Quit Logging number of LSAs at SPF Calculation time\n" |
| 755 | ) |
| 756 | { |
| 757 | unsigned char level = 0; |
| 758 | level = OSPF6_DEBUG_SPF_DATABASE; |
| 759 | OSPF6_DEBUG_SPF_OFF (level); |
| 760 | return CMD_SUCCESS; |
| 761 | } |
| 762 | |
Dinesh Dutt | 3810e06 | 2013-08-24 07:54:09 +0000 | [diff] [blame] | 763 | static int |
| 764 | ospf6_timers_spf_set (struct vty *vty, unsigned int delay, |
| 765 | unsigned int hold, |
| 766 | unsigned int max) |
| 767 | { |
| 768 | struct ospf6 *ospf = vty->index; |
| 769 | |
| 770 | ospf->spf_delay = delay; |
| 771 | ospf->spf_holdtime = hold; |
| 772 | ospf->spf_max_holdtime = max; |
| 773 | |
| 774 | return CMD_SUCCESS; |
| 775 | } |
| 776 | |
| 777 | DEFUN (ospf6_timers_throttle_spf, |
| 778 | ospf6_timers_throttle_spf_cmd, |
| 779 | "timers throttle spf <0-600000> <0-600000> <0-600000>", |
| 780 | "Adjust routing timers\n" |
| 781 | "Throttling adaptive timer\n" |
| 782 | "OSPF6 SPF timers\n" |
| 783 | "Delay (msec) from first change received till SPF calculation\n" |
| 784 | "Initial hold time (msec) between consecutive SPF calculations\n" |
| 785 | "Maximum hold time (msec)\n") |
| 786 | { |
| 787 | unsigned int delay, hold, max; |
| 788 | |
| 789 | if (argc != 3) |
| 790 | { |
| 791 | vty_out (vty, "Insufficient arguments%s", VTY_NEWLINE); |
| 792 | return CMD_WARNING; |
| 793 | } |
| 794 | |
| 795 | VTY_GET_INTEGER_RANGE ("SPF delay timer", delay, argv[0], 0, 600000); |
| 796 | VTY_GET_INTEGER_RANGE ("SPF hold timer", hold, argv[1], 0, 600000); |
| 797 | VTY_GET_INTEGER_RANGE ("SPF max-hold timer", max, argv[2], 0, 600000); |
| 798 | |
| 799 | return ospf6_timers_spf_set (vty, delay, hold, max); |
| 800 | } |
| 801 | |
| 802 | DEFUN (no_ospf6_timers_throttle_spf, |
| 803 | no_ospf6_timers_throttle_spf_cmd, |
| 804 | "no timers throttle spf", |
| 805 | NO_STR |
| 806 | "Adjust routing timers\n" |
| 807 | "Throttling adaptive timer\n" |
| 808 | "OSPF6 SPF timers\n") |
| 809 | { |
| 810 | return ospf6_timers_spf_set (vty, |
| 811 | OSPF_SPF_DELAY_DEFAULT, |
| 812 | OSPF_SPF_HOLDTIME_DEFAULT, |
| 813 | OSPF_SPF_MAX_HOLDTIME_DEFAULT); |
| 814 | } |
| 815 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 816 | int |
| 817 | config_write_ospf6_debug_spf (struct vty *vty) |
| 818 | { |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame] | 819 | if (IS_OSPF6_DEBUG_SPF (PROCESS)) |
| 820 | vty_out (vty, "debug ospf6 spf process%s", VNL); |
| 821 | if (IS_OSPF6_DEBUG_SPF (TIME)) |
| 822 | vty_out (vty, "debug ospf6 spf time%s", VNL); |
hasso | 2680aa2 | 2004-11-25 20:54:46 +0000 | [diff] [blame] | 823 | if (IS_OSPF6_DEBUG_SPF (DATABASE)) |
| 824 | vty_out (vty, "debug ospf6 spf database%s", VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 825 | return 0; |
| 826 | } |
| 827 | |
| 828 | void |
Dinesh Dutt | 3810e06 | 2013-08-24 07:54:09 +0000 | [diff] [blame] | 829 | ospf6_spf_config_write (struct vty *vty) |
| 830 | { |
| 831 | |
| 832 | if (ospf6->spf_delay != OSPF_SPF_DELAY_DEFAULT || |
| 833 | ospf6->spf_holdtime != OSPF_SPF_HOLDTIME_DEFAULT || |
| 834 | ospf6->spf_max_holdtime != OSPF_SPF_MAX_HOLDTIME_DEFAULT) |
| 835 | vty_out (vty, " timers throttle spf %d %d %d%s", |
| 836 | ospf6->spf_delay, ospf6->spf_holdtime, |
| 837 | ospf6->spf_max_holdtime, VTY_NEWLINE); |
| 838 | |
| 839 | } |
| 840 | |
| 841 | void |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 842 | install_element_ospf6_debug_spf (void) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 843 | { |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame] | 844 | install_element (ENABLE_NODE, &debug_ospf6_spf_process_cmd); |
| 845 | install_element (ENABLE_NODE, &debug_ospf6_spf_time_cmd); |
hasso | 2680aa2 | 2004-11-25 20:54:46 +0000 | [diff] [blame] | 846 | install_element (ENABLE_NODE, &debug_ospf6_spf_database_cmd); |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame] | 847 | install_element (ENABLE_NODE, &no_debug_ospf6_spf_process_cmd); |
| 848 | install_element (ENABLE_NODE, &no_debug_ospf6_spf_time_cmd); |
hasso | 2680aa2 | 2004-11-25 20:54:46 +0000 | [diff] [blame] | 849 | install_element (ENABLE_NODE, &no_debug_ospf6_spf_database_cmd); |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame] | 850 | install_element (CONFIG_NODE, &debug_ospf6_spf_process_cmd); |
| 851 | install_element (CONFIG_NODE, &debug_ospf6_spf_time_cmd); |
hasso | 2680aa2 | 2004-11-25 20:54:46 +0000 | [diff] [blame] | 852 | install_element (CONFIG_NODE, &debug_ospf6_spf_database_cmd); |
hasso | 3b68735 | 2004-08-19 06:56:53 +0000 | [diff] [blame] | 853 | install_element (CONFIG_NODE, &no_debug_ospf6_spf_process_cmd); |
| 854 | install_element (CONFIG_NODE, &no_debug_ospf6_spf_time_cmd); |
hasso | 2680aa2 | 2004-11-25 20:54:46 +0000 | [diff] [blame] | 855 | install_element (CONFIG_NODE, &no_debug_ospf6_spf_database_cmd); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 856 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 857 | |
| 858 | void |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 859 | ospf6_spf_init (void) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 860 | { |
Dinesh Dutt | 3810e06 | 2013-08-24 07:54:09 +0000 | [diff] [blame] | 861 | install_element (OSPF6_NODE, &ospf6_timers_throttle_spf_cmd); |
| 862 | install_element (OSPF6_NODE, &no_ospf6_timers_throttle_spf_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 863 | } |