]> git.proxmox.com Git - mirror_frr.git/blob - ospf6d/ospf6_spf.h
Merge pull request #8252 from SaiGomathiN/8249
[mirror_frr.git] / ospf6d / ospf6_spf.h
1 /*
2 * Copyright (C) 2003 Yasuhiro Ohara
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 along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #ifndef OSPF6_SPF_H
22 #define OSPF6_SPF_H
23
24 #include "typesafe.h"
25 #include "ospf6_top.h"
26 #include "lib/json.h"
27
28 /* Debug option */
29 extern unsigned char conf_debug_ospf6_spf;
30 #define OSPF6_DEBUG_SPF_PROCESS 0x01
31 #define OSPF6_DEBUG_SPF_TIME 0x02
32 #define OSPF6_DEBUG_SPF_DATABASE 0x04
33 #define OSPF6_DEBUG_SPF_ON(level) (conf_debug_ospf6_spf |= (level))
34 #define OSPF6_DEBUG_SPF_OFF(level) (conf_debug_ospf6_spf &= ~(level))
35 #define IS_OSPF6_DEBUG_SPF(level) \
36 (conf_debug_ospf6_spf & OSPF6_DEBUG_SPF_##level)
37
38 PREDECL_SKIPLIST_NONUNIQ(vertex_pqueue);
39 /* Transit Vertex */
40 struct ospf6_vertex {
41 /* type of this vertex */
42 uint8_t type;
43
44 /* Vertex Identifier */
45 struct prefix vertex_id;
46
47 struct vertex_pqueue_item pqi;
48
49 /* Identifier String */
50 char name[128];
51
52 /* Associated Area */
53 struct ospf6_area *area;
54
55 /* Associated LSA */
56 struct ospf6_lsa *lsa;
57
58 /* Distance from Root (i.e. Cost) */
59 uint32_t cost;
60
61 /* Router hops to this node */
62 uint8_t hops;
63
64 /* capability bits */
65 uint8_t capability;
66
67 /* Optional capabilities */
68 uint8_t options[3];
69
70 /* For tree display */
71 struct ospf6_vertex *parent;
72 struct list *child_list;
73
74 /* nexthops to this node */
75 struct list *nh_list;
76 uint32_t link_id;
77 };
78
79 #define OSPF6_VERTEX_TYPE_ROUTER 0x01
80 #define OSPF6_VERTEX_TYPE_NETWORK 0x02
81 #define VERTEX_IS_TYPE(t, v) ((v)->type == OSPF6_VERTEX_TYPE_##t ? 1 : 0)
82
83 /* What triggered the SPF? */
84 #define OSPF6_SPF_FLAGS_ROUTER_LSA_ADDED (1 << 0)
85 #define OSPF6_SPF_FLAGS_ROUTER_LSA_REMOVED (1 << 1)
86 #define OSPF6_SPF_FLAGS_NETWORK_LSA_ADDED (1 << 2)
87 #define OSPF6_SPF_FLAGS_NETWORK_LSA_REMOVED (1 << 3)
88 #define OSPF6_SPF_FLAGS_LINK_LSA_ADDED (1 << 4)
89 #define OSPF6_SPF_FLAGS_LINK_LSA_REMOVED (1 << 5)
90 #define OSPF6_SPF_FLAGS_ROUTER_LSA_ORIGINATED (1 << 6)
91 #define OSPF6_SPF_FLAGS_NETWORK_LSA_ORIGINATED (1 << 7)
92 #define OSPF6_SPF_FLAGS_CONFIG_CHANGE (1 << 8)
93
94 static inline void ospf6_set_spf_reason(struct ospf6 *ospf, unsigned int reason)
95 {
96 ospf->spf_reason |= reason;
97 }
98
99 static inline void ospf6_reset_spf_reason(struct ospf6 *ospf)
100 {
101 ospf->spf_reason = 0;
102 }
103
104 static inline unsigned int ospf6_lsadd_to_spf_reason(struct ospf6_lsa *lsa)
105 {
106 unsigned int reason = 0;
107
108 switch (ntohs(lsa->header->type)) {
109 case OSPF6_LSTYPE_ROUTER:
110 reason = OSPF6_SPF_FLAGS_ROUTER_LSA_ADDED;
111 break;
112 case OSPF6_LSTYPE_NETWORK:
113 reason = OSPF6_SPF_FLAGS_NETWORK_LSA_ADDED;
114 break;
115 case OSPF6_LSTYPE_LINK:
116 reason = OSPF6_SPF_FLAGS_LINK_LSA_ADDED;
117 break;
118 default:
119 break;
120 }
121 return (reason);
122 }
123
124 static inline unsigned int ospf6_lsremove_to_spf_reason(struct ospf6_lsa *lsa)
125 {
126 unsigned int reason = 0;
127
128 switch (ntohs(lsa->header->type)) {
129 case OSPF6_LSTYPE_ROUTER:
130 reason = OSPF6_SPF_FLAGS_ROUTER_LSA_REMOVED;
131 break;
132 case OSPF6_LSTYPE_NETWORK:
133 reason = OSPF6_SPF_FLAGS_NETWORK_LSA_REMOVED;
134 break;
135 case OSPF6_LSTYPE_LINK:
136 reason = OSPF6_SPF_FLAGS_LINK_LSA_REMOVED;
137 break;
138 default:
139 break;
140 }
141 return (reason);
142 }
143
144 extern void ospf6_spf_table_finish(struct ospf6_route_table *result_table);
145 extern void ospf6_spf_calculation(uint32_t router_id,
146 struct ospf6_route_table *result_table,
147 struct ospf6_area *oa);
148 extern void ospf6_spf_schedule(struct ospf6 *ospf, unsigned int reason);
149
150 extern void ospf6_spf_display_subtree(struct vty *vty, const char *prefix,
151 int rest, struct ospf6_vertex *v,
152 json_object *json_obj, bool use_json);
153
154 extern void ospf6_spf_config_write(struct vty *vty, struct ospf6 *ospf6);
155 extern int config_write_ospf6_debug_spf(struct vty *vty);
156 extern void install_element_ospf6_debug_spf(void);
157 extern void ospf6_spf_init(void);
158 extern void ospf6_spf_reason_string(unsigned int reason, char *buf, int size);
159 extern struct ospf6_lsa *ospf6_create_single_router_lsa(struct ospf6_area *area,
160 struct ospf6_lsdb *lsdb,
161 uint32_t adv_router);
162 extern void ospf6_remove_temp_router_lsa(struct ospf6_area *area);
163
164 #endif /* OSPF6_SPF_H */