From 509ced08dfe9a0c1fbbd18698bd4dd561c39904a Mon Sep 17 00:00:00 2001 From: NĂ©lio Laranjeiro Date: Fri, 17 Sep 2010 11:28:17 +0200 Subject: cesar/bsu: Handle specially beacon allocations, refs #1438 --- cesar/bsu/src/bsu.c | 35 ++++++++++++++++---------- cesar/bsu/test/utest/src/schedules.c | 49 ++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 13 deletions(-) (limited to 'cesar/bsu') diff --git a/cesar/bsu/src/bsu.c b/cesar/bsu/src/bsu.c index 333d3b2d6b..da12e6d185 100644 --- a/cesar/bsu/src/bsu.c +++ b/cesar/bsu/src/bsu.c @@ -285,24 +285,33 @@ bsu_schedules_merge (bsu_t *ctx, bsu_beacon_t *beacon, bsu_schedules_merge_process_init (ctx, beacon, &process, bp_index); while ((sai = bsu_schedules_merge_get_lesser (ctx, beacon, &process))) { + /* A hole is present for the first allocation. It is a beacon region, + * BSU should inform the CA with the correct glid (a reserved one). + * - When acting as CCo glid is MAC_LID_SPC_CENTRAL. + * - When acting as STA glid is MAC_LID_SPC_BEACON_LISTEN. */ + if (alloc == 0 && sai->stpf && sai->start_time_atu != 0) + { + u8 glid; + if (ctx->is_sta == BSU_UPDATE_STA_TYPE_CCO) + glid = MAC_LID_SPC_CENTRAL; + else + glid = MAC_LID_SPC_BEACON_LISTEN; + bsu_schedules_merge__allocation_add ( + ctx, schedule, alloc, sai->start_time_atu, glid); + alloc++; + } /* Add a hole between the previous allocation end this one. */ - if ((alloc - && sai->stpf - && MAC_ATU_TO_TCK(sai->start_time_atu) != - schedule->allocations[alloc-1].end_offset_tck) - || (alloc == 0 && sai->stpf && sai->start_time_atu != 0)) + else if (sai->stpf + && MAC_ATU_TO_TCK(sai->start_time_atu) + != schedule->allocations[alloc-1].end_offset_tck) { - bsu_schedules_merge__allocation_add (ctx, schedule, alloc, - sai->start_time_atu, - alloc == 0 ? - MAC_LID_SPC_BEACON_LISTEN : - MAC_LID_SPC_HOLE); + bsu_schedules_merge__allocation_add ( + ctx, schedule, alloc, sai->start_time_atu, MAC_LID_SPC_HOLE); alloc++; } /* Add this allocation. */ - bsu_schedules_merge__allocation_add (ctx, schedule, alloc, - sai->end_time_atu, - sai->glid | 0x80); + bsu_schedules_merge__allocation_add ( + ctx, schedule, alloc, sai->end_time_atu, sai->glid | 0x80); alloc++; } /* store the number of allocations. */ diff --git a/cesar/bsu/test/utest/src/schedules.c b/cesar/bsu/test/utest/src/schedules.c index fa0e9ff574..6bf6926f89 100644 --- a/cesar/bsu/test/utest/src/schedules.c +++ b/cesar/bsu/test/utest/src/schedules.c @@ -299,6 +299,54 @@ test_case_ca_schedules_intellon (test_t test) test_end; } +void +test_case_ca_schedules_special_allocations__test ( + test_t test, char *text, bsu_update_sta_type_t type) +{ + bsu_test_t t; + bsu_avln_t avln; + bsu_test_init (&t); + test_begin (test, text) + { + uint i; + ca_schedule_t sched_cmp; + sched_cmp.allocations[0].end_offset_tck = MAC_ATU_TO_TCK (500); + if (type == BSU_UPDATE_STA_TYPE_STA) + sched_cmp.allocations[0].glid = MAC_LID_SPC_BEACON_LISTEN; + else + sched_cmp.allocations[0].glid = MAC_LID_SPC_CENTRAL; + sched_cmp.allocations[1].end_offset_tck = MAC_ATU_TO_TCK (3907); + sched_cmp.allocations[1].glid = MAC_LID_SHARED_CSMA; + t.bsu->is_sta = type; + memset (&avln, 0, sizeof (bsu_avln_t)); + avln.beacon.bmis.nps.ns = 1; + avln.beacon.bmis.nps.sais[0].stpf = true; + avln.beacon.bmis.nps.sais[0].start_time_atu = 500; + avln.beacon.bmis.nps.sais[0].end_time_atu = 3907; + avln.beacon.bmis.nps.sais[0].glid = MAC_LID_SHARED_CSMA & 0x7f; + ca_schedule_t sched; + bsu_schedules_merge (t.bsu, &avln.beacon, &sched, 0); + for (i = 0; i < sched.allocations_nb; i++) + { + test_fail_unless (sched.allocations[i].end_offset_tck == + sched_cmp.allocations[i].end_offset_tck); + test_fail_unless (sched.allocations[i].glid == + sched_cmp.allocations[i].glid); + } + } + test_end; + bsu_test_uninit (&t); +} + +void +test_case_ca_schedules_special_allocations (test_t t) +{ + test_case_ca_schedules_special_allocations__test ( + t, "Region beacon acts as STA", BSU_UPDATE_STA_TYPE_STA); + test_case_ca_schedules_special_allocations__test ( + t, "Region beacon acts as CCO", BSU_UPDATE_STA_TYPE_CCO); +} + void test_suite_bsu_schedule (test_t t) { @@ -306,4 +354,5 @@ test_suite_bsu_schedule (test_t t) test_case_ca_schedules (t); test_case_bsu_schedules_countdowns (t); test_case_ca_schedules_intellon (t); + test_case_ca_schedules_special_allocations (t); } -- cgit v1.2.3