Add packet utils to packet.h
This commit is contained in:
@@ -15,7 +15,8 @@ extern "C"
|
||||
|
||||
#define PACKET_MAX_LAYERS 32
|
||||
#define PACKET_LOG_ERROR(format, ...) LOG_ERROR("packet", format, ##__VA_ARGS__)
|
||||
#define PACKET_LOG_DEBUG(format, ...) LOG_DEBUG("packet", format, ##__VA_ARGS__)
|
||||
#define PACKET_LOG_DEBUG(format, ...) void(0)
|
||||
//#define PACKET_LOG_DEBUG(format, ...) LOG_DEBUG("packet", format, ##__VA_ARGS__)
|
||||
|
||||
enum ldbc_method
|
||||
{
|
||||
@@ -26,46 +27,11 @@ enum ldbc_method
|
||||
LDBC_METHOD_HASH_INNERMOST_EXT_IP = 5,
|
||||
};
|
||||
|
||||
enum packet_direction
|
||||
enum packet_origin
|
||||
{
|
||||
PACKET_DIRECTION_I2E = 0,
|
||||
PACKET_DIRECTION_E2I = 1,
|
||||
};
|
||||
|
||||
enum packet_action
|
||||
{
|
||||
PACKET_ACTION_FORWARD = 0,
|
||||
PACKET_ACTION_DROP = 1,
|
||||
};
|
||||
|
||||
enum packet_type
|
||||
{
|
||||
PACKET_TYPE_DATA = 0,
|
||||
PACKET_TYPE_CTRL = 1,
|
||||
};
|
||||
|
||||
struct metadata
|
||||
{
|
||||
#define MAX_SID_NUM 8
|
||||
#define MAX_ROUTE_LEN 64
|
||||
|
||||
struct
|
||||
{
|
||||
uint16_t list[MAX_SID_NUM];
|
||||
uint16_t used;
|
||||
} sid;
|
||||
struct
|
||||
{
|
||||
char data[MAX_ROUTE_LEN];
|
||||
uint16_t len;
|
||||
} route;
|
||||
|
||||
void *io_ctx;
|
||||
uint64_t domain;
|
||||
uint64_t session_id;
|
||||
enum packet_direction direction;
|
||||
enum packet_action action;
|
||||
enum packet_type type;
|
||||
PACKET_ORIGIN_MARSIO = 0x1,
|
||||
PACKET_ORIGIN_DUMPFILE = 0x2,
|
||||
PACKET_ORIGIN_USER = 0x3,
|
||||
};
|
||||
|
||||
struct packet
|
||||
@@ -77,9 +43,10 @@ struct packet
|
||||
|
||||
const char *data_ptr;
|
||||
uint16_t data_len;
|
||||
bool need_free;
|
||||
|
||||
struct metadata meta;
|
||||
int need_drop;
|
||||
void *io_ctx;
|
||||
enum packet_origin origin;
|
||||
};
|
||||
|
||||
// return innermost payload
|
||||
@@ -90,50 +57,27 @@ void packet_print(const struct packet *pkt);
|
||||
// direction 0: I2E
|
||||
uint64_t packet_get_hash(const struct packet *pkt, enum ldbc_method method, int direction);
|
||||
|
||||
// return 0: success
|
||||
// return -1: failed
|
||||
int packet_set_sid(struct packet *pkt, uint16_t *sid, int num);
|
||||
// return number of sid
|
||||
int packet_get_sid(const struct packet *pkt, uint16_t *sid, int size);
|
||||
// return 0: success
|
||||
// return -1: failed
|
||||
int packet_prepend_sid(struct packet *pkt, uint16_t sid);
|
||||
// return 0: success
|
||||
// return -1: failed
|
||||
int packet_append_sid(struct packet *pkt, uint16_t sid);
|
||||
/******************************************************************************
|
||||
* Utils
|
||||
******************************************************************************/
|
||||
|
||||
// return 0: success
|
||||
// return -1: failed
|
||||
int packet_set_route_ctx(struct packet *pkt, const char *route, int len);
|
||||
// return len of route ctx
|
||||
int packet_get_route_ctx(const struct packet *pkt, char *buff, int size);
|
||||
void packet_set_origin(struct packet *pkt, enum packet_origin origin);
|
||||
enum packet_origin packet_get_origin(const struct packet *pkt);
|
||||
|
||||
void packet_set_io_ctx(struct packet *pkt, void *ctx);
|
||||
void *packet_get_io_ctx(const struct packet *pkt);
|
||||
|
||||
void packet_set_domain(struct packet *pkt, uint64_t domain);
|
||||
uint64_t packet_get_domain(const struct packet *pkt);
|
||||
|
||||
void packet_set_session_id(struct packet *pkt, uint64_t session_id);
|
||||
uint64_t packet_get_session_id(const struct packet *pkt);
|
||||
|
||||
void packet_set_direction(struct packet *pkt, enum packet_direction direction);
|
||||
enum packet_direction packet_get_direction(const struct packet *pkt);
|
||||
|
||||
void packet_set_action(struct packet *pkt, enum packet_action action);
|
||||
enum packet_action packet_get_action(const struct packet *pkt);
|
||||
|
||||
void packet_set_type(struct packet *pkt, enum packet_type type);
|
||||
enum packet_type packet_get_type(const struct packet *pkt);
|
||||
int packet_is_fragment(const struct packet *pkt);
|
||||
|
||||
struct packet *packet_new(uint16_t pkt_len);
|
||||
void packet_free(struct packet *pkt);
|
||||
struct packet *packet_dup(const struct packet *pkt);
|
||||
|
||||
const char *packet_get_data(const struct packet *pkt);
|
||||
uint16_t packet_get_len(const struct packet *pkt);
|
||||
void packet_set_domain(struct packet *pkt, uint64_t domain);
|
||||
uint64_t packet_get_domain(const struct packet *pkt);
|
||||
|
||||
bool packet_is_fragment(const struct packet *pkt);
|
||||
void packet_set_route_ctx(struct packet *pkt, const char *route, int len);
|
||||
int packet_get_route_ctx(const struct packet *pkt, char *buff, int size); // return len of route ctx
|
||||
|
||||
#ifdef __cpluscplus
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user