Signed-off-by: Nicolas Morey-Chaisemartin <nmo...@kalray.eu> --- example/classifier/odp_classifier.c | 12 +++++--- include/odp/api/classification.h | 31 +++++++------------ platform/linux-generic/odp_classification.c | 35 ++++++++++------------ .../classification/odp_classification_basic.c | 18 +++++++++-- .../classification/odp_classification_tests.c | 28 ++++++++++++----- 5 files changed, 71 insertions(+), 53 deletions(-)
diff --git a/example/classifier/odp_classifier.c b/example/classifier/odp_classifier.c index 7790313..689313d 100644 --- a/example/classifier/odp_classifier.c +++ b/example/classifier/odp_classifier.c @@ -361,10 +361,14 @@ static void configure_cos_queue(odp_pktio_t pktio, appl_args_t *args) sprintf(cos_name, "CoS%s", stats->queue_name); stats->cos = odp_cos_create(cos_name); - stats->pmr = odp_pmr_create(stats->rule.term, - &stats->rule.val, - &stats->rule.mask, - stats->val_sz); + const odp_pmr_match_t match = { + .term = stats->rule.term, + .val = &stats->rule.val, + .mask = &stats->rule.mask, + .val_sz = stats->val_sz + }; + + stats->pmr = odp_pmr_create(&match); qparam.sched.prio = i % odp_schedule_num_prio(); qparam.sched.sync = ODP_SCHED_SYNC_NONE; qparam.sched.group = ODP_SCHED_GROUP_ALL; diff --git a/include/odp/api/classification.h b/include/odp/api/classification.h index e6f14cc..a62528c 100644 --- a/include/odp/api/classification.h +++ b/include/odp/api/classification.h @@ -243,38 +243,24 @@ typedef enum odp_pmr_term { } odp_pmr_term_e; /** - * Following structure is used to define composite packet matching rules - * in the form of an array of individual match rules. - * The underlying platform may not support all or any specific combination - * of value match rules, and the application should take care - * of inspecting the return value when installing such rules, and perform - * appropriate fallback action. + * Following structure is used to define a packet matching rule */ typedef struct odp_pmr_match_t { odp_pmr_term_e term; /**< PMR term value to be matched */ const void *val; /**< Value to be matched */ const void *mask; /**< Masked set of bits to be matched */ - unsigned int val_sz; /**< Size of the term value */ + uint32_t val_sz; /**< Size of the term value */ } odp_pmr_match_t; /** * Create a packet match rule with mask and value * - * @param[in] term One of the enumerated values supported - * @param[in] val Value to match against the packet header - * in native byte order. - * @param[in] mask Mask to indicate which bits of the header - * should be matched ('1') and - * which should be ignored ('0') - * @param[in] val_sz Size of the val and mask arguments, - * that must match the value size requirement of the - * specific term. + * @param[in] match packet matching rule definition * * @return Handle of the matching rule * @retval ODP_PMR_INVAL on failure */ -odp_pmr_t odp_pmr_create(odp_pmr_term_e term, const void *val, - const void *mask, uint32_t val_sz); +odp_pmr_t odp_pmr_create(const odp_pmr_match_t *match); /** * Invalidate a packet match rule and vacate its resources @@ -332,7 +318,12 @@ unsigned odp_pmr_terms_avail(void); */ /** - * Create a composite packet match rule + * Create a composite packet match rule in the form of an array of individual + * match rules. + * The underlying platform may not support all or any specific combination + * of value match rules, and the application should take care + * of inspecting the return value when installing such rules, and perform + * appropriate fallback action. * * @param[in] num_terms Number of terms in the match rule. * @param[in] terms Array of num_terms entries, one entry per @@ -344,7 +335,7 @@ unsigned odp_pmr_terms_avail(void); * underlying platform classification engine * @retval <0 on failure */ -int odp_pmr_match_set_create(int num_terms, odp_pmr_match_t *terms, +int odp_pmr_match_set_create(int num_terms, const odp_pmr_match_t *terms, odp_pmr_set_t *pmr_set_id); /** diff --git a/platform/linux-generic/odp_classification.c b/platform/linux-generic/odp_classification.c index dd12a00..45f62ba 100644 --- a/platform/linux-generic/odp_classification.c +++ b/platform/linux-generic/odp_classification.c @@ -444,12 +444,22 @@ int odp_cos_with_l3_qos(odp_pktio_t pktio_in, return 0; } -odp_pmr_t odp_pmr_create(odp_pmr_term_e term, const void *val, - const void *mask, uint32_t val_sz) +static void odp_pmr_create_term(pmr_term_value_t *value, + const odp_pmr_match_t *match) +{ + value->term = match->term; + value->val = 0; + value->mask = 0; + memcpy(&value->val, match->val, match->val_sz); + memcpy(&value->mask, match->mask, match->val_sz); + value->val &= value->mask; +} + +odp_pmr_t odp_pmr_create(const odp_pmr_match_t *match) { pmr_t *pmr; odp_pmr_t id; - if (val_sz > ODP_PMR_TERM_BYTES_MAX) { + if (match->val_sz > ODP_PMR_TERM_BYTES_MAX) { ODP_ERR("val_sz greater than max supported limit"); return ODP_PMR_INVAL; } @@ -460,12 +470,7 @@ odp_pmr_t odp_pmr_create(odp_pmr_term_e term, const void *val, return ODP_PMR_INVAL; pmr->s.num_pmr = 1; - pmr->s.pmr_term_value[0].term = term; - pmr->s.pmr_term_value[0].val = 0; - pmr->s.pmr_term_value[0].mask = 0; - memcpy(&pmr->s.pmr_term_value[0].val, val, val_sz); - memcpy(&pmr->s.pmr_term_value[0].mask, mask, val_sz); - pmr->s.pmr_term_value[0].val &= pmr->s.pmr_term_value[0].mask; + odp_pmr_create_term(&pmr->s.pmr_term_value[0], match); UNLOCK(&pmr->s.lock); return id; } @@ -567,7 +572,7 @@ unsigned odp_pmr_terms_avail(void) return count; } -int odp_pmr_match_set_create(int num_terms, odp_pmr_match_t *terms, +int odp_pmr_match_set_create(int num_terms, const odp_pmr_match_t *terms, odp_pmr_set_t *pmr_set_id) { pmr_t *pmr; @@ -593,15 +598,7 @@ int odp_pmr_match_set_create(int num_terms, odp_pmr_match_t *terms, val_sz = terms[i].val_sz; if (val_sz > ODP_PMR_TERM_BYTES_MAX) continue; - pmr->s.pmr_term_value[i].term = terms[i].term; - pmr->s.pmr_term_value[i].val = 0; - pmr->s.pmr_term_value[i].mask = 0; - memcpy(&pmr->s.pmr_term_value[i].val, - terms[i].val, val_sz); - memcpy(&pmr->s.pmr_term_value[i].mask, - terms[i].mask, val_sz); - pmr->s.pmr_term_value[i].val &= pmr->s - .pmr_term_value[i].mask; + odp_pmr_create_term(&pmr->s.pmr_term_value[i], &terms[i]); count++; } *pmr_set_id = id; diff --git a/test/validation/classification/odp_classification_basic.c b/test/validation/classification/odp_classification_basic.c index c063b88..f8b804d 100644 --- a/test/validation/classification/odp_classification_basic.c +++ b/test/validation/classification/odp_classification_basic.c @@ -40,9 +40,16 @@ void classification_test_create_pmr_match(void) odp_pmr_t pmr; uint16_t val; uint16_t mask; + odp_pmr_match_t match; + val = 1024; mask = 0xffff; - pmr = odp_pmr_create(ODP_PMR_TCP_SPORT, &val, &mask, sizeof(val)); + match.term = ODP_PMR_TCP_SPORT; + match.val = &val; + match.mask = &mask; + match.val_sz = sizeof(val); + + pmr = odp_pmr_create(&match); CU_ASSERT(pmr != ODP_PMR_INVAL); CU_ASSERT(odp_pmr_to_u64(pmr) != odp_pmr_to_u64(ODP_PMR_INVAL)); odp_pmr_destroy(pmr); @@ -54,9 +61,16 @@ void classification_test_destroy_pmr(void) uint16_t val; uint16_t mask; int retval; + odp_pmr_match_t match; + val = 1024; mask = 0xffff; - pmr = odp_pmr_create(ODP_PMR_TCP_SPORT, &val, &mask, sizeof(val)); + match.term = ODP_PMR_TCP_SPORT; + match.val = &val; + match.mask = &mask; + match.val_sz = sizeof(val); + + pmr = odp_pmr_create(&match); retval = odp_pmr_destroy(pmr); CU_ASSERT(retval == 0); retval = odp_pmr_destroy(ODP_PMR_INVAL); diff --git a/test/validation/classification/odp_classification_tests.c b/test/validation/classification/odp_classification_tests.c index 0fb624d..8840e53 100644 --- a/test/validation/classification/odp_classification_tests.c +++ b/test/validation/classification/odp_classification_tests.c @@ -384,6 +384,7 @@ void configure_cls_pmr_chain(void) char queuename[ODP_QUEUE_NAME_LEN]; uint32_t addr; uint32_t mask; + odp_pmr_match_t match; sprintf(cosname, "SrcCos"); cos_list[CLS_PMR_CHAIN_SRC] = odp_cos_create(cosname); @@ -424,14 +425,20 @@ void configure_cls_pmr_chain(void) CU_ASSERT(retval == 0); parse_ipv4_string(CLS_PMR_CHAIN_SADDR, &addr, &mask); - pmr_list[CLS_PMR_CHAIN_SRC] = odp_pmr_create(ODP_PMR_SIP_ADDR, &addr, - &mask, sizeof(addr)); + match.term = ODP_PMR_SIP_ADDR; + match.val = &addr; + match.mask = &mask; + match.val_sz = sizeof(addr); + pmr_list[CLS_PMR_CHAIN_SRC] = odp_pmr_create(&match); CU_ASSERT_FATAL(pmr_list[CLS_PMR_CHAIN_SRC] != ODP_PMR_INVAL); val = CLS_PMR_CHAIN_SPORT; maskport = 0xffff; - pmr_list[CLS_PMR_CHAIN_DST] = odp_pmr_create(ODP_PMR_UDP_SPORT, &val, - &maskport, sizeof(val)); + match.term = ODP_PMR_UDP_SPORT; + match.val = &val; + match.mask = &maskport; + match.val_sz = sizeof(val); + pmr_list[CLS_PMR_CHAIN_DST] = odp_pmr_create(&match); CU_ASSERT_FATAL(pmr_list[CLS_PMR_CHAIN_DST] != ODP_PMR_INVAL); retval = odp_pktio_pmr_cos(pmr_list[CLS_PMR_CHAIN_SRC], pktio_loop, @@ -681,14 +688,19 @@ void configure_pmr_cos(void) uint16_t val; uint16_t mask; int retval; - val = CLS_PMR_SPORT; - mask = 0xffff; + odp_pmr_match_t match; odp_queue_param_t qparam; char cosname[ODP_COS_NAME_LEN]; char queuename[ODP_QUEUE_NAME_LEN]; - pmr_list[CLS_PMR] = odp_pmr_create(ODP_PMR_UDP_SPORT, &val, - &mask, sizeof(val)); + val = CLS_PMR_SPORT; + mask = 0xffff; + match.term = ODP_PMR_UDP_SPORT; + match.val = &val; + match.mask = &mask; + match.val_sz = sizeof(val); + + pmr_list[CLS_PMR] = odp_pmr_create(&match); CU_ASSERT(pmr_list[CLS_PMR] != ODP_PMR_INVAL); sprintf(cosname, "PMR_CoS"); -- 2.6.1.3.g8d02103 _______________________________________________ lng-odp mailing list lng-odp@lists.linaro.org https://lists.linaro.org/mailman/listinfo/lng-odp