summaryrefslogtreecommitdiff
path: root/cesar/cp/cco/action/test/src/garbage.c
blob: 7556de24842cff9d871b4ea89bbe3382527eedb3 (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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
/* Cesar project {{{
 *
 * Copyright (C) 2008 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    src/garbage.c
 * \brief   Test the garbage.
 * \ingroup cp_cco
 *
 */
#include <cyg/kernel/kapi.h>
#include <cyg/hal/hal_arch.h>

#include "common/std.h"
#include "lib/test.h"

#include "mac/common/ntb.h"

#include "cp/cp.h"
#include "cp/defs.h"
#include "cp/msg/msg.h"

#include "cp/cco/action/cco_action.h"
#include "cp/cco/action/inc/cco_action.h"

#include "cp/inc/context.h"

#include "cl/cl.h"
#include "cl/inc/context.h"
#include "mac/sar/inc/context.h"

#include "stdio.h"

#define TEST_CCO_ACTION_NB_STA 10

cyg_handle_t my_thread_handle;
cyg_thread  my_thread;
u8 my_thread_stack [CYGNUM_HAL_STACK_SIZE_TYPICAL];

/** The garbage function will call the tei_lease_check function to expire
 * the expired TEI lease in the station of the AVLN.
 *
 * Environment:
 *
 * * Add a thread to use the cyg_thread_delay, this thread will be use
 *   for this test case at least.
 * * Add some station with a TEI lease of 5 eCos ticks i.e. 50 ms.
 *
 * The time between the garbage function call and the time verification
 * of the test shall be greater than the 5 eCos ticks.
 *
 * At the end no more station shall be present i.e. the lease had expired.
 */
void
my_thread_entry (cyg_addrword_t data)
{
    test_t test;

    test_init (test, 0, NULL);

    test_case_begin (test, "Verify garbage result");

    printf ("Initialising the test ...\n");
    test_begin (test, "Verify")
    {
        cp_sta_t *sta;
        uint i;
        cp_t cp;
        cp_net_t *net;
        mac_config_t mac_config;
        uint phy;
        uint date;
        cl_t cl;
        sar_t sar;

        mac_ntb_init ((phy_t*) &phy, &mac_config);

        cp_cco_action_init (&cp);
        cp_sta_mgr_init (&cp);
        cp.cl = &cl;
        cp.sar = &sar;
        cp.mac_store = mac_store_init ();
        cp.mac_config = &mac_config;
        cl.mactotei = NULL;
        sar.mac_store = cp.mac_store;

        net = cp_sta_mgr_add_avln (&cp, 1, 1);
        cp_sta_mgr_set_our_avln (&cp, net);
        cp_sta_own_data_set_tei (&cp, 244);
        cp_sta_own_data_set_cco_status (&cp, true);

        printf ("Starting the test, please wait...\n");
        for (i = 0; i < TEST_CCO_ACTION_NB_STA; i++)
        {
            sta = cp_sta_mgr_sta_add (&cp, net, 0, i + 1);
            sta->tei_lease_ms = i;
            slab_release (sta);
            sta = cp_sta_mgr_sta_add (&cp, net, i + 1, i + 1);
            cp_sta_set_authenticated (&cp, sta, CP_NET_STA_ASSOC);
            sta->tei_lease_ms = i;
            slab_release (sta);
        }
        cp_sta_mgr_commit_to_dataplane (&cp);
        date = cyg_current_time () + 600;

        while (cyg_current_time () < date)
        {
            cyg_thread_delay (5);
            cp_cco_action_garbage (&cp);
        }

        test_fail_if (set_empty (&net->associated_stas) == false);
        test_fail_if (set_empty (&net->unassociated_stas) == false);

        cp_cco_action_uninit (&cp);
        cp_sta_mgr_uninit (&cp);
        mac_store_uninit (cp.mac_store);
    }
    test_end;

    test_begin (test, "Verify")
    {
        cp_sta_t *sta;
        uint i;
        test_t test;
        cp_t cp;
        cp_net_t *net;
        mac_config_t mac_config;
        uint phy;
        uint date;
        cl_t cl;
        sar_t sar;

        mac_ntb_init ((phy_t*) &phy, &mac_config);

        test_init (test, 0, NULL);

        cp_cco_action_init (&cp);
        cp_sta_mgr_init (&cp);
        cp.cl = &cl;
        cp.sar = &sar;
        cp.mac_store = mac_store_init ();
        cp.mac_config = &mac_config;
        cl.mactotei = NULL;
        sar.mac_store = cp.mac_store;

        net = cp_sta_mgr_add_avln (&cp, 1, 1);
        cp_sta_mgr_set_our_avln (&cp, net);
        cp_sta_own_data_set_tei (&cp, 244);
        cp_sta_own_data_set_cco_status (&cp, true);

        printf ("Starting the test, please wait...\n");
        for (i = 0; i < TEST_CCO_ACTION_NB_STA; i++)
        {
            sta = cp_sta_mgr_sta_add (&cp, net, i + 1, i + 1);
            cp_sta_set_assoc_confirmed (&cp, sta, false);
            sta->assoc_req_last_ms = i + 1;
            slab_release (sta);
        }

        date = CP_ASSOC_FULL_TIMEOUT_MS / 2;
        cp_sta_mgr__assoc__timeout (&cp, date);

        for (i = 0; i < TEST_CCO_ACTION_NB_STA; i++)
        {
            sta = cp_sta_mgr_sta_get_assoc (&cp, net, i + 1);
            test_fail_if (cp_sta_get_assoc_confirmed (&cp, sta) != false);
            slab_release (sta);
        }

        date = CP_ASSOC_FULL_TIMEOUT_MS + 100;
        cp_sta_mgr__assoc__timeout (&cp, date);

        for (i = 0; i < TEST_CCO_ACTION_NB_STA; i++)
        {
            sta = cp_sta_mgr_sta_get_assoc (&cp, net, i + 1);
            test_fail_if (cp_sta_get_assoc_confirmed (&cp, sta) != true);
            slab_release (sta);
        }

        date = CP_ASSOC_FULL_TIMEOUT_MS / 2;
        cp_sta_mgr__assoc__timeout (&cp, date);

        for (i = 0; i < TEST_CCO_ACTION_NB_STA; i++)
        {
            sta = cp_sta_mgr_sta_get_assoc (&cp, net, i + 1);
            test_fail_if (cp_sta_get_assoc_confirmed (&cp, sta) != true);
            slab_release (sta);
        }

        cp_cco_action_uninit (&cp);
        cp_sta_mgr_uninit (&cp);
        mac_store_uninit (cp.mac_store);
    }
    test_end;

    test_case_begin (test, "Memory leaks");

    test_begin (test, "Memory leaks verification")
    {
        test_fail_if (blk_check_memory() == false, "Memory not freed");
    }
    test_end;

    printf ("Initialising the test ...\n");
    test_begin (test, "Garbage calling the timeout association. ")
    {
        cp_sta_t *sta;
        uint i;
        cp_t cp;
        cp_net_t *net;
        mac_config_t mac_config;
        uint phy;
        uint date;
        cl_t cl;
        sar_t sar;

        mac_ntb_init ((phy_t*) &phy, &mac_config);

        cp_cco_action_init (&cp);
        cp_sta_mgr_init (&cp);
        cp.cl = &cl;
        cp.sar = &sar;
        cp.mac_store = mac_store_init ();
        cp.mac_config = &mac_config;
        cl.mactotei = NULL;
        sar.mac_store = cp.mac_store;

        net = cp_sta_mgr_add_avln (&cp, 1, 1);
        cp_sta_mgr_set_our_avln (&cp, net);
        cp_sta_own_data_set_tei (&cp, 244);
        cp_sta_own_data_set_cco_status (&cp, true);

        printf ("Starting the test, please wait...\n");
        for (i = 0; i < TEST_CCO_ACTION_NB_STA; i++)
        {
            sta = cp_sta_mgr_sta_add (&cp, net, i + 1, i + 1);
            cp_sta_set_assoc_confirmed (&cp, sta, false);
            sta->tei_lease_ms = 24000;
            sta->assoc_req_last_ms = 10 + i;
            slab_release (sta);
        }
        cp_sta_mgr_commit_to_dataplane (&cp);

        for (i = 0; i < TEST_CCO_ACTION_NB_STA; i++)
        {
            test_fail_if (cp_sta_get_assoc_confirmed (&cp, sta) != false);
        }

        date = cyg_current_time () + 2400;
        while (cyg_current_time () < date)
        {
            cyg_thread_delay (5);
            cp_cco_action_garbage (&cp);
        }

        for (i = 0; i < TEST_CCO_ACTION_NB_STA; i++)
        {
            test_fail_if (cp_sta_get_assoc_confirmed (&cp, sta) != true);
        }

        cp_cco_action_uninit (&cp);
        cp_sta_mgr_uninit (&cp);
        mac_store_uninit (cp.mac_store);
    }
    test_end;


    test_result (test);
    HAL_PLATFORM_EXIT (test_nb_failed (test) == 0 ? 0 : 1);
}

int
main (void)
{

    // Create the thread object.
    cyg_thread_create( 1, my_thread_entry, 0, "garbage", my_thread_stack,
                      CYGNUM_HAL_STACK_SIZE_TYPICAL, &my_thread_handle,
                      &my_thread);


    // Activate the thread.
    cyg_thread_resume (my_thread_handle);

    return 0;
}

void
cp_beacon_change_snid (cp_t *ctx, u8 snid)
{
}

/**
 * Send a CC_ASSOC.REQ.
 * \param  ctx  control plane context
 * \param  peer  peer information
 * \param  data  MME data to send
 */
void
cp_msg_cc_assoc_req_send (cp_t *ctx, cp_mme_peer_t *peer,
                          const cp_msg_cc_assoc_req_t *data)
{
}

/**
 * Receive a CC_ASSOC.REQ.
 * \param  ctx  control plane context
 * \param  mme  MME handle
 * \param  data  received MME data
 * \return  true on success
 */
bool
cp_msg_cc_assoc_req_receive (cp_t *ctx, cp_mme_rx_t *mme,
                             cp_msg_cc_assoc_req_t *data)
{
    return true;
}

/**
 * Send a CC_ASSOC.CNF.
 * \param  ctx  control plane context
 * \param  peer  peer information
 * \param  data  MME data to send
 */
void
cp_msg_cc_assoc_cnf_send (cp_t *ctx, cp_mme_peer_t *peer,
                          const cp_msg_cc_assoc_cnf_t *data)
{
}

/**
 * Receive a CC_ASSOC.CNF.
 * \param  ctx  control plane context
 * \param  mme  MME handle
 * \param  data  received MME data
 * \return  true on success
 */
bool
cp_msg_cc_assoc_cnf_receive (cp_t *ctx, cp_mme_rx_t *mme,
                             cp_msg_cc_assoc_cnf_t *data)
{
    return true;
}

/**
 * Send a CC_LEAVE.CNF.
 * \param  ctx  control plane context
 * \param  peer  peer information
 */
void
cp_msg_cc_leave_cnf_send (cp_t *ctx, cp_mme_peer_t *peer)
{
}

/**
 * Begin a CC_SET_TEI_MAP.IND construction.
 * \param  ctx  control plane context
 * \param  peer  peer information
 * \param  mode  update, add or delete
 * \param  sta_nb  number of stations sent
 * \return  the MME being constructed
 */
cp_mme_tx_t *
cp_msg_cc_set_tei_map_ind_send_begin (
    cp_t *ctx, cp_mme_peer_t *peer,
    enum cp_msg_cc_set_tei_map_ind_mode_t mode, uint sta_nb)
{
    return NULL;
}

/**
 *
 * Write a station to a CC_SET_TEI_MAP.IND being constructed.
 * \param  ctx  control plane context
 * \param  mme  MME being constructed
 * \param  tei  STA TEI
 * \param  mac  STA mac address
 * \param  status  STA status
 */
void
cp_msg_cc_set_tei_map_ind_send_sta (
    cp_t *ctx, cp_mme_tx_t *mme, cp_tei_t tei, mac_t mac,
    enum cp_msg_cc_set_tei_map_ind_status_t status)
{
}

/**
 * Finalise and send a CC_SET_TEI_MAP.IND message.
 * \param  ctx  control plane context
 * \param  mme  MME being constructed
 */
void
cp_msg_cc_set_tei_map_ind_send_end (cp_t *ctx, cp_mme_tx_t *mme)
{
}

/**
 * Receive a CM_GET_KEY.REQ.
 * \param  ctx  control plane context
 * \param  mme  MME handle
 * \param  data  received MME data
 * \return  true on success
 *
 * Encryption and protocol run information is available in the MME handle.
 */
bool
cp_msg_cm_get_key_req_receive (cp_t *ctx, cp_mme_rx_t *mme,
                               cp_msg_cm_get_key_req_t *data)
{
    return true;
}

/**
 * Send a CM_GET_KEY.CNF.
 * \param  ctx  control plane context
 * \param  peer  peer information
 * \param  peks  payload encryption key select
 * \param  prun  protocol run information
 * \param  data  MME data to send
 */
void
cp_msg_cm_get_key_cnf_send (cp_t *ctx, cp_mme_peer_t *peer,
                            cp_mme_peks_t peks,
                            const cp_secu_protocol_run_t *prun,
                            const cp_msg_cm_get_key_cnf_t *data)
{
}

/**
 * Send a CC_LEAVE.IND.
 * \param  ctx  control plane context
 * \param  peer  peer information
 * \param  reason  reason for the disassociation
 * \param  nid  NID
 */
void
cp_msg_cc_leave_ind_send (cp_t *ctx, cp_mme_peer_t *peer,
                          enum cp_msg_cc_leave_ind_reason_t reason,
                          cp_nid_t nid)
{
}

bool
cp_msg_cc_leave_req_receive (cp_t *ctx, cp_mme_rx_t *mme,
                             enum cp_msg_cc_leave_req_reason_t *reason)
{
    return true;
}

bool
cp_msg_cc_leave_ind_receive (cp_t *ctx, cp_mme_rx_t *mme,
                             enum cp_msg_cc_leave_ind_reason_t *reason,
                             cp_nid_t *nid)
{
    return true;
}

void
cp_msg_cc_leave_rsp_send (cp_t *ctx, cp_mme_peer_t *peer)
{
}