From 3b5d512b7fcccbba52732d8b20238f513ecb4e99 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Tue, 30 Apr 2013 10:57:41 +0100 Subject: [PATCH] Initialization of the GIT repository for the sqngen app --- ErrorPattern_Generator_Script | 33 ++ Makefile | 29 ++ sqnanalyzer.c | 147 +++++++ sqngen.c | 783 ++++++++++++++++++++++++++++++++++ 4 files changed, 992 insertions(+) create mode 100755 ErrorPattern_Generator_Script create mode 100644 Makefile create mode 100644 sqnanalyzer.c create mode 100644 sqngen.c diff --git a/ErrorPattern_Generator_Script b/ErrorPattern_Generator_Script new file mode 100755 index 0000000..bb7c4ba --- /dev/null +++ b/ErrorPattern_Generator_Script @@ -0,0 +1,33 @@ +#!/bin/bash + +#OUTPUT_DIR=ErrorPattern_Ballet_QP20_PCKT3778_N5_P1.1.7_B1.1.5 + +SEQNAME=BookArrivalHEVC +NLOOP=15 +NPACKETS=100 +PLOSS_INI=50 +PLOSS_INC=10 +PLOSS_FIN=50 +BLENGTH_INI=1 +BLENGTH_INC=1 +BLENGTH_FIN=1 + +OUTPUT_DIR="ErrorPattern_"$SEQNAME"_PCKT"$NPACKETS_A"_N"$NLOOP"_P"$PLOSS_INI"-"$PLOSS_INC"-"$PLOSS_FIN"_B"$BLENGTH_INI"-"$BLENGTH_INC"-"$BLENGTH_FIN + +if [ $PLOSS_INC = 0 ]; then + PLOSS_INC=1 +fi + +if [ $PLOSS_INI = 0 ]; then + PLOSS_INI=$PLOSS_INI+$PLOSS_INC +fi + +mkdir $OUTPUT_DIR + +for (( PLOSS=$PLOSS_INI; PLOSS<=$PLOSS_FIN; PLOSS=PLOSS+$PLOSS_INC )) +do + for (( BLENGTH=$BLENGTH_INI; BLENGTH<=$BLENGTH_FIN; BLENGTH=BLENGTH+$BLENGTH_INC )) + do + ./SQNGen $NLOOP $NPACKETS 0 loss_GI $PLOSS $BLENGTH -o $OUTPUT_DIR"/"$SEQNAME + done +done diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..698a6f6 --- /dev/null +++ b/Makefile @@ -0,0 +1,29 @@ +### +### Makefile for GilberModel +### +### +### + + +OUTPUT_DIR := Bin +PROJECTS := sqnanalyzer sqngen + +export DBG +export STC +export M32 +export OPENMP + +.HONY: default all $(PROJECTS) #distclean clean tags dependP + +default: all + +all: $(PROJECTS) + +sqngen: + g++ -Wall sqngen.c -lgsl -lgslcblas -o SQNGen +sqnanalyzer: + g++ -Wall sqnanalyzer.c -o SQNAnalyzer + +clean: + rm SQNGen + rm SQNAnalyzer \ No newline at end of file diff --git a/sqnanalyzer.c b/sqnanalyzer.c new file mode 100644 index 0000000..961a723 --- /dev/null +++ b/sqnanalyzer.c @@ -0,0 +1,147 @@ +// to compile g++ -Wall sqnanalyzer.c -o sqnanalyzer +// +//syntax: +// sqngenanalyzer +// +//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 1.0 final +//July 2009 +// +//This program was used to test the loss generation algorithm implemented in Netem2 +//available at http://netgroup.uniroma2.it/twiki/bin/view.cgi/Main/NetEm2 +// + +#include +#include +#include +#include +#include + +#define UNO 4294967295 + +#include +#include +using namespace std; + +void blind_external_check(int length, int gmin_max, int sequence[], int sample, float *ploss, float *mean_length_of_burst, float *density, float *pisolated_loss, float *mean_length_of_good_burst) { + bool this_is_burst; + int num_of_bursts; + int length_of_all_bursts; + int num_of_good_bursts; + int length_of_all_good_bursts; + int num_of_drops; + int num_of_burst_drops; + int num_of_isolated_drops; + for(int gmin=2;gmin0) + mean_length_of_burst[sample*j+i-1]=(float) length_of_all_bursts/num_of_bursts; + else + mean_length_of_burst[sample*j+i-1]=0; + if (num_of_good_bursts>0) + mean_length_of_good_burst[sample*j+i-1]=(float) length_of_all_good_bursts/num_of_good_bursts; + else + mean_length_of_good_burst[sample*j+i-1]=0; + density[sample*j+i-1]=100*(((float)num_of_burst_drops)/((float)length_of_all_bursts)); + printf("P_loss %.3f%% Mean_length_of_burst %.3f Density %.3f%% P_isol %.3f%% Mean_length_of_good_burst %.3f\n", ploss[sample*j+i-1], mean_length_of_burst[sample*j+i-1], density[sample*j+i-1], pisolated_loss[sample*j+i-1], mean_length_of_good_burst[sample*j+i-1]); + fstream data; + data.open("data.dat", ios::out | ios::app); + data< +//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 + +#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