Commit 4694ab9b authored by 's avatar

Flows counting fixed.


git-svn-id: file:///home/svn/mapi/trunk@1345 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent 6e94609b
......@@ -62,10 +62,7 @@ struct tlcmstat {
struct tcmstat {
unsigned int count;
unsigned int matched;
union {
unsigned int unassigned; // unmatched
unsigned int unmatched; // unmatched
};
unsigned int unmatched;
unsigned int timeouted;
};
......@@ -585,7 +582,6 @@ int main(int argc, char *argv[])
results = (unsigned int *) host[h].results_dev[d].res; // number of results/flows
flowdata = (struct flow_data *) ((char *) host[h].results_dev[d].res + sizeof(unsigned int)); // results/flows array
host[h].stats.totalflows.count += *results;
for (count = *results; count > 0; count--) {
if (LOGFILE) {
......@@ -784,6 +780,9 @@ int main(int argc, char *argv[])
}
// }}}
// remove old unmatched flow from hashtable
drop_old_and_unassigned_flows();
// GUI - ncurses {{{
if (WITH_NCURSES) {
if (totalpk.count == 0) {
......@@ -845,6 +844,7 @@ int main(int argc, char *argv[])
fprintf(fp, "\n");
for(h1 = 0; h1 < hosts; h1++) {
fprintf(fp, "top;tfch%d;Total flows captured at host %s;%u\n", h1, host[h1].name, host[h1].stats.totalflows.count);
fprintf(fp, "top;tfmh%d;Total flows matched at host %s;%u\n", h1, host[h1].name, host[h1].stats.totalflows.matched);
fprintf(fp, "top;tfuh%d;Total flows unmatched at host %s;%u\n", h1, host[h1].name, host[h1].stats.totalflows.unmatched);
fprintf(fp, "top;tfth%d;Total flows timeouted at host %s;%u\n", h1, host[h1].name, host[h1].stats.totalflows.timeouted);
fprintf(fp, "top;tpch%d;Total packets captured at host %s;%llu\n", h1, host[h1].name, host[h1].stats.totalpk.count);
......@@ -926,9 +926,6 @@ int main(int argc, char *argv[])
fclose(fp);
// }}}
// remove old unmatched flow from hashtable
drop_old_and_unassigned_flows();
sleep(REFRESH_TIME);
}
......@@ -1074,7 +1071,7 @@ void drop_old_and_unassigned_flows(void)
next = tmp->next;
if ((current_ts - tmp->data.timestamp > ((unsigned long long) (TIMEOUT)) << 32) || !tmp->assigned) {
if(!tmp->assigned) {
host[tmp->sensor].stats.totalflows.unassigned++;
host[tmp->sensor].stats.totalflows.unmatched++;
}
else {
host[tmp->sensor].stats.totalflows.timeouted++;
......@@ -1251,6 +1248,7 @@ void store_results(unsigned int sensor, unsigned int count, struct flow_data *fl
{
struct hash_bucket *tmp;
// struct hash_bucket *tmp2;
struct timeval *tp;
unsigned long long current_ts = 0;
unsigned int hsvalue = 0, pos;
......@@ -1281,8 +1279,30 @@ void store_results(unsigned int sensor, unsigned int count, struct flow_data *fl
current_ts = (((unsigned long long) tp->tv_sec) << 32) + ((tp->tv_usec * 4295) & 0xffffffff);
tmp->data.timestamp = current_ts;
}
// if(!tmp->assigned) {
// // Flow exist at the other host?
// if ((tmp2 = compare_bucket(hashtable[pos], flowdata, sensor, 1)) != NULL) {
// if(tmp2->assigned) { // the other flow already assigned
// if(tmp2->sensor2 != sensor) {
// fprintf(stderr, "packetloss: ERROR flow assigned to ANOTHER host!!! (%d->%d, not %d)\n", tmp2->sensor, tmp2->sensor2, sensor);
// }
// }
// else { // assign the other flow
// tmp2->sensor2 = tmp->sensor; // with tmp->sensor
// tmp2->assigned = 1;
// host[tmp2->sensor].stats.totalflows.matched++;
// host[tmp2->sensor].statsto[tmp->sensor].totalflows.matched++;
// }
// tmp->assigned = 1; // assign the existing flow
// tmp->sensor2 = tmp2->sensor; // with sensor2
// host[tmp->sensor].stats.totalflows.matched++;
// host[tmp->sensor].statsto[tmp2->sensor].totalflows.matched++;
// }
// }
}
else {
assigned = 0;
// Flow exist at the other host?
if ((tmp = compare_bucket(hashtable[pos], flowdata, sensor, 1)) != NULL) {
if(tmp->assigned) { // other sensor assigned
......@@ -1290,12 +1310,15 @@ void store_results(unsigned int sensor, unsigned int count, struct flow_data *fl
fprintf(stderr, "packetloss: ERROR flow assigned to ANOTHER host!!! (%d->%d, not %d)\n", tmp->sensor, tmp->sensor2, sensor);
}
}
tmp->sensor2 = sensor;
sensor2 = tmp->sensor;
tmp->assigned = 1;
assigned = 1;
host[sensor].statsto[sensor2].totalflows.matched++;
host[sensor2].statsto[sensor].totalflows.matched++;
else { // assign the other flow
tmp->sensor2 = sensor; // with sensor
tmp->assigned = 1;
host[tmp->sensor].stats.totalflows.unmatched--;
host[tmp->sensor].stats.totalflows.matched++;
host[tmp->sensor].statsto[sensor].totalflows.matched++;
}
assigned = 1; // shall assign the new flow soon
sensor2 = tmp->sensor; // with sensor2
}
// New flow
tmp = (struct hash_bucket *) malloc(sizeof(struct hash_bucket));
......@@ -1315,6 +1338,15 @@ void store_results(unsigned int sensor, unsigned int count, struct flow_data *fl
tmp->next = hashtable[pos];
hashtable[pos] = tmp;
if(assigned) {
host[sensor].stats.totalflows.matched++;
host[sensor].statsto[sensor2].totalflows.matched++;
}
else {
host[sensor].stats.totalflows.unmatched++;
}
host[sensor].stats.totalflows.count++;
}
flowdata++;
}
......
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