Skip to content

Commit

Permalink
Some simulation results and scripts, also commented out many messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kwoalk committed Jun 22, 2019
1 parent e2adb30 commit cef13d3
Show file tree
Hide file tree
Showing 75 changed files with 10,565 additions and 22 deletions.
3 changes: 2 additions & 1 deletion Sample3/Sample3/Base.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

#include "stdafx.h"

#define bigFifo 1000000
//#define bigFifo 1000000
#define bigFifo 10000

extern double taprocessk;
extern double taprocesslb;
Expand Down
8 changes: 4 additions & 4 deletions Sample3/Sample3/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void Config::ParseConfig(std::string fileName)
value = "";
}
ConfigStorage[key] = value;
cout << "Trace,Config,key " << key << " = value " << value << endl;
//### cout << "Trace,Config,key " << key << " = value " << value << endl;
}
}
file.close();
Expand Down Expand Up @@ -67,7 +67,7 @@ int Config::getValue(std::string key)
else
{
int res = std::stoi(it->second);
cout << "Trace,Config,int " << key << " is " << res << endl;
//### cout << "Trace,Config,int " << key << " is " << res << endl;
return res;
}
}
Expand All @@ -83,7 +83,7 @@ std::string Config::getValue(std::string key)
}
else
{
cout << "Trace,Config,string " << key << " is " << it->second << endl;
//### cout << "Trace,Config,string " << key << " is " << it->second << endl;
return it->second;
}
}
Expand All @@ -100,7 +100,7 @@ double Config::getValue(std::string key)
else
{
double res = std::stod(it->second);
cout << "Trace,Config,double " << key << " is " << res << endl;
//### cout << "Trace,Config,double " << key << " is " << res << endl;
return res;
}
}
6 changes: 6 additions & 0 deletions Sample3/Sample3/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

#define cnf_voteTime "voteTime"
#define cnf_rqV "rqVotes"
#define cnf_dumpVotes "dumpVotes"

#define cnf_stopAtWinners "stopAtWinners"

#define cnf_W "W"
#define cnf_S1 "S1"
Expand Down Expand Up @@ -56,6 +59,9 @@ struct Config

{ "voteTime", { "40000000", "âðåìÿ äî î÷åðåäíîãî ãîëîñà (çà ñëó÷àéíûé óçåë)" } },
{ "rqVotes", { "50", "íåîáõîäèìîå äëÿ ïîáåäû ÷èñëî ãîëîñîâ" } },
{ "dumpVotes", { "0", "ïîäðîáíîñòü âûäà÷è ñïèñêà ïîäàííûõ ãîëîñîâ è ñòàòèñòèêè" } },

{ "stopAtWinners", { "5", "îñòàíîâèòü ñèìóëÿöèþ, êîãäà äîñòèãíóòî óêàçàííîå ÷èñëî ïîáåäèòåëåé" } },

{ "W", { "0", "íîìåð óçëà W" } },
{ "S1", { "1", "íîìåð óçëà S1" } },
Expand Down
20 changes: 13 additions & 7 deletions Sample3/Sample3/Mnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void Mnode::main()
{
sent_votes = true;
double totalDelay = 0;
for (int i = 0; i < cc->Rnum; ++i)
for (int i = 0; i < cc->rndNum; ++i)
{
totalDelay += latNode.nextVoteLat();
int vote = latNode.nextVote();
Expand Down Expand Up @@ -202,16 +202,22 @@ void Mnode::ProcessBlock(routing_block& rb, double xdelay)
int sz = cc->Votes[number].size();
if (sz == cc->currMaxVotes)
{
cout << "Tie," << sc_time_stamp() << ",Mnode," << name() << ",got " << cc->Votes[number].size() << " votes (last vote was from " << rb.R << ")" << endl;
//### cout << "Tie," << sc_time_stamp() << ",Mnode," << name() << ",got " << cc->Votes[number].size() << " votes (last vote was from " << rb.R << ")" << endl;
}
else if (sz > cc->currMaxVotes)
{
cc->currMaxVotes = sz;
cout << "MAX," << sc_time_stamp() << ",Mnode," << name() << ",got " << cc->Votes[number].size() << " votes (last vote was from " << rb.R << ")" << endl;
//### cout << "MAX," << sc_time_stamp() << ",Mnode," << name() << ",got " << cc->Votes[number].size() << " votes (last vote was from " << rb.R << ")" << endl;
}
if (sz == cc->rqVotes)
{
cout << "Success," << sc_time_stamp() << ",Mnode," << name() << ",got " << cc->Votes[number].size() << " votes (last vote was from " << rb.R << ")" << endl;
//### cout << "Success," << sc_time_stamp() << ",Mnode," << name() << ",got " << cc->Votes[number].size() << " votes (last vote was from " << rb.R << ")" << endl;
cc->winTimes[cc->currWinners] = sc_time_stamp().value();
++(cc->currWinners);
if (cc->currWinners == cc->stopWinners)
{
sc_stop(); // !!!
}
}
}
else
Expand Down Expand Up @@ -318,10 +324,10 @@ void Mnode::InitializeFingers()
fingers.push_back(j);
}
fingerM = (int)fingers.size();
cout << "Trace,0,Mnode," << name() << ",fingerM = " << fingerM << "; fingers: ";
//### cout << "Trace,0,Mnode," << name() << ",fingerM = " << fingerM << "; fingers: ";
for (const auto i : fingers)
cout << i << " ";
cout << endl;
; //### cout << i << " ";
//### cout << endl;
}

void Mnode::ForwardBlock(routing_block& rb, double xdelay)
Expand Down
8 changes: 7 additions & 1 deletion Sample3/Sample3/Sample3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,14 @@ int sc_main(int argc, char *argv[])
int k = confInt(cnf_k);
int r = confInt(cnf_r);
int rqV = confInt(cnf_rqV);
int dV = confInt(cnf_dumpVotes);
int sAW = confInt(cnf_stopAtWinners);
if (sAW < 0)
{
sAW = n;
}

WSA wsa("WSA", n, k*n, confInt(cnf_W), confInt(cnf_S1), confInt(cnf_Sleader), n, r, rqV);
WSA wsa("WSA", n, k*n, confInt(cnf_W), confInt(cnf_S1), confInt(cnf_Sleader), n, r, rqV, dV, sAW);

double Ttr = 1000e9;
if (Ttr > 0)
Expand Down
54 changes: 49 additions & 5 deletions Sample3/Sample3/Top.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "stdafx.h"

WSA::WSA(sc_module_name name, int Snum_, int Anum_, int Wno_, int S1no_, int Sleaderno_, int Mno_, int Rno_, int rqV_)
: sc_module(name), Snum(Snum_), Anum(Anum_), Wno(Wno_), S1no(S1no_), Sleaderno(Sleaderno_), Mnum(Mno_), Rnum(Rno_), rqVotes(rqV_), currMaxVotes(0)
WSA::WSA(sc_module_name name, int Snum_, int Anum_, int Wno_, int S1no_, int Sleaderno_, int Mno_, int Rno_, int rqV_, int dV_, int sAW_)
: sc_module(name), Snum(Snum_), Anum(Anum_), Wno(Wno_), S1no(S1no_), Sleaderno(Sleaderno_), Mnum(Mno_), rndNum(Rno_),
rqVotes(rqV_), currMaxVotes(0), dumpVotes(dV_), currWinners(0), stopWinners(sAW_)
{
std::stringstream namegen;
//Snodes.resize(Snum);
Expand Down Expand Up @@ -39,13 +40,14 @@ WSA::WSA(sc_module_name name, int Snum_, int Anum_, int Wno_, int S1no_, int Sle
Mnodes[i] = new Mnode(namegen.str().c_str(), i, this);
Votes[i].clear(); // not necessary
}
winTimes.resize(stopWinners);

SC_THREAD(main);
}

WSA::~WSA()
{
cout << "Destructor,top,start" << endl;
//### cout << "Destructor,top,start" << endl;
//cout << "Destructing top." << endl;
//for (int i = 0; i < Snum; ++i)
//{
Expand All @@ -59,13 +61,55 @@ WSA::~WSA()
{
delete Mnodes[i];
}
cout << "Destructor,top,end" << endl;
if (dumpVotes)
{
int totalDifferentVotes = 0;
int totalOverRq = 0;
for (int i = 0; i < Votes.size(); ++i)
{
int thisOneCast = 0;
for (int k = 0; k < Mnum; ++k)
{
if (Votes[k].find(i) != Votes[k].end())
{
++thisOneCast;
}
}
if (dumpVotes > 2) cout << "Votes for " << i << " (total: " << Votes[i].size() << ", cast: " << thisOneCast << "): ";
if (Votes[i].size() >= rqVotes)
{
++totalOverRq;
}
totalDifferentVotes += Votes[i].size();
for (int j = 0; j < Mnum; ++j)
{
if (Votes[i].find(j) != Votes[i].end())
{
if (dumpVotes > 3) cout << j << " ";
}
}
if (dumpVotes > 3) cout << endl;
}
if (dumpVotes > 1) cout << "Total different votes: " << totalDifferentVotes << " (out of " << Mnum*rndNum << ")." << endl;
if (dumpVotes > 1) cout << "Total winners: " << totalOverRq << endl;
cout << "WinTimes,";
if (currWinners == 0)
{
cout << "NO WINNERS";
}
for (int i = 0; i < winTimes.size() && i < currWinners; ++i)
{
cout << winTimes[i] << ",";
}
cout << endl;
}
//### cout << "Destructor,top,end" << endl;
//cout << "Destructed top." << endl;
}

void WSA::main()
{
cout << "NodeStart," << sc_time_stamp() << "," << name() << endl;
//cout << "NodeStart," << sc_time_stamp() << "," << name() << endl;
//cout << sc_time_stamp() << ": WSA " << name() << " main is running." << endl;
}

Expand Down
8 changes: 6 additions & 2 deletions Sample3/Sample3/Top.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@ SC_MODULE(WSA)
std::vector<AnodeP> Anodes;
std::vector<MnodeP> Mnodes;

int dumpVotes;
std::vector<std::set<int>> Votes;

int Snum;
int Anum;
int Mnum;

int Rnum;
int rndNum;
int currMaxVotes;
int rqVotes;
int currWinners;
int stopWinners;
std::vector<uint64> winTimes;

int Wno;
int S1no;
Expand All @@ -23,7 +27,7 @@ SC_MODULE(WSA)
void BroadcastK(SnodeP w, k_block k);

SC_HAS_PROCESS(WSA);
WSA(sc_module_name name, int Snum_, int Anum_, int Wno_, int S1no_, int Sleaderno_, int Mno_, int Rno_, int rqV_);
WSA(sc_module_name name, int Snum_, int Anum_, int Wno_, int S1no_, int Sleaderno_, int Mno_, int Rno_, int rqV_, int dV_, int sAW_);
~WSA();

void main();
Expand Down
36 changes: 36 additions & 0 deletions Sample3/Sample3/config.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
;����������� ��������� (������ �� ������)
logging_level=8
;������ ����� M (� �����)
msize=1000
;����� ���� S1
S1=1
;���������� (W �) S �����
n=200
;������ ����� LeaderBeacon (� �����)
lbsize=1000
;���������� A ����� �� ���� S ����
k=500
;����� ���� W
W=0
;����� ���� S_leader
Sleader=2
;����� �� ��������� ����� A ����� K (��)
taprocessk=10000
;����� �� ��������� ����� A ����� Leader_beacon (��)
taprocesslb=10000
;��������� ��������: �� (��)
rndlatfrom=100000
;��������� ��������: �� (��)
rndlatto=40000000
;������ ����� K (� �����)
ksize=800000
;������ ����� shadow_request (� �����)
rqsize=1000
;������ ����� shadow_response (� �����)
pnsize=1000
;������ ����� M-sign (� �����)
msgnsize=1000
;������� ���������� ����������� (�������) ���� (���/��, ��� ��� 100 ����/� = 0.1)
bandwidth=0.1
;�������������� ����� Sleader-� (���/��, ��� ��� 18000*144*8/� = 0.02); ������������ ���������� ������ ��������� � ���������� �� (�� �� ���������� ����� ����)
diskbw=0.02
Loading

0 comments on commit cef13d3

Please sign in to comment.