interfejs startowy + usage + utworzenie metody natOverflowSimulation

This commit is contained in:
2017-01-18 21:39:07 +01:00
parent 724cb01232
commit 3b49766497
3 changed files with 50 additions and 91 deletions

127
Main.cpp
View File

@@ -10,101 +10,52 @@
#include "NATRouter.h" #include "NATRouter.h"
#include "Simulation.h" #include "Simulation.h"
void usage(string programName)
{
cerr << endl;
cerr << "Usage:" << endl;
cerr << programName << " p2p\t\t\tP2P simulation" << endl;
cerr << programName << " nat <nodes>\t\tNAT overflow simulation" << endl;
cerr << endl;
exit(1);
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
/* char *endptr=NULL;
* test puszczania sciezki external/internal int nodesCount;
Node k1("K1", "10.0.0.5", "255.255.255.0", "10.0.0.2"), k2("K2", "10.0.0.2", "255.255.255.0", "10.0.0.1"); if (argc < 2)
NATRouter n1("N1", "10.0.0.2", "255.255.255.0"), n2("N2", "10.0.0.1", "255.255.255.0"); usage(argv[0]);
n1.setWanIp("8.8.8.8");
n1.setWanMask("255.255.255.255");
n2.setWanIp("8.8.4.4");
n2.setWanMask("255.255.255.255");
n1.connectNode(&k1);
n2.connectNode(&k2);
n2.connectNode(&n1, true);
Packet pkt("TEST"); if (!strcmp(argv[1], "p2p"))
pkt.setDstIp("10.0.0.2"); {
pkt.setDstPort(1000); Simulation sim;
cout << "N2 Send: " << n2.send(pkt) << endl; sim.createThread("timer", SIM_TIMER, &sim);
cout << "Wywoluje onRecv() na N1" << endl; sim.p2pSimulation();
n1.onRecv(); }
cout << "Wywoluje onRecv() na K2" << endl; else if (!strcmp(argv[1], "nat"))
k2.onRecv(); {
if (argc < 3)
usage(argv[0]);
exit(0); nodesCount = strtol(argv[2], &endptr, 10);
*/ if (nodesCount < 1 || nodesCount > 255)
{
cerr << "Invalid number of nodes format [1,255]" << endl;
usage(argv[0]);
}
Simulation sim; Simulation sim;
sim.createThread("timer", SIM_TIMER, &sim); sim.createThread("timer", SIM_TIMER, &sim);
sim.p2pSimulation(); sim.natOverflowSimulation(nodesCount);
while(1); }
exit(0); else if (!strcmp(argv[1], "-v"))
/* {
cout << "Obiekt PC1" << endl; }
Node pc1("PC1", "10.0.0.2", "255.0.0.0", "10.0.0.1"); else
usage(argv[0]);
cout << "Obiekt PC2" << endl;
Node pc2("PC2", "10.0.0.3", "255.0.0.0", "10.0.0.1");
cout << "Obiekt R1" << endl;
NATRouter r1("R1", "10.0.0.1", "255.255.255.0");
r1.setWanIp("83.11.254.254");
r1.setWanMask("255.255.255.255");
cout << "Podlaczam PC1, PC2 z R1" << endl;
cout << r1.connectNode(&pc1) << endl;
cout << r1.connectNode(&pc2) << endl;
cout << "Obiekt S" << endl;
Node s("Serwer", "8.8.8.8", "255.255.255.255");
s.connectNode(&r1, true);
cout << "Tworze pakiet i adresuje go do PC2" << endl;
Packet p("piekna wiadomosc");
p.setDstIp("10.0.0.3");
p.setDstPort(80);
cout << "Wysylam wiadomosc z PC1: ";
cout << pc1.send(p) << endl;
cout << "Wywoluje onRecv() na R1 <-- pelni funkcje switcha" << endl;
r1.onRecv();
cout << "Wywoluje onRecv() na PC2" << endl;
pc2.onRecv();
cout << "Adresuje pakiet do serwera" << endl;
p.setDstIp("8.8.8.8");
p.setDstPort(80);
p.setMsg("to wiadomosc do serwera!");
cout << "Wysylam wiadomosc z PC1: ";
cout << pc1.send(p) << endl;
cout << "Wywoluje onRecv() na R1 <-- pelni funkcje SNAT" << endl;
r1.onRecv();
cout << "Wywoluje onRecv() na serwerze" << endl;
s.onRecv();
cout << "Serwer generuje odpowiedz (tymczasowo, poki nie ma swojej klasy)" << endl;
Packet rp("Odpowiedz z serwera do PC1");
rp.setDstIp("83.11.254.254");
rp.setDstPort(1);
cout << "Wysylam wiadomosc z serwera: ";
cout << s.send(rp) << endl;
cout << "Wywoluje onRecv() na R1 <-- pelni funkcje DNAT" << endl;
r1.onRecv();
cout << "Wywoluje onRecv() na PC1" << endl;
pc1.onRecv();
*/
return 0; return 0;
} }

View File

@@ -240,7 +240,14 @@ void Simulation::p2pSimulation()
this->createThread("p1", NODE_RECV, &seed); this->createThread("p1", NODE_RECV, &seed);
this->createThread("p2", NODE_RECV, &peer); this->createThread("p2", NODE_RECV, &peer);
while(true);
}
while(1);
void Simulation::natOverflowSimulation(int nNodes)
{
int i=0;
Node *client = new Node[nNodes];
while(true);
} }

View File

@@ -43,6 +43,7 @@ public:
void timer(); void timer();
void p2pSimulation(); void p2pSimulation();
void natOverflowSimulation(int nNodes);
}; };
#endif /* SIMULATION_H_ */ #endif /* SIMULATION_H_ */