summaryrefslogtreecommitdiff
path: root/cesar/cp/sta/action
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/cp/sta/action')
-rw-r--r--cesar/cp/sta/action/src/misc.c145
-rw-r--r--cesar/cp/sta/action/test/utest/src/misc.c222
2 files changed, 266 insertions, 101 deletions
diff --git a/cesar/cp/sta/action/src/misc.c b/cesar/cp/sta/action/src/misc.c
index 0936956cd7..17b4b828b9 100644
--- a/cesar/cp/sta/action/src/misc.c
+++ b/cesar/cp/sta/action/src/misc.c
@@ -557,110 +557,71 @@ reset_link_stats (mfs_t *mfs, cp_msg_cm_link_stats_tlflag_t transmit)
void
cp_sta_action_process_cm_link_stats_req (cp_t *ctx, cp_mme_rx_t *rx_mme)
{
+ bool error = true;
dbg_assert (ctx);
dbg_assert (rx_mme);
-
+ cp_mme_tx_t *tx_mme;
cp_msg_cm_link_stats_req_t req_data;
- cp_msg_cm_link_stats_restype_t res_type;
- cp_tei_t tei;
- mfs_t *mfs = NULL;
-
- res_type = CM_LINK_STATS_RESTYPE_SUCCESS;
-
- if (cp_msg_cm_link_stats_req_receive (ctx, rx_mme, &req_data))
+ bool mme_read_ok =
+ cp_msg_cm_link_stats_req_receive (ctx, rx_mme, &req_data);
+ if (mme_read_ok
+ && req_data.nid == cp_sta_own_data_get_nid (ctx)
+ && MAC_IS_VALID (req_data.mac))
{
- cp_mme_tx_t *tx_mme;
-
- /* check req_type */
- if (req_data.req_type >= CM_LINK_STATS_REQTYPE_NB)
- res_type = CM_LINK_STATS_RESTYPE_FAILURE;
-
- /* Check nid requested is our avln */
- if (res_type == CM_LINK_STATS_RESTYPE_SUCCESS)
+ mfs_t *mfs;
+ bool tx = req_data.transmit == CM_LINK_STATS_TLFLAG_TRANSMIT;
+ bool mme = req_data.mgmt_flag == CM_LINK_STATS_MGMT_MGMT;
+ uint lid = mme ? MAC_LID_NONE : req_data.lid;
+ /* Get station from MAC Address. */
+ cp_sta_t *sta= cp_sta_mgr_sta_get_from_mac (ctx, req_data.mac);
+ if (sta)
{
- cp_net_t* our_avln;
-
- our_avln = cp_sta_mgr_get_our_avln (ctx);
-
- if (req_data.nid != our_avln->nid)
- res_type = CM_LINK_STATS_RESTYPE_FAILURE;
- }
-
- /* Get tei from mac */
- if (res_type == CM_LINK_STATS_RESTYPE_SUCCESS)
- {
- cp_sta_t *sta;
-
- sta = cp_sta_mgr_sta_get_from_mac (ctx, req_data.mac);
- if (sta)
- {
- // The station exists get the TEI.
- tei = cp_sta_get_tei (sta);
- slab_release (sta);
- }
- else
- res_type = CM_LINK_STATS_RESTYPE_FAILURE;
- }
-
- if (res_type == CM_LINK_STATS_RESTYPE_SUCCESS)
- {
- switch (req_data.transmit)
+ cp_tei_t tei = cp_sta_get_tei (sta);
+ slab_release (sta);
+ if (mme || MAC_LID_IS_XLID (lid))
{
- case CM_LINK_STATS_TLFLAG_TRANSMIT:
- mfs = mac_store_mfs_get(ctx->mac_store, true, false,
- req_data.mgmt_flag, req_data.lid, tei);
- if (!mfs)
- res_type = CM_LINK_STATS_RESTYPE_FAILURE;
- break;
-
- case CM_LINK_STATS_TLFLAG_RECEIVE:
- mfs = mac_store_mfs_get(ctx->mac_store, false, false,
- req_data.mgmt_flag, req_data.lid, tei);
- if (!mfs)
- res_type = CM_LINK_STATS_RESTYPE_FAILURE;
- break;
-
- default:
- break;
- }
- }
-
- tx_mme = cp_msg_cm_link_stats_cnf_send_begin (ctx, &rx_mme->peer,
- req_data.req_id, res_type);
-
- if (res_type == CM_LINK_STATS_RESTYPE_SUCCESS)
- {
- switch (req_data.req_type)
- {
- case CM_LINK_STATS_REQTYPE_GET_AND_RESET:
- cp_msg_cm_link_stats_cnf_send (ctx, tx_mme, mfs,
- req_data.transmit);
- reset_link_stats(mfs, req_data.transmit);
- break;
-
- case CM_LINK_STATS_REQTYPE_GET:
- cp_msg_cm_link_stats_cnf_send (ctx, tx_mme, mfs,
- req_data.transmit);
- break;
-
- case CM_LINK_STATS_REQTYPE_RESET:
- reset_link_stats(mfs, req_data.transmit);
- break;
-
- default:
- break;
+ mfs = mac_store_mfs_get (ctx->mac_store, tx, false, mme, lid,
+ tei);
+ if (mfs)
+ {
+ tx_mme = cp_msg_cm_link_stats_cnf_send_begin (
+ ctx, &rx_mme->peer, req_data.req_id,
+ CM_LINK_STATS_RESTYPE_SUCCESS);
+ switch (req_data.req_type)
+ {
+ case CM_LINK_STATS_REQTYPE_RESET:
+ reset_link_stats (mfs, req_data.transmit);
+ cp_msg_cm_link_stats_cnf_send_end (ctx, tx_mme);
+ break;
+ case CM_LINK_STATS_REQTYPE_GET:
+ cp_msg_cm_link_stats_cnf_send (
+ ctx, tx_mme, mfs, req_data.transmit);
+ cp_msg_cm_link_stats_cnf_send_end (ctx, tx_mme);
+ break;
+ case CM_LINK_STATS_REQTYPE_GET_AND_RESET:
+ cp_msg_cm_link_stats_cnf_send (
+ ctx, tx_mme, mfs, req_data.transmit);
+ cp_msg_cm_link_stats_cnf_send_end (ctx, tx_mme);
+ reset_link_stats (mfs, req_data.transmit);
+ break;
+ default:
+ dbg_assert_default ();
+ }
+ error = false;
+ blk_release (mfs);
+ }
}
}
-
- /* release the mfs access */
- if (mfs)
- blk_release (mfs);
-
+ }
+ if (error)
+ {
+ tx_mme = cp_msg_cm_link_stats_cnf_send_begin (
+ ctx, &rx_mme->peer, mme_read_ok ? req_data.req_id : 0,
+ CM_LINK_STATS_RESTYPE_FAILURE);
cp_msg_cm_link_stats_cnf_send_end (ctx, tx_mme);
}
}
-
void
cp_sta_action_process_cm_sta_cap_req (cp_t *ctx, cp_mme_rx_t *rx_mme)
{
diff --git a/cesar/cp/sta/action/test/utest/src/misc.c b/cesar/cp/sta/action/test/utest/src/misc.c
index df68c86d77..a8e147ef99 100644
--- a/cesar/cp/sta/action/test/utest/src/misc.c
+++ b/cesar/cp/sta/action/test/utest/src/misc.c
@@ -1452,13 +1452,102 @@ misc_nw_info_test_case (test_t t)
}
void
+misc_link_stats_test_case_common (test_t t,
+ cp_msg_cm_link_stats_tlflag_t transmit)
+{
+ test_sta_action_t ctx;
+ cp_t *cp = &ctx.cp;
+ char msg [10];
+ /* init globals */
+ scenario_globals_t globals = {
+ .cp = &ctx.cp,
+ };
+ cp_mme_peer_t peer = CP_MME_PEER (0x112233445577ull, 5);
+ cp_mme_tx_t mme_to_send;
+ globals.mme = &mme_to_send;
+ test_sta_action_init (&ctx);
+ cp_net_t *my_net = cp_sta_mgr_add_avln (cp, 1, 1);
+ cp_sta_mgr_set_our_avln (cp, my_net);
+ if (transmit == CM_LINK_STATS_TLFLAG_TRANSMIT)
+ strcpy (msg, "TX");
+ else
+ strcpy (msg, "RX");
+ test_begin (t, msg)
+ {
+ uint lid;
+ bool added;
+ cp_sta_t *my_sta = cp_sta_mgr_sta_add (cp, my_net, 254,
+ MAC_ADDRESS (0x00, 0x13, 0xd7, 0x01, 0x11, 0x12));
+ for (lid = 0; lid <= 0xff; lid++)
+ {
+ if (MAC_LID_IS_XLID (lid))
+ {
+ mfs_t *mfs = mac_store_mfs_add (
+ cp->mac_store, !transmit, false, false, lid,
+ cp_sta_get_tei (my_sta),
+ &added);
+ test_fail_unless (added);
+ scenario_entry_t entries[] = {
+ SCENARIO_ACTION (process_cm_link_stats_req, .peer = peer),
+ SCENARIO_EVENT (cp_msg_cm_link_stats_req_receive,
+ .ok = true,
+ .req_type = CM_LINK_STATS_REQTYPE_GET,
+ .req_id = 0,
+ .nid = cp_net_get_nid (cp, my_net),
+ .lid = lid,
+ .transmit = transmit,
+ .mgmt_flag = CM_LINK_STATS_MGMT_NOT_MGMT,
+ .mac = cp_sta_get_mac_address (my_sta)),
+ SCENARIO_EVENT (cp_msg_cm_link_stats_cnf_send_begin,
+ .peer = peer, .req_id = 0,
+ .res_type = CM_LINK_STATS_RESTYPE_SUCCESS),
+ SCENARIO_EVENT (cp_msg_cm_link_stats_cnf_send,
+ .mfs = mfs,
+ .transmit = transmit),
+ SCENARIO_EVENT (cp_msg_cm_link_stats_cnf_send_end),
+ SCENARIO_END
+ };
+ scenario_run (t, entries, &globals);
+ mac_store_mfs_remove (cp->mac_store, mfs);
+ blk_release (mfs);
+ }
+ else
+ {
+ scenario_entry_t entries[] = {
+ SCENARIO_ACTION (process_cm_link_stats_req, .peer = peer),
+ SCENARIO_EVENT (cp_msg_cm_link_stats_req_receive,
+ .ok = true,
+ .req_type = CM_LINK_STATS_REQTYPE_GET,
+ .req_id = 0,
+ .nid = cp_net_get_nid (cp, my_net),
+ .lid = lid,
+ .transmit = transmit,
+ .mgmt_flag = CM_LINK_STATS_MGMT_NOT_MGMT,
+ .mac = cp_sta_get_mac_address (my_sta)),
+ SCENARIO_EVENT (cp_msg_cm_link_stats_cnf_send_begin,
+ .peer = peer, .req_id = 0,
+ .res_type = CM_LINK_STATS_RESTYPE_FAILURE),
+ SCENARIO_EVENT (cp_msg_cm_link_stats_cnf_send_end),
+ SCENARIO_END
+ };
+ scenario_run (t, entries, &globals);
+ }
+ }
+ cp_sta_mgr_sta_remove (cp, my_sta);
+ slab_release (my_sta);
+ test_sta_action_uninit (&ctx);
+ }
+ test_end;
+}
+
+void
misc_link_stats_test_case (test_t t)
{
/* init test context */
test_sta_action_t ctx;
cp_t *cp = &ctx.cp;
const cp_tei_t tei_1 = 10;
- const mac_t mac_1 = 0x111111111111ull;
+ const mac_t mac_1 = MAC_ADDRESS (0x00, 0x13, 0xd7, 0x00, 0x00, 0x01);
u8 lid_tx = 0;
u8 lid_rx = 1;
cp_nid_t our_nid = 0x4242;
@@ -1475,11 +1564,17 @@ misc_link_stats_test_case (test_t t)
test_sta_action_init (&ctx);
test_case_begin (t, "link_stats_req invalid message");
- test_begin (t, "ok")
+ test_begin (t, "nok")
{
scenario_entry_t entries[] = {
SCENARIO_ACTION (process_cm_link_stats_req, .peer = peer),
- SCENARIO_EVENT (cp_msg_cm_link_stats_req_receive, .ok = false),
+ SCENARIO_EVENT (cp_msg_cm_link_stats_req_receive, .ok = false,
+ .req_id = 1,
+ .req_type = CM_LINK_STATS_REQTYPE_GET),
+ SCENARIO_EVENT (cp_msg_cm_link_stats_cnf_send_begin,
+ .peer = peer, .req_id = 0,
+ .res_type = CM_LINK_STATS_RESTYPE_FAILURE),
+ SCENARIO_EVENT (cp_msg_cm_link_stats_cnf_send_end),
SCENARIO_END
};
scenario_run (t, entries, &globals);
@@ -1575,18 +1670,87 @@ misc_link_stats_test_case (test_t t)
};
scenario_run (t, entries, &globals);
} test_end;
+ mac_store_mfs_remove (cp->mac_store, m_tx);
+ blk_release (m_tx);
+
+ /* Create a tx link (tx=true, broadcast=true, mme=false) */
+ added = false;
+ m_tx = mac_store_mfs_add (cp->mac_store, true, true, false,
+ 0, 0xff, &added);
+ dbg_check (added);
+
+ test_case_begin (t, "link_stats_req valid tx link req");
+ test_begin (t, "ok")
+ {
+ test_fail_unless (added == true);
+
+ scenario_entry_t entries[] = {
+ SCENARIO_ACTION (process_cm_link_stats_req, .peer = peer),
+ SCENARIO_EVENT (cp_msg_cm_link_stats_req_receive, .ok = true,
+ .req_type = CM_LINK_STATS_REQTYPE_GET, .req_id = 4,
+ .nid = our_nid, .lid = 0,
+ .transmit = CM_LINK_STATS_TLFLAG_TRANSMIT,
+ .mgmt_flag = CM_LINK_STATS_MGMT_NOT_MGMT,
+ .mac = MAC_ADDRESS (0xff, 0xff, 0xff, 0xff, 0xff, 0xff)),
+ SCENARIO_EVENT (cp_msg_cm_link_stats_cnf_send_begin,
+ .peer = peer, .req_id = 4,
+ .res_type = CM_LINK_STATS_RESTYPE_FAILURE),
+ SCENARIO_EVENT (cp_msg_cm_link_stats_cnf_send_end),
+ SCENARIO_END
+ };
+ scenario_run (t, entries, &globals);
+ } test_end;
+ mac_store_mfs_remove (cp->mac_store, m_tx);
+ blk_release (m_tx);
+
+ /* Create a tx link (tx=true, broadcast=false, mme=true) */
+ added = false;
+ m_tx = mac_store_mfs_add (cp->mac_store, true, false, true,
+ MAC_LID_NONE, tei_1, &added);
+ dbg_check (added);
+
+ test_case_begin (t, "link_stats_req valid tx link req");
+ test_begin (t, "ok")
+ {
+ test_fail_unless (added == true);
+
+ scenario_entry_t entries[] = {
+ SCENARIO_ACTION (process_cm_link_stats_req, .peer = peer),
+ SCENARIO_EVENT (cp_msg_cm_link_stats_req_receive, .ok = true,
+ .req_type = CM_LINK_STATS_REQTYPE_GET, .req_id = 4,
+ .nid = our_nid, .lid = MAC_LID_NONE,
+ .transmit = CM_LINK_STATS_TLFLAG_TRANSMIT,
+ .mgmt_flag = CM_LINK_STATS_MGMT_MGMT, .mac = mac_1),
+ SCENARIO_EVENT (cp_msg_cm_link_stats_cnf_send_begin,
+ .peer = peer, .req_id = 4,
+ .res_type = CM_LINK_STATS_RESTYPE_SUCCESS),
+ SCENARIO_EVENT (cp_msg_cm_link_stats_cnf_send,
+ .mfs = m_tx, .transmit = CM_LINK_STATS_TLFLAG_TRANSMIT),
+ SCENARIO_EVENT (cp_msg_cm_link_stats_cnf_send_end),
+ SCENARIO_END
+ };
+ scenario_run (t, entries, &globals);
+ } test_end;
+ mac_store_mfs_remove (cp->mac_store, m_tx);
+ blk_release (m_tx);
/* Create a rx link (tx=false, broadcast=false, mme=false) */
added = false;
mfs_t *m_rx = mac_store_mfs_add (cp->mac_store, false, false, false,
lid_rx, tei_1, &added);
+ dbg_check (added);
+ mfs_t *mme_rx = mac_store_mfs_add (cp->mac_store, false, false, true,
+ MAC_LID_NONE, tei_1, &added);
+ dbg_check (added);
+ mfs_t *bcast_rx = mac_store_mfs_add (cp->mac_store, false, true, false,
+ 0, tei_1, &added);
+ dbg_check (added);
test_case_begin (t, "link_stats_req valid rx link req");
- test_begin (t, "ok")
+ test_begin (t, "multiple rx")
{
- test_fail_unless (added == true);
-
scenario_entry_t entries[] = {
+ /* Unicast link. */
SCENARIO_ACTION (process_cm_link_stats_req, .peer = peer),
SCENARIO_EVENT (cp_msg_cm_link_stats_req_receive, .ok = true,
.req_type = CM_LINK_STATS_REQTYPE_GET, .req_id = 5,
@@ -1599,10 +1763,43 @@ misc_link_stats_test_case (test_t t)
SCENARIO_EVENT (cp_msg_cm_link_stats_cnf_send,
.mfs = m_rx, .transmit = CM_LINK_STATS_TLFLAG_RECEIVE),
SCENARIO_EVENT (cp_msg_cm_link_stats_cnf_send_end),
+ /* Unicast MME link. */
+ SCENARIO_ACTION (process_cm_link_stats_req, .peer = peer),
+ SCENARIO_EVENT (cp_msg_cm_link_stats_req_receive, .ok = true,
+ .req_type = CM_LINK_STATS_REQTYPE_GET, .req_id = 5,
+ .nid = our_nid, .lid = 124,
+ .transmit = CM_LINK_STATS_TLFLAG_RECEIVE,
+ .mgmt_flag = CM_LINK_STATS_MGMT_MGMT, .mac = mac_1),
+ SCENARIO_EVENT (cp_msg_cm_link_stats_cnf_send_begin,
+ .peer = peer, .req_id = 5,
+ .res_type = CM_LINK_STATS_RESTYPE_SUCCESS),
+ SCENARIO_EVENT (cp_msg_cm_link_stats_cnf_send,
+ .mfs = mme_rx, .transmit = CM_LINK_STATS_TLFLAG_RECEIVE),
+ SCENARIO_EVENT (cp_msg_cm_link_stats_cnf_send_end),
+ /* Bcast link. */
+ SCENARIO_ACTION (process_cm_link_stats_req, .peer = peer),
+ SCENARIO_EVENT (cp_msg_cm_link_stats_req_receive, .ok = true,
+ .req_type = CM_LINK_STATS_REQTYPE_GET, .req_id = 5,
+ .nid = our_nid, .lid = 0,
+ .transmit = CM_LINK_STATS_TLFLAG_RECEIVE,
+ .mgmt_flag = CM_LINK_STATS_MGMT_NOT_MGMT,
+ .mac = MAC_BROADCAST),
+ SCENARIO_EVENT (cp_msg_cm_link_stats_cnf_send_begin,
+ .peer = peer, .req_id = 5,
+ .res_type = CM_LINK_STATS_RESTYPE_FAILURE),
+ SCENARIO_EVENT (cp_msg_cm_link_stats_cnf_send_end),
SCENARIO_END
};
scenario_run (t, entries, &globals);
} test_end;
+ mac_store_mfs_remove (cp->mac_store, mme_rx);
+ mac_store_mfs_remove (cp->mac_store, bcast_rx);
+ blk_release (mme_rx);
+ blk_release (bcast_rx);
+
+ added = false;
+ m_tx = mac_store_mfs_add (cp->mac_store, true, false, false,
+ lid_tx, tei_1, &added);
/* Force tx stats value with non-zero values */
m_tx->tx.stats.statistics_start_rtc_date = 0xFFFFFFFF;
@@ -1771,17 +1968,24 @@ misc_link_stats_test_case (test_t t)
test_fail_unless (m_rx->rx.stats.num_bursts == 0);
test_fail_unless (m_rx->rx.stats.num_icv_fails == 0);
} test_end;
-
/* Cleanup. */
mac_store_mfs_remove (cp->mac_store, m_rx);
blk_release (m_rx);
mac_store_mfs_remove (cp->mac_store, m_tx);
blk_release (m_tx);
+ cp_sta_mgr_sta_remove (cp, sta_1);
slab_release (sta_1);
- cp_sta_mgr_sta_remove_from_mac (cp, mac_1);
test_sta_action_uninit (&ctx);
}
+void
+misc_link_stats_test_case_all_lids (test_t t)
+{
+ test_case_begin (t, "All possible values");
+ misc_link_stats_test_case_common (t, CM_LINK_STATS_TLFLAG_TRANSMIT);
+ misc_link_stats_test_case_common (t, CM_LINK_STATS_TLFLAG_RECEIVE);
+}
+
void
misc_sta_cap_test_case (test_t t)
@@ -1837,7 +2041,6 @@ misc_sta_cap_test_case (test_t t)
};
scenario_run (t, entries, &globals);
} test_end;
-
/* Cleanup. */
test_sta_action_uninit (&ctx);
}
@@ -1854,6 +2057,7 @@ misc_test_suite (test_t t)
misc_nw_stats_test_case (t);
misc_nw_info_test_case (t);
misc_link_stats_test_case (t);
+ misc_link_stats_test_case_all_lids (t);
misc_sta_cap_test_case (t);
test_case_begin (t, "memory");
test_begin (t, "memory")