summaryrefslogtreecommitdiff
path: root/cesar/bsu/test/utest/src/schedules.c
blob: 61953497a09d790f8fc506da7abd013bb25512c2 (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
/* Cesar project {{{
 *
 * Copyright (C) 2010 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    bsu/test/utest/src/schedules.c
 * \brief   BSU schedule tests.
 * \ingroup bsu
 */
#include "common/std.h"
#include "lib/test.h"
#include "bsu/bsu.h"
#include "mac/common/timings.h"
#include "bsu/test/utest/tests.h"
#include "bsu/inc/bsu.h"
#include "bsu/inc/context.h"
#include "bsu/inc/interface.h"
#include <string.h>

void
bsu_schedules_merge (bsu_t *ctx, bsu_beacon_schedules_t *avln,
                     ca_schedule_t *schedules, uint nb);

void
bsu_ca_schedules (bsu_t *ctx, bsu_avln_t *avln);

void
bsu_timer_event_process (void *ud);

void
test_case_ca_schedules (test_t test)
{
    bsu_test_t t;
    bsu_avln_t avln;
    bsu_test_init (&t);
    test_case_begin (test, "CA Schedules");
    test_begin (test, "Merge function")
    {
        uint i, j;
        ca_schedule_t scheds_cmp [3];
        scheds_cmp[0].allocations[0].end_offset_tck = MAC_ATU_TO_TCK (500);
        scheds_cmp[0].allocations[0].glid = MAC_LID_SPC_HOLE;
        scheds_cmp[0].allocations[1].end_offset_tck = MAC_ATU_TO_TCK (700);
        scheds_cmp[0].allocations[1].glid = MAC_GLID_MIN;
        scheds_cmp[0].allocations[2].end_offset_tck = MAC_ATU_TO_TCK (1000);
        scheds_cmp[0].allocations[2].glid = MAC_GLID_MIN;
        scheds_cmp[0].allocations[3].end_offset_tck = MAC_ATU_TO_TCK (1600);
        scheds_cmp[0].allocations[3].glid = MAC_LID_SPC_HOLE;
        scheds_cmp[0].allocations[4].end_offset_tck = MAC_ATU_TO_TCK (2500);
        scheds_cmp[0].allocations[4].glid = MAC_GLID_MIN;
        scheds_cmp[0].allocations[5].end_offset_tck = MAC_ATU_TO_TCK (3907);
        scheds_cmp[0].allocations[5].glid = MAC_GLID_MIN;
        /* next */
        scheds_cmp[1].allocations[0].end_offset_tck = MAC_ATU_TO_TCK (500);
        scheds_cmp[1].allocations[0].glid = MAC_LID_SPC_HOLE;
        scheds_cmp[1].allocations[1].end_offset_tck = MAC_ATU_TO_TCK (700);
        scheds_cmp[1].allocations[1].glid = MAC_GLID_MIN;
        scheds_cmp[1].allocations[2].end_offset_tck = MAC_ATU_TO_TCK (1000);
        scheds_cmp[1].allocations[2].glid = MAC_GLID_MIN;
        scheds_cmp[1].allocations[3].end_offset_tck = MAC_ATU_TO_TCK (1600);
        scheds_cmp[1].allocations[3].glid = MAC_LID_SPC_HOLE;
        scheds_cmp[1].allocations[4].end_offset_tck = MAC_ATU_TO_TCK (2500);
        scheds_cmp[1].allocations[4].glid = MAC_GLID_MIN;
        scheds_cmp[1].allocations[5].end_offset_tck = MAC_ATU_TO_TCK (3907);
        scheds_cmp[1].allocations[5].glid = MAC_GLID_MIN;
        /* next */
        scheds_cmp[2].allocations[0].end_offset_tck = MAC_ATU_TO_TCK (50);
        scheds_cmp[2].allocations[0].glid = MAC_LID_SPC_HOLE;
        scheds_cmp[2].allocations[1].end_offset_tck = MAC_ATU_TO_TCK (500);
        scheds_cmp[2].allocations[1].glid = MAC_GLID_MIN;
        scheds_cmp[2].allocations[2].end_offset_tck = MAC_ATU_TO_TCK (700);
        scheds_cmp[2].allocations[2].glid = MAC_GLID_MIN;
        scheds_cmp[2].allocations[3].end_offset_tck = MAC_ATU_TO_TCK (1600);
        scheds_cmp[2].allocations[3].glid = MAC_GLID_MIN;
        scheds_cmp[2].allocations[4].end_offset_tck = MAC_ATU_TO_TCK (2500);
        scheds_cmp[2].allocations[4].glid = MAC_GLID_MIN;
        scheds_cmp[2].allocations[5].end_offset_tck = MAC_ATU_TO_TCK (3907);
        scheds_cmp[2].allocations[5].glid = MAC_GLID_MIN;
        ca_schedule_t scheds;
        bsu_test_avln_create (&t, &avln);
        for (i = 0; i < COUNT(scheds_cmp); i++)
        {
            bsu_schedules_merge (t.bsu, &avln.bs.schedules, &scheds, i);
            for (j = 0; j < scheds.allocations_nb; j++)
            {
                test_fail_unless (scheds.allocations[j].end_offset_tck
                              == scheds_cmp[i].allocations[j].end_offset_tck);
                test_fail_unless (scheds.allocations[j].glid
                                  == scheds_cmp[i].allocations[j].glid);
            }
        }
    }
    test_end;
    test_begin (test, "Ca schedules")
    {
        uint i, index;
        u32 bpsd[BSU_ACLF_BPSD_NB-1];
        ca_schedule_t *sched;
        t.bsu->ca_index = 0;
        index = t.bsu->ca_index;
        bsu_test_avln_create (&t, &avln);
        bsu_ca_schedules (t.bsu, t.bsu->sta_avln);
        bsu_aclf_beacon_period_start_date (t.bsu->aclf, bpsd, COUNT (bpsd));
        for (i = 0; i < t.ca.nb_beacon_periods; i++)
        {
            sched = ca_alloc_get_schedule (t.bsu->ca, i + index);
            test_fail_unless (bpsd[i] == t.ca.beacon_periods[i].start_date);
            test_fail_unless (i + index
                              == t.ca.beacon_periods[i].schedule_index);
        }
    }
    test_end;
    bsu_test_uninit (&t);
}

void
test_case_bsu_schedules_countdowns (test_t t)
{
    test_suite_begin (t, "Countdowns");
    test_begin (t, "SNID/EKS/HM change On event process")
    {
        uint i, j;
        ca_schedule_t *casched;
        bsu_test_t ctx;
        bsu_test_init (&ctx);
        bsu_activate (true);
        ctx.bsu->is_sta = BSU_UPDATE_STA_TYPE_STA;
        bsu_test_avln_create (&ctx, ctx.bsu->sta_avln);
        for (i = 0; i < BSU_BEACON_SCHEDULES_MAX; i++)
        {
            ctx.bsu->sta_avln->bs.schedules.snid [i] = i;
            ctx.bsu->sta_avln->bs.schedules.nek_switch [i] = i;
            ctx.bsu->sta_avln->bs.schedules.hm [i] = i;
        }
        for (i = 0; i < 3; i++)
        {
            ctx.bsu->ca_index = 0;
            bsu_timer_event_process (ctx.bsu);
            for (j = 0; j < 3; j++)
            {
                casched = ca_alloc_get_schedule (INVALID_PTR, j);
                test_fail_unless (
                    casched->snid ==
                    ctx.bsu->sta_avln->bs.schedules.snid [j]);
                test_fail_unless (
                    casched->nek_switch ==
                    ctx.bsu->sta_avln->bs.schedules.nek_switch [j]);
                test_fail_unless (
                    casched->coexistence_mode ==
                    ctx.bsu->sta_avln->bs.schedules.hm [j]);
            }
            for (j = 0; j < BSU_BEACON_SCHEDULES_MAX - 1; j++)
            {
                ctx.bsu->sta_avln->bs.schedules.snid [j] =
                    ctx.bsu->sta_avln->bs.schedules.snid [j+1];
                ctx.bsu->sta_avln->bs.schedules.nek_switch[j] =
                    ctx.bsu->sta_avln->bs.schedules.nek_switch[j+1];
                ctx.bsu->sta_avln->bs.schedules.hm [j] =
                    ctx.bsu->sta_avln->bs.schedules.hm [j+1];
            }
            ctx.bsu->sta_avln->bs.schedules.snid [2] = 2;
            ctx.bsu->sta_avln->bs.schedules.nek_switch [2] = 2;
            ctx.bsu->sta_avln->bs.schedules.hm [2] = 2;
        }
        bsu_test_uninit (&ctx);
    }
    test_end;
    test_begin (t, "SNID/EKS/HM change On beacon reception")
    {
        uint i, j;
        bsu_beacon_t beacon;
        ca_schedule_t *casched;
        bsu_test_t ctx;
        pbproc_tx_beacon_params_t bparams;
        pbproc_rx_beacon_params_t bparamsrx;
        bsu_test_init (&ctx);
        bsu_activate (true);
        bsu_test_create_beacon (&ctx, &beacon);
        ctx.mac_config.tei = 0xA;
        bparamsrx.snid = 0;
        bsu_track_avln (beacon.vf.nid, 0x0, ctx.mac_config.tei,
                        MAC_COEXISTENCE_FULL_HYBRID_MODE);
        ctx.bsu->is_sta = BSU_UPDATE_STA_TYPE_STA;
        beacon.bmis.eks.kbc = BSU_BEACON_EKS_KBC_NEK;
        for (i = 0; i < 5; i++)
        {
            pb_beacon_t *b = bsu_beacon_write (
                &beacon, BSU_BEACON_TYPE_CENTRAL, &ctx.mac_config, &bparams);
            ((pb_t *) b)->phy_pb.pb_rx.pb_measurement.crc_error = false;
            bsu_beacon_recv (ctx.bsu, b, &bparamsrx);
            ctx.bsu->ca_index = 0;
            for (j = 0; j < 3; j++)
            {
                casched = ca_alloc_get_schedule (INVALID_PTR, j);
                test_fail_unless (
                    casched->snid ==
                    ctx.bsu->sta_avln->bs.schedules.snid [j]);
                test_fail_unless (
                    casched->nek_switch ==
                    ctx.bsu->sta_avln->bs.schedules.nek_switch[j]);
                test_fail_unless (
                    casched->coexistence_mode ==
                    ctx.bsu->sta_avln->bs.schedules.hm [j]);
            }
            /* Release beacon. */
            blk_release_desc ((blk_t*) ctx.ul.beacon);
            ctx.ul.beacon = INVALID_PTR;
            beacon.bmis.change_snid.snidccd --;
            beacon.bmis.eks.kccd--;
            beacon.bmis.change_hm.hmccd--;
        }
        test_fail_unless (ctx.bsu->sta_avln->bs.schedules.snid [0] ==
                          beacon.bmis.change_snid.new_snid);
        test_fail_unless (ctx.bsu->sta_avln->bs.schedules.nek_switch [0] ==
                          beacon.bmis.eks.new_eks);
        test_fail_unless (ctx.bsu->sta_avln->bs.schedules.hm [0] ==
                          beacon.bmis.change_hm.newhm);
        bsu_test_uninit (&ctx);
    }
    test_end;
}

void
test_case_ca_schedules_intellon (test_t test)
{
    test_case_begin (test, "Intellon central beacons");
    test_begin (
        test, "Persistent schedule valid for the current beacon period")
    {
        bsu_test_t t;
        bsu_test_init (&t);
        bsu_beacon_t beacon;
        pb_beacon_t *pbbeacon;
        bsu_test_create_beacon (&t, &beacon);
        beacon.bmis.nps.ns = 0;
        beacon.bmis.ps.nb = 1;
        beacon.bmis.ps.ps[0].ns = 1;
        beacon.bmis.ps.ps[0].pscd = 0;
        beacon.bmis.ps.ps[0].cscd = 0;
        beacon.bmis.ps.ps[0].sais[0].stpf = true;
        beacon.bmis.ps.ps[0].sais[0].start_time_atu = 52;
        beacon.bmis.ps.ps[0].sais[0].end_time_atu = 3907;
        beacon.bmis.ps.ps[0].sais[0].glid = MAC_LID_SHARED_CSMA & 0x7f;
        uint i;
        for (i = 0; i < COUNT (t.bsu->aclf->bpsd); i++)
            t.bsu->aclf->bpsd[i] = i * BSU_ACLF_BP_50HZ_TCK;
        t.bsu->aclf->beacon_period = BSU_ACLF_BP_50HZ_TCK;
        *((uint*) &t.bsu->aclf->bp) = BSU_ACLF_BP_50HZ_TCK;
        pbproc_tx_beacon_params_t btx;
        pbproc_rx_beacon_params_t brx;
        memset (&brx, 0, sizeof (pbproc_rx_beacon_params_t));
        pbbeacon = bsu_beacon_write (
            &beacon, BSU_BEACON_TYPE_CENTRAL, &t.mac_config, &btx);
        pbbeacon->phy_pb.pb_rx.pb_measurement.crc_error = false;
        bsu_track_avln (beacon.vf.nid, brx.snid, 0, beacon.vf.nm);
        t.bsu->is_sta = BSU_UPDATE_STA_TYPE_STA;
        bsu_beacon_process (t.bsu, pbbeacon, &brx);
        /* Schedules which should be present. */
        test_fail_unless (t.bsu->sta_avln->bs.schedules.ps.nb == 1);
        test_fail_unless (t.bsu->sta_avln->bs.schedules.ps.ps[0].pscd == 0);
        test_fail_unless (t.bsu->sta_avln->bs.schedules.ps.ps[0].cscd == 7);
        test_fail_unless (
            t.bsu->sta_avln->bs.schedules.ps.ps[0].sais[0].glid ==
            (MAC_LID_SHARED_CSMA & 0x7f));
        test_fail_unless (
            t.bsu->sta_avln->bs.schedules.ps.ps[0].sais[0].end_time_atu ==
            3907);
        test_fail_unless (
            t.bsu->sta_avln->bs.schedules.ps.ps[0].sais[0].stpf == false);
        blk_release_desc ((blk_t*) pbbeacon);
        bsu_test_uninit (&t);
    }
    test_end;
}

void
test_suite_bsu_schedule (test_t t)
{
    test_suite_begin (t, "BSU schedules");
    test_case_ca_schedules (t);
    test_case_bsu_schedules_countdowns (t);
    test_case_ca_schedules_intellon (t);
}