TSG-20717 Service Chaining增加全局链路号以支持无历史状态发包

This commit is contained in:
luwenpeng
2024-04-20 11:40:00 +08:00
parent 6b03470739
commit a0f1eca0ce
25 changed files with 314 additions and 109 deletions

View File

@@ -119,6 +119,10 @@ enum SCE_STAT_FIELD
STAT_SESSION_NEW,
STAT_SESSION_FREE,
// stateless inject
STAT_STATELESS_INJECT_PKT,
STAT_STATELESS_INJECT_B,
// max
STAT_MAX,
};
@@ -236,6 +240,10 @@ static const char *stat_map[] =
[STAT_SESSION_NEW] = "session_new",
[STAT_SESSION_FREE] = "session_free",
// stateless inject
[STAT_STATELESS_INJECT_PKT] = "stateless_inject_P",
[STAT_STATELESS_INJECT_B] = "stateless_inject_B",
[STAT_MAX] = NULL};
static void global_metrics_parse_config(const char *profile, struct metrics_config *config)
@@ -435,6 +443,9 @@ void global_metrics_dump(struct global_metrics *global_metrics)
sum->session_new += thread->session_new;
sum->session_free += thread->session_free;
sum->stateless_inject.n_pkts += thread->stateless_inject.n_pkts;
sum->stateless_inject.n_bytes += thread->stateless_inject.n_bytes;
memset(thread, 0, sizeof(struct thread_metrics));
ATOMIC_SET(&(global_metrics->thread_metrics_flag[i]), THREAD_METRICS_CACHE_IS_FREE);
}
@@ -548,5 +559,9 @@ void global_metrics_dump(struct global_metrics *global_metrics)
FS_operate(global_metrics->fs_handle, global_metrics->fs_id[STAT_SESSION_NEW], 0, FS_OP_SET, sum->session_new);
FS_operate(global_metrics->fs_handle, global_metrics->fs_id[STAT_SESSION_FREE], 0, FS_OP_SET, sum->session_free);
// stateless inject
FS_operate(global_metrics->fs_handle, global_metrics->fs_id[STAT_STATELESS_INJECT_PKT], 0, FS_OP_SET, sum->stateless_inject.n_pkts);
FS_operate(global_metrics->fs_handle, global_metrics->fs_id[STAT_STATELESS_INJECT_B], 0, FS_OP_SET, sum->stateless_inject.n_bytes);
FS_passive_output(global_metrics->fs_handle);
}

View File

@@ -117,6 +117,12 @@ int mbuff_get_metadata(marsio_buff_t *rx_buff, struct metadata *meta)
return -1;
}
if (marsio_buff_get_metadata(rx_buff, MR_BUFF_LINK_ID, &(meta->link_id), sizeof(meta->link_id)) <= 0)
{
LOG_ERROR("%s: unable to get link_id from metadata", LOG_TAG_PKTIO);
return -1;
}
// 1: E2I
// 0: I2E
if (marsio_buff_get_metadata(rx_buff, MR_BUFF_DIR, &(meta->direction), sizeof(meta->direction)) <= 0)
@@ -181,7 +187,27 @@ int mbuff_set_metadata(marsio_buff_t *tx_buff, struct metadata *meta)
}
}
// need't set MR_BUFF_DIR, set MR_BUFF_ROUTE_CTX instead
if (meta->link_id)
{
if (marsio_buff_set_metadata(tx_buff, MR_BUFF_LINK_ID, &(meta->link_id), sizeof(meta->link_id)) != 0)
{
LOG_ERROR("%s: unable to set link_id from metadata", LOG_TAG_PKTIO);
return -1;
}
}
/*
* for stateless inject packet, set direction is necessary;
* if later set route_ctx, dir will be overwrite by route_ctx.
*
* direction : 1 (E2I)
* direction : 0 (I2E)
*/
if (marsio_buff_set_metadata(tx_buff, MR_BUFF_DIR, &(meta->direction), sizeof(meta->direction)) != 0)
{
LOG_ERROR("%s: unable to set buff_dir from metadata", LOG_TAG_PKTIO);
return -1;
}
if (meta->is_ctrl_pkt)
{
@@ -526,7 +552,7 @@ static inline int send_packet_to_sf(struct session_ctx *session_ctx, marsio_buff
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_ipid % 65535,
session_ctx->vxlan_src_port, meta->raw_len,
meta->direction, meta->is_decrypted, sf->sf_index);
meta->direction, meta->is_decrypted, sf->sf_index, meta->link_id);
nsend = marsio_buff_datalen(mbuff);
marsio_buff_set_metadata(mbuff, MR_BUFF_REHASH_INDEX, &rehash_index, sizeof(rehash_index));
PACKET_TRACE_ON_NEW(packet_io->instance, mbuff);
@@ -1215,6 +1241,7 @@ static void handle_inject_vxlan_packet(marsio_buff_t *rx_buff, struct thread_ctx
struct thread_metrics *thread_metrics = &thread_ctx->thread_metrics;
struct packet_io *packet_io = thread_ctx->ref_io;
int thread_index = thread_ctx->thread_index;
struct sce_ctx *sce_ctx = thread_ctx->ref_sce_ctx;
struct metadata meta;
struct vxlan_hdr *vxlan_hdr = NULL;
@@ -1237,9 +1264,19 @@ static void handle_inject_vxlan_packet(marsio_buff_t *rx_buff, struct thread_ctx
meta.raw_len = raw_len - VXLAN_FRAME_HDR_LEN;
meta.l7offset = 0;
meta.is_ctrl_pkt = 0;
sf_index = vxlan_get_opt(vxlan_hdr, VNI_OPT_SFINDEX);
meta.direction = vxlan_get_opt(vxlan_hdr, VNI_OPT_DIR);
meta.is_decrypted = vxlan_get_opt(vxlan_hdr, VNI_OPT_TRAFFIC);
sf_index = vxlan_get_sf_index(vxlan_hdr);
meta.direction = vxlan_get_dir(vxlan_hdr);
meta.is_decrypted = vxlan_get_traffic(vxlan_hdr);
meta.link_id = vxlan_get_link_id(vxlan_hdr);
if (vxlan_get_stateless(vxlan_hdr))
{
meta.sids.num = 1;
meta.sids.elems[0] = sce_ctx->stateless_sids;
THROUGHPUT_METRICS_INC(&(thread_metrics->stateless_inject), 1, meta.raw_len);
marsio_buff_adj(rx_buff, raw_len - meta.raw_len);
action_nf_inject(rx_buff, &meta, NULL, thread_ctx);
return;
}
session_ctx = inject_packet_search_session(session_table, meta.raw_data, meta.raw_len, thread_ctx);
if (session_ctx == NULL)

View File

@@ -74,6 +74,7 @@ struct sce_ctx *sce_ctx_create(const char *profile)
MESA_load_profile_int_def(profile, "system", "enable_debug", (int *)&(sce_ctx->enable_debug), 0);
MESA_load_profile_int_def(profile, "system", "enable_send_log", (int *)&(sce_ctx->enable_send_log), 0);
MESA_load_profile_int_def(profile, "system", "firewall_sids", (int *)&(sce_ctx->firewall_sids), 1001);
MESA_load_profile_int_def(profile, "system", "stateless_sids", (int *)&(sce_ctx->stateless_sids), 2000);
MESA_load_profile_int_def(profile, "system", "nr_worker_threads", (int *)&(sce_ctx->nr_worker_threads), 8);
MESA_load_profile_uint_range(profile, "system", "cpu_affinity_mask", MAX_THREAD_NUM, (unsigned int *)sce_ctx->cpu_affinity_mask);
MESA_load_profile_int_def(profile, "system", "ts_update_interval_ms", (int *)&(sce_ctx->ts_update_interval_ms), 1);