|
|
@ -249,9 +249,84 @@ void Simulation::p2pSimulation() |
|
|
|
|
|
|
|
void Simulation::natOverflowSimulation(int nNodes) |
|
|
|
{ |
|
|
|
int i=0; |
|
|
|
int i = 0, srcPort; |
|
|
|
stringstream ss; |
|
|
|
|
|
|
|
this->print("Creating NAT device"); |
|
|
|
NATRouter router("Router", "10.13.12.254", "255.255.255.0"); |
|
|
|
router.setLogParams(1, YELLOW, "\t\t"); |
|
|
|
router.setDelay(0); |
|
|
|
router.print("IP 10.13.12.254/24", true); |
|
|
|
sleep(1); |
|
|
|
|
|
|
|
this->print("Setting WAN configuration"); |
|
|
|
router.setWanIp("80.55.33.12"); |
|
|
|
router.setWanMask("255.255.255.255"); |
|
|
|
router.print("WAN IP 80.55.33.12/32", true); |
|
|
|
sleep(1); |
|
|
|
|
|
|
|
this->print("Creating server"); |
|
|
|
Node server("Server", "93.92.91.90", "255.255.255.255"); |
|
|
|
server.setLogParams(2, BLUE, "\t\t"); |
|
|
|
server.print("IP 93.92.91.90/32"); |
|
|
|
sleep(1); |
|
|
|
|
|
|
|
this->print("Creating and setting clients"); |
|
|
|
Node *client = new Node[nNodes]; |
|
|
|
int *currentSrcPort = new int[nNodes]; |
|
|
|
for (i = 0; i < nNodes; ++i) |
|
|
|
{ |
|
|
|
currentSrcPort[i] = 0; |
|
|
|
client[i].setLogParams(0, CYAN, "\t"); |
|
|
|
ss.str(""); |
|
|
|
ss << "Client " << (i + 1); |
|
|
|
client[i].setHostname(ss.str()); |
|
|
|
ss.str(""); |
|
|
|
ss << "10.13.12." << (i + 1); |
|
|
|
client[i].setIp(ss.str()); |
|
|
|
client[i].setMask("255.255.255.0"); |
|
|
|
client[i].setGatewayIp("10.13.12.254"); |
|
|
|
ss.str(""); |
|
|
|
ss << "IP 10.13.12." << (i + 1) << "/24, Gateway: 10.0.0.1"; |
|
|
|
client[i].print(ss.str()); |
|
|
|
usleep(12500); |
|
|
|
} |
|
|
|
|
|
|
|
for (i = 0; i < nNodes; ++i) |
|
|
|
{ |
|
|
|
ss.str(""); |
|
|
|
ss << "Plugging Client " << (i + 1) << " <---> Router"; |
|
|
|
this->print(ss.str()); |
|
|
|
router.connectNode(&client[i]); |
|
|
|
usleep(12500); |
|
|
|
} |
|
|
|
|
|
|
|
while(true); |
|
|
|
this->print("Plugging Server <---> Router"); |
|
|
|
server.connectNode(&router); |
|
|
|
usleep(600000); |
|
|
|
|
|
|
|
this->print("Starting simulation..."); |
|
|
|
sleep(2); |
|
|
|
this->createThread("router", NODE_RECV, &router); |
|
|
|
this->createThread("server", NODE_RECV, &server); |
|
|
|
this->createThread("nat", NAT_FP, &router); |
|
|
|
|
|
|
|
Packet p("test packet"); |
|
|
|
p.setDstIp("93.92.91.90"); |
|
|
|
p.setDstPort(80); |
|
|
|
i=0; |
|
|
|
struct timespec ts, ts2; |
|
|
|
ts.tv_sec = 0; |
|
|
|
ts.tv_nsec = 100; |
|
|
|
|
|
|
|
while(true) |
|
|
|
{ |
|
|
|
if (i==65535) |
|
|
|
i=1; |
|
|
|
p.setSrcPort(i++); |
|
|
|
client[0].send(p); |
|
|
|
//this->delay(10);
|
|
|
|
//usleep(1);
|
|
|
|
nanosleep(&ts, &ts2); |
|
|
|
} |
|
|
|
} |