summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author李仁杰 <[email protected]>2020-08-05 22:22:43 +0800
committer李仁杰 <[email protected]>2020-08-05 22:22:43 +0800
commite013b209a031f2f0d3329fe083b1c3fa8fa66eba (patch)
treeb0ed5603db4d0def9cbe781d2aee634a91395b71
parentb5449af4e1795eb0601bd9b22b881b9c3a095ccf (diff)
Update lirenjie_vxlan_sapp_20200803.c 入口函数改为TCP_ENTRY_ALL,在里面进行计数
-rw-r--r--lirenjie_vxlan_sapp_20200803.c147
1 files changed, 145 insertions, 2 deletions
diff --git a/lirenjie_vxlan_sapp_20200803.c b/lirenjie_vxlan_sapp_20200803.c
index afcc1fe..9bb1f59 100644
--- a/lirenjie_vxlan_sapp_20200803.c
+++ b/lirenjie_vxlan_sapp_20200803.c
@@ -685,14 +685,157 @@ static void print_traffic_info(struct traffic_info *tinfo, struct streaminfo *ps
break;
}
}
-
+static int tcp_flow_id = -1;
char TCP_ENTRY_ALL(struct streaminfo *pstream, void **pme, int thread_seq, const void *raw_pkt)
{
//printf("TCP_ENTRY_ALL SUCCESS!!!\n");
+ struct tcpdetail *raw_pdetail = (struct tcpdetail *)pstream->pdetail;
+ struct traffic_info *tinfo;
+
+#if ENABLE_COUNT_THREAD
+ all_stream_pkt_num[thread_seq]++;
+#endif
+
+ if (-1 == tcp_flow_id)
+ {
+ tcp_flow_id = project_customer_register("tcp_flow_stat", "struct");
+ if (-1 == tcp_flow_id)
+ {
+ // printf("'tcp_flow_stat' is disable, no statistics\n");
+ MESA_handle_runtime_log(runtime_log_handler, RLOG_LV_FATAL, module_name, "'tcp_flow_stat' is disable, no statistics\n");
+ }
+ }
+
+ if (pstream->pktstate == OP_STATE_PENDING)
+ {
+ tinfo = (struct traffic_info *)calloc(1, sizeof(struct traffic_info));
+ //tinfo->service_id = get_service_id_from_sport(pstream); //获取vx_lan_id字段,具体方法待定 //tinfo->service_id = get_service_id_from_vxlanid(pstream);
+ tinfo->vxlan_vpn_id = get_vpnid_from_stream(pstream);
+ /* PROTOCOL */
+ switch (pstream->addr.addrtype)
+ {
+ case ADDR_TYPE_IPV4:
+ tinfo->protocol = 1; // IPV4_TCP
+ tinfo->vx_type = 0x0800;
+ break;
+ case ADDR_TYPE_IPV6:
+ tinfo->protocol = 3; // IPV6_TCP
+ tinfo->vx_type = 0x86DD;
+ break;
+ case ADDR_TYPE_ARP:
+ tinfo->protocol = 0;
+ tinfo->vx_type = 0x0806;
+ break;
+ default:
+ tinfo->protocol = 0;
+ tinfo->vx_type = 0;
+ break;
+ }
+ /* vx_UDP_header_src_port dst_port*/
+ tinfo->vx_UDP_header_src_port = get_vx_UDP_header_src_port(pstream);
+ tinfo->vx_UDP_header_dst_port = 4789;
+ /* vx_ip_header_src_ip dst_ip*/
+ if (get_vxlan_ip_addr(pstream, tinfo) < 0)
+ {
+ goto error_drop;
+ }
+ /* IPv4、IPv6头部信息 */
+ get_ip_detail(pstream, tinfo, raw_pkt);
+ /* 应用层协议类型 用目的端口表示*/
+ tinfo->PROTO_TYPE = get_proto_type(pstream);
+
+ *pme = tinfo;
+ }
+ tinfo = (struct traffic_info *)(*pme);
+
+ if (pstream->pktstate == OP_STATE_CLOSE)
+ {
+ if (tcp_flow_id != -1)
+ {
+ struct tcp_flow_stat *tflow = (struct tcp_flow_stat *)project_req_get_struct(pstream, tcp_flow_id);
+ tinfo->C2S_pkt_num = tflow->C2S_all_pkt - tinfo->C2S_pkt_num;
+ tinfo->S2C_pkt_num = tflow->S2C_all_pkt - tinfo->S2C_pkt_num;
+ tinfo->C2S_bytes = tflow->C2S_all_byte - tinfo->C2S_bytes;
+ tinfo->S2C_bytes = tflow->S2C_all_byte - tinfo->S2C_bytes;
+ }
+ else
+ {
+ tinfo->C2S_pkt_num = 0;
+ tinfo->S2C_pkt_num = 0;
+ tinfo->C2S_bytes = 0;
+ tinfo->S2C_bytes = 0;
+ }
+#if ENABLE_COUNT_THREAD
+ close_stream_pkt_num[thread_seq] += tinfo->C2S_pkt_num;
+ close_stream_pkt_num[thread_seq] += tinfo->S2C_pkt_num;
+ push_count[thread_seq]++;
+#endif
+ /* layer_addr */
+ tinfo->addr = pstream->addr;
+ /* STAT_TIME */
+ // tinfo->stat_time = time(0);
+ gettimeofday(&tinfo->stat_time, NULL);
+
+ print_traffic_info(tinfo, pstream);
+ free(tinfo);
+
+ return DEFAULT_RETURN_VALUE;
+ }
+
+ /*每隔N秒发一次 */
+ if (pstream->pktstate == OP_STATE_DATA)
+ {
+ if (time_out)
+ {
+ if (tcp_flow_id != -1)
+ {
+ struct tcp_flow_stat *tflow = (struct tcp_flow_stat *)project_req_get_struct(pstream, tcp_flow_id);
+ tinfo->C2S_pkt_num = tflow->C2S_all_pkt - tinfo->C2S_pkt_num;
+ tinfo->S2C_pkt_num = tflow->S2C_all_pkt - tinfo->S2C_pkt_num;
+ tinfo->C2S_bytes = tflow->C2S_all_byte - tinfo->C2S_bytes;
+ tinfo->S2C_bytes = tflow->S2C_all_byte - tinfo->S2C_bytes;
+ }
+ else
+ {
+ tinfo->C2S_pkt_num = 0;
+ tinfo->S2C_pkt_num = 0;
+ tinfo->C2S_bytes = 0;
+ tinfo->S2C_bytes = 0;
+ }
+ /* layer_addr */
+ tinfo->addr = pstream->addr;
+
+ gettimeofday(&tinfo->stat_time, NULL);
+
+#if ENABLE_COUNT_THREAD
+ close_stream_pkt_num[thread_seq] += tinfo->C2S_pkt_num;
+ close_stream_pkt_num[thread_seq] += tinfo->S2C_pkt_num;
+ push_count[thread_seq]++;
+#endif
+ print_traffic_info(tinfo, pstream);
+
+ if (tcp_flow_id != -1)
+ {
+ struct tcp_flow_stat *tflow = (struct tcp_flow_stat *)project_req_get_struct(pstream, tcp_flow_id);
+ tinfo->C2S_pkt_num = tflow->C2S_all_pkt;
+ tinfo->S2C_pkt_num = tflow->S2C_all_pkt;
+ tinfo->C2S_bytes = tflow->C2S_all_byte;
+ tinfo->S2C_bytes = tflow->S2C_all_byte;
+ }
+ }
+ }
+
return DEFAULT_RETURN_VALUE;
+
+error_drop:
+#if ENABLE_COUNT_THREAD
+ error_count[thread_seq]++;
+#endif
+ free(tinfo);
+ return APP_STATE_DROPME | APP_STATE_DROPPKT;
}
-static int tcp_flow_id = -1;
+
char TCP_ENTRY(struct streaminfo *pstream, void **pme, int thread_seq, const void *raw_pkt)
{
struct tcpdetail *raw_pdetail = (struct tcpdetail *)pstream->pdetail;