diff --git a/platform/include/sce.h b/platform/include/sce.h index 7cff177..311204b 100644 --- a/platform/include/sce.h +++ b/platform/include/sce.h @@ -36,7 +36,7 @@ struct thread_ctx int session_table_need_reset; int thread_is_runing; - uint64_t tx_packets_to_sf; + uint64_t tx_packets_ipid; }; /****************************************************************************** diff --git a/platform/src/main.cpp b/platform/src/main.cpp index fe319df..88cb26e 100644 --- a/platform/src/main.cpp +++ b/platform/src/main.cpp @@ -201,7 +201,7 @@ int main(int argc, char **argv) ctx->work_threads[i].ref_enforcer = ctx->enforcer; ctx->work_threads[i].ref_sce_ctx = ctx; ctx->work_threads[i].session_table_need_reset = 0; - ctx->work_threads[i].tx_packets_to_sf = 0; + ctx->work_threads[i].tx_packets_ipid = random(); } for (int i = 0; i < ctx->nr_worker_threads; i++) diff --git a/platform/src/packet_io.cpp b/platform/src/packet_io.cpp index 13a68f5..f582d27 100644 --- a/platform/src/packet_io.cpp +++ b/platform/src/packet_io.cpp @@ -509,7 +509,7 @@ void vlan_encapsulate(marsio_buff_t *mbuff, int vlan_id, int replace_orig_vlan_h static int send_packet_to_sf(marsio_buff_t *mbuff, struct metadata *meta, struct selected_sf *sf, struct thread_ctx *thread_ctx) { - thread_ctx->tx_packets_to_sf++; + thread_ctx->tx_packets_ipid++; int nsend = 0; struct packet_io *packet_io = thread_ctx->ref_io; struct thread_metrics *thread_metrics = &thread_ctx->thread_metrics; @@ -519,7 +519,7 @@ static int send_packet_to_sf(marsio_buff_t *mbuff, struct metadata *meta, struct { case ENCAPSULATE_METHOD_VXLAN_G: vxlan_encapsulate(mbuff, packet_io->config.dev_endpoint_l3_mac, sf->sf_dst_mac, - packet_io->config.dev_endpoint_l3_ip, sf->sf_dst_ip, thread_ctx->tx_packets_to_sf % 65535, + packet_io->config.dev_endpoint_l3_ip, sf->sf_dst_ip, thread_ctx->tx_packets_ipid % 65535, meta->session_id % (65535 - 49152) + 49152, meta->raw_len, meta->is_e2i_dir, meta->is_decrypted, sf->sf_index); nsend = marsio_buff_datalen(mbuff); marsio_send_burst_with_options(packet_io->dev_endpoint_l3.mr_path, thread_ctx->thread_index, &mbuff, 1, MARSIO_SEND_OPT_REHASH); @@ -728,11 +728,16 @@ static void action_sf_chaining(struct thread_ctx *thread_ctx, struct session_ctx * handle session status ******************************************************************************/ -static int send_ctrl_packet(struct session_ctx *session_ctx, struct selected_chaining *chaining, struct thread_ctx *thread_ctx) +static int send_ctrl_packet(struct session_ctx *session_ctx, struct selected_chainings *chainings, struct thread_ctx *thread_ctx) { struct sce_ctx *sce_ctx = thread_ctx->ref_sce_ctx; struct packet_io *packet_io = thread_ctx->ref_io; + struct mutable_array *rule_ids = &session_ctx->rule_ids; + struct selected_chaining *chaining_raw = chainings->chaining_raw; + struct selected_chaining *chaining_decrypted = chainings->chaining_decrypted; int thread_index = thread_ctx->thread_index; + int sc_rsp_raw_exist = 0; + int sc_rsp_decrypted_exist = 0; char *data; size_t size; @@ -768,17 +773,57 @@ static int send_ctrl_packet(struct session_ctx *session_ctx, struct selected_cha mpack_write_cstr(&writer, "sce"); mpack_build_map(&writer); // sce value begin - mpack_write_cstr(&writer, "sf_profile_ids"); - mpack_build_array(&writer); - for (int i = 0; i < chaining->chaining_used; i++) { - struct selected_sf *sf = &(chaining->chaining[i]); - if (sf->sf_action == SESSION_ACTION_FORWARD) + mpack_write_cstr(&writer, "sc_rule_list"); + mpack_build_array(&writer); // sc_rule_list begin + for (int i = 0; i < rule_ids->num; i++) { - mpack_write_u32(&writer, sf->sf_profile_id); + mpack_write_u64(&writer, mutable_array_index_elem(rule_ids, i)); + } + mpack_complete_array(&writer); // sc_rule_list end + } + + { + for (int i = 0; i < chaining_raw->chaining_used; i++) + { + struct selected_sf *sf = &(chaining_raw->chaining[i]); + if (sf->sf_action == SESSION_ACTION_FORWARD) + { + if (sc_rsp_raw_exist == 0) + { + mpack_write_cstr(&writer, "sc_rsp_raw"); + mpack_build_array(&writer); // sc_rsp_raw begin + sc_rsp_raw_exist = 1; + } + mpack_write_u64(&writer, sf->sf_profile_id); + } + } + if (sc_rsp_raw_exist == 1) + { + mpack_complete_array(&writer); // sc_rsp_raw end + } + } + + { + for (int i = 0; i < chaining_decrypted->chaining_used; i++) + { + struct selected_sf *sf = &(chaining_decrypted->chaining[i]); + if (sf->sf_action == SESSION_ACTION_FORWARD) + { + if (sc_rsp_decrypted_exist == 0) + { + mpack_write_cstr(&writer, "sc_rsp_decrypted"); + mpack_build_array(&writer); // sc_rsp_decrypted begin + sc_rsp_decrypted_exist = 1; + } + mpack_write_u64(&writer, sf->sf_profile_id); + } + } + if (sc_rsp_decrypted_exist == 1) + { + mpack_complete_array(&writer); // sc_rsp_decrypted end } } - mpack_complete_array(&writer); mpack_complete_map(&writer); // sce value end } @@ -830,23 +875,10 @@ static void send_event_log(struct session_ctx *session_ctx, struct thread_ctx *t int nsend = 0; struct sce_ctx *sce_ctx = thread_ctx->ref_sce_ctx; struct thread_metrics *thread_metrics = &thread_ctx->thread_metrics; - struct selected_chaining *chaining_raw = session_ctx->chainings.chaining_raw; - struct selected_chaining *chaining_decrypted = session_ctx->chainings.chaining_decrypted; - if (chaining_raw->chaining_used && sce_ctx->enable_send_log) + if (sce_ctx->enable_send_log) { - nsend = send_ctrl_packet(session_ctx, chaining_raw, thread_ctx); - if (nsend > 0) - { - ATOMIC_INC(&(thread_metrics->sf_session.log)); - throughput_metrics_inc(&(thread_metrics->ctrl_pkt.tx), 1, nsend); - throughput_metrics_inc(&(thread_metrics->device.nf_tx), 1, nsend); - } - } - - if (chaining_decrypted->chaining_used && sce_ctx->enable_send_log) - { - nsend = send_ctrl_packet(session_ctx, chaining_decrypted, thread_ctx); + nsend = send_ctrl_packet(session_ctx, &session_ctx->chainings, thread_ctx); if (nsend > 0) { ATOMIC_INC(&(thread_metrics->sf_session.log));