Commit 4547eb14 authored by Jonathon Duerig's avatar Jonathon Duerig
Browse files

Fixed an overflow bug in the pcap code. Added a timer to make throughput more...

Fixed an overflow bug in the pcap code. Added a timer to make throughput more accurate (this still needs tweaking and isn't quite right).
parent 4dcbc85f
......@@ -55,10 +55,15 @@ int throughputInWindow(ThroughputAckState * state, unsigned int sequence)
// Reset the state of a connection completely.
void throughputInit(ThroughputAckState * state, unsigned int sequence)
{
state->firstUnknown = sequence;
state->nextSequence = sequence;
state->ackSize = 0;
state->repeatSize = 0;
if (state->isValid == 0)
{
state->firstUnknown = sequence;
state->nextSequence = sequence;
state->ackSize = 0;
state->repeatSize = 0;
gettimeofday(&state->lastTime, NULL);
state->isValid = 1;
}
}
// Notify the throughput monitor that a new packet has been sent
......@@ -99,10 +104,18 @@ void throughputProcessAck(ThroughputAckState * state, unsigned int sequence)
// throughputTick()?
unsigned int throughputTick(ThroughputAckState * state)
{
int result = state->ackSize;
double result = 0.0;
double divisor = 1.0;
struct timeval now;
gettimeofday(&now, NULL);
divisor = now.tv_sec - state->lastTime.tv_sec;
divisor += (now.tv_usec - state->lastTime.tv_usec)/1000000.0;
result = (state->ackSize * 8.0) / (divisor * 1000.0);
printf("ByteCount: %u\n", state->ackSize);
state->ackSize = 0;
state->repeatSize = 0;
return result;
state->lastTime = now;
return (unsigned int) result;
}
......@@ -112,6 +125,7 @@ void init_sniff_rcvdb(void) {
for (i=0; i<CONCURRENT_RECEIVERS; i++){
sniff_rcvdb[i].start = 0;
sniff_rcvdb[i].end = 0;
throughput[i].isValid = 0;
}
}
......
......@@ -60,8 +60,8 @@ struct sniff_record {
typedef struct sniff_record sniff_record;
struct sniff_path {
sniff_record records[SNIFF_WINSIZE];
short start; //circular buffer pointers
short end;
int start; //circular buffer pointers
int end;
};
typedef struct sniff_path sniff_path;
struct loss_record {
......@@ -89,6 +89,8 @@ typedef struct
unsigned int nextSequence;
unsigned int ackSize;
unsigned int repeatSize;
struct timeval lastTime;
int isValid;
} ThroughputAckState;
extern ThroughputAckState throughput[CONCURRENT_RECEIVERS];
......@@ -96,7 +98,7 @@ extern ThroughputAckState throughput[CONCURRENT_RECEIVERS];
// Returns the number of acknowledged bytes since the last
// throughputTick() call.
extern unsigned int throughputTick(ThroughputAckState * state);
extern void throughputInit(ThroughputAckState * state, unsigned int sequence);
#endif
......
......@@ -371,6 +371,7 @@ void send_receiver(unsigned long destaddr, long size, fd_set * write_fds_copy){
index = get_rcvdb_index(destaddr);
sockfd= rcvdb[index].sockfd;
FD_SET(sockfd, &write_fds);
throughput[index].isValid = 0;
error = send_all(sockfd, random_buffer, size);
}
}
......@@ -428,9 +429,8 @@ int send_monitor(int sockfd) {
for (i=0; i<CONCURRENT_RECEIVERS; i++){
if (rcvdb[i].valid == 1) {
printf("delays: %ld last: %ld\n", delays[i], last_delays[i]);
unsigned int ackSize = throughputTick(&throughput[i]);
printf("ackSize = %u --- throughput(kbps) = %f\n", ackSize,
ackSize / (5.0 * 1000));
unsigned int through = throughputTick(&throughput[i]);
printf("throughput(kbps) = %u\n", through);
//send delay
if (delays[i] != last_delays[i]) {
memcpy(outbuf_delay, &(rcvdb[i].ip), SIZEOF_LONG); //the receiver ip
......@@ -485,7 +485,6 @@ void handle_packet_buffer(struct timeval * deadline, fd_set * write_fds_copy)
// debug_temp.s_addr = packet.ip;
// printf("Sending packet to %s of size %ld\n", inet_ntoa(debug_temp),
// packet.size);
printf(".");
send_receiver(packet.ip, packet.size, write_fds_copy);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment