//to compile use the command g++ -Wall sqngen.c -lgsl -lgslcblas -o sqngen //syntax: // sqngen num_of_samples length gmin_max loss_4state p13 p31 [p32 p23 [p14]] //OR sqngen num_of_samples length gmin_max loss_GI [ploss [burst_length [density [pisol [good_burst_length]]]] //OR sqngen num_of_samples length gmin_max loss_bern_4s p //OR sqngen num_of_samples length gmin_max loss_gilb_4s p r [1-h] //OR sqngen num_of_samples length gmin_max loss_gilb_ell_4s p r [1-h [1-k]] //OR sqngen num_of_samples length gmin_max loss_gilb p r [1-h] //OR sqngen num_of_samples length gmin_max loss_gilb_ell p r [1-h [1-k]] //p13 p31 p32 p23 p14 ploss density pisol p r 1-k 1-h are percentage //num_of_samples length gmin_max burst_length good_burst_length are integer // //This program is free software; you can redistribute it and/or //modify it under the terms of the GNU General Public License //s published by the Free Software Foundation; either version //2 of the License, or (at your option) any later version. // //Author: Fabio Ludovici //Version 2.4 //January 2010 // //This program was used to test the loss generation algorithms implemented in Netem2 //available at http://netgroup.uniroma2.it/twiki/bin/view.cgi/Main/NetEm2 #include #include #include #include #include #include #include #include #include #include #ifdef WIN32 #include #define sleep(a) Sleep(a * 1000) #endif #define ONE 4294967295u #include using std::fixed; #include using namespace std; double p31; double p13; double p23=1; double p32=0; double p14=0; double p; double r; double h; double k; double burst_length; double good_burst_length; double rho; double rho_min; double pisol; double ploss; void arg_error() { printf("Error: too few arguments\n"); printf("Syntax is: sqngen num_of_samples length gmin_max loss_4state p13 p31 [p32 p23 p14]\n"); printf("or sqngen num_of_samples length gmin_max loss_GI ploss [burst_length [density [pisol [good_burst_length]]]]\n"); printf("or sqngen num_of_samples length gmin_max loss_bern_4s p\n"); printf("or sqngen num_of_samples length gmin_max loss_gilb_4s p r [1-h]\n"); printf("or sqngen num_of_samples length gmin_max loss_gilb_ell_4s p r [1-h [1-k]]\n"); printf("or sqngen num_of_samples length gmin_max loss_gilb p r [1-h]\n"); printf("or sqngen num_of_samples length gmin_max loss_gilb_ell p r [1-h [1-k]]\n"); printf("p13 p31 p32 p23 p14 ploss density pisol p r 1-k 1-h are percentage\n"); printf("num_of_samples length gmin_man burst_length good_burst_length are integer\n"); } void sqn_gen(gsl_rng * q, FILE *out_file, char* sequence, int length, double p13, double p31, double p32, double p23, double p14) { double GI_random; int state=1; int tags=0; //if(length>0) printf("The sequence is:\n"); gsl_rng_set(q, time(NULL)); for (int i=0;i<(length+tags);i++) { GI_random=gsl_rng_get(q); GI_random=GI_random/ONE; switch (state) { case 1: sequence[i]=0; //printf("0"); fprintf(out_file, "1\n"); if((00) printf("The sequence is:\n"); gsl_rng_set(q, time(NULL)); for (int i=0;i<(length+tags);i++) { switch (state) { case 1: gilb_ell_random=gsl_rng_get(q); gilb_ell_random=gilb_ell_random/ONE; if(gilb_ell_random<(1-k)) { sequence[i]=1; printf("1"); } else { sequence[i]=0; printf("0"); } gilb_ell_random=gsl_rng_get(q); gilb_ell_random=gilb_ell_random/ONE; if(gilb_ell_random0) mean_length_of_burst_bis[sample]=(double) length_of_all_bursts_bis/num_of_bursts_bis; else mean_length_of_burst_bis[sample]=0; if (num_of_good_bursts_bis>0) mean_length_of_good_burst_bis[sample]=(double) length_of_all_good_bursts_bis/num_of_good_bursts_bis; else mean_length_of_good_burst_bis[sample]=0; density_bis[sample]=100*(double) num_of_burst_drops_bis/length_of_all_bursts_bis; printf("P_loss %.3f%% Mean_length_of_burst %.3f Density %.3f%% P_isol %.3f%% Mean_length_of_good_burst %.3f\n", ploss_bis[sample], mean_length_of_burst_bis[sample], density_bis[sample], pisolated_loss_bis[sample], mean_length_of_good_burst_bis[sample]); fstream data; data.open("data.dat", ios::out | ios::app); data<0) mean_length_of_burst_ter[sample*j+i-1]=(double) length_of_all_bursts_ter/num_of_bursts_ter; else mean_length_of_burst_ter[sample*j+i-1]=0; if (num_of_good_bursts_ter>0) mean_length_of_good_burst_ter[sample*j+i-1]=(double) length_of_all_good_bursts_ter/num_of_good_bursts_ter; else mean_length_of_good_burst_ter[sample*j+i-1]=0; density_ter[sample*j+i-1]=100*(((double)num_of_burst_drops_ter)/((double)length_of_all_bursts_ter)); printf("P_loss %.3f%% Mean_length_of_burst %.3f Density %.3f%% P_isol %.3f%% Mean_length_of_good_burst %.3f\n", ploss_ter[sample*j+i-1], mean_length_of_burst_ter[sample*j+i-1], density_ter[sample*j+i-1], pisolated_loss_ter[sample*j+i-1], mean_length_of_good_burst_ter[sample*j+i-1]); fstream data; data.open("data.dat", ios::out | ios::app); data<0) pisolated_loss_cx=pisolated_loss_stddev/pisolated_loss_mean; else pisolated_loss_cx=0; mean_length_of_good_burst_cx=mean_length_of_good_burst_stddev/mean_length_of_good_burst_mean; printf("ploss %.3f mean_length_on_burst %.3f density %.3f pisol %.3f mean_length_of_good_burst %.3f\n", ploss_cx, mean_length_of_burst_cx, density_cx, pisolated_loss_cx, mean_length_of_good_burst_cx); fstream data; data.open(filename, ios::out | ios::app); data <<"Average Prob. Loss; Average Burst Length; Average Density; Average Prob. Loss Isol.; Average Good Burst Length;\n"; data<7 && (atof(argv[6])+atof(argv[7])>100)) {printf("\nError: p31+p32>100\n"); return 0;} if (argc>9 && (atof(argv[5])+atof(argv[9])>100)) {printf("\nError: p13+p14>100\n"); return 0;} p13=atof(argv[5])/100; p31=atof(argv[6])/100; if (argc>7) p32=atof(argv[7])/100; else p32=0; if (argc>8) p23=atof(argv[8])/100; else p23=1; if (argc>9) p14=atof(argv[9])/100; else p14=0; } else if (strcmp (argv[4],"loss_GI") == 0) { if (argc<6) { arg_error(); return 0; } /* Change here to get a 0.1% resolution */ //ploss=(double) atof(argv[5])/100; ploss=(double) atof(argv[5])/1000; if (ploss==0) { printf("\nError: ploss=0\n"); return 0; } if (argc>8 && (atof(argv[8])>atof(argv[5]))) { printf("\nError: pisol>ploss\n"); return 0; } if (argc>9 && (atof(argv[9])>atof(argv[6]))) { printf("\nError: good_burst_length>burst_length\n"); return 0; } if (argc>6) burst_length=atof(argv[6]); else burst_length=1/(1-ploss); if (argc>7) rho=atof(argv[7])/100; else rho=1; if (argc>8) pisol=atof(argv[8])/100; if (argc>9) good_burst_length=atoi(argv[9]); else good_burst_length=0; p13=(pisol-ploss)/(burst_length*(pisol*(rho-1)-rho+ploss)); p31=1/(burst_length*rho); if (rho<1) { if (good_burst_length>0) { p23=(1/good_burst_length); p32=(1-rho)/(rho*good_burst_length); } else { p32=(1+rho*rho*burst_length-rho-burst_length*rho)/(rho-rho*burst_length); p23=(burst_length*rho-1)/(burst_length-1); } } else { p32=0; p23=1; } if (pisol>0) p14=(double) pisol/(1-pisol); else p14=0; } else if (strcmp (argv[4],"loss_gilb_4s") == 0) { if (argc<7) { arg_error(); return 0; } p=(atof(argv[5]))/100; r=(atof(argv[6]))/100; if(argv[7]) h=1-((atof(argv[7]))/100); else h=0; ploss=(p-h*p)/(p+r); burst_length=(1-h+r*r*h)/(r*(1-h+r*h)); if(argv[7]) rho=((1-h+r*h)*(1-h+r*h)) / (1-h+r*r*h); else rho=1; p13=(-ploss)/(burst_length*(-rho+ploss)); p31=1/(burst_length*rho); if (rho<1) { p32=(1+rho*rho*burst_length-rho-burst_length*rho)/(rho-rho*burst_length); p23=(burst_length*rho-1)/(burst_length-1); } else { p32=0; p23=1; } p14=0; } else if (strcmp (argv[4],"loss_gilb_ell_4s") == 0) { if (argc<7) { arg_error(); return 0; } p=(atof(argv[5]))/100; r=(atof(argv[6]))/100; if(argv[7]) h=1-((atof(argv[7]))/100); else h=0; if(argv[8]) k=1-((atof(argv[8]))/100); else k=1; ploss=(r-k*r+p-h*p)/(p+r); burst_length=(1-h+r*r*h)/(r*(1-h+r*h)); if(argv[7]) rho=((1-h+r*h)*(1-h+r*h)) / (1-h+r*r*h); else rho=1; if(argv[8]) pisol=(r-k*r)/(p+r); else pisol=0; p13=(pisol-ploss)/(burst_length*(pisol*(rho-1)-rho+ploss)); p31=1/(burst_length*rho); if (argv[7]) { p32=(1+rho*rho*burst_length-rho-burst_length*rho) / (rho-rho*burst_length); p23=(burst_length*rho-1) / (burst_length-1); } else p32=0; if (pisol>0) p14=pisol/(1-pisol); else p14=0; } else if (strcmp (argv[4],"loss_bern") == 0) { p=atof(argv[5])/100; r=1-p; h=0; k=1; } else if (strcmp (argv[4],"loss_gilb") == 0) { if (argc<7) { arg_error(); return 0; } p=atof(argv[5])/100; r=atof(argv[6])/100; if(argc>7) { h=1-((atof(argv[7]))/100); k=0; } else { h=0; k=1; } } else if (strcmp (argv[4],"loss_gilb_ell") == 0) { if (argc<7) { arg_error(); return 0; } p=atof(argv[5])/100; r=atof(argv[6])/100; if(argc>7){ h=1-((atof(argv[7]))/100); k=0; } else { h=0; k=1; } if(argc>8) { h=1-((atof(argv[7]))/100); k=1-((atof(argv[8]))/100); } else { k=1; } } char sequence[2*length]; double ploss_bis[num_of_samples]; double pisolated_loss_bis[num_of_samples]; double mean_length_of_burst_bis[num_of_samples]; double density_bis[num_of_samples]; double mean_length_of_good_burst_bis[num_of_samples];// good burst length double ploss_ter[num_of_samples*gmin_max]; double pisolated_loss_ter[num_of_samples*gmin_max]; double mean_length_of_burst_ter[num_of_samples*gmin_max]; double density_ter[num_of_samples*gmin_max]; double mean_length_of_good_burst_ter[num_of_samples]; // good burst length gsl_rng * q=gsl_rng_alloc (gsl_rng_taus2); data.open("data.dat", ios::out); data << "Sample; Num of Samples; Legth; Model; PLoss; BurstLegth"; data.close(); for (int sample=0;sample0) { internal_check(length, sequence, sample, ploss_bis, mean_length_of_burst_bis, density_bis, pisolated_loss_bis, mean_length_of_good_burst_bis ); if (gmin_max>0) external_blind_check (length, gmin_max, sequence, sample, ploss_ter, mean_length_of_burst_ter, density_ter, pisolated_loss_ter, mean_length_of_good_burst_ter); } } if (num_of_samples>1) { char filename[100]; sprintf(filename,"%s_P%d_B%d_EPStatistics.csv", filename_common, atoi(argv[5]), atoi(argv[6]) ); printf("INTERNAL CHECK STATISTICS\n"); data.open(filename, ios::out); data << "Internal Check Statistics\n"; data << "N Samples; Length of vector; Model;"; if (strcmp (argv[4],"loss_GI") == 0){ data << "PLoss; Burst Legth;\n"; } data <0) && (num_of_samples>1)) { char filename[100]; sprintf(filename,"%s_P%d_B%d_EPStatistics.csv", filename_common, atoi(argv[5]), atoi(argv[6]) ); if (gmin_max>0) printf("\nEXTERNAL CHECK STATISTICS\n"); for (int gmin=2;gmin