reactor packet I/O & duplicated packet filter & evicted session filter
This commit is contained in:
@@ -11,10 +11,9 @@ extern "C"
|
||||
#include "tuple.h"
|
||||
#include "log.h"
|
||||
|
||||
#define PACKET_MAX_LAYERS 16
|
||||
#define PACKET_MAX_LAYERS 32
|
||||
#define PACKET_LOG_ERROR(format, ...) LOG_ERROR("packet", format, ##__VA_ARGS__)
|
||||
#define PACKET_LOG_DEBUG(format, ...) void(0)
|
||||
// #define PACKET_LOG_DEBUG(format, ...) LOG_DEBUG("packet", format, ##__VA_ARGS__)
|
||||
#define PACKET_LOG_DEBUG(format, ...) LOG_DEBUG("packet", format, ##__VA_ARGS__)
|
||||
|
||||
enum layer_type
|
||||
{
|
||||
@@ -61,7 +60,49 @@ enum ldbc_method
|
||||
LDBC_METHOD_HASH_INNERMOST_EXT_IP = 5,
|
||||
};
|
||||
|
||||
struct layer_record
|
||||
enum packet_direction
|
||||
{
|
||||
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 *user_data;
|
||||
uint64_t domain;
|
||||
uint64_t session_id;
|
||||
enum packet_direction direction;
|
||||
enum packet_action action;
|
||||
enum packet_type type;
|
||||
};
|
||||
|
||||
struct layer
|
||||
{
|
||||
enum layer_type type;
|
||||
const char *hdr_ptr; // header pointer
|
||||
@@ -71,61 +112,90 @@ struct layer_record
|
||||
uint16_t pld_len; // payload length
|
||||
};
|
||||
|
||||
#define MAX_SID_NUM 8
|
||||
#define MAX_ROUTE_LEN 64
|
||||
|
||||
struct packet
|
||||
{
|
||||
struct layer_record layers[PACKET_MAX_LAYERS];
|
||||
struct layer_record *frag_layer; // fragment layer
|
||||
struct layer layers[PACKET_MAX_LAYERS];
|
||||
struct layer *frag_layer; // fragment layer
|
||||
int8_t layers_used;
|
||||
int8_t layers_size;
|
||||
|
||||
const char *data_ptr;
|
||||
uint16_t data_len;
|
||||
uint64_t domain;
|
||||
bool need_free;
|
||||
|
||||
// metadata
|
||||
void *io_ctx;
|
||||
|
||||
uint16_t sid_list[MAX_SID_NUM];
|
||||
uint16_t sid_used;
|
||||
|
||||
char route_ctx[MAX_ROUTE_LEN];
|
||||
uint16_t route_len;
|
||||
|
||||
uint64_t session_id;
|
||||
uint8_t direction;
|
||||
uint8_t type;
|
||||
uint8_t action;
|
||||
struct metadata meta;
|
||||
};
|
||||
|
||||
// return innermost payload
|
||||
const char *packet_parse(struct packet *handler, const char *data, uint16_t len);
|
||||
void packet_print(const struct packet *handler);
|
||||
const char *packet_parse(struct packet *pkt, const char *data, uint16_t len);
|
||||
void packet_print(const struct packet *pkt);
|
||||
|
||||
// return 0 : found
|
||||
// return -1 : not found
|
||||
int packet_get_innermost_tuple2(const struct packet *handler, struct tuple2 *tuple);
|
||||
int packet_get_outermost_tuple2(const struct packet *handler, struct tuple2 *tuple);
|
||||
// return 0: found
|
||||
// return -1: not found
|
||||
int packet_get_innermost_tuple2(const struct packet *pkt, struct tuple2 *tuple);
|
||||
int packet_get_outermost_tuple2(const struct packet *pkt, struct tuple2 *tuple);
|
||||
|
||||
// return 0 : found
|
||||
// return -1 : not found
|
||||
int packet_get_innermost_tuple4(const struct packet *handler, struct tuple4 *tuple);
|
||||
int packet_get_outermost_tuple4(const struct packet *handler, struct tuple4 *tuple);
|
||||
// return 0: found
|
||||
// return -1: not found
|
||||
int packet_get_innermost_tuple4(const struct packet *pkt, struct tuple4 *tuple);
|
||||
int packet_get_outermost_tuple4(const struct packet *pkt, struct tuple4 *tuple);
|
||||
|
||||
// return 0 : found
|
||||
// return -1 : not found
|
||||
int packet_get_innermost_tuple6(const struct packet *handler, struct tuple6 *tuple);
|
||||
int packet_get_outermost_tuple6(const struct packet *handler, struct tuple6 *tuple);
|
||||
// return 0: found
|
||||
// return -1: not found
|
||||
int packet_get_innermost_tuple6(const struct packet *pkt, struct tuple6 *tuple);
|
||||
int packet_get_outermost_tuple6(const struct packet *pkt, struct tuple6 *tuple);
|
||||
|
||||
const struct layer_record *packet_get_innermost_layer(const struct packet *handler, enum layer_type type);
|
||||
const struct layer_record *packet_get_outermost_layer(const struct packet *handler, enum layer_type type);
|
||||
const struct layer *packet_get_innermost_layer(const struct packet *pkt, enum layer_type type);
|
||||
const struct layer *packet_get_outermost_layer(const struct packet *pkt, enum layer_type type);
|
||||
|
||||
// direction 1: E2I
|
||||
// direction 0: I2E
|
||||
uint64_t packet_get_hash(const struct packet *handler, enum ldbc_method method, int direction);
|
||||
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);
|
||||
|
||||
// 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_user_data(struct packet *pkt, void *user_data);
|
||||
void *packet_get_user_data(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);
|
||||
|
||||
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);
|
||||
|
||||
bool packet_is_fragment(const struct packet *pkt);
|
||||
|
||||
#ifdef __cpluscplus
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user