|
@ -7,32 +7,81 @@ |
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
#include "common.h"
|
|
|
#include "Node.h"
|
|
|
#include "Node.h"
|
|
|
|
|
|
#include "NATRouter.h"
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) |
|
|
int main(int argc, char *argv[]) |
|
|
{ |
|
|
{ |
|
|
cout << "Obiekt PC1" << endl; |
|
|
cout << "Obiekt PC1" << endl; |
|
|
Node pc1("PC1", "10.0.0.2", "255.0.0.0"); |
|
|
|
|
|
|
|
|
Node pc1("PC1", "10.0.0.2", "255.0.0.0", "10.0.0.1"); |
|
|
|
|
|
|
|
|
cout << "Obiekt PC2" << endl; |
|
|
cout << "Obiekt PC2" << endl; |
|
|
Node pc2("PC2", "10.0.0.3", "255.0.0.0"); |
|
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* zastapilem to polaczenie bezposrednie |
|
|
|
|
|
* polaczeniem przez router (a'la switch) |
|
|
|
|
|
|
|
|
cout << "Lacze PC1 z PC2" << endl; |
|
|
cout << "Lacze PC1 z PC2" << endl; |
|
|
cout << pc1.connectNode(&pc2) << endl; |
|
|
cout << pc1.connectNode(&pc2) << endl; |
|
|
|
|
|
|
|
|
cout << "Lacze PC1 z PC2 (ponownie)" << endl; |
|
|
cout << "Lacze PC1 z PC2 (ponownie)" << endl; |
|
|
cout << pc1.connectNode(&pc2) << endl; |
|
|
cout << pc1.connectNode(&pc2) << endl; |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
|
cout << "Tworze pakiet i adresuje go do PC2" << endl; |
|
|
cout << "Tworze pakiet i adresuje go do PC2" << endl; |
|
|
Packet p("piekna wiadomosc"); |
|
|
Packet p("piekna wiadomosc"); |
|
|
|
|
|
|
|
|
p.setDstIp("10.0.0.3"); |
|
|
p.setDstIp("10.0.0.3"); |
|
|
p.setDstPort(80); |
|
|
p.setDstPort(80); |
|
|
|
|
|
|
|
|
cout << "Wysylam wiadomosc: "; |
|
|
|
|
|
|
|
|
cout << "Wysylam wiadomosc z PC1: "; |
|
|
cout << pc1.send(p) << endl; |
|
|
cout << pc1.send(p) << endl; |
|
|
|
|
|
|
|
|
|
|
|
cout << "Wywoluje onRecv() na R1 <-- pelni funkcje switcha" << endl; |
|
|
|
|
|
r1.onRecv(); |
|
|
|
|
|
|
|
|
cout << "Wywoluje onRecv() na PC2" << endl; |
|
|
cout << "Wywoluje onRecv() na PC2" << endl; |
|
|
pc2.onRecv(); |
|
|
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; |
|
|
} |
|
|
} |