Commit 9a442cd2 authored by 's avatar

Direction was switched...

Unrecognised direction is counted just to statsrelwith, not to statsdir(to|from).


git-svn-id: file:///home/svn/mapi/trunk@1351 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent 4c21dbde
......@@ -903,16 +903,20 @@ int main(int argc, char *argv[])
if(h2 != h1) {
fprintf(fp, "top;tfmrwh%dh%d;Total flows matched at %s in relation with %s;%u (%.2f %%)\n", h1, h2, host[h1].name, host[h2].name, host[h1].statsrelwith[h2].totalflows.matched, (float) (host[h1].stats.totalflows.matched ? (float) host[h1].statsrelwith[h2].totalflows.matched * 100 / (float) host[h1].stats.totalflows.matched : 0));
fprintf(fp, "top;tfmdth%dh%d;Total flows matched at %s in direction to %s;%u (%.2f %%)\n", h1, h2, host[h1].name, host[h2].name, host[h1].statsdirto[h2].totalflows.matched, (float) (host[h1].stats.totalflows.matched ? (float) host[h1].statsdirto[h2].totalflows.matched * 100 / (float) host[h1].stats.totalflows.matched : 0));
fprintf(fp, "top;tfmdfh%dh%d;Total flows matched at %s in direction from %s;%u (%.2f %%)\n", h2, h1, host[h2].name, host[h1].name, host[h2].statsdirfrom[h1].totalflows.matched, (float) (host[h2].stats.totalflows.matched ? (float) host[h2].statsdirfrom[h1].totalflows.matched * 100 / (float) host[h2].stats.totalflows.matched : 0));
fprintf(fp, "top;tfmdfh%dh%d;Total flows matched at %s in direction from %s;%u (%.2f %%)\n", h1, h2, host[h1].name, host[h2].name, host[h1].statsdirfrom[h2].totalflows.matched, (float) (host[h1].stats.totalflows.matched ? (float) host[h1].statsdirfrom[h2].totalflows.matched * 100 / (float) host[h1].stats.totalflows.matched : 0));
//fprintf(fp, "top;tfmdth%dh%d;Total flows matched at %s in direction to %s;%u (%.2f %%)\n", h2, h1, host[h2].name, host[h1].name, host[h2].statsdirto[h1].totalflows.matched, (float) (host[h2].stats.totalflows.matched ? (float) host[h2].statsdirto[h1].totalflows.matched * 100 / (float) host[h2].stats.totalflows.matched : 0));
//fprintf(fp, "top;tfmdfh%dh%d;Total flows matched at %s in direction from %s;%u (%.2f %%)\n", h2, h1, host[h2].name, host[h1].name, host[h2].statsdirfrom[h1].totalflows.matched, (float) (host[h2].stats.totalflows.matched ? (float) host[h2].statsdirfrom[h1].totalflows.matched * 100 / (float) host[h2].stats.totalflows.matched : 0));
fprintf(fp, "top;tftrwh%dh%d;Total flows timeouted at %s in relation with %s;%u\n", h1, h2, host[h1].name, host[h2].name, host[h1].statsrelwith[h2].totalflows.timeouted);
fprintf(fp, "top;tftdth%dh%d;Total flows timeouted at %s in direction to %s;%u\n", h1, h2, host[h1].name, host[h2].name, host[h1].statsdirto[h2].totalflows.timeouted);
fprintf(fp, "top;tftdfh%dh%d;Total flows timeouted at %s in direction from %s;%u\n", h2, h1, host[h2].name, host[h1].name, host[h2].statsdirfrom[h1].totalflows.timeouted);
fprintf(fp, "top;tftdfh%dh%d;Total flows timeouted at %s in direction from %s;%u\n", h1, h2, host[h1].name, host[h2].name, host[h1].statsdirfrom[h2].totalflows.timeouted);
fprintf(fp, "top;tpmrwh%dh%d;Total packets matched at %s in relation with %s;%llu\n", h1, h2, host[h1].name, host[h2].name, host[h1].statsrelwith[h2].totalpk.matched);
fprintf(fp, "top;tpmdth%dh%d;Total packets matched at %s in direction to %s;%llu\n", h1, h2, host[h1].name, host[h2].name, host[h1].statsdirto[h2].totalpk.matched);
fprintf(fp, "top;tpmdfh%dh%d;Total packets matched at %s in direction from %s;%llu\n", h2, h1, host[h2].name, host[h1].name, host[h2].statsdirfrom[h1].totalpk.matched);
fprintf(fp, "top;tpmdfh%dh%d;Total packets matched at %s in direction from %s;%llu\n", h1, h2, host[h1].name, host[h2].name, host[h1].statsdirfrom[h2].totalpk.matched);
fprintf(fp, "top;tplrwh%dh%d;Total packets lost at %s in relation with %s;%llu (%.2f %%)\n", h1, h2, host[h1].name, host[h2].name, host[h1].statsrelwith[h2].totalpk.loss, (float) (totalpk.count ? (float) host[h1].statsrelwith[h2].totalpk.loss * 100 / (float) totalpk.count : 0));
fprintf(fp, "top;tpldth%dh%d;Total packets lost at %s in direction to %s;%llu (%.2f %%)\n", h1, h2, host[h1].name, host[h2].name, host[h1].statsdirto[h2].totalpk.loss, (float) (totalpk.count ? (float) host[h1].statsdirto[h2].totalpk.loss * 100 / (float) totalpk.count : 0));
fprintf(fp, "top;tpldfh%dh%d;Total packets lost at %s in direction from %s;%llu (%.2f %%)\n", h2, h1, host[h2].name, host[h1].name, host[h2].statsdirfrom[h1].totalpk.loss, (float) (totalpk.count ? (float) host[h2].statsdirfrom[h1].totalpk.loss * 100 / (float) totalpk.count : 0));
fprintf(fp, "top;tpldfh%dh%d;Total packets lost at %s in direction from %s;%llu (%.2f %%)\n", h1, h2, host[h1].name, host[h2].name, host[h1].statsdirfrom[h2].totalpk.loss, (float) (totalpk.count ? (float) host[h1].statsdirfrom[h2].totalpk.loss * 100 / (float) totalpk.count : 0));
//fprintf(fp, "top;tpldth%dh%d;Total packets lost at %s in direction to %s;%llu (%.2f %%)\n", h2, h1, host[h2].name, host[h1].name, host[h2].statsdirto[h1].totalpk.loss, (float) (totalpk.count ? (float) host[h2].statsdirto[h1].totalpk.loss * 100 / (float) totalpk.count : 0));
//fprintf(fp, "top;tpldfh%dh%d;Total packets lost at %s in direction from %s;%llu (%.2f %%)\n", h2, h1, host[h2].name, host[h1].name, host[h2].statsdirfrom[h1].totalpk.loss, (float) (totalpk.count ? (float) host[h2].statsdirfrom[h1].totalpk.loss * 100 / (float) totalpk.count : 0));
fprintf(fp, "\n");
}
}
......@@ -1227,23 +1231,31 @@ unsigned long long cmp_results(struct flow_data *data, unsigned int sensor)
matchedsensor = flow[currenthostflow]->sensor2;
if(flow[currenthostflow]->data.ttl_pkt1 <= flow[otherhostflow]->data.ttl_pkt1) {
if(flow[currenthostflow]->data.ttl_pkt1 > flow[otherhostflow]->data.ttl_pkt1) {
sendersensor = sensor;
receiversensor = matchedsensor;
senderflow = currenthostflow;
receiverflow = otherhostflow;
}
else {
else if(flow[currenthostflow]->data.ttl_pkt1 < flow[otherhostflow]->data.ttl_pkt1) {
sendersensor = matchedsensor;
receiversensor = sensor;
senderflow = otherhostflow;
receiverflow = currenthostflow;
}
else {
sendersensor = 0;
receiversensor = 0;
senderflow = 0;
receiverflow = 0;
}
host[sensor].statsrelwith[matchedsensor].totalpk.matched += flow[currenthostflow]->data.packets_count;
host[matchedsensor].statsrelwith[sensor].totalpk.matched += flow[otherhostflow]->data.packets_count;
if(sendersensor != receiversensor) {
host[sendersensor].statsdirto[receiversensor].totalpk.matched += flow[senderflow]->data.packets_count;
host[receiversensor].statsdirfrom[sendersensor].totalpk.matched += flow[receiverflow]->data.packets_count;
}
// set the index of the flow at host which looses as "looserflow"
looserflow = (flow[0]->data.packets_count > flow[1]->data.packets_count);
......@@ -1327,15 +1339,16 @@ unsigned long long cmp_results(struct flow_data *data, unsigned int sensor)
void store_results(unsigned int sensor, unsigned int count, struct flow_data *flowdata)
{
struct hash_bucket *tmp;
// struct hash_bucket *tmp2;
struct hash_bucket *flow;
struct hash_bucket *flow2;
struct hash_bucket *flownew;
struct timeval *tp;
unsigned long long current_ts = 0;
unsigned int hsvalue = 0, pos;
//unsigned int shost = 0;
//unsigned int dhost = 0;
unsigned int sensor2 = 0;
int assigned = 0;
int assign = 0;
tp = (struct timeval *) malloc(sizeof(struct timeval));
......@@ -1351,75 +1364,79 @@ void store_results(unsigned int sensor, unsigned int count, struct flow_data *fl
pos = hsvalue % HASHTABLE_SIZE;
// Flow already exist at this host?
if ((tmp = compare_bucket(hashtable[pos], flowdata, sensor, 0)) != NULL) {
if ((flow = compare_bucket(hashtable[pos], flowdata, sensor, 0)) != NULL) {
tmp->data.packets_count += flowdata->packets_count;
flow->data.packets_count += flowdata->packets_count;
if (gettimeofday(tp, NULL) == 0) { // calculate the current timestamp
current_ts = (((unsigned long long) tp->tv_sec) << 32) + ((tp->tv_usec * 4295) & 0xffffffff);
tmp->data.timestamp = current_ts;
flow->data.timestamp = current_ts;
}
}
else {
assigned = 0;
assign = 0;
// Flow exist at the other host?
if ((tmp = compare_bucket(hashtable[pos], flowdata, sensor, 1)) != NULL) {
if(tmp->assigned) { // other sensor assigned
if(tmp->sensor2 != sensor) {
fprintf(stderr, "packetloss: ERROR flow assigned to ANOTHER host!!! (%d->%d, not %d)\n", tmp->sensor, tmp->sensor2, sensor);
if ((flow2 = compare_bucket(hashtable[pos], flowdata, sensor, 1)) != NULL) {
if(flow2->assigned) { // other sensor assigned
if(flow2->sensor2 != sensor) {
fprintf(stderr, "packetloss: ERROR flow assigned to ANOTHER host!!! (%d->%d, not %d)\n", flow2->sensor, flow2->sensor2, sensor);
}
}
else { // assign the other flow
tmp->sensor2 = sensor; // with sensor
tmp->assigned = 1;
flow2->sensor2 = sensor; // with sensor
flow2->assigned = 1;
stats.totalflows.unmatched--;
stats.totalflows.matched++;
host[tmp->sensor].stats.totalflows.unmatched--;
host[tmp->sensor].stats.totalflows.matched++;
host[tmp->sensor].statsrelwith[sensor].totalflows.matched++;
if(flowdata->ttl_pkt1 < tmp->data.ttl_pkt1) {
host[tmp->sensor].statsdirfrom[sensor].totalflows.matched++;
//host[sensor].statsdirto[tmp->sensor].totalflows.matched++;
host[flow2->sensor].stats.totalflows.unmatched--;
host[flow2->sensor].stats.totalflows.matched++;
host[flow2->sensor].statsrelwith[sensor].totalflows.matched++;
if(flow2->data.ttl_pkt1 < flowdata->ttl_pkt1) {
host[flow2->sensor].statsdirfrom[sensor].totalflows.matched++;
//host[sensor].statsdirto[flow2->sensor].totalflows.matched++;
}
else if(flow2->data.ttl_pkt1 > flowdata->ttl_pkt1) {
host[flow2->sensor].statsdirto[sensor].totalflows.matched++;
//host[sensor].statsdirfrom[flow2->sensor].totalflows.matched++;
}
else {
host[tmp->sensor].statsdirto[sensor].totalflows.matched++;
//host[sensor].statsdirfrom[tmp->sensor].totalflows.matched++;
}
}
assigned = 1; // shall assign the new flow soon
sensor2 = tmp->sensor; // with sensor2
assign = 1; // shall assign the new flow soon
sensor2 = flow2->sensor; // with sensor2
}
// New flow
tmp = (struct hash_bucket *) malloc(sizeof(struct hash_bucket));
memcpy(&(tmp->data), flowdata, sizeof(struct flow_data));
tmp->hsvalue = hsvalue;
tmp->sensor = sensor;
flownew = (struct hash_bucket *) malloc(sizeof(struct hash_bucket));
memcpy(&(flownew->data), flowdata, sizeof(struct flow_data));
flownew->hsvalue = hsvalue;
flownew->sensor = sensor;
//shost = getHostByIP(saddr);
//dhost = getHostByIP(daddr);
//tmp->sensor2 = (shost != sensor ? shost : dhost);
tmp->sensor2 = assigned ? sensor2 : sensor;
tmp->assigned = assigned; // 0 or 1
//tmp->next = NULL;
//flownew->sensor2 = (shost != sensor ? shost : dhost);
flownew->sensor2 = assign ? sensor2 : sensor;
flownew->assigned = assign; // 0 or 1
//flownew->next = NULL;
if (gettimeofday(tp, NULL) == 0) { // calculate the current timestamp
current_ts = (((unsigned long long) tp->tv_sec) << 32) + ((tp->tv_usec * 4295) & 0xffffffff);
tmp->data.timestamp = current_ts;
flownew->data.timestamp = current_ts;
}
tmp->next = hashtable[pos];
hashtable[pos] = tmp;
flownew->next = hashtable[pos];
hashtable[pos] = flownew;
if(assigned) {
if(flownew->assigned) {
stats.totalflows.matched++;
host[sensor].stats.totalflows.matched++;
host[sensor].statsrelwith[sensor2].totalflows.matched++;
if(flowdata->ttl_pkt1 < tmp->data.ttl_pkt1) {
if(flownew->data.ttl_pkt1 < flow2->data.ttl_pkt1) {
host[sensor].statsdirfrom[sensor2].totalflows.matched++;
//host[sensor2].statsdirto[sensor].totalflows.matched++;
}
else if(flownew->data.ttl_pkt1 > flow2->data.ttl_pkt1) {
host[sensor].statsdirto[sensor2].totalflows.matched++;
//host[sensor2].statsdirfrom[sensor].totalflows.matched++;
}
else {
host[sensor].statsdirfrom[sensor2].totalflows.matched++;
//host[sensor2].statsdirto[sensor].totalflows.matched++;
}
}
else {
......
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