summaryrefslogtreecommitdiff
path: root/cesar/cp/cco/action/test/utest/src/handover.c
blob: ec7aff1cf3dac99f32d0df4e95fcc1c90a482888 (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
/* Cesar project {{{
 *
 * Copyright (C) 2009 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    src/handover.c
 * \brief   « brief description »
 * \ingroup « module »
 *
 * « long description »
 */
#include "common/std.h"

#include "lib/scenario/scenario.h"

#include "inc/test_cco_action.h"

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

void
handover__handover_cc_handover_cnf_receive (test_t test)
{
    cp_sta_t *sta;
    cp_net_t *net;
    test_cco_action_t ctx;
    test_cco_action_init (&ctx);
    cp_cco_action_init (&ctx.cp);


    scenario_globals_t globals = {
        .cp = &ctx.cp,
    };

    cp_mme_tx_t mme_to_send;
    globals.mme = &mme_to_send;

    test_case_begin (test, "Handover_cnf_receive");

    scenario_entry_t handover_entries[] = {
        SCENARIO_ACTION (handover__cc_handover_cnf_receive, .peer = CP_MME_PEER (3, 3)),
        SCENARIO_EVENT (cp_msg_cc_handover_cnf_receive,
                        .ok = true,
                        .result =
                        CP_MSG_CC_HANDOVER_CNF_RESULT_REJECT_ANY_HANDOVER),
        SCENARIO_EVENT (cp_fsm_branch,
                        .branch = CP_FSM_BRANCH (CCO_HANDOVER_WAIT_CC_HANDOVER_CNF,
                                                 CC_HANDOVER_CNF,
                                                 no_more_sta)),
        SCENARIO_ACTION (handover__cc_handover_cnf_receive, .peer = CP_MME_PEER (3, 3)),
        SCENARIO_EVENT (cp_msg_cc_handover_cnf_receive,
                        .ok = true,
                        .result =
                        CP_MSG_CC_HANDOVER_CNF_RESULT_ACCEPT),
        SCENARIO_EVENT (cp_msg_cc_handover_info_ind_send_begin,
                        .peer = CP_MME_PEER (3, 3),
                        .rsc = CP_MSG_CC_HANDOVER_REQ_REASON_CCO_SELECTION,
                        .bcco = MAC_TEI_UNASSOCIATED,
                        .num_sta = 2),
        SCENARIO_EVENT (cp_msg_cc_handover_info_ind_send,
                        .tei = 1,
                        .mac_addr = 1,
                        .status = 0x1,
                        .ptei = MAC_TEI_UNASSOCIATED),
        SCENARIO_EVENT (cp_msg_cc_handover_info_ind_send,
                        .tei = 4,
                        .mac_addr = 4,
                        .status = 0x1,
                        .ptei = MAC_TEI_UNASSOCIATED),
        SCENARIO_EVENT (cp_msg_cc_handover_info_ind_send_end),
        SCENARIO_EVENT (cp_fsm_event_bare_new,
                       .type = CP_FSM_EVENT_TYPE_HANDOVER_TIMEOUT),
        SCENARIO_END
    };

    scenario_entry_t handover_entries2[] = {
        SCENARIO_ACTION (handover__cc_handover_cnf_receive, .peer = CP_MME_PEER (3, 3)),
        SCENARIO_EVENT (cp_msg_cc_handover_cnf_receive,
                        .ok = true,
                        .result =
                        CP_MSG_CC_HANDOVER_CNF_RESULT_REJECT_ANY_HANDOVER),
        SCENARIO_EVENT (cp_msg_cc_handover_req_send,
                        .peer = CP_MME_PEER (2, 2),
                        .soft_hard = CP_MSG_CC_HANDOVER_REQ_HANDOVER_HARD,
                        .reason = CP_MSG_CC_HANDOVER_REQ_REASON_CCO_SELECTION
                       ),
        SCENARIO_EVENT (cp_fsm_event_bare_new,
                       .type = CP_FSM_EVENT_TYPE_HANDOVER_TIMEOUT),
        SCENARIO_EVENT (cp_fsm_branch,
                        .branch = CP_FSM_BRANCH (CCO_HANDOVER_WAIT_CC_HANDOVER_CNF,
                                                 CC_HANDOVER_CNF,
                                                 another_sta)),
        SCENARIO_END
    };

    /* Add some station to realise a better test. */
    test_cco_action_create_our_net (&ctx, 1, 1);
    net = cp_sta_mgr_get_our_avln (&ctx.cp);
    sta = cp_sta_mgr_sta_add (&ctx.cp, net, 4, 4);
    cp_sta_set_authenticated (&ctx.cp, sta, true);
    slab_release (sta);

    test_begin (test, "HANDOVER_CNF received - No more stations available")
    {
        ctx.cp.cco_action.handover_reason =
            CP_MSG_CC_HANDOVER_REQ_REASON_CCO_SELECTION;
        scenario_run (test, handover_entries, &globals);
    }
    test_end;

    sta = cp_sta_mgr_sta_add (&ctx.cp, net, 2, 2);
    cp_cco_action_cco_selection__sta_add (&ctx.cp, net, sta);
    slab_release (sta);

    test_begin (test, "HANDOVER_CNF received - More stations available")
    {
        scenario_run (test, handover_entries2, &globals);
    }
    test_end;

    cp_cco_action_uninit (&ctx.cp);
    test_cco_action_uninit (&ctx);
    /* Remove the station from the mac store. */
    dbg_check (mac_store_sta_remove (ctx.cp.mac_store, 2));
    dbg_check (mac_store_sta_remove (ctx.cp.mac_store, 4));

    mac_store_uninit (ctx.cp.mac_store);
}

void
handover__timeout (test_t test)
{
    cp_net_t *net;
    cp_sta_t *sta;

    test_cco_action_t ctx;
    test_cco_action_init (&ctx);
    cp_cco_action_init (&ctx.cp);


    scenario_globals_t globals = {
        .cp = &ctx.cp,
    };

    cp_mme_tx_t mme_to_send;
    globals.mme = &mme_to_send;

    test_case_begin (test, "Handover Timeout");

    scenario_entry_t handover_entries[] = {
        SCENARIO_ACTION (handover__timeout),
        SCENARIO_EVENT (cp_fsm_branch,
                        .branch = CP_FSM_BRANCH (CCO_HANDOVER_WAIT_CC_HANDOVER_CNF,
                                                 HANDOVER_TIMEOUT,
                                                 no_more_sta)),
        SCENARIO_END
    };

    scenario_entry_t handover_entries2[] = {
        SCENARIO_ACTION (handover__timeout),
        SCENARIO_EVENT (cp_msg_cc_handover_req_send,
                        .peer = CP_MME_PEER (3, 3),
                        .soft_hard = CP_MSG_CC_HANDOVER_REQ_HANDOVER_HARD,
                        .reason =
                        CP_MSG_CC_HANDOVER_REQ_REASON_CCO_SELECTION),
        SCENARIO_EVENT (cp_fsm_event_bare_new,
                       .type = CP_FSM_EVENT_TYPE_HANDOVER_TIMEOUT),
        SCENARIO_EVENT (cp_fsm_branch,
                        .branch = CP_FSM_BRANCH (CCO_HANDOVER_WAIT_CC_HANDOVER_CNF,
                                                 HANDOVER_TIMEOUT,
                                                 another_sta)),
        SCENARIO_END
    };

    test_begin (test, "Timeout - More stations available")
    {
        /* Add some station to realise a better test. */
        test_cco_action_create_our_net (&ctx, 1, 1);
        net = cp_sta_mgr_get_our_avln (&ctx.cp);
        sta = cp_sta_mgr_sta_add (&ctx.cp, net, 4, 4);
        cp_sta_set_authenticated (&ctx.cp, sta, true);
        cp_cco_action_cco_selection__sta_add (&ctx.cp, net, sta);
        slab_release (sta);

        scenario_run (test, handover_entries, &globals);
    }
    test_end;

    test_begin (test, "Timeout - Another station")
    {
        /* Add some station to realise a better test. */
        sta = cp_sta_mgr_sta_add (&ctx.cp, net, 4, 4);
        cp_sta_set_authenticated (&ctx.cp, sta, true);
        cp_cco_action_cco_selection__sta_add (&ctx.cp, net, sta);
        slab_release (sta);
        sta = cp_sta_mgr_sta_add (&ctx.cp, net, 3, 3);
        cp_sta_set_authenticated (&ctx.cp, sta, true);
        cp_cco_action_cco_selection__sta_add (&ctx.cp, net, sta);
        slab_release (sta);

        scenario_run (test, handover_entries2, &globals);
    }
    test_end;

    cp_cco_action_uninit (&ctx.cp);
    test_cco_action_uninit (&ctx);
    dbg_check (mac_store_sta_remove (ctx.cp.mac_store, 4));
    dbg_check (mac_store_sta_remove (ctx.cp.mac_store, 3));
    mac_store_uninit (ctx.cp.mac_store);
}

void
handover__handover_cc_handover_info_rsp_receive (test_t test)
{
    test_cco_action_t ctx;
    test_cco_action_init (&ctx);
    cp_cco_action_init (&ctx.cp);


    scenario_globals_t globals = {
        .cp = &ctx.cp,
    };

    cp_mme_tx_t mme_to_send;
    globals.mme = &mme_to_send;

    test_case_begin (test, "Handover_info_rsp_receive");

    scenario_entry_t handover_entries[] = {
        SCENARIO_ACTION (handover__cc_handover_info_rsp_receive, .peer = CP_MME_PEER (3, 3)),
        SCENARIO_EVENT (cp_msg_cc_handover_info_rsp_receive,
                        .ok = true),
        SCENARIO_EVENT (cp_beacon_handover, .tei = 3),
        SCENARIO_END
    };

    test_begin (test, "HANDOVER Info response receive")
    {
        ctx.cp.cco_action.handover_reason =
            CP_MSG_CC_HANDOVER_REQ_REASON_CCO_SELECTION;
        scenario_run (test, handover_entries, &globals);
    }
    test_end;

    cp_cco_action_uninit (&ctx.cp);
    test_cco_action_uninit (&ctx);
}

void
handover__hoip_countdown_expired (test_t test)
{
    test_case_begin (test, "Handover in progress done");

    test_cco_action_t ctx;
    test_cco_action_init (&ctx);
    cp_cco_action_init (&ctx.cp);


    scenario_globals_t globals = {
        .cp = &ctx.cp,
    };

    test_cco_action_create_our_net (&ctx, 1, 1);

    scenario_entry_t handover_entries[] = {
        SCENARIO_ACTION (handover__hoip_countdown_expired),
        SCENARIO_EVENT(cp_sta_action_assoc__authenticated__renew),
        SCENARIO_END
    };

    test_begin (test, "HANDOVER Ended")
    {
        ctx.cp.cco_action.handover_reason =
            CP_MSG_CC_HANDOVER_REQ_REASON_CCO_SELECTION;
        scenario_run (test, handover_entries, &globals);

        test_fail_unless (MAC_TEI_IS_STA(cp_sta_own_data_get_tei (&ctx.cp)));
        test_fail_unless (cp_sta_own_data_get_cco_status (&ctx.cp) == false);
    }
    test_end;

    cp_cco_action_uninit (&ctx.cp);
    test_cco_action_uninit (&ctx);
}

void
handover_test_cases (test_t test)
{
    handover__handover_cc_handover_cnf_receive (test);
    handover__timeout (test);
    handover__handover_cc_handover_info_rsp_receive (test);
    handover__hoip_countdown_expired (test);
}

void
handover_test_suite (test_t t)
{
    test_suite_begin (t, "handover");
    handover_test_cases (t);
    test_case_begin (t, "memory");
    test_begin (t, "memory")
    {
        test_fail_unless (blk_check_memory ());
    } test_end;
}