From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 10F18A0534; Wed, 12 Feb 2020 14:48:11 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 6C1A41BC25; Wed, 12 Feb 2020 14:47:57 +0100 (CET) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by dpdk.org (Postfix) with ESMTP id C0F90137D for ; Wed, 12 Feb 2020 14:47:54 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Feb 2020 05:47:54 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,433,1574150400"; d="scan'208";a="251914327" Received: from sivswdev08.ir.intel.com ([10.237.217.47]) by orsmga002.jf.intel.com with ESMTP; 12 Feb 2020 05:47:52 -0800 From: Konstantin Ananyev To: dev@dpdk.org Cc: Ido@cgstowernetworks.com, Konstantin Ananyev Date: Wed, 12 Feb 2020 13:47:45 +0000 Message-Id: <20200212134745.5723-3-konstantin.ananyev@intel.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20200212134745.5723-1-konstantin.ananyev@intel.com> References: <20200212134745.5723-1-konstantin.ananyev@intel.com> Subject: [dpdk-dev] [PATCH 2/2] test/acl: add 32-bit range test-case X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Add new test-case to improve test coverage for 32-bit range fields. Suggested-by: Ido Goshen Signed-off-by: Konstantin Ananyev --- app/test/test_acl.c | 164 +++++++++++++++++++++++++++++++++++++------- app/test/test_acl.h | 43 ++++++++++++ 2 files changed, 184 insertions(+), 23 deletions(-) diff --git a/app/test/test_acl.c b/app/test/test_acl.c index 9cd9e37db..501de35da 100644 --- a/app/test/test_acl.c +++ b/app/test/test_acl.c @@ -269,25 +269,25 @@ rte_acl_ipv4vlan_build(struct rte_acl_ctx *ctx, * Test scalar and SSE ACL lookup. */ static int -test_classify_run(struct rte_acl_ctx *acx) +test_classify_run(struct rte_acl_ctx *acx, struct ipv4_7tuple test_data[], + size_t dim) { int ret, i; uint32_t result, count; - uint32_t results[RTE_DIM(acl_test_data) * RTE_ACL_MAX_CATEGORIES]; - const uint8_t *data[RTE_DIM(acl_test_data)]; - + uint32_t results[dim * RTE_ACL_MAX_CATEGORIES]; + const uint8_t *data[dim]; /* swap all bytes in the data to network order */ - bswap_test_data(acl_test_data, RTE_DIM(acl_test_data), 1); + bswap_test_data(test_data, dim, 1); /* store pointers to test data */ - for (i = 0; i < (int) RTE_DIM(acl_test_data); i++) - data[i] = (uint8_t *)&acl_test_data[i]; + for (i = 0; i < (int) dim; i++) + data[i] = (uint8_t *)&test_data[i]; /** * these will run quite a few times, it's necessary to test code paths * from num=0 to num>8 */ - for (count = 0; count <= RTE_DIM(acl_test_data); count++) { + for (count = 0; count <= dim; count++) { ret = rte_acl_classify(acx, data, results, count, RTE_ACL_MAX_CATEGORIES); if (ret != 0) { @@ -299,10 +299,10 @@ test_classify_run(struct rte_acl_ctx *acx) for (i = 0; i < (int) count; i++) { result = results[i * RTE_ACL_MAX_CATEGORIES + ACL_ALLOW]; - if (result != acl_test_data[i].allow) { + if (result != test_data[i].allow) { printf("Line %i: Error in allow results at %i " "(expected %"PRIu32" got %"PRIu32")!\n", - __LINE__, i, acl_test_data[i].allow, + __LINE__, i, test_data[i].allow, result); ret = -EINVAL; goto err; @@ -312,10 +312,10 @@ test_classify_run(struct rte_acl_ctx *acx) /* check if we deny everything we should deny */ for (i = 0; i < (int) count; i++) { result = results[i * RTE_ACL_MAX_CATEGORIES + ACL_DENY]; - if (result != acl_test_data[i].deny) { + if (result != test_data[i].deny) { printf("Line %i: Error in deny results at %i " "(expected %"PRIu32" got %"PRIu32")!\n", - __LINE__, i, acl_test_data[i].deny, + __LINE__, i, test_data[i].deny, result); ret = -EINVAL; goto err; @@ -325,7 +325,7 @@ test_classify_run(struct rte_acl_ctx *acx) /* make a quick check for scalar */ ret = rte_acl_classify_alg(acx, data, results, - RTE_DIM(acl_test_data), RTE_ACL_MAX_CATEGORIES, + dim, RTE_ACL_MAX_CATEGORIES, RTE_ACL_CLASSIFY_SCALAR); if (ret != 0) { printf("Line %i: scalar classify failed!\n", __LINE__); @@ -333,12 +333,12 @@ test_classify_run(struct rte_acl_ctx *acx) } /* check if we allow everything we should allow */ - for (i = 0; i < (int) RTE_DIM(acl_test_data); i++) { + for (i = 0; i < (int) dim; i++) { result = results[i * RTE_ACL_MAX_CATEGORIES + ACL_ALLOW]; - if (result != acl_test_data[i].allow) { + if (result != test_data[i].allow) { printf("Line %i: Error in allow results at %i " "(expected %"PRIu32" got %"PRIu32")!\n", - __LINE__, i, acl_test_data[i].allow, + __LINE__, i, test_data[i].allow, result); ret = -EINVAL; goto err; @@ -346,12 +346,12 @@ test_classify_run(struct rte_acl_ctx *acx) } /* check if we deny everything we should deny */ - for (i = 0; i < (int) RTE_DIM(acl_test_data); i++) { + for (i = 0; i < (int) dim; i++) { result = results[i * RTE_ACL_MAX_CATEGORIES + ACL_DENY]; - if (result != acl_test_data[i].deny) { + if (result != test_data[i].deny) { printf("Line %i: Error in deny results at %i " "(expected %"PRIu32" got %"PRIu32")!\n", - __LINE__, i, acl_test_data[i].deny, + __LINE__, i, test_data[i].deny, result); ret = -EINVAL; goto err; @@ -362,7 +362,7 @@ test_classify_run(struct rte_acl_ctx *acx) err: /* swap data back to cpu order so that next time tests don't fail */ - bswap_test_data(acl_test_data, RTE_DIM(acl_test_data), 0); + bswap_test_data(test_data, dim, 0); return ret; } @@ -425,7 +425,8 @@ test_classify(void) break; } - ret = test_classify_run(acx); + ret = test_classify_run(acx, acl_test_data, + RTE_DIM(acl_test_data)); if (ret != 0) { printf("Line %i, iter: %d: %s failed!\n", __LINE__, i, __func__); @@ -434,7 +435,8 @@ test_classify(void) /* reset rules and make sure that classify still works ok. */ rte_acl_reset_rules(acx); - ret = test_classify_run(acx); + ret = test_classify_run(acx, acl_test_data, + RTE_DIM(acl_test_data)); if (ret != 0) { printf("Line %i, iter: %d: %s failed!\n", __LINE__, i, __func__); @@ -925,7 +927,8 @@ test_convert_rules(const char *desc, break; } - rc = test_classify_run(acx); + rc = test_classify_run(acx, acl_test_data, + RTE_DIM(acl_test_data)); if (rc != 0) printf("%s failed at line %i, max_size=%zu\n", __func__, __LINE__, mem_sizes[i]); @@ -1597,6 +1600,119 @@ test_misc(void) return 0; } +static uint32_t +get_u32_range_max(void) +{ + uint32_t i, max; + + max = 0; + for (i = 0; i != RTE_DIM(acl_u32_range_test_rules); i++) + max = RTE_MAX(max, acl_u32_range_test_rules[i].src_mask_len); + return max; +} + +static uint32_t +get_u32_range_min(void) +{ + uint32_t i, min; + + min = UINT32_MAX; + for (i = 0; i != RTE_DIM(acl_u32_range_test_rules); i++) + min = RTE_MIN(min, acl_u32_range_test_rules[i].src_addr); + return min; +} + +static const struct rte_acl_ipv4vlan_rule * +find_u32_range_rule(uint32_t val) +{ + uint32_t i; + + for (i = 0; i != RTE_DIM(acl_u32_range_test_rules); i++) { + if (val >= acl_u32_range_test_rules[i].src_addr && + val <= acl_u32_range_test_rules[i].src_mask_len) + return acl_u32_range_test_rules + i; + } + return NULL; +} + +static void +fill_u32_range_data(struct ipv4_7tuple tdata[], uint32_t start, uint32_t num) +{ + uint32_t i; + const struct rte_acl_ipv4vlan_rule *r; + + for (i = 0; i != num; i++) { + tdata[i].ip_src = start + i; + r = find_u32_range_rule(start + i); + if (r != NULL) + tdata[i].allow = r->data.userdata; + } +} + +static int +test_u32_range(void) +{ + int32_t rc; + uint32_t i, k, max, min; + struct rte_acl_ctx *acx; + struct acl_ipv4vlan_rule r; + struct ipv4_7tuple test_data[64]; + + acx = rte_acl_create(&acl_param); + if (acx == NULL) { + printf("%s#%i: Error creating ACL context!\n", + __func__, __LINE__); + return -1; + } + + for (i = 0; i != RTE_DIM(acl_u32_range_test_rules); i++) { + convert_rule(&acl_u32_range_test_rules[i], &r); + rc = rte_acl_add_rules(acx, (struct rte_acl_rule *)&r, 1); + if (rc != 0) { + printf("%s#%i: Adding rule to ACL context " + "failed with error code: %d\n", + __func__, __LINE__, rc); + rte_acl_free(acx); + return rc; + } + } + + rc = build_convert_rules(acx, convert_config_2, 0); + if (rc != 0) { + printf("%s#%i Error @ build_convert_rules!\n", + __func__, __LINE__); + rte_acl_free(acx); + return rc; + } + + max = get_u32_range_max(); + min = get_u32_range_min(); + + max = RTE_MAX(max, max + 1); + min = RTE_MIN(min, min - 1); + + printf("%s#%d starting range test from %u to %u\n", + __func__, __LINE__, min, max); + + for (i = min; i <= max; i += k) { + + k = RTE_MIN(max - i + 1, RTE_DIM(test_data)); + + memset(test_data, 0, sizeof(test_data)); + fill_u32_range_data(test_data, i, k); + + rc = test_classify_run(acx, test_data, k); + if (rc != 0) { + printf("%s#%d failed at [%u, %u) interval\n", + __func__, __LINE__, i, i + k); + break; + } + } + + rte_acl_free(acx); + return rc; +} + static int test_acl(void) { @@ -1616,6 +1732,8 @@ test_acl(void) return -1; if (test_convert() < 0) return -1; + if (test_u32_range() < 0) + return -1; return 0; } diff --git a/app/test/test_acl.h b/app/test/test_acl.h index 4f6e659c7..4cdead0b7 100644 --- a/app/test/test_acl.h +++ b/app/test/test_acl.h @@ -666,4 +666,47 @@ struct ipv4_7tuple acl_test_data[] = { }, /* should not match */ }; +/* + * ruleset for ACL 32 bit range (by src addr) unit test + * keep them ordered by priority in descending order. + */ +struct rte_acl_ipv4vlan_rule acl_u32_range_test_rules[] = { + { + .data = { + .userdata = 500, + .category_mask = ACL_ALLOW_MASK, + .priority = 500 + }, + .src_addr = RTE_IPV4(0, 0, 0, 1), + .src_mask_len = RTE_IPV4(0, 0, 2, 58), + }, + { + .data = { + .userdata = 400, + .category_mask = ACL_ALLOW_MASK, + .priority = 400 + }, + .src_addr = RTE_IPV4(0, 4, 3, 2), + .src_mask_len = RTE_IPV4(0, 4, 7, 255), + }, + { + .data = { + .userdata = 300, + .category_mask = ACL_ALLOW_MASK, + .priority = 300 + }, + .src_addr = RTE_IPV4(0, 1, 12, 14), + .src_mask_len = RTE_IPV4(0, 3, 11, 13), + }, + { + .data = { + .userdata = 200, + .category_mask = ACL_ALLOW_MASK, + .priority = 200 + }, + .src_addr = RTE_IPV4(0, 0, 1, 40), + .src_mask_len = RTE_IPV4(0, 4, 5, 6), + }, +}; + #endif /* TEST_ACL_H_ */ -- 2.17.1