summaryrefslogtreecommitdiff
path: root/cesar/cp/sta
diff options
context:
space:
mode:
authorJean-Philippe SAVE2011-04-13 13:51:41 +0200
committerJean-Philippe SAVE2011-04-13 13:51:41 +0200
commit8b2f777e95e3af6a32572a2af9e31915611db12e (patch)
tree8128f244aefebfecdf4307d2ce8cf4db7e9ebad6 /cesar/cp/sta
parent99e2743b4cdebec66f4626b98ae53f8c168029bd (diff)
Revert "Revert "cesar/cp/sta/mgr: restore partial ack, closes #214""
This reverts commit 99e2743b4cdebec66f4626b98ae53f8c168029bd.
Diffstat (limited to 'cesar/cp/sta')
-rw-r--r--cesar/cp/sta/mgr/src/sta_mgr.c75
-rw-r--r--cesar/cp/sta/mgr/test/src/sta_mgr.c191
2 files changed, 65 insertions, 201 deletions
diff --git a/cesar/cp/sta/mgr/src/sta_mgr.c b/cesar/cp/sta/mgr/src/sta_mgr.c
index a05739828c..db87928fda 100644
--- a/cesar/cp/sta/mgr/src/sta_mgr.c
+++ b/cesar/cp/sta/mgr/src/sta_mgr.c
@@ -35,64 +35,33 @@
* station to which the packet is send.
* \param ctx the module context.
*
- * This function choose the station using the data of the tone maps in the
- * station contained in the mac store. It shall insert in the mac config the
- * station's TEI which will acknowledge the packets.
- * The station manager is responsible to elects another station if the current
- * one is removed or if another one shall become the acknowledge station.
+ * This function choose the station randomly on the network.
*/
void
cp_sta_mgr_elects_sta_partial_ack (cp_t *ctx)
{
dbg_assert (ctx);
-
- /* FIXME:To be correctly specified, the BLE seems to not be a good
- * criteria for the partial ack, when we only have ROBO tonemap the BLE
- * is the same for all the stations. */
-// /* Do nothing if your AVLN is not set. */
-// if (ctx->sta_mgr.our_avln != NULL)
-// {
-// cp_sta_t *sta;
-// sta_t *sta_store;
-//
-// dbg_assert (ctx->mac_store);
-// dbg_assert (ctx->mac_config);
-//
-// /* The BLE is a 8 bits long field. */
-// uint ble = 0x100;
-// cp_tei_t sta_tei = MAC_TEI_UNASSOCIATED;
-//
-// /* Parse the station manager for all the station present in our AVLN.
-// * The one which as the lesser BLE will be choose to be the partial
-// * ack's station. */
-// for (sta = cp_net_sta_get_first (ctx, ctx->sta_mgr.our_avln,
-// CP_NET_STA_ASSOC);
-// sta;
-// sta = cp_net_sta_get_next (ctx, ctx->sta_mgr.our_avln, sta))
-// {
-// /* Get the station from the mac store. */
-// sta_store = mac_store_sta_get (ctx->mac_store, cp_sta_get_tei
-// (sta));
-// dbg_assert (sta_store);
-// if (sta_store->tx_tonemaps
-// && (sta_store->tx_tonemaps->default_tmi < TONEMAP_INDEX_NB))
-// {
-// uint tmi = sta_store->tx_tonemaps->default_tmi;
-//
-// if (ble > sta_store->tx_tonemaps->tm[tmi]->ble)
-// {
-// ble = sta_store->tx_tonemaps->tm[tmi]->ble;
-// sta_tei = cp_sta_get_tei (sta);
-// }
-// }
-//
-// blk_release (sta_store);
-// }
-//
-// /* Store the TEI of the station. */
-// if (sta_tei != MAC_TEI_UNASSOCIATED)
-// ctx->mac_config->partial_ack_tei_default = sta_tei;
-// }
+ cp_net_t *net = ctx->sta_mgr.our_avln;
+ if (net)
+ {
+ cp_sta_t *sta;
+ u8 *tei_table = blk_alloc ();
+ uint tei_nb = 0;
+ /* Get all the TEI of the network and store it into the tei table. */
+ /* Store the TEI of the station. */
+ for (sta = cp_net_sta_get_first (ctx, net, CP_NET_STA_ASSOC);
+ sta;
+ sta = cp_net_sta_get_next (ctx, net, sta))
+ tei_table[tei_nb++] = cp_sta_get_tei (sta);
+ if (tei_nb)
+ {
+ /* Choose the TEI of the partial ACK station, */
+ uint pos = lib_rnd_uniform (&ctx->rnd, tei_nb);
+ ctx->mac_config->partial_ack_tei_default = tei_table[pos];
+ }
+ /* Release the block used. */
+ blk_release (tei_table);
+ }
}
/**
diff --git a/cesar/cp/sta/mgr/test/src/sta_mgr.c b/cesar/cp/sta/mgr/test/src/sta_mgr.c
index aeeba2109f..fde37c53a6 100644
--- a/cesar/cp/sta/mgr/test/src/sta_mgr.c
+++ b/cesar/cp/sta/mgr/test/src/sta_mgr.c
@@ -979,19 +979,11 @@ test_case__cp_net_is_empty (test_t test)
test_begin (test, "Network is empty")
{
cp_t cp;
- cl_t cl;
- sar_t sar;
cp_net_t *net;
cp_sta_t *sta;
uint i;
/* configuring the test. */
- memset (&cp, 0, sizeof (cp_t));
- cp.sar = &sar;
- cp.cl = &cl;
- cl.mactotei = NULL;
- sar.mac_store = mac_store_init ();
- cp.mac_store = sar.mac_store;
- cp_sta_mgr_init (&cp);
+ test_sta_mgr_init (&cp);
test_fail_unless (cp_sta_mgr_net_list_is_empty (&cp) == true);
for (i = 0; i < HPAV_AVLNS_NB_MAX; i++)
{
@@ -1028,7 +1020,7 @@ test_case__cp_net_is_empty (test_t test)
test_fail_unless (cp_sta_mgr_net_list_is_empty (&cp) == true);
net->present = true;
test_fail_unless (cp_sta_mgr_net_list_is_empty (&cp) == true);
- cp_sta_mgr_uninit (&cp);
+ test_sta_mgr_uninit (&cp);
}
test_end;
}
@@ -1368,144 +1360,47 @@ void
test_case__cp_sta_mgr_partial_ack (test_t test)
{
test_case_begin (test, "Partial acknowledge");
-
-// test_begin (test, "Partial ACK")
-// {
-// cp_t cp;
-// cl_t cl;
-// sar_t sar;
-// mac_config_t mac_config;
-// cp_net_t *net;
-// cp_sta_t *sta;
-// sta_t *sta_store;
-// uint i;
-// uint nbsta = 10;
-// lib_rnd_t rand;
-//
-// memset (&cl, 0, sizeof (cl_t));
-// memset (&sar, 0, sizeof (sar_t));
-// memset (&mac_config, 0, sizeof (mac_config_t));
-// cp_sta_mgr_init (&cp);
-// cp.mac_store = mac_store_init ();
-// cp.cl = (cl_t *) &cl;
-// cp.sar = &sar;
-// sar.mac_store = cp.mac_store;
-// cp.mac_config = &mac_config;
-//
-// lib_rnd_init (&rand, 0x123);
-// memset (&mac_config, 0, sizeof (mac_config));
-//
-// /* First test, elects a station when our station does not makes part
-// * of any AVLN. */
-// cp_sta_mgr_elects_sta_partial_ack (&cp);
-// test_fail_unless (mac_config.partial_ack_tei_default == 0);
-//
-// /* Add the AVLN and configure it as our AVLN. */
-// net = cp_sta_mgr_add_avln (&cp, 1, 1);
-// cp_sta_mgr_set_our_avln (&cp, net);
-//
-// /* Create some stations. */
-// for (i = 1; i < nbsta; i++)
-// {
-// /* Add the station in the station manager and at the same time in
-// * the mac store. */
-// sta = cp_sta_mgr_sta_add (&cp, net, i, i);
-//
-// /* Get the station from the mac store. */
-// sta_store = mac_store_sta_get (cp.mac_store, i);
-// dbg_assert (sta_store);
-//
-// /* Modify the default tone map to configure the BLE.*/
-// if (sta_store->tx_tonemaps)
-// {
-// /* Allocate the tone map. */
-// sta_store->tx_tonemaps->tm[4] = tonemap_alloc ();
-// sta_store->tx_tonemaps->default_tmi = 4;
-// sta_store->tx_tonemaps->tm[4]->ble = lib_rnd32 (&rand);
-// }
-//
-// blk_release (sta_store);
-// slab_release (sta);
-// }
-//
-// cp_sta_mgr_elects_sta_partial_ack (&cp);
-// test_fail_unless (mac_config.partial_ack_tei_default == 2);
-//
-// /* Modify the BLE for station 2. */
-// sta_store = mac_store_sta_get (cp.mac_store, 2);
-// dbg_assert (sta_store);
-// sta_store->tx_tonemaps->tm[0]->ble = 51;
-// blk_release (sta_store);
-//
-// cp_sta_mgr_elects_sta_partial_ack (&cp);
-// test_fail_unless (mac_config.partial_ack_tei_default == 3);
-//
-//
-// /* Removes the current acknowledge station from the network. */
-// cp_sta_mgr_sta_remove_assoc (&cp, net, 3);
-// test_fail_unless (mac_config.partial_ack_tei_default == 8);
-//
-// /* Ends the test. */
-// cp_sta_mgr_set_our_avln (&cp, NULL);
-//
-// mac_store_uninit (cp.mac_store);
-// cp_sta_mgr_uninit (&cp);
-// }
-// test_end;
-//
-// test_begin (test, "Partial ACK no Tone maps")
-// {
-// cp_t cp;
-// cl_t cl;
-// sar_t sar;
-// mac_config_t mac_config;
-// cp_net_t *net;
-// cp_sta_t *sta;
-// uint i;
-// uint nbsta = 10;
-// lib_rnd_t rand;
-//
-// memset (&cl, 0, sizeof (cl_t));
-// memset (&sar, 0, sizeof (sar_t));
-// memset (&mac_config, 0, sizeof (mac_config_t));
-// cp_sta_mgr_init (&cp);
-// cp.mac_store = mac_store_init ();
-// cp.cl = (cl_t *) &cl;
-// cp.sar = &sar;
-// sar.mac_store = cp.mac_store;
-// cp.mac_config = &mac_config;
-//
-// lib_rnd_init (&rand, 0x123);
-// memset (&mac_config, 0, sizeof (mac_config));
-//
-// /* First test, elects a station when our station does not makes part
-// * of any AVLN. */
-// cp_sta_mgr_elects_sta_partial_ack (&cp);
-// test_fail_unless (mac_config.partial_ack_tei_default == 0);
-//
-// /* Add the AVLN and configure it as our AVLN. */
-// net = cp_sta_mgr_add_avln (&cp, 1, 1);
-// cp_sta_mgr_set_our_avln (&cp, net);
-//
-// /* Create some stations. */
-// for (i = 1; i < nbsta; i++)
-// {
-// /* Add the station in the station manager and at the same time in
-// * the mac store. */
-// sta = cp_sta_mgr_sta_add (&cp, net, i, i);
-// slab_release (sta);
-// }
-//
-// cp_sta_mgr_elects_sta_partial_ack (&cp);
-// test_fail_unless (mac_config.partial_ack_tei_default == 0);
-//
-// /* Ends the test. */
-// cp_sta_mgr_set_our_avln (&cp, NULL);
-//
-// mac_store_uninit (cp.mac_store);
-// cp_sta_mgr_uninit (&cp);
-// }
-// test_end;
+ cp_t cp;
+ test_sta_mgr_init (&cp);
+ cp_net_t *net = cp_sta_mgr_add_avln (&cp, 1, 1);
+ cp_sta_mgr_set_our_avln (&cp, net);
+ cp_sta_own_data_set_tei (&cp, 254);
+ test_begin (test, "No STA")
+ {
+ cp_sta_mgr_elects_sta_partial_ack (&cp);
+ test_fail_unless (cp.mac_config->partial_ack_tei_default
+ == MAC_TEI_UNASSOCIATED);
+ }
+ test_end;
+ test_begin (test, "Single STA")
+ {
+ uint i;
+ cp_sta_t *sta = cp_sta_mgr_sta_add (&cp, net, 1, 1);
+ for (i = 0; i < 20; i++)
+ {
+ cp_sta_mgr_elects_sta_partial_ack (&cp);
+ test_fail_unless (cp.mac_config->partial_ack_tei_default
+ == cp_sta_get_tei (sta));
+ }
+ slab_release (sta);
+ }
+ test_end;
+ test_begin (test, "Two STA")
+ {
+ uint i;
+ cp_sta_t *sta = cp_sta_mgr_sta_add (&cp, net, 2, 2);
+ cp_tei_t tei_cmp[] = { 1, 1, 1, 2, 1, 2, 2, 1, 1, 2, 1, 1, 2, 1, 2, 1,
+ 1, 1, 2, 2 };
+ for (i = 0; i < 20; i++)
+ {
+ cp_sta_mgr_elects_sta_partial_ack (&cp);
+ test_fail_unless (cp.mac_config->partial_ack_tei_default ==
+ tei_cmp[i]);
+ }
+ slab_release (sta);
+ }
+ test_end;
+ test_sta_mgr_uninit (&cp);
}
void