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