📄 ospf6_area.c
字号:
/* * Copyright (C) 2003 Yasuhiro Ohara * * This file is part of GNU Zebra. * * GNU Zebra is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2, or (at your option) any * later version. * * GNU Zebra is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GNU Zebra; see the file COPYING. If not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */#include <zebra.h>#include "log.h"#include "memory.h"#include "linklist.h"#include "thread.h"#include "vty.h"#include "command.h"#include "if.h"#include "prefix.h"#include "table.h"#include "ospf6_proto.h"#include "ospf6_lsa.h"#include "ospf6_lsdb.h"#include "ospf6_route.h"#include "ospf6_spf.h"#include "ospf6_top.h"#include "ospf6_area.h"#include "ospf6_interface.h"#include "ospf6_intra.h"#include "ospf6_abr.h"#include "ospf6d.h"intospf6_area_cmp (void *va, void *vb){ struct ospf6_area *oa = (struct ospf6_area *) va; struct ospf6_area *ob = (struct ospf6_area *) vb; return (ntohl (oa->area_id) < ntohl (ob->area_id) ? -1 : 1);}/* schedule routing table recalculation */voidospf6_area_lsdb_hook_add (struct ospf6_lsa *lsa){ switch (ntohs (lsa->header->type)) { case OSPF6_LSTYPE_ROUTER: case OSPF6_LSTYPE_NETWORK: if (IS_OSPF6_DEBUG_EXAMIN_TYPE (lsa->header->type)) { zlog_info ("Examin %s", lsa->name); zlog_info ("Schedule SPF Calculation for %s", OSPF6_AREA (lsa->lsdb->data)->name); } ospf6_spf_schedule (OSPF6_AREA (lsa->lsdb->data)); break; case OSPF6_LSTYPE_INTRA_PREFIX: ospf6_intra_prefix_lsa_add (lsa); break; case OSPF6_LSTYPE_INTER_PREFIX: case OSPF6_LSTYPE_INTER_ROUTER: ospf6_abr_examin_summary (lsa, (struct ospf6_area *) lsa->lsdb->data); break; default: break; }}voidospf6_area_lsdb_hook_remove (struct ospf6_lsa *lsa){ switch (ntohs (lsa->header->type)) { case OSPF6_LSTYPE_ROUTER: case OSPF6_LSTYPE_NETWORK: if (IS_OSPF6_DEBUG_EXAMIN_TYPE (lsa->header->type)) { zlog_info ("LSA disappearing: %s", lsa->name); zlog_info ("Schedule SPF Calculation for %s", OSPF6_AREA (lsa->lsdb->data)->name); } ospf6_spf_schedule (OSPF6_AREA (lsa->lsdb->data)); break; case OSPF6_LSTYPE_INTRA_PREFIX: ospf6_intra_prefix_lsa_remove (lsa); break; case OSPF6_LSTYPE_INTER_PREFIX: case OSPF6_LSTYPE_INTER_ROUTER: ospf6_abr_examin_summary (lsa, (struct ospf6_area *) lsa->lsdb->data); break; default: break; }}voidospf6_area_route_hook_add (struct ospf6_route *route){ struct ospf6_route *copy = ospf6_route_copy (route); ospf6_route_add (copy, ospf6->route_table);}voidospf6_area_route_hook_remove (struct ospf6_route *route){ struct ospf6_route *copy; copy = ospf6_route_lookup_identical (route, ospf6->route_table); if (copy) ospf6_route_remove (copy, ospf6->route_table);}/* Make new area structure */struct ospf6_area *ospf6_area_create (u_int32_t area_id, struct ospf6 *o){ struct ospf6_area *oa; struct ospf6_route *route; oa = XCALLOC (MTYPE_OSPF6_AREA, sizeof (struct ospf6_area)); inet_ntop (AF_INET, &area_id, oa->name, sizeof (oa->name)); oa->area_id = area_id; oa->if_list = list_new (); oa->lsdb = ospf6_lsdb_create (oa); oa->lsdb->hook_add = ospf6_area_lsdb_hook_add; oa->lsdb->hook_remove = ospf6_area_lsdb_hook_remove; oa->lsdb_self = ospf6_lsdb_create (oa); oa->spf_table = ospf6_route_table_create (); oa->route_table = ospf6_route_table_create (); oa->route_table->hook_add = ospf6_area_route_hook_add; oa->route_table->hook_remove = ospf6_area_route_hook_remove; oa->range_table = ospf6_route_table_create (); oa->summary_prefix = ospf6_route_table_create (); oa->summary_router = ospf6_route_table_create (); /* set default options */ OSPF6_OPT_SET (oa->options, OSPF6_OPT_V6); OSPF6_OPT_SET (oa->options, OSPF6_OPT_E); OSPF6_OPT_SET (oa->options, OSPF6_OPT_R); oa->ospf6 = o; listnode_add_sort (o->area_list, oa); /* import athoer area's routes as inter-area routes */ for (route = ospf6_route_head (o->route_table); route; route = ospf6_route_next (route)) ospf6_abr_originate_summary_to_area (route, oa); return oa;}voidospf6_area_delete (struct ospf6_area *oa){ listnode n; struct ospf6_interface *oi; ospf6_route_table_delete (oa->range_table); ospf6_route_table_delete (oa->summary_prefix); ospf6_route_table_delete (oa->summary_router); /* ospf6 interface list */ for (n = listhead (oa->if_list); n; nextnode (n)) { oi = (struct ospf6_interface *) getdata (n); ospf6_interface_delete (oi); } list_delete (oa->if_list); ospf6_lsdb_delete (oa->lsdb); ospf6_lsdb_delete (oa->lsdb_self); ospf6_route_table_delete (oa->spf_table); ospf6_route_table_delete (oa->route_table);#if 0 ospf6_spftree_delete (oa->spf_tree); ospf6_route_table_delete (oa->topology_table);#endif /*0*/ THREAD_OFF (oa->thread_spf_calculation); THREAD_OFF (oa->thread_route_calculation); listnode_delete (oa->ospf6->area_list, oa); oa->ospf6 = NULL; /* free area */ XFREE (MTYPE_OSPF6_AREA, oa);}struct ospf6_area *ospf6_area_lookup (u_int32_t area_id, struct ospf6 *ospf6){ struct ospf6_area *oa; listnode n; for (n = listhead (ospf6->area_list); n; nextnode (n)) { oa = (struct ospf6_area *) getdata (n); if (oa->area_id == area_id) return oa; } return (struct ospf6_area *) NULL;}struct ospf6_area *ospf6_area_get (u_int32_t area_id, struct ospf6 *o){ struct ospf6_area *oa; oa = ospf6_area_lookup (area_id, o); if (oa == NULL) oa = ospf6_area_create (area_id, o); return oa;}voidospf6_area_enable (struct ospf6_area *oa){ listnode i; struct ospf6_interface *oi; SET_FLAG (oa->flag, OSPF6_AREA_ENABLE); for (i = listhead (oa->if_list); i; nextnode (i)) { oi = (struct ospf6_interface *) getdata (i); ospf6_interface_enable (oi); }}voidospf6_area_disable (struct ospf6_area *oa){ listnode i; struct ospf6_interface *oi; UNSET_FLAG (oa->flag, OSPF6_AREA_ENABLE); for (i = listhead (oa->if_list); i; nextnode (i)) { oi = (struct ospf6_interface *) getdata (i); ospf6_interface_disable (oi); }}voidospf6_area_show (struct vty *vty, struct ospf6_area *oa){ listnode i; struct ospf6_interface *oi; vty_out (vty, " Area %s%s", oa->name, VNL); vty_out (vty, " Number of Area scoped LSAs is %u%s", oa->lsdb->count, VNL); vty_out (vty, " Interface attached to this area:"); for (i = listhead (oa->if_list); i; nextnode (i)) { oi = (struct ospf6_interface *) getdata (i); vty_out (vty, " %s", oi->interface->name); } vty_out (vty, "%s", VNL);}#define OSPF6_CMD_AREA_LOOKUP(str, oa) \{ \
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -