Signed-off-by: huanggaoyang <huanggaoya...@huawei.com> --- helper/include/odp/helper/table.h | 166 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100644 helper/include/odp/helper/table.h
diff --git a/helper/include/odp/helper/table.h b/helper/include/odp/helper/table.h new file mode 100644 index 0000000..80a5ae1 --- /dev/null +++ b/helper/include/odp/helper/table.h @@ -0,0 +1,166 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * @file + * + * ODP table + * + * Table designed to provide a standard interface to implement different + * types of tables for data processing. + * Use case: + * Table is publicly used in the following scenarios in data plane: + * ARP Table, IP Routing Table, MAC address filtering, ACL, interworking etc. + * The features of the "table": + * 1) All these different types of "table" have the common operations: + * Create a table, destroy a table, add an entry (key/value pairs), + * delete an entry, and lookup the value via the key. + * Usually these operations are software based, but also can be + * hardware accelerated if cost, power consumption are not the concern + * in your platform. + * 2) Different types of "table" can use different algorithms to + * add/delete/lookup the entry. + * + */ + +#ifndef ODPH_TABLE_H_ +#define ODPH_TABLE_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#define ODPH_TABLE_NAME_LEN 32 + +typedef ODP_HANDLE_T(odph_table_t); + +/** +* create a table +* Generally, tables only support key-value pair both with fixed size +* +* @param name +* name of this table, max ODPH_TABLE_NAME_LEN - 1 +* May be specified as NULL for anonymous table +* @param capacity +* Max memory usage this table use, in MBytes +* @param key_size +* fixed size of the 'key' in bytes. +* @param value_size +* fixed size of the 'value' in bytes. +* @return +* Handle to table instance or NULL if failed +* @note +*/ +typedef odph_table_t (*odph_table_create)(const char *name, + uint32_t capacity, + uint32_t key_size, + uint32_t value_size); + +/** + * Find a table by name + * + * @param name: Name of the table + * + * @return Handle of found table + * @retval NULL table could not be found + * + * @note + * This routine cannot be used to look up an anonymous + * table (one created with no name). + * This API supports Multiprocess + */ +typedef odph_table_t (*odph_table_lookup)(const char *name); + +/** + * Destroy a table previously created by odph_table_create() + * + * @param table: Handle of the table to be destroyed + * + * @retval 0 Success + * @retval -1 Failure + * + * @note + * This routine destroys a previously created pool + * also should free any memory allocated at creation + * + */ +typedef int (*odph_table_destroy)(odph_table_t table); + +/** + * table element add + * + * @param table: Handle of the table that the element be added + * + * @param key : address of 'key' in key-value pair. + * User should make sure the address and 'key_size' bytes after + * are accessible + * @param value : address of 'value' in key-value pair + * User should make sure the address and 'value_size' bytes after + * are accessible + * @retval 0 Success + * @retval -1 Failure + * + * @note: Add a same key again with a new value, the older one will be covered. + * This API supports Multiprocess + */ +typedef int (*odph_table_put_value)(odph_table_t table, void *key, + void *value); + +/** + * table element lookup + * + * @param table: Handle of the table that the element be added + * + * @param key : address of 'key' in key-value pair + * User should make sure the address and key_size bytes after + * are accessible + * + * @param buffer : output The buffer address to the 'value' + * After successfully found, the content of 'value' will be + * copied to this address + * User should make sure the address and value_size bytes after + * are accessible + * @param buffer_size: size of the buffer + * should be equal or bigger than value_size + * @retval 0 Success + * @retval -1 Failure + * + * @note: This API supports Multiprocess + */ +typedef int (*odph_table_get_value)(odph_table_t table, void *key, + void *buffer, + uint32_t buffer_size); +/** + * table element remove + * + * @param table: Handle of the table that the element will be removed from + * + * @param key : address of 'key' in key-value pair + * User should make sure the address and key_size bytes after + * are accessible + * + * @retval 0 Success + * @retval -1 Failure + * + * @note: This API supports Multiprocess + */ +typedef int (*odph_table_remove_value)(odph_table_t table, void *key); + +typedef struct odp_table_ops { + odph_table_create f_create; /**< Table Create */ + odph_table_lookup f_lookup; /**< Table Lookup */ + odph_table_destroy f_des; /**< Table Destroy */ + odph_table_put_value f_put; /**< Value Put */ + odph_table_get_value f_get; /**< Value Get */ + odph_table_remove_value f_remove; /**< Value Remove */ +} odph_table_ops_t; + +#ifdef __cplusplus +} +#endif + +#endif + -- 1.9.1 _______________________________________________ lng-odp mailing list lng-odp@lists.linaro.org https://lists.linaro.org/mailman/listinfo/lng-odp