Skip to content

Commit

Permalink
validation: cls: add PMR chain test where the chain is created in rev…
Browse files Browse the repository at this point in the history
…erse order

Add a test, which is the same as the PMR chain test, but create the
PMRs in reverse order. In other words, create first the PMR that is
not directly connected to the default CoS, and then create the PMR
whose source CoS is the default CoS.

Also, fix CLS_ENTRIES and remove some unused preprocessor defines.

Signed-off-by: Jere Leppänen <[email protected]>
Reviewed-by: Janne Peltonen <[email protected]>
  • Loading branch information
JereLeppanen authored and MatiasElo committed Oct 24, 2024
1 parent c052c98 commit 31cbc84
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 68 deletions.
14 changes: 8 additions & 6 deletions test/validation/api/classification/classification.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@
#define CLS_PMR_SET_SADDR "10.0.0.6/32"
#define CLS_PMR_SET_PORT 5000

/* Config values for CoS L2 Priority */
#define TEST_L2_QOS 1
#define CLS_L2_QOS_0 7
#define CLS_L2_QOS_MAX 5

#define CLS_ENTRIES (CLS_L2_QOS_0 + CLS_L2_QOS_MAX)
/* Config values for PMR_CHAIN_REV */
#define TEST_PMR_CHAIN_REV 1
#define CLS_PMR_CHAIN_REV_SRC 8
#define CLS_PMR_CHAIN_REV_DST 9
#define CLS_PMR_CHAIN_REV_SADDR "10.0.0.7/32"
#define CLS_PMR_CHAIN_REV_PORT 3001

#define CLS_ENTRIES (CLS_PMR_CHAIN_REV_DST + 1)

/* Test Packet values */
#define DATA_MAGIC 0x01020304
Expand Down
149 changes: 89 additions & 60 deletions test/validation/api/classification/odp_classification_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ static odp_cls_testcase_u tc;
#define NUM_COS_DEFAULT 1
#define NUM_COS_DROP 1
#define NUM_COS_ERROR 1
#define NUM_COS_L2_PRIO CLS_L2_QOS_MAX
#define NUM_COS_PMR 1
#define NUM_COS_COMPOSITE 1
#define PKTV_DEFAULT_SIZE 8
Expand Down Expand Up @@ -214,24 +213,60 @@ int classification_suite_pktv_term(void)
return classification_suite_common_term(true);
}

void configure_cls_pmr_chain(odp_bool_t enable_pktv)
static void configure_cls_pmr_chain_create_saddr_pmr(int src, int dst, const char *saddr)
{
/* PKTIO --> PMR_SRC(SRC IP ADDR) --> PMR_DST (TCP SPORT) */
uint32_t addr;
uint32_t mask;
odp_pmr_param_t pmr_param;

/* Packet matching only the SRC IP ADDR should be delivered
in queue[CLS_PMR_CHAIN_SRC] and a packet matching both SRC IP ADDR and
TCP SPORT should be delivered to queue[CLS_PMR_CHAIN_DST] */
parse_ipv4_string(saddr, &addr, &mask);
addr = odp_cpu_to_be_32(addr);
mask = odp_cpu_to_be_32(mask);

odp_cls_pmr_param_init(&pmr_param);
pmr_param.term = ODP_PMR_SIP_ADDR;
pmr_param.match.value = &addr;
pmr_param.match.mask = &mask;
pmr_param.val_sz = sizeof(addr);
pmr_list[dst] =
odp_cls_pmr_create(&pmr_param, 1, cos_list[src],
cos_list[dst]);
CU_ASSERT_FATAL(pmr_list[dst] != ODP_PMR_INVALID);
}

static void configure_cls_pmr_chain_create_port_pmr(int src, int dst, uint16_t port)
{
uint16_t val;
uint16_t maskport;
odp_pmr_param_t pmr_param;

val = odp_cpu_to_be_16(port);
maskport = odp_cpu_to_be_16(0xffff);
odp_cls_pmr_param_init(&pmr_param);
pmr_param.term = find_first_supported_l3_pmr();
pmr_param.match.value = &val;
pmr_param.match.mask = &maskport;
pmr_param.val_sz = sizeof(val);
pmr_list[dst] =
odp_cls_pmr_create(&pmr_param, 1, cos_list[src],
cos_list[dst]);
CU_ASSERT_FATAL(pmr_list[dst] != ODP_PMR_INVALID);
}

void configure_cls_pmr_chain(odp_bool_t enable_pktv, int src, int dst, const char *saddr,
uint16_t port, odp_bool_t saddr_first)
{
/* PKTIO --> PMR_SRC(SRC IP ADDR) --> PMR_DST (TCP SPORT) */

/* Packet matching only the SRC IP ADDR should be delivered
in queue[src] and a packet matching both SRC IP ADDR and
TCP SPORT should be delivered to queue[dst] */

char cosname[ODP_COS_NAME_LEN];
odp_queue_param_t qparam;
odp_cls_cos_param_t cls_param;
char queuename[ODP_QUEUE_NAME_LEN];
char poolname[ODP_POOL_NAME_LEN];
uint32_t addr;
uint32_t mask;
odp_pmr_param_t pmr_param;
odp_schedule_capability_t schedule_capa;

CU_ASSERT_FATAL(odp_schedule_capability(&schedule_capa) == 0);
Expand All @@ -244,18 +279,18 @@ void configure_cls_pmr_chain(odp_bool_t enable_pktv)
qparam.sched.lock_count = schedule_capa.max_ordered_locks;
sprintf(queuename, "%s", "SrcQueue");

queue_list[CLS_PMR_CHAIN_SRC] = odp_queue_create(queuename, &qparam);
queue_list[src] = odp_queue_create(queuename, &qparam);

CU_ASSERT_FATAL(queue_list[CLS_PMR_CHAIN_SRC] != ODP_QUEUE_INVALID);
CU_ASSERT_FATAL(queue_list[src] != ODP_QUEUE_INVALID);

sprintf(poolname, "%s", "SrcPool");
pool_list[CLS_PMR_CHAIN_SRC] = pool_create(poolname);
CU_ASSERT_FATAL(pool_list[CLS_PMR_CHAIN_SRC] != ODP_POOL_INVALID);
pool_list[src] = pool_create(poolname);
CU_ASSERT_FATAL(pool_list[src] != ODP_POOL_INVALID);

sprintf(cosname, "SrcCos");
odp_cls_cos_param_init(&cls_param);
cls_param.pool = pool_list[CLS_PMR_CHAIN_SRC];
cls_param.queue = queue_list[CLS_PMR_CHAIN_SRC];
cls_param.pool = pool_list[src];
cls_param.queue = queue_list[src];

if (enable_pktv) {
cls_param.vector.enable = true;
Expand All @@ -264,8 +299,8 @@ void configure_cls_pmr_chain(odp_bool_t enable_pktv)
cls_param.vector.max_tmo_ns = pktv_config.max_tmo_ns;
}

cos_list[CLS_PMR_CHAIN_SRC] = odp_cls_cos_create(cosname, &cls_param);
CU_ASSERT_FATAL(cos_list[CLS_PMR_CHAIN_SRC] != ODP_COS_INVALID);
cos_list[src] = odp_cls_cos_create(cosname, &cls_param);
CU_ASSERT_FATAL(cos_list[src] != ODP_COS_INVALID);

odp_queue_param_init(&qparam);
qparam.type = ODP_QUEUE_TYPE_SCHED;
Expand All @@ -274,17 +309,17 @@ void configure_cls_pmr_chain(odp_bool_t enable_pktv)
qparam.sched.group = ODP_SCHED_GROUP_ALL;
sprintf(queuename, "%s", "DstQueue");

queue_list[CLS_PMR_CHAIN_DST] = odp_queue_create(queuename, &qparam);
CU_ASSERT_FATAL(queue_list[CLS_PMR_CHAIN_DST] != ODP_QUEUE_INVALID);
queue_list[dst] = odp_queue_create(queuename, &qparam);
CU_ASSERT_FATAL(queue_list[dst] != ODP_QUEUE_INVALID);

sprintf(poolname, "%s", "DstPool");
pool_list[CLS_PMR_CHAIN_DST] = pool_create(poolname);
CU_ASSERT_FATAL(pool_list[CLS_PMR_CHAIN_DST] != ODP_POOL_INVALID);
pool_list[dst] = pool_create(poolname);
CU_ASSERT_FATAL(pool_list[dst] != ODP_POOL_INVALID);

sprintf(cosname, "DstCos");
odp_cls_cos_param_init(&cls_param);
cls_param.pool = pool_list[CLS_PMR_CHAIN_DST];
cls_param.queue = queue_list[CLS_PMR_CHAIN_DST];
cls_param.pool = pool_list[dst];
cls_param.queue = queue_list[dst];

if (enable_pktv) {
cls_param.vector.enable = true;
Expand All @@ -293,37 +328,19 @@ void configure_cls_pmr_chain(odp_bool_t enable_pktv)
cls_param.vector.max_tmo_ns = pktv_config.max_tmo_ns;
}

cos_list[CLS_PMR_CHAIN_DST] = odp_cls_cos_create(cosname, &cls_param);
CU_ASSERT_FATAL(cos_list[CLS_PMR_CHAIN_DST] != ODP_COS_INVALID);
cos_list[dst] = odp_cls_cos_create(cosname, &cls_param);
CU_ASSERT_FATAL(cos_list[dst] != ODP_COS_INVALID);

parse_ipv4_string(CLS_PMR_CHAIN_SADDR, &addr, &mask);
addr = odp_cpu_to_be_32(addr);
mask = odp_cpu_to_be_32(mask);

odp_cls_pmr_param_init(&pmr_param);
pmr_param.term = ODP_PMR_SIP_ADDR;
pmr_param.match.value = &addr;
pmr_param.match.mask = &mask;
pmr_param.val_sz = sizeof(addr);
pmr_list[CLS_PMR_CHAIN_SRC] =
odp_cls_pmr_create(&pmr_param, 1, cos_list[CLS_DEFAULT],
cos_list[CLS_PMR_CHAIN_SRC]);
CU_ASSERT_FATAL(pmr_list[CLS_PMR_CHAIN_SRC] != ODP_PMR_INVALID);

val = odp_cpu_to_be_16(CLS_PMR_CHAIN_PORT);
maskport = odp_cpu_to_be_16(0xffff);
odp_cls_pmr_param_init(&pmr_param);
pmr_param.term = find_first_supported_l3_pmr();
pmr_param.match.value = &val;
pmr_param.match.mask = &maskport;
pmr_param.val_sz = sizeof(val);
pmr_list[CLS_PMR_CHAIN_DST] =
odp_cls_pmr_create(&pmr_param, 1, cos_list[CLS_PMR_CHAIN_SRC],
cos_list[CLS_PMR_CHAIN_DST]);
CU_ASSERT_FATAL(pmr_list[CLS_PMR_CHAIN_DST] != ODP_PMR_INVALID);
if (saddr_first) {
configure_cls_pmr_chain_create_saddr_pmr(CLS_DEFAULT, src, saddr);
configure_cls_pmr_chain_create_port_pmr(src, dst, port);
} else {
configure_cls_pmr_chain_create_port_pmr(src, dst, port);
configure_cls_pmr_chain_create_saddr_pmr(CLS_DEFAULT, src, saddr);
}
}

void test_cls_pmr_chain(odp_bool_t enable_pktv)
void test_cls_pmr_chain(odp_bool_t enable_pktv, int src, int dst, const char *saddr, uint16_t port)
{
odp_packet_t pkt;
odph_ipv4hdr_t *ip;
Expand All @@ -342,20 +359,20 @@ void test_cls_pmr_chain(odp_bool_t enable_pktv)
CU_ASSERT(seqno != TEST_SEQ_INVALID);

ip = (odph_ipv4hdr_t *)odp_packet_l3_ptr(pkt, NULL);
parse_ipv4_string(CLS_PMR_CHAIN_SADDR, &addr, &mask);
parse_ipv4_string(saddr, &addr, &mask);
ip->src_addr = odp_cpu_to_be_32(addr);
odph_ipv4_csum_update(pkt);

set_first_supported_pmr_port(pkt, CLS_PMR_CHAIN_PORT);
set_first_supported_pmr_port(pkt, port);

enqueue_pktio_interface(pkt, pktio_loop);

pkt = receive_packet(&queue, ODP_TIME_SEC_IN_NS, enable_pktv);
CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID);
CU_ASSERT(queue == queue_list[CLS_PMR_CHAIN_DST]);
CU_ASSERT(queue == queue_list[dst]);
CU_ASSERT(seqno == cls_pkt_get_seq(pkt));
pool = odp_packet_pool(pkt);
CU_ASSERT(pool == pool_list[CLS_PMR_CHAIN_DST]);
CU_ASSERT(pool == pool_list[dst]);
odp_packet_free(pkt);

pkt = create_packet(pkt_info);
Expand All @@ -364,17 +381,17 @@ void test_cls_pmr_chain(odp_bool_t enable_pktv)
CU_ASSERT(seqno != TEST_SEQ_INVALID);

ip = (odph_ipv4hdr_t *)odp_packet_l3_ptr(pkt, NULL);
parse_ipv4_string(CLS_PMR_CHAIN_SADDR, &addr, &mask);
parse_ipv4_string(saddr, &addr, &mask);
ip->src_addr = odp_cpu_to_be_32(addr);
odph_ipv4_csum_update(pkt);

enqueue_pktio_interface(pkt, pktio_loop);
pkt = receive_packet(&queue, ODP_TIME_SEC_IN_NS, enable_pktv);
CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID);
CU_ASSERT(queue == queue_list[CLS_PMR_CHAIN_SRC]);
CU_ASSERT(queue == queue_list[src]);
CU_ASSERT(seqno == cls_pkt_get_seq(pkt));
pool = odp_packet_pool(pkt);
CU_ASSERT(pool == pool_list[CLS_PMR_CHAIN_SRC]);
CU_ASSERT(pool == pool_list[src]);
odp_packet_free(pkt);
}

Expand Down Expand Up @@ -897,10 +914,17 @@ static void cls_pktio_configure_common(odp_bool_t enable_pktv)
num_cos -= NUM_COS_ERROR;
}
if (num_cos >= NUM_COS_PMR_CHAIN && TEST_PMR_CHAIN) {
configure_cls_pmr_chain(enable_pktv);
configure_cls_pmr_chain(enable_pktv, CLS_PMR_CHAIN_SRC, CLS_PMR_CHAIN_DST,
CLS_PMR_CHAIN_SADDR, CLS_PMR_CHAIN_PORT, true);
tc.pmr_chain = 1;
num_cos -= NUM_COS_PMR_CHAIN;
}
if (num_cos >= NUM_COS_PMR_CHAIN && TEST_PMR_CHAIN_REV) {
configure_cls_pmr_chain(enable_pktv, CLS_PMR_CHAIN_REV_SRC, CLS_PMR_CHAIN_REV_DST,
CLS_PMR_CHAIN_REV_SADDR, CLS_PMR_CHAIN_REV_PORT, false);
tc.pmr_chain_rev = 1;
num_cos -= NUM_COS_PMR_CHAIN;
}
if (num_cos >= NUM_COS_PMR && TEST_PMR) {
configure_pmr_cos(enable_pktv);
tc.pmr_cos = 1;
Expand All @@ -912,6 +936,7 @@ static void cls_pktio_configure_common(odp_bool_t enable_pktv)
num_cos -= NUM_COS_COMPOSITE;
}

odp_cls_print_all();
}

static void cls_pktio_configure(void)
Expand All @@ -934,7 +959,11 @@ static void cls_pktio_test_common(odp_bool_t enable_pktv)
if (tc.error_cos && TEST_ERROR)
test_pktio_error_cos(enable_pktv);
if (tc.pmr_chain && TEST_PMR_CHAIN)
test_cls_pmr_chain(enable_pktv);
test_cls_pmr_chain(enable_pktv, CLS_PMR_CHAIN_SRC, CLS_PMR_CHAIN_DST,
CLS_PMR_CHAIN_SADDR, CLS_PMR_CHAIN_PORT);
if (tc.pmr_chain_rev && TEST_PMR_CHAIN_REV)
test_cls_pmr_chain(enable_pktv, CLS_PMR_CHAIN_REV_SRC, CLS_PMR_CHAIN_REV_DST,
CLS_PMR_CHAIN_REV_SADDR, CLS_PMR_CHAIN_REV_PORT);
if (tc.pmr_cos && TEST_PMR)
test_pmr_cos(enable_pktv);
if (tc.pmr_composite_cos && TEST_PMR_SET)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ typedef union odp_cls_testcase {
uint32_t drop_cos:1;
uint32_t error_cos:1;
uint32_t pmr_chain:1;
uint32_t pmr_chain_rev:1;
uint32_t pmr_cos:1;
uint32_t pmr_composite_cos:1;
};
Expand Down Expand Up @@ -77,8 +78,9 @@ void configure_pktio_drop_cos(odp_bool_t enable_pktv, uint32_t max_cos_stats);
void test_pktio_drop_cos(odp_bool_t enable_pktv);
void configure_pktio_error_cos(odp_bool_t enable_pktv);
void test_pktio_error_cos(odp_bool_t enable_pktv);
void configure_cls_pmr_chain(odp_bool_t enable_pktv);
void test_cls_pmr_chain(odp_bool_t enable_pktv);
void configure_cls_pmr_chain(odp_bool_t enable_pktv, int src, int dst, const char *saddr,
uint16_t port, odp_bool_t saddr_first);
void test_cls_pmr_chain(odp_bool_t enable_pktv, int src, int dst, const char *saddr, uint16_t port);
void configure_cos_with_l2_priority(odp_bool_t enable_pktv);
void test_cos_with_l2_priority(odp_bool_t enable_pktv);
void configure_pmr_cos(odp_bool_t enable_pktv);
Expand Down

0 comments on commit 31cbc84

Please sign in to comment.