Skip to content

Commit c1241ac

Browse files
committed
validation: tm: add node statistics test case
Add node stats test case similar to queue stats testcase. Signed-off-by: Nithin Dabilpuram <[email protected]>
1 parent 5f6a9fa commit c1241ac

File tree

1 file changed

+109
-0
lines changed

1 file changed

+109
-0
lines changed

test/validation/api/traffic_mngr/traffic_mngr.c

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4717,6 +4717,113 @@ static void traffic_mngr_test_queue_stats(void)
47174717
CU_ASSERT(odp_tm_is_idle(odp_tm_systems[0]));
47184718
}
47194719

4720+
static int traffic_mngr_check_node_stats(void)
4721+
{
4722+
int i;
4723+
4724+
for (i = 0; i < NUM_LEVELS; i++) {
4725+
/* Report test case as active if even one level supports
4726+
* stats.
4727+
*/
4728+
if (tm_capabilities.per_level[i].node_stats.all_counters)
4729+
return ODP_TEST_ACTIVE;
4730+
}
4731+
4732+
return ODP_TEST_INACTIVE;
4733+
}
4734+
4735+
static void traffic_mngr_test_node_stats(void)
4736+
{
4737+
odp_tm_node_stats_t stats_start[NUM_LEVELS];
4738+
odp_tm_node_stats_capability_t stats_capa;
4739+
odp_tm_node_t nodes[NUM_LEVELS];
4740+
odp_tm_node_stats_t stats_stop;
4741+
odp_tm_queue_info_t q_info;
4742+
odp_tm_node_info_t n_info;
4743+
odp_tm_queue_t tm_queue;
4744+
odp_tm_capabilities_t capa;
4745+
pkt_info_t pkt_info;
4746+
uint32_t pkts_sent;
4747+
uint32_t num_pkts = ODPH_MIN(50u, MAX_PKTS);
4748+
uint32_t pkt_len = 256;
4749+
int i;
4750+
4751+
CU_ASSERT_FATAL(odp_tm_capability(odp_tm_systems[0], &capa) == 0);
4752+
4753+
/* Reuse threshold test node */
4754+
tm_queue = find_tm_queue(0, "node_1_2_1", 0);
4755+
CU_ASSERT_FATAL(tm_queue != ODP_TM_INVALID);
4756+
4757+
/* Find parent nodes */
4758+
CU_ASSERT_FATAL(odp_tm_queue_info(tm_queue, &q_info) == 0);
4759+
CU_ASSERT_FATAL(q_info.next_tm_node != ODP_TM_INVALID);
4760+
nodes[NUM_LEVELS - 1] = q_info.next_tm_node;
4761+
4762+
for (i = NUM_LEVELS - 2; i >= 0; i--) {
4763+
CU_ASSERT_FATAL(odp_tm_node_info(nodes[i + 1], &n_info) == 0);
4764+
CU_ASSERT_FATAL(n_info.level == (i + 1));
4765+
CU_ASSERT_FATAL(n_info.next_tm_node != ODP_TM_INVALID);
4766+
4767+
/* Save next TM node */
4768+
nodes[i] = n_info.next_tm_node;
4769+
}
4770+
4771+
init_xmt_pkts(&pkt_info);
4772+
pkt_info.drop_eligible = false;
4773+
pkt_info.pkt_class = 1;
4774+
CU_ASSERT_FATAL(make_pkts(num_pkts, pkt_len, &pkt_info) == 0);
4775+
4776+
/* Collect available node stats */
4777+
for (i = 0; i < NUM_LEVELS; i++) {
4778+
if (capa.per_level[i].node_stats.all_counters == 0)
4779+
continue;
4780+
4781+
CU_ASSERT(odp_tm_node_stats(nodes[i], &stats_start[i]) == 0);
4782+
}
4783+
4784+
pkts_sent = send_pkts(tm_queue, num_pkts);
4785+
4786+
num_rcv_pkts = receive_pkts(odp_tm_systems[0], rcv_pktin, pkts_sent,
4787+
1 * GBPS);
4788+
4789+
/* Collect available node stats and validate */
4790+
for (i = 0; i < NUM_LEVELS; i++) {
4791+
stats_capa = capa.per_level[i].node_stats;
4792+
4793+
if (stats_capa.all_counters == 0)
4794+
continue;
4795+
4796+
CU_ASSERT(odp_tm_node_stats(nodes[i], &stats_stop) == 0);
4797+
4798+
if (stats_capa.counter.packets)
4799+
CU_ASSERT(stats_stop.packets >= stats_start[i].packets + num_rcv_pkts);
4800+
if (stats_capa.counter.octets)
4801+
CU_ASSERT(stats_stop.octets >= stats_start[i].octets +
4802+
(num_rcv_pkts * pkt_len));
4803+
CU_ASSERT((stats_stop.discards - stats_start[i].discards) == 0);
4804+
CU_ASSERT((stats_stop.discard_octets - stats_start[i].discard_octets) == 0);
4805+
4806+
printf("\nLevel %d TM node statistics\n-------------------\n", i);
4807+
printf(" discards: %" PRIu64 "\n", stats_stop.discards);
4808+
printf(" discard octets: %" PRIu64 "\n", stats_stop.discard_octets);
4809+
printf(" octets: %" PRIu64 "\n", stats_stop.octets);
4810+
printf(" packets: %" PRIu64 "\n", stats_stop.packets);
4811+
4812+
/* Check that all unsupported counters are still zero */
4813+
if (!stats_capa.counter.discards)
4814+
CU_ASSERT(stats_stop.discards == 0);
4815+
if (!stats_capa.counter.discard_octets)
4816+
CU_ASSERT(stats_stop.discard_octets == 0);
4817+
if (!stats_capa.counter.octets)
4818+
CU_ASSERT(stats_stop.octets == 0);
4819+
if (!stats_capa.counter.packets)
4820+
CU_ASSERT(stats_stop.packets == 0);
4821+
}
4822+
4823+
flush_leftover_pkts(odp_tm_systems[0], rcv_pktin);
4824+
CU_ASSERT(odp_tm_is_idle(odp_tm_systems[0]));
4825+
}
4826+
47204827
static int traffic_mngr_check_wred(void)
47214828
{
47224829
/* Check if wred is part of created odp_tm_t capabilities */
@@ -5088,6 +5195,8 @@ odp_testinfo_t traffic_mngr_suite[] = {
50885195
traffic_mngr_check_query),
50895196
ODP_TEST_INFO_CONDITIONAL(traffic_mngr_test_queue_stats,
50905197
traffic_mngr_check_queue_stats),
5198+
ODP_TEST_INFO_CONDITIONAL(traffic_mngr_test_node_stats,
5199+
traffic_mngr_check_node_stats),
50915200
ODP_TEST_INFO_CONDITIONAL(traffic_mngr_test_vlan_marking,
50925201
traffic_mngr_check_vlan_marking),
50935202
ODP_TEST_INFO_CONDITIONAL(traffic_mngr_test_ecn_marking,

0 commit comments

Comments
 (0)