summaryrefslogtreecommitdiff
path: root/cesar/cp2/cco/bw/bw.h
blob: 2e551ceaf8f10451730db5fc498f7bd528a58ce9 (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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
#ifndef cp2_cco_bw_h
#define cp2_cco_bw_h
/* Cesar project {{{
 *
 * Copyright (C) 2008 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    cp_cco_bw.h
 * \brief   « brief description »
 * \ingroup « module »
 *
 * « long description »
 */
#include "cp2/cp.h"
#include "cp2/cco/bw/bw_prio_heap.h"
#include "lib/list.h"
#include "lib/set.h"
#include "cp2/conn/conn.h"

enum cp_cco_bw_persistence_t
{

    CP_CCO_BW_PERSISTENCE_NOT_PERSISTENT,
    CP_CCO_BW_PERSISTENCE_PERSISTENT
};
typedef enum cp_cco_bw_persistence_t cp_cco_bw_persistence_t;

/**
 * Allocation of a connection
 */
struct cp_cco_bw_alloc_t
{
    /**
     * Start time persistent flag.
     */
    bool stpf;

    /**
     * Start Time of the allocation ATU
     */
    u16 st_atu;

    /**
     * End Time of the allocation ATU
     */
    u16 et_atu;

    /**
     * GLID of the allocation
     */
    u8 glid;

    /**
     * Connection identifier
     */
    u16 cid;

    /**
     * Persistence of the allocation. Value not defined yet (maybe regarding
     * to the priority)
     */
    cp_cco_bw_persistence_t persistence;

    /**
     * Duration of the persitence in number of beacon period
     */
    u8 duration_persistence;

    /**
     * Node of the list of alloc
     */
    list_node_t node;

    /**
     * Node for beacon use
     */
    set_node_t set_node;

};
typedef struct cp_cco_bw_alloc_t cp_cco_bw_alloc_t;

/**
 * Bandwidth Manager Module. - Create the schedule  - Allocate a specific
 * connection - finalise and return a schedule (used by the Beacon module
 * only)
 */
struct cp_cco_bw_t
{
    /**
     * Priority heap list
     */
    cp_cco_bw_prio_heap_t prio_heap[CP_CCO_BW_NB_PRIORITY_HEAPS];

    /**
     * Actual schedule
     */
    list_t actual_schedule;

    /**
     * Finalised schedule
     */
    list_t finalised_schedule;

    /**
     * Number of persistent allocation
     */
    u16 nb_alloc_pers;

    /**
     * Number of non persistent alloaction
     */
    u16 nb_alloc_no_pers;
};
typedef struct cp_cco_bw_t cp_cco_bw_t;

/**
 * Allocate at the beginning of the beacon period
 * \param  ctx  Control plane context
 * \param  duration  duration of the allocation
 * \param  glid  GLID of the allocation
 *
 * Only allocate at the first free space doesnt take care of the time between
 * the allocations
 */
void
cp_cco_bw_alloc_beginning (cp_t *ctx, u16 duration, u8 glid);

/**
 * Allocate a complete Schedule .
 * \param  ctx  Control Plane Context
 *
 */
void
cp_cco_bw_alloc_sched (cp_t *ctx);

/**
 * Allocates a unique connection.
 * \param  ctx  Control Plane Context
 * \param  conn  Connection to allocate
 * \return  Result of the allocation True if the allocation has been done
 * False if not enough free allocation time
 *
 */
bool
cp_cco_bw_alloc (cp_t *ctx, cp_link_t *link, u16 cid);

/**
 * This function will initialise a new schedule.
 * \param  ctx  control plane context
 * \return  \todo fill this
 *
 */
void
cp_cco_bw_new_sched (cp_t *ctx);


/**
 * Finalise schedule
 *
 * \param ctx control plane context
 * This function as to be called before asking for the schedule
 *  Fills the free fields with bonus allocation if there is not enough
 * time for CSMA. Otherwise it fills with CSMA
 */
void
cp_cco_bw_finalise_sched(cp_t *ctx);

/**
 * Move to the next free time allocation. Set the previous and next
 * allocation.
 * \param  ctx  Control Plane Context
 * \param  prev_alloc  Previous allocation
 * \param  next_alloc  Next allocation
 * \return  true if there is another free time space otherwise false and of
 * the allocations
 *
 */
bool
cp_cco_bw_set_next_free_time_space(cp_t *ctx,
                                   cp_cco_bw_alloc_t **prev_alloc,
                                   cp_cco_bw_alloc_t **next_alloc);
/**
 * Return the first element of schedule persistent or not
 * persistent.
 * \param  ctx  Control Plane Context
 * \param persistence persistent or not persistent
 * \return  the first element of the schedule
 *
 */
cp_cco_bw_alloc_t*
cp_cco_bw_get_first_alloc (cp_t *ctx, cp_cco_bw_persistence_t persistence);

/**
 * Return the next allocation persistent or not
 * \param  ctx  control plane context
 * \param  prev_alloc  previous allocation
 * \return  the next allocation
 *
 */
cp_cco_bw_alloc_t*
cp_cco_bw_get_next_alloc (cp_t *ctx, cp_cco_bw_alloc_t *prev_alloc);


/**
 * Return the number of allocation persistent or not
 * \param  ctx  control plane context
 * \param persistence persistent or not persistent
 * \return  return the number of allocation
 *
 */
u16
cp_cco_bw_get_nb_alloc(cp_t *ctx, cp_cco_bw_persistence_t persistence);

/**
 * Init of the BW manager.
 * \param  ctx  Control Plane Context
 *
 */
void
cp_cco_bw_init (cp_t* ctx);

/**
 * uninit the bandwidth manager allocations.
 * \param  ctx control plane context
 *
 */
void
cp_cco_bw_uninit (cp_t* ctx);

/** Add an allocation
 * \param  ctx  the control plane context.
 * \param  alloc  the allocation.
 */
void
cp_cco_bw_alloc_add (cp_t *ctx, cp_cco_bw_alloc_t *alloc);

/** Remove an allocation
 * \param  ctx  the control plane context.
 * \param  alloc  the allocation.
 * \return result of the operation true if remove donne
 */
void
cp_cco_bw_alloc_remove (cp_t *ctx, cp_cco_bw_alloc_t *alloc);

/** Remove an allocation regarding its CID
 * \param  ctx  the control plane context.
 * \param  cid connection identifier
 * \return result of the operation true if remove donne
 */
void
cp_cco_bw_alloc_remove_cid (cp_t *ctx, u16 cid);

/**
 * Returns the first allocation of a connection
 * \param  ctx  Control Plane context
 * \param  cid  Connection identifier
 * \return  the allocation
 *
 * This function is used with the cp_cco_bw_alloc_get_next function because of
 * the multiple TXOPs.
 *
 */
cp_cco_bw_alloc_t*
cp_cco_bw_alloc_get_first_txop(cp_t *ctx, u16 cid);

/**
 * Return the next allocation of the same connection
 * \param  ctx  Control Plane context
 * \param  alloc  previous allocation
 * \return  The next allocation of the same connection. If there is none is
 * return NULL.
 *
 * This function is necessary because of the multiple TXOP possibilites.
 */

cp_cco_bw_alloc_t*
cp_cco_bw_alloc_get_next_txop(cp_t *ctx, cp_cco_bw_alloc_t* alloc);
/**
 * Uninit the actual schedule allocations
 * \param  ctx  Control Plane context
 *
 */
void
cp_cco_bw_uninit_actual_sched(cp_t *ctx);

#endif /* cp_cco_bw_h */