Commit 1360e7df authored by 's avatar
Browse files

Added support for multiple interface per sensor.


git-svn-id: file:///home/svn/mapi/trunk@1338 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent 435d0667
......@@ -15,7 +15,6 @@
#define TIMEOUT 500 // time to drop an unmatched flow
#define HASHTABLE_SIZE 4096
#define MAX_INTERFACES 2
#define WITH_NCURSES 0 // set to 1 if you want ncurses, 0 otherwise
#define REFRESH_TIME 10 // 10 seconds base interval with which data will be fed into the RRD
......@@ -37,6 +36,22 @@ struct hash_bucket {
#define PCT(proto) ((proto.lost) == 0 ? 0 : (float) ((proto.lost) * 100) / (float) (proto.pkts))
typedef struct hostinfo {
char *hostname, **interfaces;
unsigned int counti; // number interface
} hostinfo;
typedef struct sensors{
hostinfo *hostA, *hostB;
//unsigned int count;
} sensors;
typedef struct multistats {
unsigned int count;
struct mapi_stat *statstable;
} multistats;
struct tlcstat {
union {
unsigned long long pkts;
......@@ -121,8 +136,8 @@ unsigned long long lastmonth = 400, lastweek = 400;
FILE *fp_log = NULL, *fp_log_lost = NULL, *fp_log_unmatched = NULL;
struct hash_bucket *hashtable[HASHTABLE_SIZE];
char *host1, *host2;
int fd;
sensors *sens;
// Functions declaration
static void terminate();
......@@ -139,45 +154,185 @@ void my_rrd_create_packetcount(char *filename, int num);
int create_packetcount_cgi(char **argv);
void store_results(unsigned int sensor, unsigned int count, struct flow_data *flowdata);
sensors *parse_hosts(int argc, char *argv[]) {
char *tmp1, *tmpstart, *tmp2, *tmp;
hostinfo *hostA, *hostB, *host;
int i;
sensors *parsedsensors;
if (argc != 4) {
fprintf(stderr, "\nUsage: %s hostA:interface1:interface2... hostB:interface1:interface2... \"pcap filter\"\n\n", argv[0]);
exit(EXIT_FAILURE);
}
tmp1 = strchr(argv[1], ':');
tmp2 = strchr(argv[2], ':');
if (tmp1 == NULL || tmp2 == NULL) {
fprintf(stderr, "Error!! You must provide at least one interface (e.g eth0) for each IP\n");
exit(EXIT_FAILURE);
}
hostA = (hostinfo *)malloc(sizeof(hostinfo));
hostB = (hostinfo *)malloc(sizeof(hostinfo));
hostA->counti = hostB->counti = 0;
*tmp1 = *tmp2 = '\0';
hostA->hostname = strdup(argv[1]);
hostB->hostname = strdup(argv[2]);
*tmp1 = *tmp2 = ':';
tmpstart = tmp1+1;
for(i = 0; tmp1 != NULL; i++ ) {
tmp1 = strchr(tmpstart, ':');
hostA->interfaces = (char **)realloc(hostA->interfaces, sizeof(char *)*(i+1));
if(tmp1 != NULL) *tmp1 = '\0';
hostA->interfaces[i] = strdup(tmpstart);
if(tmp1 != NULL) tmpstart = tmp1+1;
}
hostA->counti = i;
tmp = tmp2;
host = hostB;
tmpstart = tmp+1;
for(i = 0; tmp != NULL; i++ ) {
tmp = strchr(tmpstart, ':');
host->interfaces = (char **)realloc(host->interfaces, sizeof(char *)*(i+1));
if(tmp != NULL) *tmp = '\0';
host->interfaces[i] = strdup(tmpstart);
if(tmp != NULL) tmpstart = tmp+1;
}
hostB->counti = i;
parsedsensors = (sensors *)malloc(sizeof(sensors));
parsedsensors->hostA = hostA;
parsedsensors->hostB = hostB;
return(parsedsensors);
}
void get_mapi_stats(multistats *stats1, multistats *stats2) {
int i, totali, countA, countB, err_no;
char *sensoraddr = NULL, *hostname, *interface, error[512];
multistats *stats;
if( stats1 != NULL ) {
if( stats1->count != sens->hostA->counti ) {
//multistats for sensor 1 are uninitialized
stats1->count = sens->hostA->counti;
stats1->statstable = (struct mapi_stat *)malloc(sizeof(struct mapi_stat)*stats1->count);
}
if( stats2->count != sens->hostB->counti ) {
//multistats for sensor 2 are uninitialized
stats2->count = sens->hostB->counti;
stats2->statstable = (struct mapi_stat *)malloc(sizeof(struct mapi_stat)*stats2->count);
}
}
countA = sens->hostA->counti;
countB = sens->hostB->counti;
totali = countA + countB;
for(i = 0; i < totali; i++) {
hostname = i < countA ? sens->hostA->hostname : sens->hostB->hostname;
interface = i < countA ? sens->hostA->interfaces[i] : sens->hostB->interfaces[i%countA];
stats = i < countA ? stats1 : stats2;
sensoraddr = (char *)realloc(sensoraddr,sizeof(char)*(strlen(hostname) + strlen(interface) + 2));
sprintf(sensoraddr, "%s:%s", hostname, interface);
if (mapi_stats(sensoraddr, &(stats->statstable[i%countA]))<0) {
fprintf(stderr, "Error in mapi_stats using '%s'\n", sensoraddr);
mapi_read_error( &err_no, error);
fprintf(stderr,"Errorcode :%d description: %s \n" ,err_no, error);
exit(EXIT_FAILURE);
}
/*
fprintf(stdout, "i = %d\nInterface: %s\treceived: %u\tdropped: %u \tdropped by interface: %u\tHostname: %s\n",\
i,stats->statstable[i%countA].dev, stats->statstable[i%countA].ps_recv,stats->statstable[i%countA].ps_drop,stats->statstable[i%countA].ps_ifdrop, stats->statstable[i%countA].hostname);
*/
}
free(sensoraddr);
}
int nodroppedpkts(multistats *stats) {
unsigned int i;
for(i = 0; i < stats->count; i++) {
if(stats->statstable[i].ps_drop != 0 || stats->statstable[i].ps_ifdrop != 0)
return 0;
}
return 1;
}
char* statstostr(multistats stats1, multistats stats2) {
unsigned int i;
char *toret;
struct mapi_stat stats;
//XXX fix the size
toret = (char *)malloc(sizeof(char)*1024);
toret[0] = '\0';
sprintf(toret, "<center> <br> Sensor 1 interfaces stats:<br>");
for(i = 0; i < stats1.count;i++) {
stats = stats1.statstable[i];
sprintf(toret+strlen(toret), "<b>Interface: %s</b><br>received: %u<br>dropped: %u <br>dropped by interface: %u<br>Hostname: %s<br>",\
stats.dev, stats.ps_recv,stats.ps_drop,stats.ps_ifdrop, stats.hostname);
}
sprintf(toret+strlen(toret), "<br>Sensor 2 interfaces stats:<br>");
for(i = 0; i < stats2.count;i++) {
stats = stats2.statstable[i];
sprintf(toret+strlen(toret), "<b>Interface: %s</b><br>received: %u<br>dropped: %u<br>dropped by interface: %u\
<br>Hostname: %s<br>",\
stats.dev, stats.ps_recv,stats.ps_drop,stats.ps_ifdrop, stats.hostname);
}
sprintf(toret+strlen(toret), "</center>");
return(toret);
}
int main(int argc, char *argv[])
{
unsigned int *i, count, j = 0, matchedsensor;
unsigned int *i, count, j = 0, matchedsensor, z, totali=0, sensor, ii = 0;
unsigned long long pkloss = 0, bytes = 0, ts = 0;
char argvs[500], error[512], top_page_buf[1024];
char sample2[512], sample[512], *p, *p2, load[512], *nl, *tmp1, *tmp2;
char sample2[512], sample[512], *p, *p2, load[512], *nl;
int row, col, err_no = 0, maxpad = 13, fid_loss, fid_load, counter;
struct tlcstat old_totalpk = {{0}, {0}};
struct tlcflowstat old_flow0totalpk = {0, 0, 0}; // old values
struct tlcflowstat old_flow1totalpk = {0, 0, 0};
mapi_results_t *results, *results_netload;
struct statistics stats[MAX_INTERFACES] = { {0, 0} };
struct statistics *stats;
FILE *fp = NULL, *fp_packetloss = NULL, *fp_packetloss_packets = NULL;
float speed = 0.0;
int host1_devices = 0;
int host2_devices = 0;
int ii;
char *k = NULL;
struct mapi_stat *stats1, *stats2;
char sensorstats[512], sensorstatslink[256];
multistats stats1, stats2;
char *sensorstats, sensorstatslink[256];
struct flow_data *flowdata;
signal(SIGINT, terminate);
signal(SIGQUIT, terminate);
signal(SIGTERM, terminate);
if (argc != 4) {
fprintf(stderr, "\nUsage: %s hostA:interface hostB:interface \"pcap filter\"\n\n", argv[0]);
exit(EXIT_FAILURE);
}
// Init variables
stats1.count = stats2.count = 0;
//parse_arguments(argc, argv);
sens = parse_hosts(argc, argv);
stats = (struct statistics *)malloc(sizeof(struct statistics)*(sens->hostA->counti+sens->hostB->counti));
sprintf(argvs, "%s, %s", argv[1], argv[2]);
tmp1 = strchr(argv[1], ':');
tmp2 = strchr(argv[2], ':');
if (tmp1 == NULL || tmp2 == NULL) {
fprintf(stderr, "Error!! You must provide an interface (e.g eth0) for each IP\n");
exit(EXIT_FAILURE);
argvs[0] = '\0';
for(z = 0; z <= sens->hostA->counti-1; z++) {
if (z !=0 )strcat(argvs, ", ");
sprintf(argvs+strlen(argvs), "%s:%s", sens->hostA->hostname, sens->hostA->interfaces[z]);
}
for(z = 0; z <= sens->hostB->counti-1; z++) {
sprintf(argvs+strlen(argvs), ", %s:%s", sens->hostB->hostname, sens->hostB->interfaces[z]);
}
// fprintf(stdout, "argvs = %s\n", argvs);
totali = sens->hostA->counti + sens->hostB->counti;
/*
for (j = 0; j < totali; j++) {
fprintf(stdout, "interface %d belongs to sensor %d\n", j,j < sens->hostA->counti ? 0:1);
}
*/
fprintf(stderr, "mapi_create_flow: %s\n", argvs);
if ((fd = mapi_create_flow(argvs)) < 0) {
......@@ -187,26 +342,6 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
*tmp1 = *tmp2 = '\0';
host1 = strdup(argv[1]);
host2 = strdup(argv[2]);
*tmp1 = *tmp2 = ':';
//sprintf(argvs, "host %s and host %s", host1, host2);
// count devices per host
host1_devices = 0;
k = strtok(strdup(argv[1]), ", ");
while (k != NULL) {
host1_devices++;
k = strtok(NULL,", ");
}
host2_devices = 0;
k = strtok(strdup(argv[2]), ", ");
while (k != NULL) {
host2_devices++;
k = strtok(NULL,", ");
}
fprintf(stderr, "filter used: %s\n", argv[3]);
if ((fid_loss = mapi_apply_function(fd, "BPF_FILTER", argv[3])) < 0) {
fprintf(stderr, "Count not apply function BPF_FILTER to flow %d\n", fd);
......@@ -298,45 +433,36 @@ int main(int argc, char *argv[])
oneweek.loss[counter] = oneweek.count[counter] = 0;
}
// Total interfaces
totali = sens->hostA->counti + sens->hostB->counti;
while (1) { // Infinite Loop. Forever, report the load and packet loss
// Get EXPIRED_FLOWS and BYTE_COUNTER results from sensors
results = (mapi_results_t *) mapi_read_results(fd, fid_loss);
results_netload = (mapi_results_t *) mapi_read_results(fd, fid_load);
stats1 = (struct mapi_stat *) malloc(host1_devices * sizeof(struct mapi_stat));
stats2 = (struct mapi_stat *) malloc(host2_devices * sizeof(struct mapi_stat));
if (mapi_stats(argv[1], stats1)<0) {
fprintf(stderr, "Error in mapi_stats using '%s'\n", argv[1]);
mapi_read_error( &err_no, error);
fprintf(stderr,"Errorcode :%d description: %s \n" ,err_no, error);
return -1;
}
if (mapi_stats(argv[2], stats2)<0) {
fprintf(stderr, "Error in mapi_stats using '%s'\n", argv[2]);
mapi_read_error( &err_no, error);
fprintf(stderr,"Errorcode :%d description: %s \n" ,err_no, error);
return -1;
}
struct flow_data *flowdata;// = (struct flow_data *)((char *) i + sizeof(unsigned int));
// Get interface statistics from the sensors
get_mapi_stats(&stats1, &stats2);
// Store all the information from the sensors in the hashtable.
for (j = 0; j < 2; j++) {
for (j = 0; j < totali; j++) {
i = (unsigned int *) (results[j].res);
flowdata = (struct flow_data *)((char *) i + sizeof(unsigned int));
store_results(j, *i, flowdata);
store_results(j < sens->hostA->counti ? 0:1, *i, flowdata);
}
for (j = 0; j < 2; j++) {
for (j = 0; j < totali; j++) {
// The interface matches the sensor 0 or 1
sensor = j < sens->hostA->counti ? 0:1;
/* Network Load */
//XXX this is obselete, it should be updated!
bytes = *((unsigned long long *) results_netload[j].res);
ts = results_netload[j].ts;
speed = (float) ((bytes - stats[j].prev_bytes) * 8) / (float) (ts - stats[j].prev_ts);
if (WITH_NCURSES) {
mvprintw(row / 2 + j + 2, 8, "%*s\t %6.2f Mbit/s %8llu bytes in %1.2lf seconds\n", maxpad, argv[j + 1], speed, (bytes - stats[j].prev_bytes), (double) (ts - stats[j].prev_ts) / 1000000.0);
mvprintw(row / 2 + j + 2, 8, "%*s\t %6.2f Mbit/s %8llu bytes in %1.2lf seconds\n", maxpad, argv[sensor + 1], speed, (bytes - stats[j].prev_bytes), (double) (ts - stats[j].prev_ts) / 1000000.0);
refresh(); // refresh curses windows and lines
}
stats[j].prev_bytes = bytes;
......@@ -344,7 +470,7 @@ int main(int argc, char *argv[])
/****************/
i = (unsigned int *) (results[j].res);
if (j == 0)
if (sensor == 0)
totalflows0 += *i;
else
totalflows1 += *i;
......@@ -353,12 +479,12 @@ int main(int argc, char *argv[])
for (count = *i, i = (unsigned int *) ((char *) i + sizeof(unsigned int)); count > 0; count--) {
if (LOGFILE) {
fprintf(fp_log, "[%d]\t%u\t", j, (unsigned int)time(0));
fprintf(fp_log, "[%d]\t%u\t", sensor, (unsigned int)time(0));
print_flow(fp_log, (struct flow_data *) i, 0);
fflush(fp_log);
}
if ((pkloss = cmp_results((struct flow_data *) i, j, &matchedsensor)) != 0) {
if ((pkloss = cmp_results((struct flow_data *) i, sensor, &matchedsensor)) != 0) {
totalpk.loss += pkloss;
if (LOGFILE) {
fprintf(fp_log_lost, "%u\t",(unsigned int) time(0));
......@@ -395,9 +521,9 @@ int main(int argc, char *argv[])
if (((struct flow_data *) i)->sport == 21 || ((struct flow_data *) i)->dport == 21)
ftp.lost += pkloss;
}
if (j == 0)
if (sensor == 0)
flow0totalpk.count += ((struct flow_data *) i)->packets_count;
else if (j == 1)
else if (sensor == 1)
flow1totalpk.count += ((struct flow_data *) i)->packets_count;
i = (unsigned int *) ((struct flow_data *) i + 1);
......@@ -540,16 +666,16 @@ int main(int argc, char *argv[])
if (totalpk.count == 0) {
mvprintw(row / 2 - 5, 8, "Total packet loss ratio : 0.00 %% (0 pkts)");
mvprintw(row / 2 - 4, 8, "Total byte loss ratio : 0.00 %% (0 Kbytes)");
mvprintw(row / 2 - 1, 8, "Packet lost from %s : 0 (0.00 %%)", host1);
mvprintw(row / 2, 8, "Packet lost from %s : 0 (0.00 %%)", host2);
mvprintw(row / 2 - 1, 8, "Packet lost from %s : 0 (0.00 %%)", sens->hostA->hostname);
mvprintw(row / 2, 8, "Packet lost from %s : 0 (0.00 %%)", sens->hostB->hostname);
} else {
mvprintw(row / 2 - 5, 8, "Total packet loss ratio : %.2f %% (%llu pkts)", (float) (totalpk.loss * 100) / (float) totalpk.count, totalpk.loss);
mvprintw(row / 2 - 4, 8, "Total byte loss ratio : %.2f %% (%.2f Kbytes)", (float) (totalbytes.lost * 100) / (float) totalbytes.count, (float) (totalbytes.lost / (float) 1024));
mvprintw(row / 2 - 1, 8, "Total packets lost from %s : %llu (%.2f %%)", host1, flow0totalpk.loss, (float) (flow0totalpk.loss * 100) / (float) totalpk.count);
mvprintw(row / 2, 8, "Total packets lost from %s : %llu (%.2f %%)", host2, flow1totalpk.loss, (float) (flow1totalpk.loss * 100) / (float) totalpk.count);
mvprintw(row / 2 - 1, 8, "Total packets lost from %s : %llu (%.2f %%)", sens->hostA->hostname, flow0totalpk.loss, (float) (flow0totalpk.loss * 100) / (float) totalpk.count);
mvprintw(row / 2, 8, "Total packets lost from %s : %llu (%.2f %%)", sens->hostB->hostname, flow1totalpk.loss, (float) (flow1totalpk.loss * 100) / (float) totalpk.count);
}
mvprintw(row / 2 - 3, 8, "Total packets captured at host %s : %llu", host1, flow0totalpk.count);
mvprintw(row / 2 - 2, 8, "Total packets captured at host %s : %llu", host2, flow1totalpk.count);
mvprintw(row / 2 - 3, 8, "Total packets captured at host %s : %llu", sens->hostA->hostname, flow0totalpk.count);
mvprintw(row / 2 - 2, 8, "Total packets captured at host %s : %llu", sens->hostB->hostname, flow1totalpk.count);
refresh(); // refresh curses windows and lines
}
......@@ -562,24 +688,24 @@ int main(int argc, char *argv[])
// sprintf(sensorstatslink, "green");
fprintf(fp, "misc;ts;Timestamp;%d\n", (unsigned int) time(NULL));
fprintf(fp, "\n");
fprintf(fp, "host0;hostname;Hostname;%s\n", stats1[0].hostname);
fprintf(fp, "host0;recv;Received;%u\n", stats1[0].ps_recv);
fprintf(fp, "host0;drop;Dropped;%u\n", stats1[0].ps_drop);
for(ii = 0; ii < host1_devices; ii++) {
fprintf(fp, "host%d;if%d;Interface;%s\n", 0, ii, stats1[ii].dev);
fprintf(fp, "host0;hostname;Hostname;%s\n", sens->hostA->hostname);
fprintf(fp, "host0;recv;Received;%u\n", stats1.statstable[0].ps_recv);
fprintf(fp, "host0;drop;Dropped;%u\n", stats1.statstable[0].ps_drop);
for(ii = 0; ii < stats1.count; ii++) {
fprintf(fp, "host%d;if%d;Interface;%s\n", 0, ii, stats1.statstable[ii].dev);
//fprintf(fp, "host%d;if%drecv;Received;%u\n", 0, ii, stats1[ii].ps_recv);
//fprintf(fp, "host%d;if%ddrop;Dropped;%u\n", 0, ii, stats1[ii].ps_drop);
fprintf(fp, "host%d;if%ddropif;Dropped by interface %s;%u\n", 0, ii, stats1[ii].dev, stats1[ii].ps_ifdrop);
fprintf(fp, "host%d;if%ddropif;Dropped by interface %s;%u\n", 0, ii, stats1.statstable[ii].dev, stats1.statstable[ii].ps_ifdrop);
}
fprintf(fp, "\n");
fprintf(fp, "host1;hostname;Hostname;%s\n", stats2[0].hostname);
fprintf(fp, "host1;recv;Received;%u\n", stats2[0].ps_recv);
fprintf(fp, "host1;drop;Dropped;%u\n", stats2[0].ps_drop);
for(ii = 0; ii < host2_devices; ii++) {
fprintf(fp, "host%d;if%d;Interface;%s\n", 1, ii, stats2[ii].dev);
fprintf(fp, "host1;hostname;Hostname;%s\n", sens->hostB->hostname);
fprintf(fp, "host1;recv;Received;%u\n", stats2.statstable[0].ps_recv);
fprintf(fp, "host1;drop;Dropped;%u\n", stats2.statstable[0].ps_drop);
for(ii = 0; ii < stats2.count; ii++) {
fprintf(fp, "host%d;if%d;Interface;%s\n", 1, ii, stats2.statstable[ii].dev);
//fprintf(fp, "host%d;if%drecv;Received;%u\n", 1, ii, stats2[ii].ps_recv);
//fprintf(fp, "host%d;if%ddrop;Dropped;%u\n", 1, ii, stats2[ii].ps_drop);
fprintf(fp, "host%d;if%ddropif;Dropped by interface %s;%u\n", 1, ii, stats2[ii].dev, stats2[ii].ps_ifdrop);
fprintf(fp, "host%d;if%ddropif;Dropped by interface %s;%u\n", 1, ii, stats2.statstable[ii].dev, stats2.statstable[ii].ps_ifdrop);
}
fprintf(fp, "\n");
fprintf(fp, "top;tplr;Total Packet Loss Ratio;%.2f %% (%llu pkts)\n", (float) (totalpk.count ? (totalpk.loss * 100) / (float) totalpk.count : totalpk.count), totalpk.loss);
......@@ -593,14 +719,14 @@ int main(int argc, char *argv[])
fprintf(fp, "top;plr1y;Last 1 Year Packet Loss Ratio;%.2f %% (%llu pkts)\n", (float) (oneyear.pkcount ? (oneyear.pkloss * 100) / (float) oneyear.pkcount : oneyear.pkcount), oneyear.pkloss);
//TODO fprintf(fp, "top;blr1h;Last Hour Byte Loss Ratio;%.2f %% (%.2f Kbytes);\n", (float) (totalbytes.lost * 100) / (float) totalbytes.count, (float) (totalbytes.lost / (float) 1024));
fprintf(fp, "\n");
fprintf(fp, "top;tplh1;Total packets lost from %s;%llu (%.2f %%)\n", host1, flow0totalpk.loss, (float)(totalpk.count ? (flow0totalpk.loss * 100) / (float) totalpk.count: totalpk.count));
fprintf(fp, "top;tplh2;Total packets lost from %s;%llu (%.2f %%);\n", host2, flow1totalpk.loss, (float) (totalpk.count ? (flow1totalpk.loss * 100) / (float) totalpk.count : totalpk.count));
fprintf(fp, "top;tplh1;Total packets lost from %s;%llu (%.2f %%)\n", sens->hostA->hostname, flow0totalpk.loss, (float)(totalpk.count ? (flow0totalpk.loss * 100) / (float) totalpk.count: totalpk.count));
fprintf(fp, "top;tplh2;Total packets lost from %s;%llu (%.2f %%);\n", sens->hostB->hostname, flow1totalpk.loss, (float) (totalpk.count ? (flow1totalpk.loss * 100) / (float) totalpk.count : totalpk.count));
fprintf(fp, "\n");
fprintf(fp, "top;tpch1;Total packets captured at host %s;%llu\n", host1, flow0totalpk.count);
fprintf(fp, "top;tpch2;Total packets captured at host %s;%llu\n", host2, flow1totalpk.count);
fprintf(fp, "top;tpch1;Total packets captured at host %s;%llu\n", sens->hostA->hostname, flow0totalpk.count);
fprintf(fp, "top;tpch2;Total packets captured at host %s;%llu\n", sens->hostB->hostname, flow1totalpk.count);
fprintf(fp, "\n");
fprintf(fp, "top;tpmh1;Total packets matched at host %s;%llu\n", host1, flow0totalpk.matched);
fprintf(fp, "top;tpmh2;Total packets matched at host %s;%llu\n", host2, flow1totalpk.matched);
fprintf(fp, "top;tpmh1;Total packets matched at host %s;%llu\n", sens->hostA->hostname, flow0totalpk.matched);
fprintf(fp, "top;tpmh2;Total packets matched at host %s;%llu\n", sens->hostB->hostname, flow1totalpk.matched);
fprintf(fp, "\n");
fprintf(fp, "top;load;Network Load;%f Mbit/s\n", speed);
fprintf(fp, "\n");
......@@ -621,17 +747,16 @@ int main(int argc, char *argv[])
// Refresh the statistics on the right frame
fp = fopen(TOP_FILENAME, "w");
if( stats1[0].ps_drop != 0 || stats2[0].ps_drop != 0 || stats1[0].ps_ifdrop != 0 || stats2[0].ps_ifdrop != 0)
// red or green led?
if( nodroppedpkts(&stats1) == 0 || nodroppedpkts(&stats2) == 0)
sprintf(sensorstatslink, "<center><a href='#' id='link' onClick='toggleDisplay(document.getElementById(\\\"sensorstats\\\"),1)'>Sensors Statistics</a><img src='./led-red.gif'>");
else
sprintf(sensorstatslink, "<center><a href='#' id='link' onClick='toggleDisplay(document.getElementById(\\\"sensorstats\\\"),1)'>Sensors Statistics</a><img src='./led-green.gif'>");
sprintf(sensorstats, "<center> <br> Sensor 1 interfaces stats:<br>received: %u<br>dropped: %u\
<br>dropped by interface: %u<br>Hostname: %s<br>Interface: %s<br>\
<br>Sensor 2 interfaces stats:<br>received: %u<br>dropped: %u<br>dropped by interface: %u<br>Hostname: %s<br>Interface: %s<br></center>",\
stats1[0].ps_recv,stats1[0].ps_drop,stats1[0].ps_ifdrop,stats1[0].hostname,stats1[0].dev,\
stats2[0].ps_recv,stats2[0].ps_drop,stats2[0].ps_ifdrop,stats2[0].hostname,stats2[0].dev);
sensorstats = statstostr(stats1,stats2);
sprintf(top_page_buf, top_page, sensorstats, sensorstatslink, TOP_FILENAME);
free(sensorstats);
fprintf(fp, "%s", top_page_buf);
fprintf(fp, "<center> Total Packet Loss Ratio : %.2f %% (%llu pkts)<br>\n", (float) (totalpk.count ? (totalpk.loss * 100) / (float) totalpk.count : totalpk.count), totalpk.loss);
......@@ -643,13 +768,13 @@ int main(int argc, char *argv[])
fprintf(fp, "<center> Last 1 Month Packet Loss Ratio : %.2f %% (%llu pkts)<br>\n", (float) (onemonth.pkcount ? (onemonth.pkloss * 100) / (float) onemonth.pkcount : onemonth.pkcount), onemonth.pkloss);
fprintf(fp, "<center> Last 1 Year Packet Loss Ratio : %.2f %% (%llu pkts)<br><hr>\n", (float) (oneyear.pkcount ? (oneyear.pkloss * 100) / (float) oneyear.pkcount : oneyear.pkcount), oneyear.pkloss);
//TODO fprintf(fp, "<center> Last Hour Byte Loss Ratio : %.2f %% (%.2f Kbytes)<br><hr>\n", (float) (totalbytes.lost * 100) / (float) totalbytes.count, (float) (totalbytes.lost / (float) 1024));
fprintf(fp, "<center> Total packets lost from <font color='#00FF00'><b>%s</b></font> : %llu (%.2f %%) <br>\n", host1, flow0totalpk.loss, (float)(totalpk.count ? (flow0totalpk.loss * 100) / (float) totalpk.count: totalpk.count));
fprintf(fp, "<center> Total packets lost from <font color=\"#0066FF\"><b>%s</b></font> : %llu (%.2f %%) <br><hr>\n", host2, flow1totalpk.loss, (float) (totalpk.count ? (flow1totalpk.loss * 100) / (float) totalpk.count : totalpk.count));
fprintf(fp, "<center> Total packets lost from <font color='#00FF00'><b>%s</b></font> : %llu (%.2f %%) <br>\n", sens->hostA->hostname, flow0totalpk.loss, (float)(totalpk.count ? (flow0totalpk.loss * 100) / (float) totalpk.count: totalpk.count));
fprintf(fp, "<center> Total packets lost from <font color=\"#0066FF\"><b>%s</b></font> : %llu (%.2f %%) <br><hr>\n", sens->hostB->hostname, flow1totalpk.loss, (float) (totalpk.count ? (flow1totalpk.loss * 100) / (float) totalpk.count : totalpk.count));
fprintf(fp, "<center> Total packets captured at host <font color=\"#00FF00\"><b>%s</b></font> : %llu <br>\n", host1, flow0totalpk.count);
fprintf(fp, "<center> Total packets captured at host <font color=\"#0066FF\"><b>%s</b></font> : %llu <br><hr>\n", host2, flow1totalpk.count);
fprintf(fp, "<center> Total packets matched at host <font color=\"#00FF00\"><b>%s</b></font> : %llu <br>\n", host1, flow0totalpk.matched);
fprintf(fp, "<center> Total packets matched at host <font color=\"#0066FF\"><b>%s</b></font> : %llu <br><hr>\n", host2, flow1totalpk.matched);
fprintf(fp, "<center> Total packets captured at host <font color=\"#00FF00\"><b>%s</b></font> : %llu <br>\n", sens->hostA->hostname, flow0totalpk.count);
fprintf(fp, "<center> Total packets captured at host <font color=\"#0066FF\"><b>%s</b></font> : %llu <br><hr>\n", sens->hostB->hostname, flow1totalpk.count);
fprintf(fp, "<center> Total packets matched at host <font color=\"#00FF00\"><b>%s</b></font> : %llu <br>\n", sens->hostA->hostname, flow0totalpk.matched);
fprintf(fp, "<center> Total packets matched at host <font color=\"#0066FF\"><b>%s</b></font> : %llu <br><hr>\n", sens->hostB->hostname, flow1totalpk.matched);
fprintf(fp, "<center><i><u>Network Load</u></i> : %f Mbit/s<br><hr>\n", speed);
fprintf(fp, "</div><div id='protocolstable' ><center><table border=\"0\" width=75%% bgcolor=\"#999999\" cellpadding=\"1\" cellspacing=\"1\" class=style9>\n");
......@@ -755,18 +880,18 @@ void terminate()
if (totalpk.count == 0) {
printf("\nTotal Packet Loss Ratio : 0.00 %% (0 pkts)\n");
printf("Total Byte Loss Ratio : 0.00 %% (0 Kbytes)\n");
printf("Packet lost from %s : 0 (0.00 %%)\n", host1);
printf("Packet lost from %s : 0 (0.00 %%)\n", host2);
printf("Packet lost from %s : 0 (0.00 %%)\n", sens->hostA->hostname);
printf("Packet lost from %s : 0 (0.00 %%)\n", sens->hostB->hostname);
} else {
printf("\nTotal Packet Loss Ratio : %.2f %% (%llu pkts)\n", (float) (totalpk.loss * 100) / (float) totalpk.count, totalpk.loss);
printf("Total Byte Loss Ratio : %.2f %% (%.2f Kbytes)\n", (float) (totalbytes.lost * 100) / (float) totalbytes.count, (float) (totalbytes.lost / (float) 1024));
printf("Total packets lost from %s : %llu (%.2f %%)\n", host1, flow0totalpk.loss, (float) (flow0totalpk.loss * 100) / (float) totalpk.count);
printf("Total packets lost from %s : %llu (%.2f %%)\n", host2, flow1totalpk.loss, (float) (flow1totalpk.loss * 100) / (float) totalpk.count);
printf("Total packets lost from %s : %llu (%.2f %%)\n", sens->hostA->hostname, flow0totalpk.loss, (float) (flow0totalpk.loss * 100) / (float) totalpk.count);
printf("Total packets lost from %s : %llu (%.2f %%)\n", sens->hostB->hostname, flow1totalpk.loss, (float) (flow1totalpk.loss * 100) / (float) totalpk.count);
}
printf("Total packets captured at host %s : %llu\n", host1, flow0totalpk.count);
printf("Total packets captured at host %s : %llu\n\n", host2, flow1totalpk.count);
printf("Total flows at host %s : %d\n", host1, totalflows0);
printf("Total flows at host %s : %d\n", host2, totalflows1);
printf("Total packets captured at host %s : %llu\n", sens->hostA->hostname, flow0totalpk.count);
printf("Total packets captured at host %s : %llu\n\n", sens->hostB->hostname, flow1totalpk.count);
printf("Total flows at host %s : %d\n", sens->hostA->hostname, totalflows0);
printf("Total flows at host %s : %d\n", sens->hostB->hostname, totalflows1);
if (mapi_close_flow(fd) < 0) {
fprintf(stderr, "Close flow failed\n");
......@@ -781,8 +906,6 @@ void terminate()
fclose(fp_log_unmatched);
}
free(host1);
free(host2);
exit(EXIT_SUCCESS);
}
......
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