Optimize integration testing
- Add injection package plug-in - Add libstellar_dynamic.so to facilitate unit testing of upper-level plug-ins
This commit is contained in:
@@ -386,7 +386,7 @@ int build_udp_packet(const struct packet *first, const char *udp_pld, int pld_le
|
||||
return len - trim;
|
||||
}
|
||||
|
||||
int inject_tcp_packet(const struct session *sess, enum flow_direction inject_dir, uint8_t tcp_flags, const char *payload, uint16_t len)
|
||||
int inject_tcp_packet(struct stellar *st, const struct session *sess, enum flow_direction inject_dir, uint8_t tcp_flags, const char *payload, uint16_t len)
|
||||
{
|
||||
#define TCP_FLAGS_LOG_FORMAT "URG:%d, ACK:%d, PSH:%d, RST:%d, SYN:%d, FIN:%d"
|
||||
#define TCP_FLAGS_LOG_VALUE(flags) \
|
||||
@@ -396,6 +396,8 @@ int inject_tcp_packet(const struct session *sess, enum flow_direction inject_dir
|
||||
|
||||
uint16_t thr_idx = stellar_get_current_thread_index();
|
||||
uint64_t time_ms = stellar_get_monotonic_time_msec();
|
||||
struct packet_io *packet_io = stellar_get_packet_io(st);
|
||||
struct session_manager *sess_mgr = stellar_get_session_manager(st);
|
||||
|
||||
if (session_get_type(sess) != SESSION_TYPE_TCP)
|
||||
{
|
||||
@@ -442,8 +444,8 @@ int inject_tcp_packet(const struct session *sess, enum flow_direction inject_dir
|
||||
packet_parse(&inj_pkt, buff, pkt_len);
|
||||
packet_set_origin(&inj_pkt, PACKET_ORIGIN_USERSTACK);
|
||||
packet_set_origin_ctx(&inj_pkt, &meta);
|
||||
session_manager_record_duplicated_packet(runtime->threads[thr_idx].sess_mgr, &inj_pkt, time_ms);
|
||||
if (packet_io_inject(runtime->packet_io, thr_idx, &inj_pkt, 1) == 1)
|
||||
session_manager_record_duplicated_packet(sess_mgr, &inj_pkt, time_ms);
|
||||
if (packet_io_inject(packet_io, thr_idx, &inj_pkt, 1) == 1)
|
||||
{
|
||||
session_inc_stat((struct session *)sess, inject_dir, STAT_INJECTED_PACKETS_SUCCESS, 1);
|
||||
session_inc_stat((struct session *)sess, inject_dir, STAT_INJECTED_BYTES_SUCCESS, pkt_len);
|
||||
@@ -462,10 +464,12 @@ int inject_tcp_packet(const struct session *sess, enum flow_direction inject_dir
|
||||
}
|
||||
}
|
||||
|
||||
int inject_udp_packet(const struct session *sess, enum flow_direction inject_dir, const char *payload, uint16_t len)
|
||||
int inject_udp_packet(struct stellar *st, const struct session *sess, enum flow_direction inject_dir, const char *payload, uint16_t len)
|
||||
{
|
||||
uint16_t thr_idx = stellar_get_current_thread_index();
|
||||
uint64_t time_ms = stellar_get_monotonic_time_msec();
|
||||
struct packet_io *packet_io = stellar_get_packet_io(st);
|
||||
struct session_manager *sess_mgr = stellar_get_session_manager(st);
|
||||
|
||||
if (session_get_type(sess) != SESSION_TYPE_UDP)
|
||||
{
|
||||
@@ -505,8 +509,8 @@ int inject_udp_packet(const struct session *sess, enum flow_direction inject_dir
|
||||
packet_parse(&inj_pkt, buff, pkt_len);
|
||||
packet_set_origin(&inj_pkt, PACKET_ORIGIN_USERSTACK);
|
||||
packet_set_origin_ctx(&inj_pkt, &meta);
|
||||
session_manager_record_duplicated_packet(runtime->threads[thr_idx].sess_mgr, &inj_pkt, time_ms);
|
||||
if (packet_io_inject(runtime->packet_io, thr_idx, &inj_pkt, 1) == 1)
|
||||
session_manager_record_duplicated_packet(sess_mgr, &inj_pkt, time_ms);
|
||||
if (packet_io_inject(packet_io, thr_idx, &inj_pkt, 1) == 1)
|
||||
{
|
||||
session_inc_stat((struct session *)sess, inject_dir, STAT_INJECTED_PACKETS_SUCCESS, 1);
|
||||
session_inc_stat((struct session *)sess, inject_dir, STAT_INJECTED_BYTES_SUCCESS, pkt_len);
|
||||
@@ -529,30 +533,30 @@ int inject_udp_packet(const struct session *sess, enum flow_direction inject_dir
|
||||
* Public API
|
||||
******************************************************************************/
|
||||
|
||||
int stellar_inject_tcp_rst(const struct session *sess, enum flow_direction inject_dir)
|
||||
int stellar_inject_tcp_rst(struct stellar *st, const struct session *sess, enum flow_direction inject_dir)
|
||||
{
|
||||
return inject_tcp_packet(sess, inject_dir, TH_RST | TH_ACK, NULL, 0);
|
||||
return inject_tcp_packet(st, sess, inject_dir, TH_RST | TH_ACK, NULL, 0);
|
||||
}
|
||||
|
||||
int stellar_inject_tcp_fin(const struct session *sess, enum flow_direction inject_dir)
|
||||
int stellar_inject_tcp_fin(struct stellar *st, const struct session *sess, enum flow_direction inject_dir)
|
||||
{
|
||||
return inject_tcp_packet(sess, inject_dir, TH_FIN | TH_ACK, NULL, 0);
|
||||
return inject_tcp_packet(st, sess, inject_dir, TH_FIN | TH_ACK, NULL, 0);
|
||||
}
|
||||
|
||||
int stellar_inject_payload(const struct session *sess, enum flow_direction inject_dir, const char *payload, uint16_t len)
|
||||
int stellar_inject_payload(struct stellar *st, const struct session *sess, enum flow_direction inject_dir, const char *payload, uint16_t len)
|
||||
{
|
||||
switch (session_get_type(sess))
|
||||
{
|
||||
case SESSION_TYPE_TCP:
|
||||
return inject_tcp_packet(sess, inject_dir, TH_ACK, payload, len);
|
||||
return inject_tcp_packet(st, sess, inject_dir, TH_ACK, payload, len);
|
||||
case SESSION_TYPE_UDP:
|
||||
return inject_udp_packet(sess, inject_dir, payload, len);
|
||||
return inject_udp_packet(st, sess, inject_dir, payload, len);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int stellar_inject_ctrl_msg(const struct session *sess, const struct sid_list *sids, const char *msg, uint16_t len)
|
||||
int stellar_inject_ctrl_msg(struct stellar *st, const struct session *sess, const struct sid_list *sids, const char *msg, uint16_t len)
|
||||
{
|
||||
// TODO
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user