summaryrefslogtreecommitdiff
path: root/cesar/mac/pbproc/test/pbproc/src/tx_sound.c
blob: 77562513a103e06ce4ddfa40b45ca8d0a8d590ac (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
/* Cesar project {{{
 *
 * Copyright (C) 2009 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    src/tx_sound.c
 * \brief   TX SOUND automaton test
 * \ingroup test
 */
#include "common/std.h"

#include "lib/scenario/scenario.h"

#include "inc/test_pbproc.h"
#include "inc/utils.h"

#include "mac/common/timings.h"
#include "mac/pbproc/inc/context.h"

void
tx_sound_test (test_t t, test_pbproc_t *tp)
{
    test_within (t);
    const uint lid = 1;
    const uint stei = tp->config.tei;
    const uint dtei = 2;
    const uint beacon_tck = MAC_MS_TO_TCK (1000) / 50;
    const u32 date = 12345;
    const uint symb_nb = 19;
    const uint duration_tck = MAC_PREAMBLE_TCK + MAC_FC_AV_TCK
        + MAC_PAYLOAD_TCK (symb_nb, MAC_DX417_TCK)
        + MAC_RIFS_DEFAULT_TCK + MAC_PREAMBLE_TCK + MAC_FC_AV_TCK;
    u32 chandata_conf[1] = { 0 };
    pbproc_set_chandata_conf (
        tp->pbproc, (phy_chandata_conf_t *) chandata_conf, 1);
    mfs_tx_t *mfs = utils_mfs_tx_prepare (false, false, lid, dtei, 1);
    utils_sta_prepare_default_tonemap (tp, true, dtei,
                                       TONEMAP_INDEX_INITIAL_START, 0, 0,
                                       NULL);
    ca_access_param_t access = {
        .mfs = mfs,
        .access_date = date,
        .beacon_period_start_date = date / beacon_tck * beacon_tck,
        .duration_tck = duration_tck,
        .prp = true,
        .cfp = false,
        .hybrid = false,
    };
    pbproc_fc_sound_t sound_ack_fc = {
        .dt_av = PBPROC_FC_DT_SOUND,
        .access = false,
        .snid = tp->snid,
        .stei = dtei,
        .dtei = stei,
        .lid = lid,
        .cfs = false,
        .pbsz = false,
        .bdf = true,
        .saf = true,
        .scf = true,
        .req_tm = 0,
        .fl_av = 0,
        .mpdu_cnt = 0,
        .reserved0 = 0,
        .ppb = 0,
        .src = 0,
        .reserved1 = 0,
        .reserved2 = 0,
        .fccs_av = 0,
    };
    const uint pre_fc_fl_tck = MAC_PREAMBLE_TCK + MAC_FC_AV_TCK
        + MAC_PAYLOAD_TCK (symb_nb, MAC_DX417_TCK) + MAC_RIFS_DEFAULT_TCK;
    scenario_entry_t entries[] = {
        SCENARIO_ACTION (phy_access, .access_param = &access,
                         .prp_won = true, .slot_count = 2),
        SCENARIO_EVENT (ca_access_hold),
        SCENARIO_EVENT (phy_tx_param_sound, .fc_mode = PHY_FC_MODE_AV_1,
                        .nb_pb = 1, .mod = PHY_MOD_ROBO,
                        .fecrate = PHY_FEC_RATE_1_2,
                        .pb_size = PHY_PB_SIZE_520, .gil = PHY_GIL_417),
        SCENARIO_EVENT (phy_tx_frame, .date = date, .want_conf = false,
                        .stop_tx_on_prp_lost = true),
        SCENARIO_EVENT (ca_access_vcs_restart, .start_date = date,
                        .length_tck = MAC_EIFS_AV_TCK,
                        .anticipation_tck = PBPROC_ANTICIP_TCK,
                        .eifs = true),
        SCENARIO_EVENT (phy_rx_activate, .now = false,
                        .date = date + pre_fc_fl_tck,
                        .pre_detection = true),
        SCENARIO_ACTION (phy_rx_fc, .rx_date = date + pre_fc_fl_tck,
                         .fc_av = (u32 *) &sound_ack_fc),
        SCENARIO_EVENT (phy_rx_prepare_short),
        SCENARIO_EVENT (ca_backoff_success),
        SCENARIO_EVENT (ca_access_vcs_restart,
                        .start_date = date + pre_fc_fl_tck,
                        .length_tck = MAC_PREAMBLE_TCK + MAC_FC_AV_TCK
                        + MAC_CIFS_TCK,
                        .anticipation_tck = PBPROC_ANTICIP_TCK,
                        .eifs = false),
        SCENARIO_END
    };
    scenario_globals_t globals = {
        .tp = tp,
    };
    scenario_run (t, entries, &globals);
    test_fail_unless (mfs->stats.num_mpdus == 0);
    test_fail_unless (mfs->stats.num_bursts == 0);
    test_fail_unless (mfs->stats.num_pbs == 0);
    test_fail_unless (mfs->stats.num_segs_suc == 0);
    utils_mfs_tx_cleanup (mfs);
    dbg_check (mac_store_sta_remove (tp->store, dtei));
    test_fail_unless (tp->pbproc->fsm.current_state == PBPROC_FSM_STATE_IDLE);
    pbproc_set_chandata_conf (tp->pbproc, NULL, 0);
}

void
tx_sound_basic_test_case (test_t t)
{
    test_pbproc_t tp;
    test_case_begin (t, "basic");
    test_pbproc_init (&tp);
    test_begin (t, "basic")
    {
        tx_sound_test (t, &tp);
    } test_end;
    test_pbproc_uninit (&tp);
}

void
tx_sound_cancel_test (test_t t, test_pbproc_t *tp, bool prp_won, bool rx_fc)
{
    test_within (t);
    const uint lid = 1;
    const uint dtei = 2;
    const uint date = 123456;
    const uint beacon_tck = MAC_MS_TO_TCK (1000) / 50;
    const uint symb_nb = 19;
    u32 chandata_conf[1] = { 0 };
    pbproc_set_chandata_conf (
        tp->pbproc, (phy_chandata_conf_t *) chandata_conf, 1);
    mfs_tx_t *mfs = utils_mfs_tx_prepare (false, false, lid, dtei, 1);
    utils_sta_prepare_default_tonemap (tp, true, dtei,
                                       TONEMAP_INDEX_INITIAL_START, 0, 0,
                                       NULL);
    ca_access_param_t access = {
        .mfs = mfs,
        .access_date = date,
        .beacon_period_start_date = date / beacon_tck * beacon_tck,
        .duration_tck = MAC_PREAMBLE_TCK + MAC_FC_AV_TCK
            + MAC_PAYLOAD_TCK (symb_nb, MAC_DX417_TCK) + MAC_RIFS_DEFAULT_TCK
            + MAC_PREAMBLE_TCK + MAC_FC_AV_TCK,
        .prp = true,
        .cfp = false,
        .hybrid = false,
    };
    const uint date2 = 123456 + MAC_EIFS_AV_TCK;
    ca_access_param_t access2 = {
        .mfs = mfs,
        .access_date = date2,
        .beacon_period_start_date = date2 / beacon_tck * beacon_tck,
        .duration_tck = MAC_PREAMBLE_TCK + MAC_FC_AV_TCK
            + MAC_PAYLOAD_TCK (symb_nb, MAC_DX417_TCK) + MAC_RIFS_DEFAULT_TCK
            + MAC_PREAMBLE_TCK + MAC_FC_AV_TCK,
        .prp = false,
        .cfp = false,
        .hybrid = false,
    };
    pbproc_fc_sack_t sack_fc = {
        .dt_av = PBPROC_FC_DT_SACK,
        .access = false,
        .snid = tp->snid,
        .dtei = tp->config.tei + 8,
        .cfs = false,
        .bdf = true,
        .svn = 0,
        .rrtf = false,
        .mfs_rsp_data = MFS_FSM_RSP_ACK,
        .mfs_rsp_mgmt = MFS_FSM_RSP_ACK,
        .sackt3 = 0,
        .sackt2 = 0,
        .sackt1 = 0,
        .sackt0 = 0,
        .sacki = { 0, 0 },
        .sacki_last = 0,
        .fccs_av = 0,
    };
    const uint pre_fc_fl_tck = MAC_PREAMBLE_TCK + MAC_FC_AV_TCK
        + MAC_PAYLOAD_TCK (symb_nb, MAC_DX417_TCK) + MAC_RIFS_DEFAULT_TCK;
    const uint sack_length_tck = MAC_PREAMBLE_TCK + MAC_FC_AV_TCK
        + MAC_CIFS_TCK;
    scenario_entry_t sack_entries[] = {
        SCENARIO_ACTION (phy_access, .access_param = &access,
                         .prp_won = true, .slot_count = 6),
        SCENARIO_EVENT (ca_access_hold),
        SCENARIO_EVENT (phy_tx_param_sound, .fc_mode = PHY_FC_MODE_AV_1,
                        .nb_pb = 1, .mod = PHY_MOD_ROBO,
                        .fecrate = PHY_FEC_RATE_1_2,
                        .pb_size = PHY_PB_SIZE_520, .gil = PHY_GIL_417),
        SCENARIO_EVENT (phy_tx_frame, .date = date, .want_conf = false,
                        .stop_tx_on_prp_lost = true),
        SCENARIO_EVENT (ca_access_vcs_restart, .start_date = date,
                        .length_tck = MAC_EIFS_AV_TCK,
                        .anticipation_tck = PBPROC_ANTICIP_TCK,
                        .eifs = true),
        SCENARIO_EVENT (phy_rx_activate, .now = false,
                        .date = date + pre_fc_fl_tck,
                        .pre_detection = true),
        SCENARIO_ACTION (phy_rx_fc, .rx_date = date - MAC_SLOT_TCK,
                         .prp_won = prp_won, .slot_count = 5,
                         .fc_av = PARENT_OF (pbproc_fc_t, sack,
                                             &sack_fc)->words),
        SCENARIO_EVENT_COND (prp_won, ca_backoff_deferred, .slot_count = 3),
        SCENARIO_EVENT_COND (!prp_won, ca_backoff_cancel),
        SCENARIO_EVENT (phy_tx_cancel),
        SCENARIO_EVENT (ca_access_hold),
        SCENARIO_EVENT (phy_rx_prepare_short),
        SCENARIO_EVENT (ca_access_vcs_restart,
                        .start_date = date - MAC_SLOT_TCK,
                        .length_tck = sack_length_tck,
                        .anticipation_tck = PBPROC_ANTICIP_TCK,
                        .eifs = false),
        SCENARIO_END
    };
    scenario_entry_t access_entries[] = {
        SCENARIO_ACTION (phy_access, .access_param = &access,
                         .prp_won = true, .slot_count = 6),
        SCENARIO_EVENT (ca_access_hold),
        SCENARIO_EVENT (phy_tx_param_sound, .fc_mode = PHY_FC_MODE_AV_1,
                        .nb_pb = 1, .mod = PHY_MOD_ROBO,
                        .fecrate = PHY_FEC_RATE_1_2,
                        .pb_size = PHY_PB_SIZE_520, .gil = PHY_GIL_417),
        SCENARIO_EVENT (phy_tx_frame, .date = date, .want_conf = false,
                        .stop_tx_on_prp_lost = true),
        SCENARIO_EVENT (ca_access_vcs_restart, .start_date = date,
                        .length_tck = MAC_EIFS_AV_TCK,
                        .anticipation_tck = PBPROC_ANTICIP_TCK,
                        .eifs = true),
        SCENARIO_EVENT (phy_rx_activate, .now = false,
                        .date = date + pre_fc_fl_tck,
                        .pre_detection = true),
        SCENARIO_ACTION (phy_access, .access_param = &access2,
                         .prp_won = prp_won, .slot_count = 600),
        SCENARIO_EVENT_COND (prp_won, ca_backoff_deferred, .slot_count = 598),
        SCENARIO_EVENT_COND (!prp_won, ca_backoff_cancel),
        SCENARIO_EVENT (ca_access_hold),
        SCENARIO_EVENT (phy_tx_param_sound, .fc_mode = PHY_FC_MODE_AV_1,
                        .nb_pb = 1, .mod = PHY_MOD_ROBO,
                        .fecrate = PHY_FEC_RATE_1_2,
                        .pb_size = PHY_PB_SIZE_520, .gil = PHY_GIL_417),
        SCENARIO_EVENT (phy_tx_frame, .date = date2, .want_conf = false,
                        .stop_tx_on_prp_lost = false),
        SCENARIO_EVENT (ca_access_vcs_restart, .start_date = date2,
                        .length_tck = MAC_EIFS_AV_TCK,
                        .anticipation_tck = PBPROC_ANTICIP_TCK,
                        .eifs = true),
        SCENARIO_EVENT (phy_rx_activate, .now = false,
                        .date = date2 + pre_fc_fl_tck,
                        .pre_detection = true),
        SCENARIO_ACTION (phy_rx_fc, .rx_date = date2 - MAC_SLOT_TCK,
                         .prp_won = prp_won, .slot_count = 5,
                         .fc_av = PARENT_OF (pbproc_fc_t, sack,
                                             &sack_fc)->words),
        SCENARIO_EVENT (ca_backoff_deferred, .slot_count = 3),
        SCENARIO_EVENT (phy_tx_cancel),
        SCENARIO_EVENT (ca_access_hold),
        SCENARIO_EVENT (phy_rx_prepare_short),
        SCENARIO_EVENT (ca_access_vcs_restart,
                        .start_date = date2 - MAC_SLOT_TCK,
                        .length_tck = sack_length_tck,
                        .anticipation_tck = PBPROC_ANTICIP_TCK,
                        .eifs = false),
        SCENARIO_END
    };
    scenario_entry_t *entries = rx_fc ? sack_entries : access_entries;
    scenario_globals_t globals = {
        .tp = tp,
    };
    scenario_run (t, entries, &globals);
    test_fail_unless (mfs->stats.num_mpdus == 0);
    test_fail_unless (mfs->stats.num_bursts == 0);
    test_fail_unless (mfs->stats.num_pbs == 0);
    test_fail_unless (mfs->stats.num_segs_suc == 0);
    utils_mfs_tx_cleanup (mfs);
    dbg_check (mac_store_sta_remove (tp->store, dtei));
    test_fail_unless (tp->pbproc->fsm.current_state == PBPROC_FSM_STATE_IDLE);
    pbproc_set_chandata_conf (tp->pbproc, NULL, 0);
}

void
tx_sound_error_test_case (test_t t)
{
    test_pbproc_t tp;
    test_case_begin (t, "error");
    test_pbproc_init (&tp);
    test_begin (t, "no ack")
    {
        tx_sound_cancel_test (t, &tp, true, false);
    } test_end;
    test_begin (t, "cw lost")
    {
        tx_sound_cancel_test (t, &tp, true, true);
    } test_end;
    test_begin (t, "prp lost")
    {
        tx_sound_cancel_test (t, &tp, false, true);
    } test_end;
    test_begin (t, "prp lost and no frame")
    {
        tx_sound_cancel_test (t, &tp, false, false);
    } test_end;
    test_pbproc_uninit (&tp);
}

void
tx_sound_test_suite (test_t t)
{
    test_suite_begin (t, "tx sound");
    tx_sound_basic_test_case (t);
    tx_sound_error_test_case (t);
    test_case_begin (t, "memory");
    test_begin (t, "memory")
    {
        test_fail_unless (blk_check_memory ());
    } test_end;
}