]>
Commit | Line | Data |
---|---|---|
8e1f6512 DS |
1 | /* |
2 | * agg_table - Aggregate Table Header | |
3 | * Copyright (C) 2018 Cumulus Networks, Inc. | |
4 | * Donald Sharp | |
5 | * | |
6 | * FRR 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 | * FRR 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 | #ifndef __AGG_TABLE_H__ | |
21 | #define __AGG_TABLE_H__ | |
22 | ||
23 | #include "prefix.h" | |
24 | #include "table.h" | |
25 | ||
5e244469 RW |
26 | #ifdef __cplusplus |
27 | extern "C" { | |
28 | #endif | |
29 | ||
8e1f6512 DS |
30 | struct agg_table { |
31 | struct route_table *route_table; | |
32 | ||
33 | void *info; | |
34 | }; | |
35 | ||
36 | struct agg_node { | |
37 | /* | |
38 | * Caution these must be the very first fields | |
39 | * @see agg_node_to_rnode | |
40 | * @see agg_node_from_rnode | |
41 | */ | |
42 | ROUTE_NODE_FIELDS | |
43 | ||
c2b23567 DS |
44 | /* Aggregation. */ |
45 | void *aggregate; | |
8e1f6512 DS |
46 | }; |
47 | ||
48 | static inline struct route_node *agg_node_to_rnode(struct agg_node *node) | |
49 | { | |
50 | return (struct route_node *)node; | |
51 | } | |
52 | ||
53 | static inline struct agg_node *agg_node_from_rnode(struct route_node *node) | |
54 | { | |
55 | return (struct agg_node *)node; | |
56 | } | |
57 | ||
58 | static inline struct agg_node *agg_lock_node(struct agg_node *node) | |
59 | { | |
60 | return (struct agg_node *)route_lock_node(agg_node_to_rnode(node)); | |
61 | } | |
62 | ||
63 | static inline void agg_unlock_node(struct agg_node *node) | |
64 | { | |
d90b788e | 65 | route_unlock_node(agg_node_to_rnode(node)); |
8e1f6512 DS |
66 | } |
67 | ||
68 | static inline void agg_set_table_info(struct agg_table *atable, void *data) | |
69 | { | |
70 | atable->info = data; | |
71 | } | |
72 | ||
73 | static inline void *agg_get_table_info(struct agg_table *atable) | |
74 | { | |
75 | return atable->info; | |
76 | } | |
77 | ||
78 | static inline struct agg_node *agg_route_top(struct agg_table *table) | |
79 | { | |
80 | return agg_node_from_rnode(route_top(table->route_table)); | |
81 | } | |
82 | ||
83 | static inline struct agg_node *agg_route_next(struct agg_node *node) | |
84 | { | |
85 | return agg_node_from_rnode(route_next(agg_node_to_rnode(node))); | |
86 | } | |
87 | ||
88 | static inline struct agg_node *agg_node_get(struct agg_table *table, | |
89 | struct prefix *p) | |
90 | { | |
91 | return agg_node_from_rnode(route_node_get(table->route_table, p)); | |
92 | } | |
93 | ||
94 | static inline struct agg_node * | |
95 | agg_node_lookup(const struct agg_table *const table, struct prefix *p) | |
96 | { | |
97 | return agg_node_from_rnode(route_node_lookup(table->route_table, p)); | |
98 | } | |
99 | ||
100 | static inline struct agg_node *agg_route_next_until(struct agg_node *node, | |
101 | struct agg_node *limit) | |
102 | { | |
103 | struct route_node *rnode; | |
104 | ||
105 | rnode = route_next_until(agg_node_to_rnode(node), | |
106 | agg_node_to_rnode(limit)); | |
107 | ||
108 | return agg_node_from_rnode(rnode); | |
109 | } | |
110 | ||
111 | static inline struct agg_node *agg_node_match(struct agg_table *table, | |
112 | struct prefix *p) | |
113 | { | |
114 | return agg_node_from_rnode(route_node_match(table->route_table, p)); | |
115 | } | |
116 | ||
117 | static inline struct agg_node *agg_node_parent(struct agg_node *node) | |
118 | { | |
119 | struct route_node *rn = agg_node_to_rnode(node); | |
120 | ||
121 | return agg_node_from_rnode(rn->parent); | |
122 | } | |
123 | ||
124 | static inline struct agg_node *agg_node_left(struct agg_node *node) | |
125 | { | |
126 | struct route_node *rn = agg_node_to_rnode(node); | |
127 | ||
128 | return agg_node_from_rnode(rn->l_left); | |
129 | } | |
130 | ||
131 | static inline struct agg_node *agg_node_right(struct agg_node *node) | |
132 | { | |
133 | struct route_node *rn = agg_node_to_rnode(node); | |
134 | ||
135 | return agg_node_from_rnode(rn->l_right); | |
136 | } | |
137 | ||
138 | extern struct agg_table *agg_table_init(void); | |
139 | ||
140 | static inline void agg_table_finish(struct agg_table *atable) | |
141 | { | |
142 | route_table_finish(atable->route_table); | |
143 | atable->route_table = NULL; | |
144 | ||
145 | XFREE(MTYPE_TMP, atable); | |
146 | } | |
147 | ||
148 | static inline struct agg_node *agg_route_table_top(struct agg_node *node) | |
149 | { | |
150 | return (struct agg_node *)route_top(node->table); | |
151 | } | |
152 | ||
153 | static inline struct agg_table *agg_get_table(struct agg_node *node) | |
154 | { | |
6ca30e9e | 155 | return (struct agg_table *)route_table_get_info(node->table); |
8e1f6512 | 156 | } |
5e244469 RW |
157 | |
158 | #ifdef __cplusplus | |
159 | } | |
160 | #endif | |
161 | ||
8e1f6512 | 162 | #endif |