64 lines
2.3 KiB
C++
64 lines
2.3 KiB
C++
|
#include <iostream>
|
||
|
#include <iomanip>
|
||
|
#include <fstream>
|
||
|
#include <math.h>
|
||
|
|
||
|
#define MAX_ARRAY_SIZE 1000
|
||
|
|
||
|
using namespace std;
|
||
|
|
||
|
void calculations(float deltaVal, float deviationVal, string outputFileName);
|
||
|
|
||
|
int main(int argc, char const *argv[])
|
||
|
{
|
||
|
// calculate part a
|
||
|
calculations(0.125, 0.500, "P3A.txt");
|
||
|
calculations(0.125, 1.500, "P3B.txt");
|
||
|
calculations(0.25, 0.500, "P3C.txt");
|
||
|
|
||
|
}
|
||
|
|
||
|
void calculations(float deltaVal, float deviationVal, string outputFileName)
|
||
|
{
|
||
|
ofstream outputFile;
|
||
|
outputFile.open(outputFileName.c_str());
|
||
|
// difference = sampleRTT - estimatedRTT
|
||
|
// estimatedRTT = estimatedRTT + (delta * difference)
|
||
|
// deviation = deviation + delta(|difference| - deviation)
|
||
|
// timeOut = mu * estimatedRTT + (phi * deviation)
|
||
|
|
||
|
float delta = 0.0, mu = 0.0, phi = 0.0; //
|
||
|
float difference[MAX_ARRAY_SIZE], estimatedRTT[MAX_ARRAY_SIZE], sampleRTT;
|
||
|
float deviation[MAX_ARRAY_SIZE], timeOut = 0.0, tmpDeviation = 0.0, tmpestimateRTT = 0.0;
|
||
|
// Values for Jacobson/Karels Algorithim
|
||
|
delta = deltaVal;
|
||
|
mu = 1.0;
|
||
|
phi = 4.0;
|
||
|
|
||
|
// do-while loop
|
||
|
int i = 0;
|
||
|
outputFile << "Iteration #\t\tSampleRTT\t\tEstimatedRTT\t\t Deviation\t\tDifference\t\tTimeout\n";
|
||
|
do
|
||
|
{
|
||
|
// initial values
|
||
|
if (i == 0)
|
||
|
{
|
||
|
outputFile << fixed << setprecision(4);
|
||
|
estimatedRTT[0] = 4.000;
|
||
|
deviation[0] = deviationVal;
|
||
|
outputFile << i << "\t\t\t\t - \t\t\t\t\t" << estimatedRTT[0] << "\t\t\t\t" << deviation[0] << "\t\t\t - \t\t\t - \n";
|
||
|
i++;
|
||
|
}
|
||
|
sampleRTT = 1.0000;
|
||
|
difference[i] = sampleRTT - estimatedRTT[i-1];
|
||
|
// calculate estimatedRTT again
|
||
|
estimatedRTT[i] = estimatedRTT[i-1] + (delta * difference[i]);
|
||
|
deviation[i] = deviation[i-1] + delta*(fabs(difference[i]) - deviation[i-1]);
|
||
|
timeOut = mu * estimatedRTT[i] + (phi * deviation[i]);
|
||
|
// "Iteration #\t\tSampleRTT\t\tEstimatedRTT\t\tDeviation\t\tTimeout\n"
|
||
|
outputFile << i << "\t\t\t\t" << setw(5) << setfill(' ') << sampleRTT << setw(10) << setfill(' ') << "\t\t" << estimatedRTT[i] << setw(8) << setfill(' ') <<
|
||
|
"\t\t" << deviation[i] << setw(3) << setfill(' ') << "\t\t" << difference[i] << setw(8) << setfill(' ') << "\t" << timeOut << endl;
|
||
|
i++;
|
||
|
} while (timeOut > 4.0);
|
||
|
outputFile.close();
|
||
|
}
|