paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1 | /* |
| 2 | * OSPFv3 Top Level Data Structure |
| 3 | * Copyright (C) 1999 Yasuhiro Ohara |
| 4 | * |
| 5 | * This file is part of GNU Zebra. |
| 6 | * |
| 7 | * GNU Zebra is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License as published by the |
| 9 | * Free Software Foundation; either version 2, or (at your option) any |
| 10 | * later version. |
| 11 | * |
| 12 | * GNU Zebra is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with GNU Zebra; see the file COPYING. If not, write to the |
| 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 20 | * Boston, MA 02111-1307, USA. |
| 21 | */ |
| 22 | |
| 23 | #include <zebra.h> |
| 24 | |
| 25 | #include "log.h" |
| 26 | #include "memory.h" |
| 27 | #include "vty.h" |
| 28 | #include "linklist.h" |
| 29 | #include "prefix.h" |
| 30 | #include "table.h" |
| 31 | #include "thread.h" |
| 32 | #include "command.h" |
| 33 | |
| 34 | #include "ospf6_hook.h" |
| 35 | #include "ospf6_proto.h" |
| 36 | #include "ospf6_prefix.h" |
| 37 | #include "ospf6_lsa.h" |
| 38 | #include "ospf6_lsdb.h" |
| 39 | |
| 40 | #include "ospf6_message.h" |
| 41 | #include "ospf6_neighbor.h" |
| 42 | #include "ospf6_interface.h" |
| 43 | #include "ospf6_area.h" |
| 44 | #include "ospf6_top.h" |
| 45 | |
| 46 | #include "ospf6_route.h" |
| 47 | #include "ospf6_zebra.h" |
| 48 | |
| 49 | #include "ospf6_nsm.h" |
| 50 | #include "ospf6_asbr.h" |
| 51 | #include "ospf6_abr.h" |
| 52 | |
| 53 | #define HEADER_DEPENDENCY |
| 54 | #include "ospf6d.h" |
| 55 | #undef HEADER_DEPENDENCY |
| 56 | |
| 57 | /* global ospf6d variable */ |
| 58 | struct ospf6 *ospf6; |
| 59 | |
| 60 | static void |
| 61 | ospf6_top_foreach_area (struct ospf6 *o6, void *arg, int val, |
| 62 | void (*func) (void *, int, void *)) |
| 63 | { |
| 64 | listnode node; |
| 65 | struct ospf6_area *o6a; |
| 66 | |
| 67 | for (node = listhead (o6->area_list); node; nextnode (node)) |
| 68 | { |
| 69 | o6a = (struct ospf6_area *) getdata (node); |
| 70 | (*func) (arg, val, o6a); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | static void |
| 75 | ospf6_top_foreach_interface (struct ospf6 *o6, void *arg, int val, |
| 76 | void (*func) (void *, int, void *)) |
| 77 | { |
| 78 | listnode node; |
| 79 | struct ospf6_area *o6a; |
| 80 | |
| 81 | for (node = listhead (o6->area_list); node; nextnode (node)) |
| 82 | { |
| 83 | o6a = (struct ospf6_area *) getdata (node); |
| 84 | (*o6a->foreach_if) (o6a, arg, val, func); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | static void |
| 89 | ospf6_top_foreach_neighbor (struct ospf6 *o6, void *arg, int val, |
| 90 | void (*func) (void *, int, void *)) |
| 91 | { |
| 92 | listnode node; |
| 93 | struct ospf6_area *o6a; |
| 94 | |
| 95 | for (node = listhead (o6->area_list); node; nextnode (node)) |
| 96 | { |
| 97 | o6a = (struct ospf6_area *) getdata (node); |
| 98 | (*o6a->foreach_nei) (o6a, arg, val, func); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | static int |
| 103 | ospf6_top_maxage_remover (struct thread *t) |
| 104 | { |
| 105 | int count; |
| 106 | struct ospf6 *o6 = (struct ospf6 *) THREAD_ARG (t); |
| 107 | |
| 108 | o6->maxage_remover = (struct thread *) NULL; |
| 109 | |
| 110 | count = 0; |
| 111 | o6->foreach_nei (o6, &count, NBS_EXCHANGE, ospf6_count_state); |
| 112 | o6->foreach_nei (o6, &count, NBS_LOADING, ospf6_count_state); |
| 113 | if (count != 0) |
| 114 | return 0; |
| 115 | |
| 116 | ospf6_lsdb_remove_maxage (o6->lsdb); |
| 117 | return 0; |
| 118 | } |
| 119 | |
| 120 | void |
| 121 | ospf6_top_schedule_maxage_remover (void *arg, int val, struct ospf6 *o6) |
| 122 | { |
| 123 | if (o6->maxage_remover != NULL) |
| 124 | return; |
| 125 | |
| 126 | o6->maxage_remover = |
| 127 | thread_add_event (master, ospf6_top_maxage_remover, o6, 0); |
| 128 | } |
| 129 | |
| 130 | void |
| 131 | ospf6_show (struct vty *vty) |
| 132 | { |
| 133 | listnode n; |
| 134 | struct ospf6_area *area; |
| 135 | char id_string[32]; |
| 136 | unsigned long day, hour, min, sec; |
| 137 | struct timeval now, running; |
| 138 | |
| 139 | /* process id, router id */ |
| 140 | inet_ntop (AF_INET, &ospf6->router_id, id_string, sizeof (id_string)); |
| 141 | vty_out (vty, " Routing Process (%lu) with ID %s%s", |
| 142 | ospf6->process_id, id_string, VTY_NEWLINE); |
| 143 | |
| 144 | /* running time */ |
| 145 | gettimeofday (&now, (struct timezone *)NULL); |
| 146 | ospf6_timeval_sub (&now, &ospf6->starttime, &running); |
| 147 | ospf6_timeval_decode (&running, &day, &hour, &min, &sec, NULL, NULL); |
| 148 | vty_out (vty, " Running %ld days %ld hours %ld minutes %ld seconds%s", |
| 149 | day, hour, min, sec, VTY_NEWLINE); |
| 150 | |
| 151 | vty_out (vty, " Supports only single TOS(TOS0) routes%s", VTY_NEWLINE); |
| 152 | |
| 153 | /* Redistribute config */ |
| 154 | ospf6_redistribute_show_config (vty); |
| 155 | |
| 156 | /* LSAs */ |
| 157 | vty_out (vty, " Number of AS scoped LSAs is %u%s", |
| 158 | ospf6->lsdb->count, VTY_NEWLINE); |
| 159 | vty_out (vty, " Route calculation executed %d times%s", |
| 160 | ospf6->stat_route_calculation_execed, VTY_NEWLINE); |
| 161 | |
| 162 | /* Route Statistics */ |
| 163 | #if 0 |
| 164 | ospf6_route_statistics_show (vty, ospf6->route_table); |
| 165 | #endif |
| 166 | |
| 167 | /* Areas */ |
| 168 | vty_out (vty, " Number of areas in this router is %u%s", |
| 169 | listcount (ospf6->area_list), VTY_NEWLINE); |
| 170 | for (n = listhead (ospf6->area_list); n; nextnode (n)) |
| 171 | { |
| 172 | area = (struct ospf6_area *) getdata (n); |
| 173 | ospf6_area_show (vty, area); |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | void |
| 178 | ospf6_statistics_show (struct vty *vty, struct ospf6 *o6) |
| 179 | { |
| 180 | listnode node; |
| 181 | struct ospf6_area *o6a; |
| 182 | char running_time[128]; |
| 183 | struct timeval now, running; |
| 184 | |
| 185 | gettimeofday (&now, (struct timezone *) NULL); |
| 186 | ospf6_timeval_sub (&now, &o6->starttime, &running); |
| 187 | ospf6_timeval_string (&running, running_time, sizeof (running_time)); |
| 188 | |
| 189 | vty_out (vty, "Statistics of OSPF process %ld%s", |
| 190 | o6->process_id, VTY_NEWLINE); |
| 191 | vty_out (vty, " Running: %s%s", running_time, VTY_NEWLINE); |
| 192 | |
| 193 | #if 0 |
| 194 | ospf6_route_statistics_show (vty, o6->route_table); |
| 195 | #endif |
| 196 | |
| 197 | for (node = listhead (o6->area_list); node; nextnode (node)) |
| 198 | { |
| 199 | o6a = (struct ospf6_area *) getdata (node); |
| 200 | ospf6_area_statistics_show (vty, o6a); |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | static struct ospf6 * |
| 205 | ospf6_new () |
| 206 | { |
| 207 | struct ospf6 *new; |
| 208 | new = XMALLOC (MTYPE_OSPF6_TOP, sizeof (struct ospf6)); |
| 209 | if (new) |
| 210 | memset (new, 0, sizeof (struct ospf6)); |
| 211 | return new; |
| 212 | } |
| 213 | |
| 214 | void |
| 215 | ospf6_free (struct ospf6 *ospf6) |
| 216 | { |
| 217 | XFREE (MTYPE_OSPF6_TOP, ospf6); |
| 218 | } |
| 219 | |
| 220 | void |
| 221 | ospf6_top_topology_add (struct ospf6_route_req *request) |
| 222 | { |
| 223 | assert (request->route.type == OSPF6_DEST_TYPE_ROUTER); |
| 224 | if (CHECK_FLAG (request->path.router_bits, OSPF6_ROUTER_LSA_BIT_E)) |
| 225 | ospf6_asbr_asbr_entry_add (request); |
| 226 | } |
| 227 | |
| 228 | void |
| 229 | ospf6_top_topology_remove (struct ospf6_route_req *request) |
| 230 | { |
| 231 | assert (request->route.type == OSPF6_DEST_TYPE_ROUTER); |
| 232 | if (CHECK_FLAG (request->path.router_bits, OSPF6_ROUTER_LSA_BIT_E)) |
| 233 | ospf6_asbr_asbr_entry_remove (request); |
| 234 | } |
| 235 | |
| 236 | struct ospf6 * |
| 237 | ospf6_create (unsigned long process_id) |
| 238 | { |
| 239 | struct ospf6 *o6; |
| 240 | char namebuf[64]; |
| 241 | |
| 242 | o6 = ospf6_new (); |
| 243 | |
| 244 | /* initialize */ |
| 245 | gettimeofday (&o6->starttime, (struct timezone *)NULL); |
| 246 | o6->process_id = process_id; |
| 247 | o6->version = OSPF6_VERSION; |
| 248 | o6->area_list = list_new (); |
| 249 | |
| 250 | o6->lsdb = ospf6_lsdb_create (); |
| 251 | |
| 252 | o6->foreach_area = ospf6_top_foreach_area; |
| 253 | o6->foreach_if = ospf6_top_foreach_interface; |
| 254 | o6->foreach_nei = ospf6_top_foreach_neighbor; |
| 255 | |
| 256 | snprintf (namebuf, sizeof (namebuf), "InterTopology table"); |
| 257 | o6->topology_table = ospf6_route_table_create (namebuf); |
| 258 | ospf6_route_hook_register (ospf6_top_topology_add, |
| 259 | ospf6_top_topology_add, |
| 260 | ospf6_top_topology_remove, |
| 261 | o6->topology_table); |
| 262 | |
| 263 | #if 0 |
| 264 | snprintf (namebuf, sizeof (namebuf), "External table"); |
| 265 | o6->external_table = ospf6_route_table_create (namebuf); |
| 266 | ospf6_route_hook_register (ospf6_asbr_external_route_add, |
| 267 | ospf6_asbr_external_route_add, |
| 268 | ospf6_asbr_external_route_remove, |
| 269 | o6->external_table); |
| 270 | #endif /*0*/ |
| 271 | |
| 272 | snprintf (namebuf, sizeof (namebuf), "Top route table"); |
| 273 | o6->route_table = ospf6_route_table_create (namebuf); |
| 274 | ospf6_route_hook_register (ospf6_zebra_route_update_add, |
| 275 | ospf6_zebra_route_update_add, |
| 276 | ospf6_zebra_route_update_remove, |
| 277 | o6->route_table); |
| 278 | ospf6_route_hook_register (ospf6_abr_route_add, |
| 279 | ospf6_abr_route_add, |
| 280 | ospf6_abr_route_remove, |
| 281 | o6->route_table); |
| 282 | |
| 283 | return o6; |
| 284 | } |
| 285 | |
| 286 | void |
| 287 | ospf6_delete (struct ospf6 *ospf6) |
| 288 | { |
| 289 | ospf6_route_remove_all (ospf6->route_table); |
| 290 | ospf6_free (ospf6); |
| 291 | } |
| 292 | |
| 293 | struct ospf6 * |
| 294 | ospf6_start () |
| 295 | { |
| 296 | if (ospf6) |
| 297 | return ospf6; |
| 298 | |
| 299 | ospf6 = ospf6_create (0); |
| 300 | return ospf6; |
| 301 | } |
| 302 | |
| 303 | void |
| 304 | ospf6_stop () |
| 305 | { |
| 306 | if (!ospf6) |
| 307 | return; |
| 308 | |
| 309 | ospf6_delete (ospf6); |
| 310 | ospf6 = NULL; |
| 311 | } |
| 312 | |
| 313 | int |
| 314 | ospf6_is_asbr (struct ospf6 *o6) |
| 315 | { |
| 316 | int i = 0; |
| 317 | i |= ospf6_zebra_is_redistribute (ZEBRA_ROUTE_SYSTEM); |
| 318 | i |= ospf6_zebra_is_redistribute (ZEBRA_ROUTE_CONNECT); |
| 319 | i |= ospf6_zebra_is_redistribute (ZEBRA_ROUTE_STATIC); |
| 320 | i |= ospf6_zebra_is_redistribute (ZEBRA_ROUTE_KERNEL); |
| 321 | i |= ospf6_zebra_is_redistribute (ZEBRA_ROUTE_RIPNG); |
| 322 | i |= ospf6_zebra_is_redistribute (ZEBRA_ROUTE_BGP); |
| 323 | return (i); |
| 324 | } |
| 325 | |
| 326 | DEFUN (show_ipv6_ospf6_route, |
| 327 | show_ipv6_ospf6_route_cmd, |
| 328 | "show ipv6 ospf6 route", |
| 329 | SHOW_STR |
| 330 | IP6_STR |
| 331 | OSPF6_STR |
| 332 | "Routing table\n" |
| 333 | ) |
| 334 | { |
| 335 | OSPF6_CMD_CHECK_RUNNING (); |
| 336 | return ospf6_route_table_show (vty, argc, argv, ospf6->route_table); |
| 337 | } |
| 338 | |
| 339 | ALIAS (show_ipv6_ospf6_route, |
| 340 | show_ipv6_ospf6_route_prefix_cmd, |
| 341 | "show ipv6 ospf6 route (X::X|detail)", |
| 342 | SHOW_STR |
| 343 | IP6_STR |
| 344 | OSPF6_STR |
| 345 | "Routing table\n" |
| 346 | "match IPv6 prefix\n" |
| 347 | ) |
| 348 | |
| 349 | DEFUN (show_ipv6_ospf6_topology, |
| 350 | show_ipv6_ospf6_topology_cmd, |
| 351 | "show ipv6 ospf6 topology", |
| 352 | SHOW_STR |
| 353 | IP6_STR |
| 354 | OSPF6_STR |
| 355 | "Inter Area topology information\n" |
| 356 | ) |
| 357 | { |
| 358 | OSPF6_CMD_CHECK_RUNNING (); |
| 359 | return ospf6_route_table_show (vty, argc, argv, ospf6->topology_table); |
| 360 | } |
| 361 | |
| 362 | ALIAS (show_ipv6_ospf6_topology, |
| 363 | show_ipv6_ospf6_topology_router_cmd, |
| 364 | "show ipv6 ospf6 topology (A.B.C.D|<0-4294967295>|detail)", |
| 365 | SHOW_STR |
| 366 | IP6_STR |
| 367 | OSPF6_STR |
| 368 | "Inter Area topology information\n" |
| 369 | OSPF6_ROUTER_ID_STR |
| 370 | OSPF6_ROUTER_ID_STR |
| 371 | "Detailed information\n" |
| 372 | ) |
| 373 | |
| 374 | ALIAS (show_ipv6_ospf6_topology, |
| 375 | show_ipv6_ospf6_topology_router_lsid_cmd, |
| 376 | "show ipv6 ospf6 topology (A.B.C.D|<0-4294967295>) (A.B.C.D|<0-4294967295>)", |
| 377 | SHOW_STR |
| 378 | IP6_STR |
| 379 | OSPF6_STR |
| 380 | "Inter Area topology information\n" |
| 381 | OSPF6_ROUTER_ID_STR |
| 382 | OSPF6_ROUTER_ID_STR |
| 383 | OSPF6_LS_ID_STR |
| 384 | OSPF6_LS_ID_STR |
| 385 | ) |
| 386 | |
| 387 | void |
| 388 | ospf6_top_init () |
| 389 | { |
| 390 | install_element (VIEW_NODE, &show_ipv6_ospf6_route_cmd); |
| 391 | install_element (VIEW_NODE, &show_ipv6_ospf6_route_prefix_cmd); |
| 392 | install_element (VIEW_NODE, &show_ipv6_ospf6_topology_cmd); |
| 393 | install_element (VIEW_NODE, &show_ipv6_ospf6_topology_router_cmd); |
| 394 | install_element (VIEW_NODE, &show_ipv6_ospf6_topology_router_lsid_cmd); |
| 395 | install_element (ENABLE_NODE, &show_ipv6_ospf6_route_cmd); |
| 396 | install_element (ENABLE_NODE, &show_ipv6_ospf6_route_prefix_cmd); |
| 397 | install_element (ENABLE_NODE, &show_ipv6_ospf6_topology_cmd); |
| 398 | install_element (ENABLE_NODE, &show_ipv6_ospf6_topology_router_cmd); |
| 399 | install_element (ENABLE_NODE, &show_ipv6_ospf6_topology_router_lsid_cmd); |
| 400 | } |
| 401 | |