|
@ -155,6 +155,7 @@ void Simulation::timer() |
|
|
char str[10]; |
|
|
char str[10]; |
|
|
int h,m, s; |
|
|
int h,m, s; |
|
|
unsigned long timeElapsed; |
|
|
unsigned long timeElapsed; |
|
|
|
|
|
pthread_mutex_t *mutex; |
|
|
#endif
|
|
|
#endif
|
|
|
while(true) |
|
|
while(true) |
|
|
{ |
|
|
{ |
|
@ -164,10 +165,12 @@ void Simulation::timer() |
|
|
h = timeElapsed / 3600; |
|
|
h = timeElapsed / 3600; |
|
|
m = (timeElapsed % 3600) / 60; |
|
|
m = (timeElapsed % 3600) / 60; |
|
|
s = (timeElapsed % 3600) % 60; |
|
|
s = (timeElapsed % 3600) % 60; |
|
|
//refresh();
|
|
|
|
|
|
|
|
|
mutex = Log::getMutex(); |
|
|
|
|
|
pthread_mutex_lock(mutex); |
|
|
sprintf(str, "%02d:%02d:%02d", h, m, s); |
|
|
sprintf(str, "%02d:%02d:%02d", h, m, s); |
|
|
move(0, this->cols-strlen(str)); |
|
|
move(0, this->cols-strlen(str)); |
|
|
printw(str); |
|
|
printw(str); |
|
|
|
|
|
pthread_mutex_unlock(mutex); |
|
|
#endif
|
|
|
#endif
|
|
|
usleep(100000); // 100 ms
|
|
|
usleep(100000); // 100 ms
|
|
|
//sleep(1);
|
|
|
//sleep(1);
|
|
@ -242,16 +245,21 @@ void Simulation::p2pSimulation() |
|
|
sleep(3); |
|
|
sleep(3); |
|
|
this->createThread("p1", NODE_RECV, &seed); |
|
|
this->createThread("p1", NODE_RECV, &seed); |
|
|
this->createThread("p2", NODE_RECV, &peer); |
|
|
this->createThread("p2", NODE_RECV, &peer); |
|
|
this->createThread("nat", NAT_FP, &r1); |
|
|
|
|
|
|
|
|
|
|
|
while(true); |
|
|
while(true); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void Simulation::natOverflowSimulation(int nNodes) |
|
|
void Simulation::natOverflowSimulation(int nNodes) |
|
|
{ |
|
|
{ |
|
|
int i = 0, srcPort; |
|
|
|
|
|
|
|
|
int i = 0;//, srcPort;
|
|
|
stringstream ss; |
|
|
stringstream ss; |
|
|
|
|
|
|
|
|
|
|
|
this->print("Creating server"); |
|
|
|
|
|
Node server("Server", "93.92.91.90", "255.255.255.255"); |
|
|
|
|
|
server.setLogParams(0, BLUE, "\t\t"); |
|
|
|
|
|
server.print("IP 93.92.91.90/32"); |
|
|
|
|
|
sleep(1); |
|
|
|
|
|
|
|
|
this->print("Creating NAT device"); |
|
|
this->print("Creating NAT device"); |
|
|
NATRouter router("Router", "10.13.12.254", "255.255.255.0"); |
|
|
NATRouter router("Router", "10.13.12.254", "255.255.255.0"); |
|
|
router.setLogParams(1, YELLOW, "\t\t"); |
|
|
router.setLogParams(1, YELLOW, "\t\t"); |
|
@ -265,19 +273,13 @@ void Simulation::natOverflowSimulation(int nNodes) |
|
|
router.print("WAN IP 80.55.33.12/32", true); |
|
|
router.print("WAN IP 80.55.33.12/32", true); |
|
|
sleep(1); |
|
|
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"); |
|
|
this->print("Creating and setting clients"); |
|
|
Node *client = new Node[nNodes]; |
|
|
Node *client = new Node[nNodes]; |
|
|
int *currentSrcPort = new int[nNodes]; |
|
|
int *currentSrcPort = new int[nNodes]; |
|
|
for (i = 0; i < nNodes; ++i) |
|
|
for (i = 0; i < nNodes; ++i) |
|
|
{ |
|
|
{ |
|
|
currentSrcPort[i] = 0; |
|
|
|
|
|
client[i].setLogParams(0, CYAN, "\t"); |
|
|
|
|
|
|
|
|
currentSrcPort[i] = 1; |
|
|
|
|
|
client[i].setLogParams(2, CYAN, "\t"); |
|
|
ss.str(""); |
|
|
ss.str(""); |
|
|
ss << "Client " << (i + 1); |
|
|
ss << "Client " << (i + 1); |
|
|
client[i].setHostname(ss.str()); |
|
|
client[i].setHostname(ss.str()); |
|
@ -315,18 +317,18 @@ void Simulation::natOverflowSimulation(int nNodes) |
|
|
p.setDstIp("93.92.91.90"); |
|
|
p.setDstIp("93.92.91.90"); |
|
|
p.setDstPort(80); |
|
|
p.setDstPort(80); |
|
|
i=0; |
|
|
i=0; |
|
|
struct timespec ts, ts2; |
|
|
|
|
|
ts.tv_sec = 0; |
|
|
|
|
|
ts.tv_nsec = 100; |
|
|
|
|
|
|
|
|
|
|
|
while(true) |
|
|
while(true) |
|
|
{ |
|
|
{ |
|
|
if (i==65535) |
|
|
|
|
|
i=1; |
|
|
|
|
|
p.setSrcPort(i++); |
|
|
|
|
|
client[0].send(p); |
|
|
|
|
|
//this->delay(10);
|
|
|
|
|
|
|
|
|
i = (nNodes>1) ? rand()%nNodes : 0; |
|
|
|
|
|
if (currentSrcPort[i] == 65535) |
|
|
|
|
|
currentSrcPort[i] = 1; |
|
|
|
|
|
|
|
|
|
|
|
p.setSrcPort(currentSrcPort[i]++); |
|
|
|
|
|
|
|
|
|
|
|
client[i].send(p); |
|
|
|
|
|
|
|
|
|
|
|
this->delay(150); |
|
|
//usleep(1);
|
|
|
//usleep(1);
|
|
|
nanosleep(&ts, &ts2); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |