summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Schodet2012-11-13 16:58:06 +0100
committerNicolas Schodet2012-12-13 16:17:29 +0100
commitf3b9d5d2cea28467e5d8410583e67f94cbf91067 (patch)
treec2dfe04b78d59cc9898e007cc6a4416bbc18a38d
parent9ba734b8254eab9d8ac26188a5ec0a95c955c26f (diff)
cesar/mac/{ca,pbproc}: handle merged allocations transitions, closes #3500
Previous code was always using old merge flag value in pbproc, or new merge flag value in ca.
-rw-r--r--cesar/mac/ca/src/access.c5
-rw-r--r--cesar/mac/pbproc/src/fsm_top.c5
-rw-r--r--cesar/mac/pbproc/test/pbproc/src/test_pbproc.c134
3 files changed, 66 insertions, 78 deletions
diff --git a/cesar/mac/ca/src/access.c b/cesar/mac/ca/src/access.c
index 2e70bc7ce6..feca536310 100644
--- a/cesar/mac/ca/src/access.c
+++ b/cesar/mac/ca/src/access.c
@@ -295,6 +295,9 @@ ca_access_aifs (ca_t *ctx)
dbg_claim (ctx->current_beacon_period);
u32 date = phy_date ();
CA_TRACE (ACCESS_AIFS, date);
+ /* Save merge flag as VCS restart is needed only if previous allocation
+ * was merged with next one. */
+ bool prev_merge = ctx->current_allocation_param.merge;
/* Go on with the next allocation, first get current one. */
ca_beacon_period_t *bp = ctx->current_beacon_period;
ca_schedule_t *sched = &ctx->schedules[bp->schedule_index];
@@ -321,7 +324,7 @@ ca_access_aifs (ca_t *ctx)
ctx->current_allocation_index = alloc_i;
ca_alloc_prepare (ctx);
/* Reschedule. */
- if (!ctx->current_allocation_param.merge)
+ if (!prev_merge)
{
ca_access_vcs_restart (ctx, access_date);
}
diff --git a/cesar/mac/pbproc/src/fsm_top.c b/cesar/mac/pbproc/src/fsm_top.c
index 55ed6e6f43..760d2c9e32 100644
--- a/cesar/mac/pbproc/src/fsm_top.c
+++ b/cesar/mac/pbproc/src/fsm_top.c
@@ -45,15 +45,14 @@ pbproc_ftop_aifs (pbproc_t *ctx)
{
dbg_claim (ctx);
PBPROC_TRACE (FTOP_AIFS);
- bool merge = ctx->alloc.merge;
- if (!merge)
+ if (!ctx->alloc.merge)
{
phy_rx_activate (ctx->phy, true, 0, false);
ca_backoff_cancel (ctx->ca);
}
ctx->alloc = *ca_access_aifs (ctx->ca);
/* Change allocation parameters. */
- if (!merge)
+ if (!ctx->alloc.merge)
{
ctx->times = ctx->times_array[
PBPROC_TIMES_ARRAY_INDEX (ctx->alloc.hybrid,
diff --git a/cesar/mac/pbproc/test/pbproc/src/test_pbproc.c b/cesar/mac/pbproc/test/pbproc/src/test_pbproc.c
index e08a77cf79..8ec218768a 100644
--- a/cesar/mac/pbproc/test/pbproc/src/test_pbproc.c
+++ b/cesar/mac/pbproc/test/pbproc/src/test_pbproc.c
@@ -200,6 +200,56 @@ test_pbproc_uninit (test_pbproc_t *ctx)
ctx->store = NULL;
}
+static void
+test_pbproc_aifs (test_t t, bool from_merge, bool to_merge)
+{
+ test_within (t);
+ test_pbproc_t ctx;
+ test_pbproc_init (&ctx);
+ ctx.pbproc->alloc.merge = from_merge;
+ ca_access_param_t access_param = {
+ .access_date = 0, .cw_start_date = 0, .aifs = true,
+ };
+ ctx.pbproc->detect.hp10_detected = true;
+ ctx.pbproc->detect.hp10_detect_date =
+ phy_date () - MAC_MS_TO_TCK (1900);
+ ctx.pbproc->detect.hp11_detected = true;
+ ctx.pbproc->detect.hp11_detect_date =
+ phy_date () - MAC_MS_TO_TCK (2900);
+ scenario_entry_t entries[] = {
+ SCENARIO_ACTION (phy_access, .mfs = NULL,
+ .access_param = &access_param,
+ .prp_won = true, .slot_count = 64),
+ SCENARIO_EVENT_COND (!from_merge, phy_rx_activate, .now = true,
+ .pre_detection = false),
+ SCENARIO_EVENT_COND (!from_merge, ca_backoff_cancel),
+ SCENARIO_EVENT (ca_access_aifs,
+ .coexistence_mode =
+ MAC_COEXISTENCE_FULL_HYBRID_MODE,
+ .snid = ctx.snid, .hybrid = true, .merge = to_merge,
+ .nek_switch = 0),
+ SCENARIO_EVENT_COND (!to_merge, phy_rx_param,
+ .fc_mode = PHY_FC_MODE (true, 1)),
+ SCENARIO_END
+ };
+ scenario_globals_t globals = {
+ .tp = &ctx,
+ };
+ scenario_run (t, entries, &globals);
+ test_fail_unless (ctx.pbproc->fsm.current_state
+ == PBPROC_FSM_STATE_IDLE);
+ if (!to_merge)
+ test_fail_unless (memcmp (&ctx.pbproc->times,
+ &ctx.pbproc->times_array[true],
+ sizeof (pbproc_times_t)) == 0);
+ test_fail_unless (ctx.pbproc->detect.hp10_detected == true);
+ test_fail_unless (ctx.pbproc->detect.hp11_detected == false);
+ ctx.pbproc->detect.hp10_detected = false;
+ ctx.pbproc->detect.hp11_detected = false;
+ test_pbproc_check_stats (t, &ctx, .aifs = 1);
+ test_pbproc_uninit (&ctx);
+}
+
void
test_pbproc_init_suite (test_t t)
{
@@ -280,83 +330,19 @@ test_pbproc_init_suite (test_t t)
} test_end;
test_begin (t, "aifs")
{
- test_pbproc_init (&ctx);
- ca_access_param_t access_param = {
- .access_date = 0, .cw_start_date = 0, .aifs = true,
- };
- ctx.pbproc->detect.hp10_detected = true;
- ctx.pbproc->detect.hp10_detect_date =
- phy_date () - MAC_MS_TO_TCK (1900);
- ctx.pbproc->detect.hp11_detected = true;
- ctx.pbproc->detect.hp11_detect_date =
- phy_date () - MAC_MS_TO_TCK (2900);
- scenario_entry_t entries[] = {
- SCENARIO_ACTION (phy_access, .mfs = NULL,
- .access_param = &access_param,
- .prp_won = true, .slot_count = 64),
- SCENARIO_EVENT (phy_rx_activate, .now = true,
- .pre_detection = false),
- SCENARIO_EVENT (ca_backoff_cancel),
- SCENARIO_EVENT (ca_access_aifs,
- .coexistence_mode =
- MAC_COEXISTENCE_FULL_HYBRID_MODE,
- .snid = ctx.snid, .hybrid = true, .merge = false,
- .nek_switch = 0),
- SCENARIO_EVENT (phy_rx_param, .fc_mode = PHY_FC_MODE (true, 1)),
- SCENARIO_END
- };
- scenario_globals_t globals = {
- .tp = &ctx,
- };
- scenario_run (t, entries, &globals);
- test_fail_unless (ctx.pbproc->fsm.current_state
- == PBPROC_FSM_STATE_IDLE);
- test_fail_unless (memcmp (&ctx.pbproc->times,
- &ctx.pbproc->times_array[true],
- sizeof (pbproc_times_t)) == 0);
- test_fail_unless (ctx.pbproc->detect.hp10_detected == true);
- test_fail_unless (ctx.pbproc->detect.hp11_detected == false);
- ctx.pbproc->detect.hp10_detected = false;
- ctx.pbproc->detect.hp11_detected = false;
- test_pbproc_check_stats (t, &ctx, .aifs = 1);
- test_pbproc_uninit (&ctx);
+ test_pbproc_aifs (t, false, false);
} test_end;
test_begin (t, "aifs merged")
{
- test_pbproc_init (&ctx);
- ctx.pbproc->alloc.merge = true;
- ca_access_param_t access_param = {
- .access_date = 0, .cw_start_date = 0, .aifs = true,
- };
- ctx.pbproc->detect.hp10_detected = true;
- ctx.pbproc->detect.hp10_detect_date =
- phy_date () - MAC_MS_TO_TCK (1900);
- ctx.pbproc->detect.hp11_detected = true;
- ctx.pbproc->detect.hp11_detect_date =
- phy_date () - MAC_MS_TO_TCK (2900);
- scenario_entry_t entries[] = {
- SCENARIO_ACTION (phy_access, .mfs = NULL,
- .access_param = &access_param,
- .prp_won = true, .slot_count = 64),
- SCENARIO_EVENT (ca_access_aifs,
- .coexistence_mode =
- MAC_COEXISTENCE_FULL_HYBRID_MODE,
- .snid = ctx.snid, .hybrid = true, .merge = false,
- .nek_switch = 0),
- SCENARIO_END
- };
- scenario_globals_t globals = {
- .tp = &ctx,
- };
- scenario_run (t, entries, &globals);
- test_fail_unless (ctx.pbproc->fsm.current_state
- == PBPROC_FSM_STATE_IDLE);
- test_fail_unless (ctx.pbproc->detect.hp10_detected == true);
- test_fail_unless (ctx.pbproc->detect.hp11_detected == false);
- ctx.pbproc->detect.hp10_detected = false;
- ctx.pbproc->detect.hp11_detected = false;
- test_pbproc_check_stats (t, &ctx, .aifs = 1);
- test_pbproc_uninit (&ctx);
+ test_pbproc_aifs (t, true, true);
+ } test_end;
+ test_begin (t, "aifs to merged")
+ {
+ test_pbproc_aifs (t, false, true);
+ } test_end;
+ test_begin (t, "aifs from merged")
+ {
+ test_pbproc_aifs (t, true, false);
} test_end;
test_case_begin (t, "memory");
test_begin (t, "memory")