1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2003 Yasuhiro Ohara
10 #include "ospf6_top.h"
14 extern unsigned char conf_debug_ospf6_spf
;
15 #define OSPF6_DEBUG_SPF_PROCESS 0x01
16 #define OSPF6_DEBUG_SPF_TIME 0x02
17 #define OSPF6_DEBUG_SPF_DATABASE 0x04
18 #define OSPF6_DEBUG_SPF_ON(level) (conf_debug_ospf6_spf |= (level))
19 #define OSPF6_DEBUG_SPF_OFF(level) (conf_debug_ospf6_spf &= ~(level))
20 #define IS_OSPF6_DEBUG_SPF(level) \
21 (conf_debug_ospf6_spf & OSPF6_DEBUG_SPF_##level)
23 #define OSPF6_ASE_CALC_INTERVAL 1
25 PREDECL_SKIPLIST_NONUNIQ(vertex_pqueue
);
28 /* type of this vertex */
31 /* Vertex Identifier */
32 struct prefix vertex_id
;
34 struct vertex_pqueue_item pqi
;
36 /* Identifier String */
40 struct ospf6_area
*area
;
43 struct ospf6_lsa
*lsa
;
45 /* Distance from Root (i.e. Cost) */
48 /* Router hops to this node */
54 /* Optional capabilities */
57 /* For tree display */
58 struct ospf6_vertex
*parent
;
59 struct list
*child_list
;
61 /* nexthops to this node */
66 #define OSPF6_VERTEX_TYPE_ROUTER 0x01
67 #define OSPF6_VERTEX_TYPE_NETWORK 0x02
68 #define VERTEX_IS_TYPE(t, v) ((v)->type == OSPF6_VERTEX_TYPE_##t ? 1 : 0)
70 /* What triggered the SPF? */
71 #define OSPF6_SPF_FLAGS_ROUTER_LSA_ADDED (1 << 0)
72 #define OSPF6_SPF_FLAGS_ROUTER_LSA_REMOVED (1 << 1)
73 #define OSPF6_SPF_FLAGS_NETWORK_LSA_ADDED (1 << 2)
74 #define OSPF6_SPF_FLAGS_NETWORK_LSA_REMOVED (1 << 3)
75 #define OSPF6_SPF_FLAGS_LINK_LSA_ADDED (1 << 4)
76 #define OSPF6_SPF_FLAGS_LINK_LSA_REMOVED (1 << 5)
77 #define OSPF6_SPF_FLAGS_ROUTER_LSA_ORIGINATED (1 << 6)
78 #define OSPF6_SPF_FLAGS_NETWORK_LSA_ORIGINATED (1 << 7)
79 #define OSPF6_SPF_FLAGS_CONFIG_CHANGE (1 << 8)
80 #define OSPF6_SPF_FLAGS_ASBR_STATUS_CHANGE (1 << 9)
81 #define OSPF6_SPF_FLAGS_GR_FINISH (1 << 10)
83 static inline void ospf6_set_spf_reason(struct ospf6
*ospf
, unsigned int reason
)
85 ospf
->spf_reason
|= reason
;
88 static inline void ospf6_reset_spf_reason(struct ospf6
*ospf
)
93 static inline unsigned int ospf6_lsadd_to_spf_reason(struct ospf6_lsa
*lsa
)
95 unsigned int reason
= 0;
97 switch (ntohs(lsa
->header
->type
)) {
98 case OSPF6_LSTYPE_ROUTER
:
99 reason
= OSPF6_SPF_FLAGS_ROUTER_LSA_ADDED
;
101 case OSPF6_LSTYPE_NETWORK
:
102 reason
= OSPF6_SPF_FLAGS_NETWORK_LSA_ADDED
;
104 case OSPF6_LSTYPE_LINK
:
105 reason
= OSPF6_SPF_FLAGS_LINK_LSA_ADDED
;
113 static inline unsigned int ospf6_lsremove_to_spf_reason(struct ospf6_lsa
*lsa
)
115 unsigned int reason
= 0;
117 switch (ntohs(lsa
->header
->type
)) {
118 case OSPF6_LSTYPE_ROUTER
:
119 reason
= OSPF6_SPF_FLAGS_ROUTER_LSA_REMOVED
;
121 case OSPF6_LSTYPE_NETWORK
:
122 reason
= OSPF6_SPF_FLAGS_NETWORK_LSA_REMOVED
;
124 case OSPF6_LSTYPE_LINK
:
125 reason
= OSPF6_SPF_FLAGS_LINK_LSA_REMOVED
;
133 extern void ospf6_spf_table_finish(struct ospf6_route_table
*result_table
);
134 extern void ospf6_spf_calculation(uint32_t router_id
,
135 struct ospf6_route_table
*result_table
,
136 struct ospf6_area
*oa
);
137 extern void ospf6_spf_schedule(struct ospf6
*ospf
, unsigned int reason
);
139 extern void ospf6_spf_display_subtree(struct vty
*vty
, const char *prefix
,
140 int rest
, struct ospf6_vertex
*v
,
141 json_object
*json_obj
, bool use_json
);
143 extern void ospf6_spf_config_write(struct vty
*vty
, struct ospf6
*ospf6
);
144 extern int config_write_ospf6_debug_spf(struct vty
*vty
);
145 extern void install_element_ospf6_debug_spf(void);
146 extern void ospf6_spf_init(void);
147 extern void ospf6_spf_reason_string(unsigned int reason
, char *buf
, int size
);
148 extern struct ospf6_lsa
*ospf6_create_single_router_lsa(struct ospf6_area
*area
,
149 struct ospf6_lsdb
*lsdb
,
150 uint32_t adv_router
);
151 extern void ospf6_remove_temp_router_lsa(struct ospf6_area
*area
);
152 extern void ospf6_ase_calculate_timer_add(struct ospf6
*ospf6
);
153 extern int ospf6_ase_calculate_route(struct ospf6
*ospf6
, struct ospf6_lsa
*lsa
,
154 struct ospf6_area
*area
);
155 #endif /* OSPF6_SPF_H */