diff mbox

[API-NEXT/PATCH] validation: classification: adds Test case for ODP_PMR_DIP_ADDR

Message ID 1449138816-7870-1-git-send-email-bala.manoharan@linaro.org
State New
Headers show

Commit Message

Balasubramanian Manoharan Dec. 3, 2015, 10:33 a.m. UTC
fixes: https://bugs.linaro.org/show_bug.cgi?id=1830

Signed-off-by: Balasubramanian Manoharan <bala.manoharan@linaro.org>
---
 .../classification/odp_classification_common.c     |  4 +-
 .../classification/odp_classification_test_pmr.c   | 85 ++++++++++++++++++++++
 2 files changed, 87 insertions(+), 2 deletions(-)
diff mbox

Patch

diff --git a/test/validation/classification/odp_classification_common.c b/test/validation/classification/odp_classification_common.c
index e2999ad..b9611ca 100644
--- a/test/validation/classification/odp_classification_common.c
+++ b/test/validation/classification/odp_classification_common.c
@@ -235,10 +235,10 @@  odp_packet_t create_packet(odp_pool_t pool, bool vlan,
 	/* ipv4 */
 	ip = (odph_ipv4hdr_t *)odp_packet_l3_ptr(pkt, NULL);
 
-	parse_ipv4_string(CLS_DEFAULT_SADDR, &addr, &mask);
+	parse_ipv4_string(CLS_DEFAULT_DADDR, &addr, &mask);
 	ip->dst_addr = odp_cpu_to_be_32(addr);
 
-	parse_ipv4_string(CLS_DEFAULT_DADDR, &addr, &mask);
+	parse_ipv4_string(CLS_DEFAULT_SADDR, &addr, &mask);
 	ip->src_addr = odp_cpu_to_be_32(addr);
 	ip->ver_ihl = ODPH_IPV4 << 4 | ODPH_IPV4HDR_IHL_MIN;
 	if (flag_udp)
diff --git a/test/validation/classification/odp_classification_test_pmr.c b/test/validation/classification/odp_classification_test_pmr.c
index 3f49d4c..03a2e1f 100644
--- a/test/validation/classification/odp_classification_test_pmr.c
+++ b/test/validation/classification/odp_classification_test_pmr.c
@@ -533,11 +533,96 @@  static void classification_test_pmr_term_ipproto(void)
 	odp_pktio_close(pktio);
 }
 
+static void classification_test_pmr_term_daddr(void)
+{
+	odp_packet_t pkt;
+	uint32_t seqno;
+	int retval;
+	odp_pktio_t pktio;
+	odp_queue_t queue;
+	odp_queue_t retqueue;
+	odp_queue_t defqueue;
+	odp_pmr_t pmr;
+	odp_cos_t cos;
+	uint32_t addr;
+	uint32_t mask;
+	char cosname[ODP_QUEUE_NAME_LEN];
+	char queuename[ODP_QUEUE_NAME_LEN];
+	odp_pmr_match_t match;
+	odph_ipv4hdr_t *ip;
+	const char *dst_addr = "10.0.0.99/32";
+
+	pktio = create_pktio(ODP_QUEUE_TYPE_SCHED);
+	defqueue = create_default_inq(pktio, ODP_QUEUE_TYPE_SCHED);
+
+	parse_ipv4_string(dst_addr, &addr, &mask);
+	match.term = ODP_PMR_DIP_ADDR;
+	match.val = &addr;
+	match.mask = &mask;
+	match.val_sz = sizeof(addr);
+
+	pmr = odp_pmr_create(&match);
+	CU_ASSERT(pmr != ODP_PMR_INVAL);
+
+	sprintf(cosname, "daddr");
+	cos = odp_cos_create(cosname);
+	CU_ASSERT_FATAL(cos != ODP_COS_INVALID);
+
+	sprintf(queuename, "%s", "daddr");
+
+	queue = queue_create(queuename, true);
+	CU_ASSERT_FATAL(queue != ODP_QUEUE_INVALID);
+
+	retval = odp_cos_queue_set(cos, queue);
+	CU_ASSERT(retval == 0);
+
+	retval = odp_pktio_pmr_cos(pmr, pktio, cos);
+	CU_ASSERT(retval == 0);
+
+	/* packet with dst ip address matching PMR rule to be
+	received in the CoS queue*/
+	pkt = create_packet(pool_default, false, &seq, false);
+	ip = (odph_ipv4hdr_t *)odp_packet_l3_ptr(pkt, NULL);
+	ip->dst_addr = odp_cpu_to_be_32(addr);
+	ip->chksum = odph_ipv4_csum_update(pkt);
+
+	seqno = cls_pkt_get_seq(pkt);
+	CU_ASSERT(seqno != TEST_SEQ_INVALID);
+
+	enqueue_pktio_interface(pkt, pktio);
+
+	pkt = receive_packet(&retqueue, ODP_TIME_SEC_IN_NS);
+	CU_ASSERT(pkt != ODP_PACKET_INVALID);
+	CU_ASSERT(seqno == cls_pkt_get_seq(pkt));
+	CU_ASSERT(retqueue == queue);
+	odp_packet_free(pkt);
+
+	/* Other packets delivered to default queue */
+	pkt = create_packet(pool_default, false, &seq, false);
+	seqno = cls_pkt_get_seq(pkt);
+	CU_ASSERT(seqno != TEST_SEQ_INVALID);
+
+	enqueue_pktio_interface(pkt, pktio);
+
+	pkt = receive_packet(&retqueue, ODP_TIME_SEC_IN_NS);
+	CU_ASSERT(pkt != ODP_PACKET_INVALID);
+	CU_ASSERT(seqno == cls_pkt_get_seq(pkt));
+	CU_ASSERT(retqueue == defqueue);
+
+	odp_cos_destroy(cos);
+	odp_pmr_destroy(pmr);
+	odp_packet_free(pkt);
+	destroy_inq(pktio);
+	odp_queue_destroy(queue);
+	odp_pktio_close(pktio);
+}
+
 odp_testinfo_t classification_suite_pmr[] = {
 	ODP_TEST_INFO(classification_test_pmr_term_tcp_dport),
 	ODP_TEST_INFO(classification_test_pmr_term_tcp_sport),
 	ODP_TEST_INFO(classification_test_pmr_term_udp_dport),
 	ODP_TEST_INFO(classification_test_pmr_term_udp_sport),
 	ODP_TEST_INFO(classification_test_pmr_term_ipproto),
+	ODP_TEST_INFO(classification_test_pmr_term_daddr),
 	ODP_TEST_INFO_NULL,
 };