summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cesar/cl/src/cl.c68
-rw-r--r--cesar/cl/test/utest/Config1
-rw-r--r--cesar/cl/test/utest/Makefile1
-rw-r--r--cesar/cl/test/utest/src/misc.c47
4 files changed, 76 insertions, 41 deletions
diff --git a/cesar/cl/src/cl.c b/cesar/cl/src/cl.c
index dc60174a61..2cc3efdcc9 100644
--- a/cesar/cl/src/cl.c
+++ b/cesar/cl/src/cl.c
@@ -94,6 +94,29 @@ cl_classifer_get_lid (cl_t *ctx, uint tei, uint tag,
return lid;
}
+/**
+ * Compute the data rate for a station based on the TEI.
+ * \param ctx CL context.
+ * \param mfs the MFS used for the transmission or reception.
+ * \param length the data length.
+ */
+PRIVATE void
+cl_compute_datarate_on_sta (cl_t *ctx, mfs_t *mfs, uint length)
+{
+#if CONFIG_CL_DATA_RATE
+ if (MAC_TEI_IS_STA (mfs->common.tei))
+ {
+ sta_t *sta = mac_store_sta_get (ctx->mac_store, mfs->common.tei);
+ if (sta)
+ {
+ data_rate_update_info (
+ mfs->common.tx ? &sta->tx_data_rate : &sta->rx_data_rate,
+ length);
+ blk_release (sta);
+ }
+ }
+#endif
+}
/**
* Send a data once the TEI has been find.
@@ -118,7 +141,6 @@ cl_data_send_with_tei (cl_t *ctx, u8 *buffer, uint length, uint tei,
bool acs;
bool drop;
mfs_tx_t *mfs;
- sta_t* sta;
dbg_assert (ctx);
dbg_assert (buffer);
@@ -157,18 +179,7 @@ cl_data_send_with_tei (cl_t *ctx, u8 *buffer, uint length, uint tei,
ctx->data_send_link.tag = tag;
sar_msdu_add (ctx->sar, buffer, length, mfs, cl_data,
arrival_time_ntb);
-
- /* update data rate informations associated to the TX
- * from the local sta to the associated sta */
- if (MAC_TEI_IS_STA (tei) && CONFIG_CL_DATA_RATE)
- {
- sta = mac_store_sta_get (ctx->mac_store, tei);
- if (sta)
- {
- data_rate_update_info (&(sta->tx_data_rate), length);
- blk_release (sta);
- }
- }
+ cl_compute_datarate_on_sta (ctx, PARENT_OF (mfs_t, tx, mfs), length);
}
else
{
@@ -572,18 +583,8 @@ cl_send_multiunicast (cl_t *ctx, u8 *buffer, uint length, bool mme, uint tag,
slab_addref (cl_data);
sar_msdu_add (ctx->sar, buffer, length, mfs, cl_data,
arrival_time_ntb);
-
- /* update data rate informations associated to the TX
- * from the local sta to the associated sta */
- if (CONFIG_CL_DATA_RATE)
- {
- sta = mac_store_sta_get (ctx->mac_store, tei);
- if (sta)
- {
- data_rate_update_info (&(sta->tx_data_rate), length);
- blk_release (sta);
- }
- }
+ cl_compute_datarate_on_sta (
+ ctx, PARENT_OF (mfs_t, tx, mfs), length);
}
else
{
@@ -931,9 +932,6 @@ void cl_data_recv_init (cl_t *cl, cl_data_recv_cb_t cb, void *user)
*/
void cl_data_recv (cl_t *ctx, u8 *buffer, uint length, mfs_rx_t *mfs)
{
- uint tei;
- sta_t* sta;
-
dbg_assert (ctx);
dbg_assert (buffer);
dbg_assert ((length >= ETH_PACKET_MIN_SIZE_ALLOWED)
@@ -951,21 +949,9 @@ void cl_data_recv (cl_t *ctx, u8 *buffer, uint length, mfs_rx_t *mfs)
TRACE_U64 (smac), length);
(*ctx->data_rx.cb) (ctx->data_rx.user, buffer, length);
cl_brg_rx_add (ctx, smac, mfs->common.tei);
-
/* update data rate informations associated to the RX
* from the associated sta to the local sta */
- tei = mfs->common.tei;
-
- if (MAC_TEI_IS_STA (tei) && CONFIG_CL_DATA_RATE)
- {
- sta = mac_store_sta_get (ctx->mac_store, tei);
- if (sta)
- {
- data_rate_update_info(&(sta->rx_data_rate), length);
- blk_release (sta);
- }
- }
-
+ cl_compute_datarate_on_sta (ctx, PARENT_OF (mfs_t, rx, mfs), length);
/* Debug info. */
GPIO_TOGGLE (LED_CL_RX);
}
diff --git a/cesar/cl/test/utest/Config b/cesar/cl/test/utest/Config
index 2c7c85cbed..7f25c115f1 100644
--- a/cesar/cl/test/utest/Config
+++ b/cesar/cl/test/utest/Config
@@ -1,2 +1,3 @@
CONFIG_DEBUG_FATAL_CATCH = y
CONFIG_TRACE = y
+CONFIG_CL_DATA_RATE = y
diff --git a/cesar/cl/test/utest/Makefile b/cesar/cl/test/utest/Makefile
index 959c0fd9fc..c68a702408 100644
--- a/cesar/cl/test/utest/Makefile
+++ b/cesar/cl/test/utest/Makefile
@@ -1,5 +1,6 @@
BASE = ../../..
+DEFS = -DNO_PRIVATE
HOST_PROGRAMS = cl
cl_SOURCES = cl.c test.c send.c receive.c misc.c brg_rx.c
diff --git a/cesar/cl/test/utest/src/misc.c b/cesar/cl/test/utest/src/misc.c
index 401d834445..dda06ac235 100644
--- a/cesar/cl/test/utest/src/misc.c
+++ b/cesar/cl/test/utest/src/misc.c
@@ -23,6 +23,9 @@ cl_classifer_get_lid (cl_t *ctx, uint tei, uint tag,
bool *drop);
void
+cl_compute_datarate_on_sta (cl_t *ctx, mfs_t *mfs, uint length);
+
+void
cl_test_case__classifier (test_t test)
{
test_case_begin (test, "Testing the Classifier");
@@ -296,10 +299,54 @@ cl_test_case__cl_update_igmp_groups (test_t test)
}
void
+cl_test_case__cl_compute_datarate_on_sta_mfs (test_t test, cl_test_t *ctx,
+ mfs_t *mfs)
+{
+ uint i;
+ test_within (test);
+ for (i = 0; i < 100; i++)
+ {
+ cl_compute_datarate_on_sta (ctx->cl, mfs, 1500);
+ }
+ sta_t *sta = mac_store_sta_get (ctx->mac_store, mfs->common.tei);
+ test_fail_unless (sta);
+ test_fail_unless (mfs->common.tx ? sta->tx_data_rate.data_rate :
+ sta->rx_data_rate.data_rate == i*1500);
+ blk_release (sta);
+}
+
+void
+cl_test_case__cl_compute_datarate_on_sta (test_t test)
+{
+ test_case_begin (test, "Data rate");
+ cl_test_t ctx;
+ cl_test_init (&ctx, 0x4354);
+ test_begin (test, "TX/RX")
+ {
+ uint i;
+ bool iter[] = {false, true};
+ for (i = 0; i < COUNT (iter); i++)
+ {
+ bool added;
+ mfs_t *mfs = mac_store_mfs_add (
+ ctx.mac_store, iter[i], false, false, 1, 1, &added);
+ test_fail_unless (added);
+ cl_test_case__cl_compute_datarate_on_sta_mfs (test, &ctx, mfs);
+ mac_store_mfs_remove (ctx.mac_store, mfs);
+ dbg_check (mac_store_sta_remove (ctx.mac_store, 1));
+ blk_release (mfs);
+ }
+ }
+ test_end;
+ cl_test_uninit (&ctx);
+}
+
+void
cl_test_suite_misc (test_t test)
{
test_suite_begin (test, "CL miscellaneous");
cl_test_case__classifier (test);
cl_test_case__mactotei_test_api_copy_tag_and_tei (test);
cl_test_case__cl_update_igmp_groups (test);
+ cl_test_case__cl_compute_datarate_on_sta (test);
}