]>
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 | ||
26 | struct agg_table { | |
27 | struct route_table *route_table; | |
28 | ||
29 | void *info; | |
30 | }; | |
31 | ||
32 | struct agg_node { | |
33 | /* | |
34 | * Caution these must be the very first fields | |
35 | * @see agg_node_to_rnode | |
36 | * @see agg_node_from_rnode | |
37 | */ | |
38 | ROUTE_NODE_FIELDS | |
39 | ||
40 | }; | |
41 | ||
42 | static inline struct route_node *agg_node_to_rnode(struct agg_node *node) | |
43 | { | |
44 | return (struct route_node *)node; | |
45 | } | |
46 | ||
47 | static inline struct agg_node *agg_node_from_rnode(struct route_node *node) | |
48 | { | |
49 | return (struct agg_node *)node; | |
50 | } | |
51 | ||
52 | static inline struct agg_node *agg_lock_node(struct agg_node *node) | |
53 | { | |
54 | return (struct agg_node *)route_lock_node(agg_node_to_rnode(node)); | |
55 | } | |
56 | ||
57 | static inline void agg_unlock_node(struct agg_node *node) | |
58 | { | |
59 | return route_unlock_node(agg_node_to_rnode(node)); | |
60 | } | |
61 | ||
62 | static inline void agg_set_table_info(struct agg_table *atable, void *data) | |
63 | { | |
64 | atable->info = data; | |
65 | } | |
66 | ||
67 | static inline void *agg_get_table_info(struct agg_table *atable) | |
68 | { | |
69 | return atable->info; | |
70 | } | |
71 | ||
72 | static inline struct agg_node *agg_route_top(struct agg_table *table) | |
73 | { | |
74 | return agg_node_from_rnode(route_top(table->route_table)); | |
75 | } | |
76 | ||
77 | static inline struct agg_node *agg_route_next(struct agg_node *node) | |
78 | { | |
79 | return agg_node_from_rnode(route_next(agg_node_to_rnode(node))); | |
80 | } | |
81 | ||
82 | static inline struct agg_node *agg_node_get(struct agg_table *table, | |
83 | struct prefix *p) | |
84 | { | |
85 | return agg_node_from_rnode(route_node_get(table->route_table, p)); | |
86 | } | |
87 | ||
88 | static inline struct agg_node * | |
89 | agg_node_lookup(const struct agg_table *const table, struct prefix *p) | |
90 | { | |
91 | return agg_node_from_rnode(route_node_lookup(table->route_table, p)); | |
92 | } | |
93 | ||
94 | static inline struct agg_node *agg_route_next_until(struct agg_node *node, | |
95 | struct agg_node *limit) | |
96 | { | |
97 | struct route_node *rnode; | |
98 | ||
99 | rnode = route_next_until(agg_node_to_rnode(node), | |
100 | agg_node_to_rnode(limit)); | |
101 | ||
102 | return agg_node_from_rnode(rnode); | |
103 | } | |
104 | ||
105 | static inline struct agg_node *agg_node_match(struct agg_table *table, | |
106 | struct prefix *p) | |
107 | { | |
108 | return agg_node_from_rnode(route_node_match(table->route_table, p)); | |
109 | } | |
110 | ||
111 | static inline struct agg_node *agg_node_parent(struct agg_node *node) | |
112 | { | |
113 | struct route_node *rn = agg_node_to_rnode(node); | |
114 | ||
115 | return agg_node_from_rnode(rn->parent); | |
116 | } | |
117 | ||
118 | static inline struct agg_node *agg_node_left(struct agg_node *node) | |
119 | { | |
120 | struct route_node *rn = agg_node_to_rnode(node); | |
121 | ||
122 | return agg_node_from_rnode(rn->l_left); | |
123 | } | |
124 | ||
125 | static inline struct agg_node *agg_node_right(struct agg_node *node) | |
126 | { | |
127 | struct route_node *rn = agg_node_to_rnode(node); | |
128 | ||
129 | return agg_node_from_rnode(rn->l_right); | |
130 | } | |
131 | ||
132 | extern struct agg_table *agg_table_init(void); | |
133 | ||
134 | static inline void agg_table_finish(struct agg_table *atable) | |
135 | { | |
136 | route_table_finish(atable->route_table); | |
137 | atable->route_table = NULL; | |
138 | ||
139 | XFREE(MTYPE_TMP, atable); | |
140 | } | |
141 | ||
142 | static inline struct agg_node *agg_route_table_top(struct agg_node *node) | |
143 | { | |
144 | return (struct agg_node *)route_top(node->table); | |
145 | } | |
146 | ||
147 | static inline struct agg_table *agg_get_table(struct agg_node *node) | |
148 | { | |
149 | return (struct agg_table *)node->table->info; | |
150 | } | |
151 | #endif |