xref: /dpdk/lib/table/rte_table_lpm.c (revision 85e327081f0649c0965e53f675ac3b55eb8be6db)
199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
299a2dd95SBruce Richardson  * Copyright(c) 2010-2014 Intel Corporation
399a2dd95SBruce Richardson  */
499a2dd95SBruce Richardson 
5e9fd1ebfSTyler Retzlaff #include <stdalign.h>
699a2dd95SBruce Richardson #include <stdio.h>
7e9fd1ebfSTyler Retzlaff #include <string.h>
899a2dd95SBruce Richardson 
999a2dd95SBruce Richardson #include <rte_common.h>
1099a2dd95SBruce Richardson #include <rte_malloc.h>
1199a2dd95SBruce Richardson #include <rte_byteorder.h>
1299a2dd95SBruce Richardson #include <rte_log.h>
1399a2dd95SBruce Richardson #include <rte_lpm.h>
1499a2dd95SBruce Richardson 
1599a2dd95SBruce Richardson #include "rte_table_lpm.h"
1699a2dd95SBruce Richardson 
17ae67895bSDavid Marchand #include "table_log.h"
18ae67895bSDavid Marchand 
1999a2dd95SBruce Richardson #ifndef RTE_TABLE_LPM_MAX_NEXT_HOPS
2099a2dd95SBruce Richardson #define RTE_TABLE_LPM_MAX_NEXT_HOPS                        65536
2199a2dd95SBruce Richardson #endif
2299a2dd95SBruce Richardson 
2399a2dd95SBruce Richardson #ifdef RTE_TABLE_STATS_COLLECT
2499a2dd95SBruce Richardson 
2599a2dd95SBruce Richardson #define RTE_TABLE_LPM_STATS_PKTS_IN_ADD(table, val) \
2699a2dd95SBruce Richardson 	table->stats.n_pkts_in += val
2799a2dd95SBruce Richardson #define RTE_TABLE_LPM_STATS_PKTS_LOOKUP_MISS(table, val) \
2899a2dd95SBruce Richardson 	table->stats.n_pkts_lookup_miss += val
2999a2dd95SBruce Richardson 
3099a2dd95SBruce Richardson #else
3199a2dd95SBruce Richardson 
3299a2dd95SBruce Richardson #define RTE_TABLE_LPM_STATS_PKTS_IN_ADD(table, val)
3399a2dd95SBruce Richardson #define RTE_TABLE_LPM_STATS_PKTS_LOOKUP_MISS(table, val)
3499a2dd95SBruce Richardson 
3599a2dd95SBruce Richardson #endif
3699a2dd95SBruce Richardson 
3799a2dd95SBruce Richardson struct rte_table_lpm {
3899a2dd95SBruce Richardson 	struct rte_table_stats stats;
3999a2dd95SBruce Richardson 
4099a2dd95SBruce Richardson 	/* Input parameters */
4199a2dd95SBruce Richardson 	uint32_t entry_size;
4299a2dd95SBruce Richardson 	uint32_t entry_unique_size;
4399a2dd95SBruce Richardson 	uint32_t n_rules;
4499a2dd95SBruce Richardson 	uint32_t offset;
4599a2dd95SBruce Richardson 
4699a2dd95SBruce Richardson 	/* Handle to low-level LPM table */
4799a2dd95SBruce Richardson 	struct rte_lpm *lpm;
4899a2dd95SBruce Richardson 
4999a2dd95SBruce Richardson 	/* Next Hop Table (NHT) */
5099a2dd95SBruce Richardson 	uint32_t nht_users[RTE_TABLE_LPM_MAX_NEXT_HOPS];
51*85e32708STyler Retzlaff 	alignas(RTE_CACHE_LINE_SIZE) uint8_t nht[];
5299a2dd95SBruce Richardson };
5399a2dd95SBruce Richardson 
5499a2dd95SBruce Richardson static void *
rte_table_lpm_create(void * params,int socket_id,uint32_t entry_size)5599a2dd95SBruce Richardson rte_table_lpm_create(void *params, int socket_id, uint32_t entry_size)
5699a2dd95SBruce Richardson {
5799a2dd95SBruce Richardson 	struct rte_table_lpm_params *p = params;
5899a2dd95SBruce Richardson 	struct rte_table_lpm *lpm;
5999a2dd95SBruce Richardson 	struct rte_lpm_config lpm_config;
6099a2dd95SBruce Richardson 
6199a2dd95SBruce Richardson 	uint32_t total_size, nht_size;
6299a2dd95SBruce Richardson 
6399a2dd95SBruce Richardson 	/* Check input parameters */
6499a2dd95SBruce Richardson 	if (p == NULL) {
65ae67895bSDavid Marchand 		TABLE_LOG(ERR, "%s: NULL input parameters", __func__);
6699a2dd95SBruce Richardson 		return NULL;
6799a2dd95SBruce Richardson 	}
6899a2dd95SBruce Richardson 	if (p->n_rules == 0) {
69ae67895bSDavid Marchand 		TABLE_LOG(ERR, "%s: Invalid n_rules", __func__);
7099a2dd95SBruce Richardson 		return NULL;
7199a2dd95SBruce Richardson 	}
7299a2dd95SBruce Richardson 	if (p->number_tbl8s == 0) {
73ae67895bSDavid Marchand 		TABLE_LOG(ERR, "%s: Invalid number_tbl8s", __func__);
7499a2dd95SBruce Richardson 		return NULL;
7599a2dd95SBruce Richardson 	}
7699a2dd95SBruce Richardson 	if (p->entry_unique_size == 0) {
77ae67895bSDavid Marchand 		TABLE_LOG(ERR, "%s: Invalid entry_unique_size",
7899a2dd95SBruce Richardson 			__func__);
7999a2dd95SBruce Richardson 		return NULL;
8099a2dd95SBruce Richardson 	}
8199a2dd95SBruce Richardson 	if (p->entry_unique_size > entry_size) {
82ae67895bSDavid Marchand 		TABLE_LOG(ERR, "%s: Invalid entry_unique_size",
8399a2dd95SBruce Richardson 			__func__);
8499a2dd95SBruce Richardson 		return NULL;
8599a2dd95SBruce Richardson 	}
8699a2dd95SBruce Richardson 	if (p->name == NULL) {
87ae67895bSDavid Marchand 		TABLE_LOG(ERR, "%s: Table name is NULL",
8899a2dd95SBruce Richardson 			__func__);
8999a2dd95SBruce Richardson 		return NULL;
9099a2dd95SBruce Richardson 	}
9199a2dd95SBruce Richardson 	entry_size = RTE_ALIGN(entry_size, sizeof(uint64_t));
9299a2dd95SBruce Richardson 
9399a2dd95SBruce Richardson 	/* Memory allocation */
9499a2dd95SBruce Richardson 	nht_size = RTE_TABLE_LPM_MAX_NEXT_HOPS * entry_size;
9599a2dd95SBruce Richardson 	total_size = sizeof(struct rte_table_lpm) + nht_size;
9699a2dd95SBruce Richardson 	lpm = rte_zmalloc_socket("TABLE", total_size, RTE_CACHE_LINE_SIZE,
9799a2dd95SBruce Richardson 		socket_id);
9899a2dd95SBruce Richardson 	if (lpm == NULL) {
99ae67895bSDavid Marchand 		TABLE_LOG(ERR,
100ae67895bSDavid Marchand 			"%s: Cannot allocate %u bytes for LPM table",
10199a2dd95SBruce Richardson 			__func__, total_size);
10299a2dd95SBruce Richardson 		return NULL;
10399a2dd95SBruce Richardson 	}
10499a2dd95SBruce Richardson 
10599a2dd95SBruce Richardson 	/* LPM low-level table creation */
10699a2dd95SBruce Richardson 	lpm_config.max_rules = p->n_rules;
10799a2dd95SBruce Richardson 	lpm_config.number_tbl8s = p->number_tbl8s;
10899a2dd95SBruce Richardson 	lpm_config.flags = p->flags;
10999a2dd95SBruce Richardson 	lpm->lpm = rte_lpm_create(p->name, socket_id, &lpm_config);
11099a2dd95SBruce Richardson 
11199a2dd95SBruce Richardson 	if (lpm->lpm == NULL) {
11299a2dd95SBruce Richardson 		rte_free(lpm);
113ae67895bSDavid Marchand 		TABLE_LOG(ERR, "Unable to create low-level LPM table");
11499a2dd95SBruce Richardson 		return NULL;
11599a2dd95SBruce Richardson 	}
11699a2dd95SBruce Richardson 
11799a2dd95SBruce Richardson 	/* Memory initialization */
11899a2dd95SBruce Richardson 	lpm->entry_size = entry_size;
11999a2dd95SBruce Richardson 	lpm->entry_unique_size = p->entry_unique_size;
12099a2dd95SBruce Richardson 	lpm->n_rules = p->n_rules;
12199a2dd95SBruce Richardson 	lpm->offset = p->offset;
12299a2dd95SBruce Richardson 
12399a2dd95SBruce Richardson 	return lpm;
12499a2dd95SBruce Richardson }
12599a2dd95SBruce Richardson 
12699a2dd95SBruce Richardson static int
rte_table_lpm_free(void * table)12799a2dd95SBruce Richardson rte_table_lpm_free(void *table)
12899a2dd95SBruce Richardson {
12999a2dd95SBruce Richardson 	struct rte_table_lpm *lpm = table;
13099a2dd95SBruce Richardson 
13199a2dd95SBruce Richardson 	/* Check input parameters */
13299a2dd95SBruce Richardson 	if (lpm == NULL) {
133ae67895bSDavid Marchand 		TABLE_LOG(ERR, "%s: table parameter is NULL", __func__);
13499a2dd95SBruce Richardson 		return -EINVAL;
13599a2dd95SBruce Richardson 	}
13699a2dd95SBruce Richardson 
13799a2dd95SBruce Richardson 	/* Free previously allocated resources */
13899a2dd95SBruce Richardson 	rte_lpm_free(lpm->lpm);
13999a2dd95SBruce Richardson 	rte_free(lpm);
14099a2dd95SBruce Richardson 
14199a2dd95SBruce Richardson 	return 0;
14299a2dd95SBruce Richardson }
14399a2dd95SBruce Richardson 
14499a2dd95SBruce Richardson static int
nht_find_free(struct rte_table_lpm * lpm,uint32_t * pos)14599a2dd95SBruce Richardson nht_find_free(struct rte_table_lpm *lpm, uint32_t *pos)
14699a2dd95SBruce Richardson {
14799a2dd95SBruce Richardson 	uint32_t i;
14899a2dd95SBruce Richardson 
14999a2dd95SBruce Richardson 	for (i = 0; i < RTE_TABLE_LPM_MAX_NEXT_HOPS; i++) {
15099a2dd95SBruce Richardson 		if (lpm->nht_users[i] == 0) {
15199a2dd95SBruce Richardson 			*pos = i;
15299a2dd95SBruce Richardson 			return 1;
15399a2dd95SBruce Richardson 		}
15499a2dd95SBruce Richardson 	}
15599a2dd95SBruce Richardson 
15699a2dd95SBruce Richardson 	return 0;
15799a2dd95SBruce Richardson }
15899a2dd95SBruce Richardson 
15999a2dd95SBruce Richardson static int
nht_find_existing(struct rte_table_lpm * lpm,void * entry,uint32_t * pos)16099a2dd95SBruce Richardson nht_find_existing(struct rte_table_lpm *lpm, void *entry, uint32_t *pos)
16199a2dd95SBruce Richardson {
16299a2dd95SBruce Richardson 	uint32_t i;
16399a2dd95SBruce Richardson 
16499a2dd95SBruce Richardson 	for (i = 0; i < RTE_TABLE_LPM_MAX_NEXT_HOPS; i++) {
16599a2dd95SBruce Richardson 		uint8_t *nht_entry = &lpm->nht[i * lpm->entry_size];
16699a2dd95SBruce Richardson 
16799a2dd95SBruce Richardson 		if ((lpm->nht_users[i] > 0) && (memcmp(nht_entry, entry,
16899a2dd95SBruce Richardson 			lpm->entry_unique_size) == 0)) {
16999a2dd95SBruce Richardson 			*pos = i;
17099a2dd95SBruce Richardson 			return 1;
17199a2dd95SBruce Richardson 		}
17299a2dd95SBruce Richardson 	}
17399a2dd95SBruce Richardson 
17499a2dd95SBruce Richardson 	return 0;
17599a2dd95SBruce Richardson }
17699a2dd95SBruce Richardson 
17799a2dd95SBruce Richardson static int
rte_table_lpm_entry_add(void * table,void * key,void * entry,int * key_found,void ** entry_ptr)17899a2dd95SBruce Richardson rte_table_lpm_entry_add(
17999a2dd95SBruce Richardson 	void *table,
18099a2dd95SBruce Richardson 	void *key,
18199a2dd95SBruce Richardson 	void *entry,
18299a2dd95SBruce Richardson 	int *key_found,
18399a2dd95SBruce Richardson 	void **entry_ptr)
18499a2dd95SBruce Richardson {
18599a2dd95SBruce Richardson 	struct rte_table_lpm *lpm = table;
18699a2dd95SBruce Richardson 	struct rte_table_lpm_key *ip_prefix = key;
18799a2dd95SBruce Richardson 	uint32_t nht_pos, nht_pos0_valid;
18899a2dd95SBruce Richardson 	int status;
18999a2dd95SBruce Richardson 	uint32_t nht_pos0 = 0;
19099a2dd95SBruce Richardson 
19199a2dd95SBruce Richardson 	/* Check input parameters */
19299a2dd95SBruce Richardson 	if (lpm == NULL) {
193ae67895bSDavid Marchand 		TABLE_LOG(ERR, "%s: table parameter is NULL", __func__);
19499a2dd95SBruce Richardson 		return -EINVAL;
19599a2dd95SBruce Richardson 	}
19699a2dd95SBruce Richardson 	if (ip_prefix == NULL) {
197ae67895bSDavid Marchand 		TABLE_LOG(ERR, "%s: ip_prefix parameter is NULL",
19899a2dd95SBruce Richardson 			__func__);
19999a2dd95SBruce Richardson 		return -EINVAL;
20099a2dd95SBruce Richardson 	}
20199a2dd95SBruce Richardson 	if (entry == NULL) {
202ae67895bSDavid Marchand 		TABLE_LOG(ERR, "%s: entry parameter is NULL", __func__);
20399a2dd95SBruce Richardson 		return -EINVAL;
20499a2dd95SBruce Richardson 	}
20599a2dd95SBruce Richardson 
20699a2dd95SBruce Richardson 	if ((ip_prefix->depth == 0) || (ip_prefix->depth > 32)) {
207ae67895bSDavid Marchand 		TABLE_LOG(ERR, "%s: invalid depth (%d)",
20899a2dd95SBruce Richardson 			__func__, ip_prefix->depth);
20999a2dd95SBruce Richardson 		return -EINVAL;
21099a2dd95SBruce Richardson 	}
21199a2dd95SBruce Richardson 
21299a2dd95SBruce Richardson 	/* Check if rule is already present in the table */
21399a2dd95SBruce Richardson 	status = rte_lpm_is_rule_present(lpm->lpm, ip_prefix->ip,
21499a2dd95SBruce Richardson 		ip_prefix->depth, &nht_pos0);
21599a2dd95SBruce Richardson 	nht_pos0_valid = status > 0;
21699a2dd95SBruce Richardson 
21799a2dd95SBruce Richardson 	/* Find existing or free NHT entry */
21899a2dd95SBruce Richardson 	if (nht_find_existing(lpm, entry, &nht_pos) == 0) {
21999a2dd95SBruce Richardson 		uint8_t *nht_entry;
22099a2dd95SBruce Richardson 
22199a2dd95SBruce Richardson 		if (nht_find_free(lpm, &nht_pos) == 0) {
222ae67895bSDavid Marchand 			TABLE_LOG(ERR, "%s: NHT full", __func__);
22399a2dd95SBruce Richardson 			return -1;
22499a2dd95SBruce Richardson 		}
22599a2dd95SBruce Richardson 
22699a2dd95SBruce Richardson 		nht_entry = &lpm->nht[nht_pos * lpm->entry_size];
22799a2dd95SBruce Richardson 		memcpy(nht_entry, entry, lpm->entry_size);
22899a2dd95SBruce Richardson 	}
22999a2dd95SBruce Richardson 
23099a2dd95SBruce Richardson 	/* Add rule to low level LPM table */
23199a2dd95SBruce Richardson 	if (rte_lpm_add(lpm->lpm, ip_prefix->ip, ip_prefix->depth, nht_pos) < 0) {
232ae67895bSDavid Marchand 		TABLE_LOG(ERR, "%s: LPM rule add failed", __func__);
23399a2dd95SBruce Richardson 		return -1;
23499a2dd95SBruce Richardson 	}
23599a2dd95SBruce Richardson 
23699a2dd95SBruce Richardson 	/* Commit NHT changes */
23799a2dd95SBruce Richardson 	lpm->nht_users[nht_pos]++;
23899a2dd95SBruce Richardson 	lpm->nht_users[nht_pos0] -= nht_pos0_valid;
23999a2dd95SBruce Richardson 
24099a2dd95SBruce Richardson 	*key_found = nht_pos0_valid;
24199a2dd95SBruce Richardson 	*entry_ptr = (void *) &lpm->nht[nht_pos * lpm->entry_size];
24299a2dd95SBruce Richardson 	return 0;
24399a2dd95SBruce Richardson }
24499a2dd95SBruce Richardson 
24599a2dd95SBruce Richardson static int
rte_table_lpm_entry_delete(void * table,void * key,int * key_found,void * entry)24699a2dd95SBruce Richardson rte_table_lpm_entry_delete(
24799a2dd95SBruce Richardson 	void *table,
24899a2dd95SBruce Richardson 	void *key,
24999a2dd95SBruce Richardson 	int *key_found,
25099a2dd95SBruce Richardson 	void *entry)
25199a2dd95SBruce Richardson {
25299a2dd95SBruce Richardson 	struct rte_table_lpm *lpm = table;
25399a2dd95SBruce Richardson 	struct rte_table_lpm_key *ip_prefix = key;
25499a2dd95SBruce Richardson 	uint32_t nht_pos;
25599a2dd95SBruce Richardson 	int status;
25699a2dd95SBruce Richardson 
25799a2dd95SBruce Richardson 	/* Check input parameters */
25899a2dd95SBruce Richardson 	if (lpm == NULL) {
259ae67895bSDavid Marchand 		TABLE_LOG(ERR, "%s: table parameter is NULL", __func__);
26099a2dd95SBruce Richardson 		return -EINVAL;
26199a2dd95SBruce Richardson 	}
26299a2dd95SBruce Richardson 	if (ip_prefix == NULL) {
263ae67895bSDavid Marchand 		TABLE_LOG(ERR, "%s: ip_prefix parameter is NULL",
26499a2dd95SBruce Richardson 			__func__);
26599a2dd95SBruce Richardson 		return -EINVAL;
26699a2dd95SBruce Richardson 	}
26799a2dd95SBruce Richardson 	if ((ip_prefix->depth == 0) || (ip_prefix->depth > 32)) {
268ae67895bSDavid Marchand 		TABLE_LOG(ERR, "%s: invalid depth (%d)", __func__,
26999a2dd95SBruce Richardson 			ip_prefix->depth);
27099a2dd95SBruce Richardson 		return -EINVAL;
27199a2dd95SBruce Richardson 	}
27299a2dd95SBruce Richardson 
27399a2dd95SBruce Richardson 	/* Return if rule is not present in the table */
27499a2dd95SBruce Richardson 	status = rte_lpm_is_rule_present(lpm->lpm, ip_prefix->ip,
27599a2dd95SBruce Richardson 		ip_prefix->depth, &nht_pos);
27699a2dd95SBruce Richardson 	if (status < 0) {
277ae67895bSDavid Marchand 		TABLE_LOG(ERR, "%s: LPM algorithmic error", __func__);
27899a2dd95SBruce Richardson 		return -1;
27999a2dd95SBruce Richardson 	}
28099a2dd95SBruce Richardson 	if (status == 0) {
28199a2dd95SBruce Richardson 		*key_found = 0;
28299a2dd95SBruce Richardson 		return 0;
28399a2dd95SBruce Richardson 	}
28499a2dd95SBruce Richardson 
28599a2dd95SBruce Richardson 	/* Delete rule from the low-level LPM table */
28699a2dd95SBruce Richardson 	status = rte_lpm_delete(lpm->lpm, ip_prefix->ip, ip_prefix->depth);
28799a2dd95SBruce Richardson 	if (status) {
288ae67895bSDavid Marchand 		TABLE_LOG(ERR, "%s: LPM rule delete failed", __func__);
28999a2dd95SBruce Richardson 		return -1;
29099a2dd95SBruce Richardson 	}
29199a2dd95SBruce Richardson 
29299a2dd95SBruce Richardson 	/* Commit NHT changes */
29399a2dd95SBruce Richardson 	lpm->nht_users[nht_pos]--;
29499a2dd95SBruce Richardson 
29599a2dd95SBruce Richardson 	*key_found = 1;
29699a2dd95SBruce Richardson 	if (entry)
29799a2dd95SBruce Richardson 		memcpy(entry, &lpm->nht[nht_pos * lpm->entry_size],
29899a2dd95SBruce Richardson 			lpm->entry_size);
29999a2dd95SBruce Richardson 
30099a2dd95SBruce Richardson 	return 0;
30199a2dd95SBruce Richardson }
30299a2dd95SBruce Richardson 
30399a2dd95SBruce Richardson static int
rte_table_lpm_lookup(void * table,struct rte_mbuf ** pkts,uint64_t pkts_mask,uint64_t * lookup_hit_mask,void ** entries)30499a2dd95SBruce Richardson rte_table_lpm_lookup(
30599a2dd95SBruce Richardson 	void *table,
30699a2dd95SBruce Richardson 	struct rte_mbuf **pkts,
30799a2dd95SBruce Richardson 	uint64_t pkts_mask,
30899a2dd95SBruce Richardson 	uint64_t *lookup_hit_mask,
30999a2dd95SBruce Richardson 	void **entries)
31099a2dd95SBruce Richardson {
31199a2dd95SBruce Richardson 	struct rte_table_lpm *lpm = (struct rte_table_lpm *) table;
31299a2dd95SBruce Richardson 	uint64_t pkts_out_mask = 0;
31399a2dd95SBruce Richardson 	uint32_t i;
31499a2dd95SBruce Richardson 
3153d4e27fdSDavid Marchand 	__rte_unused uint32_t n_pkts_in = rte_popcount64(pkts_mask);
31699a2dd95SBruce Richardson 	RTE_TABLE_LPM_STATS_PKTS_IN_ADD(lpm, n_pkts_in);
31799a2dd95SBruce Richardson 
31899a2dd95SBruce Richardson 	pkts_out_mask = 0;
31999a2dd95SBruce Richardson 	for (i = 0; i < (uint32_t)(RTE_PORT_IN_BURST_SIZE_MAX -
3203d4e27fdSDavid Marchand 		rte_clz64(pkts_mask)); i++) {
32199a2dd95SBruce Richardson 		uint64_t pkt_mask = 1LLU << i;
32299a2dd95SBruce Richardson 
32399a2dd95SBruce Richardson 		if (pkt_mask & pkts_mask) {
32499a2dd95SBruce Richardson 			struct rte_mbuf *pkt = pkts[i];
32599a2dd95SBruce Richardson 			uint32_t ip = rte_bswap32(
32699a2dd95SBruce Richardson 				RTE_MBUF_METADATA_UINT32(pkt, lpm->offset));
32799a2dd95SBruce Richardson 			int status;
32899a2dd95SBruce Richardson 			uint32_t nht_pos;
32999a2dd95SBruce Richardson 
33099a2dd95SBruce Richardson 			status = rte_lpm_lookup(lpm->lpm, ip, &nht_pos);
33199a2dd95SBruce Richardson 			if (status == 0) {
33299a2dd95SBruce Richardson 				pkts_out_mask |= pkt_mask;
33399a2dd95SBruce Richardson 				entries[i] = (void *) &lpm->nht[nht_pos *
33499a2dd95SBruce Richardson 					lpm->entry_size];
33599a2dd95SBruce Richardson 			}
33699a2dd95SBruce Richardson 		}
33799a2dd95SBruce Richardson 	}
33899a2dd95SBruce Richardson 
33999a2dd95SBruce Richardson 	*lookup_hit_mask = pkts_out_mask;
3403d4e27fdSDavid Marchand 	RTE_TABLE_LPM_STATS_PKTS_LOOKUP_MISS(lpm, n_pkts_in - rte_popcount64(pkts_out_mask));
34199a2dd95SBruce Richardson 	return 0;
34299a2dd95SBruce Richardson }
34399a2dd95SBruce Richardson 
34499a2dd95SBruce Richardson static int
rte_table_lpm_stats_read(void * table,struct rte_table_stats * stats,int clear)34599a2dd95SBruce Richardson rte_table_lpm_stats_read(void *table, struct rte_table_stats *stats, int clear)
34699a2dd95SBruce Richardson {
34799a2dd95SBruce Richardson 	struct rte_table_lpm *t = table;
34899a2dd95SBruce Richardson 
34999a2dd95SBruce Richardson 	if (stats != NULL)
35099a2dd95SBruce Richardson 		memcpy(stats, &t->stats, sizeof(t->stats));
35199a2dd95SBruce Richardson 
35299a2dd95SBruce Richardson 	if (clear)
35399a2dd95SBruce Richardson 		memset(&t->stats, 0, sizeof(t->stats));
35499a2dd95SBruce Richardson 
35599a2dd95SBruce Richardson 	return 0;
35699a2dd95SBruce Richardson }
35799a2dd95SBruce Richardson 
35899a2dd95SBruce Richardson struct rte_table_ops rte_table_lpm_ops = {
35999a2dd95SBruce Richardson 	.f_create = rte_table_lpm_create,
36099a2dd95SBruce Richardson 	.f_free = rte_table_lpm_free,
36199a2dd95SBruce Richardson 	.f_add = rte_table_lpm_entry_add,
36299a2dd95SBruce Richardson 	.f_delete = rte_table_lpm_entry_delete,
36399a2dd95SBruce Richardson 	.f_add_bulk = NULL,
36499a2dd95SBruce Richardson 	.f_delete_bulk = NULL,
36599a2dd95SBruce Richardson 	.f_lookup = rte_table_lpm_lookup,
36699a2dd95SBruce Richardson 	.f_stats = rte_table_lpm_stats_read,
36799a2dd95SBruce Richardson };
368