63 lines
2.2 KiB
C++
63 lines
2.2 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 = 0.0, estimatedRTT = 0.0, sampleRTT = 0.0;
|
||
|
float deviation = 0.0, 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 = 4.000;
|
||
|
deviation = deviationVal;
|
||
|
outputFile << i << "\t\t\t\t - \t\t\t\t\t" << estimatedRTT << "\t\t\t\t" << deviation << "\t\t\t - \t\t\t - \n";
|
||
|
i++;
|
||
|
}
|
||
|
sampleRTT = 1.0000;
|
||
|
difference = sampleRTT - estimatedRTT;
|
||
|
// calculate estimatedRTT again
|
||
|
estimatedRTT = estimatedRTT + (delta * difference);
|
||
|
deviation = deviation + delta*(fabs(difference) - deviation);
|
||
|
timeOut = mu * estimatedRTT + (phi * deviation);
|
||
|
outputFile << i << "\t\t\t\t" << setw(5) << setfill(' ') << sampleRTT << setw(10) << setfill(' ') << "\t\t" << estimatedRTT << setw(8) << setfill(' ') <<
|
||
|
"\t\t" << deviation << setw(3) << setfill(' ') << "\t\t" << difference << setw(8) << setfill(' ') << "\t" << timeOut << endl;
|
||
|
i++;
|
||
|
} while (timeOut > 4.0);
|
||
|
outputFile.close();
|
||
|
}
|