summaryrefslogtreecommitdiff
path: root/cesar/cl/cl_mactotei.h
blob: d403861b457fdac45e6aa28f5e5882b90ae58bf5 (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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#ifndef CL_MACTOTEI_H_
#define CL_MACTOTEI_H_

/* Cesar project {{{
 *
 * Copyright (C) 2007 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    cl/cl_mactotei.h
 * \brief   MAC to TEI table interface between the CL and the CP.
 * \ingroup cl
 *
 * The MAC to TEI table associate a MAC address to a TEI and a tag. The tag is
 * used to know if the entry is bridged entry or not (in case of a bridge
 * entry, the tag will correspond to the entry acting as a bridge for this MAC
 * address).
 */

#include "cl/cl.h"
#include "lib/mac_lookup_table.h"

/**
 * Sorted MAC to TEI table.
 * It is based on the indexed MAC lookup table.
 */
typedef struct mac_lookup_table_t cl_mactotei_table_t;

/**
 * Non-sorted MAC to TEI table.
 * It is based on the non-sorted MAC lookup table.
 */
typedef struct mac_lookup_block_header_t cl_mactotei_blk_t;

/**
 * Struct to export one entry of mactotei.
 */
struct cl_mactotei_entry_t
{
    /** A MAC address*/
    mac_t mac;
    /** A TEI */
    uint tei;
    u8 tag;
};
typedef struct cl_mactotei_entry_t cl_mactotei_entry_t;

BEGIN_DECLS

/**
 * Create a new table to be filled by the CP.
 *
 * \return  a pointer to the new block to be fill with the mac to tei table
 * data
 */
cl_mactotei_blk_t *
cl_mactotei_new (void);

/**
 * Add a new tupple (Mac address, TEI) to the MAC to TEI table.
 *
 * \param  table  the non-sorted MAC to TEI table.
 * \param  mac_addr  the mac addr to add.
 * \param  tei  the TEI corresponding to the MAC address.
 * \param  tag  a tag provided by the CP.
 */
void
cl_mactotei_addr_add (cl_mactotei_blk_t *table, mac_t mac_addr,
                      uint tei, uint tag);

/**
 * Request the CL to copy all the entries from the actual MAC to TEI table
 * corresponding to a TEI and a tag to the new one.
 *
 * \param  ctx  the CL context.
 * \param  table  the new MAC to TEI table to fill.
 * \param  tei  the corresponding TEI entries to copy.
 * \param  tag  the corresponding tag entries to copy.
 */
void
cl_mactotei_copy_tei_and_tag (cl_t *ctx, cl_mactotei_blk_t *table,
                              uint tei, uint tag);

/**
 * Request the CL to copy all the entries from the actual MAC to TEI table
 * corresponding to a TEI.
 *
 * \param  ctx  the CL context.
 * \param  table  the new MAC to TEI table to fill.
 * \param  tei  the corresponding TEI entries to copy.
 */
void
cl_mactotei_copy_tei (cl_t *ctx, cl_mactotei_blk_t *table,
                      uint tei);

/**
 * Find a mac address in the table using a dichotomy search.
 *
 * \param  ctx  the CL context.
 * \param  mac  the mac address to look for.
 * \return  the TEI corresponding to the mac address if the entry exists.
 * Otherwise, it returns MAC_TEI_UNASSOCIATED.
 */
uint
cl_mactotei_table_find_tei_from_mac (cl_t *ctx, mac_t mac);

/**
 * Find the tei and tag associated to a mac address in the table.
 * \param  ctx  the CL context.
 * \param  mac  the mac address to look for.
 * \param  tag  the tag associated with the tei for this mac.
 * \return  the TEI corresponding to the mac address if the entry exists.
 * Otherwise, it returns MAC_TEI_UNASSOCIATED.
 */
uint
cl_mactotei_table_find_tei_and_tag_from_mac (cl_t *ctx, mac_t mac, uint *tag);

/**
 * Request the CL to use the new table and remove the old one.
 *
 * \param  ctx  the CL context.
 * \param  table  the new table to use.
 */
void
cl_mactotei_use_table (cl_t *ctx, cl_mactotei_blk_t *table);

/**
 * Release the complete table from the memory.
 *
 * \param  ctx  the convergence layer context
 */
void
cl_mactotei_release_table (cl_t *ctx);

/**
 * Copy all the entries from the current MAC to TEI table except the ones with
 * a specific tag.
 * \param  ctx  the CL context.
 * \param  table  the table where to add copied entries.
 * \param  tag  the matching tag.
 *
 * This function can be used when you want to replace bridged entries of the
 * MAC lookup table by removing all the "old" one.
 */
void
cl_mactotei_copy_except_tag (cl_t *ctx, cl_mactotei_blk_t *table, uint tag);

/**
 * Copy all the entries from the current MAC to TEI table except the ones with
 * a specific tei.
 * \param  ctx  the CL context.
 * \param  table  the table where to add copied entries.
 * \param  tei  the matching tei.
 */
void
cl_mactotei_copy_except_tei (cl_t *ctx, cl_mactotei_blk_t *table, uint tei);

/**
 * Cancel the creation of a table.
 * \param  table  the table to cancel.
 *
 * This function is quite like \see cl_mactotei_release_table. The difference,
 * is that it takes a block as argument and not a table. You should use this
 * function when you create a new table and realise that you should cancel its
 * creation and keep the old one.
 */
void
cl_mactotei_cancel (cl_mactotei_blk_t *table);

/**
 * Add a temporary entry to the bridge table (if not already existing).
 * \param  cl  the CL context.
 * \param  tei  the TEI.
 * \param  mac  the source MAC address.
 */
void
cl_mactotei_add (cl_t *ctx, uint tei, mac_t mac);

/**
 * Get TEI associated to a given MAC address of a packet
 * \param  cl  the CL context.
 * \param  mac  the source MAC address of a packet
 *
 * This function is called every time CCo has to send_sack
 */
uint
cl_mactotei_get_tei (cl_t *ctx, mac_t mac);

/*
 * This function will return the current amount of entry in the mactotei table
 * (Used by VS_GET_MACTOTEI).
 * \param  ctx  the CL context.
 * \return  amount of entry.
 */
uint
cl_mactotei_table_size (cl_t *ctx);

/**
 * This function will copy in data one specific entry of mactotei table
 * (Used by VS_GET_MACTOTEI).
 * \param  ctx  the CL context.
 * \param  index  index in the mactotei table.
 * \param  data  structure to write the result found.
 */
void
cl_mactotei_table_get_entry (cl_t *ctx, uint index,
                             cl_mactotei_entry_t* data);

END_DECLS

#endif /*CL_MACTOTEI_H_*/