summaryrefslogtreecommitdiffstats
path: root/lib/agg_table.h
blob: e98476f1b7d3e0cda389daa41c866194dcc97177 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
 * agg_table - Aggregate Table Header
 * Copyright (C) 2018 Cumulus Networks, Inc.
 *               Donald Sharp
 *
 * FRR is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2, or (at your option) any
 * later version.
 *
 * FRR is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; see the file COPYING; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 */
#ifndef __AGG_TABLE_H__
#define __AGG_TABLE_H__

#include "prefix.h"
#include "table.h"

#ifdef __cplusplus
extern "C" {
#endif

struct agg_table {
	struct route_table *route_table;

	void *info;
};

struct agg_node {
	/*
	 * Caution these must be the very first fields
	 * @see agg_node_to_rnode
	 * @see agg_node_from_rnode
	 */
	ROUTE_NODE_FIELDS

	/* Aggregation. */
	void *aggregate;
};

static inline struct route_node *agg_node_to_rnode(struct agg_node *node)
{
	return (struct route_node *)node;
}

static inline struct agg_node *agg_node_from_rnode(struct route_node *node)
{
	return (struct agg_node *)node;
}

static inline struct agg_node *agg_lock_node(struct agg_node *node)
{
	return (struct agg_node *)route_lock_node(agg_node_to_rnode(node));
}

static inline void agg_unlock_node(struct agg_node *node)
{
	route_unlock_node(agg_node_to_rnode(node));
}

static inline void agg_set_table_info(struct agg_table *atable, void *data)
{
	atable->info = data;
}

static inline void *agg_get_table_info(struct agg_table *atable)
{
	return atable->info;
}

static inline struct agg_node *agg_route_top(struct agg_table *table)
{
	return agg_node_from_rnode(route_top(table->route_table));
}

static inline struct agg_node *agg_route_next(struct agg_node *node)
{
	return agg_node_from_rnode(route_next(agg_node_to_rnode(node)));
}

static inline struct agg_node *agg_node_get(struct agg_table *table,
					    const struct prefix *p)
{
	return agg_node_from_rnode(route_node_get(table->route_table, p));
}

static inline struct agg_node *
agg_node_lookup(const struct agg_table *const table, const struct prefix *p)
{
	return agg_node_from_rnode(route_node_lookup(table->route_table, p));
}

static inline struct agg_node *agg_route_next_until(struct agg_node *node,
						    struct agg_node *limit)
{
	struct route_node *rnode;

	rnode = route_next_until(agg_node_to_rnode(node),
				agg_node_to_rnode(limit));

	return agg_node_from_rnode(rnode);
}

static inline struct agg_node *agg_node_match(struct agg_table *table,
					      const struct prefix *p)
{
	return agg_node_from_rnode(route_node_match(table->route_table, p));
}

static inline struct agg_node *agg_node_parent(struct agg_node *node)
{
	struct route_node *rn = agg_node_to_rnode(node);

	return agg_node_from_rnode(rn->parent);
}

static inline struct agg_node *agg_node_left(struct agg_node *node)
{
	struct route_node *rn = agg_node_to_rnode(node);

	return agg_node_from_rnode(rn->l_left);
}

static inline struct agg_node *agg_node_right(struct agg_node *node)
{
	struct route_node *rn = agg_node_to_rnode(node);

	return agg_node_from_rnode(rn->l_right);
}

extern struct agg_table *agg_table_init(void);

static inline void agg_table_finish(struct agg_table *atable)
{
	route_table_finish(atable->route_table);
	atable->route_table = NULL;

	XFREE(MTYPE_TMP, atable);
}

static inline struct agg_node *agg_route_table_top(struct agg_node *node)
{
	return (struct agg_node *)route_top(node->table);
}

static inline struct agg_table *agg_get_table(struct agg_node *node)
{
	return (struct agg_table *)route_table_get_info(node->table);
}

static inline const struct prefix *
agg_node_get_prefix(const struct agg_node *node)
{
	return &node->p;
}

#ifdef _FRR_ATTRIBUTE_PRINTFRR
#pragma FRR printfrr_ext "%pRN"  (struct agg_node *)
#endif

#ifdef __cplusplus
}
#endif

#endif