]> git.proxmox.com Git - mirror_frr.git/blame - lib/nexthop_group.h
Merge pull request #13649 from donaldsharp/unlock_the_node_or_else
[mirror_frr.git] / lib / nexthop_group.h
CommitLineData
acddc0ed 1// SPDX-License-Identifier: GPL-2.0-or-later
7ee30f28
DS
2/*
3 * Nexthop Group structure definition.
4 * Copyright (C) 2018 Cumulus Networks, Inc.
5 * Donald Sharp
7ee30f28
DS
6 */
7
8#ifndef __NEXTHOP_GROUP__
9#define __NEXTHOP_GROUP__
10
1b7bce04 11#include <vty.h>
010dd8ed 12#include "json.h"
1b7bce04 13
5e244469
RW
14#ifdef __cplusplus
15extern "C" {
16#endif
17
569e1411
DS
18struct nhg_resilience {
19 uint16_t buckets;
20 uint32_t idle_timer;
21 uint32_t unbalanced_timer;
22 uint64_t unbalanced_time;
23};
24
7ee30f28
DS
25/*
26 * What is a nexthop group?
27 *
28 * A nexthop group is a collection of nexthops that make up
29 * the ECMP path for the route.
30 *
31 * This module provides a proper abstraction to this idea.
32 */
33struct nexthop_group {
34 struct nexthop *nexthop;
569e1411
DS
35
36 struct nhg_resilience nhgr;
7ee30f28
DS
37};
38
31919191
DS
39struct nexthop_group *nexthop_group_new(void);
40void nexthop_group_delete(struct nexthop_group **nhg);
dba32923 41
6c8b51e1 42void nexthop_group_copy(struct nexthop_group *to,
c13bfa74 43 const struct nexthop_group *from);
e1f3a8eb
MS
44
45/*
46 * Copy a list of nexthops in 'nh' to an nhg, enforcing canonical sort order
47 */
48void nexthop_group_copy_nh_sorted(struct nexthop_group *nhg,
49 const struct nexthop *nh);
50
deff170e 51void copy_nexthops(struct nexthop **tnh, const struct nexthop *nh,
7ee30f28
DS
52 struct nexthop *rparent);
53
2f000944 54uint32_t nexthop_group_hash_no_recurse(const struct nexthop_group *nhg);
1b1fe1c4 55uint32_t nexthop_group_hash(const struct nexthop_group *nhg);
9ef49038 56void nexthop_group_mark_duplicates(struct nexthop_group *nhg);
e4a1ec74
MS
57
58/* Add a nexthop to a list, enforcing the canonical sort order. */
0eb97b86
MS
59void nexthop_group_add_sorted(struct nexthop_group *nhg,
60 struct nexthop *nexthop);
1b1fe1c4 61
7ee30f28
DS
62/* The following for loop allows to iterate over the nexthop
63 * structure of routes.
64 *
65 * head: The pointer to the first nexthop in the chain.
66 *
67 * nexthop: The pointer to the current nexthop, either in the
68 * top-level chain or in a resolved chain.
69 */
70#define ALL_NEXTHOPS(head, nhop) \
71 (nhop) = (head.nexthop); \
72 (nhop); \
73 (nhop) = nexthop_next(nhop)
31919191 74
d826a734
MS
75#define ALL_NEXTHOPS_PTR(head, nhop) \
76 (nhop) = ((head)->nexthop); \
77 (nhop); \
78 (nhop) = nexthop_next(nhop)
79
c57bd6bb 80
0a8881b4
MS
81#define NHGC_NAME_SIZE 80
82
31919191
DS
83struct nexthop_group_cmd {
84
85 RB_ENTRY(nexthop_group_cmd) nhgc_entry;
86
0a8881b4
MS
87 char name[NHGC_NAME_SIZE];
88
89 /* Name of group containing backup nexthops (if set) */
90 char backup_list_name[NHGC_NAME_SIZE];
31919191
DS
91
92 struct nexthop_group nhg;
93
c57bd6bb
DS
94 struct list *nhg_list;
95
96244aca 96 QOBJ_FIELDS;
31919191
DS
97};
98RB_HEAD(nhgc_entry_head, nexthp_group_cmd);
99RB_PROTOTYPE(nhgc_entry_head, nexthop_group_cmd, nhgc_entry,
100 nexthop_group_cmd_compare)
96244aca 101DECLARE_QOBJ_TYPE(nexthop_group_cmd);
31919191
DS
102
103/*
104 * Initialize nexthop_groups. If you are interested in when
105 * a nexthop_group is added/deleted/modified, then set the
106 * appropriate callback functions to handle it in your
107 * code
f3c6dd49
DS
108 *
109 * create - The creation of the nexthop group
110 * modify - Modification of the nexthop group when not changing a nexthop
111 * ( resilience as an example )
112 * add_nexthop - A nexthop is added to the NHG
113 * del_nexthop - A nexthop is deleted from the NHG
114 * destroy - The NHG is deleted
31919191
DS
115 */
116void nexthop_group_init(
d01b92fd 117 void (*create)(const char *name),
f3c6dd49 118 void (*modify)(const struct nexthop_group_cmd *nhgc),
31919191
DS
119 void (*add_nexthop)(const struct nexthop_group_cmd *nhgc,
120 const struct nexthop *nhop),
121 void (*del_nexthop)(const struct nexthop_group_cmd *nhgc,
122 const struct nexthop *nhop),
d01b92fd 123 void (*destroy)(const char *name));
31919191 124
98cbbaea
DS
125void nexthop_group_enable_vrf(struct vrf *vrf);
126void nexthop_group_disable_vrf(struct vrf *vrf);
127void nexthop_group_interface_state_change(struct interface *ifp,
128 ifindex_t oldifindex);
129
8f8d9845
SW
130extern struct nexthop *nexthop_exists(const struct nexthop_group *nhg,
131 const struct nexthop *nh);
2171b19c
SW
132/* This assumes ordered */
133extern bool nexthop_group_equal_no_recurse(const struct nexthop_group *nhg1,
134 const struct nexthop_group *nhg2);
135
136/* This assumes ordered */
8f8d9845
SW
137extern bool nexthop_group_equal(const struct nexthop_group *nhg1,
138 const struct nexthop_group *nhg2);
d604266c
DS
139
140extern struct nexthop_group_cmd *nhgc_find(const char *name);
141
79924520 142extern void nexthop_group_write_nexthop_simple(struct vty *vty,
a251884b
DS
143 const struct nexthop *nh,
144 char *altifname);
28593bcc
MS
145extern void nexthop_group_write_nexthop(struct vty *vty,
146 const struct nexthop *nh);
5e244469 147
28593bcc
MS
148extern void nexthop_group_json_nexthop(json_object *j,
149 const struct nexthop *nh);
010dd8ed 150
454192f4
DS
151/* Return the number of nexthops in this nhg */
152extern uint8_t nexthop_group_nexthop_num(const struct nexthop_group *nhg);
153extern uint8_t
98cda54a
SW
154nexthop_group_nexthop_num_no_recurse(const struct nexthop_group *nhg);
155extern uint8_t
454192f4 156nexthop_group_active_nexthop_num(const struct nexthop_group *nhg);
98cda54a
SW
157extern uint8_t
158nexthop_group_active_nexthop_num_no_recurse(const struct nexthop_group *nhg);
454192f4 159
78d106e1
SW
160extern bool nexthop_group_has_label(const struct nexthop_group *nhg);
161
5e244469
RW
162#ifdef __cplusplus
163}
164#endif
165
7ee30f28 166#endif