This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
tango-tsg-service-chaining-…/common/include/stream_table.h
2023-01-10 16:30:42 +08:00

51 lines
1.4 KiB
C

#ifndef _STREAM_TABLE_H
#define _STREAM_TABLE_H
#ifdef __cpluscplus
extern "C"
{
#endif
#include <stdint.h>
#include <sys/types.h>
#include "uthash.h"
#include "stream_addr.h"
// Note: key_streamaddr must be initialized by memset(0) before use !!!
typedef void fn_free_cb(void *args);
struct stream_node
{
uint64_t key_streamid; /* first key */
struct stream_addr key_streamaddr; /* second key */
void *val_data;
fn_free_cb *val_freecb;
UT_hash_handle hh1; /* handle for first hash table */
UT_hash_handle hh2; /* handle for second hash table */
};
struct stream_table;
struct stream_table *stream_table_create();
void stream_table_destory(struct stream_table *table);
// key_streamaddr : deep copy
// val_data : shallow copy (malloc by user, free by val_freecb)
int stream_table_insert(struct stream_table *table, uint64_t key_streamid, const struct stream_addr *key_streamaddr, void *val_data, const fn_free_cb *val_freecb);
int stream_table_delete_by_streamid(struct stream_table *table, uint64_t key_streamid);
int stream_table_delete_by_streamaddr(struct stream_table *table, const struct stream_addr *key_streamaddr);
struct stream_node *stream_table_search_by_streamid(struct stream_table *table, uint64_t key_streamid);
struct stream_node *stream_table_search_by_streamaddr(struct stream_table *table, const struct stream_addr *key_streamaddr);
#ifdef __cpluscplus
}
#endif
#endif