Browse Source

interfejs startowy + usage + utworzenie metody natOverflowSimulation

master
Piotr Dergun 7 years ago
parent
commit
3b49766497
3 changed files with 53 additions and 94 deletions
  1. +44
    -93
      Main.cpp
  2. +8
    -1
      Simulation.cpp
  3. +1
    -0
      Simulation.h

+ 44
- 93
Main.cpp View File

@ -10,101 +10,52 @@
#include "NATRouter.h" #include "NATRouter.h"
#include "Simulation.h" #include "Simulation.h"
int main(int argc, char *argv[])
void usage(string programName)
{ {
/*
* test puszczania sciezki external/internal
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");
NATRouter n1("N1", "10.0.0.2", "255.255.255.0"), n2("N2", "10.0.0.1", "255.255.255.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");
pkt.setDstIp("10.0.0.2");
pkt.setDstPort(1000);
cout << "N2 Send: " << n2.send(pkt) << endl;
cout << "Wywoluje onRecv() na N1" << endl;
n1.onRecv();
cout << "Wywoluje onRecv() na K2" << endl;
k2.onRecv();
exit(0);
*/
Simulation sim;
sim.createThread("timer", SIM_TIMER, &sim);
sim.p2pSimulation();
while(1);
exit(0);
/*
cout << "Obiekt PC1" << endl;
Node pc1("PC1", "10.0.0.2", "255.0.0.0", "10.0.0.1");
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;
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);
}
cout << "Wywoluje onRecv() na R1 <-- pelni funkcje DNAT" << endl;
r1.onRecv();
int main(int argc, char *argv[])
{
char *endptr=NULL;
int nodesCount;
if (argc < 2)
usage(argv[0]);
if (!strcmp(argv[1], "p2p"))
{
Simulation sim;
sim.createThread("timer", SIM_TIMER, &sim);
sim.p2pSimulation();
}
else if (!strcmp(argv[1], "nat"))
{
if (argc < 3)
usage(argv[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;
sim.createThread("timer", SIM_TIMER, &sim);
sim.natOverflowSimulation(nodesCount);
}
else if (!strcmp(argv[1], "-v"))
{
}
else
usage(argv[0]);
cout << "Wywoluje onRecv() na PC1" << endl;
pc1.onRecv();
*/
return 0; return 0;
} }

+ 8
- 1
Simulation.cpp 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);
}
void Simulation::natOverflowSimulation(int nNodes)
{
int i=0;
Node *client = new Node[nNodes];
while(1);
while(true);
} }

+ 1
- 0
Simulation.h 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_ */

Loading…
Cancel
Save