From 74e088d3839ca5159dddea000e9aee70cf3a0c76 Mon Sep 17 00:00:00 2001 From: wangyu- Date: Tue, 17 Oct 2017 05:20:30 -0500 Subject: [PATCH] implemented output_delay,more options --- delay_manager.cpp | 2 +- fec_manager.cpp | 5 +- fec_manager.h | 9 ++++ main.cpp | 133 ++++++++++++++++++++++++++++++++++++---------- makefile | 2 +- packet.h | 2 + 6 files changed, 122 insertions(+), 31 deletions(-) diff --git a/delay_manager.cpp b/delay_manager.cpp index 24e5da5..0b16cdf 100644 --- a/delay_manager.cpp +++ b/delay_manager.cpp @@ -67,7 +67,7 @@ int delay_manager_t::add(my_time_t delay,const dest_t &dest,char *data,int len) delay_data_t tmp=delay_data; tmp.data=(char *)malloc(delay_data.len+100); - memcpy(tmp.data,delay_data.data,delay_data.len); + memcpy(tmp.data,data,delay_data.len); my_time_t tmp_time=get_current_time_us(); tmp_time+=delay; diff --git a/fec_manager.cpp b/fec_manager.cpp index 97949bd..2e3583e 100644 --- a/fec_manager.cpp +++ b/fec_manager.cpp @@ -165,7 +165,8 @@ int fec_encode_manager_t::append(char *s,int len/*,int &is_first_packet*/) { itimerspec its; memset(&its.it_interval,0,sizeof(its.it_interval)); - my_time_t tmp_time=fec_pending_time+get_current_time_us(); + first_packet_time=get_current_time_us(); + my_time_t tmp_time=fec_pending_time+first_packet_time; its.it_value.tv_sec=tmp_time/1000000llu; its.it_value.tv_nsec=(tmp_time%1000000llu)*1000llu; timerfd_settime(timer_fd,TFD_TIMER_ABSTIME,&its,0); @@ -369,6 +370,7 @@ int fec_encode_manager_t::input(char *s,int len/*,int &is_first_packet*/) //mylog(log_trace,"!!! s= %d\n"); assert(ready_for_output==0); ready_for_output=1; + first_packet_time_for_output=first_packet_time; seq++; counter=0; output_n=actual_data_num+actual_redundant_num; @@ -409,6 +411,7 @@ int fec_encode_manager_t::input(char *s,int len/*,int &is_first_packet*/) int buf_idx=counter-1; assert(ready_for_output==0); ready_for_output=1; + first_packet_time_for_output=0; output_n=1; int tmp_idx=0; diff --git a/fec_manager.h b/fec_manager.h index 2029809..a275659 100644 --- a/fec_manager.h +++ b/fec_manager.h @@ -103,6 +103,10 @@ private: int fec_pending_num; int fec_pending_time; + my_time_t first_packet_time; + my_time_t first_packet_time_for_output; + + blob_encode_t blob_encode; char input_buf[max_fec_packet_num+5][buf_len]; int input_len[max_fec_packet_num+100]; @@ -124,6 +128,11 @@ public: fec_encode_manager_t(); ~fec_encode_manager_t(); + int get_first_packet_time() + { + return first_packet_time_for_output; + } + u64_t get_timer_fd64(); int re_init(int data_num,int redundant_num,int mtu,int pending_num,int pending_time,int type); int input(char *s,int len/*,int &is_first_packet*/); diff --git a/main.cpp b/main.cpp index 9d2df64..919a3db 100644 --- a/main.cpp +++ b/main.cpp @@ -16,12 +16,11 @@ typedef long long i64_t; typedef unsigned int u32_t; typedef int i32_t; -int dup_num=1; -int dup_delay_min=20; //0.1ms -int dup_delay_max=20; +//int dup_num=1; +//int dup_delay_min=20; //0.1ms +//int dup_delay_max=20; + -int jitter_min=0; -int jitter_max=0; //int random_number_fd=-1; @@ -36,9 +35,17 @@ int fec_data_num=20; int fec_redundant_num=10; int fec_mtu=1250; int fec_pending_num=200; -int fec_pending_time=10000; //10ms +int fec_pending_time=10*1000; //10ms int fec_type=0; +int jitter_min=0*1000; +int jitter_max=0*1000; + +int output_interval_min=0*1000; +int output_interval_max=0*1000; + +int fix_latency=1; + u32_t local_ip_uint32,remote_ip_uint32=0; char local_ip[100], remote_ip[100]; int local_port = -1, remote_port = -1; @@ -50,6 +57,7 @@ conn_manager_t conn_manager; delay_manager_t delay_manager; fd_manager_t fd_manager; +int time_mono_test=1; const int disable_conv_clear=0; @@ -118,7 +126,7 @@ int new_connected_socket(int &fd,u32_t ip,int port) } int delay_send(my_time_t delay,const dest_t &dest,char *data,int len) { - int rand=random()%100; + //int rand=random()%100; //mylog(log_info,"rand = %d\n",rand); if (dest.cook&&random_drop != 0) { @@ -128,12 +136,12 @@ int delay_send(my_time_t delay,const dest_t &dest,char *data,int len) } return delay_manager.add(delay,dest,data,len);; } -int from_normal_to_fec(conn_info_t & conn_info,char *data,int len,int & out_n,char **&out_arr,int *&out_len,int *&out_delay) +int from_normal_to_fec(conn_info_t & conn_info,char *data,int len,int & out_n,char **&out_arr,int *&out_len,my_time_t *&out_delay) { - static int out_delay_buf[max_fec_packet_num+100]={0}; + static my_time_t out_delay_buf[max_fec_packet_num+100]={0}; //static int out_len_buf[max_fec_packet_num+100]={0}; - static int counter=0; + //static int counter=0; out_delay=out_delay_buf; //out_len=out_len_buf; @@ -147,10 +155,11 @@ int from_normal_to_fec(conn_info_t & conn_info,char *data,int len,int & out_n,ch len_static=len; out_arr=&data_static; out_len=&len_static; + out_delay[0]=0; } else { - counter++; + //counter++; conn_info.fec_encode_manager.input(data,len); @@ -164,9 +173,30 @@ int from_normal_to_fec(conn_info_t & conn_info,char *data,int len,int & out_n,ch conn_info.fec_encode_manager.output(out_n,out_arr,out_len); - for(int i=0;i0) { - out_delay_buf[i]=0; + my_time_t common_latency=0; + my_time_t first_packet_time=conn_info.fec_encode_manager.get_first_packet_time(); + my_time_t current_time=get_current_time_us(); + if(fix_latency==1&&first_packet_time!=0) + { + my_time_t tmp; + if((my_time_t)fec_pending_time >=(current_time - first_packet_time)) + { + tmp=(my_time_t)fec_pending_time-(current_time - first_packet_time); + } + else tmp=0; + common_latency+=tmp; + } + + common_latency+=random_between(jitter_min,jitter_max); + + out_delay_buf[0]=common_latency; + + for(int i=1;i key for simple xor encryption,default:\"secret key\"\n"); printf("main options:\n"); - printf(" -d duplicated packet number, -d 0 means no duplicate. default value:0\n"); - printf(" -t duplicated packet delay time, unit: 0.1ms,default value:20(2ms)\n"); + //printf(" -d duplicated packet number, -d 0 means no duplicate. default value:0\n"); + //printf(" -t duplicated packet delay time, unit: 0.1ms,default value:20(2ms)\n"); printf(" -j simulated jitter.randomly delay first packet for 0~jitter_value*0.1 ms,to\n"); printf(" create simulated jitter.default value:0.do not use if you dont\n"); printf(" know what it means\n"); printf(" --report turn on udp send/recv report,and set a time interval for reporting,unit:s\n"); printf("advanced options:\n"); - printf(" -t tmin:tmax simliar to -t above,but delay randomly between tmin and tmax\n"); + //printf(" -t tmin:tmax simliar to -t above,but delay randomly between tmin and tmax\n"); printf(" -j jmin:jmax simliar to -j above,but create jitter randomly between jmin and jmax\n"); printf(" --random-drop simulate packet loss ,unit:0.01%%\n"); - printf(" --disable-filter disable duplicate packet filter.\n"); - printf(" -m max pending packets,to prevent the program from eating up all your memory,\n"); - printf(" default value:0(disabled).\n"); + //printf(" --disable-filter disable duplicate packet filter.\n"); + //printf(" -m max pending packets,to prevent the program from eating up all your memory,\n"); + //printf(" default value:0(disabled).\n"); printf("other options:\n"); printf(" --log-level 0:never 1:fatal 2:error 3:warn \n"); printf(" 4:info (default) 5:debug 6:trace\n"); @@ -1129,6 +1159,9 @@ void process_arg(int argc, char *argv[]) {"log-position", no_argument, 0, 1}, {"disable-color", no_argument, 0, 1}, {"disable-filter", no_argument, 0, 1}, + {"disable-fec", no_argument, 0, 1}, + {"disable-obs", no_argument, 0, 1}, + {"disable-xor", no_argument, 0, 1}, {"sock-buf", required_argument, 0, 1}, {"random-drop", required_argument, 0, 1}, {"report", required_argument, 0, 1}, @@ -1193,7 +1226,7 @@ void process_arg(int argc, char *argv[]) } int no_l = 1, no_r = 1; - while ((opt = getopt_long(argc, argv, "l:r:d:t:hcsk:j:m:f:p:n:",long_options,&option_index)) != -1) + while ((opt = getopt_long(argc, argv, "l:r:d:t:hcsk:j:m:f:p:n:i:",long_options,&option_index)) != -1) { //string opt_key; //opt_key+=opt; @@ -1230,6 +1263,8 @@ void process_arg(int argc, char *argv[]) } jitter_min=0; jitter_max=jitter; + + } else { @@ -1240,6 +1275,32 @@ void process_arg(int argc, char *argv[]) myexit(-1); } } + jitter_min*=100; + jitter_max*=100; + break; + case 'i': + if (strchr(optarg, ':') == 0) + { + int output_interval=-1; + sscanf(optarg,"%d\n",&output_interval); + if(output_interval<0||output_interval>1000*100) + { + mylog(log_fatal,"output_interval must be between 0 and 100,000(10 second)\n"); + myexit(-1); + } + output_interval_min=output_interval_max=output_interval; + } + else + { + sscanf(optarg,"%d:%d\n",&output_interval_min,&output_interval_max); + if(output_interval_min<0 ||output_interval_max<0||output_interval_min>output_interval_max) + { + mylog(log_fatal," must satisfy 0<=output_interval_min<=output_interval_max\n"); + myexit(-1); + } + } + output_interval_min*=100; + output_interval_max*=100; break; case 'f': if (strchr(optarg, ':') == 0) @@ -1356,6 +1417,22 @@ void process_arg(int argc, char *argv[]) { //enable_log_color=0; } + else if(strcmp(long_options[option_index].name,"disable-fec")==0) + { + disable_fec=1; + } + else if(strcmp(long_options[option_index].name,"disable-obs")==0) + { + disable_obscure=1; + } + else if(strcmp(long_options[option_index].name,"disable-xor")==0) + { + disable_xor=1; + } + else if(strcmp(long_options[option_index].name,"disable-filter")==0) + { + disable_replay_filter=1; + } else if(strcmp(long_options[option_index].name,"log-position")==0) { enable_log_position=1; diff --git a/makefile b/makefile index 6ab131a..43f0864 100755 --- a/makefile +++ b/makefile @@ -6,7 +6,7 @@ cc_mips24kc_le=/toolchains/lede-sdk-17.01.2-ramips-mt7621_gcc-5.4.0_musl-1.1.16. #cc_arm= /toolchains/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabi/bin/arm-linux-gnueabi-g++ -march=armv6 -marm cc_arm= /toolchains/arm-2014.05/bin/arm-none-linux-gnueabi-g++ #cc_bcm2708=/home/wangyu/raspberry/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-g++ -FLAGS= -std=c++11 -Wall -Wextra -Wno-unused-variable -Wno-unused-parameter -Wno-missing-field-initializers +FLAGS= -std=c++11 -Wall -Wextra -Wno-unused-variable -Wno-unused-parameter -Wno-missing-field-initializers -ggdb SOURCES=main.cpp log.cpp common.cpp lib/fec.c lib/rs.c packet.cpp delay_manager.cpp fd_manager.cpp connection.cpp fec_manager.cpp diff --git a/packet.h b/packet.h index e674ad9..35d1010 100644 --- a/packet.h +++ b/packet.h @@ -22,6 +22,8 @@ extern char key_string[1000]; extern int disable_replay_filter; extern int random_drop; extern int local_listen_fd; +extern int disable_obscure; +extern int disable_xor; int my_send(const dest_t &dest,char *data,int len);