Commit 28bcfc52 authored by Ulysse Beaugnon's avatar Ulysse Beaugnon

The simulator con now check the resilience

parent 0287dc9a
New log system :
we use the logging module now. There are three levels for log messages :
- info : give basic information about what vifibnet is doing
- debug : display internal work of the script (finished action, detailed
information about tunnels, etc... )
- trace : for intensive debug, display configuration, arguments given to
processes, all information pertinent to debug but not required
mot of the time
Additionally, warning, error and exception can be used.
Note : logging.exception prints informations similar to pdb.set_trace()
info, which is pretty heavy, so for exception we expect ( for
instance, connection problems to the registry ), one can print the
exception as warning. ( see db.refresh() ).
Vifibnet is a daemon setting up a resilient virtual private network over the
internet
......@@ -32,7 +18,8 @@ The organisation of the code
Note: On certain version of python (e.g. 2.7.3~rc2-2.1 ) dns lookup is
performed for each request, and cause a delay in response.
To avoid this, one can either upgrade python, or fix their resolv.conf
To avoid this, one can either upgrade python, fix their resolv.conf or use
the fix at the end of this file.
OPTIONS : REGISTRY.PY
usage : ./registry port [options...]
......@@ -243,7 +230,6 @@ the beggining of registry.py
--------------------------------------------------------------------------------
# Fix for librpcxml to avoid doing reverse dns on each request
# it was causing a 10s delay on each request when no reverse DNS was avalaible
# for tis IP
import BaseHTTPServer
......@@ -254,3 +240,17 @@ def not_insane_address_string(self):
BaseHTTPServer.BaseHTTPRequestHandler.address_string = not_insane_address_string
--------------------------------------------------------------------------------
New log system :
we use the logging module now. There are three levels for log messages :
- info : give basic information about what vifibnet is doing
- debug : display internal work of the script (finished action, detailed
information about tunnels, etc... )
- trace : for intensive debug, display configuration, arguments given to
processes, all information pertinent to debug but not required
mot of the time
Additionally, warning, error and exception can be used.
Note : logging.exception prints informations similar to pdb.set_trace()
info, which is pretty heavy, so for exception we expect ( for
instance, connection problems to the registry ), one can print the
exception as warning. ( see db.refresh() ).
\ No newline at end of file
#include "main.h"
Graph::Graph(int size, int k, int maxPeers, mt19937& generator, const Latency& latency) :
generator(generator), size(size), k(k), maxPeers(maxPeers), latency(latency),
Graph::Graph(int size, int k, int maxPeers, mt19937& rng, const Latency& latency) :
generator(mt19937(rng())), size(size), k(k), maxPeers(maxPeers), latency(latency),
distrib(uniform_int_distribution<int>(0, size-1))
{
adjacency = new unordered_set<int>[size];
......@@ -36,8 +36,9 @@ bool Graph::AddEdge(int from)
for(int i=0; i<50; i++)
{
to = distrib(generator);
if(latency.values[from][to] > 0
&& to != from
if( to != from
&& latency.values[from][to] > 0
&& adjacency[from].count(to) == 0
&& adjacency[to].size() + generated[to].size() <= maxPeers + k)
{
......@@ -218,6 +219,8 @@ double Graph::GetUnAvalaibility()
void Graph::KillMachines(float proportion)
{
size = proportion*size;
distrib = uniform_int_distribution<int>(0, size - 1);
for(int i=0; i<size; i++)
{
vector<int> toBeRemoved;
......@@ -231,4 +234,4 @@ void Graph::KillMachines(float proportion)
adjacency[i].erase(j);
}
}
}
\ No newline at end of file
}
......@@ -30,7 +30,7 @@ void Latency::Rewrite(int n)
int nReachable = 0;
for(int j=0; j<size; j++)
{
if(values[i][j] > 0)
if(j != i && values[i][j] >= 10)
nReachable++;
}
......@@ -47,9 +47,9 @@ void Latency::Rewrite(int n)
file = fopen("latency/pw-1715/rewrite", "w");
for(int i=0; i<size-1; i++)
if(nat[i] != -1)
for(int j=1; j<size; j++)
for(int j=i+1; j<size; j++)
if(nat[j] != -1)
fprintf(file, "%d %d %d\n", nat[i], nat[j], values[i][j]);
fprintf(file, "%d %d %d\n", nat[i], nat[j], values[i][j]>=10?values[i][j]:-1);
fclose(file);
}
......@@ -59,4 +59,33 @@ Latency::~Latency()
for(int i=0; i<size; i++)
delete[] values[i];
delete[] values;
}
double Latency::GetAverageDistance()
{
int size = 1555;
double** distances = new double*[size];
for(int i=0; i<size; i++)
distances[i] = new double[size];
for(int i=0; i<size; i++)
for(int j=0; j<size; j++)
if(i==j)
distances[i][j] = 0;
else if(values[i][j] > 0)
distances[i][j] = values[i][j];
else
distances[i][j] = numeric_limits<double>::infinity();
for(int i=0; i<size; i++)
for(int j=0; j<size; j++)
for(int k=0; k<size; k++)
distances[i][j] = min(distances[i][j], distances[i][k] + distances[k][j]);
double avg = 0;
for(int i=0; i<size; i++)
for(int j=0; j<size; j++)
avg += distances[i][j];
return avg / (size*size);
}
\ No newline at end of file
// To compile : g++ -std=c++0x results.cpp graph.cpp main.cpp -lpthread
// To compile : g++ -std=c++0x latency.cpp graph.cpp main.cpp -lpthread
// The best distance : 66.9239 with a full graph
#include "main.h"
void simulate(int size, int k, int maxPeer, int seed, const Latency& latency, const char* outName)
{
mt19937 rng(seed);
FILE* output = fopen(outName, "wt");
int fno = fileno(output);
fprintf(output, "round,alive,unreachable\n");
mt19937 rng(seed);
Graph graph(size, k, maxPeer, rng, latency);
cout << "\r" << 0 << "/" << 300;
......@@ -19,7 +22,7 @@ void simulate(int size, int k, int maxPeer, int seed, const Latency& latency, co
{
Graph copy(graph);
copy.KillMachines(a);
fprintf(output, "%d,%f,%f\n",i, a , copy.GetUnAvalaibility());
fprintf(output, "%d,%f,%f\n",i , a , copy.GetUnAvalaibility());
fflush(output);
fsync(fno);
}
......@@ -28,6 +31,14 @@ void simulate(int size, int k, int maxPeer, int seed, const Latency& latency, co
double avgDistance, unreachable;
double arityDistrib[31];
graph.UpdateLowRoutes(avgDistance, unreachable, arityDistrib);
/*fprintf(output, "%d,%f", i, avgDistance);
for(int j=0; j<=30; j++)
fprintf(output, ",%f", arityDistrib[j]);
fprintf(output, "\n");
fflush(output);
fsync(fno);*/
cout << "\r" << i+1 << "/" << 300;
cout.flush();
}
......@@ -39,13 +50,13 @@ void simulate(int size, int k, int maxPeer, int seed, const Latency& latency, co
int main(int argc, char** argv)
{
mt19937 rng(time(NULL));
//Latency latency("latency/pw-1715/pw-1715-latencies", 1715);
//latency.Rewrite(20);
Latency latencyR("latency/pw-1715/pw-1715-latencies", 1715);
latencyR.Rewrite(20);
Latency latency("latency/pw-1715/rewrite", 1555);
vector<future<void>> threads;
for(int i=0; i<8; i++)
for(int i=0; i<20; i++)
{
int seed = rng();
char* out = new char[20];
......@@ -54,7 +65,7 @@ int main(int argc, char** argv)
{ simulate(1555, 10, 30, seed, latency, out); delete[] out; }));
}
for(int i=0; i<8; i++)
for(int i=0; i<1; i++)
threads[i].get();
return 0;
......
......@@ -7,6 +7,7 @@
#include <future>
#include <sstream>
#include <unistd.h>
#include <limits>
using namespace std;
......@@ -17,6 +18,7 @@ public:
Latency(const char* filePath, int size);
void Rewrite(int n);
~Latency();
double GetAverageDistance();
int** values;
private:
......@@ -40,7 +42,7 @@ private:
void GetRoutesFrom(int from, int* nRoutes, int* prevs, int* distances);
int CountUnreachableFrom(int node);
mt19937& generator;
mt19937 generator;
uniform_int_distribution<int> distrib;
int maxPeers;
int k;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment