summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Schodet2012-05-25 15:06:41 +0200
committerNicolas Schodet2012-06-27 10:55:09 +0200
commit0d3b423c657820ba26e13609f76915083f320d44 (patch)
treea3ca6a58776c67bc67b4a7fc995c0103dd4a06e0
parent02897b6327ce0ef9107488dbd03dc725ebac7db0 (diff)
cesar/mac/common/store: add travel functions with locked DSR
-rw-r--r--cesar/mac/common/src/store.c87
-rw-r--r--cesar/mac/common/store.h31
-rw-r--r--cesar/mac/common/test/store/src/test_store.c17
3 files changed, 135 insertions, 0 deletions
diff --git a/cesar/mac/common/src/store.c b/cesar/mac/common/src/store.c
index 3675434634..2c1a0a6ad4 100644
--- a/cesar/mac/common/src/store.c
+++ b/cesar/mac/common/src/store.c
@@ -500,6 +500,93 @@ mac_store_mfs_travel_by_tei (mac_store_t *ctx, uint tei,
}
}
+void
+mac_store_mfs_travel_locked (mac_store_t *ctx, mac_store_travel_t travel,
+ void *user)
+{
+ uint i;
+ dbg_assert (ctx);
+ dbg_assert (travel);
+ /* First travel local MFS. */
+ for (i = 0; i < MAC_PLID_NB; i++)
+ {
+ if (ctx->bcast_tx_plid[i])
+ travel (ctx, ctx->bcast_tx_plid[i], user);
+ }
+ if (ctx->bcast_tx_mme)
+ {
+ if (ctx->bcast_tx_mme)
+ travel (ctx, ctx->bcast_tx_mme, user);
+ }
+ for (i = MAC_LLID_MIN; i <= ctx->tx_llid_max; i++)
+ {
+ if (ctx->lglid[i])
+ travel (ctx, ctx->lglid[i], user);
+ }
+ for (i = MAC_GLID_MIN; i <= ctx->glid_max; i++)
+ {
+ if (ctx->lglid[i])
+ travel (ctx, ctx->lglid[i], user);
+ }
+ /* Then unassociated MFS. */
+ list_node_t *u, *uend, *unext;
+ uend = list_end (&ctx->unassociated);
+ for (u = list_begin (&ctx->unassociated); u != uend; u = unext)
+ {
+ unext = list_next (u);
+ travel (ctx, PARENT_OF (mfs_t, common.store_unassociated_link, u),
+ user);
+ }
+ /* Do not forget beacon MFS. */
+ if (ctx->lglid[MAC_LID_DISCOVER])
+ travel (ctx, ctx->lglid[MAC_LID_DISCOVER], user);
+ if (ctx->lglid[MAC_LID_SPC_CENTRAL])
+ travel (ctx, ctx->lglid[MAC_LID_SPC_CENTRAL], user);
+ /* Now travel by TEI. */
+ for (i = MAC_TEI_STA_MIN; i <= MAC_TEI_STA_MAX; i++)
+ if (ctx->sta[i])
+ mac_store_mfs_travel_by_tei_locked (ctx, i, travel, user);
+}
+
+void
+mac_store_mfs_travel_by_tei_locked (mac_store_t *ctx, uint tei,
+ mac_store_travel_t travel, void *user)
+{
+ uint i, j;
+ mac_store_sta_t *sta;
+ dbg_assert (ctx);
+ dbg_assert (MAC_TEI_IS_STA (tei));
+ dbg_assert (travel);
+ sta = ctx->sta[tei];
+ if (sta)
+ {
+ /* Travel MFS. */
+ for (i = 0; i < MAC_STORE_KIND_STA_NB; i++)
+ {
+ for (j = 0; j < MAC_PLID_NB; j++)
+ {
+ if (sta->plid[i][j])
+ travel (ctx, sta->plid[i][j], user);
+ }
+ if (sta->mme[i])
+ travel (ctx, sta->mme[i], user);
+ }
+ if (sta->rx_llid)
+ {
+ mfs_t **rx_llid;
+ rx_llid = sta->rx_llid;
+ if (rx_llid)
+ {
+ for (i = MAC_LLID_MIN; i <= sta->rx_llid_max; i++)
+ {
+ if (rx_llid[i])
+ travel (ctx, rx_llid[i], user);
+ }
+ }
+ }
+ }
+}
+
sta_t *
mac_store_sta_get_ (mac_store_t *ctx, uint tei __FL)
{
diff --git a/cesar/mac/common/store.h b/cesar/mac/common/store.h
index 446795d544..f9debc70cc 100644
--- a/cesar/mac/common/store.h
+++ b/cesar/mac/common/store.h
@@ -269,6 +269,37 @@ mac_store_mfs_travel_by_tei (mac_store_t *ctx, uint tei,
mac_store_travel_t travel, void *user);
/**
+ * Call the provided callback for all MFS, with DSR locked.
+ * \param ctx store context
+ * \param travel callback function
+ * \param user user data
+ * \context DSR
+ *
+ * \see mac_store_mfs_travel.
+ *
+ * DSR should be locked to call this function.
+ */
+void
+mac_store_mfs_travel_locked (mac_store_t *ctx, mac_store_travel_t travel,
+ void *user);
+
+/**
+ * Call the provided callback for all MFS connected to a STA, with DSR locked.
+ * \param ctx store context
+ * \param tei terminal equipment id of the STA
+ * \param travel callback function
+ * \param user user data
+ * \context DSR
+ *
+ * \see mac_store_mfs_travel_by_tei.
+ *
+ * DSR should be locked to call this function.
+ */
+void
+mac_store_mfs_travel_by_tei_locked (mac_store_t *ctx, uint tei,
+ mac_store_travel_t travel, void *user);
+
+/**
* Get a STA information structure pointer.
* \param ctx store context
* \param tei peer terminal equipment id
diff --git a/cesar/mac/common/test/store/src/test_store.c b/cesar/mac/common/test/store/src/test_store.c
index e375710a39..ea1129f285 100644
--- a/cesar/mac/common/test/store/src/test_store.c
+++ b/cesar/mac/common/test/store/src/test_store.c
@@ -346,6 +346,9 @@ store_basic_test_case (test_t t)
} test_end;
test_begin (t, "travel")
{
+ ctx->travel_mfs_nb = 0;
+ ctx->travel_mfs_alias_nb = 0;
+ ctx->travel_mfs_unassoc_nb = 0;
mac_store_mfs_travel (ctx->store, travel_mfs, ctx);
uint mfs_alias = ctx->travel_mfs_alias_nb / 2;
test_fail_unless (ctx->travel_mfs_alias_nb % 2 == 0
@@ -355,6 +358,20 @@ store_basic_test_case (test_t t)
ctx->travel_mfs_nb - mfs_alias, mfs_alias,
ctx->travel_mfs_unassoc_nb);
} test_end;
+ test_begin (t, "travel locked")
+ {
+ ctx->travel_mfs_nb = 0;
+ ctx->travel_mfs_alias_nb = 0;
+ ctx->travel_mfs_unassoc_nb = 0;
+ mac_store_mfs_travel_locked (ctx->store, travel_mfs, ctx);
+ uint mfs_alias = ctx->travel_mfs_alias_nb / 2;
+ test_fail_unless (ctx->travel_mfs_alias_nb % 2 == 0
+ && (ctx->travel_mfs_nb - mfs_alias
+ == ctx->used_mfs_nb));
+ test_verbose_print ("mfs = %d, alias = %d, unassoc = %d",
+ ctx->travel_mfs_nb - mfs_alias, mfs_alias,
+ ctx->travel_mfs_unassoc_nb);
+ } test_end;
/* Clean up. */
test_begin (t, "cleanup")
{